diff options
Diffstat (limited to 'app.c')
| -rw-r--r-- | app.c | 132 |
1 files changed, 132 insertions, 0 deletions
@@ -0,0 +1,132 @@ +#include "app.h" +#include "physics.h" +#include "res.h" +#include "ent.h" +#include "game.h" +#include "env.h" +#include "cam.h" +#include "editor.h" + +#define RAYGUI_IMPLEMENTATION +#include "raygui.h" + +App app = {0}; +u64 dude_id = ENTITY_INVALID_IDX; +u64 car_id = ENTITY_INVALID_IDX; + +static void +app_init(void) { + SetTraceLogLevel(LOG_WARNING); + SetConfigFlags(FLAG_MSAA_4X_HINT | + FLAG_VSYNC_HINT | + FLAG_WINDOW_RESIZABLE); + + InitWindow(1280, 720, "Fun Game"); + SetExitKey(KEY_NULL); + SetTargetFPS(60); + app.run = true; + + FLAG_SET(app.flags, BIT(APP_FLAG_EDIT)); + FLAG_SET(app.flags, BIT(APP_FLAG_DEBUG)); + + physics_init(); + res_init(); + env_init(); + entity_system_init(); + game_init(); + editor_init(); + cam_init(); + + // for (int i = 0; i < 10000; ++i) { + // u64 id = entity_create(false); + // Entity *ent = entity_get(id); + + // char name[16]; + // snprintf(name, 16, "Entity %i", i); + // free(ent->name); + // ent->name = strdup(name); + + // ent->tr.pos = (Vec3){ + // GetRandomValue(-50, 50), + // GetRandomValue(-10, 10), + // GetRandomValue(-50, 50), + // }; + // } + + // for (int i = 0; i < entity_count(); ++i) { + // u64 id = entity_id_at(i); + + // if (i == 5) { + // u64 parent_id = entity_id_at(4); + // entity_set_parent(id, parent_id); + // } + + // if (i == 10) { + // entity_delete(id); + // } + // } +} + +static void +app_exit(void) { + editor_exit(); + game_exit(); + entity_system_exit(); + env_exit(); + res_exit(); + physics_exit(); +} + +static void +app_loop(void) { + app.run = !WindowShouldClose(); + + /* this is some hypothetical bullshit, probably will change */ + if (app.mode != APP_MODE_PLAY) { + editor_update(); + } + + physics_update(); + res_update(); + env_update(); + entity_system_update(); + + BeginDrawing(); + ClearBackground(RAYWHITE); + env_draw_sky(main_cam.cam); + + BeginMode3D(main_cam.cam); + entity_system_draw_3d(); + + // delete this shit later + for (u32 i = 0; i < entity_count(); ++i) { + Matrix world = entity_world_matrix(entity_id_at(i)); + + rlPushMatrix(); + rlMultMatrixf(MatrixToFloatV(world).v); + DrawCubeWiresV(Vector3Zero(), Vector3One(), GREEN); + rlPopMatrix(); + } + EndMode3D(); + + if (FLAG_CHECK(app.flags, BIT(APP_FLAG_DEBUG)) || + FLAG_CHECK(app.flags, BIT(APP_FLAG_EDIT))) { + BeginMode3D(main_cam.cam); + rlDisableDepthTest(); + editor_draw_3d(); + EndMode3D(); + } + + editor_draw_ui(); + EndDrawing(); +} + +int +main(void) { + app_init(); + while (app.run) { + app_loop(); + } + app_exit(); + return 0; +} |
