]> git.mcshandy.xyz Git - barrow_crawler/commitdiff
Clean up organization of some resource setup in renderer, and whatever else snuck in
authorRandy McShandy <randy@mcshandy.xyz>
Sat, 18 May 2024 22:59:18 +0000 (17:59 -0500)
committerRandy McShandy <randy@mcshandy.xyz>
Sat, 18 May 2024 22:59:18 +0000 (17:59 -0500)
src/main.c
src/platforms/platform_posix.c
src/render_raylib.c
src/shaders/lighting.fs

index eb6dbc7f52681559ac4e73e78d1b901343ec4068..456c15ee604ecb517f54d3363243710906c57fcc 100755 (executable)
@@ -22,7 +22,7 @@ int main(int argc, char** argv)
        }
        barrow.max_iterations *= 1;
 
-#define ENABLE_BARROWGEN 1
+#define ENABLE_BARROWGEN 0
 #if ENABLE_BARROWGEN
        generate_rd(8, barrow, grid, grid_size);
 #endif
index 3550db51c78236d188ac5b7e66784f407987f085..72aa4e891428fe14dc1ae855a990c89d25e2e29e 100644 (file)
@@ -16,6 +16,7 @@ pthread_t* threads;
 pthread_mutex_t mutex;
 pthread_barrier_t barrier;
 
+/* TODO: This should go in a header, platforms don't care. */
 float rd_a_prime(FVec2 **source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B);
 float rd_b_prime(FVec2** source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B);
 
@@ -90,6 +91,7 @@ void start(int worker_count, RD_Opts active_opt)
        }
 }
 
+/* TODO: Revisit this for any new additions. */
 int cleanup()
 {
        for (int t = 0; t < warg.worker_count; t++)
index 72f52e54da7f2f6011ce82277f72b2124de58f65..d15803ecb833eafbc6fccd53b9acaeb9bd32d904 100644 (file)
@@ -128,73 +128,91 @@ void process_inputs()
        while((key = GetKeyPressed()));
 }
 
-void initialize_prerenderer()
+void wait_initialize_shaders()
 {
-       fscreen_dims = (Vector2){.x=screen_dims.x, .y=screen_dims.y};
-}
-
-void initialize_renderer()
-{
-
        shader = LoadShader("./src/shaders/lighting.vs", "./src/shaders/lighting.fs");
+       while(!IsShaderReady(shader)){}
+
        shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
        shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp");
        cam_position_shader_loc = GetShaderLocation(shader, "cam_position");
        screen_dims_shader_loc = GetShaderLocation(shader, "screen_dims");
        map_center_shader_loc = GetShaderLocation(shader, "map_center");
-       while(!IsShaderReady(shader)){}
+}
+
+void wait_initialize_resources()
+{
+       /* Barrow resource setup. */
+       {
+               barrow_position = (Vector3){0.0f, 0.0f, 0.0f};
+               barrow_image = LoadImage("./barrow.png");
+               barrow_albedo = LoadTexture("./barrow_albedo.png");
+               barrow_scale = (Vector3){barrow_image.width/6.0f, 8.0f, barrow_image.height/6.0f};
+               barrow_rotation_axis = (Vector3){1.0f, 0.0f, 0.0f};
+               barrow_rotation = 180.0f;
+
+               while(!IsImageReady(barrow_image)){}
+               while(!IsTextureReady(barrow_albedo)){}
+               barrow_texture = LoadTextureFromImage(barrow_image);
+               while(!IsTextureReady(barrow_texture)){}
+
+               barrow_meshes[0U] = GenMeshHeightmap(barrow_image, vec3_unit);
+               barrow_model = LoadModelFromMesh(barrow_meshes[0]);
+               barrow_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = barrow_albedo;
+               barrow_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = barrow_albedo;
+               barrow_model.materials[0].shader = shader;
+
+               while(!IsModelReady(barrow_model)){}
+       }
 
-       barrow_position = (Vector3){0.0f, 0.0f, 0.0f};
-       barrow_image = LoadImage("./barrow.png");
-       barrow_albedo = LoadTexture("./barrow_albedo.png");
-       barrow_scale = (Vector3){barrow_image.width/6.0f, 8.0f, barrow_image.height/6.0f};
-       barrow_rotation_axis = (Vector3){1.0f, 0.0f, 0.0f};
-       barrow_rotation = 180.0f;
+       /* Floor resource setup. */
+       {
+               floor_image = LoadImage("./floor.png");
+               floor_albedo = LoadTexture("./floor_albedo.png");
+               floor_scale = (Vector3){floor_image.width/6.0f, 3.0f, floor_image.height/6.0f};
+               floor_position = (Vector3){0.0f, -3.0f, -floor_scale.z};
+               floor_rotation_axis = (Vector3){0.0f, 0.0f, floor_image.width};
+               floor_rotation = 0.0f;
+               while(!IsImageReady(floor_image)){}
+               while(!IsTextureReady(floor_albedo)){}
+
+               floor_texture = LoadTextureFromImage(floor_image);
+               while(!IsTextureReady(floor_texture)){}
+
+               floor_meshes[0U] = GenMeshHeightmap(floor_image, vec3_unit);
+               floor_model = LoadModelFromMesh(floor_meshes[0]);
+               floor_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = floor_albedo;
+               floor_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = floor_albedo;
+               floor_model.materials[0].shader = shader;
+               while(!IsModelReady(floor_model)){}
+       }
+
+       /* Other resource setup. */
+       {
+               coffin_scale = (Vector3){1.5f, 1.5f, 1.5f};
+               coffin_position = (Vector3){barrow_scale.x/2.0f, floor_position.y, -barrow_scale.z/2.0f};
+               coffin_rotation_axis = (Vector3){0.0f, 0.0f, 0.0f};
+               coffin_rotation = 0.0f;
+               coffin_model = LoadModel("./assets/coffin_1.glb");
+               while(!IsModelReady(coffin_model)){}
+               coffin_model.materials[0].shader = shader;
+       }
+}
+
+/* Values that are required to initialize Raylib. */
+void initialize_prerenderer()
+{
+       fscreen_dims = (Vector2){.x=screen_dims.x, .y=screen_dims.y};
 
        map_center = barrow_scale;
        map_center.x /= 2.0f;
        map_center.z /= -2.0f;
        map_center.y = -3.0f;
+}
 
-       while(!IsImageReady(barrow_image)){}
-       barrow_texture = LoadTextureFromImage(barrow_image);
-
-       while(!IsTextureReady(barrow_texture)){}
-       while(!IsTextureReady(barrow_albedo)){}
-
-       floor_image = LoadImage("./floor.png");
-       floor_albedo = LoadTexture("./floor_albedo.png");
-       floor_scale = (Vector3){floor_image.width/6.0f, 3.0f, floor_image.height/6.0f};
-       floor_position = (Vector3){0.0f, -3.0f, -floor_scale.z};
-       floor_rotation_axis = (Vector3){0.0f, 0.0f, floor_image.width};
-       floor_rotation = 0.0f;
-
-       while(!IsImageReady(floor_image)){}
-       floor_texture = LoadTextureFromImage(floor_image);
-       while(!IsTextureReady(floor_texture)){}
-       while(!IsTextureReady(floor_albedo)){}
-
-       /* Might want to replace barrow_scale with just img dimensions. */
-       barrow_meshes[0U] = GenMeshHeightmap(barrow_image, vec3_unit);
-       barrow_model = LoadModelFromMesh(barrow_meshes[0]);
-       barrow_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = barrow_albedo;
-       barrow_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = barrow_albedo;
-       barrow_model.materials[0].shader = shader;
-
-       floor_meshes[0U] = GenMeshHeightmap(floor_image, vec3_unit);
-       floor_model = LoadModelFromMesh(floor_meshes[0]);
-       floor_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = floor_albedo;
-       floor_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = floor_albedo;
-       floor_model.materials[0].shader = shader;
-
-       coffin_scale = (Vector3){1.5f, 1.5f, 1.5f};
-       coffin_position = (Vector3){barrow_scale.x/2.0f, floor_position.y, -barrow_scale.z/2.0f};
-       coffin_rotation_axis = (Vector3){0.0f, 0.0f, 0.0f};
-       coffin_rotation = 0.0f;
-       coffin_model = LoadModel("./assets/coffin_1.glb");
-       while(!IsModelReady(coffin_model)){}
-       coffin_model.materials[0].shader = shader;
-
+/* Values and things to do that have to have to be done after Raylib is initialized. */
+void initialize_renderer()
+{
        cam                                             = (Camera3D){0};
        cam.position            = barrow_position;
        cam.position.y -= 0.5f;
@@ -206,13 +224,16 @@ void initialize_renderer()
        cam.projection  = CAMERA_PERSPECTIVE;
 
        DisableCursor();
+       SetWindowState(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
 }
 
 void start_render_loop()
 {
        initialize_prerenderer();
        InitWindow(fscreen_dims.x, fscreen_dims.y, screen_title);
-       SetWindowState(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
+
+       wait_initialize_shaders();
+       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};
@@ -221,6 +242,7 @@ void start_render_loop()
        SetTargetFPS(target_fps);
        while (!WindowShouldClose())
        {
+
                player_collide_point = cam.position;
                player_collide_point.y -= 1.0f;
                process_inputs();
index 7da0f8a3891b4de6194483dbfa75a76f748b8d51..f85691024c3ad922fa86ed89a6ed526370ba57e3 100644 (file)
@@ -16,7 +16,7 @@ uniform vec3 map_center;
 out vec4 finalColor;
 
 const vec3 v3_unit = vec3(1.0f, 1.0f, 1.0f);
-const float max_lum = 0.8f;
+const float max_lum = 1.0f;
 const float max_lit_distance = 7.5f;
 const float max_center_distance = 8.0f;
 const vec4 candle_color = vec4(228.0f/255.0f, 103.0f/255.0f, 1.0f/255.0f, 255.0f/255.0f);