From 31cca61d1c7df8971ed27aca7fb9985863982be3 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 31 Dec 2013 02:25:16 +1100 Subject: [PATCH] Added position data to player objects --- server/player.hpp | 4 ++++ server/player_entity.hpp | 38 ----------------------------------- server/server_application.cpp | 14 +++++++------ 3 files changed, 12 insertions(+), 44 deletions(-) delete mode 100644 server/player_entity.hpp diff --git a/server/player.hpp b/server/player.hpp index fa015ab..e709ba4 100644 --- a/server/player.hpp +++ b/server/player.hpp @@ -22,6 +22,8 @@ #ifndef PLAYER_HPP_ #define PLAYER_HPP_ +#include "vector2.hpp" + #include #include @@ -32,6 +34,8 @@ struct Player { int clientIndex; std::string handle; std::string avatar; + Vector2 position; + Vector2 motion; }; typedef std::map PlayerMap; diff --git a/server/player_entity.hpp b/server/player_entity.hpp deleted file mode 100644 index f350384..0000000 --- a/server/player_entity.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef PLAYERENTITY_HPP_ -#define PLAYERENTITY_HPP_ - -#include "vector2.hpp" - -#include -#include - -struct PlayerEntity { - int playerIndex; - Vector2 position; - Vector2 motion; -}; - -typedef std::map PlayerEntityMap; - -#endif diff --git a/server/server_application.cpp b/server/server_application.cpp index c914487..c2f79a4 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -216,8 +216,8 @@ void ServerApplication::HandleSynchronize(NetworkPacket packet) { newPacket.playerInfo.playerIndex = it.first; snprintf(newPacket.playerInfo.handle, PACKET_STRING_SIZE, "%s", it.second.handle.c_str()); snprintf(newPacket.playerInfo.avatar, PACKET_STRING_SIZE, "%s", it.second.avatar.c_str()); - newPacket.playerInfo.position = {0,0}; - newPacket.playerInfo.motion = {0,0}; + newPacket.playerInfo.position = it.second.position; + newPacket.playerInfo.motion = it.second.motion; network.Send(&clientMap[packet.clientInfo.index].address, &newPacket, sizeof(NetworkPacket)); } } @@ -239,14 +239,16 @@ void ServerApplication::HandlePlayerNew(NetworkPacket packet) { newPlayer.clientIndex = packet.playerInfo.clientIndex; newPlayer.handle = packet.playerInfo.handle; newPlayer.avatar = packet.playerInfo.avatar; + newPlayer.position = {0,0}; + newPlayer.motion = {0,0}; //push this player playerMap[playerCounter] = newPlayer; //send the client their info packet.playerInfo.playerIndex = playerCounter; - packet.playerInfo.position = {0,0}; - packet.playerInfo.motion = {0,0}; + packet.playerInfo.position = playerMap[playerCounter].position; + packet.playerInfo.motion = playerMap[playerCounter].motion; //actually send to everyone PumpPacket(packet); @@ -284,8 +286,8 @@ void ServerApplication::HandlePlayerUpdate(NetworkPacket packet) { } //server is the slave to the clients, but only for now -// playerMap[packet.playerInfo.playerIndex].position = packet.playerInfo.position; -// playerMap[packet.playerInfo.playerIndex].motion = packet.playerInfo.motion; + playerMap[packet.playerInfo.playerIndex].position = packet.playerInfo.position; + playerMap[packet.playerInfo.playerIndex].motion = packet.playerInfo.motion; PumpPacket(packet); }