mirror of https://github.com/OpenTTD/OpenTTD
Codefix: 'Short global name'
parent
cb23bc5e2a
commit
672c5f0d98
|
@ -57,13 +57,16 @@ void StartupDisasters();
|
||||||
|
|
||||||
void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings);
|
void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings);
|
||||||
|
|
||||||
/**
|
/** Properties of current genworld process */
|
||||||
* Please only use this variable in genworld.h and genworld.cpp and
|
struct GenWorldInfo {
|
||||||
* nowhere else. For speed improvements we need it to be global, but
|
static inline bool abort; ///< Whether to abort the thread ASAP
|
||||||
* in no way the meaning of it is to use it anywhere else besides
|
static inline GenWorldMode mode; ///< What mode are we making a world in
|
||||||
* in the genworld.h and genworld.cpp!
|
static inline CompanyID lc; ///< The local_company before generating
|
||||||
*/
|
static inline uint size_x; ///< X-size of the map
|
||||||
GenWorldInfo _gw;
|
static inline uint size_y; ///< Y-size of the map
|
||||||
|
static inline GWDoneProc *proc; ///< Proc that is called when done (can be nullptr)
|
||||||
|
static inline GWAbortProc *abortp; ///< Proc that is called when aborting (can be nullptr)
|
||||||
|
};
|
||||||
|
|
||||||
/** Whether we are generating the map or not. */
|
/** Whether we are generating the map or not. */
|
||||||
bool _generating_world;
|
bool _generating_world;
|
||||||
|
@ -79,8 +82,8 @@ static void CleanupGeneration()
|
||||||
|
|
||||||
SetMouseCursorBusy(false);
|
SetMouseCursorBusy(false);
|
||||||
SetModalProgress(false);
|
SetModalProgress(false);
|
||||||
_gw.proc = nullptr;
|
GenWorldInfo::proc = nullptr;
|
||||||
_gw.abortp = nullptr;
|
GenWorldInfo::abortp = nullptr;
|
||||||
|
|
||||||
CloseWindowByClass(WC_MODAL_PROGRESS);
|
CloseWindowByClass(WC_MODAL_PROGRESS);
|
||||||
ShowFirstError();
|
ShowFirstError();
|
||||||
|
@ -117,8 +120,8 @@ static void _GenerateWorld()
|
||||||
bool landscape_generated = false;
|
bool landscape_generated = false;
|
||||||
|
|
||||||
/* Don't generate landscape items when in the scenario editor. */
|
/* Don't generate landscape items when in the scenario editor. */
|
||||||
if (_gw.mode != GWM_EMPTY) {
|
if (GenWorldInfo::mode != GWM_EMPTY) {
|
||||||
landscape_generated = GenerateLandscape(_gw.mode);
|
landscape_generated = GenerateLandscape(GenWorldInfo::mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!landscape_generated) {
|
if (!landscape_generated) {
|
||||||
|
@ -162,7 +165,7 @@ static void _GenerateWorld()
|
||||||
_generating_world = false;
|
_generating_world = false;
|
||||||
|
|
||||||
/* No need to run the tile loop in the scenario editor. */
|
/* No need to run the tile loop in the scenario editor. */
|
||||||
if (_gw.mode != GWM_EMPTY) {
|
if (GenWorldInfo::mode != GWM_EMPTY) {
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
SetGeneratingWorldProgress(GWP_RUNTILELOOP, 0x500);
|
SetGeneratingWorldProgress(GWP_RUNTILELOOP, 0x500);
|
||||||
|
@ -192,13 +195,13 @@ static void _GenerateWorld()
|
||||||
|
|
||||||
ResetObjectToPlace();
|
ResetObjectToPlace();
|
||||||
_cur_company.Trash();
|
_cur_company.Trash();
|
||||||
_current_company = _local_company = _gw.lc;
|
_current_company = _local_company = GenWorldInfo::lc;
|
||||||
/* Show all vital windows again, because we have hidden them. */
|
/* Show all vital windows again, because we have hidden them. */
|
||||||
if (_game_mode != GM_MENU) ShowVitalWindows();
|
if (_game_mode != GM_MENU) ShowVitalWindows();
|
||||||
|
|
||||||
SetGeneratingWorldProgress(GWP_GAME_START, 1);
|
SetGeneratingWorldProgress(GWP_GAME_START, 1);
|
||||||
/* Call any callback */
|
/* Call any callback */
|
||||||
if (_gw.proc != nullptr) _gw.proc();
|
if (GenWorldInfo::proc != nullptr) GenWorldInfo::proc();
|
||||||
IncreaseGeneratingWorldProgress(GWP_GAME_START);
|
IncreaseGeneratingWorldProgress(GWP_GAME_START);
|
||||||
|
|
||||||
CleanupGeneration();
|
CleanupGeneration();
|
||||||
|
@ -235,7 +238,7 @@ static void _GenerateWorld()
|
||||||
*/
|
*/
|
||||||
void GenerateWorldSetCallback(GWDoneProc *proc)
|
void GenerateWorldSetCallback(GWDoneProc *proc)
|
||||||
{
|
{
|
||||||
_gw.proc = proc;
|
GenWorldInfo::proc = proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -245,7 +248,7 @@ void GenerateWorldSetCallback(GWDoneProc *proc)
|
||||||
*/
|
*/
|
||||||
void GenerateWorldSetAbortCallback(GWAbortProc *proc)
|
void GenerateWorldSetAbortCallback(GWAbortProc *proc)
|
||||||
{
|
{
|
||||||
_gw.abortp = proc;
|
GenWorldInfo::abortp = proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,7 +256,7 @@ void GenerateWorldSetAbortCallback(GWAbortProc *proc)
|
||||||
*/
|
*/
|
||||||
void AbortGeneratingWorld()
|
void AbortGeneratingWorld()
|
||||||
{
|
{
|
||||||
_gw.abort = true;
|
GenWorldInfo::abort = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -262,7 +265,7 @@ void AbortGeneratingWorld()
|
||||||
*/
|
*/
|
||||||
bool IsGeneratingWorldAborted()
|
bool IsGeneratingWorldAborted()
|
||||||
{
|
{
|
||||||
return _gw.abort || _exit_game;
|
return GenWorldInfo::abort || _exit_game;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -273,7 +276,7 @@ void HandleGeneratingWorldAbortion()
|
||||||
/* Clean up - in SE create an empty map, otherwise, go to intro menu */
|
/* Clean up - in SE create an empty map, otherwise, go to intro menu */
|
||||||
_switch_mode = (_game_mode == GM_EDITOR) ? SM_EDITOR : SM_MENU;
|
_switch_mode = (_game_mode == GM_EDITOR) ? SM_EDITOR : SM_MENU;
|
||||||
|
|
||||||
if (_gw.abortp != nullptr) _gw.abortp();
|
if (GenWorldInfo::abortp != nullptr) GenWorldInfo::abortp();
|
||||||
|
|
||||||
throw AbortGenerateWorldSignal();
|
throw AbortGenerateWorldSignal();
|
||||||
}
|
}
|
||||||
|
@ -288,26 +291,26 @@ void HandleGeneratingWorldAbortion()
|
||||||
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
|
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings)
|
||||||
{
|
{
|
||||||
if (HasModalProgress()) return;
|
if (HasModalProgress()) return;
|
||||||
_gw.mode = mode;
|
GenWorldInfo::mode = mode;
|
||||||
_gw.size_x = size_x;
|
GenWorldInfo::size_x = size_x;
|
||||||
_gw.size_y = size_y;
|
GenWorldInfo::size_y = size_y;
|
||||||
SetModalProgress(true);
|
SetModalProgress(true);
|
||||||
_gw.abort = false;
|
GenWorldInfo::abort = false;
|
||||||
_gw.abortp = nullptr;
|
GenWorldInfo::abortp = nullptr;
|
||||||
_gw.lc = _local_company;
|
GenWorldInfo::lc = _local_company;
|
||||||
|
|
||||||
/* This disables some commands and stuff */
|
/* This disables some commands and stuff */
|
||||||
SetLocalCompany(COMPANY_SPECTATOR);
|
SetLocalCompany(COMPANY_SPECTATOR);
|
||||||
|
|
||||||
InitializeGame(_gw.size_x, _gw.size_y, true, reset_settings);
|
InitializeGame(GenWorldInfo::size_x, GenWorldInfo::size_y, true, reset_settings);
|
||||||
PrepareGenerateWorldProgress();
|
PrepareGenerateWorldProgress();
|
||||||
|
|
||||||
if (_settings_game.construction.map_height_limit == 0) {
|
if (_settings_game.construction.map_height_limit == 0) {
|
||||||
uint estimated_height = 0;
|
uint estimated_height = 0;
|
||||||
|
|
||||||
if (_gw.mode == GWM_EMPTY && _game_mode != GM_MENU) {
|
if (GenWorldInfo::mode == GWM_EMPTY && _game_mode != GM_MENU) {
|
||||||
estimated_height = _settings_game.game_creation.se_flat_world_height;
|
estimated_height = _settings_game.game_creation.se_flat_world_height;
|
||||||
} else if (_gw.mode == GWM_HEIGHTMAP) {
|
} else if (GenWorldInfo::mode == GWM_HEIGHTMAP) {
|
||||||
estimated_height = _settings_game.game_creation.heightmap_height;
|
estimated_height = _settings_game.game_creation.heightmap_height;
|
||||||
} else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
|
} else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
|
||||||
estimated_height = GetEstimationTGPMapHeight();
|
estimated_height = GetEstimationTGPMapHeight();
|
||||||
|
|
|
@ -57,17 +57,6 @@ static const uint MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM = 15; ///< When map height
|
||||||
typedef void GWDoneProc(); ///< Procedure called when the genworld process finishes
|
typedef void GWDoneProc(); ///< Procedure called when the genworld process finishes
|
||||||
typedef void GWAbortProc(); ///< Called when genworld is aborted
|
typedef void GWAbortProc(); ///< Called when genworld is aborted
|
||||||
|
|
||||||
/** Properties of current genworld process */
|
|
||||||
struct GenWorldInfo {
|
|
||||||
bool abort; ///< Whether to abort the thread ASAP
|
|
||||||
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
|
|
||||||
GWDoneProc *proc; ///< Proc that is called when done (can be nullptr)
|
|
||||||
GWAbortProc *abortp; ///< Proc that is called when aborting (can be nullptr)
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Current stage of world generation process */
|
/** Current stage of world generation process */
|
||||||
enum GenWorldProgress : uint8_t {
|
enum GenWorldProgress : uint8_t {
|
||||||
GWP_MAP_INIT, ///< Initialize/allocate the map, start economy
|
GWP_MAP_INIT, ///< Initialize/allocate the map, start economy
|
||||||
|
|
|
@ -1334,14 +1334,12 @@ static WindowDesc _generate_progress_desc(
|
||||||
);
|
);
|
||||||
|
|
||||||
struct GenWorldStatus {
|
struct GenWorldStatus {
|
||||||
uint percent;
|
static inline uint percent;
|
||||||
StringID cls;
|
static inline StringID cls;
|
||||||
uint current;
|
static inline uint current;
|
||||||
uint total;
|
static inline uint total;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GenWorldStatus _gws;
|
|
||||||
|
|
||||||
static const StringID _generation_class_table[] = {
|
static const StringID _generation_class_table[] = {
|
||||||
STR_GENERATION_WORLD_GENERATION,
|
STR_GENERATION_WORLD_GENERATION,
|
||||||
STR_GENERATION_LANDSCAPE_GENERATION,
|
STR_GENERATION_LANDSCAPE_GENERATION,
|
||||||
|
@ -1418,19 +1416,19 @@ struct GenerateProgressWindow : public Window {
|
||||||
/* Draw the % complete with a bar and a text */
|
/* Draw the % complete with a bar and a text */
|
||||||
DrawFrameRect(r, COLOUR_GREY, {FrameFlag::BorderOnly, FrameFlag::Lowered});
|
DrawFrameRect(r, COLOUR_GREY, {FrameFlag::BorderOnly, FrameFlag::Lowered});
|
||||||
Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
|
Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
|
||||||
DrawFrameRect(br.WithWidth(br.Width() * _gws.percent / 100, _current_text_dir == TD_RTL), COLOUR_MAUVE, {});
|
DrawFrameRect(br.WithWidth(br.Width() * GenWorldStatus::percent / 100, _current_text_dir == TD_RTL), COLOUR_MAUVE, {});
|
||||||
SetDParam(0, _gws.percent);
|
SetDParam(0, GenWorldStatus::percent);
|
||||||
DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, GetCharacterHeight(FS_NORMAL)), STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
|
DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, GetCharacterHeight(FS_NORMAL)), STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WID_GP_PROGRESS_TEXT:
|
case WID_GP_PROGRESS_TEXT:
|
||||||
/* Tell which class we are generating */
|
/* Tell which class we are generating */
|
||||||
DrawString(r.left, r.right, r.top, _gws.cls, TC_FROMSTRING, SA_HOR_CENTER);
|
DrawString(r.left, r.right, r.top, GenWorldStatus::cls, TC_FROMSTRING, SA_HOR_CENTER);
|
||||||
|
|
||||||
/* And say where we are in that class */
|
/* And say where we are in that class */
|
||||||
SetDParam(0, _gws.current);
|
SetDParam(0, GenWorldStatus::current);
|
||||||
SetDParam(1, _gws.total);
|
SetDParam(1, GenWorldStatus::total);
|
||||||
DrawString(r.left, r.right, r.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_HOR_CENTER);
|
DrawString(r.left, r.right, r.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_HOR_CENTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1441,10 +1439,10 @@ struct GenerateProgressWindow : public Window {
|
||||||
*/
|
*/
|
||||||
void PrepareGenerateWorldProgress()
|
void PrepareGenerateWorldProgress()
|
||||||
{
|
{
|
||||||
_gws.cls = STR_GENERATION_WORLD_GENERATION;
|
GenWorldStatus::cls = STR_GENERATION_WORLD_GENERATION;
|
||||||
_gws.current = 0;
|
GenWorldStatus::current = 0;
|
||||||
_gws.total = 0;
|
GenWorldStatus::total = 0;
|
||||||
_gws.percent = 0;
|
GenWorldStatus::percent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1474,33 +1472,33 @@ static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (total == 0) {
|
if (total == 0) {
|
||||||
assert(_gws.cls == _generation_class_table[cls]);
|
assert(GenWorldStatus::cls == _generation_class_table[cls]);
|
||||||
_gws.current += progress;
|
GenWorldStatus::current += progress;
|
||||||
assert(_gws.current <= _gws.total);
|
assert(GenWorldStatus::current <= GenWorldStatus::total);
|
||||||
} else {
|
} else {
|
||||||
_gws.cls = _generation_class_table[cls];
|
GenWorldStatus::cls = _generation_class_table[cls];
|
||||||
_gws.current = progress;
|
GenWorldStatus::current = progress;
|
||||||
_gws.total = total;
|
GenWorldStatus::total = total;
|
||||||
_gws.percent = percent_table[cls];
|
GenWorldStatus::percent = percent_table[cls];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Percentage is about the number of completed tasks, so 'current - 1' */
|
/* Percentage is about the number of completed tasks, so 'current - 1' */
|
||||||
_gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
|
GenWorldStatus::percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (GenWorldStatus::current == 0 ? 0 : GenWorldStatus::current - 1) / GenWorldStatus::total;
|
||||||
|
|
||||||
if (_network_dedicated) {
|
if (_network_dedicated) {
|
||||||
static uint last_percent = 0;
|
static uint last_percent = 0;
|
||||||
|
|
||||||
/* Never display 0% */
|
/* Never display 0% */
|
||||||
if (_gws.percent == 0) return;
|
if (GenWorldStatus::percent == 0) return;
|
||||||
/* Reset if percent is lower than the last recorded */
|
/* Reset if percent is lower than the last recorded */
|
||||||
if (_gws.percent < last_percent) last_percent = 0;
|
if (GenWorldStatus::percent < last_percent) last_percent = 0;
|
||||||
/* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
|
/* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
|
||||||
if (_gws.percent % 5 != 0 && _gws.percent <= last_percent + 5) return;
|
if (GenWorldStatus::percent % 5 != 0 && GenWorldStatus::percent <= last_percent + 5) return;
|
||||||
/* Never show steps smaller than 2%, even if it is a mod 5% */
|
/* Never show steps smaller than 2%, even if it is a mod 5% */
|
||||||
if (_gws.percent <= last_percent + 2) return;
|
if (GenWorldStatus::percent <= last_percent + 2) return;
|
||||||
|
|
||||||
Debug(net, 3, "Map generation percentage complete: {}", _gws.percent);
|
Debug(net, 3, "Map generation percentage complete: {}", GenWorldStatus::percent);
|
||||||
last_percent = _gws.percent;
|
last_percent = GenWorldStatus::percent;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue