update api

This commit is contained in:
NishiOwO 2025-04-16 17:51:23 +09:00
parent ec15a060bb
commit 7e75c0357e
No known key found for this signature in database
GPG Key ID: 27EF69B208EB9343
30 changed files with 530 additions and 265 deletions

44
engine/gf_client.c Normal file
View File

@ -0,0 +1,44 @@
#define GF_EXPOSE_CLIENT
#include <gf_pre.h>
/* External library */
/* Interface */
#include <gf_client.h>
/* Engine */
#include <gf_draw.h>
#include <gf_log.h>
/* Standard */
#include <stdlib.h>
#include <string.h>
void gf_client_begin(void) { gf_draw_begin(); }
void gf_client_end(void) { gf_draw_end(); }
gf_client_t* gf_client_create(gf_engine_t* engine, const char* title) {
gf_client_t* client = malloc(sizeof(*client));
memset(client, 0, sizeof(*client));
client->engine = engine;
client->draw = gf_draw_create(engine, title);
if(client->draw == NULL) {
gf_log_function(engine, "Failed to create drawing interface", "");
gf_client_destroy(client);
return NULL;
}
return client;
}
void gf_client_destroy(gf_client_t* client) {
if(client->draw != NULL) gf_draw_destroy(client->draw);
gf_log_function(client->engine, "Destroyed client interface", "");
free(client);
}
int gf_client_step(gf_client_t* client) {
int s = gf_draw_step(client->draw);
return s;
}

View File

@ -11,8 +11,8 @@
#include <gf_core.h> #include <gf_core.h>
/* Engine */ /* Engine */
#include <gf_draw.h> #include <gf_client.h>
#include <gf_physics.h> #include <gf_server.h>
#include <gf_log.h> #include <gf_log.h>
#include <gf_version.h> #include <gf_version.h>
@ -37,13 +37,13 @@ void gf_engine_begin(void) {
WSAStartup(MAKEWORD(1, 1), &wsa); WSAStartup(MAKEWORD(1, 1), &wsa);
gf_log_function(NULL, "Winsock ready", ""); gf_log_function(NULL, "Winsock ready", "");
#endif #endif
gf_draw_begin(); gf_client_begin();
gf_physics_begin(); gf_server_begin();
} }
void gf_engine_end(void) { void gf_engine_end(void) {
gf_physics_end(); gf_server_end();
gf_draw_end(); gf_client_end();
} }
gf_engine_t* gf_engine_create(const char* title, int nogui) { gf_engine_t* gf_engine_create(const char* title, int nogui) {
@ -51,49 +51,47 @@ gf_engine_t* gf_engine_create(const char* title, int nogui) {
memset(engine, 0, sizeof(*engine)); memset(engine, 0, sizeof(*engine));
engine->log = stderr; engine->log = stderr;
if(nogui) { if(nogui) {
gf_log_function(NULL, "No GUI mode", ""); gf_log_function(engine, "No GUI mode", "");
engine->draw = NULL; engine->client = NULL;
} else { } else {
gf_log_function(NULL, "GUI mode", ""); gf_log_function(engine, "GUI mode", "");
engine->draw = gf_draw_create(engine, title); engine->client = gf_client_create(engine, title);
if(engine->draw == NULL) { if(engine->client == NULL) {
gf_log_function(NULL, "Failed to create drawing interface", ""); gf_log_function(engine, "Failed to create client interface", "");
free(engine); gf_engine_destroy(engine);
return NULL; return NULL;
} }
gf_log_function(engine, "Switching to graphical console", ""); gf_log_function(engine, "Switching to graphical console", "");
} }
engine->physics = gf_physics_create(); engine->server = gf_server_create(engine);
return engine; return engine;
} }
void gf_engine_set_draw(gf_engine_t* engine, void (*func)(gf_draw_t*)) { gf_draw_set_draw(engine->draw, func); }
/** /**
* Writing this so I don't forget * Writing this so I don't forget
* *
* 1. Calls gf_draw_step * 1. Calls gf_client_step
* 2. gf_draw_step calls gf_draw_platform_step (Platform-dependent) * 2. gf_client_step calls gf_draw_step
* 3. gf_draw_platform_step processes platform-dependent stuffs (e.g. events) * 3. gf_draw_step calls gf_draw_platform_step (Platform-dependent)
* 4. gf_draw_platform_step calls gf_draw_driver_before * 4. gf_draw_platform_step processes platform-dependent stuffs (e.g. events)
* 5. gf_draw_platform_step calls gf_draw_frame * 5. gf_draw_platform_step calls gf_draw_driver_before
* 6. gf_draw_frame calls gf_draw_t.draw to draw frame * 6. gf_draw_platform_step calls gf_draw_frame
* 7. gf_draw_frame draws more stuffs if required * 7. gf_draw_frame draws stuffs
* 8. gf_draw_platform_step calls gf_draw_driver_after * 8. gf_draw_platform_step calls gf_draw_driver_after
* 9. gf_draw_platform_step swaps buffers * 9. gf_draw_platform_step swaps buffers
* 10. Comes back here * 10. Comes back here
*/ */
void gf_engine_loop(gf_engine_t* engine) { void gf_engine_loop(gf_engine_t* engine) {
while(1) { while(1) {
if(engine->draw != NULL) { if(engine->client != NULL) {
if(gf_draw_step(engine->draw) != 0) break; if(gf_client_step(engine->client) != 0) break;
} }
} }
} }
void gf_engine_destroy(gf_engine_t* engine) { void gf_engine_destroy(gf_engine_t* engine) {
if(engine->physics != NULL) gf_physics_destroy(engine->physics); if(engine->server != NULL) gf_server_destroy(engine->server);
if(engine->draw != NULL) gf_draw_destroy(engine->draw); if(engine->client != NULL) gf_client_destroy(engine->client);
free(engine); free(engine);
gf_log_function(NULL, "Destroyed engine", ""); gf_log_function(NULL, "Destroyed engine", "");
} }

View File

@ -15,6 +15,7 @@
#include <gf_draw_driver.h> #include <gf_draw_driver.h>
#include <gf_texture.h> #include <gf_texture.h>
#include <gf_graphic.h> #include <gf_graphic.h>
#include <gf_font.h>
#include <gf_gui.h> #include <gf_gui.h>
/* Standard */ /* Standard */
@ -31,6 +32,7 @@ gf_texture_t* test_texture;
gf_draw_t* gf_draw_create(gf_engine_t* engine, const char* title) { gf_draw_t* gf_draw_create(gf_engine_t* engine, const char* title) {
gf_draw_t* draw = malloc(sizeof(*draw)); gf_draw_t* draw = malloc(sizeof(*draw));
memset(draw, 0, sizeof(*draw)); memset(draw, 0, sizeof(*draw));
draw->engine = engine;
draw->x = 0; draw->x = 0;
draw->y = 0; draw->y = 0;
draw->width = 640; draw->width = 640;
@ -38,10 +40,10 @@ gf_draw_t* gf_draw_create(gf_engine_t* engine, const char* title) {
draw->running = 0; draw->running = 0;
draw->draw_3d = 0; draw->draw_3d = 0;
strcpy(draw->title, title); strcpy(draw->title, title);
gf_draw_platform_create(draw); draw->platform = gf_draw_platform_create(engine, draw);
if(draw->platform != NULL) { if(draw->platform != NULL) {
gf_log_function(NULL, "Created drawing interface successfully", ""); int i;
gf_draw_driver_init(draw); draw->driver = gf_draw_driver_create(engine, draw);
gf_draw_reshape(draw); gf_draw_reshape(draw);
draw->running = 1; draw->running = 1;
@ -58,15 +60,30 @@ gf_draw_t* gf_draw_create(gf_engine_t* engine, const char* title) {
draw->lookat[1] = 0; draw->lookat[1] = 0;
draw->lookat[2] = 0; draw->lookat[2] = 0;
draw->gui = gf_gui_create(draw); draw->gui = gf_gui_create(engine, draw);
if(1) { if(1) {
int w, h, c; int w, h, c;
unsigned char* d = stbi_load("texture/test.bmp", &w, &h, &c, 4); unsigned char* d = stbi_load("texture/test.bmp", &w, &h, &c, 4);
test_texture = gf_texture_register(draw, w, h, d); test_texture = gf_texture_create(draw, w, h, d);
free(d); free(d);
} }
for(i = 0; i < sizeof(gf_font) / sizeof(gf_font[0]); i++) {
unsigned char* font = malloc(8 * 8 * 4);
int j;
for(j = 0; j < 8 * 8; j++) {
unsigned char val = (gf_font[i][j / 8] >> (j % 8)) & 1 ? 255 : 0;
font[j * 4 + 0] = val;
font[j * 4 + 1] = val;
font[j * 4 + 2] = val;
font[j * 4 + 3] = val;
}
draw->font[i] = gf_texture_create(draw, 8, 8, font);
free(font);
}
gf_log_function(engine, "Registered %d glyphs", sizeof(gf_font) / sizeof(gf_font[0]));
} else { } else {
free(draw); gf_draw_destroy(draw);
draw = NULL; draw = NULL;
} }
return draw; return draw;
@ -78,28 +95,25 @@ void gf_draw_reshape(gf_draw_t* draw) { gf_draw_driver_reshape(draw); }
void gf_draw_frame(gf_draw_t* draw) { void gf_draw_frame(gf_draw_t* draw) {
gf_graphic_color_t color; gf_graphic_color_t color;
color.r = color.g = color.b = color.a = 255; color.r = color.g = color.b = color.a = 255;
if(draw->draw_3d) { if(!draw->draw_3d) {
gf_graphic_draw_texture_polygon(draw, test_texture, color, GF_GRAPHIC_3D, 4,
/* clang-format off */
0.0, 0.0,
-1.0, 0.0, -1.0,
0.0, 4.0,
-1.0, 0.0, 1.0,
4.0, 4.0,
1.0, 0.0, 1.0,
4.0, 0.0,
1.0, 0.0, -1.0
/* clang-format on */
);
} }
gf_graphic_draw_texture_polygon(draw, test_texture, color, GF_GRAPHIC_3D, 4,
/* clang-format off */
0.0, 0.0,
-1.0, 0.0, -1.0,
0.0, 8.0,
-1.0, 0.0, 1.0,
8.0, 8.0,
1.0, 0.0, 1.0,
8.0, 0.0,
1.0, 0.0, -1.0
/* clang-format on */
);
if(draw->draw != NULL) draw->draw(draw);
} }
void gf_draw_set_draw(gf_draw_t* draw, void (*func)(gf_draw_t*)) { draw->draw = func; }
int gf_draw_step(gf_draw_t* draw) { int gf_draw_step(gf_draw_t* draw) {
int ret = gf_draw_platform_step(draw); int ret = gf_draw_platform_step(draw);
if(ret != 0) return ret; if(ret != 0) return ret;
@ -109,10 +123,14 @@ int gf_draw_step(gf_draw_t* draw) {
} }
void gf_draw_destroy(gf_draw_t* draw) { void gf_draw_destroy(gf_draw_t* draw) {
int i;
if(draw->running) { if(draw->running) {
gf_draw_driver_destroy(draw); int i;
for(i = 0; i < sizeof(gf_font) / sizeof(gf_font[0]); i++) {
gf_texture_destroy(draw->font[i]);
}
} }
gf_draw_platform_destroy(draw); if(draw->driver != NULL) gf_draw_driver_destroy(draw->driver);
gf_log_function(NULL, "Destroyed drawing interface", ""); if(draw->platform != NULL) gf_draw_platform_destroy(draw->platform);
gf_log_function(draw->engine, "Destroyed drawing interface", "");
free(draw);
} }

View File

@ -18,10 +18,12 @@
gf_graphic_color_t gf_gui_base_color; gf_graphic_color_t gf_gui_base_color;
gf_graphic_color_t gf_gui_font_color; gf_graphic_color_t gf_gui_font_color;
gf_gui_t* gf_gui_create(gf_draw_t* draw) { gf_gui_t* gf_gui_create(gf_engine_t* engine, gf_draw_t* draw) {
gf_gui_t* gui = malloc(sizeof(*gui)); gf_gui_t* gui = malloc(sizeof(*gui));
gf_gui_id_t i; gf_gui_id_t i;
gui->draw = draw; memset(gui, 0, sizeof(*gui));
gui->engine = engine;
gui->draw = draw;
GF_SET_COLOR(gf_gui_base_color, 48, 96, 48, 255); GF_SET_COLOR(gf_gui_base_color, 48, 96, 48, 255);
GF_SET_COLOR(gf_gui_font_color, 256 - 32, 256 - 32, 256 - 32, 255); GF_SET_COLOR(gf_gui_font_color, 256 - 32, 256 - 32, 256 - 32, 255);

View File

@ -18,8 +18,9 @@ void gf_physics_begin(void) { dInitODE(); }
void gf_physics_end(void) { dCloseODE(); } void gf_physics_end(void) { dCloseODE(); }
gf_physics_t* gf_physics_create(void) { gf_physics_t* gf_physics_create(gf_engine_t* engine) {
gf_physics_t* physics = malloc(sizeof(*physics)); gf_physics_t* physics = malloc(sizeof(*physics));
physics->engine = engine;
physics->id = dWorldCreate(); physics->id = dWorldCreate();
dWorldSetGravity(physics->id, 0, 0, -9.81); dWorldSetGravity(physics->id, 0, 0, -9.81);
return physics; return physics;
@ -27,6 +28,6 @@ gf_physics_t* gf_physics_create(void) {
void gf_physics_destroy(gf_physics_t* physics) { void gf_physics_destroy(gf_physics_t* physics) {
dWorldDestroy(physics->id); dWorldDestroy(physics->id);
gf_log_function(physics->engine, "Destroyed physics interface", "");
free(physics); free(physics);
gf_log_function(NULL, "Destroyed physics", "");
} }

39
engine/gf_server.c Normal file
View File

@ -0,0 +1,39 @@
#define GF_EXPOSE_SERVER
#include <gf_pre.h>
/* External library */
/* Interface */
#include <gf_server.h>
/* Engine */
#include <gf_physics.h>
#include <gf_log.h>
/* Standard */
#include <stdlib.h>
#include <string.h>
void gf_server_begin(void) { gf_physics_begin(); }
void gf_server_end(void) { gf_physics_end(); }
gf_server_t* gf_server_create(gf_engine_t* engine) {
gf_server_t* server = malloc(sizeof(*server));
memset(server, 0, sizeof(*server));
server->engine = engine;
server->physics = gf_physics_create(engine);
if(server->physics == NULL) {
gf_log_function(engine, "Failed to create physics interface", "");
gf_server_destroy(server);
return NULL;
}
return server;
}
void gf_server_destroy(gf_server_t* server) {
if(server->physics != NULL) gf_physics_destroy(server->physics);
gf_log_function(server->engine, "Destroyed server interface", "");
free(server);
}

View File

@ -14,7 +14,7 @@
/* Standard */ /* Standard */
#include <stdlib.h> #include <stdlib.h>
gf_texture_t* gf_texture_register(gf_draw_t* draw, int width, int height, unsigned char* data) { gf_texture_t* gf_texture_create(gf_draw_t* draw, int width, int height, unsigned char* data) {
gf_texture_t* texture = malloc(sizeof(*texture)); gf_texture_t* texture = malloc(sizeof(*texture));
gf_draw_driver_texture_t* ddtexture; gf_draw_driver_texture_t* ddtexture;
texture->internal_width = width; texture->internal_width = width;

View File

@ -15,7 +15,6 @@
#include <gf_texture.h> #include <gf_texture.h>
#include <gf_draw.h> #include <gf_draw.h>
#include <gf_log.h> #include <gf_log.h>
#include <gf_font.h>
#include <gf_math.h> #include <gf_math.h>
#include <gf_graphic.h> #include <gf_graphic.h>
@ -66,12 +65,14 @@ void gf_draw_driver_destroy_texture(gf_draw_driver_texture_t* t) {
free(t); free(t);
} }
void gf_draw_driver_init(gf_draw_t* draw) { gf_draw_driver_t* gf_draw_driver_create(gf_engine_t* engine, gf_draw_t* draw) {
int i; int i;
int w, h, ch; int w, h, ch;
draw->driver = malloc(sizeof(*draw->driver)); gf_draw_driver_t* draw_driver = malloc(sizeof(*draw_driver));
memset(draw_driver, 0, sizeof(*draw_driver));
draw_driver->engine = engine;
gf_log_function(NULL, "OpenGL renderer: %s", (char*)glGetString(GL_RENDERER)); gf_log_function(engine, "OpenGL renderer: %s", (char*)glGetString(GL_RENDERER));
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_NORMALIZE); glEnable(GL_NORMALIZE);
@ -94,22 +95,9 @@ void gf_draw_driver_init(gf_draw_t* draw) {
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightwht); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightwht);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightwht); glLightfv(GL_LIGHT0, GL_SPECULAR, lightwht);
for(i = 0; i < sizeof(gf_font) / sizeof(gf_font[0]); i++) {
unsigned char* font = malloc(8 * 8 * 4);
int j;
for(j = 0; j < 8 * 8; j++) {
unsigned char val = (gf_font[i][j / 8] >> (j % 8)) & 1 ? 255 : 0;
font[j * 4 + 0] = val;
font[j * 4 + 1] = val;
font[j * 4 + 2] = val;
font[j * 4 + 3] = val;
}
draw->font[i] = gf_texture_register(draw, 8, 8, font);
free(font);
}
gf_log_function(NULL, "Registered %d glyphs", sizeof(gf_font) / sizeof(gf_font[0]));
glClearColor(0, 0, 0, 1); glClearColor(0, 0, 0, 1);
return draw_driver;
} }
int gf_draw_driver_has_extension(gf_draw_t* draw, const char* query) { int gf_draw_driver_has_extension(gf_draw_t* draw, const char* query) {
@ -145,11 +133,9 @@ void gf_draw_driver_end_texture_2d(gf_draw_t* draw) {
void gf_draw_driver_set_color(gf_draw_t* draw, gf_graphic_color_t color) { glColor4f(color.r / 255, color.g / 255, color.b / 255, color.a / 255); } void gf_draw_driver_set_color(gf_draw_t* draw, gf_graphic_color_t color) { glColor4f(color.r / 255, color.g / 255, color.b / 255, color.a / 255); }
void gf_draw_driver_destroy(gf_draw_t* draw) { void gf_draw_driver_destroy(gf_draw_driver_t* driver) {
int i; gf_log_function(driver->engine, "Destroyed drawing driver", "");
for(i = 0; i < sizeof(gf_font) / sizeof(gf_font[0]); i++) { free(driver);
gf_texture_destroy(draw->font[i]);
}
} }
void gf_draw_driver_before(gf_draw_t* draw) { void gf_draw_driver_before(gf_draw_t* draw) {

View File

@ -63,30 +63,32 @@ int gf_draw_platform_step(gf_draw_t* draw) {
return ret; return ret;
} }
void gf_draw_platform_create(gf_draw_t* draw) { gf_draw_platform_t* gf_draw_platform_create(gf_engine_t* engine, gf_draw_t* draw) {
draw->platform = malloc(sizeof(*draw->platform)); gf_draw_platform_t* platform = malloc(sizeof(*platform));
memset(draw->platform, 0, sizeof(*draw->platform)); memset(platform, 0, sizeof(*platform));
platform->engine = engine;
draw->platform->window = glfwCreateWindow(draw->width, draw->height, draw->title, NULL, NULL); platform->window = glfwCreateWindow(draw->width, draw->height, draw->title, NULL, NULL);
if(draw->platform->window == NULL) { if(platform->window == NULL) {
gf_log_function(NULL, "Failed to create window", ""); gf_log_function(engine, "Failed to create window", "");
gf_draw_destroy(draw); gf_draw_platform_destroy(platform);
return; return NULL;
} }
glfwSetWindowUserPointer(draw->platform->window, draw); glfwSetWindowUserPointer(platform->window, draw);
glfwSetWindowSizeCallback(draw->platform->window, gf_glfw_size); glfwSetWindowSizeCallback(platform->window, gf_glfw_size);
glfwMakeContextCurrent(draw->platform->window); glfwMakeContextCurrent(platform->window);
#ifdef DO_SWAP_INTERVAL #ifdef DO_SWAP_INTERVAL
glfwSwapInterval(1); glfwSwapInterval(1);
#endif #endif
return platform;
} }
void gf_draw_platform_destroy(gf_draw_t* draw) { void gf_draw_platform_destroy(gf_draw_platform_t* platform) {
if(draw->platform->window != NULL) { if(platform->window != NULL) {
glfwDestroyWindow(draw->platform->window); glfwDestroyWindow(platform->window);
} }
free(draw->platform); gf_log_function(platform->engine, "Destroyed platform-dependent part of drawing driver", "");
draw->platform = NULL; free(platform);
} }

View File

@ -51,7 +51,7 @@ int gf_draw_platform_has_extension(gf_draw_t* draw, const char* query) {
return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0'))); return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0')));
} }
void gf_draw_platform_create(gf_draw_t* draw) { gf_draw_platform_t* gf_draw_platform_create(gf_engine_t* engine, gf_draw_t* draw) {
int i = 0; int i = 0;
int attribs[64]; int attribs[64];
int screen; int screen;
@ -60,15 +60,15 @@ void gf_draw_platform_create(gf_draw_t* draw) {
XSetWindowAttributes attr; XSetWindowAttributes attr;
XSizeHints hints; XSizeHints hints;
int interval = 0; int interval = 0;
gf_draw_platform_t* platform = malloc(sizeof(*platform));
memset(platform, 0, sizeof(*platform));
platform->engine = engine;
draw->platform = malloc(sizeof(*draw->platform)); platform->display = XOpenDisplay(NULL);
memset(draw->platform, 0, sizeof(*draw->platform)); if(platform->display == NULL) {
gf_log_function(engine, "Failed to open display", "");
draw->platform->display = XOpenDisplay(NULL); gf_draw_platform_destroy(platform);
if(draw->platform->display == NULL) { return NULL;
gf_log_function(NULL, "Failed to open display", "");
gf_draw_destroy(draw);
return;
} }
attribs[i++] = GLX_RGBA; attribs[i++] = GLX_RGBA;
attribs[i++] = GLX_DOUBLEBUFFER; attribs[i++] = GLX_DOUBLEBUFFER;
@ -84,52 +84,52 @@ void gf_draw_platform_create(gf_draw_t* draw) {
attribs[i++] = None; attribs[i++] = None;
screen = DefaultScreen(draw->platform->display); screen = DefaultScreen(platform->display);
root = RootWindow(draw->platform->display, screen); root = RootWindow(platform->display, screen);
visual = glXChooseVisual(draw->platform->display, screen, attribs); visual = glXChooseVisual(platform->display, screen, attribs);
if(visual == NULL) { if(visual == NULL) {
gf_log_function(NULL, "Failed to get visual", ""); gf_log_function(engine, "Failed to get visual", "");
gf_draw_destroy(draw); gf_draw_platform_destroy(platform);
return; return NULL;
} }
attr.colormap = XCreateColormap(draw->platform->display, root, visual->visual, AllocNone); attr.colormap = XCreateColormap(platform->display, root, visual->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask | PointerMotionMask; attr.event_mask = StructureNotifyMask | ExposureMask | PointerMotionMask;
draw->platform->window = XCreateWindow(draw->platform->display, root, draw->width, draw->height, draw->width, draw->height, 0, visual->depth, InputOutput, visual->visual, CWColormap | CWEventMask, &attr); platform->window = XCreateWindow(platform->display, root, draw->width, draw->height, draw->width, draw->height, 0, visual->depth, InputOutput, visual->visual, CWColormap | CWEventMask, &attr);
hints.x = draw->x; hints.x = draw->x;
hints.y = draw->y; hints.y = draw->y;
hints.width = draw->width; hints.width = draw->width;
hints.height = draw->height; hints.height = draw->height;
hints.flags = USSize | USPosition; hints.flags = USSize | USPosition;
XSetNormalHints(draw->platform->display, draw->platform->window, &hints); XSetNormalHints(platform->display, platform->window, &hints);
XSetStandardProperties(draw->platform->display, draw->platform->window, draw->title, "GoldFish", None, (char**)NULL, 0, &hints); XSetStandardProperties(platform->display, platform->window, draw->title, "GoldFish", None, (char**)NULL, 0, &hints);
draw->platform->wm_delete_window = XInternAtom(draw->platform->display, "WM_DELETE_WINDOW", False); platform->wm_delete_window = XInternAtom(platform->display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(draw->platform->display, draw->platform->window, &draw->platform->wm_delete_window, 1); XSetWMProtocols(platform->display, platform->window, &platform->wm_delete_window, 1);
draw->platform->context = glXCreateContext(draw->platform->display, visual, NULL, True); platform->context = glXCreateContext(platform->display, visual, NULL, True);
if(draw->platform->context == NULL) { if(platform->context == NULL) {
XFree(visual); XFree(visual);
gf_log_function(NULL, "Failed to get OpenGL context", ""); gf_log_function(engine, "Failed to get OpenGL context", "");
gf_draw_destroy(draw); gf_draw_platform_destroy(platform);
return; return NULL;
} }
XFree(visual); XFree(visual);
XMapWindow(draw->platform->display, draw->platform->window); XMapWindow(platform->display, platform->window);
glXMakeCurrent(draw->platform->display, draw->platform->window, draw->platform->context); glXMakeCurrent(platform->display, platform->window, platform->context);
#ifdef DO_SWAP_INTERVAL #ifdef DO_SWAP_INTERVAL
if(gf_draw_platform_has_extension(draw, "GLX_EXT_swap_control")) { if(gf_draw_platform_has_extension(draw, "GLX_EXT_swap_control")) {
unsigned int tmp = -1; unsigned int tmp = -1;
PFNGLXSWAPINTERVALEXTPROC proc = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB("glXSwapIntervalEXT"); PFNGLXSWAPINTERVALEXTPROC proc = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB("glXSwapIntervalEXT");
if(proc != NULL) { if(proc != NULL) {
proc(draw->platform->display, draw->platform->window, 1); proc(platform->display, platform->window, 1);
} }
glXQueryDrawable(draw->platform->display, draw->platform->window, GLX_SWAP_INTERVAL_EXT, &tmp); glXQueryDrawable(platform->display, platform->window, GLX_SWAP_INTERVAL_EXT, &tmp);
interval = tmp; interval = tmp;
} else if(gf_draw_platform_has_extension(draw, "GLX_MESA_swap_control")) { } else if(gf_draw_platform_has_extension(draw, "GLX_MESA_swap_control")) {
PFNGLXGETSWAPINTERVALMESAPROC proc = (PFNGLXGETSWAPINTERVALMESAPROC)glXGetProcAddressARB("glXGetSwapIntervalMESA"); PFNGLXGETSWAPINTERVALMESAPROC proc = (PFNGLXGETSWAPINTERVALMESAPROC)glXGetProcAddressARB("glXGetSwapIntervalMESA");
@ -144,9 +144,10 @@ void gf_draw_platform_create(gf_draw_t* draw) {
interval = 1; interval = 1;
} }
if(interval > 0) { if(interval > 0) {
gf_log_function(NULL, "Enabled VSync", ""); gf_log_function(engine, "Enabled VSync", "");
} }
#endif #endif
return platform;
} }
int gf_draw_platform_step(gf_draw_t* draw) { int gf_draw_platform_step(gf_draw_t* draw) {
@ -181,15 +182,15 @@ int gf_draw_platform_step(gf_draw_t* draw) {
return ret; return ret;
} }
void gf_draw_platform_destroy(gf_draw_t* draw) { void gf_draw_platform_destroy(gf_draw_platform_t* platform) {
if(draw->platform->context != NULL) { if(platform->context != NULL) {
glXMakeCurrent(draw->platform->display, None, NULL); glXMakeCurrent(platform->display, None, NULL);
glXDestroyContext(draw->platform->display, draw->platform->context); glXDestroyContext(platform->display, platform->context);
} }
if(draw->platform->display != NULL) { if(platform->display != NULL) {
XDestroyWindow(draw->platform->display, draw->platform->window); XDestroyWindow(platform->display, platform->window);
XCloseDisplay(draw->platform->display); XCloseDisplay(platform->display);
} }
free(draw->platform); gf_log_function(platform->engine, "Destroyed platform-dependent part of drawing driver", "");
draw->platform = NULL; free(platform);
} }

View File

@ -97,26 +97,24 @@ int gf_draw_platform_step(gf_draw_t* draw) {
return ret; return ret;
} }
void gf_draw_platform_create(gf_draw_t* draw) { gf_draw_platform_t* gf_draw_platform_create(gf_engine_t* engine, gf_draw_t* draw) {
WNDCLASSEX wc; WNDCLASSEX wc;
PIXELFORMATDESCRIPTOR desc; PIXELFORMATDESCRIPTOR desc;
#ifdef DO_SWAP_INTERVAL #ifdef DO_SWAP_INTERVAL
PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT; PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT;
#endif #endif
RECT rect; RECT rect;
int fmt; int fmt;
DWORD style; DWORD style;
gf_draw_platform_t* platform = malloc(sizeof(*platform));
memset(platform, 0, sizeof(*platform));
platform->engine = engine;
draw->platform = malloc(sizeof(*draw->platform)); platform->instance = (HINSTANCE)GetModuleHandle(NULL);
memset(draw->platform, 0, sizeof(*draw->platform)); if(platform->instance == NULL) {
gf_log_function(engine, "Failed to get instance", "");
draw->platform->instance = (HINSTANCE)GetModuleHandle(NULL); gf_draw_platform_destroy(platform);
if(draw->platform->instance == NULL) { return NULL;
gf_log_function(NULL, "Failed to get instance", "");
gf_draw_destroy(draw);
return;
} else {
gf_log_function(NULL, "Got instance", "");
} }
wc.cbSize = sizeof(wc); wc.cbSize = sizeof(wc);
@ -124,31 +122,27 @@ void gf_draw_platform_create(gf_draw_t* draw) {
wc.lpfnWndProc = gf_draw_platform_proc; wc.lpfnWndProc = gf_draw_platform_proc;
wc.cbClsExtra = 0; wc.cbClsExtra = 0;
wc.cbWndExtra = 0; wc.cbWndExtra = 0;
wc.hInstance = draw->platform->instance; wc.hInstance = platform->instance;
wc.hIcon = LoadIcon(draw->platform->instance, "GAME"); wc.hIcon = LoadIcon(platform->instance, "GAME");
wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL; wc.hbrBackground = NULL;
wc.lpszMenuName = NULL; wc.lpszMenuName = NULL;
wc.lpszClassName = "goldfish"; wc.lpszClassName = "goldfish";
wc.hIconSm = LoadIcon(draw->platform->instance, "GAME"); wc.hIconSm = LoadIcon(platform->instance, "GAME");
if(!RegisterClassEx(&wc)) { if(!RegisterClassEx(&wc)) {
gf_log_function(NULL, "Failed to register class", ""); gf_log_function(engine, "Failed to register class", "");
gf_draw_destroy(draw); gf_draw_platform_destroy(platform);
return; return NULL;
} else {
gf_log_function(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); platform->window = CreateWindow("goldfish", draw->title, (WS_OVERLAPPEDWINDOW), draw->x, draw->y, draw->width, draw->height, NULL, 0, platform->instance, NULL);
if(draw->platform->window == NULL) { if(platform->window == NULL) {
gf_log_function(NULL, "Failed to create window", ""); gf_log_function(engine, "Failed to create window", "");
gf_draw_destroy(draw); gf_draw_platform_destroy(platform);
return; return NULL;
} else {
gf_log_function(NULL, "Created window", "");
} }
SetWindowLongPtr(draw->platform->window, GWLP_USERDATA, (LONG_PTR)draw); SetWindowLongPtr(platform->window, GWLP_USERDATA, (LONG_PTR)draw);
memset(&desc, 0, sizeof(desc)); memset(&desc, 0, sizeof(desc));
desc.nSize = sizeof(desc); desc.nSize = sizeof(desc);
@ -159,51 +153,51 @@ void gf_draw_platform_create(gf_draw_t* draw) {
desc.cAlphaBits = 8; desc.cAlphaBits = 8;
desc.cDepthBits = 32; desc.cDepthBits = 32;
draw->platform->dc = GetDC(draw->platform->window); platform->dc = GetDC(platform->window);
fmt = ChoosePixelFormat(draw->platform->dc, &desc); fmt = ChoosePixelFormat(platform->dc, &desc);
SetPixelFormat(draw->platform->dc, fmt, &desc); SetPixelFormat(platform->dc, fmt, &desc);
draw->platform->glrc = wglCreateContext(draw->platform->dc); platform->glrc = wglCreateContext(platform->dc);
if(draw->platform->glrc == NULL) { if(platform->glrc == NULL) {
gf_log_function(NULL, "Failed to create OpenGL context", ""); gf_log_function(engine, "Failed to create OpenGL context", "");
gf_draw_destroy(draw); gf_draw_platform_destroy(platform);
return; return NULL;
} else {
gf_log_function(NULL, "Created OpenGL context", "");
} }
wglMakeCurrent(draw->platform->dc, draw->platform->glrc); wglMakeCurrent(platform->dc, platform->glrc);
#ifdef DO_SWAP_INTERVAL #ifdef DO_SWAP_INTERVAL
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT"); wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT != NULL) { if(wglSwapIntervalEXT != NULL) {
gf_log_function(NULL, "Enabled VSync", ""); gf_log_function(engine, "Enabled VSync", "");
wglSwapIntervalEXT(1); wglSwapIntervalEXT(1);
} }
#endif #endif
SetRect(&rect, 0, 0, draw->width, draw->height); SetRect(&rect, 0, 0, draw->width, draw->height);
style = (DWORD)GetWindowLongPtr(draw->platform->window, GWL_STYLE); style = (DWORD)GetWindowLongPtr(platform->window, GWL_STYLE);
AdjustWindowRect(&rect, style, FALSE); AdjustWindowRect(&rect, style, FALSE);
SetWindowPos(draw->platform->window, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE); SetWindowPos(platform->window, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE);
ShowWindow(draw->platform->window, SW_NORMAL); ShowWindow(platform->window, SW_NORMAL);
UpdateWindow(draw->platform->window); UpdateWindow(platform->window);
return platform;
} }
void gf_draw_platform_destroy(gf_draw_t* draw) { void gf_draw_platform_destroy(gf_draw_platform_t* platform) {
if(draw->platform->glrc != NULL) { if(platform->glrc != NULL) {
wglMakeCurrent(NULL, NULL); wglMakeCurrent(NULL, NULL);
} }
if(draw->platform->dc != NULL) { if(platform->dc != NULL) {
ReleaseDC(draw->platform->window, draw->platform->dc); ReleaseDC(platform->window, platform->dc);
} }
if(draw->platform->glrc != NULL) { if(platform->glrc != NULL) {
wglDeleteContext(draw->platform->glrc); wglDeleteContext(platform->glrc);
} }
if(draw->platform->window != NULL) { if(platform->window != NULL) {
DestroyWindow(draw->platform->window); DestroyWindow(platform->window);
} }
free(draw->platform); gf_log_function(platform->engine, "Destroyed platform-dependent part of drawing driver", "");
draw->platform = NULL; free(platform);
} }

View File

@ -0,0 +1,57 @@
/**
* @file gf_client.h
* @~english
* @brief Client interface
*/
#ifndef __GF_CLIENT_H__
#define __GF_CLIENT_H__
#include <gf_pre.h>
#include <gf_macro.h>
/* Type */
#include <gf_type/client.h>
/* Engine */
#include <gf_type/core.h>
/* Standard */
/**
* @~english
* @brief Initialize client interface
*/
GF_EXPORT void gf_client_begin(void);
/**
* @~english
* @brief Cleanup client interface
*/
GF_EXPORT void gf_client_end(void);
/**
* @~english
* @brief Create client interface
* @param engine Engine instance
* @param title Window title
* @return Client interface
*/
GF_EXPORT gf_client_t* gf_client_create(gf_engine_t* engine, const char* title);
/**
* @~english
* @brief Destroy client interface
* @param client Client interface
*/
GF_EXPORT void gf_client_destroy(gf_client_t* client);
/**
* @~english
* @brief Do client single step
* @param client Client interface
* @return `0` if successful, otherwise if failed
*/
GF_EXPORT int gf_client_step(gf_client_t* client);
#endif

View File

@ -47,14 +47,6 @@ GF_EXPORT gf_engine_t* gf_engine_create(const char* title, int nogui);
*/ */
GF_EXPORT void gf_engine_loop(gf_engine_t* engine); GF_EXPORT void gf_engine_loop(gf_engine_t* engine);
/**
* @~english
* @brief Set user-drawing callback
* @param engine Engine instance
* @param func Callback
*/
GF_EXPORT void gf_engine_set_draw(gf_engine_t* engine, void (*func)(gf_draw_t*));
/** /**
* @~english * @~english
* @brief Destroy engine instance * @brief Destroy engine instance

View File

@ -62,14 +62,6 @@ GF_EXPORT void gf_draw_begin(void);
*/ */
GF_EXPORT void gf_draw_end(void); GF_EXPORT void gf_draw_end(void);
/**
* @~english
* @brief Set user-drawing callback
* @param engine Engine instance
* @param func User-drawing callback
*/
GF_EXPORT void gf_draw_set_draw(gf_draw_t* engine, void (*func)(gf_draw_t*));
/** /**
* @~english * @~english
* @brief Do stuffs required on resizing window * @brief Do stuffs required on resizing window

View File

@ -18,22 +18,25 @@
#include <gf_type/draw.h> #include <gf_type/draw.h>
#include <gf_type/texture.h> #include <gf_type/texture.h>
#include <gf_type/graphic.h> #include <gf_type/graphic.h>
#include <gf_type/core.h>
/* Standard */ /* Standard */
/** /**
* @~english * @~english
* @brief Initialize drawing driver * @brief Initialize drawing driver
* @param engine Engine instance
* @param draw Drawing interface * @param draw Drawing interface
* @return Drawing driver
*/ */
GF_EXPORT void gf_draw_driver_init(gf_draw_t* draw); GF_EXPORT gf_draw_driver_t* gf_draw_driver_create(gf_engine_t* engine, gf_draw_t* draw);
/** /**
* @~english * @~english
* @brief Destroy drawing driver * @brief Destroy drawing driver
* @param draw Drawing interface * @param driver Drawing driver
*/ */
GF_EXPORT void gf_draw_driver_destroy(gf_draw_t* draw); GF_EXPORT void gf_draw_driver_destroy(gf_draw_driver_t* driver);
/** /**
* @~english * @~english

View File

@ -16,22 +16,25 @@
/* Engine */ /* Engine */
#include <gf_type/draw.h> #include <gf_type/draw.h>
#include <gf_type/core.h>
/* Standard */ /* Standard */
/** /**
* @~english * @~english
* @brief Create platform-dependent part of drawing driver * @brief Create platform-dependent part of drawing driver
* @param engine Engine instance
* @param draw Drawing interface * @param draw Drawing interface
* @return Platform-dependent part of drawing driver
*/ */
GF_EXPORT void gf_draw_platform_create(gf_draw_t* draw); GF_EXPORT gf_draw_platform_t* gf_draw_platform_create(gf_engine_t* engine, gf_draw_t* draw);
/** /**
* @~english * @~english
* @brief Destroy platform-dependent part of drawing driver * @brief Destroy platform-dependent part of drawing driver
* @param draw Drawing interface * @param platform Platform-dependent part of drawing driver
*/ */
GF_EXPORT void gf_draw_platform_destroy(gf_draw_t* draw); GF_EXPORT void gf_draw_platform_destroy(gf_draw_platform_t* platform);
/** /**
* @~english * @~english

View File

@ -15,6 +15,7 @@
/* Engine */ /* Engine */
#include <gf_type/draw.h> #include <gf_type/draw.h>
#include <gf_type/core.h>
/* Standard */ /* Standard */
@ -39,11 +40,12 @@
/** /**
* @~english * @~english
* @brief Create GUI * @brief Create GUI
* @param engine Engine instance
* @param draw Drawing interface * @param draw Drawing interface
* @return GUI * @return GUI
* @note You should not have to call this - simply use gf_draw_t::gui * @note You should not have to call this - simply use gf_draw_t::gui
*/ */
GF_EXPORT gf_gui_t* gf_gui_create(gf_draw_t* draw); GF_EXPORT gf_gui_t* gf_gui_create(gf_engine_t* engine, gf_draw_t* draw);
/** /**
* @~english * @~english

View File

@ -89,6 +89,22 @@
#define GF_EXPOSE_THREAD #define GF_EXPOSE_THREAD
#endif #endif
#ifndef GF_EXPOSE_CLIENT
/**
* @~english
* @brief Expose client interface properties
*/
#define GF_EXPOSE_CLIENT
#endif
#ifndef GF_EXPOSE_SERVER
/**
* @~english
* @brief Expose server interface properties
*/
#define GF_EXPOSE_SERVER
#endif
#ifndef GF_EXPOSE_GRAPHIC #ifndef GF_EXPOSE_GRAPHIC
/** /**
* @~english * @~english

View File

@ -12,6 +12,7 @@
/* Type */ /* Type */
#include <gf_type/physics.h> #include <gf_type/physics.h>
#include <gf_type/core.h>
/* Engine */ /* Engine */
@ -32,9 +33,10 @@ GF_EXPORT void gf_physics_end(void);
/** /**
* @~english * @~english
* @brief Create physics interface * @brief Create physics interface
* @param engine Engine instance
* @return Physics interface * @return Physics interface
*/ */
GF_EXPORT gf_physics_t* gf_physics_create(void); GF_EXPORT gf_physics_t* gf_physics_create(gf_engine_t* engine);
/** /**
* @~english * @~english

View File

@ -0,0 +1,48 @@
/**
* @file gf_server.h
* @~english
* @brief Client interface
*/
#ifndef __GF_SERVER_H__
#define __GF_SERVER_H__
#include <gf_pre.h>
#include <gf_macro.h>
/* Type */
#include <gf_type/server.h>
/* Engine */
#include <gf_type/core.h>
/* Standard */
/**
* @~english
* @brief Initialize server interface
*/
GF_EXPORT void gf_server_begin(void);
/**
* @~english
* @brief Cleanup server interface
*/
GF_EXPORT void gf_server_end(void);
/**
* @~english
* @brief Create server interface
* @param engine Engine instance
* @return Server interface
*/
GF_EXPORT gf_server_t* gf_server_create(gf_engine_t* engine);
/**
* @~english
* @brief Destroy server interface
* @param server Server interface
*/
GF_EXPORT void gf_server_destroy(gf_server_t* server);
#endif

View File

@ -20,14 +20,14 @@
/** /**
* @~english * @~english
* @brief Register texture * @brief Create texture
* @param draw Drawing interface * @param draw Drawing interface
* @param width Width of texture * @param width Width of texture
* @param height Height of texture * @param height Height of texture
* @param data Texture data * @param data Texture data
* @return Texture * @return Texture
*/ */
GF_EXPORT gf_texture_t* gf_texture_register(gf_draw_t* draw, int width, int height, unsigned char* data); GF_EXPORT gf_texture_t* gf_texture_create(gf_draw_t* draw, int width, int height, unsigned char* data);
/** /**
* @~english * @~english

View File

@ -0,0 +1,30 @@
/**
* @file gf_type/client.h
* @~english
* @brief Type definitions related to client interface
*/
#ifndef __GF_TYPE_CLIENT_H__
#define __GF_TYPE_CLIENT_H__
#include <gf_pre.h>
#include <gf_macro.h>
#ifdef GF_EXPOSE_CLIENT
/* External library */
/* Engine */
#include <gf_type/core.h>
#include <gf_type/draw.h>
/* Standard */
GF_DECLARE_TYPE(client, {
gf_engine_t* engine;
gf_draw_t* draw;
});
#else
typedef void gf_client_t;
#endif
#endif

View File

@ -14,8 +14,8 @@
/* External library */ /* External library */
/* Engine */ /* Engine */
#include <gf_type/physics.h> #include <gf_type/server.h>
#include <gf_type/draw.h> #include <gf_type/client.h>
/* Standard */ /* Standard */
#include <stdio.h> #include <stdio.h>
@ -25,13 +25,11 @@
* @~english * @~english
* @brief Engine instance * @brief Engine instance
* *
* @var gf_engine_t::physics * @var gf_engine_t::server
* @brief Physics interface * @brief Server interface
* @todo Create gf_server_t and move physics there
* *
* @var gf_engine_t::draw * @var gf_engine_t::client
* @brief Drawing interface * @brief Client interface
* @todo Create gf_client_t and move draw there
* *
* @var gf_engine_t::log * @var gf_engine_t::log
* @brief Log output * @brief Log output
@ -40,9 +38,9 @@
* @warning Destroying engien instance **does not** `fclose` this * @warning Destroying engien instance **does not** `fclose` this
*/ */
GF_DECLARE_TYPE(engine, { GF_DECLARE_TYPE(engine, {
gf_physics_t* physics; gf_server_t* server;
gf_draw_t* draw; gf_client_t* client;
FILE* log; FILE* log;
}); });
#else #else
typedef void gf_engine_t; typedef void gf_engine_t;

View File

@ -23,13 +23,14 @@
/* Standard */ /* Standard */
GF_DECLARE_TYPE(draw, );
/** /**
* @struct gf_draw_t * @struct gf_draw_t
* @~english * @~english
* @brief Drawing interface * @brief Drawing interface
* *
* @var gf_draw_t::engine
* @brief Engine instance
*
* @var gf_draw_t::platform * @var gf_draw_t::platform
* @brief Platform-dependent part of drawing driver * @brief Platform-dependent part of drawing driver
* *
@ -78,11 +79,9 @@ GF_DECLARE_TYPE(draw, );
* *
* @var gf_draw_t::camera * @var gf_draw_t::camera
* @brief Camera location * @brief Camera location
*
* @var gf_draw_t::draw
* @brief User-drawing callback
*/ */
GF_DECLARE_TYPE(draw, { GF_DECLARE_TYPE(draw, {
gf_engine_t* engine;
gf_draw_platform_t* platform; gf_draw_platform_t* platform;
gf_draw_driver_t* driver; gf_draw_driver_t* driver;
gf_gui_t* gui; gf_gui_t* gui;
@ -98,7 +97,6 @@ GF_DECLARE_TYPE(draw, {
gf_math_vector_t light; gf_math_vector_t light;
gf_math_vector_t lookat; gf_math_vector_t lookat;
gf_math_vector_t camera; gf_math_vector_t camera;
void (*draw)(gf_draw_t*);
}); });
#else #else
typedef void gf_draw_t; typedef void gf_draw_t;

View File

@ -17,15 +17,17 @@
#endif #endif
/* Engine */ /* Engine */
#include <gf_type/core.h>
/* Standard */ /* Standard */
#if defined(DRV_OPENGL) #if defined(DRV_OPENGL)
GF_DECLARE_TYPE(draw_driver, { int unused; }); GF_DECLARE_TYPE(draw_driver, { gf_engine_t* engine; });
GF_DECLARE_TYPE(draw_driver_texture, { GF_DECLARE_TYPE(draw_driver_texture, {
GLuint id; gf_engine_t* engine;
int width; GLuint id;
int height; int width;
int height;
}); });
#else #else
/** /**

View File

@ -17,26 +17,32 @@
#endif #endif
/* Engine */ /* Engine */
#include <gf_type/core.h>
/* Standard */ /* Standard */
#if defined(DRV_OPENGL) #if defined(DRV_OPENGL)
#if defined(USE_GLX) #if defined(USE_GLX)
GF_DECLARE_TYPE(draw_platform, { GF_DECLARE_TYPE(draw_platform, {
Display* display; gf_engine_t* engine;
Window window; Display* display;
GLXContext context; Window window;
Atom wm_delete_window; GLXContext context;
Atom wm_delete_window;
}); });
#elif defined(USE_WGL) #elif defined(USE_WGL)
GF_DECLARE_TYPE(draw_platform, { GF_DECLARE_TYPE(draw_platform, {
HINSTANCE instance; gf_engine_t* engine;
HWND window; HINSTANCE instance;
HDC dc; HWND window;
HGLRC glrc; HDC dc;
HGLRC glrc;
}); });
#elif defined(USE_GLFW) #elif defined(USE_GLFW)
GF_DECLARE_TYPE(draw_platform, { GLFWwindow* window; }); GF_DECLARE_TYPE(draw_platform, {
gf_engine_t* engine;
GLFWwindow* window;
});
#endif #endif
#else #else
/** /**

View File

@ -21,6 +21,7 @@ typedef int gf_gui_id_t;
/* Engine */ /* Engine */
#include <gf_type/draw.h> #include <gf_type/draw.h>
#include <gf_type/core.h>
/* Standard */ /* Standard */
@ -112,6 +113,7 @@ GF_DECLARE_TYPE(gui_component, {
* @brief Created components * @brief Created components
*/ */
GF_DECLARE_TYPE(gui, { GF_DECLARE_TYPE(gui, {
gf_engine_t* engine;
gf_draw_t* draw; gf_draw_t* draw;
gf_gui_component_t area[GF_GUI_MAX_COMPONENTS]; gf_gui_component_t area[GF_GUI_MAX_COMPONENTS];
}); });

View File

@ -15,6 +15,7 @@
#include <ode/ode.h> #include <ode/ode.h>
/* Engine */ /* Engine */
#include <gf_type/core.h>
/* Standard */ /* Standard */
@ -23,10 +24,16 @@
* @~english * @~english
* @brief Physics interface * @brief Physics interface
* *
* @var gf_physics_t::engine
* @brief Engine instance
*
* @var gf_physics_t::id * @var gf_physics_t::id
* @brief ODE's world ID * @brief ODE's world ID
*/ */
GF_DECLARE_TYPE(physics, { dWorldID id; }); GF_DECLARE_TYPE(physics, {
gf_engine_t* engine;
dWorldID id;
});
#else #else
typedef void gf_physics_t; typedef void gf_physics_t;
#endif #endif

View File

@ -0,0 +1,30 @@
/**
* @file gf_type/server.h
* @~english
* @brief Type definitions related to server interface
*/
#ifndef __GF_TYPE_SERVER_H__
#define __GF_TYPE_SERVER_H__
#include <gf_pre.h>
#include <gf_macro.h>
#ifdef GF_EXPOSE_SERVER
/* External library */
/* Engine */
#include <gf_type/core.h>
#include <gf_type/physics.h>
/* Standard */
GF_DECLARE_TYPE(server, {
gf_engine_t* engine;
gf_physics_t* physics;
});
#else
typedef void gf_server_t;
#endif
#endif

View File

@ -13,13 +13,6 @@
gf_engine_t* engine; gf_engine_t* engine;
gf_gui_id_t button1 = -1;
void draw_frame(gf_draw_t* draw) {
if(button1 == -1) button1 = gf_gui_create_button(draw->gui, 10, 10, 100, 50, "Test");
gf_gui_render(draw->gui);
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
char title[64]; char title[64];
gf_version_t ver; gf_version_t ver;
@ -32,7 +25,6 @@ int main(int argc, char** argv) {
gf_engine_end(); gf_engine_end();
return 1; return 1;
} }
gf_engine_set_draw(engine, draw_frame);
gf_engine_loop(engine); gf_engine_loop(engine);
gf_engine_destroy(engine); gf_engine_destroy(engine);
gf_engine_end(); gf_engine_end();