@@ -24,13 +24,13 @@
#include "safeguards.h"
Year _cur_year; ///< Current year, starting at 0
Month _cur_month; ///< Current month (0..11)
Date _date; ///< Current date in days (day counter)
DateFract _date_fract; ///< Fractional part of the day.
uint16 _tick_counter; ///< Ever incrementing (and sometimes wrapping) tick counter for setting off various events
uint64 _tick_counter; ///< Ever incrementing tick counter for setting off various events
/**
* Set the date.
* @param date New date
* @param fract The number of ticks that have passed on this date.
*/
@@ -13,13 +13,13 @@
#include "date_type.h"
extern Year _cur_year;
extern Month _cur_month;
extern Date _date;
extern DateFract _date_fract;
extern uint16 _tick_counter;
extern uint64 _tick_counter;
void SetDate(Date date, DateFract fract);
void ConvertDateToYMD(Date date, YearMonthDay *ymd);
Date ConvertYMDToDate(Year year, Month month, Day day);
@@ -78,13 +78,13 @@ struct LoggedChange {
/** Contains information about one logged action that caused at least one logged change */
struct LoggedAction {
LoggedChange *change; ///< First logged change in this action
uint32 changes; ///< Number of changes in this action
GamelogActionType at; ///< Type of action
uint16 tick; ///< Tick when it happened
uint64 tick; ///< Tick when it happened
};
extern LoggedAction *_gamelog_action;
extern uint _gamelog_actions;
#endif /* GAMELOG_INTERNAL_H */
@@ -6310,13 +6310,13 @@ bool GetGlobalVariable(byte param, uint3
case 0x09: // date fraction
*value = _date_fract * 885;
return true;
case 0x0A: // animation counter
*value = _tick_counter;
*value = GB(_tick_counter, 0, 16);
case 0x0B: { // TTDPatch version
uint major = 2;
uint minor = 6;
uint revision = 1; // special case: 2.0.1 is 2.0.10
@@ -9811,13 +9811,13 @@ void LoadNewGRF(uint load_index, uint nu
* so all NewGRFs are loaded equally. For this we use the
* start date of the game and we set the counters, etc. to
* 0 so they're the same too. */
Date date = _date;
Year year = _cur_year;
DateFract date_fract = _date_fract;
uint16 tick_counter = _tick_counter;
uint64 tick_counter = _tick_counter;
byte display_opt = _display_opt;
if (_networking) {
_cur_year = _settings_game.game_creation.starting_year;
_date = ConvertYMDToDate(_cur_year, 0, 1);
_date_fract = 0;
@@ -50,13 +50,13 @@ struct AnimationBase {
}
/* An animation speed of 2 means the animation frame changes 4 ticks, and
* increasing this value by one doubles the wait. 0 is the minimum value
* allowed for animation_speed, which corresponds to 30ms, and 16 is the
* maximum, corresponding to around 33 minutes. */
if (_tick_counter % (1 << animation_speed) != 0) return;
if (_tick_counter % (1ULL << animation_speed) != 0) return;
uint8 frame = GetAnimationFrame(tile);
uint8 num_frames = spec->animation.frames;
bool frame_set_by_callback = false;
@@ -106,13 +106,13 @@ uint32 NewGRFProfiler::Finish()
FileCloser fcloser(f);
uint32 total_microseconds = 0;
fputs("Tick,Sprite,Feature,Item,CallbackID,Microseconds,Depth,Result\n", f);
for (const Call &c : this->calls) {
fprintf(f, "%u,%u,0x%X,%u,0x%X,%u,%u,%u\n", c.tick, c.root_sprite, c.feat, c.item, (uint)c.cb, c.time, c.subs, c.result);
fprintf(f, OTTD_PRINTF64U ",%u,0x%X,%u,0x%X,%u,%u,%u\n", c.tick, c.root_sprite, c.feat, c.item, (uint)c.cb, c.time, c.subs, c.result);
total_microseconds += c.time;
this->Abort();
return total_microseconds;
@@ -138,13 +138,13 @@ std::string NewGRFProfiler::GetOutputFil
return std::string(filepath);
uint32 NewGRFProfiler::FinishAll()
{
int max_ticks = 0;
uint64 max_ticks = 0;
for (NewGRFProfiler &pr : _newgrf_profilers) {
if (pr.active) {
total_microseconds += pr.Finish();
max_ticks = std::max(max_ticks, _tick_counter - pr.start_tick);
@@ -42,20 +42,20 @@ struct NewGRFProfiler {
struct Call {
uint32 root_sprite; ///< Pseudo-sprite index in GRF file
uint32 item; ///< Local ID of item being resolved for
uint32 result; ///< Result of callback
uint32 subs; ///< Sub-calls to other sprite groups
uint32 time; ///< Time taken for resolution (microseconds)
uint16 tick; ///< Game tick
uint64 tick; ///< Game tick
CallbackID cb; ///< Callback ID
GrfSpecFeature feat; ///< GRF feature being resolved for
const GRFFile *grffile; ///< Which GRF is being profiled
bool active; ///< Is this profiler collecting data
uint16 start_tick; ///< Tick number this profiler was started on
uint64 start_tick; ///< Tick number this profiler was started on
Call cur_call; ///< Data for current call in progress
std::vector<Call> calls; ///< All calls collected so far
extern std::vector<NewGRFProfiler> _newgrf_profilers;
extern Date _newgrf_profile_end_date;
@@ -341,13 +341,14 @@ public:
void LoadCheck(LoggedAction *la) const override { this->Load(la); }
static const SaveLoad _gamelog_desc[] = {
SLE_CONDVAR(LoggedAction, at, SLE_UINT8, SLV_RIFF_TO_ARRAY, SL_MAX_VERSION),
SLE_VAR(LoggedAction, tick, SLE_UINT16),
SLE_CONDVAR(LoggedAction, tick, SLE_FILE_U16 | SLE_VAR_U64, SL_MIN_VERSION, SLV_U64_TICK_COUNTER),
SLE_CONDVAR(LoggedAction, tick, SLE_UINT64, SLV_U64_TICK_COUNTER, SL_MAX_VERSION),
SLEG_STRUCTLIST("action", SlGamelogAction),
struct GLOGChunkHandler : ChunkHandler {
GLOGChunkHandler() : ChunkHandler('GLOG', CH_TABLE) {}
@@ -71,13 +71,14 @@ void ResetViewportAfterLoadGame()
byte _age_cargo_skip_counter; ///< Skip aging of cargo? Used before savegame version 162.
static const SaveLoad _date_desc[] = {
SLEG_CONDVAR("date", _date, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
SLEG_CONDVAR("date", _date, SLE_INT32, SLV_31, SL_MAX_VERSION),
SLEG_VAR("date_fract", _date_fract, SLE_UINT16),
SLEG_VAR("tick_counter", _tick_counter, SLE_UINT16),
SLEG_CONDVAR("tick_counter", _tick_counter, SLE_FILE_U16 | SLE_VAR_U64, SL_MIN_VERSION, SLV_U64_TICK_COUNTER),
SLEG_CONDVAR("tick_counter", _tick_counter, SLE_UINT64, SLV_U64_TICK_COUNTER, SL_MAX_VERSION),
SLEG_CONDVAR("age_cargo_skip_counter", _age_cargo_skip_counter, SLE_UINT8, SL_MIN_VERSION, SLV_162),
SLEG_CONDVAR("cur_tileloop_tile", _cur_tileloop_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
SLEG_CONDVAR("cur_tileloop_tile", _cur_tileloop_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
SLEG_VAR("next_disaster_start", _disaster_delay, SLE_UINT16),
SLEG_VAR("random_state[0]", _random.state[0], SLE_UINT32),
SLEG_VAR("random_state[1]", _random.state[1], SLE_UINT32),
@@ -1606,13 +1606,13 @@ static const OldChunks main_chunk[] = {
OCL_NULL( 4 ), ///< town counter, no longer in use
OCL_NULL( 2 ), ///< timer_counter, no longer in use
OCL_NULL( 2 ), ///< land_code, no longer in use
OCL_VAR ( OC_FILE_U16 | OC_VAR_U8, 1, &_age_cargo_skip_counter ),
OCL_VAR ( OC_UINT16, 1, &_tick_counter ),
OCL_VAR ( OC_FILE_U16 | OC_VAR_U64, 1, &_tick_counter ),
OCL_VAR ( OC_TILE, 1, &_cur_tileloop_tile ),
OCL_ASSERT( OC_TTO, 0x3A2E ),
OCL_CNULL( OC_TTO, 48 * 6 ), ///< prices
OCL_CNULL( OC_TTD, 49 * 6 ), ///< prices
@@ -337,12 +337,13 @@ enum SaveLoadVersion : uint16 {
SLV_TABLE_CHUNKS, ///< 295 PR#9322 Introduction of CH_TABLE and CH_SPARSE_TABLE.
SLV_SCRIPT_INT64, ///< 296 PR#9415 SQInteger is 64bit but was saved as 32bit.
SLV_LINKGRAPH_TRAVEL_TIME, ///< 297 PR#9457 v12.0-RC1 Store travel time in the linkgraph.
SLV_DOCK_DOCKINGTILES, ///< 298 PR#9578 All tiles around docks may be docking tiles.
SLV_REPAIR_OBJECT_DOCKING_TILES, ///< 299 PR#9594 v12.0 Fixing issue with docking tiles overlapping objects.
SLV_U64_TICK_COUNTER, ///< 300 PR#10035 Make _tick_counter 64bit to avoid wrapping.
SL_MAX_VERSION, ///< Highest possible saveload version
/** Save or load result codes. */
enum SaveOrLoadResult {
@@ -300,19 +300,27 @@
#else
# define PACK_N(type_dec, n) type_dec __attribute__((__packed__, aligned(n)))
#endif
#define PACK(type_dec) PACK_N(type_dec, 1)
/* MSVCRT of course has to have a different syntax for long long *sigh* */
#if defined(_MSC_VER) || defined(__MINGW32__)
#if defined(_MSC_VER)
# define OTTD_PRINTF64 "%I64d"
# define OTTD_PRINTF64U "%I64u"
# define OTTD_PRINTFHEX64 "%I64x"
# define PRINTF_SIZE "%Iu"
# define PRINTF_SIZEX "%IX"
#elif defined(__MINGW32__)
# define OTTD_PRINTF64U "%I64llu"
# define OTTD_PRINTF64 "%lld"
# define OTTD_PRINTF64U "%llu"
# define OTTD_PRINTFHEX64 "%llx"
# define PRINTF_SIZE "%zu"
# define PRINTF_SIZEX "%zX"
typedef unsigned char byte;
Status change: