From f86e26cdddd3af1d9a07243c3ffa7fba43caed33 Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 20 Jan 2026 14:07:56 +0900 Subject: [PATCH] use bool --- client/main.c | 22 +++++++++++++++++++ engine/include/GearSrc/Client.h | 2 ++ engine/include/GearSrc/Core.h | 2 +- engine/include/GearSrc/GL.h | 8 +++---- engine/include/GearSrc/TypeDefs.h | 5 +++++ engine/src/client.c | 36 +++++++++++++------------------ engine/src/core.c | 6 +++--- engine/src/gl_common.c | 14 ++++++------ engine/src/gl_shader.c | 16 +++++++------- engine/src/gl_shadow.c | 6 +++--- submodule/milsko | 2 +- 11 files changed, 71 insertions(+), 48 deletions(-) diff --git a/client/main.c b/client/main.c index a017b7a..5e2dcdc 100644 --- a/client/main.c +++ b/client/main.c @@ -33,6 +33,22 @@ static void tick(void){ while(!window->close && MwPending(window)) MwStep(window); } +static GSVector3 rot = {0, 0, 0}; +static GSModel model = NULL; + +static void render(GSEngine engine){ + GSGL gl = GSClientGetGL(GSEngineGetClient(engine)); + + GSGLPushMatrix(gl); + GSGLSetRotation(gl, rot); + if(model != NULL) GSModelDraw(model); + GSGLPopMatrix(gl); +} + +static void after_render(GSEngine engine){ + rot[0] = rot[1] = rot[2]++; +} + int main(int argc, char** argv){ GSEngineParam param; GSEngine engine; @@ -43,10 +59,16 @@ int main(int argc, char** argv){ param.get_tick = MwTimeGetTick; param.sleep = MwTimeSleep; param.gl_swapbuffer = gl_swapbuffer; + param.render = render; + param.after_render = after_render; GSInit(); if((engine = GSEngineCreate(¶m)) != NULL){ + model = GSModelOpen(engine, "game:/mdl/crate.gsm"); + + GSClientToggleSkybox(GSEngineGetClient(engine), GSTrue); + GSEngineLoop(engine); GSEngineDestroy(engine); } diff --git a/engine/include/GearSrc/Client.h b/engine/include/GearSrc/Client.h index 7bbb0bc..e8b47c6 100644 --- a/engine/include/GearSrc/Client.h +++ b/engine/include/GearSrc/Client.h @@ -11,6 +11,8 @@ extern "C" { GSDECL GSClient GSClientCreate(GSEngine engine); GSDECL void GSClientDestroy(GSClient client); GSDECL void GSClientStep(GSClient client); +GSDECL GSGL GSClientGetGL(GSClient client); +GSDECL void GSClientToggleSkybox(GSClient client, GSBool toggle); #ifdef __cplusplus } diff --git a/engine/include/GearSrc/Core.h b/engine/include/GearSrc/Core.h index a57e036..0901ab8 100644 --- a/engine/include/GearSrc/Core.h +++ b/engine/include/GearSrc/Core.h @@ -16,7 +16,7 @@ GSDECL void GSEngineParamInit(GSEngineParam* param); GSDECL void GSEngineLoop(GSEngine engine); GSDECL GSClient GSEngineGetClient(GSEngine engine); GSDECL GSServer GSEngineGetServer(GSEngine engine); -GSDECL int GSEngineRegisterResource(GSEngine engine, const char* name, const char* path); +GSDECL GSBool GSEngineRegisterResource(GSEngine engine, const char* name, const char* path); GSDECL void GSEngineUnregisterResource(GSEngine engine, const char* name); #ifdef __cplusplus diff --git a/engine/include/GearSrc/GL.h b/engine/include/GearSrc/GL.h index 337d461..fcc07c0 100644 --- a/engine/include/GearSrc/GL.h +++ b/engine/include/GearSrc/GL.h @@ -13,7 +13,7 @@ extern "C" { #define GSGLMaxDistance 100.0 /* gl_shader.c */ -GSDECL int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs); +GSDECL GSBool GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs); /* gl_texture.c */ GSDECL void GSGLTexturePrepare(GSGL gl, GLuint* texture, unsigned char* rgba, int width, int height); @@ -21,12 +21,12 @@ GSDECL void GSGLTextureSet(GSGL gl, GLuint texture); GSDECL void GSGLTextureDelete(GSGL gl, GLuint texture); /* gl_common.c */ -GSDECL int GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename); -GSDECL int GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix); +GSDECL GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename); +GSDECL GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix); /* gl_shadow.c */ GSDECL void GSGLShadowInit(GSGL gl); -GSDECL int GSGLShadowBeforeMapping(GSGL gl); +GSDECL GSBool GSGLShadowBeforeMapping(GSGL gl); GSDECL void GSGLShadowAfterMapping(GSGL gl); GSDECL void GSGLShadowEnd(GSGL gl); GSDECL void GSGLShadowDeinit(GSGL gl); diff --git a/engine/include/GearSrc/TypeDefs.h b/engine/include/GearSrc/TypeDefs.h index 3fc8412..5d8a4bb 100644 --- a/engine/include/GearSrc/TypeDefs.h +++ b/engine/include/GearSrc/TypeDefs.h @@ -78,6 +78,8 @@ typedef void (*GSReadyCallback)(int width, int height); typedef void (*GSTickCallback)(void); typedef long (*GSGetTickCallback)(void); typedef void (*GSSleepCallback)(int ms); +typedef void (*GSRenderCallback)(GSEngine engine); +typedef void (*GSAfterRenderCallback)(GSEngine engine); struct _GSResourceKV { char* key; @@ -107,6 +109,7 @@ struct _GSClient { GSVector3 camera; GSVector4 light0; GSSkyBox skybox; + GSBool skybox_enabled; }; struct _GSSkyBox { @@ -190,6 +193,8 @@ struct _GSEngineParam { GSTickCallback tick; GSGetTickCallback get_tick; GSSleepCallback sleep; + GSRenderCallback render; + GSAfterRenderCallback after_render; }; #endif diff --git a/engine/src/client.c b/engine/src/client.c index 36874c8..92db5c4 100644 --- a/engine/src/client.c +++ b/engine/src/client.c @@ -26,6 +26,8 @@ GSClient GSClientCreate(GSEngine engine) { client->light0[2] = 5; client->light0[3] = 1; + client->skybox_enabled = GSFalse; + client->gl = GSGLCreate(client); client->skybox = GSSkyBoxTry(client, "default"); @@ -43,20 +45,8 @@ void GSClientDestroy(GSClient client) { GSLog(GSLogInfo, "Destroyed client"); } -GSModel m = NULL; -GSVector3 rot = {0, 0, 0}; - static void scene(GSClient client) { - if(m == NULL) m = GSModelOpen(client->engine, "game:/mdl/crate.gsm"); - - rot[0]++; - rot[1]++; - rot[2]++; - - GSGLPushMatrix(client->gl); - GSGLSetRotation(client->gl, rot); - GSModelDraw(m); - GSGLPopMatrix(client->gl); + if(client->engine->param->render != NULL) client->engine->param->render(client->engine); } void GSClientStep(GSClient client) { @@ -71,17 +61,21 @@ void GSClientStep(GSClient client) { GSGLShadowAfterMapping(client->gl); } - if(client->skybox != NULL) GSSkyBoxDraw(client->skybox); + if(client->skybox_enabled){ + if(client->skybox != NULL) GSSkyBoxDraw(client->skybox); + } scene(client); GSGLShadowEnd(client->gl); client->engine->param->gl_swapbuffer(); - client->look_at[0] = 5 + cos(r) * 5; - client->look_at[2] = 5 + sin(r) * 5; - - client->look_at[0] = 0; - client->look_at[2] = 0; - - r += 0.1; + if(client->engine->param->after_render != NULL) client->engine->param->after_render(client->engine); +} + +GSGL GSClientGetGL(GSClient client){ + return client->gl; +} + +void GSClientToggleSkybox(GSClient client, GSBool toggle){ + client->skybox_enabled = toggle; } diff --git a/engine/src/core.c b/engine/src/core.c index 3f8e7b0..16dfdc1 100644 --- a/engine/src/core.c +++ b/engine/src/core.c @@ -17,17 +17,17 @@ void GSInit(void) { GSLog(GSLogInfo, "GearSrc Engine %s", version.string); } -int GSEngineRegisterResource(GSEngine engine, const char* name, const char* path) { +GSBool GSEngineRegisterResource(GSEngine engine, const char* name, const char* path) { GSResource resource; if((resource = GSResourceOpen(engine, path)) != NULL) { shput(engine->resource, name, resource); GSLog(GSLogInfo, "Registered resource %s as %s", path, name); - return 1; + return GSTrue; } - return 0; + return GSFalse; } void GSEngineUnregisterResource(GSEngine engine, const char* name) { diff --git a/engine/src/gl_common.c b/engine/src/gl_common.c index eef2733..5ab06af 100644 --- a/engine/src/gl_common.c +++ b/engine/src/gl_common.c @@ -5,15 +5,15 @@ #include -int GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename) { +GSBool GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const char* filename) { GSFile f = GSFileOpen(gl->engine, filename); unsigned char* data; unsigned char* rgba; unsigned long sz; int ch; - int st = 1; + GSBool st = GSTrue; int w, h; - if(f == NULL) return 0; + if(f == NULL) return GSFalse; sz = GSFileSize(f); @@ -22,7 +22,7 @@ int GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const GSFileClose(f); if((rgba = stbi_load_from_memory(data, sz, &w, &h, &ch, 4)) == NULL) { - st = 0; + st = GSFalse; } else { GSGLTexturePrepare(gl, texture, rgba, w, h); @@ -37,12 +37,12 @@ int GSGLTextureLoadFile(GSGL gl, GLuint* texture, int* width, int* height, const return st; } -int GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix) { +GSBool GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char* prefix) { char* png = GSStringConcat(prefix, ".png"); char* bmp = GSStringConcat(prefix, ".bmp"); char* jpg = GSStringConcat(prefix, ".jpg"); char* jpeg = GSStringConcat(prefix, ".jpeg"); - int st = 1; + GSBool st = GSTrue; if(GSGLTextureLoadFile(gl, texture, width, height, prefix)) { } else if(GSGLTextureLoadFile(gl, texture, width, height, png)) { @@ -50,7 +50,7 @@ int GSGLTextureTry(GSGL gl, GLuint* texture, int* width, int* height, const char } else if(GSGLTextureLoadFile(gl, texture, width, height, jpg)) { } else if(GSGLTextureLoadFile(gl, texture, width, height, jpeg)) { } else { - st = 0; + st = GSFalse; } free(jpeg); diff --git a/engine/src/gl_shader.c b/engine/src/gl_shader.c index 7e5a5c4..b7a0783 100644 --- a/engine/src/gl_shader.c +++ b/engine/src/gl_shader.c @@ -19,7 +19,7 @@ static void err(const char* path, GLuint shader) { free(e); } -int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) { +GSBool GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) { GLuint vsi; GLuint fsi; GSFile f; @@ -29,7 +29,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) { char* fss; GLint st; - if(glUseProgram == NULL) return 0; + if(glUseProgram == NULL) return GSFalse; if((f = GSFileOpen(gl->engine, vs)) != NULL) { int sz = GSFileSize(f); @@ -40,7 +40,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) { GSFileClose(f); } else { - return 0; + return GSFalse; } if((f = GSFileOpen(gl->engine, fs)) != NULL) { @@ -54,7 +54,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) { } else { free(vss); - return 0; + return GSFalse; } vsi = glCreateShader(GL_VERTEX_SHADER); @@ -72,7 +72,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) { glDeleteShader(fsi); free(vss); free(fss); - return 0; + return GSFalse; } glCompileShader(fsi); @@ -84,7 +84,7 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) { glDeleteShader(fsi); free(vss); free(fss); - return 0; + return GSFalse; } free(vss); @@ -102,8 +102,8 @@ int GSGLShaderPrepare(GSGL gl, GLuint* shader, const char* vs, const char* fs) { glGetProgramiv(*shader, GL_LINK_STATUS, &st); if(!st) { glDeleteProgram(*shader); - return 0; + return GSFalse; } - return 1; + return GSTrue; } diff --git a/engine/src/gl_shadow.c b/engine/src/gl_shadow.c index 3ab99af..6b25923 100644 --- a/engine/src/gl_shadow.c +++ b/engine/src/gl_shadow.c @@ -40,10 +40,10 @@ void GSGLShadowInit(GSGL gl) { } } -int GSGLShadowBeforeMapping(GSGL gl) { +GSBool GSGLShadowBeforeMapping(GSGL gl) { GSVector3 zero = {0, 0, 0}; - if(!gl->shadow_use_shader) return 0; + if(!gl->shadow_use_shader) return GSFalse; GSGLClear(gl); @@ -76,7 +76,7 @@ int GSGLShadowBeforeMapping(GSGL gl) { glPolygonOffset(1.1f, 4.0f); glEnable(GL_POLYGON_OFFSET_FILL); - return 1; + return GSTrue; } void GSGLShadowAfterMapping(GSGL gl) { diff --git a/submodule/milsko b/submodule/milsko index eb50af2..b458613 160000 --- a/submodule/milsko +++ b/submodule/milsko @@ -1 +1 @@ -Subproject commit eb50af2b815f7241d79233cd38c8a0186b3d2a6b +Subproject commit b458613f87b1cfcf05e0cf102688814861010d9f