Example #1
0
// *********************************************************************************************************
void CDisplayerVisual::updateWorldPosRecurse()
{
	//H_AUTO(R2_CDisplayerVisual_updateWorldPosRecurse)
	struct CWorldPosUpdater : public IInstanceVisitor
	{
		virtual void visit(CInstance &inst)
		{
			if (inst.getDisplayerVisual())
			{
				inst.getDisplayerVisual()->updateWorldPos();
			}
		}
	};
	nlassert(getDisplayedInstance());
	CWorldPosUpdater worldPosUpdater;
	getDisplayedInstance()->visit(worldPosUpdater);
}
Example #2
0
// *********************************************************************************************************
bool CDisplayerVisual::isSelectable() const
{
	//H_AUTO(R2_CDisplayerVisual_isSelectable)
	static volatile bool bypass = false;
	if (bypass) return false;
	TDisplayMode dm = getActualDisplayMode();
	return getDisplayedInstance()->getSelectableFromRoot() && (dm == DisplayModeVisible || dm == DisplayModeLocked);
}
Example #3
0
// *********************************************************************************************************
bool CDisplayerVisual::isActiveInCurrentAct() const
{
	//H_AUTO(R2_CDisplayerVisual_isActiveInCurrentAct)
	// parent act should be the base act (always exists), or the selected act
	CInstance *parentAct = getDisplayedInstance()->getParentAct();
	if (parentAct == getEditor().getBaseAct() || parentAct == getEditor().getCurrentAct())
	{
		return true;
	}
	return false;
}
//*********************************************************************************************************
CDisplayerVisual *CDisplayerVisualActivitySequence::getParentDV() const
{
	//H_AUTO(R2_CDisplayerVisualActivitySequence_getParentDV)
	CInstance *currParent = getDisplayedInstance()->getParent();
	CDisplayerVisual *prevDV = NULL;
	while (currParent)
	{
		prevDV = currParent->getDisplayerVisual();
		if (prevDV) break;
		currParent = currParent->getParent();
	}
	return prevDV;
}
Example #5
0
// ***************************************************************
CDisplayerVisual *CDisplayerVisual::getParent()
{
	if (_LastParentOk) return _LastParent;
	CDisplayerVisual *result = NULL;
	//H_AUTO(R2_CDisplayerVisual_getParent)
	CInstance *inst = getDisplayedInstance();
	nlassert(inst);
	CInstance *parentInstance = inst->getParent();
	if (parentInstance)
	{
		result = parentInstance->getDisplayerVisual();
	}
	_LastParent = result;
	_LastParentOk = true;
	return result;
}
Example #6
0
// *********************************************************************************************************
CDisplayerVisual::TDisplayMode CDisplayerVisual::getActualDisplayMode() const
{
	//H_AUTO(R2_CDisplayerVisual_getActualDisplayMode)
	static volatile bool bypass = false;
	if (bypass)
	{
		return CDisplayerVisual::DisplayModeVisible;
	}

	TDisplayMode dm;
	const CDisplayerVisual *parent = getParent();
	if (_InheritDisplayMode && parent)
	{
		TDisplayMode parentDM = parent->getActualDisplayMode();
		dm = parentDM == DisplayModeVisible ? _DisplayMode : parentDM;
	}
	else
	{
		dm= _DisplayMode;
	}

	static volatile bool bypass2 = false;
	if (bypass2)
	{
		return CDisplayerVisual::DisplayModeVisible;
	}

	if (!getDisplayedInstance()->getSelectableFromRoot() && dm != DisplayModeHidden)
	{
		dm = DisplayModeFrozen;
	}

	static volatile bool bypass3 = false;
	if (bypass3)
	{
		return CDisplayerVisual::DisplayModeVisible;
	}

	// If it is not an animation but a scenario started from ring access do not display things
	if ( CEditor::getIsStartingScenario() )
	{
		return DisplayModeHidden;
	}
	return dm;
}
// *********************************************************************************************************
void CDisplayerVisualShape::setActive(bool active)
{
	//H_AUTO(R2_CDisplayerVisualShape_setActive)
	if (active == _Active) return;
	if (!active)
	{
		deleteShape();
	}
	else
	{
		if (!_MapDeco.isAddedToMap() && _WorldMapDisplay)
		{
			CGroupMap *gm = CTool::getWorldMap();
			if (gm)
			{
				_MapDeco.setDisplayedInstance(getDisplayedInstance(), false);
				gm->addDeco(&_MapDeco);
				_MapDeco.invalidateCoords();
			}
		}
	}
	_Touched = true;
	_Active = active;
}
Example #8
0
// *********************************************************************************************************
void CDisplayerVisual::onPostRender()
{
	//H_AUTO(R2_CDisplayerVisual_onPostRender)
	if (!getActive()) return;

	// if this entity is currently moving then don't display the 'stop' icon
	// (it is already drawn by the mouse cursor)
	if (getDisplayedInstance() == getEditor().getSelectedInstance()
		&& dynamic_cast<CToolSelectMove *>(getEditor().getCurrentTool()))
	{
		if (_IconInScene)
		{
			_IconInScene->setActive(false);
		}
	}
	else
	{
		if (getDisplayFlag(FlagBadPos))
		{
			if (!_IconInScene && !_IconInSceneCreationFailed)
			{
				CInterfaceManager *pIM = CInterfaceManager::getInstance();
				const char *iconTemplateName = "r2ed_bad_pos_icon";
				// if the in scene 'stop' window wasn't created, then create it now
				CInterfaceGroup *group = CWidgetManager::getInstance()->getParser()->createGroupInstance (iconTemplateName , "ui:interface", NULL, 0);
				if (group)
				{
					_IconInScene = dynamic_cast<CGroupInScene *>(group);
					if (!_IconInScene)
					{
						nlwarning("Template %s has bad type : should be a derived group from CGroupInScene", iconTemplateName);
						delete group;
						_IconInSceneCreationFailed = true;
					}
					else
					{
						// Link to the interface
						CWidgetManager::getInstance()->addWindowToMasterGroup("ui:interface", group);
						CInterfaceGroup *pRoot = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
						group->setParent(pRoot);
						if (pRoot)
							pRoot->addGroup (group);
					}
				}
				else
				{
					_IconInSceneCreationFailed = true;
				}
			}
			if (_IconInScene)
			{
				_IconInScene->setActive(true);
				// tmp set a position above head
				evalIconInScenePos(_IconInScene->Position);
			}
		}
		else
		{
			if (_IconInScene)
			{
				_IconInScene->setActive(false);
			}
		}
	}
}
//*********************************************************************************************************
void CDisplayerVisualActivitySequence::update()
{
	//H_AUTO(R2_CDisplayerVisualActivitySequence_update)
	if (!_Active) return;
	if (!_Touched) return;
	_Touched = false;
	CObjectTable *activities = getProps().toTable("Components");
	if (!activities)
	{
		clear();
		return;
	}
	// get first world object parent to get start position
	nlassert(getDisplayedInstance());
	CInstance *prevZone = NULL;
	CDisplayerVisual *prevDV = getParentDV();
	if (!prevDV)
	{
		clear();
		return;
	}
	//
	clear(false);
	//
	for(uint k = 0; k < activities->getSize(); ++k)
	{
		// search next zone of activity
		CObjectTable *activity = activities->getValue(k)->toTable();
		if (!activity) continue;
		std::string activityStr = getString(activity, "Activity");
		if (activityStr == "Stand Still" || activityStr == "Inactive") continue;
		//
		CInstance *nextZone = NULL;
		std::string zoneId = getString(activity, "ActivityZoneId");
		//
		if (!zoneId.empty())
		{
			_ObserverHandles.push_back(getEditor().addInstanceObserver(zoneId, this));
			nextZone = getEditor().getInstanceFromId(zoneId);
		}

		if (!nextZone) break;
		CDisplayerVisual *nextDV = nextZone->getDisplayerVisual();
		if (!nextDV) break;

		_TraversedPrimInfos.push_back(CTraversedPrimInfo());
		_TraversedPrimInfos.back().PrimDisplay = nextDV;
		_TraversedPrimInfos.back().Visible = nextDV->getActualDisplayMode() != DisplayModeHidden;


		CWorldPosCache wpc;
		wpc.DV = nextDV;
		wpc.WorldPos2f = nextDV->getWorldPos2f();
		_WPCache.push_back(wpc);

		if (nextDV->getActualDisplayMode() != DisplayModeHidden
			&& prevDV->getActualDisplayMode() != DisplayModeHidden)
		{
			// special case for regions
			if (nextZone->isKindOf("Region"))
			{
				// first case : previous zone is not a region
				if (!prevZone || !prevZone->isKindOf("Region"))
				{
					// search shortest distance bewteen last pos and the region
					CVector entryPos;
					if (nextDV->evalEnterPoint(prevDV->evalExitPoint(), entryPos))
					{
						addFootSteps(CLine(prevDV->evalExitPoint(), entryPos));
					}
					else
					{
						addWanderSteps(prevDV->evalExitPoint());
					}
				}
				else
				{
					// region-region footsteps
					// just use the couple of vertices for which the distance is the smallest
					static std::vector<CVector2f> r0;
					static std::vector<CVector2f> r1;
					prevDV->getSonsWorldPos2f(r0);
					nextDV->getSonsWorldPos2f(r1);
					if (!r0.empty() && !r1.empty())
					{
						CVector2f p0, p1;
						float bestDist = FLT_MAX;
						for(uint k = 0; k < r0.size(); ++k)
						{
							for(uint l = 0; l < r0.size(); ++l)
							{
								float dist = (r0[k] - r1[l]).norm();
								if (dist <bestDist)
								{
									bestDist = dist;
									p0 = r0[k];
									p1 = r1[l];
								}
							}
						}
						nlassert(bestDist != FLT_MAX);
						addFootSteps(CLine(p0.asVector(), p1.asVector()));
					}
				}
			}
			else
			{
				// special case if prev zone is a region
				if (prevZone && prevZone->isKindOf("Region"))
				{
					// search shortest distance bewteen last pos and the region
					CVector entryPos;
					if (prevDV->evalEnterPoint(nextDV->evalLinkPoint(), entryPos))
					{
						addFootSteps(CLine(entryPos, nextDV->evalLinkPoint()));
					}
					else
					{
						addWanderSteps(nextDV->evalLinkPoint());
					}
				}
				else
				{
					// simple footsteps between last & new pos
					addFootSteps(CLine(prevDV->evalExitPoint(), nextDV->evalLinkPoint()));
				}
			}
		}
		prevDV   = nextDV;
		prevZone = nextZone;
	}
	//
	CGroupMap *gm = CTool::getWorldMap();
	if (!_AddedToWorldMap && gm)
	{
		gm->addDeco(this);
	}
	if (_AddedToWorldMap)
	{
		setWorldMapNumEdges((uint)_FootSteps.size());
		nlassert(gm);
		onUpdate(*gm);
	}
}