From 12aa5b6a583aa7ca9092ec6c77e7b12677cdd6a4 Mon Sep 17 00:00:00 2001 From: truebrain Date: Mon, 19 Dec 2011 20:50:54 +0000 Subject: (svn r23604) -Add: initial support for GameScripts --- src/game/game_core.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/game/game_core.cpp (limited to 'src/game/game_core.cpp') diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp new file mode 100644 index 000000000..7894ab2a6 --- /dev/null +++ b/src/game/game_core.cpp @@ -0,0 +1,64 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * 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. + * 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. + * 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 . + */ + +/** @file game_core.cpp Implementation of Game. */ + +#include "../stdafx.h" +#include "../command_func.h" +#include "../core/backup_type.hpp" +#include "../company_base.h" +#include "../company_func.h" +#include "../network/network.h" +#include "game.hpp" +#include "game_instance.hpp" + +/* static */ uint Game::frame_counter = 0; +/* static */ GameInstance *Game::instance = NULL; + +/* static */ void Game::GameLoop() +{ + if (_networking && !_network_server) return; + + Game::frame_counter++; + + Backup cur_company(_current_company, FILE_LINE); + cur_company.Change(OWNER_DEITY); + Game::instance->GameLoop(); + cur_company.Restore(); + + /* Occasionally collect garbage */ + if ((Game::frame_counter & 255) == 0) { + Game::instance->CollectGarbage(); + } +} + +/* static */ void Game::Initialize() +{ + if (Game::instance != NULL) Game::Uninitialize(); + + Game::frame_counter = 0; + if (Game::instance == NULL) { + /* Clients shouldn't start GameScripts */ + if (_networking && !_network_server) return; + + Backup cur_company(_current_company, FILE_LINE); + cur_company.Change(OWNER_DEITY); + + Game::instance = new GameInstance(); + Game::instance->Initialize(); + + cur_company.Restore(); + } +} + +/* static */ void Game::Uninitialize() +{ + delete Game::instance; + Game::instance = NULL; +} -- cgit v1.2.3-70-g09d2