void DebugTrackerVisualizer::visualizeTrackers(game::tracking::ObjectTracker *objectTracker)
	{
		assert(objectTracker != NULL);

		std::vector<ITrackerObject *> trackerList = objectTracker->getAllTrackers();

		for (int i = 0; i < (int)trackerList.size(); i++)
		{
			ITrackerObject *tracker = trackerList[i];

			std::string trackerName = tracker->getType()->getTrackerTypeName();
			
			COL col = COL(0,0,1);

			VC3 pos = tracker->getTrackerPosition();
			VC3 sizes = VC3(0.1f, 0.1f, 0.1f);

			if (trackerName == "projectile")
			{
				col = COL(1.0f,0.7f,0.0f);
				sizes *= 1.5f;
			}

			VC3 c1 = VC3(pos.x - sizes.x, pos.y + sizes.y, pos.z - sizes.z);
			VC3 c2 = VC3(pos.x + sizes.x, pos.y + sizes.y, pos.z - sizes.z);
			VC3 c3 = VC3(pos.x + sizes.x, pos.y + sizes.y, pos.z + sizes.z);
			VC3 c4 = VC3(pos.x - sizes.x, pos.y + sizes.y, pos.z + sizes.z);
			VC3 cb1 = VC3(pos.x - sizes.x, pos.y - sizes.y, pos.z - sizes.z);
			VC3 cb2 = VC3(pos.x + sizes.x, pos.y - sizes.y, pos.z - sizes.z);
			VC3 cb3 = VC3(pos.x + sizes.x, pos.y - sizes.y, pos.z + sizes.z);
			VC3 cb4 = VC3(pos.x - sizes.x, pos.y - sizes.y, pos.z + sizes.z);

			float extra_offset = 0.0f + (i / 200.0f);
			VC3 cb4_extra = VC3(pos.x - sizes.x - extra_offset, pos.y - sizes.y, pos.z + sizes.z);

			disposable_scene->AddLine(c1, c2, col);
			disposable_scene->AddLine(c2, c3, col);
			disposable_scene->AddLine(c3, c4, col);
			disposable_scene->AddLine(c4, c1, col);
			disposable_scene->AddLine(cb1, cb2, col);
			disposable_scene->AddLine(cb2, cb3, col);
			disposable_scene->AddLine(cb3, cb4, col);
			disposable_scene->AddLine(cb4, cb1, col);
			disposable_scene->AddLine(c1, cb1, col);
			disposable_scene->AddLine(c2, cb2, col);
			disposable_scene->AddLine(c3, cb3, col);
			disposable_scene->AddLine(c4, cb4, col);
			disposable_scene->AddLine(c4, cb4, col);

			COL col2 = COL(0,1,1);
			disposable_scene->AddLine(c4, cb4_extra, col2);

		}
	}
	UnifiedHandle TrackableUnifiedHandleObject::getTrackedByForTrackableTypes(TRACKABLE_TYPEID_DATATYPE trackableTypes)
	{
		if (this->trackedByCount == 0)
			return UNIFIED_HANDLE_NONE;

		// this should neven happen? more than this amount of trackers for one object...
		assert(this->trackedByCount < 10);

		int inCacheAmount = 0;
		// is it in cache?
		for (int i = 0; i < TRACKABLEUNIFIEDHANDLEOBJECT_TRACKED_BY_CACHE_SIZE; i++)
		{
			if (this->trackedBy[i] != UNIFIED_HANDLE_NONE)
			{
				inCacheAmount++;
				ITrackerObject *t = tuho_game->objectTracker->getTrackerByUnifiedHandle(this->trackedBy[i]);
				if (t != NULL)
				{
					if ((t->getType()->getTrackablesTypeOfInterest() & trackableTypes) != 0)
					{
						return this->trackedBy[i];
					}
				} else {
					// the tracker seems to have been deleted... so remove it from our "cache"? (if this happens it's a bug!)
					assert(!"TrackableUnifiedHandleObject::getTrackedByForTrackableType - data integrity lost, tracker has been deleted but is still in cache! (bug)");
					return UNIFIED_HANDLE_NONE;
				}
			}
		}

		assert(this->trackedByCount >= inCacheAmount);

		if (this->trackedByCount == inCacheAmount)
		{
			return UNIFIED_HANDLE_NONE;
		}

		if (this->trackedByCount > TRACKABLEUNIFIEDHANDLEOBJECT_TRACKED_BY_CACHE_SIZE)
		{
			// it was not in cache, gotta look it up the slow way...
			// change the ObjectTracker::getAllTrackers to return an iterator instead of vector and make it public...
			LOG_ERROR("TrackableUnifiedHandleObject::getTrackedByForTrackableType - TODO, need to look for the tracker the non-cached way...");
			assert(!"TrackableUnifiedHandleObject::getTrackedByForTrackableType - TODO, need to look for the tracker the non-cached way...");
		}

		return UNIFIED_HANDLE_NONE;
	}
Exemplo n.º 3
0
	void UnifiedHandleManager::setObjectPosition(UnifiedHandle uh, const VC3 &position)
	{
		if (IS_UNIFIED_HANDLE_TRACKER(uh))
		{
			ITrackerObject *t = game->objectTracker->getTrackerByUnifiedHandle(uh);
			assert(t != NULL);
			t->setTrackerPosition(position);
		}
		else if (IS_UNIFIED_HANDLE_UNIT(uh))
		{
			assert(game->units->doesTrackableUnifiedHandleObjectExist(uh));
			Unit *u = game->units->getUnitById(game->units->unifiedHandleToUnitId(uh));
			UnitActor *ua = getUnitActorForUnit(u);
			assert(ua != NULL);
			ua->removeUnitObstacle(u);
			u->setPosition(position);
			ua->addUnitObstacle(u);
		}
		else if (IS_UNIFIED_HANDLE_TERRAIN_OBJECT(uh))
		{
			assert(game->gameUI->getTerrain()->doesTrackableUnifiedHandleObjectExist(uh));
			int modelId = 0;
			int instanceId = 0;
			game->gameUI->getTerrain()->unifiedHandleToTerrainIds(uh, &modelId, &instanceId);
			game->gameUI->getTerrain()->setTerrainObjectPosition(modelId, instanceId, position);
		}
		else if (IS_UNIFIED_HANDLE_LIGHT(uh))
		{
			assert(game->gameUI->getLightManager()->doesLightExist(uh));
			game->gameUI->getLightManager()->setLightPositionByUnifiedHandle(uh, position);
		}
		else if (IS_UNIFIED_HANDLE_DYNAMIC_LIGHT(uh))
		{
			assert(game->gameUI->getDynamicLightManager()->doesLightExist(uh));
			game->gameUI->getDynamicLightManager()->setLightPositionByUnifiedHandle(uh, position);
		}
		else if (IS_UNIFIED_HANDLE_PARTICLE_SPAWNER(uh))
		{
			assert(game->particleSpawnerManager->doesParticleSpawnerExist(uh));
			game->particleSpawnerManager->setParticleSpawnerPosition(uh, position);
		}
		else 
		{
			// TODO: other types.
			assert(!"UnifiedHandleManager::setObjectPosition - TODO, other types.");
		}
	}
Exemplo n.º 4
0
	VC3 UnifiedHandleManager::getObjectPosition(UnifiedHandle uh) const
	{
		if (IS_UNIFIED_HANDLE_UNIT(uh))
		{
			assert(game->units->doesTrackableUnifiedHandleObjectExist(uh));
			return game->units->getTrackableUnifiedHandlePosition(uh);
		}
		else if (IS_UNIFIED_HANDLE_TERRAIN_OBJECT(uh))
		{
			assert(game->gameUI->getTerrain()->doesTrackableUnifiedHandleObjectExist(uh));
			return game->gameUI->getTerrain()->getTrackableUnifiedHandlePosition(uh);
		}
		else if (IS_UNIFIED_HANDLE_LIGHT(uh))
		{
			assert(game->gameUI->getLightManager()->doesLightExist(uh));
			return game->gameUI->getLightManager()->getLightPosition(uh);
		}
		else if (IS_UNIFIED_HANDLE_DYNAMIC_LIGHT(uh))
		{
			assert(game->gameUI->getDynamicLightManager()->doesLightExist(uh));
			return game->gameUI->getDynamicLightManager()->getLightPosition(uh);
		}
		else if (IS_UNIFIED_HANDLE_TRACKER(uh))
		{
			ITrackerObject *t = game->objectTracker->getTrackerByUnifiedHandle(uh);
			assert(t != NULL);
			return t->getTrackerPosition();
		}
		else if (IS_UNIFIED_HANDLE_PARTICLE_SPAWNER(uh))
		{
			assert(game->particleSpawnerManager->doesParticleSpawnerExist(uh));
			return game->particleSpawnerManager->getParticleSpawnerPosition(uh);
		}
		else 
		{
			// TODO: other types.
			assert(!"UnifiedHandleManager::getObjectPosition - TODO, other types.");
			return VC3(0,0,0);
		}
	}