Understanding the Simulation loop
An easy tutorial this time, we're just going to be looking at the Simulation loop and seeing how our project code fits in.
1. Understanding the engine code structure
Let's look at some engine code! The engine is a submodule, so it's super easy to dip into. Go to Libraries/AmalgamEngine/Source and look around for a second. Notice how it's structured pretty much the same as the project code (except Client and Server are now ClientLib and ServerLib).
When you're done exploring, open ServerLib/Simulation/Private/Simulation.cpp.
2. Understanding the Simulation's tick()
Here's where it all comes together: check out the first thing in tick()
:
// Call the project's pre-everything logic.
if (extension != nullptr) {
extension->beforeAll();
}
This is where our beforeAll()
is called! In fact, if you go back and look at SimulationExtension.h, you can read the hook function comments and see exactly where each hook is called in the loop.
When you have an idea for a new system, it's often necessary to think about where it should be called. Does it affect movement? It might need to happen after processMovements()
. Does it update the tile map? It should probably be called before sendTileUpdates()
. Looking at how the engine works can also give you ideas for how to implement new features, so take some time to look through the engine system calls.