kick
/Users/morten/Programmering/cpp/kick/src/kick/scene/game_object.h
00001 //
00002 //  GameObject.h
00003 //  KickCPP
00004 //
00005 //  Created by Morten Nobel-Jørgensen on 5/21/13.
00006 //  Copyright (c) 2013 Morten Nobel-Joergensen. All rights reserved.
00007 //
00008 
00009 #pragma once
00010 
00011 #include <iostream>
00012 #include <string>
00013 #include <vector>
00014 #include <functional>
00015 #include <memory>
00016 #include "kick/scene/component.h"
00017 #include "kick/scene/transform.h"
00018 #include "kick/core/event.h"
00019 
00020 
00021 namespace kick {
00022     class Scene;
00023     
00024     class GameObject {
00025     public:
00026         GameObject(const GameObject& other);
00027         GameObject(GameObject&& other);
00028         GameObject& operator=(GameObject&& other);
00029         ~GameObject();
00030         template <typename C, typename... T>
00031         std::shared_ptr<C> addComponent(T... t);
00032         template <typename C>
00033         std::shared_ptr<C> component();
00034         template <typename C>
00035         std::vector<std::shared_ptr<C>> components();
00036         template <typename C>
00037         std::shared_ptr<C> componentInParent();
00038         template <typename C>
00039         std::vector<std::shared_ptr<C>> componentsInParent();
00040         template <typename C>
00041         std::shared_ptr<C> componentInChildren();
00042         template <typename C>
00043         std::vector<std::shared_ptr<C>> componentsInChildren();
00044         bool destroyComponent(std::shared_ptr<Component> component);
00045         ConstComponentIter begin() const;
00046         ConstComponentIter end() const;
00047         ComponentIter begin();
00048         ComponentIter end();
00049         Event<std::pair<std::shared_ptr<Component>, ComponentUpdateStatus>> componentEvent;
00050         std::string name() const;
00051         void setName(std::string str);
00052 
00053         std::shared_ptr<Transform> transform(){ return mTransform; }
00054         
00055         Scene* scene(){ return mScene; }
00056 
00057         int layer() const;
00058         void setLayer(int layer);
00059         friend class Scene;
00060 
00061         int32_t uniqueId();
00062     private:
00063         GameObject(const std::string &name, Scene *scene, int uniqueId);
00064         Scene *mScene;
00065         int mUniqueId;
00066         std::string mName;
00067         int mLayer = 1;
00068         bool mDestroyed = false;
00069         std::vector<std::shared_ptr<Component>> mComponents;
00070         std::vector<std::shared_ptr<Component>> newComponents;
00071         std::vector<std::function<void (std::shared_ptr<Component>, ComponentUpdateStatus)>> componentListeners;
00072         std::shared_ptr<Transform> mTransform;
00073     };
00074 };
00075 
00076 #include "game_object.inl"
 All Classes Functions Variables