Skip to content

TIMETYPE rebuilt from the timetype.h line table

11 November 2026. TIMETYPE (in src/openblood/engine_types.h until 22 November, now in src/engine/timetype.h) follows the original timetype.h far enough that sources using time arithmetic can be written the way IOI wrote them.

What the original header holds

Line numbers come from tools/lines.py; the debug record lists the members.

Line Declaration Evidence
19 TIMETYPE(float), secs = value * 1024 constant-folded stores such as 0x4800 for 18.0f
22 to 23 TIMETYPE(), secs = 0 sw $zero at the declaration of a TIMETYPE local or member
26 copy constructor the copies of every by-value result
32 TIMETYPE(int), secs = value << 10 0x1000 stored for + 4 in ZHM3ItemBomb::ClassFrameUpdate, -0x400 for TIMETYPE(-1) in the ZBoneModifyBase constructor
34 to 36 operator= with the early return unchanged
39 operator float unchanged
54 to 60 TIMETYPE + TIMETYPE with locals s1 and t2 debug scopes
69 operator+(const TIMETYPE &, const float) forwards to line 54
72 operator+(const TIMETYPE &, const int) forwards to line 54
77 to 81 TIMETYPE - TIMETYPE
90 operator-(const TIMETYPE &, const float)
97 to 100 TIMETYPE * TIMETYPE with t, t32, t2 64-bit product shifted by 10
109 operator*(const TIMETYPE &, const float) with a named t2 one more copy than the + wrapper
122, 152, 167 TIMETYPE against TIMETYPE comparisons
125, 131, 155, 161, 176 comparisons against float, each forwarding to one of the above

The debug record gives TIMETYPE only constructors, convert, operator=, the three conversion operators and LoadSave as members. Every arithmetic and comparison operator is a free function. Ours still declares + and - between two TIMETYPEs as members; they compile to the same code.

The result type is const

operator+ and operator* return const TIMETYPE. GCC 3.2 refuses to share a stack slot when either type is const-qualified (objects_must_conflict_p in alias.c returns 0 for TYPE_READONLY), so each copy of a sum gets a slot of its own and later temporaries never land in it. With a plain TIMETYPE result the copies of one statement were reused by the next, the frame came out 0x20 or 0x30 smaller, and every stack offset after it differed. That was the whole difference in ZHM3LevelControlM00::Command (3,032 bytes), ZHM3LevelControlM05::Command (1,112 bytes) and ZEditControl::ClassFrameUpdate.

The slot order inside one statement is: the wrapper's result, the inner result, the TIMETYPE(i2) argument, then t2. The argument and t2 are not const and do reuse freed slots, which is how to tell the two kinds apart in a listing.

How to write time code now

  • m_fTime = g_pSysInterface->FrameTime + 18.0f; and tEnd + 4. No TIMETYPE(...) around the sum, no named temporary, no -felide-constructors flag.
  • TIMETYPE(2) is two seconds. Raw fixed-point literals (TIMETYPE(0x800)) are gone; a literal that is not a multiple of 0x400 was a float (0x133 is 0.3f).
  • A float assigned to a TIMETYPE converts implicitly: m_fFallingTime = FrameTime();.
  • Comparisons against a float take the operand order from the source. g_pSysInterface->FrameTime > m_fToggleTime loads g_pSysInterface first; if the original evaluates the float side first, the float is the left operand in the source.
  • !(a < f) gives slt; bnez. a >= f gives slt; xori 1.
  • A struct with a TIMETYPE member zeroes it where the struct is declared. If the original's sw $zero sits later in the function, the declaration sits later too (sUseElevatorInfo EInfo; in the elevator TakeControl functions).
  • FrameTime * 25.0f is now the fixed-point product. Where the original multiplies floats, the source converts first: static_cast<float>(g_pSysInterface->FrameTime) * 25.0f.

The shared header defines the const result types for subtraction and compound assignment, equality tests and mixed comparisons. Use the overload whose operand types and line table agree with the caller.

Method

The GCC 3.2 and 3.2.3 sources (function.c, stmt.c, c-common.c, tree-inline.c, cp/tree.c) are under build/gccsrc. Source permutations had not moved the slots; reading assign_stack_temp_for_type and its callers did. Slot reuse depends on the level a slot was allocated at, on keep, and on the type's qualifiers.

The operator- signature is not a lever, 12 November 2026

ZSoundObject::Exchange (ob_00194174) had a draft scoring 125 whose save-path fade block was 0x20 bytes short, and the suggestion was that the original's TIMETYPE - TIMETYPE took its operand by value, copying both sides into stack slots.

Measured, three forms, same source:

form ob_00194174 score
member operator-(const TIMETYPE &) const (current) 125
member operator-(TIMETYPE) const 295
free operator-(TIMETYPE, TIMETYPE), member removed 363, and the full build breaks two matched functions in zhitman3actions.cpp

So by-value is worse in both spellings, and the free-function form also changes overload resolution for the mixed operators elsewhere. The matching implementation uses the reference form of the operator.