diff options
author | truebrain <truebrain@openttd.org> | 2011-12-19 20:56:50 +0000 |
---|---|---|
committer | truebrain <truebrain@openttd.org> | 2011-12-19 20:56:50 +0000 |
commit | 83f2785f54de1c31267c5586464c97fb39f95b5a (patch) | |
tree | de073b47921321433fc0945bd63bc9c07d4a1f33 /src | |
parent | cbe43abe5db481568ccf988dbe994f43a985efbd (diff) | |
download | openttd-83f2785f54de1c31267c5586464c97fb39f95b5a.tar.xz |
(svn r23611) -Add: run the begin of the script already while generating, and don't sleep on DoCommand while doing so
Diffstat (limited to 'src')
-rw-r--r-- | src/command.cpp | 2 | ||||
-rw-r--r-- | src/genworld.cpp | 12 | ||||
-rw-r--r-- | src/genworld.h | 1 | ||||
-rw-r--r-- | src/genworld_gui.cpp | 3 | ||||
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/script/api/script_object.cpp | 9 | ||||
-rw-r--r-- | src/script/script_instance.hpp | 6 |
7 files changed, 30 insertions, 4 deletions
diff --git a/src/command.cpp b/src/command.cpp index f2bf49c13..acc5c6756 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -658,7 +658,7 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, * If we are in network, and the command is not from the network * send it to the command-queue and abort execution */ - if (_networking && !(cmd & CMD_NETWORK_COMMAND)) { + if (_networking && !_generating_world && !(cmd & CMD_NETWORK_COMMAND)) { NetworkSendCommand(tile, p1, p2, cmd & ~CMD_FLAGS_MASK, callback, text, _current_company); cur_company.Restore(); diff --git a/src/genworld.cpp b/src/genworld.cpp index f36837879..ca4f1ef6f 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -34,6 +34,7 @@ #include "progress.h" #include "error.h" #include "game/game.hpp" +#include "game/game_instance.hpp" #include "table/sprites.h" @@ -166,6 +167,17 @@ static void _GenerateWorld(void *) if (_game_mode != GM_EDITOR) { Game::StartNew(); + + if (Game::GetInstance() != NULL) { + SetGeneratingWorldProgress(GWP_RUNSCRIPT, 2500); + _generating_world = true; + for (i = 0; i < 2500; i++) { + Game::GameLoop(); + IncreaseGeneratingWorldProgress(GWP_RUNSCRIPT); + if (Game::GetInstance()->IsSleeping()) break; + } + _generating_world = false; + } } } diff --git a/src/genworld.h b/src/genworld.h index 4814e7d8b..267335423 100644 --- a/src/genworld.h +++ b/src/genworld.h @@ -65,6 +65,7 @@ enum GenWorldProgress { GWP_TREE, ///< Generate trees GWP_GAME_INIT, ///< Initialize the game GWP_RUNTILELOOP, ///< Runs the tile loop 1280 times to make snow etc + GWP_RUNSCRIPT, ///< Runs the game script at most 2500 times, or when ever the script sleeps GWP_GAME_START, ///< Really prepare to start the game GWP_CLASS_COUNT }; diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 8ee5f6c6b..05b0e7a80 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -1169,6 +1169,7 @@ static const StringID _generation_class_table[] = { STR_GENERATION_TREE_GENERATION, STR_GENERATION_SETTINGUP_GAME, STR_GENERATION_PREPARING_TILELOOP, + STR_GENERATION_PREPARING_SCRIPT, STR_GENERATION_PREPARING_GAME }; assert_compile(lengthof(_generation_class_table) == GWP_CLASS_COUNT); @@ -1272,7 +1273,7 @@ void ShowGenerateWorldProgress() static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total) { - static const int percent_table[] = {0, 5, 14, 17, 20, 40, 60, 65, 80, 85, 99, 100 }; + static const int percent_table[] = {0, 5, 14, 17, 20, 40, 60, 65, 80, 85, 95, 99, 100 }; assert_compile(lengthof(percent_table) == GWP_CLASS_COUNT + 1); assert(cls < GWP_CLASS_COUNT); diff --git a/src/lang/english.txt b/src/lang/english.txt index a044d5b39..d50228701 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2413,6 +2413,7 @@ STR_GENERATION_OBJECT_GENERATION :{BLACK}Object g STR_GENERATION_CLEARING_TILES :{BLACK}Rough and rocky area generation STR_GENERATION_SETTINGUP_GAME :{BLACK}Setting up game STR_GENERATION_PREPARING_TILELOOP :{BLACK}Running tile-loop +STR_GENERATION_PREPARING_SCRIPT :{BLACK}Running script STR_GENERATION_PREPARING_GAME :{BLACK}Preparing game # NewGRF settings diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index 1dd431d80..d9a432b44 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -15,6 +15,7 @@ #include "../../company_func.h" #include "../../network/network.h" #include "../../tunnelbridge.h" +#include "../../genworld.h" #include "../script_storage.hpp" #include "../script_instance.hpp" @@ -233,7 +234,7 @@ ScriptObject::ActiveInstance::~ActiveInstance() #endif /* Try to perform the command. */ - CommandCost res = ::DoCommandPInternal(tile, p1, p2, cmd, _networking ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : NULL, text, false, estimate_only); + CommandCost res = ::DoCommandPInternal(tile, p1, p2, cmd, (_networking && !_generating_world) ? ScriptObject::GetActiveInstance()->GetDoCommandCallback() : NULL, text, false, estimate_only); /* We failed; set the error and bail out */ if (res.Failed()) { @@ -254,7 +255,11 @@ ScriptObject::ActiveInstance::~ActiveInstance() SetLastCost(res.GetCost()); SetLastCommandRes(true); - if (_networking) { + if (_generating_world) { + IncreaseDoCommandCosts(res.GetCost()); + if (callback != NULL) callback(GetActiveInstance()); + return true; + } else if (_networking) { /* Suspend the AI till the command is really executed. */ throw Script_Suspend(-(int)GetDoCommandDelay(), callback); } else { diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp index 8aa85744c..e7a23ccd9 100644 --- a/src/script/script_instance.hpp +++ b/src/script/script_instance.hpp @@ -159,6 +159,12 @@ public: */ void InsertEvent(class ScriptEvent *event); + /** + * Check if the instance is sleeping, which either happened because the + * script executed a DoCommand, or executed this.Sleep(). + */ + bool IsSleeping() { return this->suspend != 0; } + protected: class Squirrel *engine; ///< A wrapper around the squirrel vm. |