assaultfish/client/main.c

149 lines
3 KiB
C
Raw Normal View History

2026-01-09 03:38:29 +09:00
#define MW_OPENGL_NO_INCLUDE
#define _MILSKO
2026-01-12 01:54:35 +09:00
#include <GearSrc/Foundation.h>
2026-01-09 00:40:51 +09:00
2026-01-09 03:38:29 +09:00
#include <Mw/Milsko.h>
#include <Mw/Widget/OpenGL.h>
2026-01-27 16:34:14 +09:00
#ifndef _WIN32
#include <signal.h>
#endif
2026-01-27 12:10:08 +09:00
static MwWidget window, opengl;
static GSEngine engine;
2026-01-09 03:38:29 +09:00
static void gl_swapbuffer(void){
MwOpenGLSwapBuffer(opengl);
}
static void ready(int width, int height){
MwSizeHints sh;
sh.min_width = sh.max_width = width;
sh.min_height = sh.max_height = height;
MwLibraryInit();
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, width, height,
MwNtitle, "AssaultFish",
MwNsizeHints, &sh,
NULL);
opengl = MwCreateWidget(MwOpenGLClass, "opengl", window, 0, 0, width, height);
MwOpenGLMakeCurrent(opengl);
}
static void tick(void){
while(!window->close && MwPending(window)) MwStep(window);
}
2026-01-20 14:07:56 +09:00
static GSVector3 rot = {0, 0, 0};
2026-01-27 22:27:20 +09:00
static GSVector3 pos = {0, 0, 0};
2026-01-20 14:07:56 +09:00
static GSModel model = NULL;
2026-01-27 12:10:08 +09:00
static void render(GSEngine self){
GSGL gl = GSClientGetGL(GSEngineGetClient(self));
2026-01-28 13:25:31 +09:00
GSVector3 v[] = {
{-5, -2, 5},
{-5, -2, -5},
{5, -2, -5},
{5, -2, 5}
};
GSVector3 n = {0, 1, 0};
GSVector4 col = {1, 1, 1, 1};
GSVector4 col2 = {1, 0, 0, 1};
int i, j;
2026-01-20 14:07:56 +09:00
2026-01-27 22:27:20 +09:00
pos[1] = 0;
GSGLPushMatrix(gl);
GSGLSetPosition(gl, pos);
GSGLSetRotation(gl, rot);
if(model != NULL) GSModelDraw(model);
GSGLPopMatrix(gl);
pos[1] = 1;
2026-01-20 14:07:56 +09:00
GSGLPushMatrix(gl);
2026-01-27 22:27:20 +09:00
GSGLSetPosition(gl, pos);
2026-01-20 14:07:56 +09:00
GSGLSetRotation(gl, rot);
if(model != NULL) GSModelDraw(model);
GSGLPopMatrix(gl);
2026-01-28 13:25:31 +09:00
for(i = -1; i <= 1; i++){
for(j = -1; j <= 1; j++){
GSVector3 pos2;
2026-01-28 13:28:47 +09:00
double s = fabs(sin(rot[0] / 180 * GSMathPi));
2026-01-29 15:29:20 +09:00
int n = (i + 1) * 3 + (j + 1);
2026-01-28 13:25:31 +09:00
2026-01-28 13:28:47 +09:00
pos2[0] = i * s * 2;
2026-01-28 13:25:31 +09:00
pos2[1] = 0;
2026-01-28 13:28:47 +09:00
pos2[2] = j * s * 2;
2026-01-28 13:25:31 +09:00
2026-01-29 15:29:20 +09:00
col2[2] = n & 1;
col2[1] = (n & 2) ? 1 : 0;
col2[0] = (n & 4) ? 1 : 0;
2026-01-28 13:25:31 +09:00
GSGLPushMatrix(gl);
GSGLSetPosition(gl, pos2);
GSGLSetRotation(gl, rot);
2026-01-28 13:28:47 +09:00
GSGLTetrakis(gl, s, col, col2);
2026-01-28 13:25:31 +09:00
GSGLPopMatrix(gl);
}
}
GSGLSetColor(gl, col);
GSGLPolygon(gl, 4, v, NULL, n);
2026-01-20 14:07:56 +09:00
}
2026-01-27 12:10:08 +09:00
static void after_render(GSEngine self){
rot[0] = rot[1] = rot[2] += (1.0 / GSEngineGetTPS(self)) * 90;
2026-01-27 22:27:20 +09:00
pos[0] = cos(rot[0] / 180 * GSMathPi);
pos[2] = sin(rot[0] / 180 * GSMathPi);
2026-01-27 12:10:08 +09:00
}
2026-01-27 16:34:14 +09:00
#ifndef _WIN32
2026-01-27 12:10:08 +09:00
static void shutdown_engine(int sig){
GSEngineShutdown(engine);
2026-01-20 14:07:56 +09:00
}
2026-01-27 16:34:14 +09:00
#endif
2026-01-20 14:07:56 +09:00
2026-01-09 00:40:51 +09:00
int main(int argc, char** argv){
2026-01-12 01:54:35 +09:00
GSEngineParam param;
2026-01-09 00:40:51 +09:00
2026-01-12 01:54:35 +09:00
GSEngineParamInit(&param);
2026-01-09 03:38:29 +09:00
param.ready = ready;
param.tick = tick;
param.get_tick = MwTimeGetTick;
param.sleep = MwTimeSleep;
param.gl_swapbuffer = gl_swapbuffer;
2026-01-20 14:07:56 +09:00
param.render = render;
param.after_render = after_render;
2026-01-29 09:26:52 +09:00
param.server = 1;
2026-01-09 00:40:51 +09:00
2026-01-12 01:54:35 +09:00
GSInit();
2026-01-09 00:40:51 +09:00
2026-01-12 01:54:35 +09:00
if((engine = GSEngineCreate(&param)) != NULL){
2026-01-27 14:36:27 +09:00
GSSound sound;
2026-01-27 16:34:14 +09:00
#ifndef _WIN32
2026-01-27 12:10:08 +09:00
signal(SIGINT, shutdown_engine);
signal(SIGTERM, shutdown_engine);
2026-01-27 16:34:14 +09:00
#endif
2026-01-27 12:10:08 +09:00
2026-01-25 07:06:03 +09:00
model = GSModelOpen(engine, "game:/mdl/fish.gsm");
2026-01-20 14:07:56 +09:00
2026-01-27 18:07:48 +09:00
GSClientSetSkybox(GSEngineGetClient(engine), GSTrue);
2026-01-27 14:36:27 +09:00
2026-01-29 09:26:52 +09:00
if((sound = GSSoundOpen(GSClientGetSoundEngine(GSEngineGetClient(engine)), "game:/desert2.mod")) != NULL){
2026-01-27 18:07:48 +09:00
GSSoundSetLoop(sound, 1);
2026-01-27 14:36:27 +09:00
GSSoundStart(sound);
}
2026-01-20 14:07:56 +09:00
2026-01-12 01:54:35 +09:00
GSEngineLoop(engine);
2026-01-27 14:36:27 +09:00
2026-01-12 01:54:35 +09:00
GSEngineDestroy(engine);
2026-01-09 03:38:29 +09:00
}
2026-01-09 00:40:51 +09:00
}