Skip to content

Commit cb1c44f

Browse files
committed
Script API: implement Game.TickCounter
1 parent 56fad9d commit cb1c44f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Editor/AGS.Editor/Resources/agsdefns.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,6 +3248,8 @@ builtin struct Game {
32483248
#ifdef SCRIPT_API_v363
32493249
/// Gets/sets game's running speed, in frames per second.
32503250
import static attribute int Speed;
3251+
/// Gets number of game's ticks (updates) passed since the game start.
3252+
import static readonly attribute int TickCounter;
32513253
#endif // SCRIPT_API_v363
32523254
};
32533255

Engine/ac/game.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,14 @@ void Game_SetTextReadingSpeed(int newTextSpeed)
746746
play.text_speed = newTextSpeed;
747747
}
748748

749+
int Game_GetTickCounter()
750+
{
751+
// Loop counter is uint32, but the script values are int32;
752+
// convert uint32 value into a int32 wrapped in the range of 0 - INT32_MAX.
753+
uint32_t loopcounter = get_loop_counter();
754+
return loopcounter <= INT32_MAX ? static_cast<int32_t>(loopcounter) : static_cast<int32_t>(loopcounter - INT32_MAX);
755+
}
756+
749757
int Game_GetMinimumTextDisplayTimeMs()
750758
{
751759
return play.text_min_display_time_ms;
@@ -2047,6 +2055,11 @@ RuntimeScriptValue Sc_Game_SetTextReadingSpeed(const RuntimeScriptValue *params,
20472055
API_SCALL_VOID_PINT(Game_SetTextReadingSpeed);
20482056
}
20492057

2058+
RuntimeScriptValue Sc_Game_GetTickCounter(const RuntimeScriptValue *params, int32_t param_count)
2059+
{
2060+
API_SCALL_INT(Game_GetTickCounter);
2061+
}
2062+
20502063
// const char* ()
20512064
RuntimeScriptValue Sc_Game_GetTranslationFilename(const RuntimeScriptValue *params, int32_t param_count)
20522065
{
@@ -2242,6 +2255,7 @@ void RegisterGameAPI()
22422255
{ "Game::geti_SpriteHeight", API_FN_PAIR(Game_GetSpriteHeight) },
22432256
{ "Game::get_TextReadingSpeed", API_FN_PAIR(Game_GetTextReadingSpeed) },
22442257
{ "Game::set_TextReadingSpeed", API_FN_PAIR(Game_SetTextReadingSpeed) },
2258+
{ "Game::get_TickCounter", API_FN_PAIR(Game_GetTickCounter) },
22452259
{ "Game::get_TranslationFilename", API_FN_PAIR(Game_GetTranslationFilename) },
22462260
{ "Game::get_UseNativeCoordinates", API_FN_PAIR(Game_GetUseNativeCoordinates) },
22472261
{ "Game::get_ViewCount", API_FN_PAIR(Game_GetViewCount) },

0 commit comments

Comments
 (0)