Skip to content

Commit

Permalink
auto-test: add test for matching engine render after dyn sprite update
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko authored and ericoporto committed Apr 2, 2024
1 parent 97f37fa commit d7ee3c6
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ags3/auto-test/Game.agf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--DO NOT EDIT THIS FILE. It is automatically generated by the AGS Editor, changing it manually could break your game-->
<AGSEditorDocument Version="3.0.3.2" VersionIndex="3060110" EditorVersion="3.6.1.19">
<AGSEditorDocument Version="3.0.3.2" VersionIndex="3060110" EditorVersion="3.6.1.22">
<Game>
<Settings>
<AllowRelativeAssetResolutions>False</AllowRelativeAssetResolutions>
Expand Down Expand Up @@ -1959,6 +1959,35 @@
</ScriptAndHeader>
</ScriptAndHeaders>
</ScriptFolder>
<ScriptFolder Name="tests-engine">
<SubFolders />
<ScriptAndHeaders>
<ScriptAndHeader>
<ScriptAndHeader_Header>
<Script>
<FileName>test-enginerender.ash</FileName>
<Name />
<Description />
<Author />
<Version />
<Key>751248376</Key>
<IsHeader>True</IsHeader>
</Script>
</ScriptAndHeader_Header>
<ScriptAndHeader_Script>
<Script>
<FileName>test-enginerender.asc</FileName>
<Name />
<Description />
<Author />
<Version />
<Key>751248376</Key>
<IsHeader>False</IsHeader>
</Script>
</ScriptAndHeader_Script>
</ScriptAndHeader>
</ScriptAndHeaders>
</ScriptFolder>
</SubFolders>
<ScriptAndHeaders>
<ScriptAndHeader>
Expand Down
Binary file modified ags3/auto-test/room1.crm
Binary file not shown.
2 changes: 2 additions & 0 deletions ags3/auto-test/run-tests.asc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void RunTests()
test_count += GetTestFileCount();
test_count += GetTestDrawingSurfaceCount();
test_count += GetTestMiscCount();
test_count += GetTestEngineRenderCount();

tap.clean_test();
tap.plan(test_count);
Expand All @@ -22,6 +23,7 @@ void RunTests()
TestFile();
TestDrawingSurface();
TestMisc();
TestEngineRender();
tap.done_testing();

if(tap.AnyTestFailed()) {
Expand Down
157 changes: 157 additions & 0 deletions ags3/auto-test/test-enginerender.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// Test EngineRender Module Script
int GetTestEngineRenderCount()
{
return 8;
}

void _FillSprite(DynamicSprite *spr, int color)
{
DrawingSurface *ds = spr.GetDrawingSurface();
ds.Clear(color);
ds.Release();
}

// Takes screenshot 1:1 and compares a part of the image with the given sprite
bool _TakeScreenshotAndCompareRect(int rx, int ry, int rw, int rh, DynamicSprite *match_with)
{
DynamicSprite *shot = DynamicSprite.CreateFromScreenShot(Screen.Width, Screen.Height);
DrawingSurface *test_ds = shot.GetDrawingSurface();
DrawingSurface *match_ds = match_with.GetDrawingSurface();

for (int y = 0; y < rh; y++) {
for (int x = 0; x < rw; x++) {
if (test_ds.GetPixel(x + rx, y + ry) != match_ds.GetPixel(x, y)) {
return false;
}
}
}

return true;
}

void TestEngineRender()
{
tap.Comment("start EngineRender tests");
tap.Comment(String.Format("System.HardwareAcceleration = %d", System.HardwareAcceleration));

//
// Object texture update after dynamic sprite change
//
{
int color1 = 10;
int color2 = 11;
Object* oDynamicObject = object[0];
DynamicSprite* dynspr = DynamicSprite.Create(10, 10, false);
_FillSprite(dynspr, color1);
oDynamicObject.Graphic = dynspr.Graphic;
oDynamicObject.X = 100;
oDynamicObject.Y = 100;
oDynamicObject.Visible = true;
Wait(1);
tap.ok(
_TakeScreenshotAndCompareRect(oDynamicObject.X, oDynamicObject.Y - dynspr.Height, dynspr.Width, dynspr.Height, dynspr),
"DynamicSprite update 1-1 (room object) is matched");


_FillSprite(dynspr, color2);
Wait(1);
tap.ok(
_TakeScreenshotAndCompareRect(oDynamicObject.X, oDynamicObject.Y - dynspr.Height, dynspr.Width, dynspr.Height, dynspr),
"DynamicSprite update 1-2 (room object) is matched");

oDynamicObject.Visible = false;
oDynamicObject.Graphic = 0;
dynspr.Delete();
}

//
// Object texture update after dynamic sprite recreated
// with coincidentally the same sprite ID
//
{
int color1 = 10;
int color2 = 11;
DynamicSprite* dynspr = DynamicSprite.Create(10, 10, false);
Object* oDynamicObject = object[1];
_FillSprite(dynspr, color1);
oDynamicObject.Graphic = dynspr.Graphic;
oDynamicObject.X = 100;
oDynamicObject.Y = 100;
oDynamicObject.Visible = true;
Wait(1);
tap.ok(
_TakeScreenshotAndCompareRect(oDynamicObject.X, oDynamicObject.Y - dynspr.Height, dynspr.Width, dynspr.Height, dynspr),
"DynamicSprite recreate 1-1 (room object) is matched");

dynspr.Delete();
dynspr = DynamicSprite.Create(10, 10, false);
_FillSprite(dynspr, color2);
oDynamicObject.Graphic = dynspr.Graphic;
Wait(1);
tap.ok(
_TakeScreenshotAndCompareRect(oDynamicObject.X, oDynamicObject.Y - dynspr.Height, dynspr.Width, dynspr.Height, dynspr),
"DynamicSprite recreate 1-2 (room object) is matched");

oDynamicObject.Visible = false;
oDynamicObject.Graphic = 0;
dynspr.Delete();
}

//
// Overlay texture update after dynamic sprite change;
// We test overlays separately, because they have slightly different
// path of updating their textures in the engine. Also they are
// dynamic objects themselves and may be deleted completely.
//
{
int color1 = 10;
int color2 = 11;
DynamicSprite* dynspr = DynamicSprite.Create(10, 10, false);
_FillSprite(dynspr, color1);
Overlay* over = Overlay.CreateGraphical(100, 100, dynspr.Graphic, true);
Wait(1);
tap.ok(
_TakeScreenshotAndCompareRect(over.X, over.Y, dynspr.Width, dynspr.Height, dynspr),
"DynamicSprite update 2-1 (overlay) is matched");


_FillSprite(dynspr, color2);
Wait(1);
tap.ok(
_TakeScreenshotAndCompareRect(over.X, over.Y, dynspr.Width, dynspr.Height, dynspr),
"DynamicSprite update 2-2 (overlay) is matched");

over.Remove();
dynspr.Delete();
}

//
// Overlay texture update after dynamic sprite recreated
// with coincidentally the same sprite ID
//
{
int color1 = 10;
int color2 = 11;
DynamicSprite* dynspr = DynamicSprite.Create(10, 10, false);
_FillSprite(dynspr, color1);
Overlay* over = Overlay.CreateGraphical(100, 100, dynspr.Graphic, true);
Wait(1);
tap.ok(
_TakeScreenshotAndCompareRect(over.X, over.Y, dynspr.Width, dynspr.Height, dynspr),
"DynamicSprite recreate 2-1 (overlay) is matched");

dynspr.Delete();
dynspr = DynamicSprite.Create(10, 10, false);
_FillSprite(dynspr, color2);
over.Graphic = dynspr.Graphic;
Wait(1);
tap.ok(
_TakeScreenshotAndCompareRect(over.X, over.Y, dynspr.Width, dynspr.Height, dynspr),
"DynamicSprite recreate 2-2 (overlay) is matched");

over.Remove();
dynspr.Delete();
}

tap.Comment("end EngineRender tests");
}
11 changes: 11 additions & 0 deletions ags3/auto-test/test-enginerender.ash
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Test EngineRender Module Header
//
// This module's purpose is to test engine's render, as much as possible
// from the script. The objects and sprites may be tested on their own, but
// engine may have mistakes in the drawing routine, which will not be reflected
// in game object states.
// The only available method of testing engine's render result at the moment
// is by taking screenshots and analysing their contents.
//
import void TestEngineRender();
import int GetTestEngineRenderCount();

0 comments on commit d7ee3c6

Please sign in to comment.