1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| template<typename ...SYSTEM_CTYPES>
class BaseSystem: public ISystem
{
protected:
using componentTuple_t = std::tuple<SYSTEM_CTYPES&...>;
std::vector<componentTuple_t> m_componentTuples;
public:
explicit BaseSystem() {}
virtual ~BaseSystem() {}
virtual bool addNewComponent(componentTag_t const & tag, BaseComponent* newComponent/*, Other thing ?*/) override final;
template<std::size_t PROCESS_ID, typename CTYPE, typename ...OTHER_CTYPES>
bool processNewComponent(componentTag_t const & tag, BaseComponent* newComponent/*, Other thing ?*/) ;
template<std::size_t PROCESS_ID>
bool processNewComponent(componentTag_t const & tag, BaseComponent* newComponent/*, Other thing ?*/);
// virtual void update() = 0; // implement it in the final system only
};
template<typename ...SYSTEM_CTYPES>
bool BaseSystem<SYSTEM_CTYPES...>::addNewComponent(componentTag_t const & tag, BaseComponent* newComponent)
{
if(processNewComponent<0, SYSTEM_CTYPES...>(tag, newComponent/*, Other thing ?*/))
{
return true;
}
return false;
}
template<typename ...SYSTEM_CTYPES>
template<std::size_t PROCESS_ID, typename CTYPE, typename ...OTHER_CTYPES>
bool BaseSystem<SYSTEM_CTYPES...>::processNewComponent(componentTag_t const & tag, BaseComponent* newComponent/*, Other thing ?*/)
{
DBG_ASSERT(CTYPE::signature != BaseComponent::signature)
DBG_ASSERT(tag != BaseComponent::signature)
if(CTYPE::signature == tag)
{
// do something using PROCESS_ID ( maybe store the new component in a tuple or a vector thanks to PROCESS_ID ?)
return true;
}
else
{
return processNewComponent<PROCESS_ID+1, OTHER_CTYPES...>(tag, newComponent);
}
}
template<typename ...SYSTEM_CTYPES>
template<std::size_t PROCESS_ID>
bool BaseSystem<SYSTEM_CTYPES...>::processNewComponent(componentTag_t const & tag, BaseComponent* newComponent/*, Other thing ?*/)
{
// same as before but used for termination. In this case, no match occurred
// in this case, just return false...
return false;
} |
Partager