diff options
Diffstat (limited to 'src/scenes/loading_world_scene.c')
| -rw-r--r-- | src/scenes/loading_world_scene.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/scenes/loading_world_scene.c b/src/scenes/loading_world_scene.c new file mode 100644 index 0000000..3d15909 --- /dev/null +++ b/src/scenes/loading_world_scene.c @@ -0,0 +1,116 @@ +
+void loading_world_scene_init()
+{
+
+}
+
+u64 load_start_stamp = 0;
+
+static void* start_loading_world_t(void* arg)
+{
+ load_start_stamp = platform_get_time(TIME_FULL, TIME_US); // Used for displaying info texts.
+ #ifdef MODE_DEBUG
+ // thread_sleep(1000*200);
+ #endif
+
+ char* path = (char*)arg;
+ world* world_to_load = 0;
+
+ if (path) {
+ // Load from file here
+ }
+ else {
+ world_to_load = world_create_new();
+ }
+
+ #ifdef MODE_DEBUG
+ u64 load_end_stamp = platform_get_time(TIME_FULL, TIME_US);
+ u64 elapsed_ns = load_end_stamp - load_start_stamp;
+ char info_msg[50];
+ sprintf(info_msg, "Loaded world in %.2fms", elapsed_ns/1000.0f);
+ log_info(info_msg);
+ #endif
+
+ if (!world_to_load) {
+ log_info("Failed to load world");
+ game_set_active_scene(GAME_STATE_ERROR);
+ }
+ else {
+ world_map_set_active_world(world_to_load);
+ game_set_active_scene(GAME_STATE_WORLD_MAP);
+ }
+
+ return 0;
+}
+
+void start_loading_world(char* saved_file_path)
+{
+ game_set_active_scene(GAME_STATE_LOADING_WORLD);
+ thread_start(start_loading_world_t, saved_file_path);
+}
+
+static void loading_world_draw_info_texts(font* font, s32 center_x, s32 y)
+{
+ char* texts[5] = {
+ "(Building cities)",
+ "(Connecting roads)",
+ "(Manufacturing trucks)",
+ "(Finding truck drivers)",
+ "(This is taking very long..)",
+ };
+
+ u64 load_end_stamp = platform_get_time(TIME_FULL, TIME_US);
+ u64 elapsed_ns = load_end_stamp - load_start_stamp;
+ float elapsed_sec = elapsed_ns / 1000.0f;
+ int text_index = elapsed_sec / 2000.0f; // 2 sec per text.
+ if (text_index >= 5) text_index = 4;
+
+ s32 text_len = renderer->calculate_text_width(font, texts[text_index]);
+ renderer->render_text(font, center_x - (text_len/2), y, texts[text_index], COLOR_TEXT);
+}
+
+static void loading_world_draw_animation(platform_window* window)
+{
+ s32 screen_center_x = area.x + (area.w/2);
+ s32 screen_center_y = area.y + (area.h/2);
+
+ float vertical_pad = 20 * scale;
+ float horizontal_pad = vertical_pad;
+ float spacing = 5 * scale;
+
+ s32 panel_h = 280 * scale;
+ s32 panel_item_size = (panel_h - (vertical_pad*2) - (spacing*1)) / 2;
+ s32 panel_w = (panel_item_size * 3) + (horizontal_pad*2) + (spacing*2);
+
+ s32 panel_x = screen_center_x - (panel_w/2);
+ s32 panel_y = screen_center_y - (panel_h/2);
+ panel_render(scale, panel_x, panel_y, panel_w, panel_h);
+
+ s32 carwheel_size = panel_h/4;
+
+ static float rotation = 0.0f;
+ rotation -= 0.05f;
+ gl_render_set_rotation(rotation);
+ renderer->render_image(img_carwheel, screen_center_x - (carwheel_size/2), screen_center_y - (carwheel_size/2), carwheel_size, carwheel_size);
+ gl_render_set_rotation(0.0f);
+
+
+ font* font_info = FONT_REGULAR(SIZE_RD(area.w, 28));
+ loading_world_draw_info_texts(font_info, screen_center_x, panel_y + panel_h - font_info->px_h - vertical_pad*2);
+}
+
+void loading_world_scene_render(platform_window* window)
+{
+ menu_draw_background(window);
+ loading_world_draw_animation(window);
+}
+
+void loading_world_scene_update(platform_window* window)
+{
+
+}
+
+void loading_world_scene_destroy()
+{
+
+}
\ No newline at end of file |
