void engine_startup(memory_t* memory) { if (SDL_BYTEORDER != SDL_LIL_ENDIAN) { LOG_ERROR("Machine is Big Endian; expected Little Endian."); exit(EXIT_FAILURE); } g_memory = memory; engine_t* engine = persistent_mem_alloc(&g_memory->engine, 1, sizeof(*engine)); g_engine = engine; game_t* game = persistent_mem_alloc(&g_memory->game, 1, sizeof(*game)); g_game = game; #ifdef BUILD_DEBUG DEBUG_startup(); #endif asset_mgr_startup(); audio_mgr_startup(); render_mgr_startup(); load_data1("data1.bin"); load_data2("data2.bin"); game_startup(); } void engine_shutdown(void) { game_shutdown(); } void engine_update(float dt, input_t input, bool is_window_focused, bool* out_quit) { g_engine->time += dt; g_engine->is_window_focused = is_window_focused; for (int i = 1; i < (int)g_engine->asset_mgr.transforms.count; i++) { transform_t* transform = get_transform(i); update_transform(transform); } if (is_window_focused) { game_update(dt, input, out_quit); } } void engine_render(void) { render_geo_begin(); game_render(); render_geo_end(); render_screen_begin(); render_screen_end(); } void engine_audio_callback(void* userdata, uint8_t* stream, int len) { (void)userdata; (void)stream; (void)len; fill_audio_buffer(stream, len); } #ifdef BUILD_DEBUG void engine_reload(memory_t* memory) { g_memory = memory; g_engine = (engine_t*)memory->engine.begin; g_game = (game_t*)memory->game.begin; g_debug = (debug_t*)memory->debug.begin; DEBUG_reload_shaders(&g_engine->render_mgr); DEBUG_reload_data1(); } void engine_debug(float dt, input_t input, uint64_t update_time, uint64_t render_time, uint64_t frame_time) { if (input.debug.enable) { DEBUG_camera_toggle(); } if (g_engine->is_window_focused && g_debug->camera.enabled) { DEBUG_camera_update(dt, input); } debug(update_time, render_time, frame_time); } #endif