From f7d65091f83abe1cb1a70d6823291df8accbe6ab Mon Sep 17 00:00:00 2001 From: Rafael Reilova Date: Sun, 16 Nov 2014 21:52:24 -0500 Subject: 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 --- src/staticobject.cpp | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'src/staticobject.cpp') diff --git a/src/staticobject.cpp b/src/staticobject.cpp index 973257fcf..16d98605b 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -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<::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