OpenTTD Source 20260218-master-g2123fca5ea
game.hpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef GAME_HPP
11#define GAME_HPP
12
13#include "game_scanner.hpp"
14
15#include "../script/api/script_event_types.hpp"
16
20class Game {
21public:
25 static void GameLoop();
26
30 static void Initialize();
31
35 static void StartNew();
36
41 static void Uninitialize(bool keepConfig);
42
48 static void Pause();
49
55 static void Unpause();
56
61 static bool IsPaused();
62
67 static void NewEvent(class ScriptEvent *event);
68
73 static class GameInfo *GetInfo() { return Game::info; }
74
79 static void Rescan();
80
85 static void ResetConfig();
86
90 static void Save();
91
93 static void GetConsoleList(std::back_insert_iterator<std::string> &output_iterator, bool newest_only);
95 static void GetConsoleLibraryList(std::back_insert_iterator<std::string> &output_iterator, bool newest_only);
97 static const ScriptInfoList *GetInfoList();
99 static const ScriptInfoList *GetUniqueInfoList();
101 static class GameInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
103 static class GameLibrary *FindLibrary(const std::string &library, int version);
104
109 static class GameInstance *GetInstance() { return Game::instance.get(); }
110
114 static void ResetInstance();
115
117 static bool HasGame(const ContentInfo &ci, bool md5sum);
118 static bool HasGameLibrary(const ContentInfo &ci, bool md5sum);
123
124private:
125 static uint frame_counter;
126 static std::unique_ptr<GameInstance> instance;
127 static std::unique_ptr<GameScannerInfo> scanner_info;
128 static std::unique_ptr<GameScannerLibrary> scanner_library;
129 static GameInfo *info;
130};
131
132#endif /* GAME_HPP */
All static information from an Game like name, version, etc.
Definition game_info.hpp:16
Runtime information about a game script like a pointer to the squirrel vm and the current state.
All static information from an Game library like name, version, etc.
Definition game_info.hpp:58
Game instantiation of a ScriptScanner.
Game instantiation of a ScriptScanner for libraries.
Main Game class.
Definition game.hpp:20
static void StartNew()
Start up a new GameScript.
Definition game_core.cpp:72
static GameInfo * info
Current selected GameInfo.
Definition game.hpp:129
static bool HasGameLibrary(const ContentInfo &ci, bool md5sum)
Check whether we have an Game library with the exact characteristics as ci.
static class GameInfo * FindInfo(const std::string &name, int version, bool force_exact_match)
Finds the appropriate ScriptInfo for a given script name and version.
static class GameInfo * GetInfo()
Get the current GameInfo.
Definition game.hpp:73
static bool HasGame(const ContentInfo &ci, bool md5sum)
Wrapper function for GameScanner::HasGame.
static GameScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find Game Libraries.
static void ResetConfig()
Reset all GameConfigs, and make them reload their GameInfo.
static void Unpause()
Resume execution of the Game Script.
static bool IsPaused()
Checks if the Game Script is paused.
static uint frame_counter
Tick counter for the Game code.
Definition game.hpp:125
static std::unique_ptr< GameInstance > instance
Instance to the current active Game.
Definition game.hpp:126
static void Save()
Save data from a GameScript to a savegame.
static void Rescan()
Rescans all searchpaths for available Game scripts.
static void ResetInstance()
Reset the current active instance.
static class GameLibrary * FindLibrary(const std::string &library, int version)
Find a library.
static void GetConsoleLibraryList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Get the list of registered scripts to print on the console.
static const ScriptInfoList * GetUniqueInfoList()
Get the list of the latest version of all registered scripts.
static void Pause()
Suspends the Game Script and then pause the execution of the script.
static void NewEvent(class ScriptEvent *event)
Queue a new event for the game script.
static class GameInstance * GetInstance()
Get the current active instance.
Definition game.hpp:109
static void GameLoop()
Called every game-tick to let Game do something.
Definition game_core.cpp:31
static void GetConsoleList(std::back_insert_iterator< std::string > &output_iterator, bool newest_only)
Get the list of registered scripts to print on the console.
static void Uninitialize(bool keepConfig)
Uninitialize the Game system.
static std::unique_ptr< GameScannerInfo > scanner_info
Scanner for Game scripts.
Definition game.hpp:127
static const ScriptInfoList * GetInfoList()
Get the list of all registered scripts.
static void Initialize()
Initialize the Game system.
Definition game_core.cpp:57
static std::unique_ptr< GameScannerLibrary > scanner_library
Scanner for GS Libraries.
Definition game.hpp:128
static GameScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find Game scripts.
Declarations of the class for GS scanner.
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
Container for all important information about a piece of content.