This commit is contained in:
Nishi 2026-01-27 12:10:08 +09:00
commit c7678eaeab
Signed by: nishi
GPG key ID: 27EF69B208EB9343
9 changed files with 149 additions and 36 deletions

0
engine/src/audio.c Normal file
View file

View file

@ -6,6 +6,7 @@
#include <GearSrc/Math.h>
#include <GearSrc/Model.h>
#include <GearSrc/Version.h>
#include <GearSrc/Sound.h>
#include <stb_ds.h>
@ -49,6 +50,13 @@ GSClient GSClientCreate(GSEngine engine) {
client->skybox_enabled = GSFalse;
if((client->sound = GSSoundOpen(client)) == NULL) {
GSClientDestroy(client);
GSLog(engine, GSLogError, "Failed to create client");
return NULL;
}
client->gl = GSGLCreate(client);
client->skybox = GSSkyBoxTry(client, "default");
@ -81,6 +89,8 @@ void GSClientDestroy(GSClient client) {
GSGLDestroy(client->gl);
if(client->sound != NULL) GSSoundClose(client->sound);
GSLog(client->engine, GSLogInfo, "Destroyed client");
free(client);
@ -101,7 +111,7 @@ void GSClientStep(GSClient client) {
GSVector4 yellow = {1, 1, 0, 1};
GSVector4 half = {0, 0, 0, 0.5};
GSVector2 sq[4];
int i, j, k, c;
int i, j, k, c, t;
GSGLClear(client->gl);
GSGLCameraSetup(client->gl);
@ -152,13 +162,13 @@ void GSClientStep(GSClient client) {
for(k = 0; k < 2; k++) {
c = 0;
for(i = arrlen(client->engine->log) - 1, j = 0; i >= 0 && j < 10; i--, j++) {
for(i = arrlen(client->engine->log) - 1, j = 0; i >= 0 && j < 5; i--, j++) {
if(client->engine->param->get_tick != NULL) {
if((client->engine->param->get_tick() - client->engine->log[i].tick) > 3000) continue;
}
if(k == 1) {
GSNumber y = c * GSGLTextHeight(client->gl, "M");
GSNumber y = (t - c - 1) * GSGLTextHeight(client->gl, "M");
GSNumber w = 0;
char str[6];
int level = client->engine->log[i].level;
@ -197,6 +207,8 @@ void GSClientStep(GSClient client) {
c++;
}
t = c;
if(k == 0) {
sq[0][0] = 0, sq[0][1] = 0;
sq[1][0] = 0, sq[1][1] = c * GSGLTextHeight(client->gl, "M");

View file

@ -50,8 +50,9 @@ GSEngine GSEngineCreate(GSEngineParam* param) {
engine->param = malloc(sizeof(*engine->param));
memcpy(engine->param, param, sizeof(*param));
engine->width = 800;
engine->height = 600;
engine->width = 800;
engine->height = 600;
engine->shutdown = 0;
if(param->ready != NULL && param->client) {
param->ready(engine->width, engine->height);
@ -80,6 +81,9 @@ GSEngine GSEngineCreate(GSEngineParam* param) {
engine = NULL;
}
if(param->client) engine->shutdown++;
if(param->server) engine->shutdown++;
if(engine == NULL) {
GSLog(engine, GSLogError, "Failed to create engine");
}
@ -132,7 +136,7 @@ void GSEngineLoop(GSEngine engine) {
engine->tps = tps;
engine->tps_sampled = tps;
while(1) {
while(engine->shutdown > 0) {
if(engine->client != NULL) GSClientStep(engine->client);
if(engine->server != NULL) GSServerStep(engine->server);
@ -178,3 +182,10 @@ GSServer GSEngineGetServer(GSEngine engine) {
GSNumber GSEngineGetTPS(GSEngine engine) {
return engine->tps;
}
void GSEngineShutdown(GSEngine engine) {
GSLog(engine, GSLogInfo, "Engine shutdown started");
/* TODO: proper shutdown */
engine->shutdown -= 2;
}

48
engine/src/sound.c Normal file
View file

@ -0,0 +1,48 @@
#include <GearSrc/Sound.h>
#include <GearSrc/Log.h>
#include <miniaudio.h>
static void data_callback(ma_device* device, void* output, const void* input, ma_uint32 frame) {
}
GSSound GSSoundOpen(GSClient client) {
GSSound sound = malloc(sizeof(*sound));
memset(sound, 0, sizeof(*sound));
sound->engine = client->engine;
sound->config = ma_device_config_init(ma_device_type_playback);
sound->config.playback.format = ma_format_s16;
sound->config.playback.channels = 2;
sound->config.sampleRate = GSSoundRate;
sound->config.dataCallback = data_callback;
sound->config.pUserData = sound;
if(ma_device_init(NULL, &sound->config, &sound->device) != MA_SUCCESS) {
free(sound);
GSLog(client->engine, GSLogInfo, "Failed to open sound");
return NULL;
}
if(ma_device_start(&sound->device) != MA_SUCCESS) {
ma_device_uninit(&sound->device);
free(sound);
GSLog(client->engine, GSLogInfo, "Failed to open sound");
return NULL;
}
GSLog(client->engine, GSLogInfo, "Opened sound");
return sound;
}
void GSSoundClose(GSSound sound) {
ma_device_uninit(&sound->device);
GSLog(sound->engine, GSLogInfo, "Closed sound");
free(sound);
}