void ETHActiveEntityHandler::TestEntityLists() const
{
	for (std::list<ETHRenderEntity*>::const_iterator a = m_dynamicOrTempEntities.begin(); a != m_dynamicOrTempEntities.end(); ++a)
	{
		for (std::list<ETHRenderEntity*>::const_iterator b = m_lastFrameCallbacks.begin(); b != m_lastFrameCallbacks.end(); ++b)
		{
			ETHRenderEntity* entityA = (*a);
			ETHRenderEntity* entityB = (*b);
			const int idA = entityA->GetID();
			const int idB = entityB->GetID();
			bool idAssert;
			idAssert = (idA != idB);
			assert(idAssert);
		}
	}
}
Esempio n. 2
0
// moves an entity from a bucket to another
bool ETHBucketManager::MoveEntity(const int id, const Vector2 &currentBucket, const Vector2 &destBucket)
{
    // if the destiny bucket is the current bucket, don't need to do anything
    if (currentBucket == destBucket)
        return true;

    // remove the entity from its current bucket
    ETHBucketMap::iterator bucketIter = Find(currentBucket);

    if (bucketIter == GetLastBucket())
    {
        ETH_STREAM_DECL(ss) << GS_L("The current bucket doesn't exist: (") << currentBucket.x << GS_L(",") << currentBucket.y << GS_L(")");
        m_provider->Log(ss.str(), Platform::Logger::ERROR);
        return false;
    }

    ETHRenderEntity* entity = 0;
    ETHEntityList& entityList = bucketIter->second;
    for (ETHEntityList::iterator iter = entityList.begin(); iter != entityList.end(); ++iter)
    {
        if ((*iter)->GetID() == id)
        {
            entity = *iter;
            entityList.erase(iter);
            break;
        }
    }

    // if the entity hasn't been found
    if (!entity)
    {
        ETH_STREAM_DECL(ss) << GS_L("Couldn't find entity ID ") << id << GS_L(" to move");
        m_provider->Log(ss.str(), Platform::Logger::ERROR);
        return false;
    }

    // adds the entity to the destiny bucket
    if (entity->GetType() == ETHEntityProperties::ET_HORIZONTAL)
    {
        m_entities[destBucket].push_front(entity);
    }
    else
    {
        m_entities[destBucket].push_back(entity);
    }

#if defined(_DEBUG) || defined(DEBUG)
    ETH_STREAM_DECL(ss)
            << entity->GetEntityName() << GS_L("(") << entity->GetID() << GS_L(")")
            << GS_L(" moved from bucket (") << currentBucket.x << GS_L(",") << currentBucket.y << GS_L(") to bucket (")
            << destBucket.x << GS_L(",") << destBucket.y << GS_L(")");
    m_provider->Log(ss.str(), Platform::Logger::INFO);
#endif
    return true;
}
void ETHTempEntityHandler::CheckTemporaryEntities(const Vector2& zAxisDir, ETHBucketManager& buckets, const unsigned long lastFrameElapsedTime)
{
	#ifdef _DEBUG
	TestEntityLists();
	#endif

	for (std::list<ETHRenderEntity*>::iterator iter = m_dynamicOrTempEntities.begin(); iter != m_dynamicOrTempEntities.end();)
	{
		ETHRenderEntity* pRenderEntity = *iter;

		pRenderEntity->Update(lastFrameElapsedTime, zAxisDir, buckets);

		// if the particle system is finished, erase it
		if ((pRenderEntity->IsTemporary() && pRenderEntity->AreParticlesOver()))
		{
			const Vector2 v2Bucket = ETHGlobal::GetBucket(pRenderEntity->GetPositionXY(), buckets.GetBucketSize());
			ETHBucketMap::iterator bucketIter = buckets.Find(v2Bucket);

			if (bucketIter == buckets.GetLastBucket())
			{
				iter++;
				continue;
			}

			// Remove from main bucket map
			buckets.DeleteEntity(pRenderEntity->GetID(), v2Bucket, false);

			#ifdef _DEBUG
			ETH_STREAM_DECL(ss) << GS_L("Entity ") << (*iter)->GetEntityName() << GS_L(" (ID#") << pRenderEntity->GetID() << GS_L(") removed from dynamic entity list (particle effects over)");
			m_provider->Log(ss.str(), Platform::Logger::INFO);
			#endif
			(*iter)->Release();
			iter = m_dynamicOrTempEntities.erase(iter);
			continue;
		}
		iter++;
	}
}
Esempio n. 4
0
bool ETHScene::GenerateLightmaps(const int id)
{
	if (!m_provider->IsRichLightingEnabled())
	{
		return false;
	}

	// save current global scale and temporarily set it to 1
	const ETHGlobalScaleManagerPtr& scaleManager = m_provider->GetGlobalScaleManager();
	const float globalScale = scaleManager->GetScale();
	scaleManager->SetScaleFactor(1.0f);

	const ETHSpriteEntity *pRender = (id >= 0) ? m_buckets.SeekEntity(id) : 0;
	const Vector2 v2Bucket = (pRender) ? ETHBucketManager::GetBucket(pRender->GetPositionXY(), GetBucketSize()) : Vector2(0,0);

	for (ETHBucketMap::iterator bucketIter = m_buckets.GetFirstBucket(); bucketIter != m_buckets.GetLastBucket(); ++bucketIter)
	{
		// if we're lighting only one entity and it is not in this bucket, skip it.
		// I know we could have used the find method to go directly to that bucket
		// but this function os not that critical to make the effort worth it.
		if (id >= 0) 
			if (v2Bucket != bucketIter->first)
				continue;

		// iterate over all entities in this bucket
		ETHEntityList& entityList = bucketIter->second;
		ETHEntityList::const_iterator iEnd = entityList.end();
		for (ETHEntityList::iterator iter = entityList.begin(); iter != iEnd; ++iter)
		{
			ETHRenderEntity* entity = (*iter);
			// if nID is valid, let's try to generate the lightmap for this one and only entity
			if (id >= 0)
				if (id != entity->GetID())
					continue;

			Vector2 v2Size(1,1);
			Vector2 v2AbsoluteOrigin(0,0);
			if (entity->GetSprite())
			{
				v2Size = entity->GetCurrentSize();
				v2AbsoluteOrigin = entity->ComputeAbsoluteOrigin(v2Size);
			}

			// Place the current entity at the top-left corner to align
			// it to the render target
			const Vector3 oldPos = entity->GetPosition();
			const Vector3 newPos = Vector3(v2AbsoluteOrigin.x, v2AbsoluteOrigin.y, 0);

			std::list<ETHLight> lights;

			// fill the light list
			for (ETHBucketMap::iterator lbucketIter = m_buckets.GetFirstBucket(); lbucketIter != m_buckets.GetLastBucket(); ++lbucketIter)
			{
				ETHEntityList& lEntityList = lbucketIter->second;
				ETHEntityList::const_iterator liEnd = lEntityList.end();
				for (ETHEntityList::iterator liter = lEntityList.begin(); liter != liEnd; ++liter)
				{
					ETHRenderEntity* lightEntity = (*liter);
					if (lightEntity->IsStatic() && lightEntity->HasLightSource())
					{
						lights.push_back(
							ETHEntityRenderingManager::BuildChildLight(
								*(lightEntity->GetLight()),
								newPos - oldPos + lightEntity->GetPosition(),
								lightEntity->GetScale()));
					}
				}
			}

			if (lights.size() > 0)
			{
				ETHLightmapGen((*iter), m_provider->GetShaderManager(), lights.begin(), lights.end(),
					m_buckets, oldPos, newPos, m_minSceneHeight, m_maxSceneHeight, m_sceneProps);
			}
			else
			{
				entity->ReleaseLightmap();
			}

			entity->SetOrphanPosition(oldPos);
			lights.clear();
		}
	}
	#if defined(_DEBUG) || defined(DEBUG)
	ETH_STREAM_DECL(ss) << GS_L("Lightmaps created... ");
	m_provider->Log(ss.str(), Platform::FileLogger::INFO);
	#endif

	// go back to the previous global scale
	scaleManager->SetScaleFactor(globalScale);
	return true;
}