SceneManagers as systems in entity system or as a core class used by a system?
Posted
by
Hatoru Hansou
on Game Development
See other posts from Game Development
or by Hatoru Hansou
Published on 2012-12-05T02:54:43Z
Indexed on
2012/12/05
5:33 UTC
Read the original article
Hit count: 330
It seems entity systems are really popular here. Links posted by other users convinced me of the power of such system and I decided to try it. (Well, that and my original code getting messy)
In my project, I originally had a SceneManager class that maintained needed logic and structures to organize the scene (QuadTree, 2D game). Before rendering I call selectRect() and pass the x,y of the camera and the width and height of the screen and then obtain a minimized list containing only visible entities ordered from back to front.
Now with Systems, originally in my first attempt my Render system required to get added all entities it should handle. This may sound like the correct approach but I realized this was not efficient. Trying to optimize It I reused the SceneManager class internally in the Renderer system, but then I realized I needed methods such as selectRect() in others systems too (AI principally) and make the SceneManager accessible globally again.
Currently I converted SceneManager to a system, and ended up with the following interface (only relevant methods):
/// Base system interface
class System
{
public:
virtual void tick (double delta_time) = 0;
// (methods to add and remove entities)
};
typedef std::vector<Entity*> EntitiesVector;
/// Specialized system interface to allow query the scene
class SceneManager: public System
{
public:
virtual EntitiesVector& cull () = 0;
/// Sets the entity to be used as the camera and replaces previous ones.
virtual void setCamera (Entity* entity) = 0;
};
class SceneRenderer // Not a system
{
vitual void render (EntitiesVector& entities) = 0;
};
Also I could not guess how to convert renderers to systems. My game separates logic updates from screen updates, my main class have a tick() method and a render() method that may not be called the same times. In my first attempt renderers were systems but they was saved in a separated manager, updated only in render() and not in tick() like all other systems. I realized that was silly and simply created a SceneRenderer interface and give up about converting them to systems, but that may be for another question.
Then... something does not feel right, isn't it? If I understood correctly a system should not depend on another or even count with another system exposing an specific interface. Each system should care only about its entities, or nodes (as optimization, so they have direct references to relevant components without having to constantly call the component() or getComponent() method of the entity).
© Game Development or respective owner