All of a sudden, it's lagging like hell

This commit is contained in:
2023-02-28 05:59:44 +11:00
parent d3a3896efe
commit 14602b0750
7 changed files with 74 additions and 42 deletions

View File

@@ -1,17 +1,8 @@
//this is one layer
import standard;
import engine;
import node;
//TODO: reference these from a global source (root?)
var tileWidth: int const = 64;
var tileHeight: int const = 64;
var roomWidth: int const = 10;
var roomHeight: int const = 10;
var levelXCount: int const = 9;
var levelYCount: int const = 9;
//util to generate and init a child node of a given parent
fn makeChildSprite(parent: opaque, spriteName: string) {
@@ -32,9 +23,21 @@ fn onInit(node: opaque) {
fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
//get the constants from root
var root: opaque = getRootNode();
var tileWidth: int const = root.callNodeFn("getTileWidth");
var tileHeight: int const = root.callNodeFn("getTileHeight");
var roomWidth: int const = root.callNodeFn("getRoomWidth");
var roomHeight: int const = root.callNodeFn("getRoomHeight");
var levelXCount: int const = root.callNodeFn("getLevelXCount");
var levelYCount: int const = root.callNodeFn("getLevelYCount");
//calc the modifier ratio to offset things
var mod: float = float tileWidth / (tileWidth - depth);
var tileWidth_mod: float = tileWidth * mod;
var tileHeight_mod: float = tileHeight * mod;
var camX_mod: float = (camX - camW) * mod + camW/2;

View File

@@ -1,17 +1,8 @@
//this is one layer
import standard;
import engine;
import node;
//TODO: reference these from a global source (root?)
var tileWidth: int const = 64;
var tileHeight: int const = 64;
var roomWidth: int const = 10;
var roomHeight: int const = 10;
var levelXCount: int const = 9;
var levelYCount: int const = 9;
//util to generate and init a child node of a given parent
fn makeChildSprite(parent: opaque, spriteName: string) {
@@ -32,9 +23,21 @@ fn onInit(node: opaque) {
fn drawLayer(node: opaque, camX, camY, camW, camH, depth) {
//get the constants from root
var root: opaque = getRootNode();
var tileWidth: int const = root.callNodeFn("getTileWidth");
var tileHeight: int const = root.callNodeFn("getTileHeight");
var roomWidth: int const = root.callNodeFn("getRoomWidth");
var roomHeight: int const = root.callNodeFn("getRoomHeight");
var levelXCount: int const = root.callNodeFn("getLevelXCount");
var levelYCount: int const = root.callNodeFn("getLevelYCount");
//calc the modifier ratio to offset things
var mod: float = float tileWidth / (tileWidth - depth);
var tileWidth_mod: int = round(tileWidth * mod);
var tileHeight_mod: int = round(tileHeight * mod);
var camX_mod: int = round((camX - camW) * mod + camW/2);

View File

@@ -1,24 +1,11 @@
//this file manages the tilemap-related utilities
import standard;
import engine;
import node;
var camX: float = 0;
var camY: float = 0;
//TODO: reference these from a global source (root?)
var tileWidth: int const = 64;
var tileHeight: int const = 64;
var roomWidth: int const = 10;
var roomHeight: int const = 10;
var levelXCount: int const = 9;
var levelYCount: int const = 9;
var screenWidth: int const = 1080;
var screenHeight: int const = 720;
//util to generate and init a child node of a given parent
fn makeChild(parent: opaque, fname: string) {
var child: opaque = loadNode(fname);
@@ -44,6 +31,9 @@ fn onDraw(node: opaque) {
print stepCounter;
stepCounter = 0;
var screenWidth: int const = getRootNode().callNodeFn("getScreenWidth");
var screenHeight: int const = getRootNode().callNodeFn("getScreenHeight");
//iterate over each layer, passing in the screen dimensions
for (var c = 0; c < node.getChildNodeCount(); c++) {
node.getChildNode(c).callNodeFn("drawLayer", camX, camY, screenWidth, screenHeight, c * 4.0);