From 0c7f2c5198d821217b48a4992f4eac3a605a4a89 Mon Sep 17 00:00:00 2001 From: Jocke Date: Mon, 18 Jan 2016 17:12:07 +0100 Subject: [PATCH] WIP implemented Interpolation (server logic) --- include/Engine/Network/Client.h | 5 ++++- src/Engine/Network/Client.cpp | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/Engine/Network/Client.h b/include/Engine/Network/Client.h index 7aa20126..6aaa9e77 100644 --- a/include/Engine/Network/Client.h +++ b/include/Engine/Network/Client.h @@ -4,9 +4,11 @@ #include #include #include +#include #include #include +#include #include "Network/Network.h" #include "Network/MessageType.h" @@ -68,10 +70,11 @@ private: void ping(); void parseMessageType(Packet& packet); void updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID, const std::string& componentType); - void parseConnect(Packet& packet); + void parseConnect(Packet& packet); void parsePlayerConnected(Packet& packet); void parsePing(); void parseServerPing(); + void InterpolateFields(Packet & packet, const ComponentInfo & componentInfo, const EntityID & entityID, const std::string & componentType); void parseSnapshot(Packet& packet); void identifyPacketLoss(); bool isConnected(); diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index d6e8f4c5..9ffd570b 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -112,6 +112,21 @@ void Client::parseServerPing() send(packet); } +// Fields with strings will not work right now +void Client::InterpolateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID, const std::string& componentType) +{ + int sizeOfFields = 0; + for (auto field : componentInfo.FieldsInOrder) { + ComponentInfo::Field_t fieldInfo = componentInfo.Fields.at(field); + sizeOfFields = fieldInfo.Stride; + } + // Is the size correct? + boost::shared_array eventData(new char[componentInfo.Meta.Stride]); + memcpy(eventData.get(), packet.ReadData(componentInfo.Meta.Stride), componentInfo.Meta.Stride); + //Send event to interpolat system + +} + void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, const EntityID& entityID, const std::string& componentType) { for (auto field : componentInfo.FieldsInOrder) { @@ -125,7 +140,6 @@ void Client::updateFields(Packet& packet, const ComponentInfo& componentInfo, co } } -// Field parse void Client::parseSnapshot(Packet& packet) { std::string componentType = packet.ReadString(); @@ -142,7 +156,11 @@ void Client::parseSnapshot(Packet& packet) // Check if the component exists if (m_World->HasComponent(entityID, componentType)) { // If the entity and the component exists update it - updateFields(packet, componentInfo, entityID, componentType); + if (componentType == "Transform") { + InterpolateFields(packet, componentInfo, entityID, componentType); + } else { + updateFields(packet, componentInfo, entityID, componentType); + } // if entity exists but not the component } else { // Create component