Merge branch 'voxel-upd' into vixel-upd-2

This commit is contained in:
alexei-zebra 2024-01-05 23:39:54 +03:00 • committed by GitHub
commit d9e1d353d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 498 additions and 286 deletions

View file

@ -4,7 +4,7 @@
#include <limits>
#include <stdexcept>
void BinaryWriter::put(ubyte b) {
void BinaryWriter::put(u_char8 b) {
buffer.push_back(b);
}
@ -22,7 +22,7 @@ void BinaryWriter::put(const std::string& s) {
throw std::domain_error("length > INT16_MAX");
}
putInt16(len);
put((const ubyte*)s.data(), len);
put((const u_char8*)s.data(), len);
}
void BinaryWriter::putShortStr(const std::string& s) {
@ -31,10 +31,10 @@ void BinaryWriter::putShortStr(const std::string& s) {
throw std::domain_error("length > 255");
}
put(len);
put((const ubyte*)s.data(), len);
put((const u_char8*)s.data(), len);
}
void BinaryWriter::put(const ubyte* arr, size_t size) {
void BinaryWriter::put(const u_char8* arr, size_t size) {
buffer.reserve(buffer.size() + size);
for (size_t i = 0; i < size; i++) {
buffer.push_back(arr[i]);
@ -75,7 +75,7 @@ void BinaryWriter::putFloat32(float val) {
putInt32(value.vali32);
}
BinaryReader::BinaryReader(const ubyte* data, size_t size)
BinaryReader::BinaryReader(const u_char8* data, size_t size)
: data(data), size(size), pos(0) {
}
@ -84,14 +84,14 @@ void BinaryReader::checkMagic(const char* data, size_t size) {
throw std::runtime_error("invalid magic number");
}
for (size_t i = 0; i < size; i++) {
if (this->data[pos + i] != (ubyte)data[i]){
if (this->data[pos + i] != (u_char8)data[i]){
throw std::runtime_error("invalid magic number");
}
}
pos += size;
}
ubyte BinaryReader::get() {
u_char8 BinaryReader::get() {
if (pos == size) {
throw std::underflow_error("buffer underflow");
}
@ -152,7 +152,7 @@ std::string BinaryReader::getString() {
}
std::string BinaryReader::getShortString() {
ubyte length = get();
u_char8 length = get();
if (pos+length > size) {
throw std::underflow_error("unexpected end");
}