Jump to content

Time: Difference between revisions

From OpenBOR
Line 97: Line 97:


=== Script API ===
=== Script API ===
Get Elapsed time.<syntaxhighlight lang="c" line="1">
 
==== Get Elapsed Time ====
<syntaxhighlight lang="c" line="1">
int elapsed_time = openborvariant("elapsed_time");
int elapsed_time = openborvariant("elapsed_time");
</syntaxhighlight>Set elapsed time. Be careful about setting elapsed time during game-play, as again, virtually every active game timing property depends on it.<syntaxhighlight lang="c" line="1">
</syntaxhighlight>
 
==== Set Elapsed Time ====
Be careful about setting elapsed time during game-play, as again, virtually every active game timing property depends on it.<syntaxhighlight lang="c" line="1">
int new_time = 100
int new_time = 100


Line 108: Line 113:
Ticks is a read only measure of milliseconds starting from game boot. OpenBOR natively uses ticks for the player input recording feature and for timing during load screens. Ticks therefore do not generally affect active game-play, but are useful for user content, scripting, and keeping time outside of active game-play elements when increments are not natively incremented.  
Ticks is a read only measure of milliseconds starting from game boot. OpenBOR natively uses ticks for the player input recording feature and for timing during load screens. Ticks therefore do not generally affect active game-play, but are useful for user content, scripting, and keeping time outside of active game-play elements when increments are not natively incremented.  


* <code>openborvariant("ticks")</code> - Get integer milliseconds from game boot.
=== Script API ===
 
==== Get Ticks ====
<syntaxhighlight lang="c" line="1">
int ticks = openborvariant("ticks");
</syntaxhighlight>
 
== System Time ==
System time is entirely optional and provided for creator defined script use. It is not accessed by native engine logic in any way. System is available as a Unix timestamp in either seconds or milliseconds where supported by hardware. Conversion functions allow outputting a custom formatted string or time parts as integer values for use in logic expressions.


Script API
[[Category:Script]]
[[Category:Script]]
[[Category:OpenBOR Index]]
[[Category:OpenBOR Index]]

Revision as of 17:52, 12 July 2026

Introduction

Timing is crucial to OpenBOR, as it is to most game engines. Understanding how the engine measures time, and how those measurements affect a project, is therefore essential.

OpenBOR’s primary gameplay timing unit is one-half of a centisecond, equivalent to 5 milliseconds. Animation delays, for example, are expressed as integer increments of 0.5 centiseconds. Legacy documentation often refers to these increments as centiseconds, though each increment is technically only half a centisecond. Other units are used where appropriate for particular features, circumstances, or design requirements.

Time in OpenBOR is represented by the following primary definitions:

Game Time: The traditional beat ’em up countdown timer used to maintain the pace of a level. When Game Time expires, players ordinarily lose a life. Game Time is enabled by default, though creators may disable, remove, or otherwise modify it.

Elapsed Time: An integer value reset at the beginning of each active level and incremented once for every processed logical tick. OpenBOR processes 200 logical ticks per second, making each Elapsed Time increment equal to 5 milliseconds, or one-half of a centisecond. Elapsed Time drives much of the engine’s internal timing, including animations, delays, effect durations, and other gameplay processes.

Ticks: The number of milliseconds elapsed since the engine timer began. Tick values are independent of the active level and may be used for timing operations both inside and outside gameplay, including loading processes, recorded player input, and custom script timers. Ticks are generally preferable to manually incrementing a script variable when timing must remain independent of script execution frequency.

System Time: OpenBOR’s scripting system includes an API for accessing the host system clock and obtaining real-world dates and times. System Time access is entirely optional and does not affect native engine timing or gameplay functionality.

OpenBOR exposes several types of time, including world time and time elapsed since startup.

Game Time

Game time is a default countdown timer that appears at top center of the screen during an active level. It starts at 99 and decrements once every two real world seconds. At 0, all active players take damage equal to their current HP, and the game is over if no lives or credits remain. Time resets automatically when players clear a designated level wait and at the start of each new level.

Batman Savage Dawn screenshot.
The Batman Savage Dawn fan game demonstrates OpenBOR's default game timer in action at top center of the screen.

Set Time

settime {int time}

#default
settime 99

Level header command that sets value applied to timer on level start and native resets.

  • Accepts any integer value from 0 to 99. Out of bounds values are ignored.
  • 0 = infinite time.

HUD Display

For configuring how timer displays on screen, see Heads Up Display.

Other

data/sounds/timeover.wav

If available, plays once when the game timer expires.

anim lose

If available, entity plays this animation in place of normal death when game timer expires.

  • Accessible to script as openborconstant("ANI_LOSE").

anim falllose

If available and entity does not have a lose animation, entity plays this animation in place of normal fall death when game timer expires.

  • Accessible to script as openborconstant("ANI_FALLLOSE").

Attack types

Attack types applied to players when game time expires.

  • openborconstant("ATK_TIMEOVER") - Applied to players without a lose animation.
  • openborconstant("ATK_LOSE") - Applied to players with a lose animation.

Script API

Game Time

Current game time is read and write accessible.

Get
int time = openborvariant("game_time");

Get integer representing game time remaining.

Set
int new_time = 50;

setopenborvariat("game_time", new_time);

Set game time remaining.

Timetick Event

If available, data/scripts/timetick.c fires on each game time decrement. Populates the following local variables.

  • time - Current game time value.

Elapsed Time

In terms of game mechanics, elapsed time is the most important and frequently employed time measurement as it represents OpenBOR's logical clock, though its implementation is relatively simple. For each level, a global elapsed-time counter begins at 0. OpenBOR’s logical clock runs at 200 ticks per second, and the counter increments by 1 for every processed logic tick.

Each logical tick represents 5 milliseconds, or one-half of a centisecond. Therefore, two elapsed-time ticks equal one centisecond, while 200 ticks equal one second.

OpenBOR’s logical clock is separate from its outer update and rendering rate. Depending on the selected FPS setting and display synchronization, the engine may run its outer update cycle more frequently than 200 times per second. Available FPS settings include VSync, limits of 200 or 500 FPS, and an unrestricted option.

Some operations, including the global update.c and updated.c script events, execute once per outer update cycle. These scripts may therefore run more frequently than the 200 Hz logical clock. Other operations, such as entity simulation and entity update scripts, execute according to logical ticks.

OpenBOR also keeps logical timing independent from individual rendered frames. This allows the engine to maintain consistent gameplay timing across different FPS settings. Under unusual performance conditions, the engine may process more than one logical tick during an outer update to keep elapsed time synchronized, though this is rarely noticeable in normal use.

Creators should use elapsed time rather than counting script executions when measuring durations.

Most internal timing works by setting an expiration value to the current elapsed time plus a predetermined duration. The engine then compares that expiration value against the elapsed-time counter. Once elapsed time reaches or passes the expiration value, the timed item may complete, expire, continue, or perform whatever other action its system requires.

Note: In case it matters, the current elapsed time variable is a 32bit unsigned integer. That's enough to run a single level continuously for just over eight months before rolling over.

Script API

Get Elapsed Time

int elapsed_time = openborvariant("elapsed_time");

Set Elapsed Time

Be careful about setting elapsed time during game-play, as again, virtually every active game timing property depends on it.

int new_time = 100

setopenborvariant("elapsed_time", new_time);

Ticks

Ticks is a read only measure of milliseconds starting from game boot. OpenBOR natively uses ticks for the player input recording feature and for timing during load screens. Ticks therefore do not generally affect active game-play, but are useful for user content, scripting, and keeping time outside of active game-play elements when increments are not natively incremented.

Script API

Get Ticks

int ticks = openborvariant("ticks");

System Time

System time is entirely optional and provided for creator defined script use. It is not accessed by native engine logic in any way. System is available as a Unix timestamp in either seconds or milliseconds where supported by hardware. Conversion functions allow outputting a custom formatted string or time parts as integer values for use in logic expressions.

Script API