#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}; static void app_prepare_view(void) { if (app.scr_tex.texture.width != app.rw || app.scr_tex.texture.height != app.rh) { if (app.scr_tex.id) { UnloadRenderTexture(app.scr_tex); } app.scr_tex = LoadRenderTexture(app.rw, app.rh); SetTextureFilter(app.scr_tex.texture, TEXTURE_FILTER_POINT); } f32 width = MAX(GetScreenWidth(), 1); f32 height = MAX(GetScreenHeight(), 1); f32 scale = fminf( width / app.rw, height / app.rh); app.scr_rec = (Rect){ .x = (width - app.rw * scale) * 0.5f, .y = (height - app.rh * scale) * 0.5f, .width = app.rw * scale, .height = app.rh * scale, }; } Ray app_screen_ray(Vec2 position, Camera camera) { position.x = (position.x - app.scr_rec.x) * app.rw / app.scr_rec.width; position.y = (position.y - app.scr_rec.y) * app.rh / app.scr_rec.height; return GetScreenToWorldRayEx( position, camera, app.rw, app.rh); } Vec2 app_world_to_screen(Vec3 position, Camera camera) { Vec2 point = GetWorldToScreenEx( position, camera, app.rw, app.rh); return (Vec2){ app.scr_rec.x + point.x * app.scr_rec.width / app.rw, app.scr_rec.y + point.y * app.scr_rec.height / app.rh, }; } static void app_clear_depth(void) { rlDrawRenderBatchActive(); rlEnableDepthMask(); rlColorMask(false, false, false, false); rlClearScreenBuffers(); rlColorMask(true, true, true, true); } static void app_init(void) { SetTraceLogLevel(LOG_WARNING); SetConfigFlags( // FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE); InitWindow(1280, 720, "Fun Game"); app.rw = GetScreenWidth() / 2; app.rh = GetScreenHeight() / 2; 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(); } static void app_exit(void) { UnloadRenderTexture(app.scr_tex); editor_exit(); game_exit(); entity_system_exit(); env_exit(); res_exit(); physics_exit(); } static void app_loop(void) { app.run = !WindowShouldClose(); f64 frame_start = GetTime(); app_prepare_view(); entity_system_update(); /* this is some hypothetical bullshit, probably will change */ if (app.mode == APP_MODE_EDIT) { editor_update(); } physics_update(); res_update(); env_update(); BeginDrawing(); ClearBackground(BLACK); BeginTextureMode(app.scr_tex); ClearBackground(RAYWHITE); env_draw_sky(main_cam.cam); BeginMode3D(main_cam.cam); entity_system_draw_3d(); if (FLAG_CHECK(app.flags, BIT(APP_FLAG_DEBUG)) || FLAG_CHECK(app.flags, BIT(APP_FLAG_EDIT))) { app_clear_depth(); rlEnableDepthTest(); editor_draw_3d(); } EndMode3D(); EndTextureMode(); DrawTexturePro(app.scr_tex.texture, (Rect){ 0, 0, (f32)app.scr_tex.texture.width, -(f32)app.scr_tex.texture.height, }, app.scr_rec, (Vec2){0}, 0, WHITE); editor_draw_ui(); // app.frame_time_ms = (GetTime() - frame_start) * 1000.0f; EndDrawing(); app.frame_time_ms = (GetTime() - frame_start) * 1000.0f; } int main(void) { app_init(); while (app.run) { app_loop(); } app_exit(); return 0; }