Split Engine Logic
Before we proceed, we need to make a crucial decision: should we keep our engine.odin file as
it is, or should we split the codebase into more manageable pieces? While some developers
appreciate the simplicity of a single, large file, we should take advantage of one of Odin’s
best features: everything within a folder belongs to the same package and is seamlessly visible
to each other. This allows us to break our engine into smaller, cohesive modules without losing
integration.
Let's start with the initialization procedures. There are quite a few of them, and typically do not require frequent changes.
-
Move the following procedures to a new file called
init.odin:engine_initengine_init_vulkanengine_create_swapchainengine_resize_swapchainengine_destroy_swapchainengine_init_swapchainengine_init_commandsengine_init_sync_structuresengine_init_descriptorsengine_init_background_pipelineengine_init_mesh_pipelineengine_init_pipelinesengine_init_imguiengine_init_default_dataengine_cleanup
-
Create a file called
drawing.odinand move the draw procedures:engine_get_current_frameengine_drawengine_draw_backgroundengine_ui_definitionengine_draw_imguiengine_draw_geometry
-
Move
engine_immediate_submittocore.odin.
Now, our engine.odin file contains only the Engine related structures, the engine_run
and engine_ui_definition procedures. Although the changes are minimal, this reorganization
can help keep our project more manageable. Make sure to review the final codebase to see how
the project is structured before continue.