]> git.mcshandy.xyz Git - barrow_crawler/commitdiff
Refactor for and introduce more discretized display modes
authorRandy McShandy <randy@mcshandy.xyz>
Sun, 19 May 2024 01:14:50 +0000 (20:14 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Sun, 19 May 2024 01:14:50 +0000 (20:14 -0500)
src/main.c
src/render_raylib.c
src/shaders/lighting.fs
src/structs.c
src/structs.h
src/utils.c

index 456c15ee604ecb517f54d3363243710906c57fcc..d60931d0e68c5e31b25b37f2eb9f312861be10a1 100755 (executable)
@@ -25,7 +25,10 @@ int main(int argc, char** argv)
 #define ENABLE_BARROWGEN 0
 #if ENABLE_BARROWGEN
        generate_rd(8, barrow, grid, grid_size);
-#endif
+#else
+       resource_generation_finished = 1;
+#endif /* ENABLE_BARROWGEN */
+
        start_render_loop();
 
        return 0;
index d15803ecb833eafbc6fccd53b9acaeb9bd32d904..58c8d30197d65551acd1bfd7affb0a684fdb9af1 100644 (file)
@@ -1,3 +1,4 @@
+#include <stddef.h>
 #include <raylib.h>
 #define RAYMATH_IMPLEMENTATION
 #include <raymath.h>
@@ -56,6 +57,70 @@ Vector3 vec3_010     = {0.0f, 1.0f, 0.0f};
 Vector3 vec3_up        = {0.0f, 1.0f, 0.0f};
 Vector3 vec3_down      = {0.0f, -1.0f, 0.0f};
 
+typedef void(*renderfunc)();
+#define MAX_RENDERFUNCS 2U
+renderfunc renderfuncs[MAX_RENDERFUNCS];
+
+/* Render the regular game mode.
+NOTE: Only call inside a Raylib BeginDrawing() block!
+*/
+void drawing_game_mode()
+{
+       ClearBackground(BLACK);
+
+       BeginMode3D(cam);
+       BeginShaderMode(shader);
+
+       DrawModelEx(coffin_model, coffin_position, coffin_rotation_axis, coffin_rotation, coffin_scale, DARKGRAY);
+       DrawModelEx(barrow_model, barrow_position, barrow_rotation_axis, barrow_rotation, barrow_scale, DARKGRAY);
+       DrawModelEx(floor_model, floor_position, floor_rotation_axis, floor_rotation, floor_scale, DARKGRAY);
+       DrawRay(player_collide_ray, WHITE);
+
+       EndShaderMode();
+       EndMode3D();
+
+#if DEBUG_GAME_INFO==1
+       Rectangle minimap_dest = {.width = 64.0f*img_export_scale.x, .height = 64.0f*img_export_scale.y, .x = 0.0f, .y = 0.0f};
+       Rectangle minimap_src = {.width = barrow_texture.width, .height = barrow_texture.height, .x = 0.0f, .y = 0.0f};
+
+       DrawTexturePro(floor_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
+       DrawFPS(fscreen_dims.x - 80, 10);
+       DrawText(TextFormat("cam x %f\ncam y %f\ncam z %f", cam.position.x, cam.position.y, cam.position.z), 0, 128, 16, GREEN);
+       DrawText(TextFormat("ray hit %d\nlength %f", player_collision.hit, player_collision.distance), 0, 256, 16, GREEN);
+#endif /* DEBUG_GAME_INFO */
+}
+
+/* Something to render while waiting on resources to be generated.
+NOTE: Only call inside a Raylib BeginDrawing() block!
+*/
+void drawing_resource_wait_mode()
+{
+       static int ellipses_counter = 0;
+       const char wait_string[] = "Generating resources...";
+       const int sector_speed = 2U;
+       const int sector_segments = 16;
+       const float sector_radius = 32.0f;
+       const Vector2 sector_center = {fscreen_dims.x/2.0f, 3*(fscreen_dims.y/4.0f)};
+
+       ellipses_counter+=sector_speed;
+
+       const int font_size = 32;
+       const int text_width = MeasureText(wait_string, font_size);
+
+       ClearBackground(RAYWHITE);
+       DrawText(wait_string, (fscreen_dims.x/2.0f) - (text_width/2.0f), fscreen_dims.y/2.0f, font_size, BLACK);
+       DrawCircleSector(sector_center, sector_radius,
+                       (ellipses_counter % 360),
+                       ((ellipses_counter % 360)*2),
+                       sector_segments, RED);
+
+       DrawCircleSector(sector_center, sector_radius * 0.8f,
+                       (ellipses_counter % 360),
+                       ((ellipses_counter % 360)*2),
+                       sector_segments, RAYWHITE);
+}
+
+
 void process_inputs()
 {
        Vector3 new_player_velocity = player_velocity;
@@ -197,6 +262,10 @@ void wait_initialize_resources()
                while(!IsModelReady(coffin_model)){}
                coffin_model.materials[0].shader = shader;
        }
+
+       /* Rendering handler setup */
+       renderfuncs[0U] = drawing_resource_wait_mode;
+       renderfuncs[1U] = drawing_game_mode;
 }
 
 /* Values that are required to initialize Raylib. */
@@ -236,9 +305,6 @@ void start_render_loop()
        wait_initialize_resources();
        initialize_renderer();
 
-       Rectangle minimap_dest = {.width = 64.0f*img_export_scale.x, .height = 64.0f*img_export_scale.y, .x = 0.0f, .y = 0.0f};
-       Rectangle minimap_src = {.width = barrow_texture.width, .height = barrow_texture.height, .x = 0.0f, .y = 0.0f};
-
        SetTargetFPS(target_fps);
        while (!WindowShouldClose())
        {
@@ -258,21 +324,7 @@ void start_render_loop()
 
                UpdateCameraPro(&cam, player_velocity, player_rotation, 0.0f);
                BeginDrawing();
-                       ClearBackground(BLACK);
-
-                       BeginMode3D(cam);
-                       BeginShaderMode(shader);
-                               DrawModelEx(coffin_model, coffin_position, coffin_rotation_axis, coffin_rotation, coffin_scale, DARKGRAY);
-                               DrawModelEx(barrow_model, barrow_position, barrow_rotation_axis, barrow_rotation, barrow_scale, DARKGRAY);
-                               DrawModelEx(floor_model, floor_position, floor_rotation_axis, floor_rotation, floor_scale, DARKGRAY);
-                               DrawRay(player_collide_ray, WHITE);
-                       EndShaderMode();
-                       EndMode3D();
-
-                       DrawTexturePro(floor_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
-                       DrawFPS(fscreen_dims.x - 80, 10);
-                       DrawText(TextFormat("cam x %f\ncam y %f\ncam z %f", cam.position.x, cam.position.y, cam.position.z), 0, 128, 16, GREEN);
-                       DrawText(TextFormat("ray hit %d\nlength %f", player_collision.hit, player_collision.distance), 0, 256, 16, GREEN);
+                       renderfuncs[resource_generation_finished]();
                EndDrawing();
 
                /* Decay forward velocity and rotation */
index f85691024c3ad922fa86ed89a6ed526370ba57e3..d5e98f1be0887120190b84e4bf00e63ee2c9ff20 100644 (file)
@@ -126,7 +126,7 @@ void main()
                lumWeights = vec4(1.0f) * lumWeight;
                lumWeights *= dot(finalColor, lumWeights);
 
-               lighting_color = vec4(mix(candle_color.rgb * candle_weight, lumWeights.rgb, 0.2f), 1.0f);
+               lighting_color = vec4(mix(candle_color.rgb * candle_weight, lumWeights.rgb, 0.4f), 1.0f);
                finalColor = finalColor * lighting_color;
 
                // All single color channel variations with this looks cool as FUCK
index e4c9a7c68a715efe2c96c5c297b7886049c96e7c..648ff0ad1d194ed766d4aabf757996c355ee0b2a 100644 (file)
@@ -77,4 +77,5 @@ const char* screen_title = "Barrow Crawler";
 const int target_fps = 60;
 
 const IVec2 img_export_scale = {.x = 2, .y = 2};
+int resource_generation_finished = 0;
 
index 929689c67a2e4a05ee86ca1ad264a9e81762164e..990ea0aca9756b80743caadb2977e94643f680b4 100644 (file)
@@ -71,6 +71,7 @@ extern const char* screen_title;
 extern const int target_fps;
 
 extern const IVec2 img_export_scale;
+extern int resource_generation_finished;
 
 int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2 pgrid_size);
 #endif //__RD_STRUCTS__
index 5ab0e65e70c64b8ebd1c78381ddc8573f95b8187..1e4d8b74e7e1e0dc9028cd520081aa1b3e30d292 100644 (file)
@@ -245,6 +245,8 @@ int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2
        stbi_write_png(floor_albedo_name, pgrid_size.x*img_export_scale.x, pgrid_size.y*img_export_scale.y, 4, large_albedo_buffer, pgrid_size.x * sizeof(uint32_t)*img_export_scale.x);
 
        cleanup();
+       resource_generation_finished = 1;
+
        return 0;
 }