Added logic for mapping between ServerEntityIDs and LocalEntityIDs removed old code that wasn't used.
Added 1 map to Client and renamed m_ServerToClientMap to m_ServerIDToClientID. // Good to know To keep this structure please use insertIntoServerClientMaps() when adding items to them. m_ServerIDToClientID and m_ClientIDToServerID maps between server EntityIDs and local EntityIDs. To see if a local EntityID exist in m_ClientIDToServerID use clientServerMapsHasEntity(EntityID clientEntityID); To see if server EntityID exist in m_ServerIDToClientID use serverClientMapsHasEntity(EntityID serverEntityID);
This commit is contained in:
@@ -34,8 +34,6 @@ private:
|
||||
// Sending message to server logic
|
||||
int bytesRead = -1;
|
||||
char readBuf[INPUTSIZE] = { 0 };
|
||||
int snapshotInterval = 33;
|
||||
std::clock_t previousSnapshotMessage = std::clock();
|
||||
|
||||
// Packet loss logic
|
||||
unsigned int m_PacketID = 0;
|
||||
@@ -46,40 +44,43 @@ private:
|
||||
World* m_World;
|
||||
std::string m_PlayerName;
|
||||
int m_PlayerID = -1;
|
||||
|
||||
EntityID m_ServerEntityID = std::numeric_limits<EntityID>::max();
|
||||
// Server Client Lookup map
|
||||
// Assumes that root node for client and server is EntityID 0.
|
||||
std::unordered_map<EntityID, EntityID> m_ServerToClientMap;
|
||||
|
||||
// Don't Add items to these two maps with insert, use insertIntoServerClientMaps(EntityID, EntityID)!!!!
|
||||
std::unordered_map<EntityID, EntityID> m_ServerIDToClientID;
|
||||
std::unordered_map<EntityID, EntityID> m_ClientIDToServerID;
|
||||
|
||||
// Network logic
|
||||
PlayerDefinition m_PlayerDefinitions[MAXCONNECTIONS];
|
||||
SnapshotDefinitions m_NextSnapshot;
|
||||
double m_DurationOfPingTime;
|
||||
std::clock_t m_StartPingTime;
|
||||
// Use to check if we should send disconnect message
|
||||
// if game is turned of by closing window.
|
||||
bool m_WasStarted = false;
|
||||
|
||||
// Private member functions
|
||||
void readFromServer();
|
||||
void sendInputEvents();
|
||||
int receive(char* data, size_t length);
|
||||
void send(Packet& packet);
|
||||
void connect();
|
||||
void disconnect();
|
||||
void ping();
|
||||
void moveMessageHead(char*& data, size_t& length, size_t stepSize);
|
||||
void parseMessageType(Packet& packet);
|
||||
void parseEventMessage(Packet& packet);
|
||||
void updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID, const std::string& componentType);
|
||||
void parseConnect(Packet& packet);
|
||||
void parsePlayerConnected(Packet& packet);
|
||||
void parsePing();
|
||||
void parseServerPing();
|
||||
void parseSnapshot(Packet& packet);
|
||||
void identifyPacketLoss();
|
||||
bool isConnected();
|
||||
EntityID createPlayer();
|
||||
bool hasMappedEntity(EntityID entityID);
|
||||
// Mapping Logic
|
||||
// Returns if local EntityID exist in map
|
||||
bool clientServerMapsHasEntity(EntityID clientEntityID);
|
||||
// Returns if server EntityID exist in map
|
||||
bool serverClientMapsHasEntity(EntityID serverEntityID);
|
||||
void insertIntoServerClientMaps(EntityID serverEntityID, EntityID clientEntityID);
|
||||
|
||||
// Events
|
||||
EventBroker* m_EventBroker;
|
||||
|
||||
Reference in New Issue
Block a user