Page 4 of 5

Re: [Library] tiny-ecs - Fast Simple Entity Component System

Posted: Thu Feb 23, 2017 11:46 am
by Zireael
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...

Re: [Library] tiny-ecs - Fast Simple Entity Component System

Posted: Thu Mar 16, 2017 5:59 pm
by emanevitaerc
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

Posted: Sat Mar 18, 2017 4:56 pm
by bakpakin
Try calling sortedSystem:onModify(). This is called once every time new items are added, and resorts the system.

Re: [Library] tiny-ecs - Fast Simple Entity Component System

Posted: Sat Mar 18, 2017 9:27 pm
by emanevitaerc
bakpakin wrote:
Sat Mar 18, 2017 4:56 pm
Try calling sortedSystem:onModify(). This is called once every time new items are added, and resorts the system.
EDIT: Misread your comment, this does work for my intentions. Thanks!

Re: [Library] tiny-ecs - Fast Simple Entity Component System

Posted: Wed Sep 13, 2017 4:40 am
by HanaIndiana
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!

Re: [Library] tiny-ecs - Fast Simple Entity Component System

Posted: Sun Apr 01, 2018 8:28 pm
by Dr. Peeps
bakpakin wrote:Inactive Systems should be updated manually or not at all via system:update(dt)
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?

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

Posted: Mon Apr 02, 2018 2:24 am
by bakpakin
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.

Re: [Library] tiny-ecs - Fast Simple Entity Component System

Posted: Mon Apr 02, 2018 2:44 am
by Dr. Peeps
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.
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!

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

Posted: Mon Apr 02, 2018 2:47 pm
by bakpakin
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.

Re: [Library] tiny-ecs - Fast Simple Entity Component System

Posted: Thu Apr 05, 2018 11:13 pm
by Dr. Peeps
bakpakin wrote:
Mon Apr 02, 2018 2:24 am
To make sure that nothing is updated during world.update, set system.active to false. You can call system:update(dt) whenever you want.
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.