Compiles on dolphin, finally
All checks were successful
Build Dusk / run-tests (push) Successful in 1m39s
Build Dusk / build-linux (push) Successful in 1m34s
Build Dusk / build-psp (push) Successful in 2m7s
Build Dusk / build-dolphin (push) Successful in 1m48s

This commit is contained in:
2026-02-08 19:30:02 -06:00
parent ef25fb09da
commit 13c4df0d85
18 changed files with 84 additions and 84 deletions

View File

@@ -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.

View File

@@ -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"

View File

@@ -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)

View File

@@ -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()

View File

@@ -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
add_asset(TILESET minogram.png type=ALPHA tileWidth=6 tileHeight=10 columns=16 rows=6)

View File

@@ -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:

View File

@@ -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));

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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
}

View File

@@ -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;

View File

@@ -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.