Added dummy serialization functions

This commit is contained in:
Kayne Ruse
2014-03-06 00:20:31 +11:00
parent 7703c4b0ad
commit a850d6b1af
8 changed files with 103 additions and 14 deletions
+15 -5
View File
@@ -65,11 +65,14 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet
packet.playerInfo.motion = {0,0};
//send it
network.Send(Channels::SERVER, &packet, sizeof(NetworkPacket));
char buffer[sizeof(NetworkPacket)];
serialize(&packet, buffer);
network.Send(Channels::SERVER, buffer, sizeof(NetworkPacket));
//request a sync
packet.meta.type = NetworkPacket::Type::SYNCHRONIZE;
network.Send(Channels::SERVER, &packet, sizeof(NetworkPacket));
serialize(&packet, buffer);
network.Send(Channels::SERVER, buffer, sizeof(NetworkPacket));
}
InWorld::~InWorld() {
@@ -295,7 +298,10 @@ void InWorld::SendState() {
packet.playerInfo.position = localCharacter->GetPosition();
packet.playerInfo.motion = localCharacter->GetMotion();
network.Send(Channels::SERVER, &packet, sizeof(NetworkPacket));
char buffer[sizeof(NetworkPacket)];
serialize(&packet, buffer);
network.Send(Channels::SERVER, buffer, sizeof(NetworkPacket));
}
void InWorld::RequestDisconnect() {
@@ -303,7 +309,9 @@ void InWorld::RequestDisconnect() {
NetworkPacket packet;
packet.meta.type = NetworkPacket::Type::DISCONNECT;
packet.clientInfo.index = clientIndex;
network.Send(Channels::SERVER, &packet, sizeof(NetworkPacket));
char buffer[sizeof(NetworkPacket)];
serialize(&packet, buffer);
network.Send(Channels::SERVER, buffer, sizeof(NetworkPacket));
}
void InWorld::RequestShutDown() {
@@ -311,5 +319,7 @@ void InWorld::RequestShutDown() {
NetworkPacket packet;
packet.meta.type = NetworkPacket::Type::SHUTDOWN;
packet.clientInfo.index = clientIndex;
network.Send(Channels::SERVER, &packet, sizeof(NetworkPacket));
char buffer[sizeof(NetworkPacket)];
serialize(&packet, buffer);
network.Send(Channels::SERVER, buffer, sizeof(NetworkPacket));
}
+1
View File
@@ -27,6 +27,7 @@
#include "config_utility.hpp"
#include "udp_network_utility.hpp"
#include "network_packet.hpp"
#include "serial.hpp"
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
+7 -3
View File
@@ -80,7 +80,7 @@ void LobbyMenu::Update(double delta) {
//suck in all waiting packets
NetworkPacket packet;
while(network.Receive()) {
memcpy(&packet, network.GetInData(), sizeof(NetworkPacket));
deserialize(&packet, network.GetInData());
packet.meta.srcAddress = network.GetInPacket()->address;
HandlePacket(packet);
}
@@ -128,7 +128,9 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//broadcast to the network, or a specific server
NetworkPacket packet;
packet.meta.type = NetworkPacket::Type::BROADCAST_REQUEST;
network.Send(config["server.host"].c_str(), config.Int("server.port"), reinterpret_cast<void*>(&packet), sizeof(NetworkPacket));
char buffer[sizeof(NetworkPacket)];
serialize(&packet, buffer);
network.Send(config["server.host"].c_str(), config.Int("server.port"), buffer, sizeof(NetworkPacket));
//reset the server list
serverInfo.clear();
@@ -139,7 +141,9 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//join the selected server
NetworkPacket packet;
packet.meta.type = NetworkPacket::Type::JOIN_REQUEST;
network.Send(&selection->address, &packet, sizeof(NetworkPacket));
char buffer[sizeof(NetworkPacket)];
serialize(&packet, buffer);
network.Send(&selection->address, buffer, sizeof(NetworkPacket));
selection = nullptr;
}
+1
View File
@@ -31,6 +31,7 @@
#include "config_utility.hpp"
#include "udp_network_utility.hpp"
#include "network_packet.hpp"
#include "serial.hpp"
#include <vector>