Skip to content
Permalink
Browse files

Refactor Game class (part 2) (#5422)

* showPauseMenu is now part of game
* remove many flags parameters passed to game functions, use the member.
* rename VolatileRunFlags to GameUIFlags (this will permit to share structure with client and CSM
* updatePointedThing: remove pointer ref, we already have the pointer in rundata
* move some attributes outside of VolatileRunFlags after renaming, to game class
* rename statustext to m_statustext
* make some const variables static
* All those changes permit to reduce a little bit function class cost and will permit to interface CSM with some interesting Game flags
* Expose GameUIFlags to client
* Client now have GameUIFlags parameter and setters for other classes
* Fix minimap show/hide in Lua because we now have access to the real flag
  • Loading branch information...
nerzhul committed Mar 19, 2017
1 parent 2e3778e commit 3c4ac70348db5375118d1e714a6d4681c3cfcd05
Showing with 285 additions and 266 deletions.
  1. +35 −2 src/client.cpp
  2. +11 −1 src/client.h
  3. +216 −262 src/game.cpp
  4. +12 −0 src/game.h
  5. +1 −1 src/guiFormSpecMenu.h
  6. +10 −0 src/script/lua_api/l_minimap.cpp
@@ -46,6 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serialization.h"
#include "guiscalingfilter.h"
#include "script/clientscripting.h"
#include "game.h"

extern gui::IGUIEnvironment* guienv;

@@ -198,7 +199,8 @@ Client::Client(
IWritableNodeDefManager *nodedef,
ISoundManager *sound,
MtEventManager *event,
bool ipv6
bool ipv6,
GameUIFlags *game_ui_flags
):
m_packetcounter_timer(0.0),
m_connection_reinit_timer(0.1),
@@ -250,7 +252,8 @@ Client::Client(
m_state(LC_Created),
m_localdb(NULL),
m_script(NULL),
m_mod_storage_save_timer(10.0f)
m_mod_storage_save_timer(10.0f),
m_game_ui_flags(game_ui_flags)
{
// Add local player
m_env.setLocalPlayer(new LocalPlayer(this, playername));
@@ -1935,6 +1938,36 @@ bool Client::shouldShowMinimap() const
return !m_minimap_disabled_by_server;
}

void Client::showGameChat(const bool show)
{
m_game_ui_flags->show_chat = show;
}

void Client::showGameHud(const bool show)
{
m_game_ui_flags->show_hud = show;
}

void Client::showMinimap(const bool show)
{
m_game_ui_flags->show_minimap = show;
}

void Client::showProfiler(const bool show)
{
m_game_ui_flags->show_profiler_graph = show;
}

void Client::showGameFog(const bool show)
{
m_game_ui_flags->force_fog_off = !show;
}

void Client::showGameDebug(const bool show)
{
m_game_ui_flags->show_debug = show;
}

// IGameDef interface
// Under envlock
IItemDefManager* Client::getItemDefManager()
@@ -307,6 +307,7 @@ class PacketCounter
};

class ClientScripting;
class GameUIFlags;

class Client : public con::PeerHandler, public InventoryManager, public IGameDef
{
@@ -326,7 +327,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
IWritableNodeDefManager *nodedef,
ISoundManager *sound,
MtEventManager *event,
bool ipv6
bool ipv6,
GameUIFlags *game_ui_flags
);

~Client();
@@ -578,6 +580,13 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
m_client_event_queue.push(event);
}

void showGameChat(const bool show = true);
void showGameHud(const bool show = true);
void showMinimap(const bool show = true);
void showProfiler(const bool show = true);
void showGameFog(const bool show = true);
void showGameDebug(const bool show = true);

private:

// Virtual methods from con::PeerHandler
@@ -725,6 +734,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
bool m_modding_enabled;
UNORDERED_MAP<std::string, ModMetadata *> m_mod_storages;
float m_mod_storage_save_timer;
GameUIFlags *m_game_ui_flags;

DISABLE_CLASS_COPY(Client);
};

0 comments on commit 3c4ac70

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