Replace DATE_UNIT_SIZE macro with a function

pull/647/head
Jonathan G Rennison 3 months ago
parent d39236d50c
commit d456f4a3a5

@ -101,6 +101,15 @@ inline DateTicks NowDateTicks()
return DateToDateTicks(_date, _date_fract); return DateToDateTicks(_date, _date_fract);
} }
inline Ticks TimetableDisplayUnitSize()
{
if (_settings_time.time_in_minutes) {
return _settings_time.ticks_per_minute;
} else {
return DAY_TICKS * _settings_game.economy.day_length_factor;
}
}
struct debug_date_dumper { struct debug_date_dumper {
const char *HexDate(Date date, DateFract date_fract, uint8_t tick_skip_counter); const char *HexDate(Date date, DateFract date_fract, uint8_t tick_skip_counter);

@ -137,8 +137,6 @@ struct TickMinuteOperations {
/* The type to store StateTicks-based minutes in */ /* The type to store StateTicks-based minutes in */
using TickMinutes = StrongType::Typedef<int64_t, struct TickMinutesTag, StrongType::Compare, StrongType::Integer, MinuteOperations<true>, TickMinuteOperations>; using TickMinutes = StrongType::Typedef<int64_t, struct TickMinutesTag, StrongType::Compare, StrongType::Integer, MinuteOperations<true>, TickMinuteOperations>;
#define DATE_UNIT_SIZE (_settings_time.time_in_minutes ? _settings_time.ticks_per_minute : (DAY_TICKS * _settings_game.economy.day_length_factor))
static const int STATION_RATING_TICKS = 185; ///< cycle duration for updating station rating static const int STATION_RATING_TICKS = 185; ///< cycle duration for updating station rating
static const int STATION_ACCEPTANCE_TICKS = 250; ///< cycle duration for updating station acceptance static const int STATION_ACCEPTANCE_TICKS = 250; ///< cycle duration for updating station acceptance
static const int STATION_LINKGRAPH_TICKS = 504; ///< cycle duration for cleaning dead links static const int STATION_LINKGRAPH_TICKS = 504; ///< cycle duration for cleaning dead links

@ -928,7 +928,7 @@ void DeparturesWindow<Twaypoint>::DrawDeparturesListItems(const Rect &r) const
/* The vehicle has been cancelled. */ /* The vehicle has been cancelled. */
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_CANCELLED); DrawString(status_left, status_right, y + 1, STR_DEPARTURES_CANCELLED);
} else{ } else{
if (d->lateness <= DATE_UNIT_SIZE && d->scheduled_tick > now_date) { if (d->lateness <= TimetableDisplayUnitSize() && d->scheduled_tick > now_date) {
/* We have no evidence that the vehicle is late, so assume it is on time. */ /* We have no evidence that the vehicle is late, so assume it is on time. */
DrawString(status_left, status_right, y + 1, STR_DEPARTURES_ON_TIME); DrawString(status_left, status_right, y + 1, STR_DEPARTURES_ON_TIME);
} else { } else {

@ -92,8 +92,10 @@ struct Departure {
if (this->calling_at[i] != d.calling_at[i]) return false; if (this->calling_at[i] != d.calling_at[i]) return false;
} }
const Ticks timetable_unit_size = TimetableDisplayUnitSize();
return return
(this->scheduled_tick.base() / DATE_UNIT_SIZE) == (d.scheduled_tick.base() / DATE_UNIT_SIZE) && (this->scheduled_tick.base() / timetable_unit_size) == (d.scheduled_tick.base() / timetable_unit_size) &&
this->vehicle->type == d.vehicle->type && this->vehicle->type == d.vehicle->type &&
this->via == d.via && this->via == d.via &&
this->via2 == d.via2 && this->via2 == d.via2 &&

@ -2591,7 +2591,7 @@ public:
case OCV_TIMETABLE: case OCV_TIMETABLE:
value = order->GetXData(); value = order->GetXData();
if (!_settings_client.gui.timetable_in_ticks) value /= DATE_UNIT_SIZE; if (!_settings_client.gui.timetable_in_ticks) value /= TimetableDisplayUnitSize();
break; break;
case OCV_CARGO_WAITING_AMOUNT: case OCV_CARGO_WAITING_AMOUNT:
@ -3191,7 +3191,7 @@ public:
case OCV_TIMETABLE: case OCV_TIMETABLE:
value = order->GetXData(); value = order->GetXData();
if (!_settings_client.gui.timetable_in_ticks) { if (!_settings_client.gui.timetable_in_ticks) {
value /= DATE_UNIT_SIZE; value /= TimetableDisplayUnitSize();
charset_filter = CS_NUMERAL_DECIMAL; charset_filter = CS_NUMERAL_DECIMAL;
} }
break; break;

@ -896,7 +896,7 @@ struct SchdispatchWindow : GeneralVehicleWindow {
int32_t ProcessDurationForQueryString(int32_t duration) const int32_t ProcessDurationForQueryString(int32_t duration) const
{ {
if (!_settings_client.gui.timetable_in_ticks) duration = RoundDivSU(duration, DATE_UNIT_SIZE); if (!_settings_client.gui.timetable_in_ticks) duration = RoundDivSU(duration, TimetableDisplayUnitSize());
return duration; return duration;
} }

@ -1587,10 +1587,10 @@ static void FormatString(StringBuilder builder, const char *str_arg, StringParam
FormatString(builder, GetStringPtr(STR_UNITS_TICKS), tmp_params); FormatString(builder, GetStringPtr(STR_UNITS_TICKS), tmp_params);
} else { } else {
StringID str = _settings_time.time_in_minutes ? STR_TIMETABLE_MINUTES : STR_UNITS_DAYS; StringID str = _settings_time.time_in_minutes ? STR_TIMETABLE_MINUTES : STR_UNITS_DAYS;
int64_t ticks = args.GetNextParameter<int64_t>(); const int64_t ticks = args.GetNextParameter<int64_t>();
int64_t ratio = DATE_UNIT_SIZE; const int64_t ratio = TimetableDisplayUnitSize();
int64_t units = ticks / ratio; const int64_t units = ticks / ratio;
int64_t leftover = _settings_client.gui.timetable_leftover_ticks ? ticks % ratio : 0; const int64_t leftover = _settings_client.gui.timetable_leftover_ticks ? ticks % ratio : 0;
auto tmp_params = MakeParameters(units); auto tmp_params = MakeParameters(units);
FormatString(builder, GetStringPtr(str), tmp_params); FormatString(builder, GetStringPtr(str), tmp_params);
if (b == SCC_TT_TICKS_LONG && _settings_time.time_in_minutes && units > 59) { if (b == SCC_TT_TICKS_LONG && _settings_time.time_in_minutes && units > 59) {

@ -73,7 +73,7 @@ Ticks ParseTimetableDuration(const char *str)
char tmp_buffer[64]; char tmp_buffer[64];
strecpy(tmp_buffer, str, lastof(tmp_buffer)); strecpy(tmp_buffer, str, lastof(tmp_buffer));
str_replace_wchar(tmp_buffer, lastof(tmp_buffer), GetDecimalSeparatorChar(), '.'); str_replace_wchar(tmp_buffer, lastof(tmp_buffer), GetDecimalSeparatorChar(), '.');
return atof(tmp_buffer) * DATE_UNIT_SIZE; return atof(tmp_buffer) * TimetableDisplayUnitSize();
} }
/** /**
@ -747,7 +747,8 @@ struct TimetableWindow : GeneralVehicleWindow {
Dimension lock_d = GetSpriteSize(SPR_LOCK); Dimension lock_d = GetSpriteSize(SPR_LOCK);
int line_height = std::max<int>(GetCharacterHeight(FS_NORMAL), lock_d.height); int line_height = std::max<int>(GetCharacterHeight(FS_NORMAL), lock_d.height);
bool show_late = this->show_expected && v->lateness_counter > DATE_UNIT_SIZE; const Ticks timetable_unit_size = TimetableDisplayUnitSize();
bool show_late = this->show_expected && v->lateness_counter >= timetable_unit_size;
Ticks offset = show_late ? 0 : -v->lateness_counter; Ticks offset = show_late ? 0 : -v->lateness_counter;
bool rtl = _current_text_dir == TD_RTL; bool rtl = _current_text_dir == TD_RTL;
@ -803,7 +804,7 @@ struct TimetableWindow : GeneralVehicleWindow {
/* We aren't running on a timetable yet, so how can we be "on time" /* We aren't running on a timetable yet, so how can we be "on time"
* when we aren't even "on service"/"on duty"? */ * when we aren't even "on service"/"on duty"? */
DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED); DrawString(tr, STR_TIMETABLE_STATUS_NOT_STARTED);
} else if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / DATE_UNIT_SIZE == 0)) { } else if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / TimetableDisplayUnitSize() == 0)) {
DrawString(tr, STR_TIMETABLE_STATUS_ON_TIME); DrawString(tr, STR_TIMETABLE_STATUS_ON_TIME);
} else { } else {
SetTimetableParams(0, abs(v->lateness_counter)); SetTimetableParams(0, abs(v->lateness_counter));
@ -924,7 +925,7 @@ struct TimetableWindow : GeneralVehicleWindow {
if (order != nullptr) { if (order != nullptr) {
uint time = (selected % 2 != 0) ? order->GetTravelTime() : order->GetWaitTime(); uint time = (selected % 2 != 0) ? order->GetTravelTime() : order->GetWaitTime();
if (!_settings_client.gui.timetable_in_ticks) time /= DATE_UNIT_SIZE; if (!_settings_client.gui.timetable_in_ticks) time /= TimetableDisplayUnitSize();
if (time != 0) { if (time != 0) {
SetDParam(0, time); SetDParam(0, time);

@ -1957,7 +1957,7 @@ void BaseVehicleListWindow::DrawVehicleListItems(VehicleID selected_vehicle, int
} }
case VST_TIMETABLE_DELAY: { case VST_TIMETABLE_DELAY: {
if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / DATE_UNIT_SIZE == 0)) { if (v->lateness_counter == 0 || (!_settings_client.gui.timetable_in_ticks && v->lateness_counter / TimetableDisplayUnitSize() == 0)) {
str = STR_VEHICLE_LIST_TIMETABLE_DELAY_ON_TIME; str = STR_VEHICLE_LIST_TIMETABLE_DELAY_ON_TIME;
} else { } else {
str = v->lateness_counter > 0 ? STR_VEHICLE_LIST_TIMETABLE_DELAY_LATE : STR_VEHICLE_LIST_TIMETABLE_DELAY_EARLY; str = v->lateness_counter > 0 ? STR_VEHICLE_LIST_TIMETABLE_DELAY_LATE : STR_VEHICLE_LIST_TIMETABLE_DELAY_EARLY;

Loading…
Cancel
Save