Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 fd5a130
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 152 deletions.
21 changes: 7 additions & 14 deletions src/client.cpp
Expand Up @@ -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") ?
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/client.h
Expand Up @@ -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); }
Expand Down
13 changes: 5 additions & 8 deletions src/clientiface.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/content_cao.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit fd5a130

Please sign in to comment.