<commit_before>#include "Object.h"
#include "../StarComponents.h"
#include "../Components/TransformComponent.h"
#include "../Graphics/GraphicsManager.h"
#include "../Scenes/BaseScene.h"
#include "../Physics/Collision/CollisionManager.h"
#include <algorithm>
#include <typeinfo>

namespace star
{
	Object::Object(void)
		: m_bIsInitialized(false)
		, m_IsVisible(true)
		, m_IsFrozen(false)
		, m_pParentGameObject(nullptr)
		, m_pPathFindComp(nullptr)
		, m_pScene(nullptr)
		, m_pComponents()
		, m_pGarbageComponents()
		, m_pChildren()
		, m_pGarbageChildren()
		, m_Name(_T("Default"))
		, m_CollisionTag(_T("Default"))
	{
		m_pComponents.push_back(new TransformComponent(this));
	}

	Object::~Object(void)
	{
		for(auto comp : m_pComponents)
		{
			delete comp;
		}
		m_pComponents.clear();

		for(auto child : m_pChildren)
		{
			delete child;
		}
		m_pChildren.clear();
	}
	
	Object* Object::GetParent() const
	{
		return (m_pParentGameObject);
	}

	void Object::BaseInitialize()
	{
		if (m_bIsInitialized)
		{
			return;
		}

		Initialize();
		for(auto comp : m_pComponents)
		{
			if(comp && !comp->IsInitialized())
			{
				comp->Initialize();
			}
		}

		for(auto child : m_pChildren)
		{
			if(child && !child->m_bIsInitialized)
			{
				child->BaseInitialize();
			}
		}
		BaseAfterInitialized();
		m_bIsInitialized = true;
	}

	void Object::Initialize()
	{
		//DO nothing, unless a derived class overrides this
	}

	void Object::BaseAfterInitialized()
	{
		AfterInitialized();
	}

	void Object::AfterInitialized()
	{
		//DO nothing, unless a derived class overrides this
	}

	void Object::Update(const Context& context)
	{
		//DO nothing, unless a derived class overrides this
	}
	
	void Object::BaseUpdate(const Context & context)
	{
		CollectGarbage();
		if(!m_IsFrozen)
		{
			Update(context);
			for(auto component : m_pComponents)
			{
				if(component)
				{
					component->BaseUpdate(context);
				}
			}

			for(auto child : m_pChildren)
			{
				if(child)
				{
					child->BaseUpdate(context);
				}
			}
		}
	}

	void Object::Draw()
	{
		//DO nothing, unless a derived class overrides this
	}

	void Object::BaseDraw()
	{
		if(m_IsVisible)
		{
			Draw();
			for(auto component : m_pComponents)
			{
				if(component)
				{
					component->BaseDraw();
				} 
			}

			for(auto child : m_pChildren)
			{
				if(child)
				{
					child->BaseDraw();
				}
			}
		}
	}

	const tstring& Object::GetName() const
	{
		return m_Name;
	}

	void Object::SetName(const tstring& name)
	{
		m_Name = name;
	}

	void Object::AddComponent(BaseComponent *pComponent)
	{
		bool isValid(true);
		for(auto comp : m_pComponents)
		{
			if(typeid(*comp) == typeid(*pComponent))
			{
				isValid = false;
				break;
			}
		}

		ASSERT(isValid, _T("Adding 2 components of the same type to the same object is illegal."));

		if(isValid)
		{
			pComponent->SetParent(this);

			if(m_bIsInitialized && ! pComponent->IsInitialized())
			{
				pComponent->Initialize();
			}

			m_pComponents.push_back(pComponent);
		}
	}	

	void Object::AddChild(Object *pChild)<commit_msg>Cleaned up some code<commit_after>#include "Object.h"
#include "../StarComponents.h"
#include "../Components/TransformComponent.h"
#include "../Graphics/GraphicsManager.h"
#include "../Scenes/BaseScene.h"
#include "../Physics/Collision/CollisionManager.h"
#include <algorithm>
#include <typeinfo>

namespace star
{
	Object::Object(void)
		: m_bIsInitialized(false)
		, m_IsVisible(true)
		, m_IsFrozen(false)
		, m_pParentGameObject(nullptr)
		, m_pPathFindComp(nullptr)
		, m_pScene(nullptr)
		, m_pComponents()
		, m_pGarbageComponents()
		, m_pChildren()
		, m_pGarbageChildren()
		, m_Name(_T("Default"))
		, m_CollisionTag(_T("Default"))
	{
		m_pComponents.push_back(new TransformComponent(this));
	}

	Object::~Object(void)
	{
		for(auto comp : m_pComponents)
		{
			delete comp;
		}
		m_pComponents.clear();

		for(auto child : m_pChildren)
		{
			delete child;
		}
		m_pChildren.clear();
	}
	
	Object* Object::GetParent() const
	{
		return (m_pParentGameObject);
	}

	void Object::BaseInitialize()
	{
		if (m_bIsInitialized)
		{
			return;
		}

		Initialize();
		for(auto comp : m_pComponents)
		{
			if(comp && !comp->IsInitialized())
			{
				comp->Initialize();
			}
		}

		for(auto child : m_pChildren)
		{
			if(child && !child->m_bIsInitialized)
			{
				child->BaseInitialize();
			}
		}
		BaseAfterInitialized();
		m_bIsInitialized = true;
	}

	void Object::Initialize()
	{
		//DO nothing, unless a derived class overrides this
	}

	void Object::BaseAfterInitialized()
	{
		AfterInitialized();
	}

	void Object::AfterInitialized()
	{
		//DO nothing, unless a derived class overrides this
	}

	void Object::Update(const Context& context)
	{
		//DO nothing, unless a derived class overrides this
	}
	
	void Object::BaseUpdate(const Context & context)
	{
		CollectGarbage();
		if(!m_IsFrozen)
		{
			Update(context);
			for(auto component : m_pComponents)
			{
				if(component)
				{
					component->BaseUpdate(context);
				}
			}

			for(auto child : m_pChildren)
			{
				if(child)
				{
					child->BaseUpdate(context);
				}
			}
		}
	}

	void Object::Draw()
	{
		//DO nothing, unless a derived class overrides this
	}

	void Object::BaseDraw()
	{
		if(m_IsVisible)
		{
			Draw();
			for(auto component : m_pComponents)
			{
				if(component)
				{
					component->BaseDraw();
				} 
			}

			for(auto child : m_pChildren)
			{
				if(child)
				{
					child->BaseDraw();
				}
			}
		}
	}

	const tstring& Object::GetName() const
	{
		return m_Name;
	}

	void Object::SetName(const tstring& name)
	{
		m_Name = name;
	}

	void Object::AddComponent(BaseComponent *pComponent)
	{
		for(auto comp : m_pComponents)
		{
			ASSERT(typeid(*comp) != typeid(*pComponent), 
				_T("Object::AddComponent: \
				   Adding 2 components of the same type to the same object is illegal."));
		}

		pComponent->SetParent(this);

		if(m_bIsInitialized && ! pComponent->IsInitialized())
		{
			pComponent->Initialize();
		}

		m_pComponents.push_back(pComponent);
	}	

	void Object::AddChild(Object *pChild)
{'fraction_non_alphanumeric': 0.1394736842105263, 'fraction_numerical': 0.0003289473684210526, 'mean_word_length': 3.3560171919770774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '647792', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2211, 'n_words': 388}