3mcd / harmony-ecs Goto Github PK
View Code? Open in Web Editor NEWA small archetypal ECS focused on compatibility and performance
Home Page: https://3mcd.github.io/harmony-ecs
License: MIT License
A small archetypal ECS focused on compatibility and performance
Home Page: https://3mcd.github.io/harmony-ecs
License: MIT License
Enable noImplicitAny
and strict
in tsconfig.json and put the fires out.
Hey @3mcd!
First off, I recently read this blog post and super appreciate the shoutout and that you are also trying to bridge the synchronization gap between SoA and objects. I don't feel so lonely now ๐ . Also, great job implementing archetypes! I still haven't had time to implement those.
Second, I was hoping that you would be willing to weigh in on an alternative way forward for the synchronization of data between SoA and objects that I drafted a short proposal for. As always, my focus is performance ๐๏ธ. I believe this method of synchronization can bring the most performance benefits and provides an extreme level of interoperable flexibility, but I am keen to get a wide variety of opinions on this. Let me know what you think!
Cheers ๐ป
I recently helped port the fantastic prediction/reconciliation algorithm CrystalOrb from Rust to JavaScript. The JS port works very well (see a very rough demo here) but CrystalOrb's current design (see this issue) works best when most game logic is located in the World.step
function. Furthermore, the CrystalOrb client maintains two separate (but complete) simulations, without exposing one as the source of truth for client-only physics (e.g. particle physics).
This design makes it a bit tricky to implement ECS alongside CrystalOrb, since ECS logic is traditionally implemented as small, pure-ish functions (in that they usually only modify a small subset of entities and components), and writing non-predictive code is a bit difficult without implementing an entire command/snapshot/interpolate workflow, or writing similar command logic around the CrystalOrb "protocol".
It would be awesome if Harmony (and eventually Javelin) had support for this kind of predictive algorithm out-of-the-box. I'm dubbing this "Predictive Systems" in the meantime. Of course, currently Harmony doesn't have a concept of systems at all (only entities, components, and queries), but new structures could be introduced with this proposal which cover other best practices for system design and organization outside of netcode.
CrystalOrb does a few things that we can learn from:
Things we'll want to add
New structures and functions to consider
// System is defined like normal, without any notion of prediction
function input(ecs) {
let command: InputCommand
while (command = Command.take(ecs, CommandType.Input)) {
const velocity = Entity.get(ecs, command.entity, Velocity)
if (command.jump) {
velocity.y += 10
}
// ...
Entity.set(ecs, command.entity, Velocity, velocity)
}
}
// On the client, we define a blend function that could interpolate between
// the latest predicted state and previous snapshot
function blend(queryFrom, queryTo, t) {
}
const pipeline = Pipeline.make(
// On the client, a predictive system is configured with one or more
// types to simulate in the future (relative to a server). Queries executed
// within the predictive systems would somehow interact with "overlayed"
// entity tables that shadow the original archetypes
System.makePredictive(input, [Prefabs.Player], [Commands.Input], blend),
System.make(render),
)
// Some built-in commands would provide clock sync instructions and state
// snapshots to the pipeline's state for each predictive system
const commands = Command.makeCommandBuffer()
Pipeline.step(pipeline, world, commands)
// The server will need to generate snapshots at regular intervals and
// send timestamped payloads to the client
Entity relocates are currently slow because most of the code was hurriedly written to get my ideas down. moveToArchetype
and related functions need to be refactored.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.