From: Randy McShandy Date: Sun, 19 May 2024 01:14:50 +0000 (-0500) Subject: Refactor for and introduce more discretized display modes X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=afb5c4d290ff2fcc5674067dfd5bca7381f6c9f5;p=barrow_crawler Refactor for and introduce more discretized display modes --- diff --git a/src/main.c b/src/main.c index 456c15e..d60931d 100755 --- a/src/main.c +++ b/src/main.c @@ -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; diff --git a/src/render_raylib.c b/src/render_raylib.c index d15803e..58c8d30 100644 --- a/src/render_raylib.c +++ b/src/render_raylib.c @@ -1,3 +1,4 @@ +#include #include #define RAYMATH_IMPLEMENTATION #include @@ -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 */ diff --git a/src/shaders/lighting.fs b/src/shaders/lighting.fs index f856910..d5e98f1 100644 --- a/src/shaders/lighting.fs +++ b/src/shaders/lighting.fs @@ -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 diff --git a/src/structs.c b/src/structs.c index e4c9a7c..648ff0a 100644 --- a/src/structs.c +++ b/src/structs.c @@ -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; diff --git a/src/structs.h b/src/structs.h index 929689c..990ea0a 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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__ diff --git a/src/utils.c b/src/utils.c index 5ab0e65..1e4d8b7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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; }