Changeset - r11333:7fe1ca4e3964
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-03-12 14:28:55
rubidium@openttd.org
(svn r15688) -Codechange: unifiy cleaning up the map generation (normal and abort)
1 file changed with 22 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/genworld.cpp
Show inline comments
 
@@ -74,24 +74,44 @@ bool IsGeneratingWorldReadyForPaint()
 
	return _gw.wait_for_draw;
 
}
 

	
 
/**
 
 * Tells if the world generation is done in a thread or not.
 
 */
 
bool IsGenerateWorldThreaded()
 
{
 
	return _gw.threaded && !_gw.quit_thread;
 
}
 

	
 
/**
 
 * Clean up the 'mess' of generation. That is show windows again, reset
 
 * thread variables and delete the progress window.
 
 */
 
static void CleanupGeneration()
 
{
 
	_generating_world = false;
 

	
 
	if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
 
	/* Show all vital windows again, because we have hidden them */
 
	if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
 
	_gw.active   = false;
 
	_gw.proc     = NULL;
 
	_gw.abortp   = NULL;
 
	_gw.threaded = false;
 

	
 
	DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
 
	MarkWholeScreenDirty();
 
}
 

	
 
/**
 
 * The internal, real, generate function.
 
 */
 
static void _GenerateWorld(void *arg)
 
{
 
	try {
 
		_generating_world = true;
 
		if (_network_dedicated) DEBUG(net, 0, "Generating map, please wait...");
 
		/* Set the Random() seed to generation_seed so we produce the same map with the same seed */
 
		if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = _settings_newgame.game_creation.generation_seed = InteractiveRandom();
 
		_random.SetSeed(_settings_game.game_creation.generation_seed);
 
		SetGeneratingWorldProgress(GWP_MAP_INIT, 2);
 
		SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
 
@@ -149,33 +169,25 @@ static void _GenerateWorld(void *arg)
 
				IncreaseGeneratingWorldProgress(GWP_RUNTILELOOP);
 
			}
 
		}
 

	
 
		ResetObjectToPlace();
 
		_local_company = _gw.lc;
 

	
 
		SetGeneratingWorldProgress(GWP_GAME_START, 1);
 
		/* Call any callback */
 
		if (_gw.proc != NULL) _gw.proc();
 
		IncreaseGeneratingWorldProgress(GWP_GAME_START);
 

	
 
		if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
 
		/* Show all vital windows again, because we have hidden them */
 
		if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
 
		_gw.active   = false;
 
		_gw.proc     = NULL;
 
		_gw.threaded = false;
 

	
 
		DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
 
		MarkWholeScreenDirty();
 
		CleanupGeneration();
 

	
 
		if (_network_dedicated) DEBUG(net, 0, "Map generated, starting game");
 
		DEBUG(desync, 1, "new_map: %i\n", _settings_game.game_creation.generation_seed);
 

	
 
		if (_settings_client.gui.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, CMD_PAUSE);
 
		if (_debug_desync_level > 0) {
 
			char name[MAX_PATH];
 
			snprintf(name, lengthof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
 
			SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR);
 
		}
 
	} catch (...) {
 
		_generating_world = false;
 
@@ -232,35 +244,25 @@ bool IsGeneratingWorldAborted()
 
}
 

	
 
/**
 
 * Really handle the abortion, i.e. clean up some of the mess
 
 */
 
void HandleGeneratingWorldAbortion()
 
{
 
	/* Clean up - in SE create an empty map, otherwise, go to intro menu */
 
	_switch_mode = (_game_mode == GM_EDITOR) ? SM_EDITOR : SM_MENU;
 

	
 
	if (_gw.abortp != NULL) _gw.abortp();
 

	
 
	if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
 
	/* Show all vital windows again, because we have hidden them */
 
	if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
 

	
 
	_gw.active   = false;
 
	_gw.proc     = NULL;
 
	_gw.abortp   = NULL;
 
	_gw.threaded = false;
 

	
 
	DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
 
	MarkWholeScreenDirty();
 
	CleanupGeneration();
 

	
 
	_gw.thread->Exit();
 
}
 

	
 
/**
 
 * Generate a world.
 
 * @param mode The mode of world generation (see GenerateWorldModes).
 
 * @param size_x The X-size of the map.
 
 * @param size_y The Y-size of the map.
 
 */
 
void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y)
 
{
0 comments (0 inline, 0 general)