metaforce/Runtime/World/CActor.cpp

788 lines
26 KiB
C++
Raw Normal View History

#include "CActor.hpp"
2016-04-22 20:22:45 +00:00
#include "CActorParameters.hpp"
#include "CStateManager.hpp"
#include "Collision/CMaterialList.hpp"
2016-04-29 10:08:46 +00:00
#include "Audio/CSfxManager.hpp"
2017-01-15 03:07:01 +00:00
#include "TCastTo.hpp"
2017-02-11 00:52:52 +00:00
#include "Character/IAnimReader.hpp"
#include "Character/CActorLights.hpp"
2017-06-03 06:03:07 +00:00
#include "Camera/CGameCamera.hpp"
2017-11-24 08:23:28 +00:00
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
2018-02-05 06:56:09 +00:00
#include "CWorld.hpp"
#include "Graphics/CBooRenderer.hpp"
#include "CTimeProvider.hpp"
#include "Graphics/CSkinnedModel.hpp"
2016-03-04 23:04:53 +00:00
namespace urde
{
2016-04-22 20:22:45 +00:00
static CMaterialList MakeActorMaterialList(const CMaterialList& materialList, const CActorParameters& params)
{
CMaterialList ret = materialList;
if (params.GetVisorParameters().x0_4_b1)
ret.Add(EMaterialTypes::Unknown46);
if (params.GetVisorParameters().x0_5_scanPassthrough)
ret.Add(EMaterialTypes::ScanPassthrough);
2016-04-22 20:22:45 +00:00
return ret;
}
2017-11-26 03:04:25 +00:00
CActor::CActor(TUniqueId uid, bool active, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
CModelData&& mData, const CMaterialList& list, const CActorParameters& params, TUniqueId otherUid)
: CEntity(uid, info, active, name)
2017-11-26 03:04:25 +00:00
, x34_transform(xf)
, x68_material(MakeActorMaterialList(list, params))
2017-01-07 01:58:05 +00:00
, x70_materialFilter(CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {0ull}))
, xc6_nextDrawNode(otherUid)
2016-04-22 20:22:45 +00:00
{
2017-11-24 08:23:28 +00:00
x90_actorLights = mData.IsNull() ? std::unique_ptr<CActorLights>() : params.x0_lightParms.MakeActorLights();
2016-05-03 08:27:28 +00:00
if (mData.x10_animData || mData.x1c_normalModel)
2016-04-22 20:22:45 +00:00
x64_modelData = std::make_unique<CModelData>(std::move(mData));
2018-02-09 07:12:26 +00:00
xd0_thermalMag = params.x64_thermalMag;
2017-06-03 06:03:07 +00:00
xd8_nonLoopingSfxHandles.resize(2);
2017-11-26 03:04:25 +00:00
xe4_27_notInSortedLists = true;
xe4_28_transformDirty = true;
2017-11-24 08:23:28 +00:00
xe4_29_actorLightsDirty = true;
2018-05-11 07:02:42 +00:00
xe4_31_calculateLighting = true;
2017-11-24 08:23:28 +00:00
xe5_27_useInSortedLists = true;
xe5_28_callTouch = true;
xe5_29_globalTimeProvider = params.x58_24_globalTimeProvider;
xe5_30_renderUnsorted = params.x58_26_renderUnsorted;
2018-02-08 06:18:27 +00:00
xe6_27_thermalVisorFlags = u8(params.x58_25_thermalHeat ? 2 : 1);
xe6_29_renderParticleDBInside = true;
2017-11-24 08:23:28 +00:00
xe6_31_targetableVisorFlags = params.GetVisorParameters().GetMask();
2018-02-05 06:56:09 +00:00
xe7_27_enableRender = true;
2018-05-18 04:16:33 +00:00
xe7_29_drawEnabled = active;
2017-11-24 08:23:28 +00:00
xe7_30_doTargetDistanceTest = true;
xe7_31_targetable = true;
if (x64_modelData)
{
if (params.x44_xrayAssets.first.IsValid())
x64_modelData->SetXRayModel(params.x44_xrayAssets);
if (params.x4c_thermalAssets.first.IsValid())
x64_modelData->SetInfraModel(params.x4c_thermalAssets);
if (!params.x0_lightParms.x1c_makeLights || params.x0_lightParms.x3c_maxAreaLights == 0)
x64_modelData->x18_ambientColor = params.x0_lightParms.x18_noLightsAmbient;
x64_modelData->x14_25_sortThermal = !params.x58_27_noSortThermal;
}
2018-05-08 02:11:07 +00:00
2017-11-24 08:23:28 +00:00
if (params.x40_scanParms.GetScanId().IsValid())
x98_scanObjectInfo = g_SimplePool->GetObj(SObjectTag{FOURCC('SCAN'), params.x40_scanParms.GetScanId()});
2016-04-22 20:22:45 +00:00
}
2016-04-29 10:08:46 +00:00
void CActor::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
{
switch (msg)
2016-04-29 10:08:46 +00:00
{
case EScriptObjectMessage::Activate:
{
if (!x30_24_active)
xbc_time = CGraphics::GetSecondsMod900();
2018-05-18 04:16:33 +00:00
break;
2016-04-29 10:08:46 +00:00
}
2018-05-18 04:16:33 +00:00
case EScriptObjectMessage::Deactivate:
2016-04-29 10:08:46 +00:00
RemoveEmitter();
break;
2018-05-18 04:16:33 +00:00
case EScriptObjectMessage::Deleted: // 34
{
RemoveEmitter();
if (HasModelData() && x64_modelData->AnimationData() && x64_modelData->GetNormalModel())
x64_modelData->AnimationData()->GetParticleDB().DeleteAllLights(mgr);
break;
}
2017-03-24 05:30:16 +00:00
case EScriptObjectMessage::Registered: // 33
2016-04-29 10:08:46 +00:00
{
2016-12-29 21:38:59 +00:00
if (x98_scanObjectInfo)
AddMaterial(EMaterialTypes::Scannable, mgr);
2016-04-29 10:08:46 +00:00
else
2016-12-29 21:38:59 +00:00
RemoveMaterial(EMaterialTypes::Scannable, mgr);
2016-04-29 10:08:46 +00:00
if (HasModelData() && x64_modelData->AnimationData())
{
TAreaId aid = GetAreaId();
2017-11-24 08:01:06 +00:00
x64_modelData->AnimationData()->InitializeEffects(mgr, aid, x64_modelData->GetScale());
2016-04-29 10:08:46 +00:00
}
2018-05-18 04:16:33 +00:00
break;
2016-04-29 10:08:46 +00:00
}
2018-05-18 04:16:33 +00:00
case EScriptObjectMessage::UpdateSplashInhabitant: // 37
SetInFluid(true, uid);
break;
case EScriptObjectMessage::RemoveSplashInhabitant: // 39
SetInFluid(false, kInvalidUniqueId);
break;
2017-03-24 05:30:16 +00:00
case EScriptObjectMessage::InitializedInArea: // 35
2016-04-29 10:08:46 +00:00
{
for (const SConnection& conn : x20_conns)
{
2017-08-01 10:08:42 +00:00
if (conn.x0_state != EScriptObjectState::Default)
2016-04-29 10:08:46 +00:00
continue;
2017-01-15 03:07:01 +00:00
const CActor* act = TCastToConstPtr<CActor>(mgr.GetObjectById(mgr.GetIdForScript(conn.x8_objId)));
if (act && xc6_nextDrawNode == kInvalidUniqueId)
xc6_nextDrawNode = act->GetUniqueId();
2016-04-29 10:08:46 +00:00
}
break;
2018-05-18 04:16:33 +00:00
}
default:
break;
2016-04-29 10:08:46 +00:00
}
CEntity::AcceptScriptMsg(msg, uid, mgr);
}
2018-02-05 06:56:09 +00:00
void CActor::PreRender(CStateManager& mgr, const zeus::CFrustum& planes)
{
2018-02-05 06:56:09 +00:00
if (!x64_modelData || x64_modelData->IsNull())
return;
2018-02-05 06:56:09 +00:00
xe4_30_outOfFrustum = !planes.aabbFrustumTest(x9c_renderBounds);
if (!xe4_30_outOfFrustum)
{
2018-05-11 07:02:42 +00:00
xe7_28_worldLightingDirty = true;
2018-02-05 06:56:09 +00:00
bool lightsDirty = false;
if (xe4_29_actorLightsDirty)
{
xe4_29_actorLightsDirty = false;
lightsDirty = true;
xe5_25_shadowDirty = true;
}
else if (xe7_28_worldLightingDirty)
{
lightsDirty = true;
}
else if (x90_actorLights && x90_actorLights->GetIsDirty())
{
lightsDirty = true;
}
if (xe5_25_shadowDirty && xe5_24_shadowEnabled && x94_simpleShadow)
{
x94_simpleShadow->Calculate(x64_modelData->GetBounds(), x34_transform, mgr);
xe5_25_shadowDirty = false;
}
2018-05-11 07:02:42 +00:00
if (xe4_31_calculateLighting && x90_actorLights)
2018-02-05 06:56:09 +00:00
{
zeus::CAABox bounds = x64_modelData->GetBounds(x34_transform);
if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::Thermal)
{
x90_actorLights->BuildConstantAmbientLighting();
}
else
{
if (lightsDirty && x4_areaId != kInvalidAreaId)
{
const CGameArea* area = mgr.GetWorld()->GetAreaAlways(x4_areaId);
if (area->IsPostConstructed())
if (x90_actorLights->BuildAreaLightList(mgr, *area, bounds))
xe7_28_worldLightingDirty = false;
}
x90_actorLights->BuildDynamicLightList(mgr, bounds);
}
}
if (x64_modelData->HasAnimData())
x64_modelData->AnimationData()->PreRender();
}
else
{
if (xe4_29_actorLightsDirty)
{
xe4_29_actorLightsDirty = false;
xe5_25_shadowDirty = true;
}
if (xe5_25_shadowDirty && xe5_24_shadowEnabled && x94_simpleShadow)
{
zeus::CAABox bounds = x64_modelData->GetBounds(x34_transform);
if (planes.aabbFrustumTest(x94_simpleShadow->GetMaxShadowBox(bounds)))
{
x94_simpleShadow->Calculate(x64_modelData->GetBounds(), x34_transform, mgr);
xe5_25_shadowDirty = false;
}
}
}
}
2018-02-05 06:56:09 +00:00
void CActor::AddToRenderer(const zeus::CFrustum& planes, const CStateManager& mgr) const
{
2018-02-05 06:56:09 +00:00
if (!x64_modelData || x64_modelData->IsNull())
return;
if (xe6_29_renderParticleDBInside)
2018-02-05 06:56:09 +00:00
x64_modelData->RenderParticles(planes);
if (!xe4_30_outOfFrustum)
{
if (CanRenderUnsorted(mgr))
Render(mgr);
else
EnsureRendered(mgr);
}
if (mgr.GetPlayerState()->GetActiveVisor(mgr) != CPlayerState::EPlayerVisor::XRay &&
mgr.GetPlayerState()->GetActiveVisor(mgr) != CPlayerState::EPlayerVisor::Thermal &&
xe5_24_shadowEnabled && x94_simpleShadow->Valid() &&
planes.aabbFrustumTest(x94_simpleShadow->GetBounds()))
g_Renderer->AddDrawable(x94_simpleShadow.get(), x94_simpleShadow->GetTransform().origin,
x94_simpleShadow->GetBounds(), 1, CBooRenderer::EDrawableSorting::SortedCallback);
}
void CActor::DrawTouchBounds() const
{
// Empty
}
void CActor::RenderInternal(const CStateManager& mgr) const
{
CModelData::EWhichModel which = CModelData::GetRenderingModel(mgr);
if (which == CModelData::EWhichModel::ThermalHot)
{
if (x64_modelData->GetSortThermal())
{
float addMag;
float mulMag = 1.f;
if (xd0_thermalMag <= 1.f)
{
mulMag = xd0_thermalMag;
addMag = 0.f;
}
else if (xd0_thermalMag < 2.f)
{
addMag = xd0_thermalMag - 1.f;
}
else
{
addMag = 1.f;
}
zeus::CColor mulColor(mulMag * xb4_drawFlags.x4_color.a, xb4_drawFlags.x4_color.a);
zeus::CColor addColor(addMag, xb4_drawFlags.x4_color.a / 4.f);
x64_modelData->RenderThermal(x34_transform, mulColor, addColor, xb4_drawFlags);
return;
}
else if (mgr.GetThermalColdScale2() > 0.00001f && !xb4_drawFlags.x0_blendMode)
{
zeus::CColor color(zeus::clamp(0.f,
std::min((mgr.GetThermalColdScale2() + mgr.GetThermalColdScale1()) * mgr.GetThermalColdScale2(),
mgr.GetThermalColdScale2()), 1.f), 1.f);
CModelFlags flags(2, xb4_drawFlags.x1_matSetIdx, xb4_drawFlags.x2_flags, color);
x64_modelData->Render(mgr, x34_transform, x90_actorLights.get(), flags);
return;
}
}
x64_modelData->Render(which, x34_transform, x90_actorLights.get(), xb4_drawFlags);
}
bool CActor::IsModelOpaque(const CStateManager& mgr) const
{
if (xe5_31_pointGeneratorParticles)
return false;
if (!x64_modelData || x64_modelData->IsNull())
return true;
if (xb4_drawFlags.x0_blendMode > 4)
return false;
return x64_modelData->IsDefinitelyOpaque(CModelData::GetRenderingModel(mgr));
}
2018-02-05 06:56:09 +00:00
void CActor::Render(const CStateManager& mgr) const
{
2018-02-05 06:56:09 +00:00
if (x64_modelData && !x64_modelData->IsNull())
{
bool renderPrePostParticles = xe6_29_renderParticleDBInside && x64_modelData && x64_modelData->HasAnimData();
2018-02-05 06:56:09 +00:00
if (renderPrePostParticles)
x64_modelData->AnimationData()->GetParticleDB().RenderSystemsToBeDrawnFirst();
if (xe7_27_enableRender)
{
if (xe5_31_pointGeneratorParticles)
mgr.SetupParticleHook(*this);
if (xe5_29_globalTimeProvider)
{
RenderInternal(mgr);
}
else
{
float timeSince = CGraphics::GetSecondsMod900() - xbc_time;
float tpTime = timeSince - std::floor(timeSince / 900.f) * 900.f;
CTimeProvider tp(tpTime);
RenderInternal(mgr);
}
if (xe5_31_pointGeneratorParticles)
{
CSkinnedModel::ClearPointGeneratorFunc();
mgr.GetActorModelParticles()->Render(*this);
}
}
2018-02-05 06:56:09 +00:00
if (renderPrePostParticles)
x64_modelData->AnimationData()->GetParticleDB().RenderSystemsToBeDrawnLast();
}
DrawTouchBounds();
}
bool CActor::CanRenderUnsorted(const CStateManager& mgr) const
{
if (x64_modelData && x64_modelData->HasAnimData() &&
x64_modelData->GetAnimationData()->GetParticleDB().AreAnySystemsDrawnWithModel() &&
xe6_29_renderParticleDBInside)
return false;
else if (xe5_30_renderUnsorted || IsModelOpaque(mgr))
return true;
return false;
}
2016-11-20 21:53:15 +00:00
void CActor::CalculateRenderBounds()
{
2016-11-20 21:53:15 +00:00
if (x64_modelData && (x64_modelData->AnimationData() || x64_modelData->GetNormalModel()))
2017-08-10 07:05:27 +00:00
x9c_renderBounds = x64_modelData->GetBounds(x34_transform);
2016-11-20 21:53:15 +00:00
else
2017-08-10 07:05:27 +00:00
x9c_renderBounds = zeus::CAABox(x34_transform.origin, x34_transform.origin);
}
2017-08-20 05:23:22 +00:00
CHealthInfo* CActor::HealthInfo(CStateManager&) { return nullptr; }
const CDamageVulnerability* CActor::GetDamageVulnerability() const
{
return &CDamageVulnerability::NormalVulnerabilty();
}
const CDamageVulnerability* CActor::GetDamageVulnerability(const zeus::CVector3f&, const zeus::CVector3f&,
const CDamageInfo&) const
{
return GetDamageVulnerability();
}
std::experimental::optional<zeus::CAABox> CActor::GetTouchBounds() const { return {}; }
void CActor::Touch(CActor&, CStateManager&) {}
zeus::CVector3f CActor::GetOrbitPosition(const CStateManager&) const { return x34_transform.origin; }
zeus::CVector3f CActor::GetAimPosition(const CStateManager&, float) const { return x34_transform.origin; }
2016-05-03 08:27:28 +00:00
zeus::CVector3f CActor::GetHomingPosition(const CStateManager& mgr, float f) const { return GetAimPosition(mgr, f); }
zeus::CVector3f CActor::GetScanObjectIndicatorPosition(const CStateManager& mgr) const
{
const CGameCamera* cam = mgr.GetCameraManager()->GetCurrentCamera(mgr);
zeus::CVector3f orbitPos = GetOrbitPosition(mgr);
float camToOrbitPos = (cam->GetTranslation() - orbitPos).magnitude();
zeus::CVector3f boundsExtent = x9c_renderBounds.max - x9c_renderBounds.min;
float distFac = std::min(std::max(boundsExtent.x, std::max(boundsExtent.y, boundsExtent.z)) * 0.5f,
camToOrbitPos - cam->GetNearClipDistance() - 0.1f);
return orbitPos - (orbitPos - cam->GetTranslation()).normalized() * distFac;
}
2016-04-29 10:08:46 +00:00
void CActor::RemoveEmitter()
{
2017-06-03 06:03:07 +00:00
if (x8c_loopingSfxHandle)
2016-04-29 10:08:46 +00:00
{
2017-06-03 06:03:07 +00:00
CSfxManager::RemoveEmitter(x8c_loopingSfxHandle);
2016-04-29 10:08:46 +00:00
x88_sfxId = -1;
2017-06-03 06:03:07 +00:00
x8c_loopingSfxHandle.reset();
2016-04-29 10:08:46 +00:00
}
}
2017-07-14 05:14:19 +00:00
void CActor::SetVolume(float vol)
{
if (x8c_loopingSfxHandle)
CSfxManager::UpdateEmitter(x8c_loopingSfxHandle, GetTranslation(), zeus::CVector3f::skZero, vol);
}
2017-11-13 06:19:18 +00:00
const zeus::CTransform CActor::GetScaledLocatorTransform(std::string_view segName) const
2016-10-31 22:56:44 +00:00
{
return x64_modelData->GetScaledLocatorTransform(segName);
}
2017-11-13 06:19:18 +00:00
const zeus::CTransform CActor::GetLocatorTransform(std::string_view segName) const
2016-10-31 22:56:44 +00:00
{
return x64_modelData->GetLocatorTransform(segName);
}
EWeaponCollisionResponseTypes CActor::GetCollisionResponseType(const zeus::CVector3f&, const zeus::CVector3f&,
2018-02-12 05:30:21 +00:00
const CWeaponMode&, EProjectileAttrib) const
2016-05-03 08:27:28 +00:00
{
2018-02-12 05:30:21 +00:00
return EWeaponCollisionResponseTypes::OtherProjectile;
2016-05-03 08:27:28 +00:00
}
void CActor::FluidFXThink(CActor::EFluidState, CScriptWater&, CStateManager&) {}
void CActor::OnScanStateChanged(EScanState state, CStateManager& mgr)
{
2016-11-22 20:43:16 +00:00
if (state == EScanState::Start)
SendScriptMsgs(EScriptObjectState::ScanStart, mgr, EScriptObjectMessage::None);
else if (state == EScanState::Processing)
SendScriptMsgs(EScriptObjectState::ScanProcessing, mgr, EScriptObjectMessage::None);
else if (state == EScanState::Done)
SendScriptMsgs(EScriptObjectState::ScanDone, mgr, EScriptObjectMessage::None);
}
2017-08-10 07:05:27 +00:00
zeus::CAABox CActor::GetSortingBounds(const CStateManager&) const { return x9c_renderBounds; }
2018-01-15 12:36:04 +00:00
void CActor::DoUserAnimEvent(CStateManager&, CInt32POINode&, EUserEventType event, float)
{
if (event == EUserEventType::LoopedSoundStop)
RemoveEmitter();
}
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, EMaterialTypes t4,
CStateManager& mgr)
2016-04-22 20:22:45 +00:00
{
x68_material.Remove(t1);
2016-04-22 20:22:45 +00:00
RemoveMaterial(t2, t3, t4, mgr);
}
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, CStateManager& mgr)
2016-04-22 20:22:45 +00:00
{
x68_material.Remove(t1);
2016-04-22 20:22:45 +00:00
RemoveMaterial(t2, t3, mgr);
}
2018-01-15 12:36:04 +00:00
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, CStateManager& mgr)
{
x68_material.Remove(t1);
RemoveMaterial(t2, mgr);
}
2016-04-22 20:22:45 +00:00
void CActor::RemoveMaterial(EMaterialTypes t, CStateManager& mgr)
{
x68_material.Remove(t);
2016-04-22 20:22:45 +00:00
mgr.UpdateObjectInLists(*this);
}
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, EMaterialTypes t4, EMaterialTypes t5,
CStateManager& mgr)
2016-04-22 20:22:45 +00:00
{
x68_material.Add(t1);
2016-04-22 20:22:45 +00:00
AddMaterial(t2, t3, t4, t5, mgr);
}
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, EMaterialTypes t4, CStateManager& mgr)
{
x68_material.Add(t1);
2016-04-22 20:22:45 +00:00
AddMaterial(t2, t3, t4, mgr);
}
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, CStateManager& mgr)
{
x68_material.Add(t1);
2016-04-22 20:22:45 +00:00
AddMaterial(t2, t3, mgr);
}
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, CStateManager& mgr)
{
x68_material.Add(t1);
2016-04-22 20:22:45 +00:00
AddMaterial(t2, mgr);
}
void CActor::AddMaterial(EMaterialTypes type, CStateManager& mgr)
2016-04-19 00:17:49 +00:00
{
x68_material.Add(type);
2016-04-22 20:22:45 +00:00
mgr.UpdateObjectInLists(*this);
2016-04-19 00:17:49 +00:00
}
2017-03-26 04:12:06 +00:00
void CActor::AddMaterial(const CMaterialList& l)
{
x68_material.Add(l);
}
2017-02-03 23:32:15 +00:00
void CActor::CreateShadow(bool b)
{
if (b)
{
_CreateShadow();
2018-02-05 06:56:09 +00:00
if (!xe5_24_shadowEnabled && x94_simpleShadow)
xe5_25_shadowDirty = true;
2017-02-03 23:32:15 +00:00
}
2018-02-05 06:56:09 +00:00
xe5_24_shadowEnabled = b;
2017-02-03 23:32:15 +00:00
}
void CActor::_CreateShadow()
{
if (!x94_simpleShadow && x64_modelData && (x64_modelData->HasAnimData() || x64_modelData->HasNormalModel()))
x94_simpleShadow.reset(new CSimpleShadow(1.f, 1.f, 20.f, 0.05f));
}
void CActor::SetCallTouch(bool callTouch) { xe5_28_callTouch = callTouch; }
2016-05-03 08:27:28 +00:00
bool CActor::GetCallTouch() const { return xe5_28_callTouch; }
2016-05-03 08:27:28 +00:00
2017-02-14 04:27:20 +00:00
void CActor::SetUseInSortedLists(bool use) { xe5_27_useInSortedLists = use; }
2016-05-03 08:27:28 +00:00
bool CActor::GetUseInSortedLists() const { return xe5_27_useInSortedLists; }
2016-05-03 08:27:28 +00:00
void CActor::SetInFluid(bool in, TUniqueId uid)
{
if (in)
{
2017-06-12 04:23:34 +00:00
xe6_24_fluidCounter += 1;
2016-05-03 08:27:28 +00:00
xc4_fluidId = uid;
}
else
{
2017-06-12 04:23:34 +00:00
if (!xe6_24_fluidCounter)
2016-05-03 08:27:28 +00:00
return;
2017-06-12 04:23:34 +00:00
xe6_24_fluidCounter -= 1;
if (xe6_24_fluidCounter == 0)
2016-05-03 08:27:28 +00:00
xc4_fluidId = kInvalidUniqueId;
}
}
bool CActor::HasModelData() const { return bool(x64_modelData); }
2016-05-03 08:27:28 +00:00
2017-06-03 06:03:07 +00:00
void CActor::SetSoundEventPitchBend(s32 val)
2016-05-03 08:27:28 +00:00
{
xe6_30_enablePitchBend = true;
2017-07-16 06:13:37 +00:00
xc0_pitchBend = val / 8192.f - 1.f;
2017-06-03 06:03:07 +00:00
if (!x8c_loopingSfxHandle)
2016-05-03 08:27:28 +00:00
return;
2017-07-16 06:13:37 +00:00
CSfxManager::PitchBend(x8c_loopingSfxHandle, xc0_pitchBend);
2016-04-29 10:08:46 +00:00
}
2017-01-21 06:03:37 +00:00
void CActor::SetRotation(const zeus::CQuaternion &q)
{
x34_transform = q.toTransform(x34_transform.origin);
2017-11-26 03:04:25 +00:00
xe4_27_notInSortedLists = true;
xe4_28_transformDirty = true;
2017-08-13 07:56:35 +00:00
xe4_29_actorLightsDirty = true;
2017-01-21 06:03:37 +00:00
}
void CActor::SetTranslation(const zeus::CVector3f& tr)
2016-09-01 04:10:08 +00:00
{
x34_transform.origin = tr;
2017-11-26 03:04:25 +00:00
xe4_27_notInSortedLists = true;
xe4_28_transformDirty = true;
2017-08-13 07:56:35 +00:00
xe4_29_actorLightsDirty = true;
2016-09-01 04:10:08 +00:00
}
2017-01-24 17:23:10 +00:00
void CActor::SetTransform(const zeus::CTransform& tr)
{
x34_transform = tr;
2017-11-26 03:04:25 +00:00
xe4_27_notInSortedLists = true;
xe4_28_transformDirty = true;
2017-08-13 07:56:35 +00:00
xe4_29_actorLightsDirty = true;
2017-01-24 17:23:10 +00:00
}
void CActor::SetAddedToken(u32 tok) { xcc_addedToken = tok; }
2016-11-20 21:53:15 +00:00
float CActor::GetPitch() const { return zeus::CQuaternion(x34_transform.buildMatrix3f()).pitch(); }
2016-10-31 22:56:44 +00:00
float CActor::GetYaw() const { return zeus::CQuaternion(x34_transform.buildMatrix3f()).yaw(); }
2017-02-11 00:52:52 +00:00
2018-02-05 06:56:09 +00:00
void CActor::EnsureRendered(const CStateManager& mgr) const
2017-08-18 01:30:15 +00:00
{
zeus::CAABox aabb = GetSortingBounds(mgr);
EnsureRendered(mgr, aabb.closestPointAlongVector(CGraphics::g_ViewMatrix.origin), aabb);
}
2017-03-20 05:09:53 +00:00
void CActor::EnsureRendered(const CStateManager& stateMgr, const zeus::CVector3f& pos,
const zeus::CAABox& aabb) const
{
if (x64_modelData)
{
x64_modelData->RenderUnsortedParts(x64_modelData->GetRenderingModel(stateMgr),
x34_transform, x90_actorLights.get(), xb4_drawFlags);
}
stateMgr.AddDrawableActor(*this, pos, aabb);
}
2017-06-03 06:03:07 +00:00
void CActor::UpdateSfxEmitters()
{
for (CSfxHandle& sfx : xd8_nonLoopingSfxHandles)
CSfxManager::UpdateEmitter(sfx, x34_transform.origin, zeus::CVector3f::skZero, xd4_maxVol);
}
void CActor::ProcessSoundEvent(u32 sfxId, float weight, u32 flags, float falloff, float maxDist,
float minVol, float maxVol, const zeus::CVector3f& toListener,
const zeus::CVector3f& position, TAreaId aid, CStateManager& mgr,
bool translateId)
2017-02-11 00:52:52 +00:00
{
2017-06-03 06:03:07 +00:00
if (toListener.magSquared() >= maxDist * maxDist)
return;
u16 id = translateId ? CSfxManager::TranslateSFXID(sfxId) : sfxId;
u32 musyxFlags = 0x1; // Continuous parameter update
if (flags & 0x8)
musyxFlags |= 0x8; // Doppler FX
CAudioSys::C3DEmitterParmData parms;
parms.x0_pos = position;
parms.xc_dir = zeus::CVector3f::skZero;
parms.x18_maxDist = maxDist;
parms.x1c_distComp = falloff;
parms.x20_flags = musyxFlags;
parms.x24_sfxId = id;
parms.x26_maxVol = maxVol;
parms.x27_minVol = minVol;
parms.x28_important = false;
parms.x29_prio = 0x7f;
bool useAcoustics = (flags & 0x80) == 0;
bool looping = (sfxId & 0x80000000) != 0;
bool nonEmitter = (sfxId & 0x40000000) != 0;
bool continuousUpdate = (sfxId & 0x20000000) != 0;
if (mgr.GetActiveRandom()->Float() > weight)
return;
if (looping)
{
u16 curId = x88_sfxId;
if (!x8c_loopingSfxHandle)
{
CSfxHandle handle;
if (nonEmitter)
handle = CSfxManager::SfxStart(id, 1.f, 0.f, true, 0x7f, true, aid);
else
handle = CSfxManager::AddEmitter(parms, useAcoustics, 0x7f, true, aid);
if (handle)
{
x88_sfxId = id;
x8c_loopingSfxHandle = handle;
if (xe6_30_enablePitchBend)
CSfxManager::PitchBend(handle, xc0_pitchBend);
}
}
else if (curId == id)
{
CSfxManager::UpdateEmitter(x8c_loopingSfxHandle, position, zeus::CVector3f::skZero, maxVol);
}
else if (flags & 0x4)
{
CSfxManager::RemoveEmitter(x8c_loopingSfxHandle);
CSfxHandle handle = CSfxManager::AddEmitter(parms, useAcoustics, 0x7f, true, aid);
if (handle)
{
x88_sfxId = id;
x8c_loopingSfxHandle = handle;
if (xe6_30_enablePitchBend)
CSfxManager::PitchBend(handle, xc0_pitchBend);
}
}
}
else
{
CSfxHandle handle;
if (nonEmitter)
handle = CSfxManager::SfxStart(id, 1.f, 0.f, useAcoustics, 0x7f, false, aid);
else
handle = CSfxManager::AddEmitter(parms, useAcoustics, 0x7f, false, aid);
if (continuousUpdate)
{
xd8_nonLoopingSfxHandles[xe4_24_nextNonLoopingSfxHandle] = handle;
xe4_24_nextNonLoopingSfxHandle = (xe4_24_nextNonLoopingSfxHandle + 1) % xd8_nonLoopingSfxHandles.size();
}
if (xe6_30_enablePitchBend)
CSfxManager::PitchBend(handle, xc0_pitchBend);
}
}
SAdvancementDeltas CActor::UpdateAnimation(float dt, CStateManager& mgr, bool advTree)
{
SAdvancementDeltas deltas = x64_modelData->AdvanceAnimation(dt, mgr, GetAreaId(), advTree);
x64_modelData->AdvanceParticles(x34_transform, dt, mgr);
UpdateSfxEmitters();
if (x64_modelData && x64_modelData->HasAnimData())
{
zeus::CVector3f toCamera =
mgr.GetCameraManager()->GetCurrentCamera(mgr)->GetTranslation() - x34_transform.origin;
for (int i=0 ; i<x64_modelData->GetAnimationData()->GetPassedSoundPOICount() ; ++i)
{
CSoundPOINode& poi = CAnimData::g_SoundPOINodes[i];
if (poi.GetPoiType() != EPOIType::Sound)
continue;
if (xe5_26_muted)
continue;
if (poi.GetCharacterIndex() != -1 &&
x64_modelData->GetAnimationData()->GetCharacterIndex() != poi.GetCharacterIndex())
continue;
ProcessSoundEvent(poi.GetSfxId(), poi.GetWeight(), poi.GetFlags(), poi.GetFalloff(),
poi.GetMaxDist(), 0.16f, xd4_maxVol, toCamera, x34_transform.origin, x4_areaId,
mgr, true);
}
for (int i=0 ; i<x64_modelData->GetAnimationData()->GetPassedIntPOICount() ; ++i)
{
CInt32POINode& poi = CAnimData::g_Int32POINodes[i];
if (poi.GetPoiType() == EPOIType::SoundInt32)
{
if (xe5_26_muted)
continue;
if (poi.GetCharacterIndex() != -1 &&
x64_modelData->GetAnimationData()->GetCharacterIndex() != poi.GetCharacterIndex())
continue;
ProcessSoundEvent(poi.GetValue(), poi.GetWeight(), poi.GetFlags(), 0.1f,
150.f, 0.16f, xd4_maxVol, toCamera, x34_transform.origin, x4_areaId,
mgr, true);
}
else if (poi.GetPoiType() == EPOIType::UserEvent)
{
DoUserAnimEvent(mgr, poi, EUserEventType(poi.GetValue()), dt);
}
}
for (int i=0 ; i<x64_modelData->GetAnimationData()->GetPassedParticlePOICount() ; ++i)
{
CParticlePOINode& poi = CAnimData::g_ParticlePOINodes[i];
if (poi.GetCharacterIndex() != -1 &&
x64_modelData->GetAnimationData()->GetCharacterIndex() != poi.GetCharacterIndex())
continue;
x64_modelData->AnimationData()->GetParticleDB().SetParticleEffectState(poi.GetString(), true, mgr);
}
}
return deltas;
2017-02-11 00:52:52 +00:00
}
2017-09-30 03:45:57 +00:00
void CActor::SetActorLights(std::unique_ptr<CActorLights>&& lights)
{
x90_actorLights = std::move(lights);
2018-05-11 07:02:42 +00:00
xe4_31_calculateLighting = true;
}
2017-03-05 07:57:12 +00:00
bool CActor::CanDrawStatic() const
{
if (!x30_24_active)
return false;
if (x64_modelData && x64_modelData->HasNormalModel())
2017-03-20 05:09:53 +00:00
return xb4_drawFlags.x0_blendMode <= 4;
2017-03-05 07:57:12 +00:00
return false;
}
2017-04-02 03:03:37 +00:00
const CScannableObjectInfo* CActor::GetScannableObjectInfo() const
{
2017-11-24 08:23:28 +00:00
if (!x98_scanObjectInfo || !x98_scanObjectInfo.IsLoaded())
2017-04-02 03:03:37 +00:00
return nullptr;
2017-11-24 08:23:28 +00:00
return x98_scanObjectInfo.GetObj();
2017-04-02 03:03:37 +00:00
}
void CActor::SetCalculateLighting(bool c)
{
if (!x90_actorLights)
x90_actorLights = std::make_unique<CActorLights>(8, zeus::CVector3f::skZero,
4, 4, false, false, false, 0.1f);
2018-05-11 07:02:42 +00:00
xe4_31_calculateLighting = c;
}
2017-07-10 04:55:51 +00:00
float CActor::GetAverageAnimVelocity(int anim) const
{
if (HasModelData() && GetModelData()->HasAnimData())
return GetModelData()->GetAnimationData()->GetAverageVelocity(anim);
return 0.f;
}
2017-08-18 01:30:15 +00:00
void CActor::SetModelData(std::unique_ptr<CModelData>&& mData)
{
if (mData->IsNull())
x64_modelData.reset();
else
x64_modelData = std::move(mData);
}
}