Codechange: Place gamelog into its own class, along with internal data.

Data is now stored in vectors to avoid manual memory management and
passing lengths around.
This commit is contained in:
Peter Nelson
2023-05-01 18:14:31 +01:00
committed by PeterN
parent 47a8d12f0e
commit 00bf42353a
18 changed files with 308 additions and 345 deletions

View File

@@ -26,36 +26,77 @@ enum GamelogActionType : uint8 {
GLAT_NONE = 0xFF, ///< No logging active; in savegames, end of list
};
void GamelogStartAction(GamelogActionType at);
void GamelogStopAction();
void GamelogStopAnyAction();
/** Type of logged change */
enum GamelogChangeType : uint8 {
GLCT_MODE, ///< Scenario editor x Game, different landscape
GLCT_REVISION, ///< Changed game revision string
GLCT_OLDVER, ///< Loaded from savegame without logged data
GLCT_SETTING, ///< Non-networksafe setting value changed
GLCT_GRFADD, ///< Removed GRF
GLCT_GRFREM, ///< Added GRF
GLCT_GRFCOMPAT, ///< Loading compatible GRF
GLCT_GRFPARAM, ///< GRF parameter changed
GLCT_GRFMOVE, ///< GRF order changed
GLCT_GRFBUG, ///< GRF bug triggered
GLCT_EMERGENCY, ///< Emergency savegame
GLCT_END, ///< So we know how many GLCTs are there
GLCT_NONE = 0xFF, ///< In savegames, end of list
};
void GamelogFree(struct LoggedAction *gamelog_action, uint gamelog_actions);
void GamelogReset();
struct LoggedChange;
struct LoggedAction;
struct GamelogInternalData;
void GamelogPrint(std::function<void(const char *)> proc);
void GamelogPrintDebug(int level);
void GamelogPrintConsole();
class Gamelog {
private:
std::unique_ptr<GamelogInternalData> data;
GamelogActionType action_type;
struct LoggedAction *current_action;
void GamelogEmergency();
bool GamelogTestEmergency();
LoggedChange *Change(GamelogChangeType ct);
void GamelogRevision();
void GamelogMode();
void GamelogOldver();
void GamelogSetting(const std::string &name, int32 oldval, int32 newval);
public:
Gamelog();
~Gamelog();
void GamelogGRFUpdate(const GRFConfig *oldg, const GRFConfig *newg);
void GamelogGRFAddList(const GRFConfig *newg);
void GamelogGRFRemove(uint32 grfid);
void GamelogGRFAdd(const GRFConfig *newg);
void GamelogGRFCompatible(const GRFIdentifier *newg);
void StartAction(GamelogActionType at);
void StopAction();
void StopAnyAction();
void GamelogTestRevision();
void GamelogTestMode();
void Reset();
bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id);
void Print(std::function<void(const char *)> proc);
void PrintDebug(int level);
void PrintConsole();
void GamelogInfo(struct LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs);
void Emergency();
bool TestEmergency();
void Revision();
void Mode();
void Oldver();
void Setting(const std::string &name, int32 oldval, int32 newval);
void GRFUpdate(const GRFConfig *oldg, const GRFConfig *newg);
void GRFAddList(const GRFConfig *newg);
void GRFRemove(uint32 grfid);
void GRFAdd(const GRFConfig *newg);
void GRFBug(uint32 grfid, byte bug, uint64 data);
bool GRFBugReverse(uint32 grfid, uint16 internal_id);
void GRFCompatible(const GRFIdentifier *newg);
void GRFMove(uint32 grfid, int32 offset);
void GRFParameters(uint32 grfid);
void TestRevision();
void TestMode();
void Info(uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs);
const GRFIdentifier *GetOverriddenIdentifier(const GRFConfig *c);
/* Saveload handler for gamelog needs access to internal data. */
friend struct GLOGChunkHandler;
};
extern Gamelog _gamelog;
#endif /* GAMELOG_H */