Skip to content

Commit e226ebf

Browse files
committed
ags3/ags4-auto-test: corrected game ticks counting
This is not certain, but there's 1 game update somewhere between leaving one room and entering another, when repeatedly_execute_always is not getting called, which means that our timer variable in script becomes 1 tick behind the game's loop counter. This breaks calculation of "ticks left in second", necessary for Idle Start Test. Try to adjust our counter in "room leave" event.
1 parent 37cfd03 commit e226ebf

File tree

10 files changed

+120
-24
lines changed

10 files changed

+120
-24
lines changed

ags3/auto-test/Game.agf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,6 +4209,30 @@
42094209
</Script>
42104210
</ScriptAndHeader_Script>
42114211
</ScriptAndHeader>
4212+
<ScriptAndHeader>
4213+
<ScriptAndHeader_Header>
4214+
<Script>
4215+
<FileName>helpers.ash</FileName>
4216+
<Name />
4217+
<Description />
4218+
<Author />
4219+
<Version />
4220+
<Key>620806988</Key>
4221+
<IsHeader>True</IsHeader>
4222+
</Script>
4223+
</ScriptAndHeader_Header>
4224+
<ScriptAndHeader_Script>
4225+
<Script>
4226+
<FileName>helpers.asc</FileName>
4227+
<Name />
4228+
<Description />
4229+
<Author />
4230+
<Version />
4231+
<Key>620806988</Key>
4232+
<IsHeader>False</IsHeader>
4233+
</Script>
4234+
</ScriptAndHeader_Script>
4235+
</ScriptAndHeader>
42124236
</ScriptAndHeaders>
42134237
</ScriptFolder>
42144238
<ScriptFolder Name="tests">

ags3/auto-test/helpers.asc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Helper utilities
2+
3+
GameTimer GT;
4+
export GT;
5+
6+
function repeatedly_execute_always()
7+
{
8+
GT.GameTicks++;
9+
if (GT.GameTicks < 0)
10+
GT.GameTicks = 0;
11+
}
12+
13+
function on_event(EventType evt, int data1)
14+
{
15+
// This is not certain, but there's 1 game update somewhere between
16+
// leaving one room and entering another, when repeatedly_execute_always
17+
// is not getting called, which means that our timer variable in script
18+
// becomes 1 tick behind the game's loop counter.
19+
// Try to adjust it in "room leave" event.
20+
if (evt == eEventLeaveRoom)
21+
{
22+
GT.GameTicks++;
23+
}
24+
}

ags3/auto-test/helpers.ash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Helper utilities
2+
3+
struct GameTimer
4+
{
5+
int GameTicks;
6+
};
7+
8+
import GameTimer GT;

ags3/auto-test/room1.crm

30 Bytes
Binary file not shown.

ags3/auto-test/room2.crm

30 Bytes
Binary file not shown.

ags3/auto-test/test-characters.asc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ int GetTestCharactersCount()
77
;
88
}
99

10-
int game_ticks = 0;
11-
1210
void TestChangingDirectionLoop()
1311
{
1412
Character* turner = cWalker2;
@@ -153,7 +151,7 @@ void TestIdleStartsInTime(Character* idler, int idle_start_delay, String test_na
153151
// NOTE: undocumented, but AGS does not decrement idle timer on each tick,
154152
// instead it decrements whole second each game second, using seconds counted from
155153
// the *game's start*, rather than seconds counted from the last character action.
156-
int second_ticks_passed = game_ticks % game_speed;
154+
int second_ticks_passed = GT.GameTicks % game_speed;
157155
idle_time -= second_ticks_passed;
158156
//tap.Comment(String.Format("second_ticks_passed = %d", second_ticks_passed));
159157

@@ -163,6 +161,7 @@ void TestIdleStartsInTime(Character* idler, int idle_start_delay, String test_na
163161
{
164162
idle_time += game_speed;
165163
}
164+
idle_time = idle_time + 1; // if speed is 0, there will be still 1 tick to update the idle timer
166165

167166
tap.isnt_int(idler.View, idler.IdleView, String.Format("Character idle start (%s): before idling", test_name));
168167
int ticks_till_idle = 0;
@@ -215,9 +214,9 @@ void TestIdleViewStart()
215214
idler.SetIdleView(VIDLING, idle_start_delay);
216215
Speech.SkipStyle = eSkipTime;
217216
idler.SpeechView = -1;
218-
int last_game_ticks = game_ticks;
217+
int last_game_ticks = GT.GameTicks;
219218
idler.Say("x");
220-
TestIdleStartsInTime(idler, idle_start_delay, "after blocking say no view", game_ticks - last_game_ticks, true);
219+
TestIdleStartsInTime(idler, idle_start_delay, "after blocking say no view", GT.GameTicks - last_game_ticks, true);
221220
// note previous idling counts as action too, resetting idle timer by -1 s
222221

223222
// Blocking say with speech view: idling is inactive
@@ -233,13 +232,6 @@ void TestIdleViewStart()
233232
TestIdleStartsInTime(idler, idle_start_delay, "after custom animate", 0, true);
234233
}
235234

236-
function repeatedly_execute_always()
237-
{
238-
game_ticks++;
239-
if (game_ticks < 0)
240-
game_ticks = 0;
241-
}
242-
243235
void TestCharacters()
244236
{
245237
tap.Comment("start Character tests");

ags4/auto-test/Game.agf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4274,6 +4274,30 @@
42744274
</Script>
42754275
</ScriptAndHeader_Script>
42764276
</ScriptAndHeader>
4277+
<ScriptAndHeader>
4278+
<ScriptAndHeader_Header>
4279+
<Script>
4280+
<FileName>helpers.ash</FileName>
4281+
<Name />
4282+
<Description />
4283+
<Author />
4284+
<Version />
4285+
<Key>779066366</Key>
4286+
<IsHeader>True</IsHeader>
4287+
</Script>
4288+
</ScriptAndHeader_Header>
4289+
<ScriptAndHeader_Script>
4290+
<Script>
4291+
<FileName>helpers.asc</FileName>
4292+
<Name />
4293+
<Description />
4294+
<Author />
4295+
<Version />
4296+
<Key>779066366</Key>
4297+
<IsHeader>False</IsHeader>
4298+
</Script>
4299+
</ScriptAndHeader_Script>
4300+
</ScriptAndHeader>
42774301
</ScriptAndHeaders>
42784302
</ScriptFolder>
42794303
<ScriptFolder Name="tests">

ags4/auto-test/helpers.asc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Helper utilities
2+
3+
GameTimer GT;
4+
export GT;
5+
6+
function repeatedly_execute_always()
7+
{
8+
GT.GameTicks++;
9+
if (GT.GameTicks < 0)
10+
GT.GameTicks = 0;
11+
}
12+
13+
function on_event(EventType evt, int data1)
14+
{
15+
// This is not certain, but there's 1 game update somewhere between
16+
// leaving one room and entering another, when repeatedly_execute_always
17+
// is not getting called, which means that our timer variable in script
18+
// becomes 1 tick behind the game's loop counter.
19+
// Try to adjust it in "room leave" event.
20+
if (evt == eEventLeaveRoom)
21+
{
22+
GT.GameTicks++;
23+
}
24+
}

ags4/auto-test/helpers.ash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Helper utilities
2+
3+
struct GameTimer
4+
{
5+
int GameTicks;
6+
};
7+
8+
import GameTimer GT;

ags4/auto-test/test-characters.asc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ int GetTestCharactersCount()
77
;
88
}
99

10-
int game_ticks = 0;
11-
1210
void TestChangingDirectionLoop()
1311
{
1412
Character* turner = cWalker2;
@@ -153,7 +151,7 @@ void TestIdleStartsInTime(Character* idler, int idle_start_delay, String test_na
153151
// NOTE: undocumented, but AGS does not decrement idle timer on each tick,
154152
// instead it decrements whole second each game second, using seconds counted from
155153
// the *game's start*, rather than seconds counted from the last character action.
156-
int second_ticks_passed = game_ticks % game_speed;
154+
int second_ticks_passed = GT.GameTicks % game_speed;
157155
idle_time -= second_ticks_passed;
158156
//tap.Comment(String.Format("second_ticks_passed = %d", second_ticks_passed));
159157

@@ -163,6 +161,7 @@ void TestIdleStartsInTime(Character* idler, int idle_start_delay, String test_na
163161
{
164162
idle_time += game_speed;
165163
}
164+
idle_time = idle_time + 1; // if speed is 0, there will be still 1 tick to update the idle timer
166165

167166
tap.isnt_int(idler.View, idler.IdleView, String.Format("Character idle start (%s): before idling", test_name));
168167
int ticks_till_idle = 0;
@@ -215,9 +214,9 @@ void TestIdleViewStart()
215214
idler.SetIdleView(VIDLING, idle_start_delay);
216215
Speech.SkipStyle = eSkipTime;
217216
idler.SpeechView = -1;
218-
int last_game_ticks = game_ticks;
217+
int last_game_ticks = GT.GameTicks;
219218
idler.Say("x");
220-
TestIdleStartsInTime(idler, idle_start_delay, "after blocking say no view", game_ticks - last_game_ticks, true);
219+
TestIdleStartsInTime(idler, idle_start_delay, "after blocking say no view", GT.GameTicks - last_game_ticks, true);
221220
// note previous idling counts as action too, resetting idle timer by -1 s
222221

223222
// Blocking say with speech view: idling is inactive
@@ -233,13 +232,6 @@ void TestIdleViewStart()
233232
TestIdleStartsInTime(idler, idle_start_delay, "after custom animate", 0, true);
234233
}
235234

236-
function repeatedly_execute_always()
237-
{
238-
game_ticks++;
239-
if (game_ticks < 0)
240-
game_ticks = 0;
241-
}
242-
243235
void TestCharacters()
244236
{
245237
tap.Comment("start Character tests");

0 commit comments

Comments
 (0)