2010-01-09 20:20:14 +01:00
|
|
|
/* Copyright (C) 2010 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "simulation2/system/Component.h"
|
|
|
|
#include "ICmpVisual.h"
|
|
|
|
|
|
|
|
#include "ICmpPosition.h"
|
2010-09-23 14:13:13 +02:00
|
|
|
#include "ICmpRangeManager.h"
|
|
|
|
#include "ICmpVision.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "simulation2/MessageTypes.h"
|
|
|
|
|
|
|
|
#include "graphics/Frustum.h"
|
|
|
|
#include "graphics/Model.h"
|
|
|
|
#include "graphics/ObjectBase.h"
|
|
|
|
#include "graphics/ObjectEntry.h"
|
|
|
|
#include "graphics/Unit.h"
|
2010-06-06 00:23:28 +02:00
|
|
|
#include "graphics/UnitAnimation.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "graphics/UnitManager.h"
|
2010-03-01 15:55:34 +01:00
|
|
|
#include "lib/utf8.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "maths/Matrix3D.h"
|
|
|
|
#include "maths/Vector3D.h"
|
|
|
|
#include "ps/CLogger.h"
|
|
|
|
#include "renderer/Scene.h"
|
|
|
|
|
|
|
|
class CCmpVisualActor : public ICmpVisual
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void ClassInit(CComponentManager& componentManager)
|
|
|
|
{
|
2010-09-03 11:55:14 +02:00
|
|
|
componentManager.SubscribeToMessageType(MT_Update_Final);
|
2010-01-22 21:03:14 +01:00
|
|
|
componentManager.SubscribeToMessageType(MT_Interpolate);
|
|
|
|
componentManager.SubscribeToMessageType(MT_RenderSubmit);
|
|
|
|
componentManager.SubscribeToMessageType(MT_OwnershipChanged);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DEFAULT_COMPONENT_ALLOCATOR(VisualActor)
|
|
|
|
|
2010-06-03 03:29:43 +02:00
|
|
|
std::wstring m_ActorName;
|
2010-02-07 21:06:16 +01:00
|
|
|
CUnit* m_Unit;
|
|
|
|
|
2010-10-04 19:34:33 +02:00
|
|
|
fixed m_R, m_G, m_B; // shading colour
|
|
|
|
|
2010-09-23 14:13:13 +02:00
|
|
|
ICmpRangeManager::ELosVisibility m_Visibility; // only valid between Interpolate and RenderSubmit
|
2010-08-05 12:20:47 +02:00
|
|
|
|
2010-02-07 21:06:16 +01:00
|
|
|
// Current animation state
|
2010-09-03 11:55:14 +02:00
|
|
|
float m_AnimRunThreshold; // if non-zero this is the special walk/run mode
|
2010-02-07 21:06:16 +01:00
|
|
|
std::string m_AnimName;
|
|
|
|
bool m_AnimOnce;
|
|
|
|
float m_AnimSpeed;
|
2010-04-06 01:09:34 +02:00
|
|
|
std::wstring m_SoundGroup;
|
2010-06-03 03:29:43 +02:00
|
|
|
float m_AnimDesync;
|
|
|
|
|
|
|
|
float m_AnimSyncRepeatTime; // 0.0 if not synced
|
2010-02-07 21:06:16 +01:00
|
|
|
|
2010-04-09 21:02:39 +02:00
|
|
|
static std::string GetSchema()
|
|
|
|
{
|
|
|
|
return
|
2010-04-23 18:09:03 +02:00
|
|
|
"<a:help>Display the unit using the engine's actor system.</a:help>"
|
|
|
|
"<a:example>"
|
|
|
|
"<Actor>units/hellenes/infantry_spearman_b.xml</Actor>"
|
|
|
|
"</a:example>"
|
|
|
|
"<a:example>"
|
|
|
|
"<Actor>structures/hellenes/barracks.xml</Actor>"
|
|
|
|
"<FoundationActor>structures/fndn_4x4.xml</FoundationActor>"
|
|
|
|
"</a:example>"
|
|
|
|
"<element name='Actor' a:help='Filename of the actor to be used for this unit'>"
|
|
|
|
"<text/>"
|
|
|
|
"</element>"
|
2010-04-09 21:02:39 +02:00
|
|
|
"<optional>"
|
2010-04-23 18:09:03 +02:00
|
|
|
"<element name='FoundationActor' a:help='Filename of the actor to be used the foundation while this unit is being constructed'>"
|
|
|
|
"<text/>"
|
|
|
|
"</element>"
|
2010-04-09 21:02:39 +02:00
|
|
|
"</optional>"
|
|
|
|
"<optional>"
|
2010-04-23 18:09:03 +02:00
|
|
|
"<element name='Foundation' a:help='Used internally; if present the unit will be rendered as a foundation'>"
|
|
|
|
"<empty/>"
|
|
|
|
"</element>"
|
|
|
|
"</optional>";
|
2010-04-09 21:02:39 +02:00
|
|
|
}
|
2010-04-15 21:59:07 +02:00
|
|
|
|
2011-01-16 15:08:38 +01:00
|
|
|
virtual void Init(const CParamNode& paramNode)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2010-08-05 12:20:47 +02:00
|
|
|
m_Unit = NULL;
|
|
|
|
|
2011-01-16 15:08:38 +01:00
|
|
|
if (!GetSimContext().HasUnitManager())
|
2010-02-08 23:05:05 +01:00
|
|
|
return; // do nothing if graphics are disabled
|
|
|
|
|
2010-03-12 23:28:51 +01:00
|
|
|
// 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
|
2010-04-09 21:02:39 +02:00
|
|
|
if (paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk())
|
2010-06-03 03:29:43 +02:00
|
|
|
m_ActorName = paramNode.GetChild("FoundationActor").ToString();
|
2010-03-12 23:28:51 +01:00
|
|
|
else
|
2010-06-03 03:29:43 +02:00
|
|
|
m_ActorName = paramNode.GetChild("Actor").ToString();
|
2010-03-12 23:28:51 +01:00
|
|
|
|
2010-10-04 19:34:33 +02:00
|
|
|
m_R = m_G = m_B = fixed::FromInt(1);
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
std::set<CStr> selections;
|
2011-01-16 15:08:38 +01:00
|
|
|
m_Unit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, selections);
|
2010-01-09 20:20:14 +01:00
|
|
|
if (!m_Unit)
|
|
|
|
{
|
|
|
|
// The error will have already been logged
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-03 03:29:43 +02:00
|
|
|
m_Unit->SetID(GetEntityId());
|
2010-02-07 21:06:16 +01:00
|
|
|
|
2010-06-03 03:29:43 +02:00
|
|
|
SelectAnimation("idle", false, 0.f, L"");
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
2011-01-16 15:08:38 +01:00
|
|
|
virtual void Deinit()
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
|
|
|
if (m_Unit)
|
|
|
|
{
|
2011-01-16 15:08:38 +01:00
|
|
|
GetSimContext().GetUnitManager().DeleteUnit(m_Unit);
|
2010-01-09 20:20:14 +01:00
|
|
|
m_Unit = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Serialize(ISerializer& serialize)
|
|
|
|
{
|
|
|
|
// TODO: store the actor name, if !debug and it differs from the template
|
|
|
|
|
|
|
|
if (serialize.IsDebug())
|
|
|
|
{
|
2010-06-03 03:29:43 +02:00
|
|
|
serialize.String("actor", m_ActorName, 0, 256);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: store random variation. This ought to be synchronised across saved games
|
|
|
|
// and networks, so everyone sees the same thing. Saving the list of selection strings
|
|
|
|
// would be awfully inefficient, so actors should be changed to (by default) represent
|
|
|
|
// variations with a 16-bit RNG seed (selected randomly when creating new units, or
|
|
|
|
// when someone hits the "randomise" button in the map editor), only overridden with
|
|
|
|
// a list of strings if it really needs to be a specific variation.
|
2010-02-07 21:06:16 +01:00
|
|
|
|
|
|
|
// TODO: store animation state
|
2010-03-17 23:56:49 +01:00
|
|
|
|
2010-10-23 21:59:40 +02:00
|
|
|
serialize.NumberFixed_Unbounded("r", m_R);
|
|
|
|
serialize.NumberFixed_Unbounded("g", m_G);
|
|
|
|
serialize.NumberFixed_Unbounded("b", m_B);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
2011-01-16 15:08:38 +01:00
|
|
|
virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2011-01-16 15:08:38 +01:00
|
|
|
Init(paramNode);
|
2010-10-23 21:59:40 +02:00
|
|
|
|
|
|
|
deserialize.NumberFixed_Unbounded("r", m_R);
|
|
|
|
deserialize.NumberFixed_Unbounded("g", m_G);
|
|
|
|
deserialize.NumberFixed_Unbounded("b", m_B);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
2011-01-16 15:08:38 +01:00
|
|
|
virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2010-09-19 20:08:56 +02:00
|
|
|
// Quick exit for running in non-graphical mode
|
|
|
|
if (m_Unit == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
switch (msg.GetType())
|
|
|
|
{
|
2010-09-03 11:55:14 +02:00
|
|
|
case MT_Update_Final:
|
|
|
|
{
|
|
|
|
const CMessageUpdate_Final& msgData = static_cast<const CMessageUpdate_Final&> (msg);
|
|
|
|
Update(msgData.turnLength);
|
|
|
|
break;
|
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
case MT_Interpolate:
|
|
|
|
{
|
2010-02-07 21:06:16 +01:00
|
|
|
const CMessageInterpolate& msgData = static_cast<const CMessageInterpolate&> (msg);
|
2010-09-03 11:55:14 +02:00
|
|
|
Interpolate(msgData.frameTime, msgData.offset);
|
2010-01-09 20:20:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MT_RenderSubmit:
|
|
|
|
{
|
|
|
|
const CMessageRenderSubmit& msgData = static_cast<const CMessageRenderSubmit&> (msg);
|
2010-09-03 11:55:14 +02:00
|
|
|
RenderSubmit(msgData.collector, msgData.frustum, msgData.culling);
|
2010-01-09 20:20:14 +01:00
|
|
|
break;
|
|
|
|
}
|
2010-01-22 21:03:14 +01:00
|
|
|
case MT_OwnershipChanged:
|
|
|
|
{
|
|
|
|
const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg);
|
2010-09-19 20:08:56 +02:00
|
|
|
m_Unit->GetModel().SetPlayerID(msgData.to);
|
2010-01-22 21:03:14 +01:00
|
|
|
break;
|
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual CBound GetBounds()
|
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return CBound();
|
2010-04-17 13:44:08 +02:00
|
|
|
return m_Unit->GetModel().GetBounds();
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
2010-03-11 21:01:16 +01:00
|
|
|
virtual CVector3D GetPosition()
|
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return CVector3D(0, 0, 0);
|
2010-04-17 13:44:08 +02:00
|
|
|
return m_Unit->GetModel().GetTransform().GetTranslation();
|
2010-03-11 21:01:16 +01:00
|
|
|
}
|
|
|
|
|
2010-06-03 03:29:43 +02:00
|
|
|
virtual std::wstring GetActorShortName()
|
2010-04-17 13:34:40 +02:00
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return L"";
|
2010-06-03 03:29:43 +02:00
|
|
|
return m_Unit->GetObject().m_Base->m_ShortName;
|
2010-04-17 13:34:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::wstring GetProjectileActor()
|
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return L"";
|
|
|
|
return m_Unit->GetObject().m_ProjectileModelName;
|
|
|
|
}
|
|
|
|
|
2010-06-05 02:49:14 +02:00
|
|
|
virtual CVector3D GetProjectileLaunchPoint()
|
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return CVector3D();
|
2010-09-23 15:09:35 +02:00
|
|
|
|
|
|
|
// Ensure the prop transforms are correct
|
|
|
|
m_Unit->GetModel().ValidatePosition();
|
|
|
|
|
2010-06-05 02:49:14 +02:00
|
|
|
CModel* ammo = m_Unit->GetModel().FindFirstAmmoProp();
|
|
|
|
if (!ammo)
|
|
|
|
return CVector3D();
|
|
|
|
return ammo->GetTransform().GetTranslation();
|
|
|
|
}
|
|
|
|
|
2010-04-06 01:09:34 +02:00
|
|
|
virtual void SelectAnimation(std::string name, bool once, float speed, std::wstring soundgroup)
|
2010-02-07 21:06:16 +01:00
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!isfinite(speed) || speed < 0) // JS 'undefined' converts to NaN, which causes Bad Things
|
2010-04-06 01:09:34 +02:00
|
|
|
speed = 1.f;
|
|
|
|
|
2010-09-03 11:55:14 +02:00
|
|
|
m_AnimRunThreshold = 0.f;
|
2010-02-07 21:06:16 +01:00
|
|
|
m_AnimName = name;
|
|
|
|
m_AnimOnce = once;
|
|
|
|
m_AnimSpeed = speed;
|
2010-04-06 01:09:34 +02:00
|
|
|
m_SoundGroup = soundgroup;
|
2010-06-03 03:29:43 +02:00
|
|
|
m_AnimDesync = 0.05f; // TODO: make this an argument
|
|
|
|
m_AnimSyncRepeatTime = 0.0f;
|
2010-04-06 01:09:34 +02:00
|
|
|
|
2010-06-06 00:23:28 +02:00
|
|
|
m_Unit->GetAnimation().SetAnimationState(m_AnimName, m_AnimOnce, m_AnimSpeed, m_AnimDesync, false, m_SoundGroup.c_str());
|
2010-04-06 01:09:34 +02:00
|
|
|
}
|
|
|
|
|
2010-09-03 11:55:14 +02:00
|
|
|
virtual void SelectMovementAnimation(float runThreshold)
|
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_AnimRunThreshold = runThreshold;
|
|
|
|
|
|
|
|
m_Unit->GetAnimation().SetAnimationState("walk", false, 1.f, 0.f, false, L"");
|
|
|
|
}
|
|
|
|
|
2010-06-06 00:23:28 +02:00
|
|
|
virtual void SetAnimationSyncRepeat(float repeattime)
|
2010-04-06 01:09:34 +02:00
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return;
|
2010-02-07 21:06:16 +01:00
|
|
|
|
2010-06-03 03:29:43 +02:00
|
|
|
m_AnimSyncRepeatTime = repeattime;
|
|
|
|
|
2010-06-06 00:23:28 +02:00
|
|
|
m_Unit->GetAnimation().SetAnimationSyncRepeat(m_AnimSyncRepeatTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetAnimationSyncOffset(float actiontime)
|
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_Unit->GetAnimation().SetAnimationSyncOffset(actiontime);
|
2010-02-07 21:06:16 +01:00
|
|
|
}
|
|
|
|
|
2010-05-02 22:32:37 +02:00
|
|
|
virtual void SetShadingColour(fixed r, fixed g, fixed b, fixed a)
|
2010-03-17 23:56:49 +01:00
|
|
|
{
|
2010-10-04 19:34:33 +02:00
|
|
|
m_R = r;
|
|
|
|
m_G = g;
|
|
|
|
m_B = b;
|
|
|
|
UNUSED2(a); // TODO: why is this even an argument?
|
2010-03-17 23:56:49 +01:00
|
|
|
}
|
|
|
|
|
2010-06-03 03:29:43 +02:00
|
|
|
virtual void Hotload(const std::wstring& name)
|
|
|
|
{
|
|
|
|
if (!m_Unit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (name != m_ActorName)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::set<CStr> selections;
|
2010-06-05 02:49:14 +02:00
|
|
|
CUnit* newUnit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, selections);
|
2010-06-03 03:29:43 +02:00
|
|
|
|
|
|
|
if (!newUnit)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Save some data from the old unit
|
|
|
|
CColor shading = m_Unit->GetModel().GetShadingColor();
|
|
|
|
size_t playerID = m_Unit->GetModel().GetPlayerID();
|
|
|
|
|
|
|
|
// Replace with the new unit
|
|
|
|
GetSimContext().GetUnitManager().DeleteUnit(m_Unit);
|
|
|
|
m_Unit = newUnit;
|
|
|
|
|
|
|
|
m_Unit->SetID(GetEntityId());
|
|
|
|
|
2010-06-06 00:23:28 +02:00
|
|
|
m_Unit->GetAnimation().SetAnimationState(m_AnimName, m_AnimOnce, m_AnimSpeed, m_AnimDesync, false, m_SoundGroup.c_str());
|
2010-06-03 03:29:43 +02:00
|
|
|
|
|
|
|
// We'll lose the exact synchronisation but we should at least make sure it's going at the correct rate
|
|
|
|
if (m_AnimSyncRepeatTime != 0.0f)
|
2010-06-06 00:23:28 +02:00
|
|
|
m_Unit->GetAnimation().SetAnimationSyncRepeat(m_AnimSyncRepeatTime);
|
2010-06-03 03:29:43 +02:00
|
|
|
|
|
|
|
m_Unit->GetModel().SetShadingColor(shading);
|
|
|
|
|
|
|
|
m_Unit->GetModel().SetPlayerID(playerID);
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
private:
|
2010-09-03 11:55:14 +02:00
|
|
|
void Update(fixed turnLength);
|
|
|
|
void Interpolate(float frameTime, float frameOffset);
|
|
|
|
void RenderSubmit(SceneCollector& collector, const CFrustum& frustum, bool culling);
|
2010-01-09 20:20:14 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_COMPONENT_TYPE(VisualActor)
|
|
|
|
|
2010-09-03 11:55:14 +02:00
|
|
|
void CCmpVisualActor::Update(fixed turnLength)
|
|
|
|
{
|
|
|
|
if (m_Unit == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we're in the special movement mode, select an appropriate animation
|
|
|
|
if (m_AnimRunThreshold)
|
|
|
|
{
|
|
|
|
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
|
|
|
if (cmpPosition.null() || !cmpPosition->IsInWorld())
|
|
|
|
return;
|
|
|
|
|
|
|
|
float speed = cmpPosition->GetDistanceTravelled().ToFloat() / turnLength.ToFloat();
|
|
|
|
|
|
|
|
if (speed == 0.0f)
|
|
|
|
m_Unit->GetAnimation().SetAnimationState("idle", false, 1.f, 0.f, false, L"");
|
|
|
|
else if (speed < m_AnimRunThreshold)
|
|
|
|
m_Unit->GetAnimation().SetAnimationState("walk", false, speed, 0.f, false, L"");
|
|
|
|
else
|
|
|
|
m_Unit->GetAnimation().SetAnimationState("run", false, speed, 0.f, false, L"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCmpVisualActor::Interpolate(float frameTime, float frameOffset)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
|
|
|
if (m_Unit == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-09-03 11:55:14 +02:00
|
|
|
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), GetEntityId());
|
2010-01-09 20:20:14 +01:00
|
|
|
if (cmpPosition.null())
|
|
|
|
return;
|
|
|
|
|
2010-08-05 12:20:47 +02:00
|
|
|
// Disable rendering of the unit if it has no position
|
2010-01-09 20:20:14 +01:00
|
|
|
if (!cmpPosition->IsInWorld())
|
|
|
|
{
|
2010-09-23 14:13:13 +02:00
|
|
|
m_Visibility = ICmpRangeManager::VIS_HIDDEN;
|
2010-01-09 20:20:14 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-04 19:34:33 +02:00
|
|
|
// The 'always visible' flag means we should always render the unit
|
|
|
|
// (regardless of whether the LOS system thinks it's visible)
|
|
|
|
CmpPtr<ICmpVision> cmpVision(GetSimContext(), GetEntityId());
|
|
|
|
if (!cmpVision.null() && cmpVision->GetAlwaysVisible())
|
|
|
|
{
|
|
|
|
m_Visibility = ICmpRangeManager::VIS_VISIBLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CmpPtr<ICmpRangeManager> cmpRangeManager(GetSimContext(), SYSTEM_ENTITY);
|
|
|
|
m_Visibility = cmpRangeManager->GetLosVisibility(GetEntityId(), GetSimContext().GetCurrentDisplayedPlayer());
|
|
|
|
}
|
2010-09-23 14:13:13 +02:00
|
|
|
|
|
|
|
// Even if HIDDEN due to LOS, we need to set up the transforms
|
|
|
|
// so that projectiles will be launched from the right place
|
2010-08-05 12:20:47 +02:00
|
|
|
|
2010-08-09 03:28:13 +02:00
|
|
|
bool floating = m_Unit->GetObject().m_Base->m_Properties.m_FloatOnWater;
|
|
|
|
|
|
|
|
CMatrix3D transform(cmpPosition->GetInterpolatedTransform(frameOffset, floating));
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2010-10-04 19:34:33 +02:00
|
|
|
CModel& model = m_Unit->GetModel();
|
|
|
|
|
|
|
|
model.SetTransform(transform);
|
2010-02-07 21:06:16 +01:00
|
|
|
m_Unit->UpdateModel(frameTime);
|
2010-10-04 19:34:33 +02:00
|
|
|
|
|
|
|
// If not hidden, then we need to set up some extra state for rendering
|
|
|
|
if (m_Visibility != ICmpRangeManager::VIS_HIDDEN)
|
|
|
|
{
|
|
|
|
model.ValidatePosition();
|
|
|
|
|
|
|
|
if (m_Visibility == ICmpRangeManager::VIS_FOGGED)
|
2010-10-04 19:35:13 +02:00
|
|
|
model.SetShadingColor(CColor(0.5f * m_R.ToFloat(), 0.5f * m_G.ToFloat(), 0.5f * m_B.ToFloat(), 1.0f));
|
2010-10-04 19:34:33 +02:00
|
|
|
else
|
|
|
|
model.SetShadingColor(CColor(m_R.ToFloat(), m_G.ToFloat(), m_B.ToFloat(), 1.0f));
|
|
|
|
}
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|
|
|
|
|
2010-09-03 11:55:14 +02:00
|
|
|
void CCmpVisualActor::RenderSubmit(SceneCollector& collector, const CFrustum& frustum, bool culling)
|
2010-01-09 20:20:14 +01:00
|
|
|
{
|
2010-01-22 21:03:14 +01:00
|
|
|
if (m_Unit == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-09-23 14:13:13 +02:00
|
|
|
if (m_Visibility == ICmpRangeManager::VIS_HIDDEN)
|
2010-08-05 12:20:47 +02:00
|
|
|
return;
|
|
|
|
|
2010-04-17 13:44:08 +02:00
|
|
|
CModel& model = m_Unit->GetModel();
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2010-04-17 13:44:08 +02:00
|
|
|
if (culling && !frustum.IsBoxVisible(CVector3D(0, 0, 0), model.GetBounds()))
|
2010-01-09 20:20:14 +01:00
|
|
|
return;
|
|
|
|
|
2010-04-17 13:44:08 +02:00
|
|
|
collector.SubmitRecursive(&model);
|
2010-01-09 20:20:14 +01:00
|
|
|
}
|