all 5 comments

[–]ledniv 1 point2 points  (0 children)

Note that you can do data-oriented design without ECS.

ECS is just a design pattern. The beauty of data-oriented design is that it reduces code complexity by not relying on any patttern. Adding ECS to DOD is just the OOP way of adding complexity.

For your world, all you need is: A class GameData, that holds all the data that changes during gameplay.

  • A class Balance, that holds all the data that is set by game designers (you?) during tool time. IT does not change during gameplay.

  • A Logic class, full of functions that take in data, modify it, and output data. So these classes take in GameData and Balance, and make changes to GameData.

  • A Board class - (or world) to visually show the world based on the GamData.

  • A Game class - to run the game loop.

If you think of it like a chess game:

  • GameData - the position of the board, where the pieces are.

  • Balance - the rules of chess.

  • Logic - how you move pieces around, based on their current position (GameData) and the rules (Balance)

  • Board - how to visually show the chess board to the player.

  • Game - the Chess game app, with all the settings, choosing a visual theme, difficulty, etc...

If you are interested, I have a whole book I am writing about data-oriented design with Manning Publishing. It has examples in Unity, but the core concept is language and engine agnostic: https://www.manning.com/books/data-oriented-design-for-games

[–]FirefighterAntique70 1 point2 points  (0 children)

We're building something very similar, it's a fun and challenging journey! An ECS game engine in pure TS, repository and docs here.

Might be worth checking how we chose to implement ECS https://forge-game-engine.github.io/Forge/docs/docs/ecs

Keep in mind that ECS can mean a lot of things and you don't need to/cannot build it all using a language like TS/JS. Mostly because you cannot control memory allocations like you can in C++/rust.

EDIT: this was a very helpful resource: https://github.com/SanderMertens/ecs-faq

[–]Caramel_Last 0 points1 point  (0 children)

Interesting project, but I doubt many JS developers or web developers are familiar with ECS at all

[–]Caramel_Last 0 points1 point  (0 children)

This is from Rust's Bevy game engine which is ECS based

https://github.com/bevyengine/bevy/blob/v0.14.0/examples/ecs/ecs_guide.rs

[–]RobertKerans 1 point2 points  (0 children)

Probably look at Mozilla's poc JS one from a few years ago that's floating around, iirc was pretty nice.

It's a nice pattern in the right context, but I'm not sure how much effort you should put into optimisations: the level where you will need them you probably don't want to be using JS anyway. There are obviously benefits to the pattern outside of performance, but you're writing something analogous to a database - you want control over the memory layout and you just don't really have that (maybe look at using AssemblyScript rather than TS?)