1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

serialize.h: use machine native byte swapping if available, fall-back to previous generic method if not (supported for GCC using endian.h, detection done in cmake) write/readARGB8() - just write 32-bit color in one op, instead of 4 1-byte ops cleanup: removed unneeded buffer init for some serialize-out functions use a #define for the fixed point factor in read/writeF1000()

nodemetadata.cpp, nodetimer.cpp
	optimzation: simpler deserialize node position method

staticobject.cpp:
	cleanup: use util/serialize.h inlines instead of its own de/serialization

serialize.cpp:
	minor optimization/cleanup: avoid generation of unneeded string temporary

CMakeLists.txt, cmake_config.h.in: detection of endian.h

config.h: added HAVE_ENDIAN_H

Commits due to feedback squashed

Signed-off-by: Craig Robbins <kde.psych@gmail.com>
This commit is contained in:
Rafael Reilova 2014-11-16 21:52:24 -05:00 committed by Craig Robbins
parent d406ac994b
commit f7d65091f8
8 changed files with 115 additions and 85 deletions

View file

@ -22,42 +22,31 @@ with this program; if not, write to the Free Software Foundation, Inc.,
void StaticObject::serialize(std::ostream &os)
{
char buf[12];
// type
buf[0] = type;
os.write(buf, 1);
writeU8(os, type);
// pos
writeV3S32((u8*)buf, v3s32(pos.X*1000,pos.Y*1000,pos.Z*1000));
os.write(buf, 12);
writeV3F1000(os, pos);
// data
os<<serializeString(data);
}
void StaticObject::deSerialize(std::istream &is, u8 version)
{
char buf[12];
// type
is.read(buf, 1);
type = buf[0];
type = readU8(is);
// pos
is.read(buf, 12);
v3s32 intp = readV3S32((u8*)buf);
pos.X = (f32)intp.X/1000;
pos.Y = (f32)intp.Y/1000;
pos.Z = (f32)intp.Z/1000;
pos = readV3F1000(is);
// data
data = deSerializeString(is);
}
void StaticObjectList::serialize(std::ostream &os)
{
char buf[12];
// version
buf[0] = 0;
os.write(buf, 1);
u8 version = 0;
writeU8(os, version);
// count
u16 count = m_stored.size() + m_active.size();
writeU16((u8*)buf, count);
os.write(buf, 2);
writeU16(os, count);
for(std::list<StaticObject>::iterator
i = m_stored.begin();
i != m_stored.end(); ++i)
@ -75,13 +64,10 @@ void StaticObjectList::serialize(std::ostream &os)
}
void StaticObjectList::deSerialize(std::istream &is)
{
char buf[12];
// version
is.read(buf, 1);
u8 version = buf[0];
u8 version = readU8(is);
// count
is.read(buf, 2);
u16 count = readU16((u8*)buf);
u16 count = readU16(is);
for(u16 i=0; i<count; i++)
{
StaticObject s_obj;