Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualMadhed

Posted 12 May 2013 - 06:13 AM

The goal is for every component system contain the components without having to define the std::map and accessory methods in every system. That is 100's of lines of cut and paste for every component system (create_component(), component_exists(), etc).

,>

 

Ah okay, seems I haven't had enough coffee yet. biggrin.png

But why would you need the upcast to the base system? Could you derive base system from a type agnostic interface that has create_component etc. return the base component type and then downcast that if you need to?

 

// Pseudocode

interface BaseComponentSystem {
    BaseComponent* createComponent();
    bool hasComponent(id componentId);
}

class SpecialComponentSystem<T> : public BaseComponentSystem {
    map<int, T> components;
    BaseComponent* createComponent() {
        return components.add(generateID(), new T());
    }
    // ...
}

#1Madhed

Posted 12 May 2013 - 06:11 AM

The goal is for every component system contain the components without having to define the std::map and accessory methods in every system. That is 100's of lines of cut and paste for every component system (create_component(), component_exists(), etc).

,>

 

Ah okay, seems I haven't had enough coffee yet. biggrin.png

But why would you need the upcast to the base system? Could you derive base system from a type agnostic interface that has create_component etc. return the base component type and then downcast that if you need to?

 

// Pseudocode

interface BaseComponentSystem {
    BaseComponent* createComponent();
    bool hasComponent(id componentId);
}

class SpecialComponentSystem<T> : public IComponentSystem {
    map<int, T> components;
    BaseComponent* createComponent() {
        return components.add(generateID(), new T());
    }
    // ...
}

PARTNERS