+#include <stdio.h>
#include <stddef.h>
#include <raylib.h>
#include <stdlib.h>
#include "structs.h"
+#define VEC3_UNROLL(v3) v3.x, v3.y, v3.z
+
Vector2 fscreen_dims;
Camera3D cam;
Image barrow_image;
typedef void(*renderfunc)();
typedef void(*controlfunc)();
-#define MAX_RENDERFUNCS 2U
+#define MAX_RENDERFUNCS 3U
renderfunc renderfuncs[MAX_RENDERFUNCS];
controlfunc controlfuncs[MAX_RENDERFUNCS];
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();
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};
+
if(map_visible)
{
+ DrawFPS(fscreen_dims.x - 80, 10);
DrawTexturePro(floor_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
+ 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("tgt x %f\ntgt y %f\ntgt z %f", cam.target.x, cam.target.y, cam.target.z), 0, 128+64, 16, GREEN);
+ DrawText(TextFormat("rot x %f\nrot y %f\nrot z %f", player_angles.x, player_angles.y, player_angles.z), 0, 128+(64*2), 16, GREEN);
+ DrawText(TextFormat("ray hit %d\nlength %f", player_collision.hit, player_collision.distance), 0, 128+(64*3), 16, GREEN);
}
+}
-#define DEBUG_GAME_INFO 0
-#if DEBUG_GAME_INFO==1
+void drawing_resource_ready_mode()
+{
+ static int status_phase = 0;
+ const float font_size =32.0f;
+ const char format_string[] = "%s\n\n%3.2f%%";
+ const char tribute_string[] = "This game is dedicated to the North American Muskrat, Ondatra Zibethicus";
- DrawFPS(fscreen_dims.x - 80, 10);
- DrawTexturePro(floor_texture, minimap_src, minimap_dest, (Vector2){0.0f, 0.0f}, 0.0f, RAYWHITE);
- 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("tgt x %f\ntgt y %f\ntgt z %f", cam.target.x, cam.target.y, cam.target.z), 0, 128+64, 16, GREEN);
- DrawText(TextFormat("rot x %f\nrot y %f\nrot z %f", player_angles.x, player_angles.y, player_angles.z), 0, 128+(64*2), 16, GREEN);
- DrawText(TextFormat("ray hit %d\nlength %f", player_collision.hit, player_collision.distance), 0, 128+(64*3), 16, GREEN);
-#endif /* DEBUG_GAME_INFO */
+ ClearBackground(LIGHTGRAY);
+ DrawText(tribute_string,
+ (fscreen_dims.x/2.0f) - (MeasureText(tribute_string, font_size)/2.0f), 3.0f * (fscreen_dims.y/4.0f), font_size, BLACK);
}
/* Something to render while waiting on resources to be generated.
player_collide_ray = (Ray){cam.position, vec3_up};
player_collision = GetRayCollisionMesh(player_collide_ray, barrow_model.meshes[0U], barrow_mat);
player_rotation = new_player_rotation;
+
if (player_collision.distance >= 0.3f)
{
player_velocity = new_player_velocity;
{
floor_image = LoadImage("./floor.png");
floor_albedo = LoadTexture("./floor_albedo.png");
+ while(!IsImageReady(floor_image)){}
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)){}
hand_position = (Vector2){0, fscreen_dims.y - (hand_01_image.height * hand_scale)};
hand_rotation = 0.0f;
}
-
- /* Mode handler setup */
- {
- renderfuncs[0U] = drawing_resource_wait_mode;
- renderfuncs[1U] = drawing_game_mode;
- controlfuncs[0U] = control_resource_wait_mode;
- controlfuncs[1U] = control_game_mode;
- }
-}
-
-/* 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;
}
/* Values and things to do that have to have to be done after Raylib is initialized. */
SetWindowState(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
}
+void control_resource_ready_mode()
+{
+ if(resource_state == 1)
+ {
+ wait_initialize_resources();
+ initialize_renderer();
+ resource_state = 2;
+ }
+}
+
+/* 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;
+
+ /* Mode handler setup */
+ {
+ renderfuncs[0U] = drawing_resource_wait_mode;
+ renderfuncs[1U] = drawing_resource_ready_mode;
+ renderfuncs[2U] = drawing_game_mode;
+ controlfuncs[0U] = control_resource_wait_mode;
+ controlfuncs[1U] = control_resource_ready_mode;
+ controlfuncs[2U] = control_game_mode;
+ }
+}
+
void start_render_loop()
{
initialize_prerenderer();
SetTraceLogLevel(LOG_ALL);
InitWindow(fscreen_dims.x, fscreen_dims.y, screen_title);
-
wait_initialize_shaders();
- wait_initialize_resources();
- initialize_renderer();
SetTargetFPS(target_fps);
while (!WindowShouldClose())
{
+ int func_idx = resource_state;
+
player_collide_point = cam.position;
player_collide_point.y -= 1.0f;
- controlfuncs[resource_generation_finished]();
+ controlfuncs[func_idx]();
Matrix mat_trans = MatrixTranslate(barrow_position.x, barrow_position.y, barrow_position.z);
Matrix mat_rot = MatrixRotate(barrow_rotation_axis, DEG2RAD * barrow_rotation);
UpdateCameraPro(&cam, player_velocity, player_rotation, 0.0f);
BeginDrawing();
- renderfuncs[resource_generation_finished]();
+ renderfuncs[func_idx]();
EndDrawing();
/* Decay forward velocity and rotation */