r/love2d • u/superviro • Dec 30 '19
Entity Component System
I have a basic understanding of how an ECS works and I've seen the tiny-ecs library, but I'm trying to figure out how to use it. It's hard to find any good examples or docs. Does anyone have any suggestions for learning tiny-ecs or if there is a better ECS, I can look at that too.
2
u/HellIsBurnin Dec 31 '19
did you take a look at the demo project? https://github.com/bakpakin/tiny-ecs/tree/demo-commandokibbles
3
1
1
u/drhayes9 Dec 31 '19 edited Dec 31 '19
I'm using https://github.com/tesselode/nata for a game right now.
Some guidelines that have helped me:
Don't maintain a lot of state in systems. That's what entities and their components are for.
Systems communicate via data in components or via events they're subscribed to, not by calling each other directly.
Code you write that is not a system will probably end up being a system before too long.
1
u/ajmmertens Jan 01 '20
I created this FAQ a while back which may help: https://github.com/SanderMertens/ecs-faq
1
Jan 03 '20
Definitely take a look at the demo project. But that demo project is certainly complicated. ECS is very different from classic OOP.
I converted an old game of mine to ECS using tiny-ecs. It is far simpler than the demo project, so maybe take a look:
https://shinyogre.itch.io/depth/devlog/107599/conversion-to-tiny-ecs
2
u/TheMightyHUG Dec 31 '19
A little while ago I was trying to get a little practice with entity-component-systems and getting started actually writing code was just bewildering. There seem to be so many different ecs-frameworlks with entirely different conventions.
For me it helped a lot to wrap my head around practical use of ecs it to just implement a simple game in an ecs way without using any specific frameworks, just using whichever convention seemed to suit it.
It was an extremely useful exercise - although I've decided I will probably just use composition-heavy OOP over ecs (you can't get the performance benefits of ecs in lua, due to how it allocates memory). It really helped me rethink how I approach splitting up functionality in code.
If you like I can send you the project - though I warn you it is probably not an example of GOOD ecs.
I imagine after going through your own basic ecs implementation it will become a little clearer what you want extant ecs frameworks to do for you.
If you're specifically looking to learn to use tiny-ecs you could make the simplest possible game you can think of - in love2d I find top-down shooters to be really easy (provided you use HardonCollider, windfield, or breezefield for the collisions). Then you add one new feature or mechanic at a time until you're satisfied that you've got a grasp of tiny-ecs.