Skip to content
Permalink
Browse files

More code cleanup (UNORDERED + RemotePlayer/LocalPlayer)

* ClientEnvironment now uses UNORDERED MAP for active objects
* Use RemotePlayer and LocalPlayer everywhere it's possible
* Minor code style fixes
* Drop Client::getBreath() unused function
  • Loading branch information
nerzhul committed Oct 8, 2016
1 parent 067766e commit fd5a130b86c08f0b3190c3d81affd4869c139fb7
@@ -383,7 +383,7 @@ void Client::step(float dtime)
if(counter <= 0.0) {
counter = 2.0;

Player *myplayer = m_env.getLocalPlayer();
LocalPlayer *myplayer = m_env.getLocalPlayer();
FATAL_ERROR_IF(myplayer == NULL, "Local player not found in environment.");

u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ?
@@ -613,7 +613,7 @@ void Client::step(float dtime)
{
// Do this every <interval> seconds after TOCLIENT_INVENTORY
// Reset the locally changed inventory to the authoritative inventory
Player *player = m_env.getLocalPlayer();
LocalPlayer *player = m_env.getLocalPlayer();
player->inventory = *m_inventory_from_server;
m_inventory_updated = true;
}
@@ -1191,7 +1191,7 @@ void Client::sendChatMessage(const std::wstring &message)
void Client::sendChangePassword(const std::string &oldpassword,
const std::string &newpassword)
{
Player *player = m_env.getLocalPlayer();
LocalPlayer *player = m_env.getLocalPlayer();
if (player == NULL)
return;

@@ -1317,7 +1317,7 @@ void Client::sendPlayerPos()

void Client::sendPlayerItem(u16 item)
{
Player *myplayer = m_env.getLocalPlayer();
LocalPlayer *myplayer = m_env.getLocalPlayer();
if(myplayer == NULL)
return;

@@ -1398,7 +1398,7 @@ bool Client::getLocalInventoryUpdated()
// Copies the inventory of the local player to parameter
void Client::getLocalInventory(Inventory &dst)
{
Player *player = m_env.getLocalPlayer();
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
dst = player->inventory;
}
@@ -1411,7 +1411,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc)
break;
case InventoryLocation::CURRENT_PLAYER:
{
Player *player = m_env.getLocalPlayer();
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
return &player->inventory;
}
@@ -1537,18 +1537,11 @@ void Client::setCrack(int level, v3s16 pos)

u16 Client::getHP()
{
Player *player = m_env.getLocalPlayer();
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
return player->hp;
}

u16 Client::getBreath()
{
Player *player = m_env.getLocalPlayer();
assert(player != NULL);
return player->getBreath();
}

bool Client::getChatMessage(std::wstring &message)
{
if(m_chat_queue.size() == 0)
@@ -460,7 +460,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
void setCrack(int level, v3s16 pos);

u16 getHP();
u16 getBreath();

bool checkPrivilege(const std::string &priv) const
{ return (m_privileges.count(priv) != 0); }
@@ -77,9 +77,9 @@ void RemoteClient::GetNextBlocks (
if(m_nothing_to_send_pause_timer >= 0)
return;

Player *player = env->getPlayer(peer_id);
RemotePlayer *player = env->getPlayer(peer_id);
// This can happen sometimes; clients and players are not in perfect sync.
if(player == NULL)
if (player == NULL)
return;

// Won't send anything if already sending
@@ -645,19 +645,16 @@ void ClientInterface::step(float dtime)

void ClientInterface::UpdatePlayerList()
{
if (m_env != NULL)
{
if (m_env != NULL) {
std::vector<u16> clients = getClientIDs();
m_clients_names.clear();


if(!clients.empty())
infostream<<"Players:"<<std::endl;

for(std::vector<u16>::iterator
i = clients.begin();
i != clients.end(); ++i) {
Player *player = m_env->getPlayer(*i);
for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) {
RemotePlayer *player = m_env->getPlayer(*i);

if (player == NULL)
continue;
@@ -655,12 +655,11 @@ void GenericCAO::initialize(const std::string &data)

if(m_is_player)
{
Player *player = m_env->getPlayer(m_name.c_str());
if(player && player->isLocal())
{
LocalPlayer *player = m_env->getPlayer(m_name.c_str());
if (player && player->isLocal()) {
m_is_local_player = true;
m_is_visible = false;
LocalPlayer* localplayer = dynamic_cast<LocalPlayer*>(player);
LocalPlayer* localplayer = player;

assert( localplayer != NULL );
localplayer->setCAO(this);

0 comments on commit fd5a130

Please sign in to comment.
You can’t perform that action at this time.