Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaltby committed Apr 3, 2024
1 parent 0299e04 commit c85275f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/lib/compiler/compileImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const imageTileAllocationColorOnly: ImageTileAllocationStrategy = (
// After that split evenly between bank 1 and 2
return {
tileIndex: 128 + Math.floor((tileIndex - 256) / 2),
inVRAM2: tileIndex % 2 === 0,
inVRAM2: tileIndex % 2 !== 0,
};
};

Expand Down
2 changes: 1 addition & 1 deletion test/data/compiler/compileData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import compile, {
precompileBackgrounds,
precompileScenes,
} from "../../../src/lib/compiler/compileData";
import { compileSceneProjectiles } from "../../../src/lib/compiler/compileData2";
import { compileSceneProjectiles } from "../../../src/lib/compiler/generateGBVMData";
import { EVENT_TEXT, EVENT_IF_TRUE, EVENT_SET_TRUE } from "../../../src/consts";
import { projectileStateTest } from "./_files/data/projectiles";
import { getTestScriptHandlers } from "../../getTestScriptHandlers";
Expand Down
90 changes: 58 additions & 32 deletions test/data/compiler/compileImages.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import compileImages from "lib/compiler/compileImages";
import compileImages, {
imageTileAllocationColorOnly,
imageTileAllocationDefault,
} from "lib/compiler/compileImages";
import { BackgroundData } from "shared/lib/entities/entitiesTypes";

const BYTES_PER_TILE = 16;
Expand All @@ -15,14 +18,10 @@ test("should compile images", async () => {
[],
false,
`${__dirname}/_files/`,
`${__dirname}/_tmp/`,
{ warnings: () => {} }
);
expect(res.tilemaps["img1"].length).toEqual(360);
expect(res.tilemapsTileset["img1"].length).toEqual(1);
expect(res.tilesets[res.tilemapsTileset["img1"][0]].length).toEqual(
114 * BYTES_PER_TILE
);
expect(res[0].tilemap.length).toEqual(360);
expect(res[0].vramData[0].length).toEqual(114 * BYTES_PER_TILE);
});

test("should compile split large images into two tilesets for CGB mode", async () => {
Expand All @@ -37,17 +36,11 @@ test("should compile split large images into two tilesets for CGB mode", async (
[],
true,
`${__dirname}/_files/`,
`${__dirname}/_tmp/`,
{ warnings: () => {} }
);
expect(res.tilemaps["img1"].length).toEqual(3136);
expect(res.tilemapsTileset["img1"].length).toEqual(2);
expect(res.tilesets[res.tilemapsTileset["img1"][0]].length).toEqual(
192 * BYTES_PER_TILE
);
expect(res.tilesets[res.tilemapsTileset["img1"][1]].length).toEqual(
192 * BYTES_PER_TILE
);
expect(res[0].tilemap.length).toEqual(3136);
expect(res[0].vramData[0].length).toEqual(192 * BYTES_PER_TILE);
expect(res[0].vramData[1].length).toEqual(192 * BYTES_PER_TILE);
});

test("should compile large images into one overflowing bank when not in color only mode", async () => {
Expand All @@ -62,17 +55,13 @@ test("should compile large images into one overflowing bank when not in color on
[],
false,
`${__dirname}/_files/`,
`${__dirname}/_tmp/`,
{ warnings: () => {} }
);
expect(res.tilemaps["img1"].length).toEqual(3136);
expect(res.tilemapsTileset["img1"].length).toEqual(1);
expect(res.tilesets[res.tilemapsTileset["img1"][0]].length).toEqual(
384 * BYTES_PER_TILE
);
expect(res[0].tilemap.length).toEqual(3136);
expect(res[0].vramData[0].length).toEqual(384 * BYTES_PER_TILE);
});

test("should split tiles into two banks evenly when in color only mode", async () => {
test("should split tiles into two banks when in color only mode, filling first 128 tiles of vram bank 1 first", async () => {
const backgroundData = [
{
id: "img1",
Expand All @@ -84,15 +73,52 @@ test("should split tiles into two banks evenly when in color only mode", async (
[],
true,
`${__dirname}/_files/`,
`${__dirname}/_tmp/`,
{ warnings: () => {} }
);
expect(res.tilemaps["img1"].length).toEqual(1440);
expect(res.tilemapsTileset["img1"].length).toEqual(2);
expect(res.tilesets[res.tilemapsTileset["img1"][0]].length).toEqual(
96 * BYTES_PER_TILE
);
expect(res.tilesets[res.tilemapsTileset["img1"][1]].length).toEqual(
95 * BYTES_PER_TILE
);
expect(res[0].tilemap.length).toEqual(1440);
expect(res[0].vramData[0].length).toEqual(128 * BYTES_PER_TILE);
expect(res[0].vramData[1].length).toEqual(63 * BYTES_PER_TILE);
});

test("Should allocate all tiles to VRAM1 in original order by default", () => {
const backgroundData = [
{
id: "img1",
filename: "parallax.png",
},
] as unknown as BackgroundData;
for (let i = 0; i < 192; i++) {
expect(imageTileAllocationDefault(i, 192, backgroundData)).toEqual({
tileIndex: i,
inVRAM2: false,
});
}
});

test("Should allocate first 128 tiles to vram1, next 128 to vram2 and split the rest evenly when in color only mode", () => {
const backgroundData = [
{
id: "img1",
filename: "parallax.png",
},
] as unknown as BackgroundData;
for (let i = 0; i < 384; i++) {
let shouldBeVRAM2 = false;
let index = i;
// Tiles 128 to 255 go in vram2
if (i >= 128 && i < 256) {
shouldBeVRAM2 = true;
index -= 128;
}
// After 255 tiles alternate between vram1 and vram2
if (i >= 256) {
shouldBeVRAM2 = i % 2 !== 0;
index = Math.floor((i - 256) / 2) + 128;
}

expect(imageTileAllocationColorOnly(i, 384, backgroundData)).toEqual({
tileIndex: index,
inVRAM2: shouldBeVRAM2,
});
}
});
2 changes: 1 addition & 1 deletion test/data/compiler/scriptBuilder2.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrecompiledScene } from "../../../src/lib/compiler/compileData2";
import { PrecompiledScene } from "../../../src/lib/compiler/generateGBVMData";
import ScriptBuilder from "../../../src/lib/compiler/scriptBuilder";
import { ScriptEvent } from "../../../src/shared/lib/entities/entitiesTypes";
import {
Expand Down
5 changes: 2 additions & 3 deletions test/dummydata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { projectTemplatesRoot } from "../src/consts";
import {
PrecompiledBackground,
PrecompiledSprite,
} from "../src/lib/compiler/compileData2";
} from "../src/lib/compiler/generateGBVMData";

export const dummySceneNormalized: SceneNormalized = {
id: "",
Expand Down Expand Up @@ -109,7 +109,6 @@ export const dummyPrecompiledBackground: PrecompiledBackground = {
name: "",
width: 1,
height: 1,
data: new Uint8Array(),
tileset: {
symbol: "ts_1",
data: new Uint8Array(),
Expand Down Expand Up @@ -175,7 +174,6 @@ export const dummyPrecompiledSpriteSheet: PrecompiledSprite = {
symbol: "ts_1",
data: new Uint8Array(),
},
data: [],
tiles: [],
metasprites: [],
animationOffsets: [],
Expand All @@ -185,6 +183,7 @@ export const dummyPrecompiledSpriteSheet: PrecompiledSprite = {
width: 32,
height: 32,
animSpeed: 15,
vramData: [[], []],
};

export const dummyMusic: Music = {
Expand Down

0 comments on commit c85275f

Please sign in to comment.