HooECS, the wise choice!

Showcase your libraries, tools and other projects that help your fellow love users.
Fuzzlix
Citizen
Posts: 53
Joined: Thu Oct 13, 2016 5:36 pm

Re: HooECS, the wise choice!

Post by Fuzzlix » 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. ;-)

User avatar
erasio
Citizen
Posts: 91
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: HooECS, the wise choice!

Post by erasio » Sun Nov 05, 2017 10:20 am

Fuzzlix wrote:
Sat Nov 04, 2017 8:43 pm
erasio wrote:
Sat Nov 04, 2017 6:36 pm
The entity list is not intended as array list. But as unique identifier. It's used with pairs across the core code. Users are not expected to use the ID or entity list directly.
Thats all true. But HooECS uses this list internally to calculate the next free ID.
erasio wrote:
Sat Nov 04, 2017 6:36 pm
But I don't think that's a serious issue. Especially not a deal breaking one ;)
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?
Oh snap! I totally overlooked that part of lovetoys!

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!
Fuzzlix wrote:
Sat Nov 04, 2017 10:43 pm
in EventManager.lua:

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
The test should be:

Code: Select all

if registeredListener[1].class == listener.class then
Since listener here is a string parameter provided by the user when calling the function. The key "listener.class" can not possibly exist.

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.
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 :)
There is a demo project available in the docs!

I've added a second, more basic one just now too!

More complex lovetoys example (100% compatible)

Minimal example
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. ;-)
You are absolutely right. I had to force myself to use it initially and getting behind takes some time.

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.

Fuzzlix
Citizen
Posts: 53
Joined: Thu Oct 13, 2016 5:36 pm

Re: HooECS, the wise choice!

Post by Fuzzlix » Wed Nov 15, 2017 9:43 pm

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.
Attachments
ecs.lua
(32 KiB) Downloaded 8 times

User avatar
erasio
Citizen
Posts: 91
Joined: Wed Mar 15, 2017 8:52 am
Location: Germany

Re: HooECS, the wise choice!

Post by erasio » Thu Nov 16, 2017 8:35 am

I'll take a look. Thanks for sharing!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests