[Library] tiny-ecs - Fast Simple Entity Component System
Re: [Library] tiny-ecs - Fast Simple Entity Component System
Are the two demos by bakpakin the only examples of how to use it? I wanted to change parts of my existing project to a component structure since I'm having problems with loops/diamond problem when using inheritance...
- emanevitaerc
- Prole
- Posts: 17
- Joined: Sun Mar 13, 2016 7:21 am
Re: [Library] tiny-ecs - Fast Simple Entity Component System
How can I make a sorted processing system re-sort its entities? I'm using one to sort drawn entities by depth to get them in a proper draw order, but it only sorts them once upon their addition, so after their depth changes they stay in the same position in the draw system's entity list.
Re: [Library] tiny-ecs - Fast Simple Entity Component System
Try calling sortedSystem:onModify(). This is called once every time new items are added, and resorts the system.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
- emanevitaerc
- Prole
- Posts: 17
- Joined: Sun Mar 13, 2016 7:21 am
- HanaIndiana
- Prole
- Posts: 12
- Joined: Fri Jul 10, 2015 12:48 am
- Location: Northern CA
- Contact:
Re: [Library] tiny-ecs - Fast Simple Entity Component System
Does anyone have an example of using the world:removeEntity(entity) function? I'm either not using it right, or it's working in a way I'm not expecting. I'm wondering if the system:onRemove(entity) needs to always be included as well. Either way, I'm lost.
The two demos bakpakin has in git (kibbles and weregoat), while helpful, don't use either of these functions.
Here is a short example of one thing I've tried.
If I have an entity called "Word", added to the world like this:
world:add(Word(100,50,assets.lrgfont,"Game Title"))
To remove this entity, would I use this syntax?
world:removeEntity(Word)
I also have a system that uses this Entity, called "WordSystem". And I have a function belonging to this system called:
function WordSystem:onRemove(entity)
But the function doesn't appear to be called when the removeEntity function is used.
Any help is appreciated!
The two demos bakpakin has in git (kibbles and weregoat), while helpful, don't use either of these functions.
Here is a short example of one thing I've tried.
If I have an entity called "Word", added to the world like this:
world:add(Word(100,50,assets.lrgfont,"Game Title"))
To remove this entity, would I use this syntax?
world:removeEntity(Word)
I also have a system that uses this Entity, called "WordSystem". And I have a function belonging to this system called:
function WordSystem:onRemove(entity)
But the function doesn't appear to be called when the removeEntity function is used.
Any help is appreciated!
Re: [Library] tiny-ecs - Fast Simple Entity Component System
Bakpakin, do I understand this correctly, that it's perfectly acceptable to just update each system manually with system:update() and never bother calling world:update() at all?bakpakin wrote:Inactive Systems should be updated manually or not at all via system:update(dt)
This would be preferable in my current project, as each system must process entities at certain times, and some other non-system code must be run between some systems as well.
Thanks!
Re: [Library] tiny-ecs - Fast Simple Entity Component System
Yes, you can do exactly that. You can also run code between other systems by creating a very simple system that processes no entities and simply runs your custom code on update. Not all systems need to process entities. To make sure that nothing is updated during world.update, set system.active to false. You can call system:update(dt) whenever you want.
However, you still need to call world.update put newly added entities into the correct systems and do other book keeping.
However, you still need to call world.update put newly added entities into the correct systems and do other book keeping.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
Re: [Library] tiny-ecs - Fast Simple Entity Component System
Excellent. Thanks for the explanation. I also just realized how the system:pre/postProcess() and system:pre/postWrap() functions work - those are even more appropriate for me in some cases than running code "between systems". (Really, what I needed was that a system do some extra steps after it was done processing entities.) Very flexible!bakpakin wrote: ↑Mon Apr 02, 2018 2:24 am Yes, you can do exactly that. You can also run code between other systems by creating a very simple system that processes no entities and simply runs your custom code on update. Not all systems need to process entities. To make sure that nothing is updated during world.update, set system.active to false. You can call system:update(dt) whenever you want.
However, you still need to call world.update put newly added entities into the correct systems and do other book keeping.
Last question: To get systems to run in an exact order, I just need to call world:setSystemIndex(system, index) and assign a numeric value to each system, correct?
Thanks for providing this library to us, btw! I've found it to be very handy so far.
Re: [Library] tiny-ecs - Fast Simple Entity Component System
Yes, you can modify the order of the systems. However, it is usually easier to set up all of the systems up front in the correct order.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
Re: [Library] tiny-ecs - Fast Simple Entity Component System
Bakpakin, I'm getting some unexpected behaviour in my sorted processing systems when doing the above:
- When I set system.active = false and call system:update() myself, entities are not processed in the correct order.
- When I set system.active = true and call world:update(), entities are processed in the correct order.
Could this be a bug in tiny-ecs when dealing with sorted systems?
EDIT: I should clarify a bit - system:compare() isn't getting called at all when I call system:update() myself.
Who is online
Users browsing this forum: No registered users and 3 guests