void Client::sendPlayerPos() { //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out Player *myplayer = m_env.getLocalPlayer(); if(myplayer == NULL) return; u16 our_peer_id; { //JMutexAutoLock lock(m_con_mutex); //bulk comment-out our_peer_id = m_con.GetPeerID(); } // Set peer id if not set already if(myplayer->peer_id == PEER_ID_INEXISTENT) myplayer->peer_id = our_peer_id; // Check that an existing peer_id is the same as the connection's assert(myplayer->peer_id == our_peer_id); v3f pf = myplayer->getPosition(); v3s32 position(pf.X*100, pf.Y*100, pf.Z*100); v3f sf = myplayer->getSpeed(); v3s32 speed(sf.X*100, sf.Y*100, sf.Z*100); s32 pitch = myplayer->getPitch() * 100; s32 yaw = myplayer->getYaw() * 100; /* Format: [0] u16 command [2] v3s32 position*100 [2+12] v3s32 speed*100 [2+12+12] s32 pitch*100 [2+12+12+4] s32 yaw*100 */ SharedBuffer<u8> data(2+12+12+4+4); writeU16(&data[0], TOSERVER_PLAYERPOS); writeV3S32(&data[2], position); writeV3S32(&data[2+12], speed); writeS32(&data[2+12+12], pitch); writeS32(&data[2+12+12+4], yaw); // Send as unreliable Send(0, data, false); }
void StaticObject::serialize(std::ostream &os) { char buf[12]; // type buf[0] = type; os.write(buf, 1); // pos writeV3S32((u8*)buf, v3s32(pos.X*1000,pos.Y*1000,pos.Z*1000)); os.write(buf, 12); // data os<<serializeString(data); }
void TestSerialization::testStreamWrite() { std::ostringstream os(std::ios_base::binary); std::string data; writeU8(os, 0x11); writeU16(os, 0x2233); writeU32(os, 0x44556677); writeU64(os, 0x8899AABBCCDDEEFF); writeS8(os, -128); writeS16(os, 30000); writeS32(os, -6); writeS64(os, -43); writeF1000(os, 53.53467f); writeF1000(os, -300000.32f); writeF1000(os, F1000_MIN); writeF1000(os, F1000_MAX); os << serializeString("foobar!"); data = os.str(); UASSERT(data.size() < sizeof(test_serialized_data)); UASSERT(!memcmp(&data[0], test_serialized_data, data.size())); writeV2S16(os, v2s16(500, 500)); writeV3S16(os, v3s16(4207, 604, -30)); writeV2S32(os, v2s32(1920, 1080)); writeV3S32(os, v3s32(-400, 6400054, 290549855)); writeV2F1000(os, v2f(500.65661f, 350.34567f)); os << serializeWideString(L"\x02~woof~\x5455"); writeV3F1000(os, v3f(500, 10024.2f, -192.54f)); writeARGB8(os, video::SColor(255, 128, 50, 128)); os << serializeLongString("some longer string here"); writeU16(os, 0xF00D); data = os.str(); UASSERT(data.size() == sizeof(test_serialized_data)); UASSERT(!memcmp(&data[0], test_serialized_data, sizeof(test_serialized_data))); }