mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r23611) -Add: run the begin of the script already while generating, and don't sleep on DoCommand while doing so
This commit is contained in:
parent
cbe43abe5d
commit
83f2785f54
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue