(svn r23606) -Add: GameScanner, to auto-detect game scripts, and wire it in the console

This commit is contained in:
truebrain
2011-12-19 20:55:56 +00:00
parent b4f832f29f
commit c99950c215
18 changed files with 608 additions and 11 deletions

View File

@@ -12,18 +12,26 @@
#include "../stdafx.h"
#include "../command_func.h"
#include "../core/backup_type.hpp"
#include "../core/bitmath_func.hpp"
#include "../company_base.h"
#include "../company_func.h"
#include "../network/network.h"
#include "../window_func.h"
#include "../fileio_func.h"
#include "game.hpp"
#include "game_scanner.hpp"
#include "game_config.hpp"
#include "game_instance.hpp"
/* static */ uint Game::frame_counter = 0;
/* static */ GameInfo *Game::info = NULL;
/* static */ GameInstance *Game::instance = NULL;
/* static */ GameScannerInfo *Game::scanner = NULL;
/* static */ void Game::GameLoop()
{
if (_networking && !_network_server) return;
if (Game::instance == NULL) return;
Game::frame_counter++;
@@ -40,25 +48,112 @@
/* static */ void Game::Initialize()
{
if (Game::instance != NULL) Game::Uninitialize();
if (Game::instance != NULL) Game::Uninitialize(true);
Game::frame_counter = 0;
if (Game::scanner == NULL) {
TarScanner::DoScan(TarScanner::GAME);
Game::scanner = new GameScannerInfo();
Game::scanner->Initialize();
}
if (Game::instance == NULL) {
/* Clients shouldn't start GameScripts */
if (_networking && !_network_server) return;
GameConfig *config = GameConfig::GetConfig();
GameInfo *info = config->GetInfo();
if (info == NULL) return;
Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
cur_company.Change(OWNER_DEITY);
Game::info = info;
Game::instance = new GameInstance();
Game::instance->Initialize();
Game::instance->Initialize(info);
cur_company.Restore();
InvalidateWindowData(WC_AI_DEBUG, 0, -1);
}
}
/* static */ void Game::Uninitialize()
/* static */ void Game::Uninitialize(bool keepConfig)
{
delete Game::instance;
Game::instance = NULL;
if (keepConfig) {
Rescan();
} else {
delete Game::scanner;
Game::scanner = NULL;
if (_settings_game.game_config != NULL) {
delete _settings_game.game_config;
_settings_game.game_config = NULL;
}
if (_settings_newgame.game_config != NULL) {
delete _settings_newgame.game_config;
_settings_newgame.game_config = NULL;
}
}
}
/* static */ void Game::ResetConfig()
{
/* Check for both newgame as current game if we can reload the GameInfo insde
* 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->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) {
delete Game::instance;
Game::instance = NULL;
}
} else if (Game::instance != NULL) {
Game::info = _settings_game.game_config->GetInfo();
}
}
if (_settings_newgame.game_config != NULL && _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);
}
}
}
/* static */ void Game::Rescan()
{
TarScanner::DoScan(TarScanner::GAME);
Game::scanner->RescanDir();
ResetConfig();
InvalidateWindowData(WC_AI_LIST, 0, 1);
SetWindowClassesDirty(WC_AI_DEBUG);
SetWindowDirty(WC_AI_SETTINGS, 0);
}
/* static */ char *Game::GetConsoleList(char *p, const char *last, bool newest_only)
{
return Game::scanner->GetConsoleList(p, last, newest_only);
}
/* static */ const ScriptInfoList *Game::GetInfoList()
{
return Game::scanner->GetInfoList();
}
/* static */ const ScriptInfoList *Game::GetUniqueInfoList()
{
return Game::scanner->GetUniqueInfoList();
}
/* static */ GameInfo *Game::FindInfo(const char *name, int version, bool force_exact_match)
{
return Game::scanner->FindInfo(name, version, force_exact_match);
}