add property

This commit is contained in:
NishiOwO 2025-04-10 15:15:34 +09:00
parent 98395fdcb0
commit 25fcdd891f
No known key found for this signature in database
GPG Key ID: 27EF69B208EB9343
12 changed files with 57 additions and 37 deletions

View File

@ -19,6 +19,7 @@
/* Standard */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void gf_engine_begin(void) {
gf_version_t ver;
@ -26,14 +27,14 @@ void gf_engine_begin(void) {
WSADATA wsa;
#endif
gf_get_version(&ver);
gf_function_log("GoldFish Engine %s", ver.full);
gf_function_log("Lua %s", ver.lua);
gf_function_log("zlib %s", ver.zlib);
gf_function_log("Thread model: %s", ver.thread);
gf_function_log("Renderer: %s on %s", ver.driver, ver.backend);
gf_function_log(NULL, "GoldFish Engine %s", ver.full);
gf_function_log(NULL, "Lua %s", ver.lua);
gf_function_log(NULL, "zlib %s", ver.zlib);
gf_function_log(NULL, "Thread model: %s", ver.thread);
gf_function_log(NULL, "Renderer: %s on %s", ver.driver, ver.backend);
#ifdef _WIN32
WSAStartup(MAKEWORD(1, 1), &wsa);
gf_function_log("Winsock ready", "");
gf_function_log(NULL, "Winsock ready", "");
#endif
gf_draw_begin();
gf_physics_begin();
@ -47,17 +48,19 @@ void gf_engine_end(void) {
gf_engine_t* gf_engine_create(const char* title, int nogui) {
gf_engine_t* engine = malloc(sizeof(*engine));
memset(engine, 0, sizeof(*engine));
engine->log = stderr;
if(nogui) {
gf_function_log("No GUI mode", "");
gf_function_log(NULL, "No GUI mode", "");
engine->draw = NULL;
} else {
gf_function_log("GUI mode", "");
engine->draw = gf_draw_create(title);
gf_function_log(NULL, "GUI mode", "");
engine->draw = gf_draw_create(engine, title);
if(engine->draw == NULL) {
gf_function_log("Failed to create drawing interface", "");
gf_function_log(NULL, "Failed to create drawing interface", "");
free(engine);
return NULL;
}
gf_function_log(engine, "Switching to graphical console", "");
}
engine->physics = gf_physics_create();
return engine;
@ -90,5 +93,5 @@ void gf_engine_destroy(gf_engine_t* engine) {
if(engine->physics != NULL) gf_physics_destroy(engine->physics);
if(engine->draw != NULL) gf_draw_destroy(engine->draw);
free(engine);
gf_function_log("Destroyed engine", "");
gf_function_log(NULL, "Destroyed engine", "");
}

View File

@ -8,6 +8,7 @@
#include <gf_draw.h>
/* Engine */
#include <gf_core.h>
#include <gf_log.h>
#include <gf_draw_platform.h>
#include <gf_draw_driver.h>
@ -22,7 +23,7 @@ void gf_draw_begin(void) { gf_draw_platform_begin(); }
void gf_draw_end(void) { gf_draw_platform_end(); }
gf_draw_t* gf_draw_create(const char* title) {
gf_draw_t* gf_draw_create(gf_engine_t* engine, const char* title) {
gf_draw_t* draw = malloc(sizeof(*draw));
memset(draw, 0, sizeof(*draw));
draw->x = 0;
@ -33,7 +34,7 @@ gf_draw_t* gf_draw_create(const char* title) {
strcpy(draw->title, title);
gf_draw_platform_create(draw);
if(draw->platform != NULL) {
gf_function_log("Created drawing interface successfully", "");
gf_function_log(NULL, "Created drawing interface successfully", "");
gf_draw_driver_init(draw);
gf_draw_reshape(draw);
draw->running = 1;
@ -77,5 +78,5 @@ void gf_draw_destroy(gf_draw_t* draw) {
gf_draw_driver_destroy(draw);
}
gf_draw_platform_destroy(draw);
gf_function_log("Destroyed drawing interface", "");
gf_function_log(NULL, "Destroyed drawing interface", "");
}

View File

@ -1,3 +1,5 @@
#define GF_EXPOSE_CORE
#include <gf_pre.h>
/* External library */
@ -6,14 +8,22 @@
#include <gf_log.h>
/* Engine */
#include <gf_core.h>
/* Standard */
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
void gf_log(const char* fmt, ...) {
void gf_log(gf_engine_t* engine, const char* fmt, ...) {
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
FILE* out = stderr;
if(engine != NULL) {
out = engine->log;
}
if(out != NULL) {
va_start(va, fmt);
vfprintf(out, fmt, va);
va_end(va);
}
}

View File

@ -28,5 +28,5 @@ gf_physics_t* gf_physics_create(void) {
void gf_physics_destroy(gf_physics_t* physics) {
dWorldDestroy(physics->id);
free(physics);
gf_function_log("Destroyed physics", "");
gf_function_log(NULL, "Destroyed physics", "");
}

View File

@ -103,7 +103,7 @@ void gf_draw_driver_init(gf_draw_t* draw) {
draw->font[i] = gf_register_texture(draw, 8, 8, font);
free(font);
}
gf_function_log("Registered %d glyphs", sizeof(gf_font) / sizeof(gf_font[0]));
gf_function_log(NULL, "Registered %d glyphs", sizeof(gf_font) / sizeof(gf_font[0]));
glClearColor(0, 0, 0, 1);

View File

@ -71,7 +71,7 @@ void gf_draw_platform_create(gf_draw_t* draw) {
draw->platform->window = glfwCreateWindow(draw->width, draw->height, draw->title, NULL, NULL);
if(draw->platform->window == NULL) {
gf_function_log("Failed to create window", "");
gf_function_log(NULL, "Failed to create window", "");
gf_draw_destroy(draw);
return;
}

View File

@ -68,7 +68,7 @@ void gf_draw_platform_create(gf_draw_t* draw) {
draw->platform->display = XOpenDisplay(NULL);
if(draw->platform->display == NULL) {
gf_function_log("Failed to open display", "");
gf_function_log(NULL, "Failed to open display", "");
gf_draw_destroy(draw);
return;
}
@ -91,7 +91,7 @@ void gf_draw_platform_create(gf_draw_t* draw) {
visual = glXChooseVisual(draw->platform->display, screen, attribs);
if(visual == NULL) {
gf_function_log("Failed to get visual", "");
gf_function_log(NULL, "Failed to get visual", "");
gf_draw_destroy(draw);
return;
}
@ -114,7 +114,7 @@ void gf_draw_platform_create(gf_draw_t* draw) {
draw->platform->context = glXCreateContext(draw->platform->display, visual, NULL, True);
if(draw->platform->context == NULL) {
XFree(visual);
gf_function_log("Failed to get OpenGL context", "");
gf_function_log(NULL, "Failed to get OpenGL context", "");
gf_draw_destroy(draw);
return;
}
@ -146,7 +146,7 @@ void gf_draw_platform_create(gf_draw_t* draw) {
interval = 1;
}
if(interval > 0) {
gf_function_log("Enabled VSync", "");
gf_function_log(NULL, "Enabled VSync", "");
}
#endif
}

View File

@ -108,11 +108,11 @@ void gf_draw_platform_create(gf_draw_t* draw) {
draw->platform->instance = (HINSTANCE)GetModuleHandle(NULL);
if(draw->platform->instance == NULL) {
gf_function_log("Failed to get instance", "");
gf_function_log(NULL, "Failed to get instance", "");
gf_draw_destroy(draw);
return;
} else {
gf_function_log("Got instance", "");
gf_function_log(NULL, "Got instance", "");
}
wc.cbSize = sizeof(wc);
@ -128,20 +128,20 @@ void gf_draw_platform_create(gf_draw_t* draw) {
wc.lpszClassName = "goldfish";
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if(!RegisterClassEx(&wc)) {
gf_function_log("Failed to register class", "");
gf_function_log(NULL, "Failed to register class", "");
gf_draw_destroy(draw);
return;
} else {
gf_function_log("Registered class", "");
gf_function_log(NULL, "Registered class", "");
}
draw->platform->window = CreateWindow("goldfish", draw->title, (WS_OVERLAPPEDWINDOW), draw->x, draw->y, draw->width, draw->height, NULL, 0, draw->platform->instance, NULL);
if(draw->platform->window == NULL) {
gf_function_log("Failed to create window", "");
gf_function_log(NULL, "Failed to create window", "");
gf_draw_destroy(draw);
return;
} else {
gf_function_log("Created window", "");
gf_function_log(NULL, "Created window", "");
}
SetWindowLongPtr(draw->platform->window, GWLP_USERDATA, (LONG_PTR)draw);
@ -162,18 +162,18 @@ void gf_draw_platform_create(gf_draw_t* draw) {
draw->platform->glrc = wglCreateContext(draw->platform->dc);
if(draw->platform->glrc == NULL) {
gf_function_log("Failed to create OpenGL context", "");
gf_function_log(NULL, "Failed to create OpenGL context", "");
gf_draw_destroy(draw);
return;
} else {
gf_function_log("Created OpenGL context", "");
gf_function_log(NULL, "Created OpenGL context", "");
}
wglMakeCurrent(draw->platform->dc, draw->platform->glrc);
#ifdef DO_SWAP_INTERVAL
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT != NULL) {
gf_function_log("Enabled VSync", "");
gf_function_log(NULL, "Enabled VSync", "");
wglSwapIntervalEXT(1);
}
#endif

View File

@ -8,10 +8,11 @@
#include <gf_type/draw.h>
/* Engine */
#include <gf_type/core.h>
/* Standard */
gf_draw_t* gf_draw_create(const char* title);
gf_draw_t* gf_draw_create(gf_engine_t* engine, const char* title);
void gf_draw_destroy(gf_draw_t* draw);
void gf_draw_frame(gf_draw_t* draw);
int gf_draw_step(gf_draw_t* draw);

View File

@ -9,9 +9,10 @@
/* Engine */
/* Standard */
#include <gf_type/core.h>
#define gf_function_log(fmt, ...) gf_log("%6d %24s: " fmt "\n", __LINE__, __FUNCTION_NAME__, __VA_ARGS__)
#define gf_function_log(engine, fmt, ...) gf_log(engine, "%6d %24s: " fmt "\n", __LINE__, __FUNCTION_NAME__, __VA_ARGS__)
void gf_log(const char* fmt, ...);
void gf_log(gf_engine_t* engine, const char* fmt, ...);
#endif

View File

@ -12,10 +12,12 @@
#include <gf_type/draw.h>
/* Standard */
#include <stdio.h>
GF_DECLARE_TYPE(engine, {
gf_physics_t* physics;
gf_draw_t* draw;
FILE* log;
});
#else
typedef void gf_engine_t;

View File

@ -11,6 +11,7 @@
#include <gf_type/draw_platform.h>
#include <gf_type/draw_driver.h>
#include <gf_type/texture.h>
#include <gf_type/core.h>
#include <gf_type/math.h>
/* Standard */
@ -18,6 +19,7 @@
GF_DECLARE_TYPE(draw, );
GF_DECLARE_TYPE(draw, {
gf_engine_t* engine;
gf_draw_platform_t* platform;
gf_draw_driver_t* driver;
int close;