Added position data to player objects

This commit is contained in:
Kayne Ruse
2013-12-31 02:25:16 +11:00
parent 071e0d9021
commit e040a17ca7
3 changed files with 12 additions and 44 deletions
+4
View File
@@ -22,6 +22,8 @@
#ifndef PLAYER_HPP_
#define PLAYER_HPP_
#include "vector2.hpp"
#include <string>
#include <map>
@@ -32,6 +34,8 @@ struct Player {
int clientIndex;
std::string handle;
std::string avatar;
Vector2 position;
Vector2 motion;
};
typedef std::map<int, Player> PlayerMap;
-38
View File
@@ -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 <map>
#include <string>
struct PlayerEntity {
int playerIndex;
Vector2 position;
Vector2 motion;
};
typedef std::map<int, PlayerEntity> PlayerEntityMap;
#endif
+8 -6
View File
@@ -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);
}