Jump to content

  • Log In with Google      Sign In   
  • Create Account

simber

Member Since 10 Oct 2012
Offline Last Active Dec 21 2014 06:42 PM

#5161797 Abstract Class Deriving Upwards

Posted by simber on 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.




#5117992 Good OOP book

Posted by simber on 18 December 2013 - 07:02 PM

Design Patterns: Elements of Reusable Object-Oriented Software

Clean Code: A Handbook of Agile Software Craftsmanship




#5106268 Component entity system - create from template

Posted by simber on 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>
{
    ...
};

 




PARTNERS