math and things
This commit is contained in:
parent
247661fc13
commit
2fe23438b0
17 changed files with 243 additions and 35 deletions
|
|
@ -3,11 +3,18 @@
|
|||
#include <GearBox/Log.h>
|
||||
|
||||
GBClient GBClientCreate(GBEngine engine) {
|
||||
GBClient client = malloc(sizeof(*client));
|
||||
|
||||
memset(client, 0, sizeof(*client));
|
||||
|
||||
GBLog(GBLogInfo, "Creating client");
|
||||
|
||||
return NULL;
|
||||
return client;
|
||||
}
|
||||
|
||||
void GBClientDestroy(GBClient client) {
|
||||
free(client);
|
||||
}
|
||||
|
||||
void GBClientStep(GBClient client) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <GearBox/Client.h>
|
||||
#include <GearBox/Server.h>
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
void GBInit(void) {
|
||||
GBVersion version;
|
||||
|
||||
|
|
@ -18,6 +20,17 @@ GBEngine GBEngineCreate(GBEngineParam* param) {
|
|||
|
||||
memset(engine, 0, sizeof(*engine));
|
||||
|
||||
engine->param = malloc(sizeof(*engine->param));
|
||||
memcpy(engine->param, param, sizeof(*param));
|
||||
|
||||
if(param->ready != NULL) {
|
||||
param->ready(1024, 768);
|
||||
}
|
||||
|
||||
if(param->gl_getprocaddress != NULL) {
|
||||
gladLoadGLLoader(param->gl_getprocaddress);
|
||||
}
|
||||
|
||||
if(engine != NULL && param->client && (engine->client = GBClientCreate(engine)) == NULL) {
|
||||
GBLog(GBLogError, "Failed to create client");
|
||||
|
||||
|
|
@ -44,12 +57,63 @@ GBEngine GBEngineCreate(GBEngineParam* param) {
|
|||
void GBEngineDestroy(GBEngine engine) {
|
||||
if(engine->server != NULL) GBServerDestroy(engine->server);
|
||||
if(engine->client != NULL) GBClientDestroy(engine->client);
|
||||
if(engine->param != NULL) free(engine->param);
|
||||
|
||||
free(engine);
|
||||
}
|
||||
|
||||
void GBEngineStart(GBEngine engine) {
|
||||
void GBEngineParamInit(GBEngineParam* param) {
|
||||
memset(param, 0, sizeof(*param));
|
||||
|
||||
param->server = 0;
|
||||
param->client = 1;
|
||||
param->gl_getprocaddress = NULL;
|
||||
param->gl_swapbuffer = NULL;
|
||||
param->ready = NULL;
|
||||
param->sleep = NULL;
|
||||
param->get_tick = NULL;
|
||||
}
|
||||
|
||||
void GBEngineLoop(GBEngine engine) {
|
||||
long t = 0;
|
||||
int wait_actually = 0;
|
||||
int more = 0;
|
||||
long wait = 1000 / 50.0;
|
||||
|
||||
if(engine->param->sleep == NULL || engine->param->get_tick == NULL) {
|
||||
GBLog(GBLogWarn, "sleep and/or get_tick parameter are missing!");
|
||||
GBLog(GBLogWarn, "This will result game to be crazy fast!!!");
|
||||
} else {
|
||||
t = engine->param->get_tick();
|
||||
|
||||
wait_actually = 1;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
GBClientStep(engine->client);
|
||||
GBServerStep(engine->server);
|
||||
|
||||
if(engine->param->tick != NULL) engine->param->tick();
|
||||
|
||||
if(wait_actually) {
|
||||
int diff = (wait - more) - (engine->param->get_tick() - t);
|
||||
|
||||
if(diff > 0) {
|
||||
engine->param->sleep(diff);
|
||||
}
|
||||
|
||||
more -= diff;
|
||||
if(more < 0) more = 0;
|
||||
|
||||
t = engine->param->get_tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GBClient GBEngineGetClient(GBEngine engine) {
|
||||
return engine->client;
|
||||
}
|
||||
|
||||
GBServer GBEngineGetServer(GBEngine engine) {
|
||||
return engine->server;
|
||||
}
|
||||
|
|
|
|||
54
engine/src/math.c
Normal file
54
engine/src/math.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include <GearBox/Math.h>
|
||||
|
||||
void GBMathCross(double* out, double v00, double v01, double v02, double v10, double v11, double v12) {
|
||||
out[0] = v01 * v12 - v02 * v11;
|
||||
out[1] = v02 * v10 - v00 * v12;
|
||||
out[2] = v00 * v11 - v01 * v10;
|
||||
}
|
||||
|
||||
/*
|
||||
* v0-v2
|
||||
* | /
|
||||
* v1/
|
||||
*/
|
||||
void GBMathNormal3(double* out, double v00, double v01, double v02, double v10, double v11, double v12, double v20, double v21, double v22) {
|
||||
double v[3];
|
||||
double l = 0;
|
||||
int i;
|
||||
|
||||
GBMathCross(&v[0], /**/
|
||||
v10 - v00, v11 - v01, v12 - v02, /**/
|
||||
v20 - v00, v21 - v01, v22 - v02 /**/
|
||||
);
|
||||
|
||||
l = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
out[i] = v[i] / l;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* v0-v3
|
||||
* | |
|
||||
* v1-v2
|
||||
*/
|
||||
void GBMathNormal4(double* out, double v00, double v01, double v02, double v10, double v11, double v12, double v20, double v21, double v22, double v30, double v31, double v32) {
|
||||
double v0[3];
|
||||
double v1[3];
|
||||
int i;
|
||||
double l = 0;
|
||||
|
||||
GBMathNormal3(&v0[0], v00, v01, v02, v10, v11, v12, v30, v31, v32);
|
||||
GBMathNormal3(&v1[0], v10, v11, v12, v20, v21, v22, v30, v31, v32);
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
out[i] = v0[i] + v1[i];
|
||||
}
|
||||
|
||||
l = sqrt(out[0] * out[0] + out[1] * out[1] + out[2] * out[2]);
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
out[i] = out[i] / l;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,12 +3,18 @@
|
|||
#include <GearBox/Log.h>
|
||||
|
||||
GBServer GBServerCreate(GBEngine engine) {
|
||||
GBServer server = malloc(sizeof(*server));
|
||||
|
||||
memset(server, 0, sizeof(*server));
|
||||
|
||||
GBLog(GBLogInfo, "Creating server");
|
||||
|
||||
return NULL;
|
||||
return server;
|
||||
}
|
||||
|
||||
void GBServerDestroy(GBServer server) {
|
||||
|
||||
free(server);
|
||||
}
|
||||
|
||||
void GBServerStep(GBServer server) {
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue