#include "baseentity.h"
#include "tier0/platform.h"
#include "tier1/utlstring.h"

CUtlSelfReferencingVector<CBaseEntity*> g_entities;
CUtlVector<CEntityRegistry*> g_RegisteredEntities;

CBaseEntity::CBaseEntity()
{
	glm_mat3_identity(m_matrix);
	glm_vec3_zero(m_position);
	glm_vec3_zero(m_scale);
};
void CBaseEntity::ReadParameter( const char *szName, const char *szValue )
{
	CUtlString name = szName;
	if (name == "origin")
		V_sscanf(szValue, "%f %f %f", &m_position[0], &m_position[1], &m_position[2]);
}

void CBaseEntity::SetPosition( vec3 position )
{
	V_memcpy(m_position, position, sizeof(vec3));
}

void CBaseEntity::SetRotationEuler( vec3 euler )
{

}

void CBaseEntity::SetRotationQuat( vec4 quaternion )
{

}

void CBaseEntity::SetRotationMatrix( mat3 matrix )
{
	V_memcpy(m_matrix, matrix, sizeof(mat3));
}

void CBaseEntity::SetScale( vec3 scale )
{
	V_memcpy(m_scale, scale, sizeof(vec3));
}


CEntityRegistry::CEntityRegistry(const char *szName, const char *szClass, EntityRegistryFn pfn) : 
	m_szName(szName), m_szClass(szClass), m_pfn(pfn), m_pClientfn(0)
{
	g_RegisteredEntities.AppendTail(this);
};


C_EntityRegistry::C_EntityRegistry( const char *szName, ClientEntityRegistryFn pfn )
{
	for (auto &entity: g_RegisteredEntities)
	{
		if (!V_strcmp(entity->m_szClass, szName))
		{
                        entity->m_pClientfn = pfn;
                }
        }
}
