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

Author Topic: Looking for EntityManager tutorials or suggestions on how to hangle such manage.  (Read 2649 times)

0 Members and 1 Guest are viewing this topic.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Hello.
Currently i am trying to design a class that would manage all drawing/sprites for each "unit" ingame.
And is that a good way to go if seeking for improved performance? if it is not then what is?

Currently i got idea of something like this
Code: [Select]
class BaseEntity//Each class that wants to be entity has to inherit this
{
int EntityVAPosition;//Vertex array position for destruction or editing
};
class EntityManager
{
public:
void AddEntity(BaseEntity & entity, sf::Vector2f Pos, sf::Vecto2f TexPos);
void RemoveEntity(BaseEntity);
};
The thinking with this is that entities will be added and removed from the VertexArray thus the options are:
1:Reconstruct the whole array each time that is done
2:Have empty holes in VertexArray and keep track of them and when entity is added fill them up.
this will most likely be a vertex array holding first index of empty VertexArray position.
When AddEntity is gonna be called, instead of appending at end its gonna check if(Vector.size > 0) and use the vertexFrom the list instead of expending the VertexArray, i think this will be efficient.

Each entity is gonna be 4Verices and the primitive type used is Quads

That being said, id like to get ideas from a tutorial on Entity manager using sfml.
I went digging but i think the name of what i am looking for is not called "Entity manager".
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
SFML is able to handle a lot of draw calls and since entities are usually relatively rare compared to static objects, it's from my point of view questionable if a vertex array "optimization" would work well. Plus entities are mostly "dynamic", so they are in constant change in one or the other way, so the question is at one point does the "optimization" out-weight the additional overhead and limitation in code creation. A final answer to this reasoning can only be given through an implementation with testing etc. ;)

1:Reconstruct the whole array each time that is done
2:Have empty holes in VertexArray and keep track of them and when entity is added fill them up.
this will most likely be a vertex array holding first index of empty VertexArray position.
You could also think about different data structures/algorithms that operate on an array, e.g. if you sorted the entity vertices based on how long something gets used, thus you could ignore the first part of an array since they'd never get removed etc, but again this needs a lot of thinking, otherwise the overhead will be larger than simply removing stuff.

That being said, id like to get ideas from a tutorial on Entity manager using sfml.
I went digging but i think the name of what i am looking for is not called "Entity manager".
You might also want to look at Component Systems, they are a different approach than the Object Oriented Systems, other than that, entity systems are really an abstract concept of which there are many, many tutorials on the internet. From there it's really not that hard to implement it with SFML, after all SFML is just a toolbox so you can create whatever you imagine. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Keep the logics (entity) and graphics (vertex array) separated. The latter depend on the former, but not vice versa.

class Entity
{
public:
    sf::Vector2f getPosition() const;
};

class EntityRenderer : public sf::Drawable
{
public:
    void addEntity(Entity& e)
    {
        entities.push_back(&e);
        // resize vertices
    };

    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        for (Entity* e : entities)
            // adapt 4 corresponding vertices

        target.draw(vetices, states);
    }

private:
    std::vector<Entity*> entities;
    sf::VertexArray vertices;
};
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
First id like to thank " eXpl0it3r" for the "Component Systems" link that was very helpful.

After a bit of research on this topic i decided, the approach i was gonna take is suiting with what i want to make.
There where allot of changes i had to make in order for it to be efficient/usable, because at end of the day that is what i want, i will code for a long time so i could add stuff with only few clicks wasting minimal time on that part since i enjoy crafting witty code  ;D.
Thank you on the suggestions.
I procrastinated like crazy last 5 months but its time to go... aint getting younger  ;) again thx.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Here is my most loved ECS link: http://t-machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-1/ to a whole article series.
I especially like how the author of it emphasizes that its a leap away from OOP-pattern thinking back to structuring the data table-like.
It got me convinced a SOA way is better as it groups same components to be worked on linearly by one system. Throwing a mess into an entity barrel where then every time you need some component you ask all entities to typecheck all components I think wont work as well.
You may also want to avoid creating an observer-spaghetti-pattern-event-avalanche-generator that some people feel tempted to implement ( not that I think you would ;) ), by instead letting the systems directly operate on component arrays.
« Last Edit: November 26, 2013, 01:12:44 am by wintertime »

 

anything