iuno just screwing around tbh
This commit is contained in:
@@ -8,7 +8,7 @@ ENTITY_DIR_WEST = 1
|
||||
ENTITY_DIR_EAST = 2
|
||||
ENTITY_DIR_NORTH = 3
|
||||
|
||||
ENTITY_COUNT = 256
|
||||
ENTITY_COUNT = 128
|
||||
|
||||
ENTITY_TYPE_NULL = 0
|
||||
ENTITY_TYPE_PLAYER = 1
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
#include "script/scriptmanager.h"
|
||||
#include "debug/debug.h"
|
||||
|
||||
#include "script/scriptcontext.h"
|
||||
|
||||
engine_t ENGINE;
|
||||
|
||||
errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
||||
@@ -41,10 +39,9 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
||||
errorChain(sceneManagerInit());
|
||||
|
||||
// Run the initial script.
|
||||
scriptcontext_t testCtx;
|
||||
errorChain(scriptContextInit(&testCtx));
|
||||
errorChain(scriptContextExecFile(&testCtx, "script/test.dsf"));
|
||||
scriptContextDispose(&testCtx);
|
||||
errorChain(scriptContextInit(&ENGINE.mainScriptContext));
|
||||
errorChain(scriptContextExecFile(&ENGINE.mainScriptContext, "script/test.dsf"));
|
||||
scriptContextDispose(&ENGINE.mainScriptContext);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#pragma once
|
||||
#include "display/display.h"// Important to be included first.
|
||||
#include "error/error.h"
|
||||
#include "script/scriptcontext.h"
|
||||
|
||||
typedef struct {
|
||||
bool_t running;
|
||||
int32_t argc;
|
||||
const char_t **argv;
|
||||
scriptcontext_t mainScriptContext;
|
||||
} engine_t;
|
||||
|
||||
extern engine_t ENGINE;
|
||||
|
||||
@@ -15,9 +15,8 @@ map_t MAP;
|
||||
|
||||
errorret_t mapInit() {
|
||||
memoryZero(&MAP, sizeof(map_t));
|
||||
|
||||
// Init the default chunks. In future I'll probably make this based on where
|
||||
// the player spawns in to save an initial mapSet.
|
||||
|
||||
// Init the first chunks.
|
||||
chunkindex_t index = 0;
|
||||
for(chunkunit_t z = 0; z < MAP_CHUNK_DEPTH; z++) {
|
||||
for(chunkunit_t y = 0; y < MAP_CHUNK_HEIGHT; y++) {
|
||||
|
||||
@@ -18,12 +18,6 @@ errorret_t sceneManagerInit(void) {
|
||||
|
||||
sceneManagerRegisterScene(&SCENE_TEST);
|
||||
sceneManagerRegisterScene(&SCENE_MAP);
|
||||
|
||||
// Initial scene
|
||||
scene_t *initial = sceneManagerGetSceneByName("map");
|
||||
sceneManagerSetScene(initial);
|
||||
if(initial->init) errorChain(initial->init(&SCENE_MANAGER.sceneData));
|
||||
initial->flags |= SCENE_FLAG_INITIALIZED;
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "scene.h"
|
||||
#include "scenedata.h"
|
||||
|
||||
#define SCENE_MANAGER_SCENE_COUNT_MAX 32
|
||||
#define SCENE_MANAGER_SCENE_COUNT_MAX 16
|
||||
|
||||
typedef struct {
|
||||
scene_t *current;
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include "script/scriptcontext.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
|
||||
|
||||
void scriptFuncCamera(scriptcontext_t *context) {
|
||||
assertNotNull(context, "Script context cannot be NULL");
|
||||
}
|
||||
39
src/script/func/scriptfuncscene.h
Normal file
39
src/script/func/scriptfuncscene.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/scriptcontext.h"
|
||||
#include "scene/scenemanager.h"
|
||||
#include "debug/debug.h"
|
||||
#include "assert/assert.h"
|
||||
#include "error/error.h"
|
||||
|
||||
int32_t scriptFuncSetScene(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL");
|
||||
assertTrue(lua_isstring(L, 1), "First argument must be a string");
|
||||
|
||||
const char_t *sceneName = lua_tostring(L, 1);
|
||||
scene_t *scene = sceneManagerGetSceneByName(sceneName);
|
||||
assertNotNull(scene, "Scene with given name does not exist");
|
||||
|
||||
sceneManagerSetScene(scene);
|
||||
|
||||
if(scene->init) {
|
||||
errorret_t err = scene->init(&SCENE_MANAGER.sceneData);
|
||||
assertTrue(err.code == ERROR_OK, "Scene initialization failed");
|
||||
}
|
||||
scene->flags |= SCENE_FLAG_INITIALIZED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void scriptFuncScene(scriptcontext_t *context) {
|
||||
assertNotNull(context, "Script context cannot be NULL");
|
||||
|
||||
scriptContextRegFunc(context, "setScene", scriptFuncSetScene);
|
||||
}
|
||||
@@ -34,19 +34,19 @@ int32_t scriptFuncPrint(lua_State *L) {
|
||||
|
||||
int32_t scriptFuncInclude(lua_State *L) {
|
||||
assertNotNull(L, "Lua state cannot be NULL");
|
||||
assertTrue(lua_isstring(L, 1), "Expected string filename");
|
||||
|
||||
scriptcontext_t* ctx = *(scriptcontext_t**)lua_getextraspace(L);
|
||||
if (!ctx) return luaL_error(L, "Lua extraspace ctx not set");
|
||||
assertNotNull(ctx, "Script context cannot be NULL");
|
||||
|
||||
const char_t *filename = luaL_checkstring(L, 1);
|
||||
if(filename == NULL || filename[0] == '\0') {
|
||||
luaL_error(L, "Filename cannot be NULL or empty");
|
||||
return 0;
|
||||
}
|
||||
assertNotNull(filename, "Filename cannot be NULL");
|
||||
assertStrLenMin(filename, 1, "Filename cannot be empty");
|
||||
|
||||
//
|
||||
// Copy out filename to mutable buffer
|
||||
char_t buffer[1024];
|
||||
stringCopy(buffer, filename, 1024);
|
||||
|
||||
// Ensure it has .dsf extension
|
||||
size_t len = strlen(buffer);
|
||||
if(len < 4 || strcmp(&buffer[len - 4], ".dsf") != 0) {
|
||||
@@ -58,6 +58,7 @@ int32_t scriptFuncInclude(lua_State *L) {
|
||||
stringCopy(&buffer[len], ".dsf", 5);
|
||||
}
|
||||
|
||||
// Execute the script file
|
||||
errorret_t err = scriptContextExecFile(
|
||||
ctx,
|
||||
buffer
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "script/func/scriptfunccamera.h"
|
||||
#include "script/func/scriptfuncentity.h"
|
||||
#include "script/func/scriptfuncsystem.h"
|
||||
#include "script/func/scriptfuncscene.h"
|
||||
|
||||
errorret_t scriptContextInit(scriptcontext_t *context) {
|
||||
assertNotNull(context, "Script context cannot be NULL");
|
||||
@@ -30,9 +31,14 @@ errorret_t scriptContextInit(scriptcontext_t *context) {
|
||||
// Store context in Lua extraspace
|
||||
*(scriptcontext_t**)lua_getextraspace(context->luaState) = context;
|
||||
|
||||
// Register variables
|
||||
// scriptContextExec(context, "PLATFORM = 'DESKTOP'");
|
||||
|
||||
// Register functions
|
||||
scriptFuncSystem(context);
|
||||
scriptFuncEntity(context);
|
||||
scriptFuncCamera(context);
|
||||
scriptFuncScene(context);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user