Replaced several lookups to the same object with a reference

This commit is contained in:
Kayne Ruse
2014-06-02 22:35:55 +10:00
parent 2bebfdfb97
commit 0a03535ecb
2 changed files with 13 additions and 4 deletions
+1
View File
@@ -32,6 +32,7 @@
#define NETWORK_VERSION 20140601 #define NETWORK_VERSION 20140601
#define PACKET_STRING_SIZE 100 #define PACKET_STRING_SIZE 100
//TODO: would it be possible to serialize structures directly?
union SerialPacket { union SerialPacket {
//types of packets //types of packets
enum class Type { enum class Type {
+12 -4
View File
@@ -70,13 +70,21 @@ void ServerApplication::HandleJoinRequest(SerialPacket packet) {
//bounce this packet //bounce this packet
network.SendTo(&newClient.address, &packet); network.SendTo(&newClient.address, &packet);
//reference to prevent multiple lookups
//TODO: I need a way to pack structures unto packets more easily
//NOTE: this chunk of code is similar to HandleSynchronize
CharacterData& character = characterMap[characterIndex];
//send the new character to all clients //send the new character to all clients
packet.meta.type = SerialPacket::Type::CHARACTER_NEW; packet.meta.type = SerialPacket::Type::CHARACTER_NEW;
packet.characterInfo.characterIndex = characterIndex; packet.characterInfo.characterIndex = characterIndex;
strncpy(packet.characterInfo.handle, characterMap[characterIndex].handle.c_str(), PACKET_STRING_SIZE); strncpy(packet.characterInfo.handle, character.handle.c_str(), PACKET_STRING_SIZE);
strncpy(packet.characterInfo.avatar, characterMap[characterIndex].avatar.c_str(), PACKET_STRING_SIZE); strncpy(packet.characterInfo.avatar, character.avatar.c_str(), PACKET_STRING_SIZE);
packet.characterInfo.origin = characterMap[characterIndex].origin; packet.characterInfo.mapIndex = character.mapIndex;
packet.characterInfo.motion = characterMap[characterIndex].motion; packet.characterInfo.origin = character.origin;
packet.characterInfo.motion = character.motion;
packet.characterInfo.stats = character.stats;
PumpPacket(packet); PumpPacket(packet);
//TODO: don't send anything to a certain client until they send the OK (the sync packet? or ignore client side?) //TODO: don't send anything to a certain client until they send the OK (the sync packet? or ignore client side?)