Added some debugging analytics

This commit is contained in:
2023-07-31 21:14:40 +10:00
parent 34542f73bb
commit 490926f10a
4 changed files with 36 additions and 72 deletions

2
Box

Submodule Box updated: d1359cd1f8...e4d39a43fc

View File

@@ -84,6 +84,8 @@ fn onKeyDown(node: opaque, event: string) {
//scene loading //scene loading
fn generateLevel(node: opaque, rng: opaque) { fn generateLevel(node: opaque, rng: opaque) {
print clock() + " - begin generating level";
//load and run the generator script //load and run the generator script
var generatorScript: opaque = loadScript("scripts:/tilemap/generator.toy"); var generatorScript: opaque = loadScript("scripts:/tilemap/generator.toy");
generatorScript.runScript(); generatorScript.runScript();
@@ -130,6 +132,8 @@ fn generateLevel(node: opaque, rng: opaque) {
//increment here //increment here
i++; i++;
} }
print clock() + " - end generating level";
} }

View File

@@ -58,6 +58,8 @@ var metadata: [[[string: any]]] = null;
//public functions //public functions
fn generateTilemapData(rng: opaque) { fn generateTilemapData(rng: opaque) {
print clock() + " - generating tilemap data";
//generate a grid filled with only empty tiles, as a starting point //generate a grid filled with only empty tiles, as a starting point
tilemap = []; tilemap = [];
@@ -69,6 +71,8 @@ fn generateTilemapData(rng: opaque) {
} }
} }
print clock() + " - generating room metadata";
//generate the metadata of each room //generate the metadata of each room
var roomData = []; var roomData = [];
@@ -91,9 +95,13 @@ fn generateTilemapData(rng: opaque) {
roomData.push(inner); roomData.push(inner);
} }
print clock() + " - generating corridor metadata";
//generate corridor metadata //generate corridor metadata
var corridorData = generateCorridorData(rng); var corridorData = generateCorridorData(rng);
print clock() + " - etching rooms";
//etch each tile string into the tilemap //etch each tile string into the tilemap
for (var j: int = 0; j < CELL_COUNT_Y; j++) { for (var j: int = 0; j < CELL_COUNT_Y; j++) {
for (var i: int = 0; i < CELL_COUNT_X; i++) { for (var i: int = 0; i < CELL_COUNT_X; i++) {
@@ -101,13 +109,19 @@ fn generateTilemapData(rng: opaque) {
} }
} }
print clock() + " - etching corridors";
//etch the corridors //etch the corridors
etchCorridors(roomData, corridorData, rng); etchCorridors(roomData, corridorData, rng);
print clock() + " - etching walls";
//etch the walls with marching squares, based on the room's themes //etch the walls with marching squares, based on the room's themes
etchWalls(roomData); etchWalls(roomData);
//save the metadata for later retrieval print clock() + " - finished tilemap generation";
//save the room metadata for later retrieval
metadata = roomData; metadata = roomData;
} }
@@ -377,21 +391,19 @@ fn etchLine(x: int, y: int, xLength: int, yLength: int, theme: string, rng: opaq
} }
fn etchWalls(roomData) { fn etchWalls(roomData) {
//zero'd signals //signal the wall to use
var signals: [string] = []; var signals: [string] = [];
for (var j: int = 0; j < CELL_COUNT_Y * CELL_HEIGHT; j++) { print clock() + " -> parse the tilemap at each position";
for (var i: int = 0; i < CELL_COUNT_X * CELL_WIDTH; i++) {
signals.push(""); //empty //determine the walls' layout from the tilemap
for (var j: int = 0; j < MAP_GRID_HEIGHT; j++) {
for (var i: int = 0; i < MAP_GRID_WIDTH; i++) {
signals.push(parseTilemapAt(i, j));
} }
} }
//determine the walls' layout from the tilemap print clock() + " -> etch the signals into the tilemap";
for (var i: int = 0; i < MAP_GRID_WIDTH; i++) {
for (var j: int = 0; j < MAP_GRID_HEIGHT; j++) {
signals[j * MAP_GRID_WIDTH + i] = parseTilemapAt(i, j);
}
}
//etch the walls into the tilemap, based on the room theme //etch the walls into the tilemap, based on the room theme
for (var i: int = 0; i < MAP_GRID_WIDTH; i++) { for (var i: int = 0; i < MAP_GRID_WIDTH; i++) {
@@ -409,66 +421,10 @@ fn etchWalls(roomData) {
tilemap[ITERATION + 2] = tileset[index][2]; tilemap[ITERATION + 2] = tileset[index][2];
} }
} }
print clock() + " -> finished";
} }
/*
//lets say snapshot looks like this
snapshot:
0, 0, 1
0, 0, 1
0, 0, 1
result should be "wall-l",
//lets say filter looks like this
filter:
1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1
find the position within the filter, that gives the result "wall-l"
//lets say result looks like this
"edge-br" "wall-b" "edge-bl"
"wall-r" "pillar" "wall-l"
"edge-tr" "wall-t" "edge-tl"
let's try this...
*/
/* 9x9
var marchingFilter: [int] const = [
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 1, 1, 1, 0, 0, 1,
1, 0, 0, 1, 1, 1, 0, 0, 1,
1, 0, 0, 1, 1, 1, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1
];
var marchingFilterResult: [string] const = [
"", "", "", "", "", "", "", "", "",
"", "edge-tr", "wall-b", "wall-b", "wall-b", "wall-b", "wall-b", "edge-tl", "",
"", "wall-r", "corner-tl", "wall-t", "wall-t", "wall-t", "corner-tr", "wall-l", "",
"", "wall-r", "wall-l", "", "", "", "wall-r", "wall-l", "",
"", "wall-r", "wall-l", "", "", "", "wall-r", "wall-l", "",
"", "wall-r", "wall-l", "", "", "", "wall-r", "wall-l", "",
"", "wall-r", "corner-bl", "wall-b", "wall-b", "wall-b", "corner-br", "wall-l", "",
"", "edge-br", "wall-t", "wall-t", "wall-t", "wall-t", "wall-t", "edge-bl", "",
"", "", "", "", "", "", "", "", ""
];
*/
//this is a nightmare //this is a nightmare
var marchingFilter: [int] const = [ var marchingFilter: [int] const = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -504,7 +460,7 @@ var marchingFilterResult: [string] const = [
//if walkable is below, then return top, etc. //if walkable is below, then return top, etc.
fn parseTilemapAt(x: int, y: int) { fn parseTilemapAt(x: int, y: int) {
//parse based on walkability, for now //parse based on walkability, for now
if (tilemap[y * MAP_GRID_WIDTH * 3 + x * 3 + 2] != 0) { if (tilemap[y * MAP_GRID_WIDTH * 3 + x * 3 + 2] > 0) {
return ""; //empty return ""; //empty
} }
@@ -555,7 +511,7 @@ fn generateSnapshotAt(x: int, y: int) {
result.push(0); result.push(0);
} }
else { else {
result.push(tilemap[(y+j) * MAP_GRID_WIDTH * 3 + (x+i) * 3 + 2] != 0 ? 1 : 0); //walkable result.push(tilemap[(y+j) * MAP_GRID_WIDTH * 3 + (x+i) * 3 + 2]); //walkable
} }
} }
} }

View File

@@ -37,6 +37,8 @@ fn onLoad(node: opaque) {
fn setTilemap(node: opaque, tilemap: [int]) { fn setTilemap(node: opaque, tilemap: [int]) {
assert tilemap, "provided tilemap is null (in setTilemap)"; assert tilemap, "provided tilemap is null (in setTilemap)";
print clock() + " - begin rendering map";
var child: opaque = node.getChildNode(0); var child: opaque = node.getChildNode(0);
setRenderTarget(child); setRenderTarget(child);
@@ -70,4 +72,6 @@ fn setTilemap(node: opaque, tilemap: [int]) {
//reset the render target to the screen //reset the render target to the screen
setRenderTarget(null); setRenderTarget(null);
print clock() + " - end rendering map";
} }