ECS is a great concept in theory. I suggest you read the blog post mentioned in lovetoys/HooECS's readme.
After reading this really informative blog post i started a learning project using HooECS/lovetoys 3 weeks ago.
(I still mention lovetoys when talking about HooECS, because i dont want to blame HooECS for the bugs imported from lovetoys. lovetoys is still beta in best case.)
If you are a "bloody" Löve beginner, it may be better to avoid ECS in the first place. I try 3 weeks now to reimplement a already half done game using ECS and i make slow process. Maybe i am too old and/or too fixed in old coding habits. ;-)
HooECS, the wise choice!
Re: HooECS, the wise choice!
Oh snap! I totally overlooked that part of lovetoys!Fuzzlix wrote: ↑Sat Nov 04, 2017 8:43 pmThats all true. But HooECS uses this list internally to calculate the next free ID.Depending on the real use case the "#" operator may give back (in rare situations) false results.
There are 2 solutions:
1. use a static counter and increment this counter each new addEntity()
2. use the entity itself as ID like "entity.id = entity"
This make sense?
Truth be told it probably works out alright due to how arrays work in lua. But it can create issues in specific cases when creating the list this way. (By which I mean initializing a holeless array and inserting holes later on will return the full list length in most cases).
But it can create issues in other cases.
I'm on it!
Since listener here is a string parameter provided by the user when calling the function. The key "listener.class" can not possibly exist.Fuzzlix wrote: ↑Sat Nov 04, 2017 10:43 pm in EventManager.lua:The test should be:Code: Select all
function EventManager:removeListener(eventName, listener) if self.eventListeners[eventName] then for key, registeredListener in pairs(self.eventListeners[eventName]) do if registeredListener[1].class.name == listener then -- << BUG! table.remove(self.eventListeners[eventName], key) return end end ... end ... end
Code: Select all
if registeredListener[1].class == listener.class then
This function has tests written for it which verifies correct behavior by comparing the list of events and making sure removal results in the removal of the listener function.
The naming might not be ideal. But the code works.
There is a demo project available in the docs!yetneverdone wrote: ↑Sat Nov 04, 2017 10:48 pm I suggest that a source code be available on how to use this library in an actual game would really help beginners (or like me, who is unfamiliar/inexperienced) with this system. Like just a simple pong or snake game would really do![]()
I've added a second, more basic one just now too!
More complex lovetoys example (100% compatible)
Minimal example
You are absolutely right. I had to force myself to use it initially and getting behind takes some time.Fuzzlix wrote: ↑Sun Nov 05, 2017 7:20 am ECS is a great concept in theory. I suggest you read the blog post mentioned in lovetoys/HooECS's readme.
After reading this really informative blog post i started a learning project using HooECS/lovetoys 3 weeks ago.
(I still mention lovetoys when talking about HooECS, because i dont want to blame HooECS for the bugs imported from lovetoys. lovetoys is still beta in best case.)
If you are a "bloody" Löve beginner, it may be better to avoid ECS in the first place. I try 3 weeks now to reimplement a already half done game using ECS and i make slow process. Maybe i am too old and/or too fixed in old coding habits. ;-)
But I've come to love it. The way you separate functionality and can operate on your data is just neatly organized and separated without jumping around in code to find where events are picked up and what class manages which functionality.
Re: HooECS, the wise choice!
Hi erasio.
Meanwhile i modified HooEcs so heaviely, so i cant send you pull requests for HooECS.
- I implemented some gamestate management: 3 events and some changes in the System class.
- I circumvented the issue in the eventmanager we talked about by using the instance itself as table key.
- Systems are singleton instances of system sub classes.
- Engine is a singleton and become started automatically.
- new bookkeeping for components and systems and events.( ecs.component.<name>, ecs.system.<name>, ecs.event.<name>)
- 3 types of components:
* normal component as in HooECS
* Flags: singletons without Values
* globals: singleton components with values.
- The entire ecs lib is in a single file.
I did not stick on the lovetoys api and changed a few things as i needed. Maybe you find some useful ideas /code snippets good enouth for HooECS.
Meanwhile i modified HooEcs so heaviely, so i cant send you pull requests for HooECS.
- I implemented some gamestate management: 3 events and some changes in the System class.
- I circumvented the issue in the eventmanager we talked about by using the instance itself as table key.
- Systems are singleton instances of system sub classes.
- Engine is a singleton and become started automatically.
- new bookkeeping for components and systems and events.( ecs.component.<name>, ecs.system.<name>, ecs.event.<name>)
- 3 types of components:
* normal component as in HooECS
* Flags: singletons without Values
* globals: singleton components with values.
- The entire ecs lib is in a single file.
I did not stick on the lovetoys api and changed a few things as i needed. Maybe you find some useful ideas /code snippets good enouth for HooECS.
- Attachments
-
- ecs.lua
- (32 KiB) Downloaded 156 times
Re: HooECS, the wise choice!
I'll take a look. Thanks for sharing!
Who is online
Users browsing this forum: No registered users and 6 guests