diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-11-04 00:10:13 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-12-16 22:28:32 +0100 |
commit | 2637c06f88ed6f9dea55449883f42a62c30f19d8 (patch) | |
tree | d54f06200b16c0c51b40cce65242e3099c8b4b7c /src/timetable_gui.cpp | |
parent | 211c630cbe4185a2adf8b8cd8f52ca58f8bf17ed (diff) | |
download | openttd-2637c06f88ed6f9dea55449883f42a62c30f19d8.tar.xz |
Codechange: Un-bitstuff timetable commands.
Diffstat (limited to 'src/timetable_gui.cpp')
-rw-r--r-- | src/timetable_gui.cpp | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 12c391487..9a09bce36 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -23,6 +23,7 @@ #include "vehicle_gui.h" #include "settings_type.h" #include "timetable_cmd.h" +#include <cstdint> #include "widgets/timetable_widget.h" @@ -141,9 +142,9 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID * @param w the window related to the setting of the date * @param date the actually chosen date */ -static void ChangeTimetableStartCallback(const Window *w, Date date) +static void ChangeTimetableStartCallback(const Window *w, Date date, void *data) { - Command<CMD_SET_TIMETABLE_START>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, 0, w->window_number, date, {}); + Command<CMD_SET_TIMETABLE_START>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, (VehicleID)w->window_number, reinterpret_cast<std::uintptr_t>(data) != 0, date); } @@ -502,14 +503,14 @@ struct TimetableWindow : Window { } } - static inline uint32 PackTimetableArgs(const Vehicle *v, uint selected, bool speed) + static inline std::tuple<VehicleOrderID, ModifyTimetableFlags> PackTimetableArgs(const Vehicle *v, uint selected, bool speed) { uint order_number = (selected + 1) / 2; ModifyTimetableFlags mtf = (selected % 2 == 1) ? (speed ? MTF_TRAVEL_SPEED : MTF_TRAVEL_TIME) : MTF_WAIT_TIME; if (order_number >= v->GetNumOrders()) order_number = 0; - return v->index | (order_number << 20) | (mtf << 28); + return { order_number, mtf }; } void OnClick(Point pt, int widget, int click_count) override @@ -530,7 +531,7 @@ struct TimetableWindow : Window { } case WID_VT_START_DATE: // Change the date that the timetable starts. - ShowSetDateWindow(this, v->index | (v->orders.list->IsCompleteTimetable() && _ctrl_pressed ? 1U << 20 : 0), _date, _cur_year, _cur_year + 15, ChangeTimetableStartCallback); + ShowSetDateWindow(this, v->index, _date, _cur_year, _cur_year + 15, ChangeTimetableStartCallback, reinterpret_cast<void *>(static_cast<uintptr_t>(v->orders.list->IsCompleteTimetable() && _ctrl_pressed))); break; case WID_VT_CHANGE_TIME: { // "Wait For" button. @@ -578,26 +579,23 @@ struct TimetableWindow : Window { } case WID_VT_CLEAR_TIME: { // Clear waiting time. - uint32 p1 = PackTimetableArgs(v, this->sel_index, false); - Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, 0, p1, 0, {}); + auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, false); + Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, 0); break; } case WID_VT_CLEAR_SPEED: { // Clear max speed button. - uint32 p1 = PackTimetableArgs(v, this->sel_index, true); - Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, 0, p1, UINT16_MAX, {}); + auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, true); + Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, UINT16_MAX); break; } case WID_VT_RESET_LATENESS: // Reset the vehicle's late counter. - Command<CMD_SET_VEHICLE_ON_TIME>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, 0, v->index, 0, {}); + Command<CMD_SET_VEHICLE_ON_TIME>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index); break; case WID_VT_AUTOFILL: { // Autofill the timetable. - uint32 p2 = 0; - if (!HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(p2, 0); - if (_ctrl_pressed) SetBit(p2, 1); - Command<CMD_AUTOFILL_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, 0, v->index, p2, {}); + Command<CMD_AUTOFILL_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, !HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE), _ctrl_pressed); break; } @@ -619,8 +617,6 @@ struct TimetableWindow : Window { const Vehicle *v = this->vehicle; - uint32 p1 = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query); - uint64 val = StrEmpty(str) ? 0 : strtoul(str, nullptr, 10); if (this->query_is_speed_query) { val = ConvertDisplaySpeedToKmhishSpeed(val); @@ -628,9 +624,8 @@ struct TimetableWindow : Window { if (!_settings_client.gui.timetable_in_ticks) val *= DAY_TICKS; } - uint32 p2 = std::min<uint32>(val, UINT16_MAX); - - Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, 0, p1, p2, {}); + auto [order_id, mtf] = PackTimetableArgs(v, this->sel_index, this->query_is_speed_query); + Command<CMD_CHANGE_TIMETABLE>::Post(STR_ERROR_CAN_T_TIMETABLE_VEHICLE, v->index, order_id, mtf, std::min<uint32>(val, UINT16_MAX)); } void OnResize() override |