From a82572d0f5a55a33df4163b429f891ea76ed92a7 Mon Sep 17 00:00:00 2001 From: Yexo Date: Fri, 29 May 2020 22:31:14 +0200 Subject: [PATCH 1/8] Codechange: remove has_newhouses global --- src/newgrf.cpp | 3 --- src/newgrf.h | 1 - src/newgrf_house.cpp | 4 ---- src/town_cmd.cpp | 6 ++---- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 6f12fbbf9f..4429771e59 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2384,8 +2384,6 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt if (!CargoSpec::Get(housespec->accepts_cargo[2])->IsValid()) { housespec->cargo_acceptance[2] = 0; } - - _loaded_newgrf_features.has_newhouses = true; break; } @@ -8633,7 +8631,6 @@ void ResetNewGRFData() _loaded_newgrf_features.has_2CC = false; _loaded_newgrf_features.used_liveries = 1 << LS_DEFAULT; - _loaded_newgrf_features.has_newhouses = false; _loaded_newgrf_features.has_newindustries = false; _loaded_newgrf_features.shore = SHORE_REPLACE_NONE; _loaded_newgrf_features.tram = TRAMWAY_REPLACE_DEPOT_NONE; diff --git a/src/newgrf.h b/src/newgrf.h index 65df3698e4..20a178e1f9 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -174,7 +174,6 @@ enum TramReplacement { struct GRFLoadedFeatures { bool has_2CC; ///< Set if any vehicle is loaded which uses 2cc (two company colours). uint64 used_liveries; ///< Bitmask of #LiveryScheme used by the defined engines. - bool has_newhouses; ///< Set if there are any newhouses loaded. bool has_newindustries; ///< Set if there are any newindustries loaded. ShoreReplacement shore; ///< In which way shore sprites were replaced. TramReplacement tram; ///< In which way tram depots were replaced. diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index b585a682dc..544f346e04 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -108,8 +108,6 @@ void IncreaseBuildingCount(Town *t, HouseID house_id) { HouseClassID class_id = HouseSpec::Get(house_id)->class_id; - if (!_loaded_newgrf_features.has_newhouses) return; - t->cache.building_counts.id_count[house_id]++; _building_counts.id_count[house_id]++; @@ -129,8 +127,6 @@ void DecreaseBuildingCount(Town *t, HouseID house_id) { HouseClassID class_id = HouseSpec::Get(house_id)->class_id; - if (!_loaded_newgrf_features.has_newhouses) return; - if (t->cache.building_counts.id_count[house_id] > 0) t->cache.building_counts.id_count[house_id]--; if (_building_counts.id_count[house_id] > 0) _building_counts.id_count[house_id]--; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 9372d37111..39dfa7db17 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2492,8 +2492,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile) if (t->cache.building_counts.id_count[i] == UINT16_MAX) continue; } - /* Without NewHouses, all houses have probability '1' */ - uint cur_prob = (_loaded_newgrf_features.has_newhouses ? hs->probability : 1); + uint cur_prob = hs->probability; probability_max += cur_prob; probs[num] = cur_prob; houses[num++] = (HouseID)i; @@ -2526,8 +2525,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile) const HouseSpec *hs = HouseSpec::Get(house); - if (_loaded_newgrf_features.has_newhouses && !_generating_world && - _game_mode != GM_EDITOR && (hs->extra_flags & BUILDING_IS_HISTORICAL) != 0) { + if (!_generating_world && _game_mode != GM_EDITOR && (hs->extra_flags & BUILDING_IS_HISTORICAL) != 0) { continue; } From ce618bf7e96ddc92b1ceb7c82c821af822b3796d Mon Sep 17 00:00:00 2001 From: Yexo Date: Mon, 1 Jun 2020 00:43:47 +0200 Subject: [PATCH 2/8] Codechange: replace custom timer and OnGameTick() with OnHundrethTick() --- src/industry_gui.cpp | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index a5f03a2b94..c7ba3345c9 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -270,8 +270,6 @@ static WindowDesc _build_industry_desc( class BuildIndustryWindow : public Window { int selected_index; ///< index of the element in the matrix IndustryType selected_type; ///< industry corresponding to the above index - uint16 callback_timer; ///< timer counter for callback eventual verification - bool timer_enabled; ///< timer can be used uint16 count; ///< How many industries are loaded IndustryType index[NUM_INDUSTRYTYPES + 1]; ///< Type of industry, in the order it was loaded bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_PROBABILITY (if ever) @@ -295,7 +293,6 @@ class BuildIndustryWindow : public Window { this->index[this->count] = INVALID_INDUSTRYTYPE; this->enabled[this->count] = true; this->count++; - this->timer_enabled = false; } /* Fill the arrays with industries. * The tests performed after the enabled allow to load the industries @@ -387,13 +384,9 @@ class BuildIndustryWindow : public Window { public: BuildIndustryWindow() : Window(&_build_industry_desc) { - this->timer_enabled = _loaded_newgrf_features.has_newindustries; - this->selected_index = -1; this->selected_type = INVALID_INDUSTRYTYPE; - this->callback_timer = DAY_TICKS; - this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_DPI_SCROLLBAR); this->FinishInitNested(0); @@ -673,25 +666,19 @@ public: if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace(); } - void OnGameTick() override + void OnHundredthTick() override { - if (!this->timer_enabled) return; - if (--this->callback_timer == 0) { - /* We have just passed another day. - * See if we need to update availability of currently selected industry */ - this->callback_timer = DAY_TICKS; // restart counter + if (_game_mode == GM_EDITOR) return; + const IndustrySpec *indsp = GetIndustrySpec(this->selected_type); - const IndustrySpec *indsp = GetIndustrySpec(this->selected_type); + if (indsp->enabled) { + bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0; - if (indsp->enabled) { - bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0; - - /* Only if result does match the previous state would it require a redraw. */ - if (call_back_result != this->enabled[this->selected_index]) { - this->enabled[this->selected_index] = call_back_result; - this->SetButtons(); - this->SetDirty(); - } + /* Only if result does match the previous state would it require a redraw. */ + if (call_back_result != this->enabled[this->selected_index]) { + this->enabled[this->selected_index] = call_back_result; + this->SetButtons(); + this->SetDirty(); } } } From 1507902d0083b4983d59efdd3859dde0a9b19fa3 Mon Sep 17 00:00:00 2001 From: Yexo Date: Mon, 1 Jun 2020 00:44:11 +0200 Subject: [PATCH 3/8] Codechange: remove has_newindustries global --- src/industry_gui.cpp | 12 +++++++++--- src/newgrf.cpp | 2 -- src/newgrf.h | 1 - 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index c7ba3345c9..88cbc91d10 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -416,10 +416,11 @@ public: } case WID_DPI_INFOPANEL: { - /* Extra line for cost outside of editor + extra lines for 'extra' information for NewGRFs. */ - int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1) + (_loaded_newgrf_features.has_newindustries ? 4 : 0); + /* Extra line for cost outside of editor. */ + int height = 2 + (_game_mode == GM_EDITOR ? 0 : 1); uint extra_lines_req = 0; uint extra_lines_prd = 0; + uint extra_lines_newgrf = 0; uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS; Dimension d = {0, 0}; for (byte i = 0; i < this->count; i++) { @@ -447,10 +448,15 @@ public: strdim.width = max_minwidth; } d = maxdim(d, strdim); + + if (indsp->grf_prop.grffile != nullptr) { + /* Reserve a few extra lines for text from an industry NewGRF. */ + extra_lines_newgrf = 4; + } } /* Set it to something more sane :) */ - height += extra_lines_prd + extra_lines_req; + height += extra_lines_prd + extra_lines_req + extra_lines_newgrf; size->height = height * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; size->width = d.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; break; diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 4429771e59..4abbcb3b72 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -8631,7 +8631,6 @@ void ResetNewGRFData() _loaded_newgrf_features.has_2CC = false; _loaded_newgrf_features.used_liveries = 1 << LS_DEFAULT; - _loaded_newgrf_features.has_newindustries = false; _loaded_newgrf_features.shore = SHORE_REPLACE_NONE; _loaded_newgrf_features.tram = TRAMWAY_REPLACE_DEPOT_NONE; @@ -9151,7 +9150,6 @@ static void FinaliseIndustriesArray() } _industry_mngr.SetEntitySpec(indsp); - _loaded_newgrf_features.has_newindustries = true; } } } diff --git a/src/newgrf.h b/src/newgrf.h index 20a178e1f9..d9c8a4da58 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -174,7 +174,6 @@ enum TramReplacement { struct GRFLoadedFeatures { bool has_2CC; ///< Set if any vehicle is loaded which uses 2cc (two company colours). uint64 used_liveries; ///< Bitmask of #LiveryScheme used by the defined engines. - bool has_newindustries; ///< Set if there are any newindustries loaded. ShoreReplacement shore; ///< In which way shore sprites were replaced. TramReplacement tram; ///< In which way tram depots were replaced. }; From cdd2892c49f0fa7b6a197a463cfa84ba0edcb20d Mon Sep 17 00:00:00 2001 From: TechGeekNZ Date: Thu, 4 Jun 2020 18:23:57 +1200 Subject: [PATCH 4/8] Codechange: Realign SDL driver with SDL2 driver to ease maintenance and emphasise differences. --- src/video/sdl2_v.cpp | 4 +--- src/video/sdl_v.cpp | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 0442a0e87a..0dff1af4c5 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -170,9 +170,7 @@ static void DrawSurfaceToScreen() } else { if (_sdl_surface != _sdl_realscreen) { for (int i = 0; i < n; i++) { - SDL_BlitSurface( - _sdl_surface, &_dirty_rects[i], - _sdl_realscreen, &_dirty_rects[i]); + SDL_BlitSurface(_sdl_surface, &_dirty_rects[i], _sdl_realscreen, &_dirty_rects[i]); } } diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index fba6166c9c..98777a87d5 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -31,7 +31,7 @@ static FVideoDriver_SDL iFVideoDriver_SDL; -static SDL_Surface *_sdl_screen; +static SDL_Surface *_sdl_surface; static SDL_Surface *_sdl_realscreen; static bool _all_modes; @@ -73,11 +73,11 @@ static void UpdatePalette(bool init = false) pal[i].unused = 0; } - SDL_SetColors(_sdl_screen, pal, _local_palette.first_dirty, _local_palette.count_dirty); + SDL_SetColors(_sdl_surface, pal, _local_palette.first_dirty, _local_palette.count_dirty); - if (_sdl_screen != _sdl_realscreen && init) { + if (_sdl_surface != _sdl_realscreen && init) { /* When using a shadow surface, also set our palette on the real screen. This lets SDL - * allocate as much colors (or approximations) as + * allocate as many colors (or approximations) as * possible, instead of using only the default SDL * palette. This allows us to get more colors exactly * right and might allow using better approximations for @@ -99,7 +99,7 @@ static void UpdatePalette(bool init = false) SDL_SetColors(_sdl_realscreen, pal, _local_palette.first_dirty, _local_palette.count_dirty); } - if (_sdl_screen != _sdl_realscreen && !init) { + if (_sdl_surface != _sdl_realscreen && !init) { /* We're not using real hardware palette, but are letting SDL * approximate the palette during shadow -> screen copy. To * change the palette, we need to recopy the entire screen. @@ -110,7 +110,7 @@ static void UpdatePalette(bool init = false) * best mapping of shadow palette colors to real palette * colors from scratch. */ - SDL_BlitSurface(_sdl_screen, nullptr, _sdl_realscreen, nullptr); + SDL_BlitSurface(_sdl_surface, nullptr, _sdl_realscreen, nullptr); SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0); } } @@ -155,17 +155,20 @@ static void DrawSurfaceToScreen() if (n == 0) return; _num_dirty_rects = 0; + if (n > MAX_DIRTY_RECTS) { - if (_sdl_screen != _sdl_realscreen) { - SDL_BlitSurface(_sdl_screen, nullptr, _sdl_realscreen, nullptr); + if (_sdl_surface != _sdl_realscreen) { + SDL_BlitSurface(_sdl_surface, nullptr, _sdl_realscreen, nullptr); } + SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0); } else { - if (_sdl_screen != _sdl_realscreen) { + if (_sdl_surface != _sdl_realscreen) { for (int i = 0; i < n; i++) { - SDL_BlitSurface(_sdl_screen, &_dirty_rects[i], _sdl_realscreen, &_dirty_rects[i]); + SDL_BlitSurface(_sdl_surface, &_dirty_rects[i], _sdl_realscreen, &_dirty_rects[i]); } } + SDL_UpdateRects(_sdl_realscreen, n, _dirty_rects); } } @@ -308,7 +311,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) if (want_hwpalette) DEBUG(driver, 1, "SDL: requesting hardware palette"); /* Free any previously allocated shadow surface */ - if (_sdl_screen != nullptr && _sdl_screen != _sdl_realscreen) SDL_FreeSurface(_sdl_screen); + if (_sdl_surface != nullptr && _sdl_surface != _sdl_realscreen) SDL_FreeSurface(_sdl_surface); if (_sdl_realscreen != nullptr) { if (_requested_hwpalette != want_hwpalette) { @@ -375,7 +378,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) _screen.height = newscreen->h; _screen.pitch = newscreen->pitch / (bpp / 8); _screen.dst_ptr = newscreen->pixels; - _sdl_screen = newscreen; + _sdl_surface = newscreen; /* When in full screen, we will always have the mouse cursor * within the window, even though SDL does not give us the @@ -610,7 +613,7 @@ const char *VideoDriver_SDL::Start(const StringList &parm) } else if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { ret_code = SDL_InitSubSystem(SDL_INIT_VIDEO); } - if (ret_code == -1) return SDL_GetError(); + if (ret_code < 0) return SDL_GetError(); GetVideoModes(); if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) { From f246f8faef8d9f949e7d64a624a5a1628a857508 Mon Sep 17 00:00:00 2001 From: TechGeekNZ Date: Fri, 5 Jun 2020 14:31:28 +1200 Subject: [PATCH 5/8] Cleanup: Fix typo in settings.h.preamble. --- src/table/settings.h.preamble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index ddb9d2abfc..2b2257539b 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -28,7 +28,7 @@ static size_t ConvertLandscape(const char *value); * These are for client-only variables. Here the 'var' refers to an * entry inside _settings_client. * 3. SDT_something - * Thse are for members in the struct described by the current + * These are for members in the struct described by the current * #SettingDesc list / .ini file. Here, 'base' specifies type of the * struct while 'var' points out the member of the struct (the actual * struct to store it in is implicitly defined by the #SettingDesc From 012fea301d886534733ba5c7d70b8af4381ab260 Mon Sep 17 00:00:00 2001 From: TechGeekNZ Date: Fri, 5 Jun 2020 14:32:26 +1200 Subject: [PATCH 6/8] Cleanup: Add note explaining how settings.h is generated from source. --- src/table/settings.h.preamble | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index 2b2257539b..3d372c2452 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -13,7 +13,9 @@ static size_t ConvertLandscape(const char *value); /**************************** * OTTD specific INI stuff - ****************************/ + **************************** + * DO NOT edit this file. This file is automatically generated from the contents of /src/table/ + */ /** * Settings-macro usage: From 937b3665463fb9e5155199a9675e5e43c8760bbf Mon Sep 17 00:00:00 2001 From: TechGeekNZ Date: Thu, 4 Jun 2020 23:07:19 +1200 Subject: [PATCH 7/8] Cleanup: StationCargoList::AreMergable doxygen comment references Vehicle instead of Station. --- src/cargopacket.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargopacket.h b/src/cargopacket.h index c058bafdbb..e34298895c 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -538,8 +538,8 @@ public: uint Reroute(uint max_move, StationCargoList *dest, StationID avoid, StationID avoid2, const GoodsEntry *ge); /** - * Are two the two CargoPackets mergeable in the context of - * a list of CargoPackets for a Vehicle? + * Are the two CargoPackets mergeable in the context of + * a list of CargoPackets for a Station? * @param cp1 First CargoPacket. * @param cp2 Second CargoPacket. * @return True if they are mergeable. From eeed3a7613d375f66781f53b42e03729a4ca1c33 Mon Sep 17 00:00:00 2001 From: Marcus Calhoun-Lopez Date: Thu, 4 Jun 2020 14:49:40 +0200 Subject: [PATCH 8/8] Fix: unbreak building with ICU on macOS A symbol clash breaks building ICU on macOS, and although it isn't necessary, it might as well be possible. --- src/string.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/string.cpp b/src/string.cpp index bec7c8e926..d0de261e53 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -32,10 +32,6 @@ #include "os/windows/string_uniscribe.h" #endif -#if defined(WITH_COCOA) -#include "os/macosx/string_osx.h" -#endif - #ifdef WITH_ICU_I18N /* Required by strnatcmp. */ #include @@ -43,6 +39,10 @@ #include "gfx_func.h" #endif /* WITH_ICU_I18N */ +#if defined(WITH_COCOA) +#include "os/macosx/string_osx.h" +#endif + /* The function vsnprintf is used internally to perform the required formatting * tasks. As such this one must be allowed, and makes sure it's terminated. */ #include "safeguards.h"