int start(int argc, char **argv) { window.title = fixed_string("My epic game"); window.width = 700; window.height = 400; window.x = 200; window.y = 200; Gfx_Image *bush_image = load_image_from_disk(fixed_string("berry_bush.png")); assert(bush_image, "Failed loading berry_bush.png"); Gfx_Image *hammer_image = load_image_from_disk(fixed_string("hammer.png")); assert(hammer_image, "Failed loading hammer.png"); seed_for_random = os_get_current_cycle_count(); const float64 fps_limit = 69000; const float64 min_frametime = 1.0 / fps_limit; Matrix4 camera_view = m4_scalar(1.0); float64 last_time = os_get_current_time_in_seconds(); while (!window.should_close) { reset_temporary_storage(); context.allocator = temp; float64 now = os_get_current_time_in_seconds(); float64 delta = now - last_time; if (delta < min_frametime) { os_high_precision_sleep((min_frametime-delta)*1000.0); now = os_get_current_time_in_seconds(); delta = now - last_time; } last_time = now; os_update(); if (is_key_just_released(KEY_ESCAPE)) { window.should_close = true; } if (is_key_just_pressed(KEY_ARROW_LEFT)) { window.width += 10; window.x -= 10; } if (is_key_just_pressed(KEY_ARROW_RIGHT)) { window.width += 10; } if (is_key_just_released('Q')) { push_allocator(get_heap_allocator()); delete_image(bush_image); bush_image = load_image_from_disk(fixed_string("berry_bush.png")); assert(bush_image, "Failed loading berry_bush.png"); pop_allocator(); } const float32 cam_move_speed = 4.0; Vector2 cam_move_axis = v2(0, 0); if (is_key_down('A')) { cam_move_axis.x -= 1.0; } if (is_key_down('D')) { cam_move_axis.x += 1.0; } if (is_key_down('S')) { cam_move_axis.y -= 1.0; } if (is_key_down('W')) { cam_move_axis.y += 1.0; } Vector2 cam_move = v2_mulf(cam_move_axis, delta * cam_move_speed); camera_view = m4_translate(camera_view, v3(v2_expand(cam_move), 0)); draw_frame.view = camera_view; Matrix4 hammer_xform = m4_scalar(1.0); hammer_xform = m4_rotate_z(hammer_xform, (f32)now); hammer_xform = m4_translate(hammer_xform, v3(-.25f, -.25f, 0)); draw_image_xform(hammer_image, hammer_xform, v2(.5f, .5f), COLOR_RED); Vector2 hover_position = v2_rotate_point_around_pivot(v2(-.5, -.5), v2(0, 0), (f32)now); Vector2 local_pivot = v2(.125f, .125f); draw_rect(v2_sub(hover_position, local_pivot), v2(.25f, .25f), v4((sin(now)+1.0)/2.0, 1.0, 0.0, 1.0)); draw_image(bush_image, v2(0.65, 0.65), v2(0.2*sin(now), 0.2*sin(now)), COLOR_WHITE); gfx_update(); if (is_key_just_released('E')) { log("FPS: %.2f", 1.0 / delta); log("ms: %.2f", delta*1000.0); } } return 0; }