void ServerGame::sendMovePacket(ClassId class_id, int obj_id) { Entity* ent = (Entity*)(EntitySpawner::instance()->GetEntity(class_id, obj_id)); // If this is not a player and the player is dead, don't update if (class_id == ClassId::PLAYER) { if (!((Player*)ent)->IsAlive()) return; } Packet packet; packet.hdr.sender_id = SERVER_ID; packet.hdr.packet_type = MOVE_EVENT; PosInfo p; packet.dat.game_data_id = POS_OBJ; // Extract the vector and send it with the posinfo object btVector3 vec = ent->GetEntityPosition(); p.cid = class_id; p.oid = obj_id; p.x = vec.getX(); p.y = vec.getY(); p.z = vec.getZ(); if (class_id == PLAYER) { p.num_eggs = ((Player*)ent)->GetScore(); p.jump = ((Player*)ent)->GetJumpSem(); p.hp = ((Player*)ent)->GetHP(); } p.serialize(packet.dat.buf); const unsigned int packet_size = sizeof(Packet); char packet_data[packet_size]; packet.serialize(packet_data); network->sendToAll(packet_data, packet_size); }
void ServerGame::sendRotationPacket(int class_id, int obj_id) { const unsigned int packet_size = sizeof(Packet); char packet_data[packet_size]; Entity* ent = (Entity*)(EntitySpawner::instance()->GetEntity(class_id, obj_id)); // If this is not a player and the player is dead, don't update if (class_id == ClassId::PLAYER) { if (!((Player*)ent)->IsAlive()) return; } Packet packet; packet.hdr.sender_id = SERVER_ID; packet.hdr.packet_type = V_ROTATION_EVENT; packet.dat.game_data_id = POS_OBJ; PosInfo p; p.cid = (ClassId) class_id; p.oid = obj_id; // why do we switch w and y and multiply by negative, we don't know but it fixes it btQuaternion q = ent->GetEntityRotation(); btVector3 v = ent->GetEntityPosition(); p.x = v.getX(); p.y = v.getY(); p.z = v.getZ(); p.rotw = q.getW(); p.rotx = q.getX(); p.roty = q.getY(); p.rotz = q.getZ(); p.serialize(packet.dat.buf); packet.serialize(packet_data); network->sendToAll(packet_data, packet_size); }