2024-06-29 01:18:22 +02:00
|
|
|
|
|
|
|
|
2024-07-01 02:14:08 +02:00
|
|
|
|
2024-06-29 13:27:37 +02:00
|
|
|
int start(int argc, char **argv) {
|
2024-06-29 01:18:22 +02:00
|
|
|
|
|
|
|
window.title = fixed_string("My epic game");
|
2024-07-01 16:50:56 +07:00
|
|
|
window.width = 1280;
|
|
|
|
window.height = 720;
|
2024-06-29 13:27:37 +02:00
|
|
|
window.x = 200;
|
|
|
|
window.y = 200;
|
2024-06-29 01:18:22 +02:00
|
|
|
|
2024-07-01 02:14:08 +02:00
|
|
|
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");
|
|
|
|
|
2024-06-29 13:27:37 +02:00
|
|
|
seed_for_random = os_get_current_cycle_count();
|
2024-06-29 01:18:22 +02:00
|
|
|
|
2024-07-01 02:14:08 +02:00
|
|
|
const float64 fps_limit = 69000;
|
- File IO
- os_file_open(string path, Os_Io_Open_Flags flags)
- os_file_close(File f)
- os_file_delete(string path)
- os_file_write_string(File f, string s)
- os_file_write_bytes(File f, void *buffer, u64 size_in_bytes)
- os_file_read(File f, void* buffer, u64 bytes_to_read, u64 *actual_read_bytes)
- os_write_entire_file_handle(File f, string data)
- os_write_entire_file(string path, string data)
- os_read_entire_file_handle(File f, string *result)
- os_read_entire_file(string path, string *result)
- fprint(File, string/char*, ...)
- Buncha tests
- os_high_precision_sleep
- talloc_string
- Program memory is touched on VirtualAlloc so it actually allocates physical memory (and we can tell when an address is untouched)
2024-06-29 20:55:43 +02:00
|
|
|
const float64 min_frametime = 1.0 / fps_limit;
|
|
|
|
|
2024-07-01 02:14:08 +02:00
|
|
|
Matrix4 camera_view = m4_scalar(1.0);
|
|
|
|
|
2024-06-29 13:27:37 +02:00
|
|
|
float64 last_time = os_get_current_time_in_seconds();
|
2024-06-29 01:18:22 +02:00
|
|
|
while (!window.should_close) {
|
|
|
|
reset_temporary_storage();
|
|
|
|
context.allocator = temp;
|
|
|
|
|
2024-06-29 13:27:37 +02:00
|
|
|
float64 now = os_get_current_time_in_seconds();
|
|
|
|
float64 delta = now - last_time;
|
- File IO
- os_file_open(string path, Os_Io_Open_Flags flags)
- os_file_close(File f)
- os_file_delete(string path)
- os_file_write_string(File f, string s)
- os_file_write_bytes(File f, void *buffer, u64 size_in_bytes)
- os_file_read(File f, void* buffer, u64 bytes_to_read, u64 *actual_read_bytes)
- os_write_entire_file_handle(File f, string data)
- os_write_entire_file(string path, string data)
- os_read_entire_file_handle(File f, string *result)
- os_read_entire_file(string path, string *result)
- fprint(File, string/char*, ...)
- Buncha tests
- os_high_precision_sleep
- talloc_string
- Program memory is touched on VirtualAlloc so it actually allocates physical memory (and we can tell when an address is untouched)
2024-06-29 20:55:43 +02:00
|
|
|
if (delta < min_frametime) {
|
|
|
|
os_high_precision_sleep((min_frametime-delta)*1000.0);
|
|
|
|
now = os_get_current_time_in_seconds();
|
|
|
|
delta = now - last_time;
|
|
|
|
}
|
2024-06-29 13:27:37 +02:00
|
|
|
last_time = now;
|
2024-07-01 02:14:08 +02:00
|
|
|
os_update();
|
2024-06-29 17:54:30 +02:00
|
|
|
|
|
|
|
if (is_key_just_released(KEY_ESCAPE)) {
|
|
|
|
window.should_close = true;
|
|
|
|
}
|
|
|
|
|
2024-07-01 02:14:08 +02:00
|
|
|
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;
|
2024-06-29 17:54:30 +02:00
|
|
|
}
|
|
|
|
|
2024-07-01 02:14:08 +02:00
|
|
|
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();
|
2024-06-29 17:54:30 +02:00
|
|
|
}
|
|
|
|
|
2024-07-01 02:14:08 +02:00
|
|
|
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;
|
2024-06-29 01:18:22 +02:00
|
|
|
|
2024-07-01 02:14:08 +02:00
|
|
|
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);
|
2024-06-29 13:27:37 +02:00
|
|
|
|
2024-07-01 02:14:08 +02:00
|
|
|
Vector2 hover_position = v2_rotate_point_around_pivot(v2(-.5, -.5), v2(0, 0), (f32)now);
|
2024-06-29 13:27:37 +02:00
|
|
|
Vector2 local_pivot = v2(.125f, .125f);
|
2024-07-01 02:14:08 +02:00
|
|
|
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);
|
2024-06-29 13:27:37 +02:00
|
|
|
|
|
|
|
gfx_update();
|
2024-07-01 02:14:08 +02:00
|
|
|
|
|
|
|
if (is_key_just_released('E')) {
|
|
|
|
log("FPS: %.2f", 1.0 / delta);
|
|
|
|
log("ms: %.2f", delta*1000.0);
|
|
|
|
}
|
2024-06-29 01:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|