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

Showcase your libraries, tools and other projects that help your fellow love users.
Zireael
Party member
Posts: 139
Joined: Fri Sep 02, 2016 10:52 am

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

Post 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...
User avatar
emanevitaerc
Prole
Posts: 17
Joined: Sun Mar 13, 2016 7:21 am

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

Post 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.
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

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

Post by bakpakin »

Try calling sortedSystem:onModify(). This is called once every time new items are added, and resorts the system.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
User avatar
emanevitaerc
Prole
Posts: 17
Joined: Sun Mar 13, 2016 7:21 am

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

Post 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!
User avatar
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

Post 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!
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

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

Post 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!
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

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

Post 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.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

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

Post 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.
User avatar
bakpakin
Party member
Posts: 114
Joined: Sun Mar 15, 2015 9:29 am
Location: Boston

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

Post 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.
((_((_CRAYOLA_((_((_> GitHub <_((_((_CRAYOLA_((_(()
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests