diff options
author | Henry Wilson <m3henry@googlemail.com> | 2019-04-10 22:07:06 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-10 23:22:20 +0200 |
commit | 7c8e7c6b6e16d4a26259a676db32d8776b99817e (patch) | |
tree | 99f134b7e66367cf11e10bc5061896eab4a3264f /src/game | |
parent | 3b4f224c0bc50e7248050d4bcbb6d83fd510c1cc (diff) | |
download | openttd-7c8e7c6b6e16d4a26259a676db32d8776b99817e.tar.xz |
Codechange: Use null pointer literal instead of the NULL macro
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/game_config.cpp | 4 | ||||
-rw-r--r-- | src/game/game_core.cpp | 62 | ||||
-rw-r--r-- | src/game/game_info.cpp | 8 | ||||
-rw-r--r-- | src/game/game_info.hpp | 2 | ||||
-rw-r--r-- | src/game/game_instance.cpp | 4 | ||||
-rw-r--r-- | src/game/game_scanner.cpp | 10 | ||||
-rw-r--r-- | src/game/game_scanner.hpp | 4 | ||||
-rw-r--r-- | src/game/game_text.cpp | 40 | ||||
-rw-r--r-- | src/game/game_text.hpp | 2 |
9 files changed, 68 insertions, 68 deletions
diff --git a/src/game/game_config.cpp b/src/game/game_config.cpp index 50cd5da4e..f96985ef7 100644 --- a/src/game/game_config.cpp +++ b/src/game/game_config.cpp @@ -25,7 +25,7 @@ } else { config = &_settings_game.game_config; } - if (*config == NULL) *config = new GameConfig(); + if (*config == nullptr) *config = new GameConfig(); return *config; } @@ -42,5 +42,5 @@ ScriptInfo *GameConfig::FindInfo(const char *name, int version, bool force_exact bool GameConfig::ResetInfo(bool force_exact_match) { this->info = (ScriptInfo *)Game::FindInfo(this->name, force_exact_match ? this->version : -1, force_exact_match); - return this->info != NULL; + return this->info != nullptr; } diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp index 7b05abb40..181e8b6bb 100644 --- a/src/game/game_core.cpp +++ b/src/game/game_core.cpp @@ -25,10 +25,10 @@ #include "../safeguards.h" /* static */ uint Game::frame_counter = 0; -/* static */ GameInfo *Game::info = NULL; -/* static */ GameInstance *Game::instance = NULL; -/* static */ GameScannerInfo *Game::scanner_info = NULL; -/* static */ GameScannerLibrary *Game::scanner_library = NULL; +/* static */ GameInfo *Game::info = nullptr; +/* static */ GameInstance *Game::instance = nullptr; +/* static */ GameScannerInfo *Game::scanner_info = nullptr; +/* static */ GameScannerLibrary *Game::scanner_library = nullptr; /* static */ void Game::GameLoop() { @@ -36,7 +36,7 @@ PerformanceMeasurer::SetInactive(PFE_GAMESCRIPT); return; } - if (Game::instance == NULL) { + if (Game::instance == nullptr) { PerformanceMeasurer::SetInactive(PFE_GAMESCRIPT); return; } @@ -58,11 +58,11 @@ /* static */ void Game::Initialize() { - if (Game::instance != NULL) Game::Uninitialize(true); + if (Game::instance != nullptr) Game::Uninitialize(true); Game::frame_counter = 0; - if (Game::scanner_info == NULL) { + if (Game::scanner_info == nullptr) { TarScanner::DoScan(TarScanner::GAME); Game::scanner_info = new GameScannerInfo(); Game::scanner_info->Initialize(); @@ -73,14 +73,14 @@ /* static */ void Game::StartNew() { - if (Game::instance != NULL) return; + if (Game::instance != nullptr) return; /* Clients shouldn't start GameScripts */ if (_networking && !_network_server) return; GameConfig *config = GameConfig::GetConfig(GameConfig::SSS_FORCE_GAME); GameInfo *info = config->GetInfo(); - if (info == NULL) return; + if (info == nullptr) return; config->AnchorUnchangeableSettings(); @@ -101,8 +101,8 @@ Backup<CompanyByte> cur_company(_current_company, FILE_LINE); delete Game::instance; - Game::instance = NULL; - Game::info = NULL; + Game::instance = nullptr; + Game::info = nullptr; cur_company.Restore(); @@ -111,33 +111,33 @@ } else { delete Game::scanner_info; delete Game::scanner_library; - Game::scanner_info = NULL; - Game::scanner_library = NULL; + Game::scanner_info = nullptr; + Game::scanner_library = nullptr; - if (_settings_game.game_config != NULL) { + if (_settings_game.game_config != nullptr) { delete _settings_game.game_config; - _settings_game.game_config = NULL; + _settings_game.game_config = nullptr; } - if (_settings_newgame.game_config != NULL) { + if (_settings_newgame.game_config != nullptr) { delete _settings_newgame.game_config; - _settings_newgame.game_config = NULL; + _settings_newgame.game_config = nullptr; } } } /* static */ void Game::Pause() { - if (Game::instance != NULL) Game::instance->Pause(); + if (Game::instance != nullptr) Game::instance->Pause(); } /* static */ void Game::Unpause() { - if (Game::instance != NULL) Game::instance->Unpause(); + if (Game::instance != nullptr) Game::instance->Unpause(); } /* static */ bool Game::IsPaused() { - return Game::instance != NULL? Game::instance->IsPaused() : false; + return Game::instance != nullptr? Game::instance->IsPaused() : false; } /* static */ void Game::NewEvent(ScriptEvent *event) @@ -152,7 +152,7 @@ } /* Check if Game instance is alive */ - if (Game::instance == NULL) { + if (Game::instance == nullptr) { event->Release(); return; } @@ -169,23 +169,23 @@ { /* Check for both newgame as current game if we can reload the GameInfo inside * the GameConfig. If not, remove the Game from the list. */ - if (_settings_game.game_config != NULL && _settings_game.game_config->HasScript()) { + if (_settings_game.game_config != nullptr && _settings_game.game_config->HasScript()) { if (!_settings_game.game_config->ResetInfo(true)) { DEBUG(script, 0, "After a reload, the GameScript by the name '%s' was no longer found, and removed from the list.", _settings_game.game_config->GetName()); - _settings_game.game_config->Change(NULL); - if (Game::instance != NULL) { + _settings_game.game_config->Change(nullptr); + if (Game::instance != nullptr) { delete Game::instance; - Game::instance = NULL; - Game::info = NULL; + Game::instance = nullptr; + Game::info = nullptr; } - } else if (Game::instance != NULL) { + } else if (Game::instance != nullptr) { Game::info = _settings_game.game_config->GetInfo(); } } - if (_settings_newgame.game_config != NULL && _settings_newgame.game_config->HasScript()) { + if (_settings_newgame.game_config != nullptr && _settings_newgame.game_config->HasScript()) { if (!_settings_newgame.game_config->ResetInfo(false)) { DEBUG(script, 0, "After a reload, the GameScript by the name '%s' was no longer found, and removed from the list.", _settings_newgame.game_config->GetName()); - _settings_newgame.game_config->Change(NULL); + _settings_newgame.game_config->Change(nullptr); } } } @@ -206,7 +206,7 @@ /* static */ void Game::Save() { - if (Game::instance != NULL && (!_networking || _network_server)) { + if (Game::instance != nullptr && (!_networking || _network_server)) { Backup<CompanyByte> cur_company(_current_company, OWNER_DEITY, FILE_LINE); Game::instance->Save(); cur_company.Restore(); @@ -217,7 +217,7 @@ /* static */ void Game::Load(int version) { - if (Game::instance != NULL && (!_networking || _network_server)) { + if (Game::instance != nullptr && (!_networking || _network_server)) { Backup<CompanyByte> cur_company(_current_company, OWNER_DEITY, FILE_LINE); Game::instance->Load(version); cur_company.Restore(); diff --git a/src/game/game_info.cpp b/src/game/game_info.cpp index 0aa316174..d815e6fd2 100644 --- a/src/game/game_info.cpp +++ b/src/game/game_info.cpp @@ -55,8 +55,8 @@ template <> const char *GetClassName<GameInfo, ST_GS>() { return "GSInfo"; } /* static */ SQInteger GameInfo::Constructor(HSQUIRRELVM vm) { /* Get the GameInfo */ - SQUserPointer instance = NULL; - if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == NULL) return sq_throwerror(vm, "Pass an instance of a child class of GameInfo to RegisterGame"); + SQUserPointer instance = nullptr; + if (SQ_FAILED(sq_getinstanceup(vm, 2, &instance, 0)) || instance == nullptr) return sq_throwerror(vm, "Pass an instance of a child class of GameInfo to RegisterGame"); GameInfo *info = (GameInfo *)instance; SQInteger res = ScriptInfo::Constructor(vm, info); @@ -82,7 +82,7 @@ template <> const char *GetClassName<GameInfo, ST_GS>() { return "GSInfo"; } } /* Remove the link to the real instance, else it might get deleted by RegisterGame() */ - sq_setinstanceup(vm, 2, NULL); + sq_setinstanceup(vm, 2, nullptr); /* Register the Game to the base system */ info->GetScanner()->RegisterScript(info); return 0; @@ -91,7 +91,7 @@ template <> const char *GetClassName<GameInfo, ST_GS>() { return "GSInfo"; } GameInfo::GameInfo() : min_loadable_version(0), is_developer_only(false), - api_version(NULL) + api_version(nullptr) { } diff --git a/src/game/game_info.hpp b/src/game/game_info.hpp index a799ed7d6..8a2215d52 100644 --- a/src/game/game_info.hpp +++ b/src/game/game_info.hpp @@ -51,7 +51,7 @@ private: /** All static information from an Game library like name, version, etc. */ class GameLibrary : public ScriptInfo { public: - GameLibrary() : ScriptInfo(), category(NULL) {}; + GameLibrary() : ScriptInfo(), category(nullptr) {}; ~GameLibrary(); /** diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp index e2b377511..26a61a790 100644 --- a/src/game/game_instance.cpp +++ b/src/game/game_instance.cpp @@ -239,10 +239,10 @@ void GameInstance::Died() ShowAIDebugWindow(OWNER_DEITY); const GameInfo *info = Game::GetInfo(); - if (info != NULL) { + if (info != nullptr) { ShowErrorMessage(STR_ERROR_AI_PLEASE_REPORT_CRASH, INVALID_STRING_ID, WL_WARNING); - if (info->GetURL() != NULL) { + if (info->GetURL() != nullptr) { ScriptLog::Info("Please report the error to the following URL:"); ScriptLog::Info(info->GetURL()); } diff --git a/src/game/game_scanner.cpp b/src/game/game_scanner.cpp index 38afdd135..862c867cf 100644 --- a/src/game/game_scanner.cpp +++ b/src/game/game_scanner.cpp @@ -35,14 +35,14 @@ void GameScannerInfo::RegisterAPI(class Squirrel *engine) GameInfo *GameScannerInfo::FindInfo(const char *nameParam, int versionParam, bool force_exact_match) { - if (this->info_list.size() == 0) return NULL; - if (nameParam == NULL) return NULL; + if (this->info_list.size() == 0) return nullptr; + if (nameParam == nullptr) return nullptr; char game_name[1024]; strecpy(game_name, nameParam, lastof(game_name)); strtolower(game_name); - GameInfo *info = NULL; + GameInfo *info = nullptr; int version = -1; if (versionParam == -1) { @@ -51,7 +51,7 @@ GameInfo *GameScannerInfo::FindInfo(const char *nameParam, int versionParam, boo /* If we didn't find a match Game script, maybe the user included a version */ char *e = strrchr(game_name, '.'); - if (e == NULL) return NULL; + if (e == nullptr) return nullptr; *e = '\0'; e++; versionParam = atoi(e); @@ -106,7 +106,7 @@ GameLibrary *GameScannerLibrary::FindLibrary(const char *library, int version) /* Check if the library + version exists */ ScriptInfoList::iterator iter = this->info_list.find(library_name); - if (iter == this->info_list.end()) return NULL; + if (iter == this->info_list.end()) return nullptr; return static_cast<GameLibrary *>((*iter).second); } diff --git a/src/game/game_scanner.hpp b/src/game/game_scanner.hpp index 492545c2b..2530ec792 100644 --- a/src/game/game_scanner.hpp +++ b/src/game/game_scanner.hpp @@ -23,7 +23,7 @@ public: * @param nameParam The name of the game script. * @param versionParam The version of the game script, or -1 if you want the latest. * @param force_exact_match Only match name+version, never latest. - * @return NULL if no match found, otherwise the game script that matched. + * @return nullptr if no match found, otherwise the game script that matched. */ class GameInfo *FindInfo(const char *nameParam, int versionParam, bool force_exact_match); @@ -44,7 +44,7 @@ public: * Find a library in the pool. * @param library The library name to find. * @param version The version the library should have. - * @return The library if found, NULL otherwise. + * @return The library if found, nullptr otherwise. */ class GameLibrary *FindLibrary(const char *library, int version); diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp index 944bf82d1..bde2a5a69 100644 --- a/src/game/game_text.cpp +++ b/src/game/game_text.cpp @@ -63,11 +63,11 @@ void NORETURN CDECL strgen_fatal(const char *s, ...) /** * Create a new container for language strings. * @param language The language name. - * @param end If not NULL, terminate \a language at this position. + * @param end If not nullptr, terminate \a language at this position. */ LanguageStrings::LanguageStrings(const char *language, const char *end) { - this->language = stredup(language, end != NULL ? end - 1 : NULL); + this->language = stredup(language, end != nullptr ? end - 1 : nullptr); } /** Free everything. */ @@ -79,31 +79,31 @@ LanguageStrings::~LanguageStrings() /** * Read all the raw language strings from the given file. * @param file The file to read from. - * @return The raw strings, or NULL upon error. + * @return The raw strings, or nullptr upon error. */ std::unique_ptr<LanguageStrings> ReadRawLanguageStrings(const char *file) { try { size_t to_read; FILE *fh = FioFOpenFile(file, "rb", GAME_DIR, &to_read); - if (fh == NULL) return NULL; + if (fh == nullptr) return nullptr; FileCloser fhClose(fh); const char *langname = strrchr(file, PATHSEPCHAR); - if (langname == NULL) { + if (langname == nullptr) { langname = file; } else { langname++; } /* Check for invalid empty filename */ - if (*langname == '.' || *langname == 0) return NULL; + if (*langname == '.' || *langname == 0) return nullptr; std::unique_ptr<LanguageStrings> ret(new LanguageStrings(langname, strchr(langname, '.'))); char buffer[2048]; - while (to_read != 0 && fgets(buffer, sizeof(buffer), fh) != NULL) { + while (to_read != 0 && fgets(buffer, sizeof(buffer), fh) != nullptr) { size_t len = strlen(buffer); /* Remove trailing spaces/newlines from the string. */ @@ -122,7 +122,7 @@ std::unique_ptr<LanguageStrings> ReadRawLanguageStrings(const char *file) return ret; } catch (...) { - return NULL; + return nullptr; } } @@ -146,7 +146,7 @@ struct StringListReader : StringReader { char *ReadLine(char *buffer, const char *last) override { - if (this->p == this->end) return NULL; + if (this->p == this->end) return nullptr; strecpy(buffer, this->p->c_str(), last); this->p++; @@ -237,7 +237,7 @@ public: if (strcmp(filename, exclude) == 0) return true; auto ls = ReadRawLanguageStrings(filename); - if (ls == NULL) return false; + if (ls == nullptr) return false; gs->raw_strings.push_back(std::move(ls)); return true; @@ -254,14 +254,14 @@ GameStrings *LoadTranslations() char filename[512]; strecpy(filename, info->GetMainScript(), lastof(filename)); char *e = strrchr(filename, PATHSEPCHAR); - if (e == NULL) return NULL; + if (e == nullptr) return nullptr; e++; // Make 'e' point after the PATHSEPCHAR strecpy(e, "lang" PATHSEP "english.txt", lastof(filename)); - if (!FioCheckFileExists(filename, GAME_DIR)) return NULL; + if (!FioCheckFileExists(filename, GAME_DIR)) return nullptr; auto ls = ReadRawLanguageStrings(filename); - if (ls == NULL) return NULL; + if (ls == nullptr) return nullptr; GameStrings *gs = new GameStrings(); try { @@ -274,7 +274,7 @@ GameStrings *LoadTranslations() const char *tar_filename = info->GetTarFile(); TarList::iterator iter; - if (tar_filename != NULL && (iter = _tar_list[GAME_DIR].find(tar_filename)) != _tar_list[GAME_DIR].end()) { + if (tar_filename != nullptr && (iter = _tar_list[GAME_DIR].find(tar_filename)) != _tar_list[GAME_DIR].end()) { /* The main script is in a tar file, so find all files that * are in the same tar and add them to the langfile scanner. */ TarFileList::iterator tar; @@ -297,7 +297,7 @@ GameStrings *LoadTranslations() return gs; } catch (...) { delete gs; - return NULL; + return nullptr; } } @@ -327,7 +327,7 @@ void GameStrings::Compile() } /** The currently loaded game strings. */ -GameStrings *_current_data = NULL; +GameStrings *_current_data = nullptr; /** * Get the string pointer of a particular game string. @@ -348,7 +348,7 @@ void RegisterGameTranslation(Squirrel *engine) { delete _current_data; _current_data = LoadTranslations(); - if (_current_data == NULL) return; + if (_current_data == nullptr) return; HSQUIRRELVM vm = engine->GetVM(); sq_pushroottable(vm); @@ -373,19 +373,19 @@ void RegisterGameTranslation(Squirrel *engine) */ void ReconsiderGameScriptLanguage() { - if (_current_data == NULL) return; + if (_current_data == nullptr) return; char temp[MAX_PATH]; strecpy(temp, _current_language->file, lastof(temp)); /* Remove the extension */ char *l = strrchr(temp, '.'); - assert(l != NULL); + assert(l != nullptr); *l = '\0'; /* Skip the path */ char *language = strrchr(temp, PATHSEPCHAR); - assert(language != NULL); + assert(language != nullptr); language++; for (auto &p : _current_data->compiled_strings) { diff --git a/src/game/game_text.hpp b/src/game/game_text.hpp index d199a5281..c662e28f4 100644 --- a/src/game/game_text.hpp +++ b/src/game/game_text.hpp @@ -23,7 +23,7 @@ struct LanguageStrings { const char *language; ///< Name of the language (base filename). StringList lines; ///< The lines of the file to pass into the parser/encoder. - LanguageStrings(const char *language, const char *end = NULL); + LanguageStrings(const char *language, const char *end = nullptr); ~LanguageStrings(); }; |