Moved a few things around, definitely not clean but better.
Some checks failed
Build Dusk / run-tests (push) Failing after 2m3s
Build Dusk / build-linux (push) Successful in 2m13s
Build Dusk / build-psp (push) Successful in 1m56s

This commit is contained in:
2026-01-28 15:00:59 -06:00
parent c190271565
commit 794e0574ad
27 changed files with 558 additions and 66 deletions

View File

@@ -8,7 +8,7 @@
#pragma once #pragma once
#include "scene/scene.h" #include "scene/scene.h"
#include "rpg/entity/entity.h" #include "rpg/entity/entity.h"
#include "display/camera.h" #include "display/camera/camera.h"
#include "asset/asset.h" #include "asset/asset.h"
typedef struct { typedef struct {

View File

@@ -1,8 +1,14 @@
module('spritebatch') module('spritebatch')
module('time') module('time')
module('camera')
module('glm')
x = 0.0 camera = cameraCreate(CAMERA_PROJECTION_TYPE_PERSPECTIVE)
y = 0.0
print('Camera position')
print(camera.position.x)
print(camera.position.y)
print(camera.position.z)
function sceneDispose() function sceneDispose()
-- print('Disposing initial scene') -- print('Disposing initial scene')
@@ -10,19 +16,18 @@ end
function sceneUpdate() function sceneUpdate()
-- print('Updating initial scene') -- print('Updating initial scene')
x = x + TIME.delta * 10.0
y = y + TIME.delta * 10.0
end end
function sceneRender() function sceneRender()
-- print('Rendering initial scene') cameraPushMatrix(camera)
x1 = x + 32
y1 = y + 32
spriteBatchPush( spriteBatchPush(
nil, nil,
x, y, 0, 0,
x1, y1, 1, 1,
nil nil
) )
spriteBatchFlush() spriteBatchFlush()
cameraPopMatrix()
end end

View File

@@ -8,13 +8,13 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC PUBLIC
display.c display.c
framebuffer.c framebuffer.c
camera.c
screen.c screen.c
texture.c texture.c
spritebatch.c spritebatch.c
) )
# Subdirectories # Subdirectories
add_subdirectory(camera)
add_subdirectory(mesh) add_subdirectory(mesh)
add_subdirectory(palette) add_subdirectory(palette)
add_subdirectory(tileset) add_subdirectory(tileset)

View File

@@ -0,0 +1,10 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
camera.c
)

View File

@@ -9,8 +9,6 @@
#include "dusk.h" #include "dusk.h"
#include "display/color.h" #include "display/color.h"
#define CAMERA_COUNT_MAX 4
typedef enum { typedef enum {
CAMERA_PROJECTION_TYPE_PERSPECTIVE, CAMERA_PROJECTION_TYPE_PERSPECTIVE,
CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED, CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED,
@@ -32,20 +30,20 @@ typedef struct {
mat4 view; mat4 view;
struct { struct {
float_t position[3]; vec3 position;
float_t target[3]; vec3 target;
float_t up[3]; vec3 up;
} lookat; } lookat;
struct { struct {
float_t offset[3]; vec3 offset;
float_t target[3]; vec3 target;
float_t up[3]; vec3 up;
float_t pixelsPerUnit; float_t pixelsPerUnit;
} lookatPixelPerfect; } lookatPixelPerfect;
struct { struct {
float_t position[2]; vec2 position;
float_t zoom; float_t zoom;
} _2d; } _2d;
}; };

View File

@@ -8,7 +8,7 @@
#pragma once #pragma once
#include "displaydefs.h" #include "displaydefs.h"
#include "error/error.h" #include "error/error.h"
#include "display/camera.h" #include "display/camera/camera.h"
#include "display/framebuffer.h" #include "display/framebuffer.h"
typedef struct { typedef struct {

View File

@@ -8,7 +8,7 @@
#pragma once #pragma once
#include "dusk.h" #include "dusk.h"
#include "display/framebuffer.h" #include "display/framebuffer.h"
#include "display/camera.h" #include "display/camera/camera.h"
#include "display/mesh/quad.h" #include "display/mesh/quad.h"
#if DISPLAY_SIZE_DYNAMIC == 1 #if DISPLAY_SIZE_DYNAMIC == 1

View File

@@ -8,7 +8,7 @@
#include "event.h" #include "event.h"
#include "assert/assert.h" #include "assert/assert.h"
#include "util/memory.h" #include "util/memory.h"
#include "script/scriptstruct.h" #include "script/struct/scriptstruct.h"
void eventInit( void eventInit(
event_t *event, event_t *event,

View File

@@ -7,26 +7,20 @@
#include "assert/assert.h" #include "assert/assert.h"
#include "util/memory.h" #include "util/memory.h"
#include "display/camera.h" #include "display/camera/camera.h"
#include "display/screen.h" #include "display/screen.h"
scene_t SCENE; scene_t SCENE;
camera_t cam;
errorret_t sceneInit(void) { errorret_t sceneInit(void) {
memoryZero(&SCENE, sizeof(scene_t)); memoryZero(&SCENE, sizeof(scene_t));
cameraInitOrthographic(&cam);
errorChain(scriptContextInit(&SCENE.scriptContext)); errorChain(scriptContextInit(&SCENE.scriptContext));
errorOk(); errorOk();
} }
void sceneUpdate(void) { void sceneUpdate(void) {
if(!scriptContextHasFunc(&SCENE.scriptContext, "sceneUpdate")) { if(!scriptContextHasFunc(&SCENE.scriptContext, "sceneUpdate")) return;
return;
}
errorret_t err = scriptContextCallFunc( errorret_t err = scriptContextCallFunc(
&SCENE.scriptContext, "sceneUpdate", NULL, 0, NULL &SCENE.scriptContext, "sceneUpdate", NULL, 0, NULL
@@ -35,20 +29,11 @@ void sceneUpdate(void) {
} }
void sceneRender(void) { void sceneRender(void) {
if(!scriptContextHasFunc(&SCENE.scriptContext, "sceneRender")) { if(!scriptContextHasFunc(&SCENE.scriptContext, "sceneRender")) return;
return;
}
cam.orthographic.right = SCREEN.width;
cam.orthographic.bottom = SCREEN.height;
cam.orthographic.left = 0.0f;
cam.orthographic.top = 0.0f;
cameraPushMatrix(&cam);
errorret_t err = scriptContextCallFunc( errorret_t err = scriptContextCallFunc(
&SCENE.scriptContext, "sceneRender", NULL, 0, NULL &SCENE.scriptContext, "sceneRender", NULL, 0, NULL
); );
cameraPopMatrix();
errorCatch(errorPrint(err)); errorCatch(errorPrint(err));
} }

View File

@@ -9,8 +9,8 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
scriptmanager.c scriptmanager.c
scriptcontext.c scriptcontext.c
scriptmodule.c scriptmodule.c
scriptstruct.c
) )
# Subdirectories # Subdirectories
add_subdirectory(module) add_subdirectory(module)
add_subdirectory(struct)

View File

@@ -6,5 +6,8 @@
# Sources # Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME} target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC PUBLIC
moduleglm.c
modulecamera.c
modulespritebatch.c modulespritebatch.c
moduleglm.c
) )

View File

@@ -0,0 +1,300 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "modulecamera.h"
#include "assert/assert.h"
#include "display/camera/camera.h"
#include "util/memory.h"
#include "script/struct/scriptstruct.h"
#include "util/string.h"
void moduleCamera(scriptcontext_t *context) {
assertNotNull(context, "Context cannot be NULL.");
// Structure
scriptStructRegister(
context,
"camera_mt",
moduleCameraGetter,
moduleCameraSetter
);
// Definitions
#define MODULE_CAMERA_SCRIPT_LEN 64
char_t buffer[MODULE_CAMERA_SCRIPT_LEN];
#define MODULE_CAMERA_DEF(str, val) \
snprintf( \
buffer, \
MODULE_CAMERA_SCRIPT_LEN, \
"%s = %d", \
str, \
val \
); \
scriptContextExec(context, buffer);
MODULE_CAMERA_DEF(
"CAMERA_PROJECTION_TYPE_PERSPECTIVE",
CAMERA_PROJECTION_TYPE_PERSPECTIVE
);
MODULE_CAMERA_DEF(
"CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED",
CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED
);
MODULE_CAMERA_DEF(
"CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC",
CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC
);
MODULE_CAMERA_DEF(
"CAMERA_VIEW_TYPE_MATRIX",
CAMERA_VIEW_TYPE_MATRIX
);
MODULE_CAMERA_DEF(
"CAMERA_VIEW_TYPE_LOOKAT",
CAMERA_VIEW_TYPE_LOOKAT
);
MODULE_CAMERA_DEF(
"CAMERA_VIEW_TYPE_2D",
CAMERA_VIEW_TYPE_2D
);
MODULE_CAMERA_DEF(
"CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT",
CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT
);
// Methods
scriptContextRegFunc(context, "cameraCreate", moduleCameraCreate);
scriptContextRegFunc(context, "cameraPushMatrix", moduleCameraPushMatrix);
scriptContextRegFunc(context, "cameraPopMatrix", moduleCameraPopMatrix);
}
int moduleCameraCreate(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL.");
scriptcontext_t *context = *(scriptcontext_t **)lua_getextraspace(L);
assertNotNull(context, "Script context cannot be NULL.");
// 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);
}
// Create camera.
camera_t *cam = (camera_t *)lua_newuserdata(L, sizeof(camera_t));
memoryZero(cam, sizeof(camera_t));
// Push metatable.
scriptStructPushMetatable(context, "camera_mt", cam);
// Init camera
switch(projType) {
case CAMERA_PROJECTION_TYPE_PERSPECTIVE:
case CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED:
cameraInitPerspective(cam);
cam->projType = projType;
break;
case CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC:
cameraInitOrthographic(cam);
cam->projType = projType;
break;
default:
luaL_error(L, "Invalid camera projection type specified.");
break;
}
return 1;
}
int moduleCameraPushMatrix(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL.");
// Camera should be provided (pointer to camera_t).
camera_t *cam = *(camera_t **)lua_touserdata(L, 1);
assertNotNull(cam, "Camera pointer cannot be NULL.");
cameraPushMatrix(cam);
return 0;
}
int moduleCameraPopMatrix(lua_State *L) {
assertNotNull(L, "Lua state cannot be NULL.");
cameraPopMatrix();
return 0;
}
void moduleCameraGetter(
const scriptcontext_t *context,
const char_t *key,
const void *structPtr,
scriptvalue_t *outValue
) {
assertNotNull(context, "Script context cannot be NULL.");
assertNotNull(key, "Key cannot be NULL.");
assertNotNull(structPtr, "Structure pointer cannot be NULL.");
assertNotNull(outValue, "Output value cannot be NULL.");
camera_t *cam = (camera_t *)structPtr;
if(stringCompare(key, "near") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = cam->nearClip;
return;
} else if(stringCompare(key, "far") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = cam->farClip;
return;
} else if(stringCompare(key, "nearClip") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = cam->nearClip;
return;
} else if(stringCompare(key, "farClip") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = cam->farClip;
return;
}
// Perspective relative values
if(cam->projType == CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
if(stringCompare(key, "left") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = cam->orthographic.left;
return;
} else if(stringCompare(key, "right") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = cam->orthographic.right;
return;
} else if(stringCompare(key, "top") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = cam->orthographic.top;
return;
} else if(stringCompare(key, "bottom") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = cam->orthographic.bottom;
return;
}
} else if(
cam->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE ||
cam->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED
) {
if(stringCompare(key, "fov") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = cam->perspective.fov;
return;
}
}
// View type relative values.
if(cam->viewType == CAMERA_VIEW_TYPE_MATRIX) {
} else if(cam->viewType == CAMERA_VIEW_TYPE_LOOKAT) {
if(stringCompare(key, "position") == 0) {
scriptStructPushMetatable(
context,
"vec3_mt",
(void*)&cam->lookat.position
);
outValue->type = SCRIPT_VALUE_TYPE_USERDATA;
return;
}
} else if(cam->viewType == CAMERA_VIEW_TYPE_LOOKAT_PIXEL_PERFECT) {
} else if(cam->viewType == CAMERA_VIEW_TYPE_2D) {
}
}
void moduleCameraSetter(
const scriptcontext_t *context,
const char_t *key,
void *structPtr,
const scriptvalue_t *inValue
) {
assertNotNull(context, "Script context cannot be NULL.");
assertNotNull(key, "Key cannot be NULL.");
assertNotNull(structPtr, "Structure pointer cannot be NULL.");
assertNotNull(inValue, "Input value cannot be NULL.");
camera_t *cam = (camera_t *)structPtr;
if(stringCompare(key, "near") == 0) {
if(inValue->type == SCRIPT_VALUE_TYPE_FLOAT) {
cam->nearClip = inValue->value.floatValue;
} else if(inValue->type == SCRIPT_VALUE_TYPE_INT) {
cam->nearClip = (float_t)inValue->value.intValue;
}
return;
} else if(stringCompare(key, "far") == 0) {
if(inValue->type == SCRIPT_VALUE_TYPE_FLOAT) {
cam->farClip = inValue->value.floatValue;
} else if(inValue->type == SCRIPT_VALUE_TYPE_INT) {
cam->farClip = (float_t)inValue->value.intValue;
}
return;
} else if(stringCompare(key, "nearClip") == 0) {
if(inValue->type == SCRIPT_VALUE_TYPE_FLOAT) {
cam->nearClip = inValue->value.floatValue;
} else if(inValue->type == SCRIPT_VALUE_TYPE_INT) {
cam->nearClip = (float_t)inValue->value.intValue;
}
return;
} else if(stringCompare(key, "farClip") == 0) {
if(inValue->type == SCRIPT_VALUE_TYPE_FLOAT) {
cam->farClip = inValue->value.floatValue;
} else if(inValue->type == SCRIPT_VALUE_TYPE_INT) {
cam->farClip = (float_t)inValue->value.intValue;
}
return;
}
// Perspective relative values
if(cam->projType == CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
if(stringCompare(key, "left") == 0) {
if(inValue->type == SCRIPT_VALUE_TYPE_FLOAT) {
cam->orthographic.left = inValue->value.floatValue;
} else if(inValue->type == SCRIPT_VALUE_TYPE_INT) {
cam->orthographic.left = (float_t)inValue->value.intValue;
}
return;
} else if(stringCompare(key, "right") == 0) {
if(inValue->type == SCRIPT_VALUE_TYPE_FLOAT) {
cam->orthographic.right = inValue->value.floatValue;
} else if(inValue->type == SCRIPT_VALUE_TYPE_INT) {
cam->orthographic.right = (float_t)inValue->value.intValue;
}
return;
} else if(stringCompare(key, "top") == 0) {
if(inValue->type == SCRIPT_VALUE_TYPE_FLOAT) {
cam->orthographic.top = inValue->value.floatValue;
} else if(inValue->type == SCRIPT_VALUE_TYPE_INT) {
cam->orthographic.top = (float_t)inValue->value.intValue;
}
return;
} else if(stringCompare(key, "bottom") == 0) {
if(inValue->type == SCRIPT_VALUE_TYPE_FLOAT) {
cam->orthographic.bottom = inValue->value.floatValue;
} else if(inValue->type == SCRIPT_VALUE_TYPE_INT) {
cam->orthographic.bottom = (float_t)inValue->value.intValue;
}
return;
}
} else if(
cam->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE ||
cam->projType == CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED
) {
if(stringCompare(key, "fov") == 0) {
if(inValue->type == SCRIPT_VALUE_TYPE_FLOAT) {
cam->perspective.fov = inValue->value.floatValue;
} else if(inValue->type == SCRIPT_VALUE_TYPE_INT) {
cam->perspective.fov = (float_t)inValue->value.intValue;
}
return;
}
}
}

View File

@@ -0,0 +1,70 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "script/scriptcontext.h"
/**
* Register camera functions to the given script context.
*
* @param context The script context to register camera functions to.
*/
void moduleCamera(scriptcontext_t *context);
/**
* Script binding for creating a new camera.
*
* @param L The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleCameraCreate(lua_State *L);
/**
* Script binding for pushing the camera matrix onto the matrix stack.
*
* @param L The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleCameraPushMatrix(lua_State *L);
/**
* Script binding for popping the camera matrix from the matrix stack.
*
* @param L The Lua state.
* @return Number of return values on the Lua stack.
*/
int moduleCameraPopMatrix(lua_State *L);
/**
* Getter for camera structure fields.
*
* @param context The script context.
* @param key The field key.
* @param structPtr Pointer to the camera structure.
* @param outValue Output script value.
*/
void moduleCameraGetter(
const scriptcontext_t *context,
const char_t *key,
const void *structPtr,
scriptvalue_t *outValue
);
/**
* Setter for camera structure fields.
*
* @param context The script context.
* @param key The field key.
* @param structPtr Pointer to the camera structure.
* @param inValue Input script value.
*/
void moduleCameraSetter(
const scriptcontext_t *context,
const char_t *key,
void *structPtr,
const scriptvalue_t *inValue
);

View File

@@ -0,0 +1,49 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "moduleglm.h"
#include "assert/assert.h"
#include "script/struct/scriptstruct.h"
#include "util/string.h"
void moduleGLM(scriptcontext_t *context) {
assertNotNull(context, "Context cannot be NULL.");
scriptStructRegister(
context,
"vec3_mt",
moduleGLMVec3Getter,
NULL
);
}
void moduleGLMVec3Getter(
const scriptcontext_t *context,
const char_t *key,
const void *structPtr,
scriptvalue_t *outValue
) {
assertNotNull(context, "Script context cannot be NULL.");
assertNotNull(key, "Key cannot be NULL.");
assertNotNull(structPtr, "Structure pointer cannot be NULL.");
assertNotNull(outValue, "Output value cannot be NULL.");
vec3 *v = (vec3 *)structPtr;
if(stringCompare(key, "x") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = (*v)[0];
return;
} else if(stringCompare(key, "y") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = (*v)[1];
return;
} else if(stringCompare(key, "z") == 0) {
outValue->type = SCRIPT_VALUE_TYPE_FLOAT;
outValue->value.floatValue = (*v)[2];
return;
}
}

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "script/scriptcontext.h"
/**
* Registers the GLM module with the given script context.
*
* @param context The script context to register the module with.
*/
void moduleGLM(scriptcontext_t *context);
/**
* Getter function for the vec3 structure.
*
* @param context The script context.
* @param key The key to get.
* @param structPtr Pointer to the vec3 structure.
* @param outValue Pointer to store the output value.
*/
void moduleGLMVec3Getter(
const scriptcontext_t *context,
const char_t *key,
const void *structPtr,
scriptvalue_t *outValue
);

View File

@@ -9,6 +9,7 @@
#include "input/input.h" #include "input/input.h"
#include "assert/assert.h" #include "assert/assert.h"
#include "util/string.h" #include "util/string.h"
#include "script/struct/scriptstruct.h"
void moduleInput(scriptcontext_t *context) { void moduleInput(scriptcontext_t *context) {
assertNotNull(context, "Script context cannot be NULL"); assertNotNull(context, "Script context cannot be NULL");

View File

@@ -7,7 +7,6 @@
#pragma once #pragma once
#include "script/scriptcontext.h" #include "script/scriptcontext.h"
#include "script/scriptstruct.h"
/** /**
* Register input functions to the given script context. * Register input functions to the given script context.

View File

@@ -7,7 +7,7 @@
#include "moduletime.h" #include "moduletime.h"
#include "assert/assert.h" #include "assert/assert.h"
#include "script/scriptstruct.h" #include "script/struct/scriptstruct.h"
void moduleTime(scriptcontext_t *ctx) { void moduleTime(scriptcontext_t *ctx) {
assertNotNull(ctx, "Script context cannot be NULL"); assertNotNull(ctx, "Script context cannot be NULL");

View File

@@ -15,6 +15,8 @@
#include "script/module/time/moduletime.h" #include "script/module/time/moduletime.h"
#include "script/module/event/moduleevent.h" #include "script/module/event/moduleevent.h"
#include "script/module/display/modulespritebatch.h" #include "script/module/display/modulespritebatch.h"
#include "script/module/display/modulecamera.h"
#include "script/module/display/moduleglm.h"
#include "util/string.h" #include "util/string.h"
const scriptmodule_t SCRIPT_MODULE_LIST[] = { const scriptmodule_t SCRIPT_MODULE_LIST[] = {
@@ -27,6 +29,8 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = {
{ .name = "time", .callback = moduleTime }, { .name = "time", .callback = moduleTime },
{ .name = "event", .callback = moduleEvent }, { .name = "event", .callback = moduleEvent },
{ .name = "spritebatch", .callback = moduleSpriteBatch }, { .name = "spritebatch", .callback = moduleSpriteBatch },
{ .name = "camera", .callback = moduleCamera },
{ .name = "glm", .callback = moduleGLM },
}; };
#define SCRIPT_MODULE_COUNT ( \ #define SCRIPT_MODULE_COUNT ( \

View File

@@ -13,14 +13,15 @@
#define SCRIPT_VALUE_TYPE_FLOAT 2 #define SCRIPT_VALUE_TYPE_FLOAT 2
#define SCRIPT_VALUE_TYPE_STRING 3 #define SCRIPT_VALUE_TYPE_STRING 3
#define SCRIPT_VALUE_TYPE_BOOL 4 #define SCRIPT_VALUE_TYPE_BOOL 4
#define SCRIPT_VALUE_TYPE_USERDATA 5
typedef struct scriptvalue_s { typedef struct scriptvalue_s {
uint8_t type; uint8_t type;
union { union {
int32_t intValue; int32_t intValue;
float floatValue; float_t floatValue;
const char_t *strValue; const char_t *strValue;
bool boolValue; bool_t boolValue;
} value; } value;
} scriptvalue_t; } scriptvalue_t;

View File

@@ -0,0 +1,10 @@
# Copyright (c) 2026 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DUSK_LIBRARY_TARGET_NAME}
PUBLIC
scriptstruct.c
)

View File

@@ -73,9 +73,16 @@ int scriptStructIndex(lua_State *l) {
lua_pushboolean(l, outValue.value.boolValue); lua_pushboolean(l, outValue.value.boolValue);
break; break;
default: case SCRIPT_VALUE_TYPE_NIL:
lua_pushnil(l); lua_pushnil(l);
break; break;
case SCRIPT_VALUE_TYPE_USERDATA:
break;
default:
assertUnreachable("Unsupported value type for struct field retrieval");
break;
} }
return 1; return 1;
@@ -147,7 +154,7 @@ structmetatablecontext_t * scriptStructGetMetatableContext(lua_State *L) {
} }
void scriptStructPushMetatable( void scriptStructPushMetatable(
scriptcontext_t *context, const scriptcontext_t *context,
const char_t *metatableName, const char_t *metatableName,
void *structPtr void *structPtr
) { ) {

View File

@@ -6,21 +6,8 @@
*/ */
#pragma once #pragma once
#include "scriptcontext.h" #include "scriptstructgetter.h"
#include "scriptstructsetter.h"
typedef void (*scriptstructgetter_t)(
const scriptcontext_t *context,
const char_t *key,
const void *structPtr,
scriptvalue_t *outValue
);
typedef void (*scriptstructsetter_t)(
const scriptcontext_t *context,
const char_t *key,
void *structPtr,
const scriptvalue_t *inValue
);
typedef struct { typedef struct {
scriptcontext_t *context; scriptcontext_t *context;
@@ -78,7 +65,7 @@ structmetatablecontext_t *scriptStructGetMetatableContext(lua_State *l);
* @param structPtr Pointer to the structure to push. * @param structPtr Pointer to the structure to push.
*/ */
void scriptStructPushMetatable( void scriptStructPushMetatable(
scriptcontext_t *context, const scriptcontext_t *context,
const char_t *metatableName, const char_t *metatableName,
void *structPtr void *structPtr
); );

View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "script/scriptcontext.h"
typedef void (*scriptstructgetter_t)(
const scriptcontext_t *context,
const char_t *key,
const void *structPtr,
scriptvalue_t *outValue
);

View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "script/scriptcontext.h"
typedef void (*scriptstructsetter_t)(
const scriptcontext_t *context,
const char_t *key,
void *structPtr,
const scriptvalue_t *inValue
);

View File

@@ -9,7 +9,7 @@
#include "asset/asset.h" #include "asset/asset.h"
#include "display/texture.h" #include "display/texture.h"
#include "display/tileset/tileset.h" #include "display/tileset/tileset.h"
#include "display/camera.h" #include "display/camera/camera.h"
typedef struct { typedef struct {
camera_t camera; camera_t camera;