Writing Deterministic Code
The simulation must give the same result for the same inputs on every machine and every build. Everything the online match,
the rollback, the sync test and the replays rely on comes from this rule. Follow it whenever you write a frame event, a state
condition or change the simulation code (AFTCore).
The rules
- Only
FAFTSimStatechanges duringStep. It must stay POD without padding:AFT_ASSERT_ROLLBACK_SAFEchecks it at compile time (std::is_trivially_copyableandstd::has_unique_object_representations). Useint32fields,FAFTFixed, fixed size arrays; no pointers, noTArray, noboolbetweenint32s (padding). - No floats, no
FMath::Rand, no time, no world queries. UseFAFTFixedmath and the simulation random generator (State.Match.Rng). - Data comes from
FAFTSimDatabase(compiled at battle start, read only). A new asset value that affects gameplay must be added to the content hash (HashValue), so that two peers with different data refuse to play. - Stable iteration order: no
TMap/TSetiteration in the simulation (lookups are fine). - Effects go through events (
Emit), played by the presentation; never spawn or play anything from the simulation. - Run a Sync Test match after every gameplay change (see Testing the Netcode).
Fixed capacities
AFTCoreTypes.h defines the capacities of the state (no allocation per frame):
| Constant | Value |
|---|---|
FrameRate | 60 |
MaxTeams / MaxTeamSize | 2 / 3 (6 fighters) |
MaxProjectiles | 16 |
InputHistoryLength | 32 frames per team |
MaxHitboxes / MaxHurtboxes | 8 / 6 per entity |
MaxHitsPerAction | 8 |
MaxCancelActions | 12 |
MaxGotoChain | 4 |
Fixed point
FAFTFixed stores a value in 1/1000 of a centimeter in an int32 (AFT::FixedScale = 1000). In the editor, fixed values are shown
and edited in centimeters (a details customization converts them). FAFTFixedVector and FAFTFixedBox are the vector and box types
of the simulation; UAFTFixedLibrary exposes them to Blueprint: conversions for tools and UI, and the deterministic math nodes
(+ - * /, comparisons, Fixed From Int...) of the Blueprint extensions below.
Where to extend
| Extension | How |
|---|---|
| New frame event | Derive from FAFTFrameEvent, implement Execute (see Actions and Frame Events). Or in Blueprint: parent class AFT Frame Event Blueprint, override Execute with the AFT Frame Event functions and the AFT Fixed math nodes (see Custom frame events (Blueprint)). |
| New state graph condition | Derive from FAFTStateCondition, implement Evaluate. Or in Blueprint: parent class AFT State Condition Blueprint, override Evaluate with the AFT State Condition functions (see Custom conditions (Blueprint)). |
| Wall rules | Derive from UAFTWallRules, override NativeWallContact / NativeHit / NativeComboEnd and HashSettings; state in the fighter and match wall memory only. Or in Blueprint: override On Wall Contact / On Hit / On Combo End with the wall context (see Walls). |
| CPU brain | Derive from UAFTCpuBrain, override Think; random numbers and memory from the context only. Or in Blueprint: override On Think with the CPU context (see Custom CPU Brains). |
| Presentation | Anything in AFTGame reads the state and the events: fighter actor, camera, presentation, HUD can use floats and the world freely. |