GameInstance.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * GameInstance.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "GameEngineUser.h"
  12. class CServerHandler;
  13. class GlobalLobbyClient;
  14. class CPlayerInterface;
  15. class CMapHandler;
  16. class CMainMenu;
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. class INetworkHandler;
  19. VCMI_LIB_NAMESPACE_END
  20. class GameShutdownException final : public std::exception
  21. {
  22. public:
  23. const char* what() const noexcept final
  24. {
  25. return "Game shutdown has been requested";
  26. }
  27. };
  28. class GameInstance final : boost::noncopyable, public IGameEngineUser
  29. {
  30. std::unique_ptr<CServerHandler> serverInstance;
  31. std::unique_ptr<CMapHandler> mapInstance;
  32. std::shared_ptr<CMainMenu> mainMenuInstance;
  33. CPlayerInterface * interfaceInstance;
  34. public:
  35. GameInstance();
  36. ~GameInstance();
  37. CServerHandler & server();
  38. CMapHandler & map();
  39. std::shared_ptr<CMainMenu> mainmenu();
  40. CPlayerInterface * interface();
  41. void setServerInstance(std::unique_ptr<CServerHandler> ptr);
  42. void setMapInstance(std::unique_ptr<CMapHandler> ptr);
  43. void setInterfaceInstance(CPlayerInterface * ptr);
  44. void onGlobalLobbyInterfaceActivated() final;
  45. void onUpdate() final;
  46. bool capturedAllEvents() final;
  47. void onShutdownRequested(bool askForConfirmation) final;
  48. };
  49. extern std::unique_ptr<GameInstance> GAME;