From dd697d5650d02f56361096c0930bcea7041b54f9 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Thu, 5 Feb 2026 08:43:49 -0600 Subject: [PATCH] Emu vs Real! --- assets/init.lua | 2 +- assets/scene/initial.lua | 62 ++++++++++++++++++++------------- src/engine/engine.c | 70 +++++++++++++++++++------------------- src/scene/scene.c | 26 +++++++++++++- src/script/scriptcontext.c | 2 +- 5 files changed, 101 insertions(+), 61 deletions(-) diff --git a/assets/init.lua b/assets/init.lua index dc559d5..46a3d5e 100644 --- a/assets/init.lua +++ b/assets/init.lua @@ -38,4 +38,4 @@ else end localeSet(DUSK_LOCALE_EN_US) --- sceneSet('scene/initial.dsf') \ No newline at end of file +sceneSet('scene/initial.dsf') \ No newline at end of file diff --git a/assets/scene/initial.lua b/assets/scene/initial.lua index 48e1b66..3469ca8 100644 --- a/assets/scene/initial.lua +++ b/assets/scene/initial.lua @@ -8,37 +8,53 @@ module('time') module('map') module('glm') -screenSetBackground(colorBlack()) -mapLoad('map/testmap/testmap.dmf') -camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) +screenSetBackground(colorLime()) mapCamera = cameraCreate() - -text = "Hello World" - +text = "Hello, Dusk!" function sceneDispose() end - function sceneUpdate() end - function sceneRender() - -- Map Test + mapCamera.position = vec3(4, 4, 4) cameraPushMatrix(mapCamera) - mapCamera.position = vec3(300, 300, 300) - mapRender() + spriteBatchPush(nil, -1, -1, 1, 1, colorBlue()) + spriteBatchFlush() cameraPopMatrix() +end - -- UI Test - cameraPushMatrix(camera) - camera.bottom = screenGetHeight() - camera.right = screenGetWidth() - width, height = textMeasure(text) - x = (screenGetWidth() - width) - x = math.sin(TIME.time * 2) * (x / 2) + (x / 2) - y = (screenGetHeight() - height) / 2 - y = math.cos(TIME.time * 3) * (y) + (y) - textDraw(x, y, text, colorMagenta()) +-- screenSetBackground(colorBlack()) +-- mapLoad('map/testmap/testmap.dmf') +-- camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) +-- mapCamera = cameraCreate() - cameraPopMatrix() -end \ No newline at end of file +-- text = "Hello World" + +-- function sceneDispose() +-- end + +-- function sceneUpdate() +-- end + +-- function sceneRender() +-- -- Map Test +-- mapCamera.position = vec3(300, 300, 300) +-- cameraPushMatrix(mapCamera) +-- mapRender() +-- cameraPopMatrix() + +-- -- UI Test +-- cameraPushMatrix(camera) +-- camera.bottom = screenGetHeight() +-- camera.right = screenGetWidth() + +-- width, height = textMeasure(text) +-- x = (screenGetWidth() - width) +-- x = math.sin(TIME.time * 2) * (x / 2) + (x / 2) +-- y = (screenGetHeight() - height) / 2 +-- y = math.cos(TIME.time * 3) * (y) + (y) +-- textDraw(x, y, text, colorMagenta()) + +-- cameraPopMatrix() +-- end \ No newline at end of file diff --git a/src/engine/engine.c b/src/engine/engine.c index fe49cf3..b0df1f6 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -45,42 +45,42 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { errorChain(scriptContextInit(&ctx)); // errorChain(scriptContextExecFile(&ctx, "init.dsf")); - errorChain(scriptContextExec(&ctx, - "printf('Lua still working')" - // "module('platform')\n" - // "module('input')\n" - // "module('scene')\n" - // "module('locale')\n" - // "if PLATFORM == \"psp\" then\n" - // " inputBind(\"up\", INPUT_ACTION_UP)\n" - // " inputBind(\"down\", INPUT_ACTION_DOWN)\n" - // " inputBind(\"left\", INPUT_ACTION_LEFT)\n" - // " inputBind(\"right\", INPUT_ACTION_RIGHT)\n" - // " inputBind(\"circle\", INPUT_ACTION_CANCEL)\n" - // " inputBind(\"cross\", INPUT_ACTION_ACCEPT)\n" - // " inputBind(\"select\", INPUT_ACTION_RAGEQUIT)\n" - // " inputBind(\"lstick_up\", INPUT_ACTION_UP)\n" - // " inputBind(\"lstick_down\", INPUT_ACTION_DOWN)\n" - // " inputBind(\"lstick_left\", INPUT_ACTION_LEFT)\n" - // " inputBind(\"lstick_right\", INPUT_ACTION_RIGHT)\n" - // "else\n" - // " if INPUT_KEYBOARD then\n" - // " inputBind(\"w\", INPUT_ACTION_UP)\n" - // " inputBind(\"s\", INPUT_ACTION_DOWN)\n" - // " inputBind(\"a\", INPUT_ACTION_LEFT)\n" - // " inputBind(\"d\", INPUT_ACTION_RIGHT)\n" - // " inputBind(\"left\", INPUT_ACTION_LEFT)\n" - // " inputBind(\"right\", INPUT_ACTION_RIGHT)\n" - // " inputBind(\"up\", INPUT_ACTION_UP)\n" - // " inputBind(\"down\", INPUT_ACTION_DOWN)\n" - // " inputBind(\"enter\", INPUT_ACTION_ACCEPT)\n" - // " inputBind(\"e\", INPUT_ACTION_ACCEPT)\n" - // " inputBind(\"q\", INPUT_ACTION_CANCEL)\n" - // " inputBind(\"escape\", INPUT_ACTION_RAGEQUIT)\n" - // " end \n" - // "end\n" + errorChain(scriptContextExec(&ctx, + "module('platform')\n" + "module('input')\n" + "module('scene')\n" + "module('locale')\n" + "if PLATFORM == \"psp\" then\n" + " inputBind(\"up\", INPUT_ACTION_UP)\n" + " inputBind(\"down\", INPUT_ACTION_DOWN)\n" + " inputBind(\"left\", INPUT_ACTION_LEFT)\n" + " inputBind(\"right\", INPUT_ACTION_RIGHT)\n" + " inputBind(\"circle\", INPUT_ACTION_CANCEL)\n" + " inputBind(\"cross\", INPUT_ACTION_ACCEPT)\n" + " inputBind(\"select\", INPUT_ACTION_RAGEQUIT)\n" + " inputBind(\"lstick_up\", INPUT_ACTION_UP)\n" + " inputBind(\"lstick_down\", INPUT_ACTION_DOWN)\n" + " inputBind(\"lstick_left\", INPUT_ACTION_LEFT)\n" + " inputBind(\"lstick_right\", INPUT_ACTION_RIGHT)\n" + "else\n" + " if INPUT_KEYBOARD then\n" + " inputBind(\"w\", INPUT_ACTION_UP)\n" + " inputBind(\"s\", INPUT_ACTION_DOWN)\n" + " inputBind(\"a\", INPUT_ACTION_LEFT)\n" + " inputBind(\"d\", INPUT_ACTION_RIGHT)\n" + " inputBind(\"left\", INPUT_ACTION_LEFT)\n" + " inputBind(\"right\", INPUT_ACTION_RIGHT)\n" + " inputBind(\"up\", INPUT_ACTION_UP)\n" + " inputBind(\"down\", INPUT_ACTION_DOWN)\n" + " inputBind(\"enter\", INPUT_ACTION_ACCEPT)\n" + " inputBind(\"e\", INPUT_ACTION_ACCEPT)\n" + " inputBind(\"q\", INPUT_ACTION_CANCEL)\n" + " inputBind(\"escape\", INPUT_ACTION_RAGEQUIT)\n" + " end \n" + "end\n" // "localeSet(DUSK_LOCALE_EN_US)\n" - // "print('Good here')" + "sceneSet('scene/initial.dsf')\n" + )); scriptContextDispose(&ctx); diff --git a/src/scene/scene.c b/src/scene/scene.c index d5a64c5..2ce754e 100644 --- a/src/scene/scene.c +++ b/src/scene/scene.c @@ -75,7 +75,31 @@ errorret_t sceneSet(const char_t *script) { // Create a new script context. errorChain(scriptContextInit(&SCENE.scriptContext)); - errorChain(scriptContextExecFile(&SCENE.scriptContext, script)); + // errorChain(scriptContextExecFile(&SCENE.scriptContext, script)); + errorChain(scriptContextExec(&SCENE.scriptContext, + "module('spritebatch')\n" + "module('camera')\n" + "module('color')\n" + "module('text')\n" + "module('screen')\n" + "module('time')\n" + "module('map')\n" + "module('glm')\n" + "screenSetBackground(colorLime())\n" + "mapCamera = cameraCreate()\n" + "text = 'Hello World'\n" + "function sceneDispose()\n" + "end\n" + "function sceneUpdate()\n" + "end\n" + "function sceneRender()\n" + " mapCamera.position = vec3(4, 4, 4)\n" + " cameraPushMatrix(mapCamera)\n" + " spriteBatchPush(nil, -1, -1, 1, 1, colorBlue())\n" + " spriteBatchFlush()\n" + " cameraPopMatrix()\n" + "end\n" + )); errorOk(); } diff --git a/src/script/scriptcontext.c b/src/script/scriptcontext.c index c95b8b1..872bac1 100644 --- a/src/script/scriptcontext.c +++ b/src/script/scriptcontext.c @@ -45,7 +45,7 @@ errorret_t scriptContextExec(scriptcontext_t *context, const char_t *script) { if(luaL_dostring(context->luaState, script) != LUA_OK) { const char_t *strErr = lua_tostring(context->luaState, -1); lua_pop(context->luaState, 1); - errorThrow("Failed to execute Lua: ", strErr); + errorThrow("Failed to execute Lua: %s", strErr); } errorOk();