Add variable arg overload of addComponent()
parent
62dc516cf4
commit
188b49e962
|
@ -24,11 +24,20 @@ public:
|
|||
updateGlobalPosition();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<typename T>
|
||||
void addComponent(T *comp) {
|
||||
_components[T::className] = std::unique_ptr<Component>(comp);
|
||||
}
|
||||
|
||||
template<typename T, typename... _Args>
|
||||
inline T *addComponent(_Args&&... __args) {
|
||||
auto ptr = std::make_unique<T>(std::forward<_Args>(__args)...);
|
||||
T *rptr = ptr.get();
|
||||
|
||||
_components[T::className] = std::move(ptr);
|
||||
return rptr;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void recurseComponents(const std::function<bool(T*)> &cb) {
|
||||
auto &name = T::className;
|
||||
|
|
|
@ -19,7 +19,7 @@ int main() {
|
|||
auto root = std::make_shared<Node>();
|
||||
{
|
||||
auto square = std::make_shared<Node>();
|
||||
square->addComponent<MeshDrawComponent>(new MeshDrawComponent(square, shaderProgram));
|
||||
square->addComponent<MeshDrawComponent>(square, shaderProgram);
|
||||
root->addChild(square);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue