Implemented new version of snapshot for 3D world. Also some cleanup.

This commit is contained in:
stiffly
2015-12-08 17:57:01 +01:00
parent d1880754f5
commit 9f54a08536
5 changed files with 52 additions and 112 deletions
+8 -3
View File
@@ -203,14 +203,19 @@ void Server::Broadcast(char * data, size_t length)
void Server::SendSnapshot()
{
char* data = new char[128];
char* data = new char[INPUTSIZE];
int offset = CreateHeader(MessageType::Snapshot, data);
for (size_t i = 0; i < MAXCONNECTIONS; i++) {
memcpy(data + offset, &m_PlayerPositions[i].x, sizeof(float));
// Pack player pos into data package
glm::vec3 playerPos = m_World->GetComponent(m_PlayerDefinitions[i].EntityID, "Transform")["Position"];
memcpy(data + offset, &playerPos.x, sizeof(float));
offset += sizeof(float);
memcpy(data + offset, &m_PlayerPositions[i].y, sizeof(float));
memcpy(data + offset, &playerPos.y, sizeof(float));
offset += sizeof(float);
memcpy(data + offset, &playerPos.z, sizeof(float));
offset += sizeof(float);
// +1 for null terminator
// Pack player name into data package
memcpy(data + offset, m_PlayerDefinitions[i].Name.data(), m_PlayerDefinitions[i].Name.size() + 1);
offset += (m_PlayerDefinitions[i].Name.size() + 1) * sizeof(char);
}