Skip to content

Commit 0ff1596

Browse files
committed
Script API: add GetTimerPos()
1 parent 135bd7b commit 0ff1596

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

Editor/AGS.Editor/Resources/agsdefns.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,10 @@ import void SetSpeechStyle(eSpeechStyle);
12651265
import void SetTimer(int timerID, int timeout);
12661266
/// Returns true the first time this is called after the timer expires.
12671267
import bool IsTimerExpired(int timerID);
1268+
#ifdef SCRIPT_API_v362
1269+
/// Returns the specified timer's time value; returns 0 if timer is not running, and 1 if it's expiring.
1270+
import int GetTimerPos(int timerID);
1271+
#endif
12681272
/// Sets whether the game can continue to run in the background if the player switches to another application.
12691273
import void SetMultitaskingMode (int mode);
12701274
/// Converts a floating point value to an integer.

Engine/ac/global_api.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,11 @@ RuntimeScriptValue Sc_sc_GetTime(const RuntimeScriptValue *params, int32_t param
793793
API_SCALL_INT_PINT(sc_GetTime);
794794
}
795795

796+
RuntimeScriptValue Sc_GetTimerPos(const RuntimeScriptValue *params, int32_t param_count)
797+
{
798+
API_SCALL_INT_PINT(GetTimerPos);
799+
}
800+
796801
// char * (const char *text)
797802
RuntimeScriptValue Sc_get_translation(const RuntimeScriptValue *params, int32_t param_count)
798803
{
@@ -1999,9 +2004,9 @@ RuntimeScriptValue Sc_SetTextWindowGUI(const RuntimeScriptValue *params, int32_t
19992004
}
20002005

20012006
// void (int tnum,int timeout)
2002-
RuntimeScriptValue Sc_script_SetTimer(const RuntimeScriptValue *params, int32_t param_count)
2007+
RuntimeScriptValue Sc_SetTimer(const RuntimeScriptValue *params, int32_t param_count)
20032008
{
2004-
API_SCALL_VOID_PINT2(script_SetTimer);
2009+
API_SCALL_VOID_PINT2(SetTimer);
20052010
}
20062011

20072012
// void (int offsx,int offsy)
@@ -2453,6 +2458,7 @@ void RegisterGlobalAPI(ScriptAPIVersion base_api, ScriptAPIVersion /*compat_api*
24532458
{ "GetFontHeight", API_FN_PAIR(GetFontHeight) },
24542459
{ "GetFontLineSpacing", API_FN_PAIR(GetFontLineSpacing) },
24552460
{ "GetTime", API_FN_PAIR(sc_GetTime) },
2461+
{ "GetTimerPos", API_FN_PAIR(GetTimerPos) },
24562462
{ "GetTranslation", API_FN_PAIR(get_translation) },
24572463
{ "GetTranslationName", API_FN_PAIR(GetTranslationName) },
24582464
{ "GetViewportX", API_FN_PAIR(GetViewportX) },
@@ -2659,7 +2665,7 @@ void RegisterGlobalAPI(ScriptAPIVersion base_api, ScriptAPIVersion /*compat_api*
26592665
{ "SetTextBoxText", API_FN_PAIR(SetTextBoxText) },
26602666
{ "SetTextOverlay", Sc_SetTextOverlay, ScPl_SetTextOverlay },
26612667
{ "SetTextWindowGUI", API_FN_PAIR(SetTextWindowGUI) },
2662-
{ "SetTimer", API_FN_PAIR(script_SetTimer) },
2668+
{ "SetTimer", API_FN_PAIR(SetTimer) },
26632669
{ "SetViewport", API_FN_PAIR(SetViewport) },
26642670
{ "SetVoiceMode", API_FN_PAIR(SetVoiceMode) },
26652671
{ "SetWalkBehindBase", API_FN_PAIR(SetWalkBehindBase) },

Engine/ac/global_timer.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@
1717
#include "ac/gamestate.h"
1818

1919

20-
void script_SetTimer(int tnum,int timeout) {
20+
void SetTimer(int tnum,int timeout)
21+
{
2122
if ((tnum < 1) || (tnum >= MAX_TIMERS))
2223
quit("!StartTimer: invalid timer number");
2324
play.script_timers[tnum] = timeout;
2425
}
2526

26-
int IsTimerExpired(int tnum) {
27+
int GetTimerPos(int tnum)
28+
{
29+
if ((tnum < 1) || (tnum >= MAX_TIMERS))
30+
quit("!IsTimerExpired: invalid timer number");
31+
return play.script_timers[tnum];
32+
}
33+
34+
int IsTimerExpired(int tnum)
35+
{
2736
if ((tnum < 1) || (tnum >= MAX_TIMERS))
2837
quit("!IsTimerExpired: invalid timer number");
2938
if (play.script_timers[tnum] == 1) {

Engine/ac/global_timer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
//
1313
//=============================================================================
1414
//
15-
//
15+
// Timer script API.
1616
//
1717
//=============================================================================
1818
#ifndef __AGS_EE_AC__GLOBALTIMER_H
1919
#define __AGS_EE_AC__GLOBALTIMER_H
2020

21-
void script_SetTimer(int tnum,int timeout);
21+
void SetTimer(int tnum, int timeout);
22+
int GetTimerPos(int tnum);
2223
int IsTimerExpired(int tnum);
2324

2425
#endif // __AGS_EE_AC__GLOBALTIMER_H

0 commit comments

Comments
 (0)