Skip to content

Instantly share code, notes, and snippets.

@Hexlord
Created January 6, 2022 03:38
Show Gist options
  • Save Hexlord/63aa36c2fe6854c911f10cae808893ba to your computer and use it in GitHub Desktop.
Save Hexlord/63aa36c2fe6854c911f10cae808893ba to your computer and use it in GitHub Desktop.
modules be like
Import<MCoreComponents>(ECS);
Import<MGameStateComponents>(ECS);
Import<MLifespanComponents>(ECS);
Import<MPlayerControllerComponents>(ECS);
Import<MTilesComponents>(ECS);
Import<MEditorTilesComponents>(ECS);
Import<MRenderTilesComponents>(ECS);
Import<MInputComponents>(ECS);
Import<MMouseControlsComponents>(ECS);
Import<MPhysicsComponents>(ECS);
Import<MPostFrameActionsComponents>(ECS);
Import<MAnimationComponents>(ECS);
Import<MConfigComponents>(ECS);
Import<MViewComponents>(ECS);
Import<MLayoutComponents>(ECS);
Import<MTransformComponents>(ECS);
Import<MBufferComponents>(ECS);
Import<MFontComponents>(ECS);
Import<MPrimitiveComponents>(ECS);
Import<MTextureComponents>(ECS);
Import<MRenderPipelinesComponents>(ECS);
Import<MRenderPrimitivesComponents>(ECS);
// 1. First we run main thread logic before ECS.progress()
// 2. Then we exucute multi-threaded game logic (velocity, attacking) and produce some Events
// [sync] 3. Then we reach the first single-threaded system and enter a sync point (On Add/Set/Destruct Listeners executed)
// 4. Then we reach no_staging system with event queue processor (EventListeners executed)
// [sync] 5. Then we reach multi-threaded rendering systems
// [sync] 6. Then we reach main thread render submitting systems
Impl::MultiThreadedSection([&]() {
/// Logic
Import<MLifespanSystems>(ECS);
Import<MGeometryFluctuationSystems>(ECS);
SetModuleEnabled<MGeometryFluctuationSystems>(ECS, false);
// Update game state debug text.
Import<MGameStateSystems>(ECS);
Import<MAnimationSystems>(ECS);
if constexpr (SE_DEBUG) {
Import<MValidationSystems>(ECS);
}
/// Physics
// Must happen as close to no staging system as possible, because physics thread is getting blocked.
Import<MPhysicsLockSystems>(ECS);
});
Impl::SingleThreadedSection([&]() {
ECS.system("No Staging System").no_staging().iter([](iter &Iter) {
auto ECS = Iter.world();
ECS.defer_end();
Check(!ECS.is_deferred());
Check(!IsDeferredContext(ECS));
// Must happen as close to MPhysicsLockSystems as possible, because physics thread is getting blocked.
Physics::Impl::UnlockAndSchedulePhysics();
Impl::ProcessEventQueue(ECS);
Layout::Impl::RebuildRootNodeLayout(ECS);
Impl::ProcessEventQueue(ECS);
ECS.defer_begin();
});
/// Graphics
Import<MViewSystems>(ECS);
// Buffer changes are single-threaded to avoid locks.
Import<MPrimitiveSystems>(ECS);
Import<MTextureSystems>(ECS);
Import<MLayoutSystems>(ECS);
});
Impl::MultiThreadedSection([&]() {
/// Render cooking
Import<MRenderPrimitivesCookingSystems>(ECS);
Import<MRenderTilesCookingSystems>(ECS);
});
Import<MRenderPrepareSystems>(ECS);
Import<MRenderPrimitivesSubmitSystems>(ECS);
Import<MRenderTilesSubmitSystems>(ECS);
Import<MRenderRootSubmitSystems>(ECS);
Import<MRenderFrameSystems>(ECS);
Import<MRenderCleanupSystems>(ECS);
Import<MCoreSystems>(ECS);
/// World
Import<MGameStateEntities>(ECS);
Import<MRenderTilesEntities>(ECS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment