Example #1
0
int ETHScriptWrapper::AddEntity(const str_type::string &file, const Vector3 &v3Pos, const float angle, ETHEntity **ppOutEntity,
								const str_type::string &alternativeName, const float scale)
{
	if (WarnIfRunsInMainFunction(GS_L("AddEntity")))
		return -1;

	const str_type::string resourceDirectory = m_provider->GetFileIOHub()->GetResourceDirectory();
	const ETHEntityProperties* props = m_entityCache.Get(file, resourceDirectory + ETHDirectories::GetEntityDirectory(),
														 m_provider->GetFileManager());

	if (!props)
	{
		return -1;
	}

	const float globalScale = m_provider->GetGlobalScaleManager()->GetScale();

	ETHRenderEntity* entity = new ETHRenderEntity(m_provider, *props, angle, scale * globalScale);
	entity->SetOrphanPosition(v3Pos);
	entity->SetAngle(angle);

	if (ppOutEntity)
	{
		entity->AddRef();
		*ppOutEntity = entity;
	}

	return m_pScene->AddEntity(entity, alternativeName);
}
int ETHScriptWrapper::AddEntity(const str_type::string &file, const Vector3 &v3Pos, const float angle, ETHEntity **ppOutEntity,
								const str_type::string &alternativeName, const float scale)
{
	if (WarnIfRunsInMainFunction(GS_L("AddEntity")))
		return -1;

	const ETHEntityProperties* props = m_entityCache.Get(file, m_provider->GetResourcePath() + ETHDirectories::GetEntityPath(),
														 m_provider->GetVideo()->GetFileManager());

	if (!props)
	{
		return -1;
	}

	const float globalScale = m_provider->GetGlobalScaleManager()->GetScale();

	ETHRenderEntity* entity = new ETHRenderEntity(m_provider, *props, angle, scale * globalScale);
	entity->SetOrphanPosition(v3Pos);
	entity->SetAngle(angle);

	if (entity->IsStatic() && entity->IsApplyLight())
	{
		str_type::stringstream ss;
		ss << GS_L("AddEntity - This is a static entity and its lightmap has not been rendered yet. ") << 
			  GS_L("It might be incorrectly lit: ") << m_provider->GetResourcePath() << ETHDirectories::GetEntityPath() << file;
		ShowMessage(ss.str(), ETH_WARNING);
	}

	if (ppOutEntity)
	{
		entity->AddRef();
		*ppOutEntity = entity;
	}

	return m_pScene->AddEntity(entity, alternativeName);
}