diff options
Diffstat (limited to 'src/crepe/api')
| -rw-r--r-- | src/crepe/api/GameObject.cpp | 21 | ||||
| -rw-r--r-- | src/crepe/api/GameObject.h | 5 | ||||
| -rw-r--r-- | src/crepe/api/Transform.cpp | 3 | ||||
| -rw-r--r-- | src/crepe/api/Transform.h | 4 | 
4 files changed, 16 insertions, 17 deletions
diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 2592d2d..8a1a235 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -6,20 +6,21 @@  using namespace crepe;  using namespace std; -GameObject::GameObject(uint32_t id, std::string name, std::string tag, -					   Point position, double rotation, double scale) -	: id(id) { +GameObject::GameObject(uint32_t id, std::string name, std::string tag, const Point & position, double rotation, double scale) : id(id) {  	ComponentManager & mgr = ComponentManager::get_instance();  	mgr.add_component<Transform>(this->id, position, rotation, scale);  	mgr.add_component<Metadata>(this->id, name, tag);  } -void GameObject::set_parent(GameObject & parent) { +void GameObject::set_parent(const GameObject & parent) {  	auto & mgr = ComponentManager::get_instance(); -	vector<reference_wrapper<Metadata>> thisMetadata -		= mgr.get_components_by_id<Metadata>(this->id); -	vector<reference_wrapper<Metadata>> parentMetadata -		= mgr.get_components_by_id<Metadata>(parent.id); -	thisMetadata.at(0).get().parent = parent.id; -	parentMetadata.at(0).get().children.push_back(this->id); + +	// set parent on own Metadata component +	vector<reference_wrapper<Metadata>> this_metadata = mgr.get_components_by_id<Metadata>(this->id); +	this_metadata.at(0).get().parent = parent.id; + +	// add own id to children list of parent's Metadata component +	vector<reference_wrapper<Metadata>> parent_metadata = mgr.get_components_by_id<Metadata>(parent.id); +	parent_metadata.at(0).get().children.push_back(this->id);  } + diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index dcd33ad..4c87639 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -9,9 +9,8 @@ namespace crepe {  class GameObject {  public: -	GameObject(uint32_t id, std::string name, std::string tag, Point position, -			   double rotation, double scale); -	void set_parent(GameObject & parent); +	GameObject(uint32_t id, std::string name, std::string tag, const Point & position, double rotation, double scale); +	void set_parent(const GameObject & parent);  	template <typename T, typename... Args>  	T & add_component(Args &&... args); diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index a80aff3..9c9bb06 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -8,11 +8,10 @@  using namespace crepe; -Transform::Transform(uint32_t game_id, Point point, double rot, double scale) +Transform::Transform(uint32_t game_id, const Point & point, double rot, double scale)  	: Component(game_id), position(point), rotation(rot), scale(scale) {  	dbg_trace();  }  Transform::~Transform() { dbg_trace(); } -int Transform::get_instances_max() const { return 1; } diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h index f918115..557061b 100644 --- a/src/crepe/api/Transform.h +++ b/src/crepe/api/Transform.h @@ -14,9 +14,9 @@ class Transform : public Component {  	// works similar (or the same) as those found in GLSL?  public: -	Transform(uint32_t id, Point, double, double); +	Transform(uint32_t id, const Point &, double, double);  	~Transform(); -	int get_instances_max() const; +	virtual int get_instances_max() const { return 1; }  	//! Translation (shift)  	Point position;  	//! Rotation, in radians  |