diff --git a/archive/modulemap.h b/archive/modulemap.h index ce126c6..759af4d 100644 --- a/archive/modulemap.h +++ b/archive/modulemap.h @@ -22,13 +22,13 @@ int moduleMapLoad(lua_State *L) { // Potentially provide up to 3 params chunkpos_t initial = { .x = 0, .y = 0, .z = 0 }; if(lua_isnumber(L, 2)) { - initial.x = (chunkunit_t)luaL_checkinteger(L, 2); + initial.x = (chunkunit_t)lua_tonumber(L, 2); } if(lua_isnumber(L, 3)) { - initial.y = (chunkunit_t)luaL_checkinteger(L, 3); + initial.y = (chunkunit_t)lua_tonumber(L, 3); } if(lua_isnumber(L, 4)) { - initial.z = (chunkunit_t)luaL_checkinteger(L, 4); + initial.z = (chunkunit_t)lua_tonumber(L, 4); } // Load the map. diff --git a/archive/scriptfuncentity.h b/archive/scriptfuncentity.h index 0232df0..40d4422 100644 --- a/archive/scriptfuncentity.h +++ b/archive/scriptfuncentity.h @@ -12,10 +12,9 @@ int scriptFuncEntityAdd(lua_State *L) { assertNotNull(L, "Lua state cannot be NULL"); + assertTrue(lua_isnumber(L, 1), "Expected integer entity type"); - assertTrue(lua_isinteger(L, 1), "Expected integer entity type"); - - lua_Integer entityType = luaL_checkinteger(L, 1); + entitytype_t entityType = (entitytype_t)luaL_checknumber(L, 1); assertTrue( entityType >= ENTITY_TYPE_NULL && entityType < ENTITY_TYPE_COUNT, "Invalid entity type passed to scriptFuncEntityAdd" diff --git a/assets/init.lua b/assets/init.lua index 651de26..bb83a01 100644 --- a/assets/init.lua +++ b/assets/init.lua @@ -1,5 +1,5 @@ -module('platform') module('input') +module('platform') module('scene') module('locale') @@ -22,8 +22,8 @@ elseif DOLPHIN then inputBind("down", INPUT_ACTION_DOWN) inputBind("left", INPUT_ACTION_LEFT) inputBind("right", INPUT_ACTION_RIGHT) - inputBind("circle", INPUT_ACTION_CANCEL) - inputBind("cross", INPUT_ACTION_ACCEPT) + inputBind("b", INPUT_ACTION_CANCEL) + inputBind("a", INPUT_ACTION_ACCEPT) inputBind("z", INPUT_ACTION_RAGEQUIT) inputBind("lstick_up", INPUT_ACTION_UP) inputBind("lstick_down", INPUT_ACTION_DOWN) diff --git a/assets/scene/initial.lua b/assets/scene/initial.lua index ed6eb03..fe17caa 100644 --- a/assets/scene/initial.lua +++ b/assets/scene/initial.lua @@ -11,7 +11,6 @@ module('glm') screenSetBackground(colorBlack()) -- mapLoad('map/testmap/testmap.dmf') camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) -mapCamera = cameraCreate() text = "Hello World" @@ -23,11 +22,10 @@ end function sceneRender() -- Map Test - -- mapCamera.position = vec3(300, 300, 300) -- cameraPushMatrix(mapCamera) -- mapRender() -- cameraPopMatrix() - + -- UI Test cameraPushMatrix(camera) camera.bottom = screenGetHeight() diff --git a/assets/ui/CMakeLists.txt b/assets/ui/CMakeLists.txt index f91b305..ffe622f 100644 --- a/assets/ui/CMakeLists.txt +++ b/assets/ui/CMakeLists.txt @@ -3,5 +3,4 @@ # This software is released under the MIT License. # https://opensource.org/licenses/MIT -add_asset(TILESET minogram.png type=ALPHA tileWidth=6 tileHeight=10 columns=16 rows=6) -# add_asset(TILESET minogram.png type=PALETTIZED tileWidth=6 tileHeight=10 columns=16 rows=6)# Fixes PSP rendering \ No newline at end of file +add_asset(TILESET minogram.png type=ALPHA tileWidth=6 tileHeight=10 columns=16 rows=6) \ No newline at end of file diff --git a/src/display/camera/camera.c b/src/display/camera/camera.c index 2edece6..059a2d4 100644 --- a/src/display/camera/camera.c +++ b/src/display/camera/camera.c @@ -57,10 +57,10 @@ void cameraPushMatrix(camera_t *camera) { case CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC: guOrtho( guProjection, + camera->orthographic.top, + camera->orthographic.bottom, camera->orthographic.left, camera->orthographic.right, - camera->orthographic.bottom, - camera->orthographic.top, camera->nearClip, camera->farClip ); @@ -115,16 +115,9 @@ void cameraPushMatrix(camera_t *camera) { break; case CAMERA_VIEW_TYPE_2D: - guOrtho( - guProjection, - camera->orthographic.top, - camera->orthographic.bottom, - camera->orthographic.left, - camera->orthographic.right, - camera->nearClip, - camera->farClip - ); - assertUnreachable("2D camera not implemented"); + guMtxIdentity(guView); + guMtxTrans(guView, -camera->_2d.position[0], -camera->_2d.position[1], 0.0f); + guMtxScale(guView, camera->_2d.zoom, camera->_2d.zoom, 1.0f); break; default: diff --git a/src/engine/engine.c b/src/engine/engine.c index 281d0da..670fe3b 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -39,7 +39,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) { errorChain(mapInit()); errorChain(sceneInit()); backpackInit(); - + // Run the initial script. scriptcontext_t ctx; errorChain(scriptContextInit(&ctx)); diff --git a/src/script/module/display/modulecamera.c b/src/script/module/display/modulecamera.c index ec73e55..6d70443 100644 --- a/src/script/module/display/modulecamera.c +++ b/src/script/module/display/modulecamera.c @@ -82,7 +82,11 @@ int moduleCameraCreate(lua_State *L) { // If we are provided a projection type, use it. cameraprojectiontype_t projType = CAMERA_PROJECTION_TYPE_PERSPECTIVE; if(lua_gettop(L) >= 1) { - projType = (cameraprojectiontype_t)luaL_checkinteger(L, 1); + if(!lua_isnumber(L, 1)) { + luaL_error(L, "Camera projection type must be a number."); + return 0; + } + projType = (cameraprojectiontype_t)lua_tonumber(L, 1); } // Create camera that Lua will own diff --git a/src/script/module/display/modulecolor.c b/src/script/module/display/modulecolor.c index d5825cb..9d0970d 100644 --- a/src/script/module/display/modulecolor.c +++ b/src/script/module/display/modulecolor.c @@ -78,19 +78,19 @@ int moduleColorIndex(lua_State *L) { assertNotNull(color, "Color struct cannot be NULL."); if(stringCompare(key, "r") == 0) { - lua_pushinteger(L, color->r); + lua_pushnumber(L, color->r); return 1; } if(stringCompare(key, "g") == 0) { - lua_pushinteger(L, color->g); + lua_pushnumber(L, color->g); return 1; } if(stringCompare(key, "b") == 0) { - lua_pushinteger(L, color->b); + lua_pushnumber(L, color->b); return 1; } if(stringCompare(key, "a") == 0) { - lua_pushinteger(L, color->a); + lua_pushnumber(L, color->a); return 1; } diff --git a/src/script/module/display/modulescreen.c b/src/script/module/display/modulescreen.c index fcd2e07..432969a 100644 --- a/src/script/module/display/modulescreen.c +++ b/src/script/module/display/modulescreen.c @@ -19,13 +19,13 @@ void moduleScreen(scriptcontext_t *context) { int moduleScreenGetWidth(lua_State *L) { assertNotNull(L, "Lua state is null"); - lua_pushinteger(L, SCREEN.width); + lua_pushnumber(L, SCREEN.width); return 1; } int moduleScreenGetHeight(lua_State *L) { assertNotNull(L, "Lua state is null"); - lua_pushinteger(L, SCREEN.height); + lua_pushnumber(L, SCREEN.height); return 1; } diff --git a/src/script/module/display/moduletext.c b/src/script/module/display/moduletext.c index 8805825..5ff4d8f 100644 --- a/src/script/module/display/moduletext.c +++ b/src/script/module/display/moduletext.c @@ -77,7 +77,7 @@ int moduleTextMeasure(lua_State *L) { &height ); - lua_pushinteger(L, width); - lua_pushinteger(L, height); + lua_pushnumber(L, width); + lua_pushnumber(L, height); return 2; } \ No newline at end of file diff --git a/src/script/module/event/moduleevent.c b/src/script/module/event/moduleevent.c index 2a8ab6b..db4186a 100644 --- a/src/script/module/event/moduleevent.c +++ b/src/script/module/event/moduleevent.c @@ -35,7 +35,7 @@ int moduleEventSubscribe(lua_State *L) { eventsub_t id = eventSubscribeScriptContext(event, context, 2); // Pass back to lua. - lua_pushinteger(L, id); + lua_pushnumber(L, id); return 1; } diff --git a/src/script/module/input/moduleinput.c b/src/script/module/input/moduleinput.c index 0fc29c7..c34a71a 100644 --- a/src/script/module/input/moduleinput.c +++ b/src/script/module/input/moduleinput.c @@ -39,9 +39,8 @@ void moduleInput(scriptcontext_t *context) { if(luaL_newmetatable(context->luaState, "input_mt")) { lua_pushcfunction(context->luaState, moduleInputIndex); lua_setfield(context->luaState, -2, "__index"); - lua_pop(context->luaState, 1); } - + lua_pop(context->luaState, 1); // Events lua_pushlightuserdata(context->luaState, &INPUT.eventPressed); @@ -61,10 +60,13 @@ int moduleInputIndex(lua_State *l) { assertStrLenMin(key, 1, "Key cannot be empty."); if(stringCompare(key, "action") == 0) { - lua_pushinteger( - l, - ((const inputevent_t*)lua_touserdata(l, 1))->action - ); + const inputevent_t *event = (const inputevent_t*)lua_touserdata(l, 1); + if(event == NULL) { + luaL_error(l, "Expected input event as first argument"); + return 0; + } + + lua_pushnumber(l, event->action); return 1; } @@ -82,24 +84,29 @@ int moduleInputBind(lua_State *L) { } // Expect action ID - if(!lua_isinteger(L, 2)) { + if(!lua_isnumber(L, 2)) { luaL_error(L, "inputBind: Expected action ID as second argument"); return 0; } const char_t *strBtn = lua_tostring(L, 1); - const inputaction_t action = (inputaction_t)lua_tointeger(L, 2); + const inputaction_t action = (inputaction_t)lua_tonumber(L, 2); + + if(strBtn == NULL || strlen(strBtn) == 0) { + luaL_error(L, "inputBind: Button name cannot be NULL or empty"); + return 0; + } // Validate action if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) { - luaL_error(L, "inputBind: Invalid action ID %d", (int)action); + luaL_error(L, "inputBind: Invalid action ID %d with str %s", action, strBtn); return 0; } // Get button by name inputbutton_t btn = inputButtonGetByName(strBtn); if(btn.type == INPUT_BUTTON_TYPE_NONE) { - printf("inputBind: Unknown button name '%s'\n", strBtn); + luaL_error(L, "inputBind: Invalid button name '%s'", strBtn); return 0; } diff --git a/src/script/module/item/moduleitem.c b/src/script/module/item/moduleitem.c index a38b9e0..3e26dbc 100644 --- a/src/script/module/item/moduleitem.c +++ b/src/script/module/item/moduleitem.c @@ -42,13 +42,13 @@ int moduleInventoryItemExists(lua_State *L) { return 0; } - if(!lua_isinteger(L, 2)) { + if(!lua_isnumber(L, 2)) { luaL_error(L, "inventoryItemExists: Expected item ID as second argument"); return 0; } inventory_t *inventory = (inventory_t *)lua_touserdata(L, 1); - itemid_t item = (itemid_t)lua_tointeger(L, 2); + itemid_t item = (itemid_t)lua_tonumber(L, 2); assertNotNull(inventory, "Inventory pointer cannot be NULL."); @@ -72,19 +72,19 @@ int moduleInventorySet(lua_State *L) { return 0; } - if(!lua_isinteger(L, 2)) { + if(!lua_isnumber(L, 2)) { luaL_error(L, "inventorySet: Expected item ID as second argument"); return 0; } - if(!lua_isinteger(L, 3)) { + if(!lua_isnumber(L, 3)) { luaL_error(L, "inventorySet: Expected quantity as third argument"); return 0; } inventory_t *inventory = (inventory_t *)lua_touserdata(L, 1); - itemid_t item = (itemid_t)lua_tointeger(L, 2); - uint8_t quantity = (uint8_t)lua_tointeger(L, 3); + itemid_t item = (itemid_t)lua_tonumber(L, 2); + uint8_t quantity = (uint8_t)lua_tonumber(L, 3); assertNotNull(inventory, "Inventory pointer cannot be NULL."); inventorySet(inventory, item, quantity); @@ -100,19 +100,19 @@ int moduleInventoryAdd(lua_State *L) { return 0; } - if(!lua_isinteger(L, 2)) { + if(!lua_isnumber(L, 2)) { luaL_error(L, "inventoryAdd: Expected item ID as second argument"); return 0; } - if(!lua_isinteger(L, 3)) { + if(!lua_isnumber(L, 3)) { luaL_error(L, "inventoryAdd: Expected quantity as third argument"); return 0; } inventory_t *inventory = (inventory_t *)lua_touserdata(L, 1); - itemid_t item = (itemid_t)lua_tointeger(L, 2); - uint8_t quantity = (uint8_t)lua_tointeger(L, 3); + itemid_t item = (itemid_t)lua_tonumber(L, 2); + uint8_t quantity = (uint8_t)lua_tonumber(L, 3); assertNotNull(inventory, "Inventory pointer cannot be NULL."); inventoryAdd(inventory, item, quantity); @@ -128,23 +128,23 @@ int moduleInventoryRemove(lua_State *L) { return 0; } - if(!lua_isinteger(L, 2)) { + if(!lua_isnumber(L, 2)) { luaL_error(L, "inventoryRemove: Expected item ID as second argument"); return 0; } inventory_t *inventory = (inventory_t *)lua_touserdata(L, 1); - itemid_t item = (itemid_t)lua_tointeger(L, 2); + itemid_t item = (itemid_t)lua_tonumber(L, 2); assertNotNull(inventory, "Inventory pointer cannot be NULL."); // if there is a third argument (quantity), then we are actually doing a // partial removal. if(lua_gettop(L) >= 3) { - if(!lua_isinteger(L, 3)) { + if(!lua_isnumber(L, 3)) { luaL_error(L, "inventoryRemove: Expected quantity as third argument"); return 0; } - uint8_t amount = (uint8_t)lua_tointeger(L, 3); + uint8_t amount = (uint8_t)lua_tonumber(L, 3); uint8_t currentQuantity = inventoryGetCount(inventory, item); if(amount >= currentQuantity) { // Remove entire stack @@ -170,18 +170,18 @@ int moduleInventoryGetCount(lua_State *L) { return 0; } - if(!lua_isinteger(L, 2)) { + if(!lua_isnumber(L, 2)) { luaL_error(L, "inventoryGetCount: Expected item ID as second argument"); return 0; } inventory_t *inventory = (inventory_t *)lua_touserdata(L, 1); - itemid_t item = (itemid_t)lua_tointeger(L, 2); + itemid_t item = (itemid_t)lua_tonumber(L, 2); assertNotNull(inventory, "Inventory pointer cannot be NULL."); uint8_t count = inventoryGetCount(inventory, item); - lua_pushinteger(L, count); + lua_pushnumber(L, count); return 1; } @@ -212,13 +212,13 @@ int moduleInventoryItemFull(lua_State *L) { return 0; } - if(!lua_isinteger(L, 2)) { + if(!lua_isnumber(L, 2)) { luaL_error(L, "inventoryItemFull: Expected item ID as second argument"); return 0; } inventory_t *inventory = (inventory_t *)lua_touserdata(L, 1); - itemid_t item = (itemid_t)lua_tointeger(L, 2); + itemid_t item = (itemid_t)lua_tonumber(L, 2); assertNotNull(inventory, "Inventory pointer cannot be NULL."); @@ -236,7 +236,7 @@ int moduleInventorySort(lua_State *L) { return 0; } - if(!lua_isinteger(L, 2)) { + if(!lua_isnumber(L, 2)) { luaL_error(L, "inventorySort: Expected sort type as second argument"); return 0; } @@ -253,7 +253,7 @@ int moduleInventorySort(lua_State *L) { } inventory_t *inventory = (inventory_t *)lua_touserdata(L, 1); - inventorysort_t sortBy = (inventorysort_t)lua_tointeger(L, 2); + inventorysort_t sortBy = (inventorysort_t)lua_tonumber(L, 2); assertNotNull(inventory, "Inventory pointer cannot be NULL."); inventorySort(inventory, sortBy, reverse); diff --git a/src/script/module/locale/modulelocale.c b/src/script/module/locale/modulelocale.c index e179809..51b327b 100644 --- a/src/script/module/locale/modulelocale.c +++ b/src/script/module/locale/modulelocale.c @@ -25,7 +25,7 @@ int moduleLocaleGet(lua_State *L) { // No arguments expected dusklocale_t locale = LOCALE.locale; - lua_pushinteger(L, (lua_Integer)locale); + lua_pushnumber(L, (lua_Number)locale); return 1; } @@ -33,13 +33,13 @@ int moduleLocaleSet(lua_State *L) { assertNotNull(L, "Lua state cannot be NULL"); // Requires locale ID - if(!lua_isinteger(L, 1)) { + if(!lua_isnumber(L, 1)) { luaL_error(L, "localeSet: Expected locale ID as first argument"); return 0; } errorret_t err; - dusklocale_t locale = (dusklocale_t)lua_tointeger(L, 1); + dusklocale_t locale = (dusklocale_t)lua_tonumber(L, 1); if(locale >= DUSK_LOCALE_COUNT || locale == DUSK_LOCALE_NULL) { luaL_error(L, "localeSet: Invalid locale ID"); return 0; @@ -61,11 +61,11 @@ int moduleLocaleGetName(lua_State *L) { // Optional ID, otherwise return current locale name dusklocale_t locale = LOCALE.locale; if(lua_gettop(L) >= 1) { - if(!lua_isinteger(L, 1)) { + if(!lua_isnumber(L, 1)) { luaL_error(L, "localeGetName: Expected locale ID as first argument"); return 0; } - locale = (dusklocale_t)lua_tointeger(L, 1); + locale = (dusklocale_t)lua_tonumber(L, 1); if(locale >= DUSK_LOCALE_COUNT || locale == DUSK_LOCALE_NULL) { luaL_error(L, "localeGetName: Invalid locale ID"); return 0; diff --git a/src/script/module/moduleplatform.h b/src/script/module/moduleplatform.h index 7a5365a..d4b8b18 100644 --- a/src/script/module/moduleplatform.h +++ b/src/script/module/moduleplatform.h @@ -13,13 +13,13 @@ #error "DUSK_TARGET_SYSTEM must be defined" #endif -#define PLATFORM_VALUE "PLATFORM = '" DUSK_TARGET_SYSTEM "'" +#define PLATFORM_VALUE "PLATFORM = '" DUSK_TARGET_SYSTEM "'\n" void modulePlatform(scriptcontext_t *ctx) { assertNotNull(ctx, "Script context cannot be NULL"); scriptContextExec(ctx, PLATFORM_VALUE); #if DOLPHIN - scriptContextExec(ctx, "DOLPHIN = true"); + scriptContextExec(ctx, "DOLPHIN = true\n"); #endif } \ No newline at end of file diff --git a/src/script/module/story/modulestoryflag.c b/src/script/module/story/modulestoryflag.c index 7f2efbc..c0dc665 100644 --- a/src/script/module/story/modulestoryflag.c +++ b/src/script/module/story/modulestoryflag.c @@ -31,14 +31,14 @@ int moduleStoryFlagGet(lua_State *L) { return 0; } - storyflag_t flag = (storyflag_t)lua_tointeger(L, 1); + storyflag_t flag = (storyflag_t)lua_tonumber(L, 1); if(flag <= STORY_FLAG_NULL || flag >= STORY_FLAG_COUNT) { luaL_error(L, "Invalid flag ID %d", flag); return 0; } storyflagvalue_t value = storyFlagGet(flag); - lua_pushinteger(L, value); + lua_pushnumber(L, value); return 1; } @@ -57,13 +57,13 @@ int moduleStoryFlagSet(lua_State *L) { return 0; } - storyflag_t flag = (storyflag_t)lua_tointeger(L, 1); + storyflag_t flag = (storyflag_t)lua_tonumber(L, 1); if(flag <= STORY_FLAG_NULL || flag >= STORY_FLAG_COUNT) { luaL_error(L, "Invalid flag ID %d", flag); return 0; } - storyflagvalue_t value = (storyflagvalue_t)lua_tointeger(L, 2); + storyflagvalue_t value = (storyflagvalue_t)lua_tonumber(L, 2); storyFlagSet(flag, value); return 0; } @@ -77,7 +77,7 @@ int moduleStoryFlagIncrement(lua_State *L) { return 0; } - storyflag_t flag = (storyflag_t)lua_tointeger(L, 1); + storyflag_t flag = (storyflag_t)lua_tonumber(L, 1); if(flag <= STORY_FLAG_NULL || flag >= STORY_FLAG_COUNT) { luaL_error(L, "Invalid flag ID %d", flag); return 0; @@ -97,7 +97,7 @@ int moduleStoryFlagDecrement(lua_State *L) { return 0; } - storyflag_t flag = (storyflag_t)lua_tointeger(L, 1); + storyflag_t flag = (storyflag_t)lua_tonumber(L, 1); if(flag <= STORY_FLAG_NULL || flag >= STORY_FLAG_COUNT) { luaL_error(L, "Invalid flag ID %d", flag); return 0; diff --git a/tools/input/csv/__main__.py b/tools/input/csv/__main__.py index 66c5a45..5e954b8 100644 --- a/tools/input/csv/__main__.py +++ b/tools/input/csv/__main__.py @@ -33,13 +33,13 @@ with open(args.csv, newline="", encoding="utf-8") as csvfile: # For each ID, create enum entry. count = 0 outHeader += "typedef enum {\n" - outHeader += f" INPUT_ACTION_NULL = {count},\n\n" + outHeader += f" INPUT_ACTION_NULL = 0x{count:x},\n\n" count += 1 for inputId in inputIds: inputIdValues[inputId] = count - outHeader += f" {csvIdToEnumName(inputId)} = {count},\n" + outHeader += f" {csvIdToEnumName(inputId)} = 0x{count:x},\n" count += 1 - outHeader += f"\n INPUT_ACTION_COUNT = {count}\n" + outHeader += f"\n INPUT_ACTION_COUNT = 0x{count:x}\n" outHeader += "} inputaction_t;\n\n" # Write IDs to char array.