assaultfish/engine/src/client.c

128 lines
3.1 KiB
C
Raw Normal View History

2026-01-12 01:54:35 +09:00
#include <GearSrc/Client.h>
2026-01-09 00:40:51 +09:00
2026-01-12 01:54:35 +09:00
#include <GearSrc/Log.h>
#include <GearSrc/GL.h>
#include <GearSrc/SkyBox.h>
#include <GearSrc/Math.h>
2026-01-13 04:28:36 +09:00
#include <GearSrc/Model.h>
2026-01-20 14:34:13 +09:00
#include <GearSrc/Version.h>
2026-01-09 00:40:51 +09:00
2026-01-12 01:54:35 +09:00
GSClient GSClientCreate(GSEngine engine) {
GSClient client = malloc(sizeof(*client));
2026-01-09 03:38:29 +09:00
memset(client, 0, sizeof(*client));
2026-01-09 06:12:57 +09:00
client->engine = engine;
2026-01-13 04:28:36 +09:00
client->camera[0] = 0;
2026-01-19 14:11:10 +09:00
client->camera[1] = 0;
2026-01-12 04:55:35 +09:00
client->camera[2] = 5;
2026-01-11 01:36:32 +09:00
client->look_at[0] = 0;
2026-01-13 04:28:36 +09:00
client->look_at[1] = 0;
2026-01-11 01:36:32 +09:00
client->look_at[2] = 0;
2026-01-12 04:41:17 +09:00
client->light0[0] = 2.5;
2026-01-11 17:43:03 +09:00
client->light0[1] = 5;
client->light0[2] = 5;
2026-01-11 18:27:41 +09:00
client->light0[3] = 1;
2026-01-11 01:36:32 +09:00
2026-01-20 14:07:56 +09:00
client->skybox_enabled = GSFalse;
2026-01-12 01:54:35 +09:00
client->gl = GSGLCreate(client);
2026-01-10 19:51:48 +09:00
2026-01-12 09:10:17 +09:00
client->skybox = GSSkyBoxTry(client, "default");
2026-01-12 01:03:18 +09:00
2026-01-20 14:34:13 +09:00
if(GSGLTextureTry(client->gl, &client->font, &client->font_width, &client->font_height, "game:/font")){
}else if(GSGLTextureTry(client->gl, &client->font, &client->font_width, &client->font_height, "base:/font")){
}else{
client->font = 0;
}
2026-01-12 01:54:35 +09:00
GSLog(GSLogInfo, "Created client");
2026-01-09 00:40:51 +09:00
2026-01-09 03:38:29 +09:00
return client;
2026-01-09 00:40:51 +09:00
}
2026-01-12 01:54:35 +09:00
void GSClientDestroy(GSClient client) {
2026-01-20 14:34:13 +09:00
if(client->font != 0) GSGLTextureDelete(client->gl, client->font);
2026-01-12 01:54:35 +09:00
GSGLDestroy(client->gl);
2026-01-10 19:51:48 +09:00
2026-01-09 00:40:51 +09:00
free(client);
2026-01-10 19:51:48 +09:00
2026-01-12 01:54:35 +09:00
GSLog(GSLogInfo, "Destroyed client");
2026-01-09 00:40:51 +09:00
}
2026-01-09 03:38:29 +09:00
2026-01-12 01:54:35 +09:00
static void scene(GSClient client) {
2026-01-20 14:07:56 +09:00
if(client->engine->param->render != NULL) client->engine->param->render(client->engine);
2026-01-11 01:36:32 +09:00
}
2026-01-12 01:54:35 +09:00
void GSClientStep(GSClient client) {
2026-01-20 14:34:13 +09:00
int tw, th;
int tw2, th2;
int sw, sh;
char buf[512];
char buf2[512];
GSVersion ver;
GSVector4 white = {1, 1, 1, 1};
GSVector4 half = {0, 0, 0, 0.5};
GSVector2 sq[4];
2026-01-12 05:33:04 +09:00
2026-01-12 01:54:35 +09:00
GSGLClear(client->gl);
GSGLCameraSetup(client->gl);
GSGLSetLight(client->gl);
2026-01-11 01:36:32 +09:00
2026-01-12 01:54:35 +09:00
if(GSGLShadowBeforeMapping(client->gl)) {
2026-01-11 23:10:13 +09:00
scene(client);
2026-01-12 01:54:35 +09:00
GSGLShadowAfterMapping(client->gl);
2026-01-11 18:27:41 +09:00
}
2026-01-11 20:26:15 +09:00
2026-01-20 14:07:56 +09:00
if(client->skybox_enabled){
if(client->skybox != NULL) GSSkyBoxDraw(client->skybox);
}
2026-01-11 23:10:13 +09:00
scene(client);
2026-01-12 01:54:35 +09:00
GSGLShadowEnd(client->gl);
2026-01-11 01:36:32 +09:00
2026-01-20 14:34:13 +09:00
GSVersionGet(&ver);
sprintf(buf, "GearSrc Engine %s", ver.string);
tw = GSGLTextWidth(client->gl, buf);
th = GSGLTextHeight(client->gl, buf);
sprintf(buf2, "%s", ver.copyright);
tw2 = GSGLTextWidth(client->gl, buf2);
th2 = GSGLTextHeight(client->gl, buf2);
sw = tw > tw2 ? tw : tw2;
sh = th + th2;
sq[0][0] = client->engine->width - sw, sq[0][1] = client->engine->height - sh;
sq[1][0] = client->engine->width - sw, sq[1][1] = client->engine->height;
sq[2][0] = client->engine->width, sq[2][1] = client->engine->height;
sq[3][0] = client->engine->width, sq[3][1] = client->engine->height - sh;
GSGLSetColor(client->gl, half);
GSGLBegin2D(client->gl);
GSGLPolygon2D(client->gl, 4, sq, NULL);
GSGLEnd2D(client->gl);
GSGLSetColor(client->gl, white);
GSGLText(client->gl, client->engine->width - tw, client->engine->height - th * 2, buf);
GSGLText(client->gl, client->engine->width - tw2, client->engine->height - th2, buf2);
2026-01-10 19:51:48 +09:00
client->engine->param->gl_swapbuffer();
2026-01-11 01:36:32 +09:00
2026-01-20 14:07:56 +09:00
if(client->engine->param->after_render != NULL) client->engine->param->after_render(client->engine);
}
2026-01-12 04:55:35 +09:00
2026-01-20 14:07:56 +09:00
GSGL GSClientGetGL(GSClient client){
return client->gl;
}
2026-01-11 01:36:32 +09:00
2026-01-20 14:07:56 +09:00
void GSClientToggleSkybox(GSClient client, GSBool toggle){
client->skybox_enabled = toggle;
2026-01-09 03:38:29 +09:00
}