ecs: type safety & message passing systems exploration #381
No reviewers
Labels
No labels
CI
all
basisu
blog
bug
build
contributor-friendly
core
correctness
deferred
dev
direct3d-headers
docs
driver-os-issue
duplicate
dxcompiler
editor
examples
experiment
feature-idea
feedback
flac
freetype
gamemode
gkurve
glfw
gpu
gpu-dawn
harfbuzz
help welcome
in-progress
infrastructure
invalid
libmach
linux-audio-headers
long-term
mach
mach.gfx
mach.math
mach.physics
mach.testing
model3d
needs-triage
object
opengl-headers
opus
os/linux
os/macos
os/wasm
os/windows
package-manager
priority
proposal
proposal-accepted
question
roadmap
slipped
stability
sysaudio
sysgpu
sysjs
validating-fix
vulkan-zig-generated
wayland-headers
website
wontfix
wrench
www
x11-headers
xcode-frameworks
zig-update
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
hexops/mach!381
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "sg/ecs-type-safety"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Best reviewed with whitespace hidden.
This PR causes our ECS to be type-safe (the type safety here is mostly fully baked), and begin exploring message passing (this part is super early stages.)
Type safety
This implements the type safety described in https://github.com/hexops/mach/pull/349 where you define head of time as part of an ECS module what components you are defining. Then you may add/remove those components, or components from any other ECS module, to entities in the world at your choosing. The ECS world has a complete picture of all potential component types that will be used, and can thus enforce you are using the right type at comptime.
Message passing
This is exploratory, the thought process is that message passing between systems could be both a nice way of allowing systems to communicate with each-other (you'll have to use your imagination for why that would be useful) as well as scheduling when systems run.
The engine could send a tick message to all systems per frame (your classical system run schedule); you could ask the engine to send an event at a specific schedule (systems that run faster/slower than the frame rate); the engine could send user input events as messages (so you can have systems that only run when user input events become available); etc
sending a message is just directly calling the system currently (so literally a function call with a tagged union.) General thinking is the closer to that we remain the better, as it'd be good to avoid any overhead of storing messages. But multi-threading is a really important aspect here, I will potentially explore introducing async into the mix
I also haven't thought out how to namespace messages yet, there is clearly a need for some global messages (tick etc.) and namespaced messages
Observability
the nice thing w.r.t. observability (assuming you can get deterministic messaging) is you could record all messages and then you have a clear linear path of execution for every action in the ECS, rather than what appear to be disjointed systems across multiple ticks talking to eachother via messages shuffled into the ECS data as components
Networking
one aspect I haven't really thought of, but believe is true, is how message passing could potentially enable some quite nice networking code. An ECS system talking to a server could literally be just one system (e.g. player controller) sending messages to another system (the client system or something)
State of messaging
my plan is to explore it more, merge now and continue iterating on it, but not commit to it fully yet (i.e. if it turns out to be bad for multithreading systems, we may have to rip it out)