• Content count

  • Joined

  • Last visited

Community Reputation

931 Good

About TheAngryPlatypus

  • Rank
  1. Learning C++11

    You might want to look into the std algorithms (include <algorithm> and <numeric>). That stuff can eliminate a lot of for-loops and it works on vectors sets, lists etc. all the same way. For your example it would look like this: #include <vector> #include <set> #include <numeric> #include <iostream> int main() { std::vector<int> v{1, 3, 5, 7, 11}; // the vector sum using accumulate from <numeric> header. std::cout << std::accumulate(v.begin(), v.end(), 0) << std::endl; std::set<int> s{1, 3, 5, 7, 11}; // same function for the set. std::cout << std::accumulate(s.begin(), s.end(), 0) << std::endl; return 0; }
  2. Casting Problem

    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 :)
  3. Why isn't this working (c++ templates)?

    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.
  4. Perspective projections in LH and RH systems

    Calculation for projection matrix in the table DirectX RH the denominator for factors C and E has to be (n - f) not (f - n).
  5. Abstract Class Deriving Upwards

    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.
  6. Good OOP book

    Design Patterns: Elements of Reusable Object-Oriented Software Clean Code: A Handbook of Agile Software Craftsmanship
  7.   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 .
  8. 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> { ... };  
  9. Multiple base classes design

    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)