summaryrefslogtreecommitdiff
path: root/src/staticobject.cpp
diff options
context:
space:
mode:
authorRafael Reilova <rafael7@users.noreply.github.com>2014-11-16 21:52:24 -0500
committerCraig Robbins <kde.psych@gmail.com>2014-11-21 22:33:48 +1000
commitf7d65091f83abe1cb1a70d6823291df8accbe6ab (patch)
tree6955cb513a7d92e9db775e33e18389dfc2738667 /src/staticobject.cpp
parentd406ac994b8092c5bd2dc32eda1a2eafbf95a30c (diff)
downloadminetest-f7d65091f83abe1cb1a70d6823291df8accbe6ab.tar.gz
minetest-f7d65091f83abe1cb1a70d6823291df8accbe6ab.tar.bz2
minetest-f7d65091f83abe1cb1a70d6823291df8accbe6ab.zip
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>
Diffstat (limited to 'src/staticobject.cpp')
-rw-r--r--src/staticobject.cpp32
1 files changed, 9 insertions, 23 deletions
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<<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;