Skip to content

Commit

Permalink
Fix a bunch of warnings and some errors in process
Browse files Browse the repository at this point in the history
  • Loading branch information
ldpl committed Feb 19, 2024
1 parent 013c512 commit f5f570b
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/citymania/cm_bitstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Money BitIStream::ReadMoney() {
std::vector<byte> BitIStream::ReadData() {
auto len = this->ReadBytes(2);
std::vector<byte> res;
for (auto i = 0; i < len; i++) res.push_back(this->ReadBytes(1));
for (uint i = 0; i < len; i++) res.push_back(this->ReadBytes(1));
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion src/citymania/cm_bitstream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BitOStream {
};

class BitIStreamUnexpectedEnd: public std::exception {
virtual const char* what() const throw() {
const char* what() const throw() override {
return "Unexpected end of bit input stream";
}
};
Expand Down
12 changes: 4 additions & 8 deletions src/citymania/cm_cargo_table_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,25 @@ void InvalidateCargosWindows(CompanyID cid)
struct CargosWindow : Window {

CargoOption cargoPeriod;
CargosWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
{
CargosWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc) {
this->InitNested(window_number);
this->owner = (Owner)this->window_number;
this->cargoPeriod = WID_CT_OPTION_CARGO_TOTAL;
}

virtual void SetStringParameters(int widget) const
{
void SetStringParameters(int widget) const override {
if(widget != WID_CT_CAPTION) return;
SetDParam(0, (CompanyID)this->window_number);
SetDParam(1, (CompanyID)this->window_number);
}

virtual void OnClick(Point pt, int widget, int click_count)
{
void OnClick(Point pt, int widget, int click_count) override {
if(widget != WID_CT_HEADER_CARGO) return;
this->cargoPeriod = (this->cargoPeriod == WID_CT_OPTION_CARGO_TOTAL) ? WID_CT_OPTION_CARGO_MONTH : WID_CT_OPTION_CARGO_TOTAL;
this->SetDirty();
}

void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
{
void UpdateWidgetSize(int widget, Dimension *size, [[maybe_unused]] const Dimension &padding, Dimension *fill, Dimension *resize) {
Dimension icon_size = this->GetMaxIconSize();
int line_height = std::max(GetCharacterHeight(FS_NORMAL), (int)icon_size.height);
int icon_space = icon_size.width + ScaleGUITrad(CT_ICON_MARGIN);
Expand Down
18 changes: 9 additions & 9 deletions src/citymania/cm_console_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void IConsoleHelp(const char *str)
IConsolePrint(CC_WARNING, "- {}", str);
}

bool ConGameSpeed(byte argc, char *argv[]) {
bool ConGameSpeed([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[]) {
if (argc == 0 || argc > 2) {
IConsoleHelp("Changes game speed. Usage: 'cmgamespeed [n]'");
return true;
Expand All @@ -50,7 +50,7 @@ bool ConGameSpeed(byte argc, char *argv[]) {
return true;
}

bool ConStep(byte argc, char *argv[]) {
bool ConStep([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[]) {
if (argc == 0 || argc > 2) {
IConsoleHelp("Advances the game for a certain amount of ticks (default 1). Usage: 'cmstep [n]'");
return true;
Expand All @@ -63,7 +63,7 @@ bool ConStep(byte argc, char *argv[]) {
return true;
}

bool ConExport(byte argc, char *argv[]) {
bool ConExport([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[]) {
if (argc == 0) {
IConsoleHelp("Exports various game data in json format to openttd.json file");
return true;
Expand All @@ -75,7 +75,7 @@ bool ConExport(byte argc, char *argv[]) {
return true;
}

bool ConTreeMap(byte argc, char *argv[]) {
bool ConTreeMap([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[]) {
if (argc == 0) {
IConsoleHelp("Loads heighmap-like file and plants trees according to it, values 0-256 ore scaled to 0-4 trees.");
IConsoleHelp("Usage: 'cmtreemap <file>'");
Expand Down Expand Up @@ -138,7 +138,7 @@ bool ConTreeMap(byte argc, char *argv[]) {

extern void (*UpdateTownGrowthRate)(Town *t);

bool ConResetTownGrowth(byte argc, char *argv[]) {
bool ConResetTownGrowth([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[]) {
if (argc == 0) {
IConsoleHelp("Resets growth to normal for all towns.");
IConsoleHelp("Usage: 'cmresettowngrowth'");
Expand Down Expand Up @@ -181,7 +181,7 @@ void SetReplaySaveInterval(uint32 interval) {
if (_replay_save_interval) MakeReplaySave();
}

bool ConLoadCommands(byte argc, char *argv[]) {
bool ConLoadCommands([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[]) {
if (argc == 0) {
IConsoleHelp("Loads a file with command queue to execute");
IConsoleHelp("Usage: 'cmloadcommands <file>'");
Expand All @@ -198,17 +198,17 @@ bool ConLoadCommands(byte argc, char *argv[]) {
return true;
}

bool ConStartRecord(byte argc, char *argv[]) {
bool ConStartRecord([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[]) {
StartRecording();
return true;
}

bool ConStopRecord(byte argc, char *argv[]) {
bool ConStopRecord([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[]) {
StopRecording();
return true;
}

bool ConGameStats(byte argc, char *argv[]) {
bool ConGameStats([[maybe_unused]] byte argc, [[maybe_unused]] char *argv[]) {
auto num_trains = 0u;
auto num_rvs = 0u;
auto num_ships = 0u;
Expand Down
6 changes: 1 addition & 5 deletions src/citymania/cm_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ void WriteHouseSpecInfo(JsonWriter &j) {

void WriteCargoSpecInfo(JsonWriter &j) {
j.begin_list_with_key("cargo_specs");
const CargoSpec *cs;
char buffer[128];
char cargo_label[16];
bool first = true;
SetDParam(0, 123);
for (const CargoSpec *cs : CargoSpec::Iterate()) {
j.begin_dict();
Expand Down Expand Up @@ -287,12 +284,11 @@ void WritePaletteInfo(JsonWriter &j) {
j.f << "]";
}
j.end_list();
const byte *remap = GetNonSprite(GB(PALETTE_TO_RED, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
// const byte *remap = GetNonSprite(GB(PALETTE_TO_RED, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
}

void WriteEngineInfo(JsonWriter &j) {
j.begin_list_with_key("engines");
const Engine *e;
for (const Engine *e : Engine::Iterate()) {
if (e->type != VEH_TRAIN) continue;
j.begin_dict();
Expand Down
2 changes: 1 addition & 1 deletion src/citymania/cm_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Game::Game() {
}
});

this->events.listen<event::TownCachesRebuilt>(event::Slot::GAME, [this] (const event::TownCachesRebuilt &event) {
this->events.listen<event::TownCachesRebuilt>(event::Slot::GAME, [this] ([[maybe_unused]] const event::TownCachesRebuilt &event) {
this->towns_growth_tiles.clear();
this->towns_growth_tiles_last_month.clear();
for (Town *town : Town::Iterate()) {
Expand Down
2 changes: 1 addition & 1 deletion src/citymania/cm_watch_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ void WatchCompany::OnDoCommand(CompanyID company, TileIndex tile )
/** Used to decrement the activity counter
*
*/
void WatchCompany::OnTick()
void WatchCompany::OnRealtimeTick([[maybe_unused]] uint delta_ms)
{
bool set_dirty = false;
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
Expand Down
20 changes: 10 additions & 10 deletions src/citymania/cm_watch_gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ class WatchCompany : public Window
public:
WatchCompany(WindowDesc *desc, int window_number, CompanyID company_to_watch, int Wtype);

virtual void DrawWidget(const Rect &r, int widget) const;
virtual void OnClick(Point pt, int widget, int click_count);
virtual void OnResize();
virtual void OnScroll(Point delta);
virtual void OnMouseWheel(int wheel);
virtual void OnInvalidateData(int data, bool gui_scope);
virtual void SetStringParameters(int widget) const;
virtual void OnTick();
virtual void OnPaint();
virtual void OnQueryTextFinished(char *str);
void DrawWidget(const Rect &r, int widget) const override;
void OnClick(Point pt, int widget, int click_count) override;
void OnResize() override;
void OnScroll(Point delta) override;
void OnMouseWheel(int wheel) override;
void OnInvalidateData(int data, bool gui_scope) override;
void SetStringParameters(int widget) const override;
void OnRealtimeTick([[maybe_unused]] uint delta_ms) override;
void OnPaint() override;
void OnQueryTextFinished(char *str) override;

void OnDoCommand(CompanyID company, TileIndex tile);
};
Expand Down
2 changes: 0 additions & 2 deletions src/core/math_func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,4 @@ static inline T DivTowardsPositiveInf(T a, T b)

/* CityMania code end */

uint32 IntSqrt(uint32 num);

#endif /* MATH_FUNC_HPP */
4 changes: 2 additions & 2 deletions src/depot_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ struct DepotWindow : Window {
} else {
/* Arrange unitnumber and flag vertically */
diff_x = 0;
diff_y = WidgetDimensions::scaled.matrix.top + 'GetCharacterHeight(FS_NORMAL)' + WidgetDimensions::scaled.vsep_normal;
diff_y = WidgetDimensions::scaled.matrix.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
}

text = text.WithWidth(this->header_width - WidgetDimensions::scaled.hsep_normal, rtl).WithHeight(GetCharacterHeight(FS_NORMAL)).Indent(diff_x, rtl);
Expand Down Expand Up @@ -1110,7 +1110,7 @@ struct DepotWindow : Window {
return (this->type == VEH_AIRCRAFT) ? ::GetStationIndex(this->window_number) : ::GetDepotIndex(this->window_number);
}

virtual EventState OnHotkey(int hotkey)
EventState OnHotkey(int hotkey) override
{
if (this->owner != _local_company) return ES_NOT_HANDLED;
return Window::OnHotkey(hotkey);
Expand Down
8 changes: 4 additions & 4 deletions src/graph_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow {
this->legend_width = (GetCharacterHeight(FS_SMALL) - ScaleGUITrad(1)) * 8 / 5;
}

virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
if (widget != WID_CPR_MATRIX) {
BaseGraphWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
Expand All @@ -775,7 +775,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow {
fill->height = this->line_height;
}

virtual void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
if (widget != WID_CPR_MATRIX) {
BaseGraphWindow::DrawWidget(r, widget);
Expand Down Expand Up @@ -822,7 +822,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow {
InvalidateWindowData(WC_PAYMENT_RATES, 0);
}

virtual void OnClick(Point pt, int widget, int click_count)
void OnClick([[maybe_unused]] Point pt, [[maybe_unused]] int widget, [[maybe_unused]] int click_count) override
{
switch (widget) {
case WID_GRAPH_KEY_BUTTON:
Expand Down Expand Up @@ -862,7 +862,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow {
}
}

virtual void OnResize()
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_CPR_MATRIX);
}
Expand Down
2 changes: 1 addition & 1 deletion src/industry_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class BuildIndustryWindow : public Window {
this->SetDirty();
}

virtual EventState OnHotkey(int hotkey)
EventState OnHotkey(int hotkey) override
{
switch (hotkey) {
case CM_HOTKEY_SWITCH_LAYOUT:
Expand Down
8 changes: 4 additions & 4 deletions src/rail_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,9 @@ struct BuildRailStationWindow : public PickerWindowBase {
break;

case CM_BRASHK_ROTATE:
this->RaiseWidget(_railstation.orientation + WID_BRAS_PLATFORM_DIR_X);
this->RaiseWidget(WID_BRAS_PLATFORM_DIR_X + _railstation.orientation);
_railstation.orientation = OtherAxis(_railstation.orientation);
this->LowerWidget(_railstation.orientation + WID_BRAS_PLATFORM_DIR_X);
this->LowerWidget(WID_BRAS_PLATFORM_DIR_X + _railstation.orientation);
this->SetDirty();
CloseWindowById(WC_SELECT_STATION, 0);
return ES_HANDLED;
Expand Down Expand Up @@ -2225,9 +2225,9 @@ struct BuildRailDepotWindow : public PickerWindowBase {
* then from a click and that the CTRL state should be ignored. */
case BRDHK_ROTATE:
if (_build_depot_direction < DIAGDIR_END) {
this->RaiseWidget(_build_depot_direction + WID_BRAD_DEPOT_NE);
this->RaiseWidget(WID_BRAD_DEPOT_NE + _build_depot_direction);
_build_depot_direction = ChangeDiagDir(_build_depot_direction, DIAGDIRDIFF_90RIGHT);
this->LowerWidget(_build_depot_direction + WID_BRAD_DEPOT_NE);
this->LowerWidget(WID_BRAD_DEPOT_NE + _build_depot_direction);
} else {
citymania::RotateAutodetection();
}
Expand Down
18 changes: 9 additions & 9 deletions src/town_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ struct TownAuthorityWindow : Window {
}
}

void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
void UpdateWidgetSize(WidgetID widget, Dimension *size, const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
{
switch (widget) {
case WID_TA_ACTION_INFO: {
Expand Down Expand Up @@ -365,7 +365,7 @@ struct TownAuthorityWindow : Window {
}
}

virtual EventState OnHotkey(int hotkey)
EventState OnHotkey(int hotkey) override
{
TownExecuteAction(this->town, hotkey);
return ES_HANDLED;
Expand Down Expand Up @@ -670,7 +670,7 @@ struct TownViewWindow : Window {
Command<CMD_RENAME_TOWN>::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, str);
}

virtual EventState OnHotkey(int hotkey)
EventState OnHotkey(int hotkey) override
{
if(hotkey == WID_TV_CB) ShowCBTownWindow(this->window_number);
else if (hotkey == HK_STATUE + 0x80){
Expand Down Expand Up @@ -1510,7 +1510,7 @@ struct CBTownWindow : Window {
if(HasBit(this->town->advertise_regularly, _local_company)) this->LowerWidget(WID_CB_ADVERT_REGULAR);
}

virtual void OnClick(Point pt, int widget, int click_count)
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
case WID_CB_CENTER_VIEW:
Expand Down Expand Up @@ -1552,7 +1552,7 @@ struct CBTownWindow : Window {
}
}

virtual void OnQueryTextFinished(char *str)
void OnQueryTextFinished(char *str) override
{
if (str != NULL) SetBit(this->town->advertise_regularly, _local_company);
else ClrBit(this->town->advertise_regularly, _local_company);
Expand All @@ -1566,7 +1566,7 @@ struct CBTownWindow : Window {
this->town->ad_rating_goal = ((val << 8) + 255) / 101;
}

virtual void SetStringParameters(int widget) const
void SetStringParameters(int widget) const override
{
if (widget == WID_CB_CAPTION){
SetDParam(0, this->town->index);
Expand Down Expand Up @@ -1623,7 +1623,7 @@ struct CBTownWindow : Window {
}
}

void DrawWidget(const Rect &r, int widget) const
void DrawWidget(const Rect &r, int widget) const override
{
static const uint EXP_LINESPACE = GetCharacterHeight(FS_NORMAL) + 2;
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
Expand Down Expand Up @@ -1788,7 +1788,7 @@ struct CBTownWindow : Window {
/* Citybuilder things enabled*/
}

virtual void OnPaint() {
void OnPaint() override {
if (!this->IsShaded()) {
int plane = CB_Enabled() ? CBTWP_MP_CB : CBTWP_MP_GOALS;
NWidgetStacked *wi = this->GetWidget<NWidgetStacked>(WID_CB_SELECT_REQUIREMENTS);
Expand All @@ -1802,7 +1802,7 @@ struct CBTownWindow : Window {
}


virtual EventState OnHotkey(int hotkey)
EventState OnHotkey(int hotkey) override
{
TownExecuteAction(this->town, hotkey);
return ES_HANDLED;
Expand Down
2 changes: 1 addition & 1 deletion src/video/sdl2_v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ void VideoDriver_SDL_Base::InputLoop()
uint32_t mod = SDL_GetModState();
const Uint8 *keys = SDL_GetKeyboardState(nullptr);

bool old_ctrl_pressed = _ctrl_pressed;
// CM bool old_ctrl_pressed = _ctrl_pressed;

_ctrl_pressed = !!(mod & KMOD_CTRL);
_alt_pressed = !!(mod & KMOD_ALT);
Expand Down
2 changes: 1 addition & 1 deletion src/window_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ enum WindowPopupType {
struct WindowPopup: public Window {
public:
WindowPopup(WindowDesc *desc, WindowPopupType t = WPUT_ORIGIN);
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number);
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override;
protected:
uint wpu_widget; ///< The widget to which the computation would be made from when type is #WPUT_WIDGET_RELATIVE.
int wpu_mod_x; ///< The X axis modifier. A negative value would bring the window closer to the left edge of the screen. Default value is -5.
Expand Down

0 comments on commit f5f570b

Please sign in to comment.