Skip to content

Commit 8924328

Browse files
committed
Script API: expand properties describing blocking action and wait state
- Split InBlockingWait into InBlockingWait and InBlockingAction. - Add BlockingWaitCounter and BlockingWaitSkipType.
1 parent 4009f25 commit 8924328

File tree

6 files changed

+71
-6
lines changed

6 files changed

+71
-6
lines changed

Editor/AGS.Editor/Resources/agsdefns.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3246,14 +3246,20 @@ builtin struct Game {
32463246
import static int[] GetSaveSlots(int min_slot, int max_slot, SaveGameSortStyle saveSortStyle = eSaveGameSort_None, SortDirection sortDirection = eSortNoDirection);
32473247
/// Prescans save slots from "min_slot" to "max_slot" and fills the compatible ones into the provided dynamic array.
32483248
import static void ScanSaveSlots(int valid_slots[], int min_slot, int max_slot, SaveGameSortStyle saveSortStyle = eSaveGameSort_None, SortDirection sortDirection = eSortNoDirection, int user_param = 0);
3249-
/// Gets whether the game is currently in a blocking state, that is during a blocking action or a Wait() call.
3249+
/// Gets whether the game is currently running inside a Wait() call.
32503250
import static readonly attribute bool InBlockingWait;
32513251
#endif // SCRIPT_API_v362
32523252
#ifdef SCRIPT_API_v363
32533253
/// Gets/sets game's running speed, in frames per second.
32543254
import static attribute int Speed;
32553255
/// Gets number of game's ticks (updates) passed since the game start.
32563256
import static readonly attribute int TickCounter;
3257+
/// Gets whether the game is currently in a blocking state, that is during any blocking action or a Wait() call.
3258+
import static readonly attribute bool InBlockingAction;
3259+
/// Gets the current blocking wait's counter, telling how much time is remaining until the waiting ends.
3260+
import static readonly attribute int BlockingWaitCounter;
3261+
/// Gets the current blocking wait's skip type.
3262+
import static readonly attribute InputType BlockingWaitSkipType;
32573263
#endif // SCRIPT_API_v363
32583264
};
32593265

Engine/ac/game.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,14 +934,33 @@ void Game_SimulateKeyPress(int key)
934934
ags_simulate_keypress(static_cast<eAGSKeyCode>(key), (game.options[OPT_KEYHANDLEAPI] == 0));
935935
}
936936

937+
int Game_BlockingWaitCounter()
938+
{
939+
return play.GetWaitCounter();
940+
}
941+
937942
int Game_BlockingWaitSkipped()
938943
{
939944
return play.GetWaitSkipResult();
940945
}
941946

947+
int Game_BlockingWaitSkipType()
948+
{
949+
// Convert to the InputType flags
950+
return play.GetWaitSkipType() << SKIP_RESULT_TYPE_SHIFT;
951+
}
952+
953+
int Game_InBlockingAction()
954+
{
955+
return IsInBlockingAction();
956+
}
957+
942958
int Game_InBlockingWait()
943959
{
944-
return IsInWaitMode();
960+
// A design mistake in 3.6.2: IsInBlockingWait name was used to report any blocking action state
961+
return game.options[OPT_BASESCRIPTAPI] >= kScriptAPI_v363 ?
962+
play.IsInWait() :
963+
IsInBlockingAction();
945964
}
946965

947966
void Game_PrecacheSprite(int sprnum)
@@ -2123,11 +2142,26 @@ RuntimeScriptValue Sc_Game_SimulateKeyPress(const RuntimeScriptValue *params, in
21232142
API_SCALL_VOID_PINT(Game_SimulateKeyPress);
21242143
}
21252144

2145+
RuntimeScriptValue Sc_Game_BlockingWaitCounter(const RuntimeScriptValue *params, int32_t param_count)
2146+
{
2147+
API_SCALL_INT(Game_BlockingWaitCounter);
2148+
}
2149+
21262150
RuntimeScriptValue Sc_Game_BlockingWaitSkipped(const RuntimeScriptValue *params, int32_t param_count)
21272151
{
21282152
API_SCALL_INT(Game_BlockingWaitSkipped);
21292153
}
21302154

2155+
RuntimeScriptValue Sc_Game_BlockingWaitSkipType(const RuntimeScriptValue *params, int32_t param_count)
2156+
{
2157+
API_SCALL_INT(Game_BlockingWaitSkipType);
2158+
}
2159+
2160+
RuntimeScriptValue Sc_Game_InBlockingAction(const RuntimeScriptValue *params, int32_t param_count)
2161+
{
2162+
API_SCALL_BOOL(Game_InBlockingAction);
2163+
}
2164+
21312165
RuntimeScriptValue Sc_Game_InBlockingWait(const RuntimeScriptValue *params, int32_t param_count)
21322166
{
21332167
API_SCALL_BOOL(Game_InBlockingWait);
@@ -2221,7 +2255,9 @@ void RegisterGameAPI()
22212255
{ "Game::ScanSaveSlots^6", API_FN_PAIR(Game_ScanSaveSlots) },
22222256
{ "Game::get_AudioClipCount", API_FN_PAIR(Game_GetAudioClipCount) },
22232257
{ "Game::geti_AudioClips", API_FN_PAIR(Game_GetAudioClip) },
2258+
{ "Game::get_BlockingWaitCounter", API_FN_PAIR(Game_BlockingWaitCounter) },
22242259
{ "Game::get_BlockingWaitSkipped", API_FN_PAIR(Game_BlockingWaitSkipped) },
2260+
{ "Game::get_BlockingWaitSkipType", API_FN_PAIR(Game_BlockingWaitSkipType) },
22252261
{ "Game::get_Camera", API_FN_PAIR(Game_GetCamera) },
22262262
{ "Game::get_CameraCount", API_FN_PAIR(Game_GetCameraCount) },
22272263
{ "Game::geti_Cameras", API_FN_PAIR(Game_GetAnyCamera) },
@@ -2235,6 +2271,7 @@ void RegisterGameAPI()
22352271
{ "Game::get_GUICount", API_FN_PAIR(Game_GetGUICount) },
22362272
{ "Game::get_IgnoreUserInputAfterTextTimeoutMs", API_FN_PAIR(Game_GetIgnoreUserInputAfterTextTimeoutMs) },
22372273
{ "Game::set_IgnoreUserInputAfterTextTimeoutMs", API_FN_PAIR(Game_SetIgnoreUserInputAfterTextTimeoutMs) },
2274+
{ "Game::get_InBlockingAction", API_FN_PAIR(Game_InBlockingAction) },
22382275
{ "Game::get_InBlockingWait", API_FN_PAIR(Game_InBlockingWait) },
22392276
{ "Game::get_InSkippableCutscene", API_FN_PAIR(Game_GetInSkippableCutscene) },
22402277
{ "Game::get_InventoryItemCount", API_FN_PAIR(Game_GetInventoryItemCount) },

Engine/ac/gamestate.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,25 @@ void GamePlayState::ClearIgnoreInput()
420420
_ignoreUserInputUntilTime = Clock::now();
421421
}
422422

423+
bool GamePlayState::IsInWait() const
424+
{
425+
// wait counter is either
426+
// * positive, and then there's a wait with timeout;
427+
// * negative, and then there's a wait without timeout;
428+
// * zero, which means there's no wait
429+
return wait_counter != 0;
430+
}
431+
432+
int GamePlayState::GetWaitCounter() const
433+
{
434+
return wait_counter;
435+
}
436+
437+
int GamePlayState::GetWaitSkipType() const
438+
{
439+
return play.key_skip_wait;
440+
}
441+
423442
void GamePlayState::SetWaitSkipResult(int how, int data)
424443
{
425444
wait_counter = 0;

Engine/ac/gamestate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,15 @@ struct GamePlayState
447447
// Clears ignore input state
448448
void ClearIgnoreInput();
449449

450+
bool IsInWait() const;
450451
// Set how the last blocking wait was skipped
451452
void SetWaitSkipResult(int how, int data = 0);
452453
void SetWaitKeySkip(const KeyInput &kp)
453454
{
454455
SetWaitSkipResult(SKIP_KEYPRESS, AGSKeyToScriptKey(kp.Key) | kp.Mod);
455456
}
457+
int GetWaitCounter() const;
458+
int GetWaitSkipType() const;
456459
// Returns the information about how the latest blocking wait was skipped.
457460
// The information is packed into int32 value like this:
458461
// | 0xFF | 0xFF | 0xF | 0xFFF |

Engine/main/game_run.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static bool game_loop_check_ground_level_interactions()
264264
// engine, but result was more or less same by accident, as the number
265265
// of scheduled callbacks was limited to a very small number.
266266
// (That was pretty unreliable though.)
267-
if (IsInWaitMode() && (loaded_game_file_version >= kGameVersion_362))
267+
if (IsInBlockingAction() && (loaded_game_file_version >= kGameVersion_362))
268268
{
269269
// NOTE: if we do update play.player_on_region here, then player might
270270
// trigger "walk on/off region" after finishing blocking walk if
@@ -1204,7 +1204,7 @@ static void UpdateSavedCursorOverLocation()
12041204
}
12051205
}
12061206

1207-
bool IsInWaitMode()
1207+
bool IsInBlockingAction()
12081208
{
12091209
return restrict_until != nullptr;
12101210
}

Engine/main/game_run.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ void UpdateCursorAndDrawables();
4343
// Useful after a major game state change, such as loading new room, in case we expect
4444
// that a render may occur before a normal game update is performed.
4545
void SyncDrawablesState();
46-
// Checks if currently in waiting state (blocking action, or Wait called from script).
47-
bool IsInWaitMode();
46+
// Checks if currently in blocking action state (blocking action, or Wait called from script).
47+
bool IsInBlockingAction();
4848
// Shuts down game's waiting state, if one is running right now.
4949
void ShutGameWaitState();
5050

0 commit comments

Comments
 (0)