Jump to content

  • Log In with Google      Sign In   
  • Create Account

simber

Member Since 10 Oct 2012
Offline Last Active Jul 26 2016 12:45 PM

Posts I've Made

In Topic: Casting Problem

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)
{
#ifdef USE_OXYGINE_RENDERING
   oxygine::core::init_desc oxygine_desc;

   //copy over settings to oxygine_desc
   
   oxygine::core::init(&oxygine_desc);
#endif
}

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 :)


In Topic: Why isn't this working (c++ templates)?

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.


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 .


PARTNERS