Remove some verbose logs

This commit is contained in:
Edgaru089 2024-03-05 11:55:26 +08:00
parent ae28f1c770
commit a802522eda
3 changed files with 19 additions and 28 deletions

26
app.c
View File

@ -9,17 +9,6 @@
#include <stdio.h>
static void _app_onHitBy(Entity *me, Entity *other, Vec2 triedDelta, void *data) {
fprintf(
stderr,
"[_app_onHit] Entity \"%s\" hit by \"%s\", delta: [%.2lf, %.2lf]\n",
me->name,
other->name,
triedDelta.x,
triedDelta.y);
}
App *app_NewApp() {
App *app = malloc(sizeof(App));
@ -32,37 +21,34 @@ App *app_NewApp() {
Entity *player = entity_Create(app->entity, "player");
ADD_COMPONENT(player, player, zero_malloc(sizeof(Component_Player)));
ADD_COMPONENT(player, position, zero_malloc(sizeof(Component_Position)));
ADD_COMPONENT(player, player);
ADD_COMPONENT(player, position);
player->position->position = vec2(500, 500);
player->position->velocity = vec2(0, 0);
ADD_COMPONENT(player, hitbox, zero_malloc(sizeof(Component_Hitbox)));
ADD_COMPONENT(player, hitbox);
player->hitbox->box.lefttop = vec2(-20, -80);
player->hitbox->box.size = vec2(40, 80);
entity_Commit(app->entity, player);
Entity *hit1 = entity_Create(app->entity, "hit1");
ADD_COMPONENT(hit1, hitbox, zero_malloc(sizeof(Component_Hitbox)));
ADD_COMPONENT(hit1, hitbox);
hit1->hitbox->box.lefttop = vec2(200, 200);
hit1->hitbox->box.size = vec2(100, 400);
hit1->hitbox->fixed = true;
hit1->hitbox->onHitBy = &_app_onHitBy;
entity_Commit(app->entity, hit1);
Entity *hit2 = entity_Create(app->entity, "hit2");
ADD_COMPONENT(hit2, hitbox, zero_malloc(sizeof(Component_Hitbox)));
ADD_COMPONENT(hit2, hitbox);
hit2->hitbox->box.lefttop = vec2(700, 200);
hit2->hitbox->box.size = vec2(100, 400);
hit2->hitbox->fixed = true;
hit2->hitbox->onHitBy = &_app_onHitBy;
entity_Commit(app->entity, hit2);
Entity *hit3 = entity_Create(app->entity, "hit3");
ADD_COMPONENT(hit3, hitbox, zero_malloc(sizeof(Component_Hitbox)));
ADD_COMPONENT(hit3, hitbox);
hit3->hitbox->box.lefttop = vec2(100, 550);
hit3->hitbox->box.size = vec2(800, 30);
hit3->hitbox->fixed = true;
hit3->hitbox->onHitBy = &_app_onHitBy;
entity_Commit(app->entity, hit3);
return app;

View File

@ -30,10 +30,12 @@ typedef struct _Entity {
void *thinkerData; // Data managed by the Thinker, if exists.
} Entity;
#define ADD_COMPONENT(entity, component, value) \
do { \
entity->component = value; \
entity->component->super = entity; \
// https://en.cppreference.com/w/c/language/sizeof
// The expression in sizeof is not evaluated
#define ADD_COMPONENT(entity, component) \
do { \
entity->component = zero_malloc(sizeof(*entity->component)); \
entity->component->super = entity; \
} while (false)

View File

@ -12,13 +12,16 @@ int main() {
lastFrame = lastUpdate = frameCounter = time_Now();
int frameCount = 0;
initgraph(1280, 720);
HWND win = initgraph(1280, 720);
SetWindowTextA(win, "JacksEscape");
App *app = app_NewApp();
while (!app->wantQuit) {
if (time_Since(frameCounter).microseconds >= 1000000) { // 1 sec
Duration d = time_Reset(&frameCounter);
fprintf(stderr, "[Main] %d frames in the last %.4lf seconds\n", frameCount, duration_Seconds(d));
/* Duration d = */ time_Reset(&frameCounter);
char buf[128];
snprintf(buf, sizeof(buf) - 1, "JacksEscape (%d FPS)", frameCount);
SetWindowTextA(win, buf);
frameCount = 0;
}
frameCount++;
@ -30,7 +33,7 @@ int main() {
app_Render(app);
EndBatchDraw();
Duration toSleep = {.microseconds = 1000000 / 30 - time_Reset(&lastFrame).microseconds};
Duration toSleep = {.microseconds = 1000000 / 60 - time_Reset(&lastFrame).microseconds};
duration_Sleep(toSleep);
}