int main(int argc, char** argv) { if (init_systems()) return -1; main_poll(); return shut_systems(); }
int main(int argc, char** argv) { init_core(); debug_message("[hunter] initialized core"); init_graphic(); debug_message("[hunter] initialized graphics, mode W%d H%d", window_get_width(global_get(global_get_singleton(), GLOBAL_WINDOW)), window_get_height(global_get(global_get_singleton(), GLOBAL_WINDOW))); init_sound(); debug_message("[hunter] initialized sound"); init_systems(); debug_message("[hunter] initialized systems"); window* window_handle = global_get(global_get_singleton(), GLOBAL_WINDOW); input* input_handle = global_get(global_get_singleton(), GLOBAL_INPUT); syscontainer* syscontainer_handle = global_get(global_get_singleton(), GLOBAL_SYSCONTAINER); text* text_handle = global_get(global_get_singleton(), GLOBAL_TEXT); hl_render* hl_render_handle = global_get(global_get_singleton(), GLOBAL_HL_RENDER); shader* shader_texture_handle = global_get(global_get_singleton(), GLOBAL_SHADER_TEXTURE); camera* camera_handle = global_get(global_get_singleton(), GLOBAL_CAMERA); debug_draw* debug_draw_handle = global_get(global_get_singleton(), GLOBAL_DEBUG_DRAW); float delta_ref_point = time_get_elapsed(window_handle); float delta_accumulator = 0.0f; float delta_frame_time = 0.0f; float fps_accumulator = 0.0f; float fps_value = 0.0f; float fps_value_last = fps_value; unsigned int fps_counter = 0; unsigned int game_kill_flag = 0; debug_message("[hunter] posting init event to systems"); syscontainer_post_event(syscontainer_handle, EVENT_INIT); while (!game_kill_flag) { delta_frame_time = time_get_elapsed(window_handle) - delta_ref_point; delta_ref_point = time_get_elapsed(window_handle); window_update(window_handle); input_state current_input_state; input_get_input_state(input_handle, ¤t_input_state); game_kill_flag |= window_get_should_close(window_handle); game_kill_flag |= current_input_state.key_dev; window_set_clear_color(window_handle, 1.0f, 0.0f, 1.0f, 0.0f); debug_draw_clear(debug_draw_handle); window_clear(window_handle); delta_accumulator += delta_frame_time; if (delta_accumulator < 0.0f) { delta_accumulator = 0.0f; } while (delta_accumulator >= 1.0f / DELTA_REFERENCE_FPS) { syscontainer_post_event(syscontainer_handle, EVENT_PRE_LOGIC); syscontainer_post_event(syscontainer_handle, EVENT_LOGIC); syscontainer_post_event(syscontainer_handle, EVENT_POST_LOGIC); delta_accumulator -= 1.0f / DELTA_REFERENCE_FPS; } syscontainer_post_event(syscontainer_handle, EVENT_DRAW); window_set_blend_mode(window_handle, WINDOW_BLEND_ALPHA); debug_draw_render_all(debug_draw_handle); hl_render_draw(hl_render_handle, shader_texture_handle, camera_handle); hl_render_clear(hl_render_handle); fps_counter++; fps_accumulator += delta_frame_time; if (fps_accumulator >= 1.0f) { fps_value_last = fps_value; fps_value = (float) fps_counter / fps_accumulator; fps_counter = 0; fps_accumulator = 0.0f; } text_batch fps_batch = {20, 20, 0.2f, 0.8f, 1.0f, 1.0f, "", "monospace", 12}; sprintf(fps_batch.text_data, "FPS : %3.2f (%3.2f)", fps_value, fps_value - fps_value_last); text_submit_batch(text_handle, &fps_batch); text_render_all(text_handle); text_flush_batch(text_handle); window_swap_buffers(window_handle); } debug_message("[hunter] posting destroy event to systems"); syscontainer_post_event(syscontainer_handle, EVENT_DESTROY); free_systems(); free_sound(); free_graphic(); free_core(); h_free_all(); debug_message("[hunter] terminated cleanly"); return 0; }