Jump to content

  • Log In with Google      Sign In   
  • Create Account

simber

Member Since 10 Oct 2012
Offline Last Active Yesterday, 06:42 PM

Posts I've Made

In Topic: Abstract Class Deriving Upwards

20 June 2014 - 02:46 PM

I consider a pointer cast more ugly than a nice typesafe template :) . But static_pointer_cast should work in VS10.

 

My resource system has improved drastically by deviding it to respectively one resource cache by resource type.


In Topic: Good OOP book

18 December 2013 - 07:02 PM

Design Patterns: Elements of Reusable Object-Oriented Software

Clean Code: A Handbook of Agile Software Craftsmanship


In Topic: Component entity system - create from template

02 November 2013 - 11:05 AM


And assuming EntitySpawner knows about all the Component Systems, how do I register a component within a specific system?

In component based entity system, there are systems (or processes) that updates the components, I'm still not sure how I can introduce the needed components to the correct system in an elegant way.

 

You can explicitly add entities to systems like this (assuming Entity is just an identifier):

class System
{
public:
   void add(Entity e);

protected:
   std::vector<Entity> m_entities;
};

// update example
void MoveSystem::update(EntitySpawner& spawner)
{
   for( auto &e : m_entities )
   {
      Position& position = spawner.get<Position>(e);
      Velocity& velocity = spawner.get<Velocity>(e);
      position += velocity;
   }
}

Or you let the system query combinations of Components, no adding needed:

void MoveSystem::update(EntitySpawner& spawner)
{
   std::vector<Entity> entities = spawner.getEntitiesWithComponents<Position, Velocity>();
   for( auto &e : entities )
   {
      Position& position = spawner.get<Position>(e);
      Velocity& velocity = spawner.get<Velocity>(e);
      position += velocity;
   }
   
}

I used EntitySpawner here like you did , which may not be the best name for what it does.

 

These are only two incomplete examples, there are dozens of design possibilities for components and systems. For the second approach I can suggest to have a look at entityx .


In Topic: Component entity system - create from template

01 November 2013 - 10:15 AM

I would do it this way:

std::vector< std::unique_ptr<Component> > prototype;
// ... parse JSON and create/add components to prototype
// store prototype somewhere

// create an entity from prototype
Entity e = createEntity();
for( auto &comp : prototype )
{
   e.attach( comp->clone() );
}

For this approach your components need a virtual clone function. With the use of CRTP u can automatically create it:


class Component
{
public:
   virtual ~Component() { }
   virtual Component* clone() = 0;
};

template <class Derived>
class TComponent : public Component
{
public:
   virtual Component* clone()
   {
      return new Derived(static_cast<Derived const &>(*this));
   }
};

class Position : public TComponent<Position>
{
    ...
};

 


In Topic: Multiple base classes design

11 June 2013 - 07:58 AM

Hello Texus.

 

After a short look in your TGUI code, I think the problem is the Window class.

First: the naming is confusing. In a GUI I expect a window to be a widget. In your case Window is a renderer and should act like a root for your widgets as well. (Thats why it inherits from Group but not from Object)

 

My idea: I would get rid of the Group class and put all its code into GroupObject. Then let window contain a GroupObject named root. (or inherit a RootObject or Desktop etc. from GroupObject)


PARTNERS