Changeset View
Changeset View
Standalone View
Standalone View
source/ps/Game.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | class CGame | ||||
player_id_t m_PlayerID; | player_id_t m_PlayerID; | ||||
/** | /** | ||||
* Differs from m_PlayerID if a defeated player or observer views another player. | * Differs from m_PlayerID if a defeated player or observer views another player. | ||||
*/ | */ | ||||
player_id_t m_ViewedPlayerID; | player_id_t m_ViewedPlayerID; | ||||
CTurnManager* m_TurnManager; | CTurnManager* m_TurnManager; | ||||
private: | |||||
static CGame* s_Game; | |||||
vladislavbelov: Put the private part under the public one.
Also I'd prefer to try use `std::unique_ptr`… | |||||
SilierAuthorUnsubmitted Done Inline Actionsidea was to enforce getter Silier: idea was to enforce getter | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsIt's not related to. I'm talking about storing, you're always able to return raw pointer as unique_ptr.get(). vladislavbelov: It's not related to. I'm talking about storing, you're always able to return raw pointer as… | |||||
SilierAuthorUnsubmitted Done Inline Actionsok I missunderstood put the private under public Silier: ok I missunderstood put the private under public | |||||
public: | public: | ||||
static CGame* GetGame(); | |||||
static void InitGame(bool disableGraphics = false, bool replayLog = true); | |||||
static void DeInitGame(); | |||||
static bool IsGameInitialised(); | |||||
Not Done Inline ActionsYou need to use the Singleton<Game> deriving instead on the own implementation. vladislavbelov: You need to use the `Singleton<Game>` deriving instead on the own implementation. | |||||
Done Inline ActionsI was not aware about this option. But can it be used if g_Game is initialised with different parameters and deleted in several places? Silier: I was not aware about this option. But can it be used if g_Game is initialised with different… | |||||
Not Done Inline ActionsYes, it's possible, something like this: class CGame : public Singleton<CGame> {}; // Before usage new CGame(..., ...); // Usage CGame::GetSingleton().Call...; // After usage delete CGame::GetSingletonPtr(); vladislavbelov: Yes, it's possible, something like this:
```lang=cpp
class CGame : public Singleton<CGame> {}… | |||||
CGame(bool disableGraphics = false, bool replayLog = true); | CGame(bool disableGraphics = false, bool replayLog = true); | ||||
~CGame(); | ~CGame(); | ||||
/** | /** | ||||
* the game is paused and no updates will be performed if true. | * the game is paused and no updates will be performed if true. | ||||
**/ | **/ | ||||
bool m_Paused; | bool m_Paused; | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | private: | ||||
int LoadVisualReplayData(); | int LoadVisualReplayData(); | ||||
OsPath m_ReplayPath; | OsPath m_ReplayPath; | ||||
bool m_IsVisualReplay; | bool m_IsVisualReplay; | ||||
std::istream* m_ReplayStream; | std::istream* m_ReplayStream; | ||||
u32 m_FinalReplayTurn; | u32 m_FinalReplayTurn; | ||||
}; | }; | ||||
extern CGame *g_Game; | |||||
#endif | #endif |
Wildfire Games · Phabricator
Put the private part under the public one.
Also I'd prefer to try use std::unique_ptr instead of raw pointers for a more safe control.