packer & compiler test
This commit is contained in:
parent
d7a26473c8
commit
d16a987949
@ -7,3 +7,11 @@ dependencies {
|
||||
implementation(project(":prometeu-packer:prometeu-packer-api"))
|
||||
implementation("org.apache.tika:tika-core:3.2.1")
|
||||
}
|
||||
|
||||
tasks.register<JavaExec>("runPackMain") {
|
||||
group = "application"
|
||||
description = "Runs p.packer.PackMain against test-projects/main."
|
||||
classpath = sourceSets.main.get().runtimeClasspath
|
||||
mainClass = "p.packer.PackMain"
|
||||
workingDir = rootDir
|
||||
}
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package p.packer;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import p.packer.messages.PackWorkspaceRequest;
|
||||
import p.packer.messages.PackerOperationStatus;
|
||||
import p.packer.messages.PackerProjectContext;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class PackMain {
|
||||
private PackMain() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final Path projectRoot = args.length == 0
|
||||
? Path.of("test-projects/main")
|
||||
: Path.of(args[0]);
|
||||
final String projectId = projectRoot.getFileName() == null
|
||||
? "project"
|
||||
: projectRoot.getFileName().toString();
|
||||
|
||||
try (var packer = Packer.bootstrap(new ObjectMapper(), event -> { })) {
|
||||
final var result = packer.workspaceService().packWorkspace(
|
||||
new PackWorkspaceRequest(new PackerProjectContext(projectId, projectRoot)));
|
||||
System.out.println(result.summary());
|
||||
if (result.status() != PackerOperationStatus.SUCCESS) {
|
||||
throw new IllegalStateException("pack failed with status: " + result.status());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -37,6 +37,8 @@ import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class FileSystemPackerWorkspaceService implements PackerWorkspaceService {
|
||||
private static final int TILE_BANK_COLOR_KEY_RGB565 = 0xF81F;
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
private final PackerWorkspaceFoundation workspaceFoundation;
|
||||
private final PackerAssetDetailsService detailsService;
|
||||
@ -863,6 +865,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
final List<Map<String, Object>> assetTable = new ArrayList<>();
|
||||
final List<Map<String, Object>> preload = new ArrayList<>();
|
||||
final List<Map<String, Object>> assetTableMetadata = new ArrayList<>();
|
||||
final Map<String, Integer> nextPreloadSlotByBankType = new HashMap<>();
|
||||
final ByteArrayOutputStream payload = new ByteArrayOutputStream();
|
||||
for (PackedAsset packedAsset : packedAssets) {
|
||||
final int offset = payload.size();
|
||||
@ -877,7 +880,11 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
"codec", packedAsset.codec(),
|
||||
"metadata", packedAsset.metadata())));
|
||||
if (packedAsset.preloadEnabled()) {
|
||||
preload.add(new LinkedHashMap<>(Map.of("asset_id", packedAsset.assetId())));
|
||||
final int slot = nextPreloadSlotByBankType.getOrDefault(packedAsset.bankType(), 0);
|
||||
nextPreloadSlotByBankType.put(packedAsset.bankType(), slot + 1);
|
||||
preload.add(new LinkedHashMap<>(Map.of(
|
||||
"asset_id", packedAsset.assetId(),
|
||||
"slot", slot)));
|
||||
}
|
||||
assetTableMetadata.add(new LinkedHashMap<>(Map.of(
|
||||
"asset_id", packedAsset.assetId(),
|
||||
@ -1015,13 +1022,16 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
if (paletteIndex < 0 || paletteIndex >= 64) {
|
||||
continue;
|
||||
}
|
||||
final int paletteBaseOffset = (paletteIndex * 16) * 2;
|
||||
bytes[paletteBaseOffset] = (byte) (TILE_BANK_COLOR_KEY_RGB565 & 0xFF);
|
||||
bytes[paletteBaseOffset + 1] = (byte) ((TILE_BANK_COLOR_KEY_RGB565 >>> 8) & 0xFF);
|
||||
final JsonNode convertedNode = paletteNode.path("convertedRgb565");
|
||||
if (!convertedNode.isArray()) {
|
||||
continue;
|
||||
}
|
||||
for (int colorIndex = 0; colorIndex < Math.min(16, convertedNode.size()); colorIndex += 1) {
|
||||
for (int colorIndex = 0; colorIndex < Math.min(15, convertedNode.size()); colorIndex += 1) {
|
||||
final int rgb565 = convertedNode.get(colorIndex).asInt(0);
|
||||
final int baseOffset = ((paletteIndex * 16) + colorIndex) * 2;
|
||||
final int baseOffset = ((paletteIndex * 16) + colorIndex + 1) * 2;
|
||||
bytes[baseOffset] = (byte) (rgb565 & 0xFF);
|
||||
bytes[baseOffset + 1] = (byte) ((rgb565 >>> 8) & 0xFF);
|
||||
}
|
||||
@ -1042,12 +1052,13 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
|
||||
private byte[] buildPrelude(int headerLength) {
|
||||
final int preludeLength = 24;
|
||||
final int preludeLength = 32;
|
||||
final ByteBuffer buffer = ByteBuffer.allocate(preludeLength).order(ByteOrder.LITTLE_ENDIAN);
|
||||
buffer.put((byte) 'P').put((byte) 'P').put((byte) 'A').put((byte) 'K');
|
||||
buffer.put((byte) 'A').put((byte) 'S').put((byte) 'P').put((byte) 'A');
|
||||
buffer.putInt(1);
|
||||
buffer.putInt(headerLength);
|
||||
buffer.putInt(preludeLength + headerLength);
|
||||
buffer.putLong((long) preludeLength + headerLength);
|
||||
buffer.putInt(0);
|
||||
buffer.putInt(0);
|
||||
buffer.putInt(0);
|
||||
return buffer.array();
|
||||
|
||||
@ -311,8 +311,24 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
assertTrue(Files.isRegularFile(projectRoot.resolve("build/preload.json")));
|
||||
assertTrue(Files.isRegularFile(projectRoot.resolve("build/asset_table_metadata.json")));
|
||||
|
||||
final byte[] assetsPa = Files.readAllBytes(projectRoot.resolve("build/assets.pa"));
|
||||
assertTrue(assetsPa.length > 32);
|
||||
assertEquals('A', assetsPa[0]);
|
||||
assertEquals('S', assetsPa[1]);
|
||||
assertEquals('P', assetsPa[2]);
|
||||
assertEquals('A', assetsPa[3]);
|
||||
assertEquals(1, readLeInt(assetsPa, 4));
|
||||
assertEquals(32 + readLeInt(assetsPa, 8), readLeLong(assetsPa, 12));
|
||||
|
||||
final var assetTable = MAPPER.readTree(projectRoot.resolve("build/asset_table.json").toFile());
|
||||
assertEquals(1, assetTable.size());
|
||||
final int payloadOffset = (int) readLeLong(assetsPa, 12);
|
||||
final int assetOffset = assetTable.get(0).path("offset").asInt();
|
||||
final int packedPixelBytes = (assetTable.get(0).path("metadata").path("width").asInt()
|
||||
* assetTable.get(0).path("metadata").path("height").asInt()) / 2;
|
||||
final int paletteStart = payloadOffset + assetOffset + packedPixelBytes;
|
||||
assertEquals(0xF81F, readLeUnsignedShort(assetsPa, paletteStart));
|
||||
assertEquals(0xF800, readLeUnsignedShort(assetsPa, paletteStart + 2));
|
||||
assertEquals(1, assetTable.get(0).path("asset_id").asInt());
|
||||
assertEquals("TILES", assetTable.get(0).path("bank_type").asText());
|
||||
assertEquals("NONE", assetTable.get(0).path("codec").asText());
|
||||
@ -327,6 +343,7 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
final var preload = MAPPER.readTree(projectRoot.resolve("build/preload.json").toFile());
|
||||
assertEquals(1, preload.size());
|
||||
assertEquals(1, preload.get(0).path("asset_id").asInt());
|
||||
assertEquals(0, preload.get(0).path("slot").asInt());
|
||||
|
||||
final var assetTableMetadata = MAPPER.readTree(projectRoot.resolve("build/asset_table_metadata.json").toFile());
|
||||
assertEquals(1, assetTableMetadata.size());
|
||||
@ -1353,4 +1370,26 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
}
|
||||
ImageIO.write(image, "png", path.toFile());
|
||||
}
|
||||
|
||||
private static int readLeInt(byte[] bytes, int offset) {
|
||||
return (bytes[offset] & 0xFF)
|
||||
| ((bytes[offset + 1] & 0xFF) << 8)
|
||||
| ((bytes[offset + 2] & 0xFF) << 16)
|
||||
| ((bytes[offset + 3] & 0xFF) << 24);
|
||||
}
|
||||
|
||||
private static long readLeLong(byte[] bytes, int offset) {
|
||||
return ((long) bytes[offset] & 0xFF)
|
||||
| (((long) bytes[offset + 1] & 0xFF) << 8)
|
||||
| (((long) bytes[offset + 2] & 0xFF) << 16)
|
||||
| (((long) bytes[offset + 3] & 0xFF) << 24)
|
||||
| (((long) bytes[offset + 4] & 0xFF) << 32)
|
||||
| (((long) bytes[offset + 5] & 0xFF) << 40)
|
||||
| (((long) bytes[offset + 6] & 0xFF) << 48)
|
||||
| (((long) bytes[offset + 7] & 0xFF) << 56);
|
||||
}
|
||||
|
||||
private static int readLeUnsignedShort(byte[] bytes, int offset) {
|
||||
return (bytes[offset] & 0xFF) | ((bytes[offset + 1] & 0xFF) << 8);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,54 @@
|
||||
[ {
|
||||
"source" : "Assets",
|
||||
"message" : "7 assets loaded",
|
||||
"severity" : "SUCCESS",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Asset scan diagnostics updated.",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: bla",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: one-more-atlas",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: ui_atlas",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: one-more-atlas",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: bbb2",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: ui_atlas",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: Bigode",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Asset scan started",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Asset scan diagnostics updated.",
|
||||
"severity" : "INFO",
|
||||
@ -2448,54 +2498,4 @@
|
||||
"message" : "Discovered asset: one-more-atlas",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: ui_atlas",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: one-more-atlas",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: bbb2",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: ui_atlas",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: Bigode",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Asset scan started",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "7 assets loaded",
|
||||
"severity" : "SUCCESS",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Asset scan diagnostics updated.",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: bla",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
}, {
|
||||
"source" : "Assets",
|
||||
"message" : "Discovered asset: one-more-atlas",
|
||||
"severity" : "INFO",
|
||||
"sticky" : false
|
||||
} ]
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -10,7 +10,7 @@ fn frame() -> void
|
||||
|
||||
Gfx.clear(new Color(6577));
|
||||
// Gfx.draw_square(touch.x() - 8, touch.y() - 8, 16, 16, new Color(65535), new Color(13271));
|
||||
let sprite_status = Gfx.set_sprite(0, 0, touch.x() - 8, touch.y() - 8, 0, 1, true, false, false, 0);
|
||||
let sprite_status = Gfx.set_sprite(0, 0, touch.x() - 8, touch.y() - 8, 0, 0, true, false, false, 0);
|
||||
|
||||
let a = 10;
|
||||
let b = 15;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user