From 70f104be076321330a0827010704761a040d8ec7 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 8 Oct 2016 23:13:38 +0200 Subject: Environment cleanup * Move client list to ServerEnvironment and use RemotePlayer members instead of Player * ClientEnvironment only use setLocalPlayer to specify the current player * Remove ClientEnvironment dead code on player list (in fact other players are CAO not Player objects) * Drop LocalPlayer::getPlayer(xxx) functions which aren't used. * Improve a little bit performance by using const ref list for ClientEnvironment::getPlayerNames() & Client::getConnectedPlayerNames() * Drop isLocal() function from (Local)Player which is not needed anymore because of previous changes This change permits to cleanup shared client list which is very old code. ClientEnvironment doesn't use player list anymore, it only contains the local player, as addPlayer is only called from Client constructor client side. Clients are only CAO on client side, this cleanup permit to remove confusion about player list. --- src/environment.h | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'src/environment.h') diff --git a/src/environment.h b/src/environment.h index f19708ad7..83ad69562 100644 --- a/src/environment.h +++ b/src/environment.h @@ -72,9 +72,6 @@ public: virtual Map & getMap() = 0; - virtual void addPlayer(Player *player); - void removePlayer(Player *player); - u32 getDayNightRatio(); // 0-23999 @@ -94,12 +91,6 @@ public: u32 m_added_objects; protected: - Player *getPlayer(u16 peer_id); - Player *getPlayer(const char *name); - - // peer_ids in here should be unique, except that there may be many 0s - std::vector m_players; - GenericAtomic m_time_of_day_speed; /* @@ -325,6 +316,8 @@ public: void saveLoadedPlayers(); void savePlayer(RemotePlayer *player); RemotePlayer *loadPlayer(const std::string &playername); + void addPlayer(RemotePlayer *player); + void removePlayer(RemotePlayer *player); /* Save and load time of day and game timer @@ -520,6 +513,9 @@ private: // Can raise to high values like 15s with eg. map generation mods. float m_max_lag_estimate; + // peer_ids in here should be unique, except that there may be many 0s + std::vector m_players; + // Particles IntervalLimiter m_particle_management_interval; UNORDERED_MAP m_particle_spawners; @@ -579,8 +575,8 @@ public: void step(f32 dtime); - virtual void addPlayer(LocalPlayer *player); - LocalPlayer * getLocalPlayer(); + virtual void setLocalPlayer(LocalPlayer *player); + LocalPlayer *getLocalPlayer() { return m_local_player; } /* ClientSimpleObjects @@ -630,21 +626,15 @@ public: u16 attachement_parent_ids[USHRT_MAX + 1]; - std::list getPlayerNames() - { return m_player_names; } - void addPlayerName(std::string name) - { m_player_names.push_back(name); } - void removePlayerName(std::string name) - { m_player_names.remove(name); } + const std::list &getPlayerNames() { return m_player_names; } + void addPlayerName(const std::string &name) { m_player_names.push_back(name); } + void removePlayerName(const std::string &name) { m_player_names.remove(name); } void updateCameraOffset(v3s16 camera_offset) { m_camera_offset = camera_offset; } v3s16 getCameraOffset() const { return m_camera_offset; } - - LocalPlayer *getPlayer(const u16 peer_id); - LocalPlayer *getPlayer(const char* name); - private: ClientMap *m_map; + LocalPlayer *m_local_player; scene::ISceneManager *m_smgr; ITextureSource *m_texturesource; IGameDef *m_gamedef; -- cgit v1.2.3