assaultfish/client/main.c

121 lines
2.5 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-02-01 08:09:18 +09:00
GSPhysicsObject obj[128];
2026-01-20 14:07:56 +09:00
2026-01-27 12:10:08 +09:00
static void render(GSEngine self){
GSGL gl = GSClientGetGL(GSEngineGetClient(self));
2026-02-01 08:09:18 +09:00
int i;
GSVector4 col1 = {1, 0, 0, 1};
GSVector4 col2 = {1, 1, 1, 1};
2026-01-28 13:25:31 +09:00
GSVector3 v[] = {
2026-02-01 22:52:50 +09:00
{-20, 0, 20},
{-20, 0, -20},
{20, 0, -20},
{20, 0, 20}
2026-01-28 13:25:31 +09:00
};
GSVector3 n = {0, 1, 0};
2026-01-20 14:07:56 +09:00
2026-02-01 08:09:18 +09:00
for(i = 0; i < sizeof(obj) / sizeof(obj[0]); i++){
GSVector3 rv;
GSMatrix3x3 rm;
2026-01-27 22:27:20 +09:00
2026-02-01 08:09:18 +09:00
GSPhysicsGetPosition(obj[i], rv);
GSPhysicsGetRotation(obj[i], rm);
2026-01-27 22:27:20 +09:00
2026-02-01 08:09:18 +09:00
GSGLPushMatrix(gl);
GSGLSetPosition(gl, rv);
GSGLSetRotation3x3(gl, rm);
2026-02-01 22:34:10 +09:00
GSGLTetrakis(gl, 0.5, col1, col2);
2026-02-01 08:09:18 +09:00
GSGLPopMatrix(gl);
}
2026-01-27 22:27:20 +09:00
2026-02-01 08:09:18 +09:00
GSGLSetColor(gl, col2);
2026-01-28 13:25:31 +09:00
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){
}
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 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-02-01 08:09:18 +09:00
int i;
GSVector3 pos = {0, 1, 0};
GSVector3 sz = {1, 1, 1};
for(i = 0; i < sizeof(obj) / sizeof(obj[0]); i++){
obj[i] = GSPhysicsCreateSphere(GSServerGetPhysics(GSEngineGetServer(engine)), 1, 0.5);
2026-01-20 14:07:56 +09:00
2026-02-01 08:09:18 +09:00
pos[0] = ((GSNumber)rand() / RAND_MAX - 0.5) * 20;
pos[1] = 10;
pos[2] = ((GSNumber)rand() / RAND_MAX - 0.5) * 20;
GSPhysicsSetPosition(obj[i], pos);
2026-01-27 14:36:27 +09:00
}
2026-01-20 14:07:56 +09:00
2026-02-01 08:09:18 +09:00
GSClientSetSkybox(GSEngineGetClient(engine), GSTrue);
2026-01-12 01:54:35 +09:00
GSEngineLoop(engine);
GSEngineDestroy(engine);
2026-01-09 03:38:29 +09:00
}
2026-01-09 00:40:51 +09:00
}