void ItemSAO::step(float dtime, bool send_recommended) { ScopeProfiler sp2(g_profiler, "ItemSAO::step avg", SPT_AVG); assert(m_env); const float interval = 0.2; if(m_move_interval.step(dtime, interval)==false) return; dtime = interval; core::aabbox3d<f32> box(-BS/3.,0.0,-BS/3., BS/3.,BS*2./3.,BS/3.); collisionMoveResult moveresult; // Apply gravity m_speed_f += v3f(0, -dtime*9.81*BS, 0); // Maximum movement without glitches f32 pos_max_d = BS*0.25; // Limit speed if(m_speed_f.getLength()*dtime > pos_max_d) m_speed_f *= pos_max_d / (m_speed_f.getLength()*dtime); v3f pos_f = getBasePosition(); v3f pos_f_old = pos_f; IGameDef *gamedef = m_env->getGameDef(); moveresult = collisionMoveSimple(&m_env->getMap(), gamedef, pos_max_d, box, dtime, pos_f, m_speed_f); if(send_recommended == false) return; if(pos_f.getDistanceFrom(m_last_sent_position) > 0.05*BS) { setBasePosition(pos_f); m_last_sent_position = pos_f; std::ostringstream os(std::ios::binary); char buf[6]; // command (0 = update position) buf[0] = 0; os.write(buf, 1); // pos writeS32((u8*)buf, m_base_position.X*1000); os.write(buf, 4); writeS32((u8*)buf, m_base_position.Y*1000); os.write(buf, 4); writeS32((u8*)buf, m_base_position.Z*1000); os.write(buf, 4); // create message and add to list ActiveObjectMessage aom(getId(), false, os.str()); m_messages_out.push_back(aom); } }
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); }
std::string ItemSAO::getClientInitializationData() { std::ostringstream os(std::ios::binary); char buf[6]; // version buf[0] = 0; os.write(buf, 1); // pos writeS32((u8*)buf, m_base_position.X*1000); os.write(buf, 4); writeS32((u8*)buf, m_base_position.Y*1000); os.write(buf, 4); writeS32((u8*)buf, m_base_position.Z*1000); os.write(buf, 4); // inventorystring os<<serializeString(m_inventorystring); return os.str(); }
U32 PInternalQuitApplicationPkt::serialize( S8 * buf, S32 offset ) const { U32 cur_pos = PPacketBase::serialize( buf, offset ); S8 * buff = buf + offset; writeS32( buff + cur_pos , m_iReaseaon ); cur_pos += sizeof(S32); return cur_pos ; }
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))); }
/** * 固定小数として書き出す。 * */ void BinaryOutputStream::writeFixed32(const float data, const s32 bits) { writeS32(real2fixed<float, s32>(data, bits)); }
void pnVaultNode::write(unsigned char* buffer, size_t size) const { if (size < sizeof(uint64_t)) { plDebug::Error("Invalid node buffer"); return; } writeU64(fDirtyMask, buffer, size); for (size_t bit=0; bit<kNumFields; bit++) { if ((fDirtyMask & (1ULL<<bit)) == 0) continue; switch (bit) { case kNodeIdx: writeU32(fNodeIdx, buffer, size); break; case kCreateTime: writeU32(fCreateTime, buffer, size); break; case kModifyTime: writeU32(fModifyTime, buffer, size); break; case kCreateAgeName: writeString(fCreateAgeName, buffer, size); break; case kCreateAgeUuid: writeUuid(fCreateAgeUuid, buffer, size); break; case kCreatorUuid: writeUuid(fCreatorUuid, buffer, size); break; case kCreatorIdx: writeU32(fCreatorIdx, buffer, size); break; case kNodeType: writeU32(fNodeType, buffer, size); break; case kInt32_1: case kInt32_2: case kInt32_3: case kInt32_4: writeS32(fInt32[bit - kInt32_1], buffer, size); break; case kUint32_1: case kUint32_2: case kUint32_3: case kUint32_4: writeU32(fUint32[bit - kUint32_1], buffer, size); break; case kUuid_1: case kUuid_2: case kUuid_3: case kUuid_4: writeUuid(fUuid[bit - kUuid_1], buffer, size); break; case kString64_1: case kString64_2: case kString64_3: case kString64_4: case kString64_5: case kString64_6: writeString(fString64[bit - kString64_1], buffer, size); break; case kIString64_1: case kIString64_2: writeString(fIString64[bit - kIString64_1], buffer, size); break; case kText_1: case kText_2: writeString(fText[bit - kText_1], buffer, size); break; case kBlob_1: case kBlob_2: writeU32(fBlob[bit - kBlob_1].getSize(), buffer, size); memcpy(buffer, fBlob[bit - kBlob_1].getData(), fBlob[bit - kBlob_1].getSize()); buffer += fBlob[bit - kBlob_1].getSize(); size -= fBlob[bit - kBlob_1].getSize(); break; } } if (size != 0) plDebug::Warning("Node %d is truncated", fNodeIdx); }