Added position data to player objects
This commit is contained in:
@@ -22,6 +22,8 @@
|
|||||||
#ifndef PLAYER_HPP_
|
#ifndef PLAYER_HPP_
|
||||||
#define PLAYER_HPP_
|
#define PLAYER_HPP_
|
||||||
|
|
||||||
|
#include "vector2.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@@ -32,6 +34,8 @@ struct Player {
|
|||||||
int clientIndex;
|
int clientIndex;
|
||||||
std::string handle;
|
std::string handle;
|
||||||
std::string avatar;
|
std::string avatar;
|
||||||
|
Vector2 position;
|
||||||
|
Vector2 motion;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<int, Player> PlayerMap;
|
typedef std::map<int, Player> PlayerMap;
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -216,8 +216,8 @@ void ServerApplication::HandleSynchronize(NetworkPacket packet) {
|
|||||||
newPacket.playerInfo.playerIndex = it.first;
|
newPacket.playerInfo.playerIndex = it.first;
|
||||||
snprintf(newPacket.playerInfo.handle, PACKET_STRING_SIZE, "%s", it.second.handle.c_str());
|
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());
|
snprintf(newPacket.playerInfo.avatar, PACKET_STRING_SIZE, "%s", it.second.avatar.c_str());
|
||||||
newPacket.playerInfo.position = {0,0};
|
newPacket.playerInfo.position = it.second.position;
|
||||||
newPacket.playerInfo.motion = {0,0};
|
newPacket.playerInfo.motion = it.second.motion;
|
||||||
network.Send(&clientMap[packet.clientInfo.index].address, &newPacket, sizeof(NetworkPacket));
|
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.clientIndex = packet.playerInfo.clientIndex;
|
||||||
newPlayer.handle = packet.playerInfo.handle;
|
newPlayer.handle = packet.playerInfo.handle;
|
||||||
newPlayer.avatar = packet.playerInfo.avatar;
|
newPlayer.avatar = packet.playerInfo.avatar;
|
||||||
|
newPlayer.position = {0,0};
|
||||||
|
newPlayer.motion = {0,0};
|
||||||
|
|
||||||
//push this player
|
//push this player
|
||||||
playerMap[playerCounter] = newPlayer;
|
playerMap[playerCounter] = newPlayer;
|
||||||
|
|
||||||
//send the client their info
|
//send the client their info
|
||||||
packet.playerInfo.playerIndex = playerCounter;
|
packet.playerInfo.playerIndex = playerCounter;
|
||||||
packet.playerInfo.position = {0,0};
|
packet.playerInfo.position = playerMap[playerCounter].position;
|
||||||
packet.playerInfo.motion = {0,0};
|
packet.playerInfo.motion = playerMap[playerCounter].motion;
|
||||||
|
|
||||||
//actually send to everyone
|
//actually send to everyone
|
||||||
PumpPacket(packet);
|
PumpPacket(packet);
|
||||||
@@ -284,8 +286,8 @@ void ServerApplication::HandlePlayerUpdate(NetworkPacket packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//server is the slave to the clients, but only for now
|
//server is the slave to the clients, but only for now
|
||||||
// playerMap[packet.playerInfo.playerIndex].position = packet.playerInfo.position;
|
playerMap[packet.playerInfo.playerIndex].position = packet.playerInfo.position;
|
||||||
// playerMap[packet.playerInfo.playerIndex].motion = packet.playerInfo.motion;
|
playerMap[packet.playerInfo.playerIndex].motion = packet.playerInfo.motion;
|
||||||
|
|
||||||
PumpPacket(packet);
|
PumpPacket(packet);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user