(svn r18853) -Codechange: apply coding style to GenWorld's enums, structs and typedefs

This commit is contained in:
smatz 2010-01-17 22:59:24 +00:00
parent a271ef214b
commit 11e3a00a23
5 changed files with 67 additions and 67 deletions

View File

@ -48,11 +48,11 @@ void StartupDisasters();
void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings);
/* Please only use this variable in genworld.h and genworld.c and
/* Please only use this variable in genworld.h and genworld.cpp and
* nowhere else. For speed improvements we need it to be global, but
* in no way the meaning of it is to use it anywhere else besides
* in the genworld.h and genworld.c! -- TrueLight */
gw_info _gw;
* in the genworld.h and genworld.cpp! -- TrueLight */
GenWorldInfo _gw;
/** Rights for the map generation */
ThreadMutex *_genworld_mapgen_mutex = ThreadMutex::New();
@ -108,7 +108,7 @@ static void _GenerateWorld(void *arg)
StartupEconomy();
/* Don't generate landscape items when in the scenario editor. */
if (_gw.mode == GW_EMPTY) {
if (_gw.mode == GWM_EMPTY) {
SetGeneratingWorldProgress(GWP_UNMOVABLE, 1);
/* Make sure the tiles at the north border are void tiles if needed. */
@ -150,7 +150,7 @@ static void _GenerateWorld(void *arg)
_generating_world = false;
/* No need to run the tile loop in the scenario editor. */
if (_gw.mode != GW_EMPTY) {
if (_gw.mode != GWM_EMPTY) {
uint i;
SetGeneratingWorldProgress(GWP_RUNTILELOOP, 0x500);
@ -192,7 +192,7 @@ static void _GenerateWorld(void *arg)
* Set here the function, if any, that you want to be called when landscape
* generation is done.
*/
void GenerateWorldSetCallback(gw_done_proc *proc)
void GenerateWorldSetCallback(GWDoneProc *proc)
{
_gw.proc = proc;
}
@ -201,7 +201,7 @@ void GenerateWorldSetCallback(gw_done_proc *proc)
* Set here the function, if any, that you want to be called when landscape
* generation is aborted.
*/
void GenerateWorldSetAbortCallback(gw_abort_proc *proc)
void GenerateWorldSetAbortCallback(GWAbortProc *proc)
{
_gw.abortp = proc;
}
@ -266,7 +266,7 @@ void HandleGeneratingWorldAbortion()
* @param size_y The Y-size of the map.
* @param reset_settings Whether to reset the game configuration (used for restart)
*/
void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y, bool reset_settings)
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
{
if (_gw.active) return;
_gw.mode = mode;
@ -308,7 +308,7 @@ void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y, bool reset_
}
if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0 ||
!ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
!ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode");
_gw.threaded = false;
_genworld_mapgen_mutex->EndCritical();

View File

@ -28,31 +28,31 @@ enum {
};
/* Modes for GenerateWorld */
enum GenerateWorldMode {
GW_NEWGAME = 0, ///< Generate a map for a new game
GW_EMPTY = 1, ///< Generate an empty map (sea-level)
GW_RANDOM = 2, ///< Generate a random map for SE
GW_HEIGHTMAP = 3, ///< Generate a newgame from a heightmap
enum GenWorldMode {
GWM_NEWGAME = 0, ///< Generate a map for a new game
GWM_EMPTY = 1, ///< Generate an empty map (sea-level)
GWM_RANDOM = 2, ///< Generate a random map for SE
GWM_HEIGHTMAP = 3, ///< Generate a newgame from a heightmap
};
typedef void gw_done_proc();
typedef void gw_abort_proc();
typedef void GWDoneProc();
typedef void GWAbortProc();
struct gw_info {
struct GenWorldInfo {
bool active; ///< Is generating world active
bool abort; ///< Whether to abort the thread ASAP
bool quit_thread; ///< Do we want to quit the active thread
bool threaded; ///< Whether we run _GenerateWorld threaded
GenerateWorldMode mode;///< What mode are we making a world in
GenWorldMode mode; ///< What mode are we making a world in
CompanyID lc; ///< The local_company before generating
uint size_x; ///< X-size of the map
uint size_y; ///< Y-size of the map
gw_done_proc *proc; ///< Proc that is called when done (can be NULL)
gw_abort_proc *abortp; ///< Proc that is called when aborting (can be NULL)
GWDoneProc *proc; ///< Proc that is called when done (can be NULL)
GWAbortProc *abortp; ///< Proc that is called when aborting (can be NULL)
class ThreadObject *thread; ///< The thread we are in (can be NULL)
};
enum gwp_class {
enum GenWorldProgress {
GWP_MAP_INIT, ///< Initialize/allocate the map, start economy
GWP_LANDSCAPE, ///< Create the landscape
GWP_ROUGH_ROCKY, ///< Make rough and rocky areas
@ -71,24 +71,23 @@ enum gwp_class {
*/
static inline bool IsGeneratingWorld()
{
extern gw_info _gw;
extern GenWorldInfo _gw;
return _gw.active;
}
/* genworld.cpp */
bool IsGenerateWorldThreaded();
void GenerateWorldSetCallback(gw_done_proc *proc);
void GenerateWorldSetAbortCallback(gw_abort_proc *proc);
void GenerateWorldSetCallback(GWDoneProc *proc);
void GenerateWorldSetAbortCallback(GWAbortProc *proc);
void WaitTillGeneratedWorld();
void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y, bool reset_settings = true);
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings = true);
void AbortGeneratingWorld();
bool IsGeneratingWorldAborted();
void HandleGeneratingWorldAbortion();
/* genworld_gui.cpp */
void SetGeneratingWorldProgress(gwp_class cls, uint total);
void IncreaseGeneratingWorldProgress(gwp_class cls);
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total);
void IncreaseGeneratingWorldProgress(GenWorldProgress cls);
void PrepareGenerateWorldProgress();
void ShowGenerateWorldProgress();
void StartNewGameWithoutGUI(uint seed);

View File

@ -1112,7 +1112,7 @@ static const WindowDesc _generate_progress_desc(
_nested_generate_progress_widgets, lengthof(_nested_generate_progress_widgets)
);
struct tp_info {
struct GenWorldStatus {
uint percent;
StringID cls;
uint current;
@ -1120,9 +1120,9 @@ struct tp_info {
int timer;
};
static tp_info _tp;
static GenWorldStatus _gws;
static const StringID _generation_class_table[GWP_CLASS_COUNT] = {
static const StringID _generation_class_table[] = {
STR_GENERATION_WORLD_GENERATION,
STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION,
STR_GENERATION_CLEARING_TILES,
@ -1134,6 +1134,7 @@ static const StringID _generation_class_table[GWP_CLASS_COUNT] = {
STR_GENERATION_PREPARING_TILELOOP,
STR_GENERATION_PREPARING_GAME
};
assert_compile(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
@ -1198,18 +1199,18 @@ struct GenerateProgressWindow : public Window {
case GPWW_PROGRESS_BAR:
/* Draw the % complete with a bar and a text */
DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
DrawFrameRect(r.left + 1, r.top + 1, (int)((r.right - r.left - 2) * _tp.percent / 100) + r.left + 1, r.bottom - 1, COLOUR_MAUVE, FR_NONE);
SetDParam(0, _tp.percent);
DrawFrameRect(r.left + 1, r.top + 1, (int)((r.right - r.left - 2) * _gws.percent / 100) + r.left + 1, r.bottom - 1, COLOUR_MAUVE, FR_NONE);
SetDParam(0, _gws.percent);
DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_CENTER);
break;
case GPWW_PROGRESS_TEXT:
/* Tell which class we are generating */
DrawString(r.left, r.right, r.top, _tp.cls, TC_FROMSTRING, SA_CENTER);
DrawString(r.left, r.right, r.top, _gws.cls, TC_FROMSTRING, SA_CENTER);
/* And say where we are in that class */
SetDParam(0, _tp.current);
SetDParam(1, _tp.total);
SetDParam(0, _gws.current);
SetDParam(1, _gws.total);
DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_CENTER);
}
}
@ -1220,11 +1221,11 @@ struct GenerateProgressWindow : public Window {
*/
void PrepareGenerateWorldProgress()
{
_tp.cls = STR_GENERATION_WORLD_GENERATION;
_tp.current = 0;
_tp.total = 0;
_tp.percent = 0;
_tp.timer = 0; // Forces to paint the progress window immediatelly
_gws.cls = STR_GENERATION_WORLD_GENERATION;
_gws.current = 0;
_gws.total = 0;
_gws.percent = 0;
_gws.timer = 0; // Forces to paint the progress window immediatelly
}
/**
@ -1236,7 +1237,7 @@ void ShowGenerateWorldProgress()
new GenerateProgressWindow();
}
static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total)
static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
{
static const int percent_table[GWP_CLASS_COUNT + 1] = {0, 5, 15, 20, 40, 60, 65, 80, 85, 99, 100 };
@ -1248,36 +1249,36 @@ static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total
if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
if (total == 0) {
assert(_tp.cls == _generation_class_table[cls]);
_tp.current += progress;
assert(_tp.current <= _tp.total);
assert(_gws.cls == _generation_class_table[cls]);
_gws.current += progress;
assert(_gws.current <= _gws.total);
} else {
_tp.cls = _generation_class_table[cls];
_tp.current = progress;
_tp.total = total;
_tp.percent = percent_table[cls];
_gws.cls = _generation_class_table[cls];
_gws.current = progress;
_gws.total = total;
_gws.percent = percent_table[cls];
}
/* Don't update the screen too often. So update it once in every once in a while... */
if (!_network_dedicated && _tp.timer != 0 && _realtime_tick - _tp.timer < GENWORLD_REDRAW_TIMEOUT) return;
if (!_network_dedicated && _gws.timer != 0 && _realtime_tick - _gws.timer < GENWORLD_REDRAW_TIMEOUT) return;
/* Percentage is about the number of completed tasks, so 'current - 1' */
_tp.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total;
_gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
if (_network_dedicated) {
static uint last_percent = 0;
/* Never display 0% */
if (_tp.percent == 0) return;
if (_gws.percent == 0) return;
/* Reset if percent is lower than the last recorded */
if (_tp.percent < last_percent) last_percent = 0;
if (_gws.percent < last_percent) last_percent = 0;
/* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
if (_tp.percent % 5 != 0 && _tp.percent <= last_percent + 5) return;
if (_gws.percent % 5 != 0 && _gws.percent <= last_percent + 5) return;
/* Never show steps smaller than 2%, even if it is a mod 5% */
if (_tp.percent <= last_percent + 2) return;
if (_gws.percent <= last_percent + 2) return;
DEBUG(net, 1, "Map generation percentage complete: %d", _tp.percent);
last_percent = _tp.percent;
DEBUG(net, 1, "Map generation percentage complete: %d", _gws.percent);
last_percent = _gws.percent;
/* Don't continue as dedicated never has a thread running */
return;
@ -1295,7 +1296,7 @@ static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total
_genworld_mapgen_mutex->BeginCritical();
_genworld_paint_mutex->EndCritical();
_tp.timer = _realtime_tick;
_gws.timer = _realtime_tick;
}
/**
@ -1306,7 +1307,7 @@ static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total
* Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always.
* Also, progress works if total is zero, total works if progress is zero.
*/
void SetGeneratingWorldProgress(gwp_class cls, uint total)
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
{
if (total == 0) return;
@ -1320,7 +1321,7 @@ void SetGeneratingWorldProgress(gwp_class cls, uint total)
* Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always.
* Also, progress works if total is zero, total works if progress is zero.
*/
void IncreaseGeneratingWorldProgress(gwp_class cls)
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
{
/* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
_SetGeneratingWorldProgress(cls, 1, 0);

View File

@ -867,7 +867,7 @@ void GenerateLandscape(byte mode)
};
uint steps = (_settings_game.game_creation.landscape == LT_TROPIC) ? GLS_TROPIC : GLS_OTHER;
if (mode == GW_HEIGHTMAP) {
if (mode == GWM_HEIGHTMAP) {
SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP);
LoadHeightmap(_file_to_saveload.name);
IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);

View File

@ -368,7 +368,7 @@ static void LoadIntroGame()
/* Load the default opening screen savegame */
if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) {
GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
WaitTillGeneratedWorld();
SetLocalCompany(COMPANY_SPECTATOR);
} else {
@ -721,7 +721,7 @@ int ttd_main(int argc, char *argv[])
_genworld_paint_mutex->BeginCritical();
_genworld_mapgen_mutex->BeginCritical();
GenerateWorld(GW_EMPTY, 64, 64); // Make the viewport initialization happy
GenerateWorld(GWM_EMPTY, 64, 64); // Make the viewport initialization happy
WaitTillGeneratedWorld();
CheckForMissingGlyphsInLoadedLanguagePack();
@ -833,7 +833,7 @@ static void MakeNewGame(bool from_heightmap, bool reset_settings)
InitializeDynamicVariables();
GenerateWorldSetCallback(&MakeNewGameDone);
GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y, reset_settings);
GenerateWorld(from_heightmap ? GWM_HEIGHTMAP : GWM_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y, reset_settings);
}
static void MakeNewEditorWorldDone()
@ -848,7 +848,7 @@ static void MakeNewEditorWorld()
ResetGRFConfig(true);
GenerateWorldSetCallback(&MakeNewEditorWorldDone);
GenerateWorld(GW_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
GenerateWorld(GWM_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
}
void StartupCompanies();
@ -1033,7 +1033,7 @@ void SwitchToMode(SwitchMode new_mode)
case SM_LOAD_HEIGHTMAP: // Load heightmap from scenario editor
SetLocalCompany(OWNER_NONE);
GenerateWorld(GW_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
GenerateWorld(GWM_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
MarkWholeScreenDirty();
break;
@ -1066,7 +1066,7 @@ void SwitchToMode(SwitchMode new_mode)
case SM_GENRANDLAND: // Generate random land within scenario editor
SetLocalCompany(OWNER_NONE);
GenerateWorld(GW_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
GenerateWorld(GWM_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
/* XXX: set date */
MarkWholeScreenDirty();
break;