mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 13:30:06 +00:00
Save pointer to Player struct in CNSocket.
This is an insignificant optimization now, but will be necessary when we start switching around the the algorithms and datastructures used in proximity detection.
This commit is contained in:
parent
3865249387
commit
579aa9d31d
@ -132,6 +132,8 @@ enum ACTIVEKEY {
|
||||
SOCKETKEY_FE
|
||||
};
|
||||
|
||||
struct Player;
|
||||
|
||||
class CNSocket;
|
||||
typedef void (*PacketHandler)(CNSocket* sock, CNPacketData* data);
|
||||
|
||||
@ -153,6 +155,7 @@ private:
|
||||
public:
|
||||
SOCKET sock;
|
||||
PacketHandler pHandler;
|
||||
Player *plr = nullptr;
|
||||
|
||||
CNSocket(SOCKET s, PacketHandler ph);
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
#include "settings.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
@ -45,6 +47,8 @@ void PlayerManager::addPlayer(CNSocket* key, Player plr) {
|
||||
players[key].plr = p;
|
||||
players[key].lastHeartbeat = 0;
|
||||
|
||||
key->plr = p;
|
||||
|
||||
std::cout << U16toU8(plr.PCStyle.szFirstName) << " " << U16toU8(plr.PCStyle.szLastName) << " has joined!" << std::endl;
|
||||
std::cout << players.size() << " players" << std::endl;
|
||||
}
|
||||
@ -66,6 +70,7 @@ void PlayerManager::removePlayer(CNSocket* key) {
|
||||
std::cout << U16toU8(cachedView.plr->PCStyle.szFirstName) << " " << U16toU8(cachedView.plr->PCStyle.szLastName) << " has left!" << std::endl;
|
||||
std::cout << players.size() << " players" << std::endl;
|
||||
|
||||
key->plr = nullptr;
|
||||
delete cachedView.plr;
|
||||
players.erase(key);
|
||||
}
|
||||
@ -692,7 +697,8 @@ void PlayerManager::changePlayerGuide(CNSocket *sock, CNPacketData *data) {
|
||||
|
||||
#pragma region Helper methods
|
||||
Player *PlayerManager::getPlayer(CNSocket* key) {
|
||||
return players[key].plr;
|
||||
assert(key->plr != nullptr);
|
||||
return key->plr;
|
||||
}
|
||||
|
||||
WarpLocation PlayerManager::getRespawnPoint(Player *plr) {
|
||||
|
Loading…
Reference in New Issue
Block a user