logging
This commit is contained in:
parent
a489f54814
commit
fb9f9d30ed
4 changed files with 124 additions and 34 deletions
|
|
@ -58,6 +58,7 @@ typedef struct _GSModel* GSModel;
|
|||
typedef struct _GSModelFace GSModelFace;
|
||||
typedef struct _GSModelMaterial GSModelMaterial;
|
||||
typedef struct _GSModelUseMaterial GSModelUseMaterial;
|
||||
typedef struct _GSEngineLog GSEngineLog;
|
||||
#else
|
||||
typedef void* GSClient;
|
||||
typedef void* GSServer;
|
||||
|
|
@ -183,6 +184,12 @@ struct _GSServer {
|
|||
GSEngine engine;
|
||||
};
|
||||
|
||||
struct _GSEngineLog {
|
||||
char log[1024];
|
||||
int level;
|
||||
long tick;
|
||||
};
|
||||
|
||||
struct _GSEngine {
|
||||
GSEngineParam* param;
|
||||
GSClient client;
|
||||
|
|
@ -192,6 +199,8 @@ struct _GSEngine {
|
|||
int height;
|
||||
GSNumber tps;
|
||||
GSNumber tps_sampled;
|
||||
|
||||
GSEngineLog* log;
|
||||
};
|
||||
|
||||
struct _GSFile {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include <GearSrc/Model.h>
|
||||
#include <GearSrc/Version.h>
|
||||
|
||||
#include <stb_ds.h>
|
||||
|
||||
GSClient GSClientCreate(GSEngine engine) {
|
||||
GSClient client = malloc(sizeof(*client));
|
||||
void* ptr[] = {
|
||||
|
|
@ -99,10 +101,12 @@ 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;
|
||||
|
||||
GSGLClear(client->gl);
|
||||
GSGLCameraSetup(client->gl);
|
||||
GSGLSetLight(client->gl);
|
||||
GSGLSetColor(client->gl, white);
|
||||
|
||||
GSGLTextBold(client->gl, 0);
|
||||
|
||||
|
|
@ -117,27 +121,6 @@ void GSClientStep(GSClient client) {
|
|||
scene(client);
|
||||
GSGLShadowEnd(client->gl);
|
||||
|
||||
sprintf(buf, "%.1f FPS", client->engine->tps_sampled);
|
||||
sprintf(buf2, "%s%s", client->engine->tps_sampled < 10 ? " " : "", buf);
|
||||
|
||||
tw = GSGLTextWidth(client->gl, buf2);
|
||||
th = GSGLTextHeight(client->gl, buf2);
|
||||
|
||||
sq[0][0] = client->engine->width - tw, sq[0][1] = 0;
|
||||
sq[1][0] = client->engine->width - tw, sq[1][1] = th;
|
||||
sq[2][0] = client->engine->width, sq[2][1] = th;
|
||||
sq[3][0] = client->engine->width, sq[3][1] = 0;
|
||||
|
||||
GSGLSetColor(client->gl, half);
|
||||
GSGLBegin2D(client->gl);
|
||||
GSGLPolygon2D(client->gl, 4, sq, NULL);
|
||||
GSGLEnd2D(client->gl);
|
||||
|
||||
GSGLSetColor(client->gl, yellow);
|
||||
GSGLTextBold(client->gl, 1);
|
||||
GSGLText(client->gl, client->engine->width - tw, 0, buf2);
|
||||
GSGLTextBold(client->gl, 0);
|
||||
|
||||
GSVersionGet(&ver);
|
||||
|
||||
sprintf(buf, "Engine version %s", ver.string);
|
||||
|
|
@ -154,9 +137,9 @@ void GSClientStep(GSClient client) {
|
|||
sh = th + th2;
|
||||
|
||||
sq[0][0] = client->engine->width - sw, sq[0][1] = client->engine->height - sh;
|
||||
sq[1][0] = client->engine->width - sw, sq[1][1] = client->engine->height;
|
||||
sq[2][0] = client->engine->width, sq[2][1] = client->engine->height;
|
||||
sq[3][0] = client->engine->width, sq[3][1] = client->engine->height - sh;
|
||||
sq[1][0] = sq[0][0], sq[1][1] = client->engine->height;
|
||||
sq[2][0] = client->engine->width, sq[2][1] = sq[1][1];
|
||||
sq[3][0] = sq[2][0], sq[3][1] = sq[0][1];
|
||||
|
||||
GSGLSetColor(client->gl, half);
|
||||
GSGLBegin2D(client->gl);
|
||||
|
|
@ -167,13 +150,90 @@ void GSClientStep(GSClient client) {
|
|||
GSGLText(client->gl, client->engine->width - tw, client->engine->height - th * 2, buf);
|
||||
GSGLText(client->gl, client->engine->width - tw2, client->engine->height - th2, buf2);
|
||||
|
||||
for(k = 0; k < 2; k++) {
|
||||
c = 0;
|
||||
for(i = arrlen(client->engine->log) - 1, j = 0; i >= 0 && j < 10; 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 w = 0;
|
||||
char str[6];
|
||||
int level = client->engine->log[i].level;
|
||||
GSVector4 col = {0, 0, 0, 1};
|
||||
|
||||
str[0] = 0;
|
||||
|
||||
if(level == GSLogInfo) {
|
||||
strcpy(str, "INFO");
|
||||
|
||||
col[0] = col[1] = col[2] = 1;
|
||||
} else if(level == GSLogWarn) {
|
||||
strcpy(str, "WARN");
|
||||
|
||||
col[0] = col[2] = 1;
|
||||
} else if(level == GSLogError) {
|
||||
strcpy(str, "ERROR");
|
||||
|
||||
col[0] = 1;
|
||||
} else if(level == GSLogDebug) {
|
||||
strcpy(str, "DEBUG");
|
||||
|
||||
col[2] = 1;
|
||||
}
|
||||
GSGLSetColor(client->gl, col);
|
||||
|
||||
GSGLTextBold(client->gl, 1);
|
||||
GSGLText(client->gl, (5 - strlen(str)) * GSGLTextWidth(client->gl, "M") / 2, y, str);
|
||||
GSGLTextBold(client->gl, 0);
|
||||
|
||||
GSGLSetColor(client->gl, white);
|
||||
GSGLText(client->gl, 0, y, " |");
|
||||
GSGLText(client->gl, GSGLTextWidth(client->gl, "M") * 6, y, client->engine->log[i].log);
|
||||
}
|
||||
|
||||
c++;
|
||||
}
|
||||
|
||||
if(k == 0) {
|
||||
sq[0][0] = 0, sq[0][1] = 0;
|
||||
sq[1][0] = 0, sq[1][1] = c * GSGLTextHeight(client->gl, "M");
|
||||
sq[2][0] = client->engine->width, sq[2][1] = sq[1][1];
|
||||
sq[3][0] = sq[2][0], sq[3][1] = 0;
|
||||
|
||||
GSGLSetColor(client->gl, half);
|
||||
GSGLBegin2D(client->gl);
|
||||
GSGLPolygon2D(client->gl, 4, sq, NULL);
|
||||
GSGLEnd2D(client->gl);
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(buf, "%.1f FPS", client->engine->tps_sampled);
|
||||
sprintf(buf2, "%s%s", client->engine->tps_sampled < 10 ? " " : "", buf);
|
||||
|
||||
tw = GSGLTextWidth(client->gl, buf2);
|
||||
th = GSGLTextHeight(client->gl, buf2);
|
||||
|
||||
sq[0][0] = client->engine->width - tw, sq[0][1] = 0;
|
||||
sq[1][0] = sq[0][0], sq[1][1] = th;
|
||||
sq[2][0] = client->engine->width, sq[2][1] = sq[1][1];
|
||||
sq[3][0] = sq[2][0], sq[3][1] = 0;
|
||||
|
||||
GSGLSetColor(client->gl, half);
|
||||
GSGLBegin2D(client->gl);
|
||||
GSGLPolygon2D(client->gl, 4, sq, NULL);
|
||||
GSGLEnd2D(client->gl);
|
||||
|
||||
GSGLSetColor(client->gl, yellow);
|
||||
GSGLTextBold(client->gl, 1);
|
||||
GSGLText(client->gl, client->engine->width - tw, 0, buf2);
|
||||
GSGLTextBold(client->gl, 0);
|
||||
|
||||
client->engine->param->gl_swapbuffer();
|
||||
|
||||
if(client->engine->param->after_render != NULL) client->engine->param->after_render(client->engine);
|
||||
|
||||
static double r = 0;
|
||||
|
||||
r += 0.1;
|
||||
}
|
||||
|
||||
GSGL GSClientGetGL(GSClient client) {
|
||||
|
|
|
|||
|
|
@ -97,14 +97,14 @@ void GSGLTextEx(GSGL gl, GSNumber x, GSNumber y, const char* text, GSNumber sx,
|
|||
gy = gy * sh;
|
||||
|
||||
v[0][0] = px, v[0][1] = py;
|
||||
v[1][0] = px, v[1][1] = py + gh;
|
||||
v[2][0] = px + gw, v[2][1] = py + gh;
|
||||
v[3][0] = px + gw, v[3][1] = py;
|
||||
v[1][0] = v[0][0], v[1][1] = py + gh;
|
||||
v[2][0] = px + gw, v[2][1] = v[1][1];
|
||||
v[3][0] = v[2][0], v[3][1] = v[0][1];
|
||||
|
||||
t[0][0] = gx, t[0][1] = gy;
|
||||
t[1][0] = gx, t[1][1] = gy + sh;
|
||||
t[2][0] = gx + sw, t[2][1] = gy + sh;
|
||||
t[3][0] = gx + sw, t[3][1] = gy;
|
||||
t[1][0] = t[0][0], t[1][1] = gy + sh;
|
||||
t[2][0] = gx + sw, t[2][1] = t[1][1];
|
||||
t[3][0] = t[2][0], t[3][1] = t[0][1];
|
||||
|
||||
GSGLPolygon2D(gl, 4, v, t);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include <GearSrc/Log.h>
|
||||
|
||||
#include <stb_ds.h>
|
||||
|
||||
void GSLog(GSEngine engine, int level, const char* fmt, ...) {
|
||||
va_list va;
|
||||
FILE* out = stdout;
|
||||
|
|
@ -40,5 +42,24 @@ void GSLog(GSEngine engine, int level, const char* fmt, ...) {
|
|||
vfprintf(out, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
if(engine != NULL) {
|
||||
GSEngineLog log;
|
||||
char str[6];
|
||||
|
||||
log.level = level;
|
||||
|
||||
va_start(va, fmt);
|
||||
vsprintf(log.log, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
if(engine->param->get_tick == NULL) {
|
||||
log.tick = 0;
|
||||
} else {
|
||||
log.tick = engine->param->get_tick();
|
||||
}
|
||||
|
||||
arrput(engine->log, log);
|
||||
}
|
||||
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue