Final refactor of basebuffer

This commit is contained in:
2026-02-22 23:56:48 -05:00
parent cbbe475f65
commit 8889a36ba3
8 changed files with 162 additions and 128 deletions

View File

@@ -248,6 +248,9 @@ using LuaValue = BaseLuaValue<eng::string>;
class StreamBufferConfig {
public:
using string_type = eng::string;
using fvector_type = util::XYZ;
using dvector_type = util::DXYZ;
using luavalue_type = LuaValue;
void *basebuffer_malloc(size_t size) { return eng::malloc(size); }
void basebuffer_free(void *p) { eng::free(p); }
void clear_error_flags() { }
@@ -260,50 +263,16 @@ class StreamBuffer : public eng::nevernew, public BaseBuffer<StreamBufferConfig>
public:
using BaseBuffer::BaseBuffer;
void write_xyz(const util::XYZ &xyz) {
write_float(xyz.x);
write_float(xyz.y);
write_float(xyz.z);
}
void write_dxyz(const util::DXYZ &xyz) {
write_double(xyz.x);
write_double(xyz.y);
write_double(xyz.z);
}
void write_hashvalue(const util::HashValue &h) {
write_uint64(h.first);
write_uint64(h.second);
}
util::XYZ read_xyz() {
float x = read_float();
float y = read_float();
float z = read_float();
return util::XYZ(x, y, z);
}
util::DXYZ read_dxyz() {
double x = read_double();
double y = read_double();
double z = read_double();
return util::DXYZ(x, y, z);
}
util::HashValue read_hashvalue() {
uint64_t f = read_uint64();
uint64_t s = read_uint64();
return util::HashValue(f, s);
}
bool contents_equal(const StreamBuffer *sb) {
return view() == sb->view();
}
void copy_into(StreamBuffer *sb) {
sb->write_bytes(view());
}
};
// Use a streambuffer as a lua_writer.