예제 #1
0
	virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize)
	{
		Init(paramNode);

		u32 oldSeed = GetActorSeed();

		SerializeCommon(deserialize);

		// If we serialized a different seed, reload actor
		if (oldSeed != GetActorSeed())
			ReloadActor();

		fixed repeattime = m_AnimSyncRepeatTime; // save because SelectAnimation overwrites it

		if (m_AnimRunThreshold.IsZero())
			SelectAnimation(m_AnimName, m_AnimOnce, m_AnimSpeed, m_SoundGroup);
		else
			SelectMovementAnimation(m_AnimRunThreshold);

		SetAnimationSyncRepeat(repeattime);

		if (m_Unit)
		{
			CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId());
			if (cmpOwnership)
				m_Unit->GetModel().SetPlayerID(cmpOwnership->GetOwner());
		}
	}
예제 #2
0
	virtual void Init(const CParamNode& paramNode)
	{
		m_PreviouslyRendered = false;
		m_Unit = NULL;
		m_Visibility = ICmpRangeManager::VIS_HIDDEN;

		m_R = m_G = m_B = fixed::FromInt(1);

		if (!GetSimContext().HasUnitManager())
			return; // do nothing further if graphics are disabled

		// TODO: we should do some fancy animation of under-construction buildings rising from the ground,
		// but for now we'll just use the foundation actor and ignore the normal one
		if (paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk())
			m_ActorName = paramNode.GetChild("FoundationActor").ToString();
		else
			m_ActorName = paramNode.GetChild("Actor").ToString();

		std::set<CStr> selections;
		m_Unit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections);
		if (m_Unit)
		{
			CModelAbstract& model = m_Unit->GetModel();
			if (model.ToCModel())
			{
				u32 modelFlags = 0;

				if (paramNode.GetChild("SilhouetteDisplay").ToBool())
					modelFlags |= MODELFLAG_SILHOUETTE_DISPLAY;

				if (paramNode.GetChild("SilhouetteOccluder").ToBool())
					modelFlags |= MODELFLAG_SILHOUETTE_OCCLUDER;

				CmpPtr<ICmpVision> cmpVision(GetSimContext(), GetEntityId());
				if (cmpVision && cmpVision->GetAlwaysVisible())
					modelFlags |= MODELFLAG_IGNORE_LOS;

				model.ToCModel()->AddFlagsRec(modelFlags);
			}

			// Initialize the model's selection shape descriptor. This currently relies on the component initialization order; the 
			// Footprint component must be initialized before this component (VisualActor) to support the ability to use the footprint
			// shape for the selection box (instead of the default recursive bounding box). See TypeList.h for the order in
			// which components are initialized; if for whatever reason you need to get rid of this dependency, you can always just
			// initialize the selection shape descriptor on-demand.
			InitSelectionShapeDescriptor(model, paramNode);

			m_Unit->SetID(GetEntityId());
		}

		SelectAnimation("idle", false, fixed::FromInt(1), L"");
	}
예제 #3
0
	virtual void Hotload(const VfsPath& name)
	{
		if (!m_Unit)
			return;

		if (name != m_ActorName)
			return;

		std::set<CStr> selections;
		CUnit* newUnit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections);

		if (!newUnit)
			return;

		// Save some data from the old unit
		CColor shading = m_Unit->GetModel().GetShadingColor();
		player_id_t playerID = m_Unit->GetModel().GetPlayerID();

		// Replace with the new unit
		GetSimContext().GetUnitManager().DeleteUnit(m_Unit);
		m_Unit = newUnit;

		m_Unit->SetID(GetEntityId());

		m_Unit->SetEntitySelection(m_AnimName);
		if (m_Unit->GetAnimation())
			m_Unit->GetAnimation()->SetAnimationState(m_AnimName, m_AnimOnce, m_AnimSpeed.ToFloat(), m_AnimDesync.ToFloat(), m_SoundGroup.c_str());

		// We'll lose the exact synchronisation but we should at least make sure it's going at the correct rate
		if (!m_AnimSyncRepeatTime.IsZero())
			if (m_Unit->GetAnimation())
				m_Unit->GetAnimation()->SetAnimationSyncRepeat(m_AnimSyncRepeatTime.ToFloat());

		m_Unit->GetModel().SetShadingColor(shading);

		m_Unit->GetModel().SetPlayerID(playerID);

		// TODO: should copy/reset silhouette flags
	}
예제 #4
0
	virtual void Init(const CParamNode& paramNode)
	{
		m_Unit = NULL;

		if (!GetSimContext().HasUnitManager())
			return; // do nothing if graphics are disabled

		// TODO: we should do some fancy animation of under-construction buildings rising from the ground,
		// but for now we'll just use the foundation actor and ignore the normal one
		if (paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk())
			m_ActorName = paramNode.GetChild("FoundationActor").ToString();
		else
			m_ActorName = paramNode.GetChild("Actor").ToString();

		m_R = m_G = m_B = fixed::FromInt(1);

		std::set<CStr> selections;
		m_Unit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections);
		if (!m_Unit)
		{
			// The error will have already been logged
			return;
		}

		u32 modelFlags = 0;
		if (paramNode.GetChild("SilhouetteDisplay").ToBool())
			modelFlags |= MODELFLAG_SILHOUETTE_DISPLAY;
		if (paramNode.GetChild("SilhouetteOccluder").ToBool())
			modelFlags |= MODELFLAG_SILHOUETTE_OCCLUDER;

		if (m_Unit->GetModel().ToCModel())
			m_Unit->GetModel().ToCModel()->AddFlagsRec(modelFlags);

		m_Unit->SetID(GetEntityId());

		SelectAnimation("idle", false, 0.f, L"");
	}