From bcefd785993c835f2c60e65e597f28b94e56cd09 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Mon, 12 Jan 2026 07:28:24 +0900 Subject: [PATCH] add xml --- data/manifest.xml | 2 +- engine/CMakeLists.txt | 2 +- engine/data/manifest.xml | 2 +- engine/include/GearSrc/Foundation.h | 1 + engine/include/GearSrc/MachDep.h | 4 +++ engine/include/GearSrc/TypeDefs.h | 3 ++ engine/include/GearSrc/XML.h | 18 ++++++++++ engine/src/core.c | 22 +++++++++++- engine/src/xml.c | 52 +++++++++++++++++++++++++++++ 9 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 engine/include/GearSrc/XML.h create mode 100644 engine/src/xml.c diff --git a/data/manifest.xml b/data/manifest.xml index 0ea1ffa..af58785 100644 --- a/data/manifest.xml +++ b/data/manifest.xml @@ -1,4 +1,4 @@ - + bang.ogg diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 9a6773e..66d9ff3 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -19,7 +19,7 @@ file(GLOB GearSrc_SRC src/*.c) add_library(GearSrc SHARED ${GearSrc_SRC}) target_include_directories(GearSrc PUBLIC include) target_compile_definitions(GearSrc PRIVATE _GEARSRC) -target_link_libraries(GearSrc PRIVATE ode lz4) +target_link_libraries(GearSrc PRIVATE xemil ode lz4) target_link_options(GearSrc PRIVATE -static-libgcc -static-libstdc++) if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows") target_link_libraries(GearSrc PRIVATE m) diff --git a/engine/data/manifest.xml b/engine/data/manifest.xml index 9203f03..775961e 100644 --- a/engine/data/manifest.xml +++ b/engine/data/manifest.xml @@ -1,4 +1,4 @@ - + left.png diff --git a/engine/include/GearSrc/Foundation.h b/engine/include/GearSrc/Foundation.h index 1f690b4..0ffce5c 100644 --- a/engine/include/GearSrc/Foundation.h +++ b/engine/include/GearSrc/Foundation.h @@ -15,5 +15,6 @@ #include #include #include +#include #endif diff --git a/engine/include/GearSrc/MachDep.h b/engine/include/GearSrc/MachDep.h index 1d14942..f016600 100644 --- a/engine/include/GearSrc/MachDep.h +++ b/engine/include/GearSrc/MachDep.h @@ -7,6 +7,10 @@ #include #include +#ifdef _GEARSRC +#include +#endif + #if defined(_GEARSRC) && defined(_WIN32) #define GSDECL extern __declspec(dllexport) #elif defined(_WIN32) diff --git a/engine/include/GearSrc/TypeDefs.h b/engine/include/GearSrc/TypeDefs.h index 247bd92..2ab490f 100644 --- a/engine/include/GearSrc/TypeDefs.h +++ b/engine/include/GearSrc/TypeDefs.h @@ -48,6 +48,7 @@ typedef struct _GSFile* GSFile; typedef struct _GSResource* GSResource; typedef struct _GSGL* GSGL; typedef struct _GSSkyBox* GSSkyBox; +typedef xemil_t* GSXML; #else typedef void* GSClient; typedef void* GSServer; @@ -56,6 +57,7 @@ typedef void* GSFile; typedef void* GSResource; typedef void* GSGL; typedef void* GSSkyBox; +typedef void* GSXML; #endif typedef float GSNumber; typedef GSNumber GSVector2[2]; @@ -72,6 +74,7 @@ typedef void (*GSSleepCallback)(int ms); struct _GSResourceKV { char* key; GSResource value; + GSXML xml; }; #ifdef _GEARSRC diff --git a/engine/include/GearSrc/XML.h b/engine/include/GearSrc/XML.h new file mode 100644 index 0000000..7ee489d --- /dev/null +++ b/engine/include/GearSrc/XML.h @@ -0,0 +1,18 @@ +#ifndef __GEARSRC_XML_H__ +#define __GEARSRC_XML_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +GSDECL GSXML GSXMLOpen(GSEngine engine, const char* path); +GSDECL void GSXMLClose(GSXML xml); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/engine/src/core.c b/engine/src/core.c index 50e3a8e..bbb5a27 100644 --- a/engine/src/core.c +++ b/engine/src/core.c @@ -4,8 +4,9 @@ #include #include #include -#include #include +#include +#include #include @@ -20,8 +21,26 @@ void GSInit(void) { int GSEngineRegisterResource(GSEngine engine, const char* name, const char* path) { GSResource resource; if((resource = GSResourceOpen(engine, path)) != NULL) { + GSXML xl; + char* s = GSStringConcat(name, ":/manifest.xml"); + int ind; + shput(engine->resource, name, resource); + if((xl = GSXMLOpen(engine, s)) == NULL) { + free(s); + + GSResourceClose(resource); + + shdel(engine->resource, name); + + return 0; + } + free(s); + + ind = shgeti(engine->resource, name); + engine->resource[ind].xml = xl; + return 1; } @@ -76,6 +95,7 @@ GSEngine GSEngineCreate(GSEngineParam* param) { void GSEngineDestroy(GSEngine engine) { int i; for(i = 0; i < shlen(engine->resource); i++) { + GSXMLClose(engine->resource[i].xml); GSResourceClose(engine->resource[i].value); } shfree(engine->resource); diff --git a/engine/src/xml.c b/engine/src/xml.c new file mode 100644 index 0000000..e83387a --- /dev/null +++ b/engine/src/xml.c @@ -0,0 +1,52 @@ +#include + +#include + +typedef struct arg { + GSEngine engine; + const char* path; +} arg_t; + +static int driver_open(xemil_t* handle) { + arg_t* arg = handle->drv_arg; + + if((handle->drv_opaque = GSFileOpen(arg->engine, arg->path)) == NULL) return 0; + + return 1; +} + +static int driver_read(xemil_t* handle, void* data, int size) { + return GSFileRead(handle->drv_opaque, data, size); +} + +static void driver_close(xemil_t* handle) { + GSFileClose(handle->drv_opaque); +} + +static xl_driver_t driver_rec = { + driver_open, + driver_read, + driver_close}; +static xl_driver_t* driver = &driver_rec; + +GSXML GSXMLOpen(GSEngine engine, const char* path) { + arg_t arg; + xemil_t* xl; + + arg.engine = engine; + arg.path = path; + + xl = xl_open(driver, &arg); + if(xl == NULL) return NULL; + if(!xl_parse(xl)) { + xl_close(xl); + + return NULL; + } + + return xl; +} + +void GSXMLClose(GSXML xml) { + xl_close(xml); +}