This commit is contained in:
Nishi 2026-02-01 00:22:34 +09:00
commit 51d273b8fb
Signed by: nishi
GPG key ID: 27EF69B208EB9343
4 changed files with 52 additions and 2 deletions

View file

@ -8,7 +8,10 @@
extern "C" {
#endif
GSDECL void GSPhysicsInit(void);
GSDECL void GSPhysicsInit(void);
GSDECL GSPhysics GSPhysicsCreate(GSServer server);
GSDECL void GSPhysicsDestroy(GSPhysics physics);
GSDECL void GSPhysicsStep(GSPhysics physics);
#ifdef __cplusplus
}

View file

@ -66,6 +66,7 @@ typedef struct _GSSound* GSSound;
typedef struct _GSNetClient* GSNetClient;
typedef struct _GSNetServer* GSNetServer;
typedef struct _GSNetSocket* GSNetSocket;
typedef struct _GSPhysics* GSPhysics;
typedef struct _GSModelFace GSModelFace;
typedef struct _GSModelMaterial GSModelMaterial;
@ -86,6 +87,7 @@ typedef void* GSSound;
typedef void* GSNetClient;
typedef void* GSNetServer;
typedef void* GSNetSocket;
typedef void* GSPhysics;
#endif
typedef float GSNumber;
typedef GSNumber GSVector2[2];
@ -311,6 +313,13 @@ struct _GSNetSocket {
GSBool client;
};
struct _GSPhysics {
GSEngine engine;
dWorldID world;
dSpaceID space;
};
struct _GSClient {
GSEngine engine;
@ -343,6 +352,8 @@ struct _GSServer {
GSEngine engine;
GSNetServer net;
GSPhysics physics;
};
struct _GSEngineLog {

View file

@ -4,6 +4,33 @@
#include <ode/ode.h>
void GSPhysicsInit(void){
void GSPhysicsInit(void) {
dInitODE2(0);
}
GSPhysics GSPhysicsCreate(GSServer server) {
GSPhysics physics = malloc(sizeof(*physics));
memset(physics, 0, sizeof(*physics));
physics->engine = server->engine;
physics->world = dWorldCreate();
physics->space = dSimpleSpaceCreate(0);
GSLog(server->engine, GSLogInfo, "Created physics engine");
return physics;
}
void GSPhysicsDestroy(GSPhysics physics) {
dSpaceDestroy(physics->space);
dWorldDestroy(physics->world);
GSLog(physics->engine, GSLogInfo, "Destroyed physics engine");
free(physics);
}
void GSPhysicsStep(GSPhysics physics) {
}

View file

@ -2,6 +2,7 @@
#include <GearSrc/Log.h>
#include <GearSrc/Net.h>
#include <GearSrc/Physics.h>
GSServer GSServerCreate(GSEngine engine) {
GSServer server = malloc(sizeof(*server));
@ -17,6 +18,13 @@ GSServer GSServerCreate(GSEngine engine) {
return NULL;
}
if((server->physics = GSPhysicsCreate(server)) == NULL) {
GSLog(engine, GSLogError, "Failed to create physics engine");
GSServerDestroy(server);
return NULL;
}
GSLog(engine, GSLogInfo, "Created server");
return server;
@ -24,6 +32,7 @@ GSServer GSServerCreate(GSEngine engine) {
void GSServerDestroy(GSServer server) {
if(server->net != NULL) GSNetServerClose(server->net);
if(server->physics != NULL) GSPhysicsDestroy(server->physics);
GSLog(server->engine, GSLogInfo, "Destroyed server");