Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 10 Oct 2012
Offline Last Active Nov 27 2015 12:44 PM

#5228791 Casting Problem

Posted by simber on 13 May 2015 - 08:09 AM

Just a thought about the design: Those InitiationSettings seem to be just a collection of data that is used to initialize the graphics system. And which graphics system is used will be decided at compile time. Your solution uses run-time-polymorphism combined with up-casting and preprocessor switches. I think the run-time switching part is not necessary here, as is the polymorphic class for the init data.


I thought of something like this:

struct InitiationSettings
   std::string title;
   int width;
   int height;
   bool vsync;
   bool fullscreen;

void GraphicsFactory::init(const InitiationSettings& settings)
   oxygine::core::init_desc oxygine_desc;

   //copy over settings to oxygine_desc

But you may have other reasons to use your version, so its just some input, because i don't like putting data into abstract classes :)

#5226176 Why isn't this working (c++ templates)?

Posted by simber on 28 April 2015 - 06:39 PM

template <typename T, size_t MemoryPoolNumElements = 8192, size_t Alignment=16, size_t NumPagesPerMemoryPool = 16, typename T_Size=uint16_t, uint8_t MemoryPoolGroupElementsExp=5, size_t ReserveSize=16>
using Vector = typename MemoryPool<T, MemoryPoolNumElements, Alignment, NumPagesPerMemoryPool, T_Size>::template MultipleObjectsAllocator<MemoryPoolGroupElementsExp>::template Vector < ReserveSize > ;

Does this work? The "typename" in front of MemoryPool is important because you are using an inner type(def) of a templateed:


edited: A and those extra ::template identifiers are important. I found this link which should explain everything.

#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
   virtual ~Component() { }
   virtual Component* clone() = 0;

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

class Position : public TComponent<Position>