Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: zmcEntitySystem - A Component-Entity System  (Read 3767 times)

0 Members and 2 Guests are viewing this topic.

Furkanzmc

  • Newbie
  • *
  • Posts: 13
    • View Profile
zmcEntitySystem - A Component-Entity System
« on: March 27, 2014, 06:27:33 pm »
Hello guys. After getting into game development I started learning the principles and Component-Entity system is next in line. After reading articles and researching other systems I came up with this implementation of Component-Entity System and it's based on Artemis Entity System Framework. If you have time to have a look at it, I'd really appreciate your feedback. - https://github.com/Furkanzmc/zmcEntitySystem
« Last Edit: March 27, 2014, 06:29:18 pm by Furkanzmc »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: zmcEntitySystem - A Component-Entity System
« Reply #1 on: March 27, 2014, 07:24:24 pm »
Hi

Could you quickly describe the rough design and maybe show how it can be used?

Some random comments about the code:

    E* createEntity(int groupIdentifier)
    {
        std::unique_ptr<BaseEntity> entity(new E());
        entity->setEntityID(mLastEntityID++);
        entity->setGroup(groupIdentifier);
        entity->setComponentManager(mComponentManager);
        mEntityMap.insert(std::make_pair(mLastEntityID , std::move(entity)));
        return dynamic_cast<E*>(mEntityMap.at(mLastEntityID).get());
    }
Avoid dynamic_cast, it's almost always a design mistake. Here, it's completely unnecessary; you could just store std::unique_ptr<E> and then use the derived-to-base conversion when inserting it to the map. In the other cases, you should rather assert that the dynamic type is correct and then use static_cast in release mode. Logic errors like expecting the wrong type must be recognized immediately, don't hide them by returning a null pointer.

You don't adhere to the Rule Of Three.

A lot of functions are virtual although they needn't be. In EntityBase, most functions are only accessors to the attributes, why override them?

I would make the protected member variables private. It improves encapsulation and allows to modify the base class without breaking client code.

It's nice that you use RAII (smart pointers and STL containers) to store the objects. For shared_ptr, make sure it's really necessary and you don't copy it too often (pass by reference). Also use make_shared() where possible.

Get functions should be const-qualified.

Constructors taking a single element should be explicit, unless conversion is desired.

How do you ensure uniqueness of the integer IDs for entities, groups or component types? I could imagine that this could become a type-safety and scalability problem in a bigger project. An option would be opaque and typesafe handles (i.e. objects hiding the int internally), that your library gives to the user.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: zmcEntitySystem - A Component-Entity System
« Reply #2 on: March 27, 2014, 07:56:14 pm »
Funny, I've been working on a similar system :D Yours looks promising, also similar to other already existing entity systems :D

Furkanzmc

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: zmcEntitySystem - A Component-Entity System
« Reply #3 on: April 02, 2014, 07:33:15 pm »
Hello. Thank you so much for your feedback. I did correct the things you mentioned and wrote a blog post about it and how to use it. I'm particularly new to blogging so I hope it's a good one! :D

Blog post:
http://furkanzmc.blogspot.com.tr/2014/04/entitycomponent-system-written-in-c.html

eigenbom

  • Full Member
  • ***
  • Posts: 228
    • View Profile
Re: zmcEntitySystem - A Component-Entity System
« Reply #4 on: April 03, 2014, 12:39:59 am »
Some quick points:
You can remove the components enum by using crtp pattern on components.
Inheriting ship from entity seems to go against the whole idea. Instead a ship component that you add to an entity would be the standard way. (Not that there's any "right" way.)
Here's a blog post on my own system, which I use for my game: http://bp.io/post/1617

Furkanzmc

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: zmcEntitySystem - A Component-Entity System
« Reply #5 on: April 03, 2014, 03:05:56 pm »
You are right. I knew I should have done it that way but I had something different in my mind and never really reconsidered it after making it. Now that you mentioned it, I did it the way it's supposed to be done. Thank you for your feedback!

EDIT: I'll update the blog post...
EDIT 2: I update the blog post.
« Last Edit: April 03, 2014, 03:19:00 pm by Furkanzmc »

 

anything