metaforce/Runtime/World/CActor.cpp

709 lines
25 KiB
C++
Raw Normal View History

#include "Runtime/World/CActor.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/CTimeProvider.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Audio/CSfxManager.hpp"
#include "Runtime/Camera/CGameCamera.hpp"
#include "Runtime/Character/CActorLights.hpp"
#include "Runtime/Character/IAnimReader.hpp"
#include "Runtime/Collision/CMaterialList.hpp"
#include "Runtime/Graphics/CBooRenderer.hpp"
#include "Runtime/Graphics/CSkinnedModel.hpp"
#include "Runtime/World/CActorParameters.hpp"
#include "Runtime/World/CWorld.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
#include <hecl/CVarManager.hpp>
2021-04-10 08:42:06 +00:00
namespace metaforce {
2018-12-08 05:30:43 +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);
return ret;
2016-04-22 20:22:45 +00:00
}
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)
, xe5_29_globalTimeProvider(params.x58_24_globalTimeProvider)
, xe5_30_renderUnsorted(params.x58_26_renderUnsorted)
, xe6_27_thermalVisorFlags(u8(params.x58_25_thermalHeat ? 2 : 1))
, xe6_31_targetableVisorFlags(params.GetVisorParameters().GetMask())
, xe7_29_drawEnabled(active) {
x90_actorLights = mData.IsNull() ? nullptr : params.x0_lightParms.MakeActorLights();
2018-12-08 05:30:43 +00:00
if (mData.x10_animData || mData.x1c_normalModel)
x64_modelData = std::make_unique<CModelData>(std::move(mData));
xd0_damageMag = params.x64_thermalMag;
xd8_nonLoopingSfxHandles.resize(2);
2018-12-08 05:30:43 +00:00
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;
}
if (params.x40_scanParms.GetScanId().IsValid())
x98_scanObjectInfo = g_SimplePool->GetObj(SObjectTag{FOURCC('SCAN'), params.x40_scanParms.GetScanId()});
}
void CActor::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
switch (msg) {
case EScriptObjectMessage::Activate: {
if (!x30_24_active)
xbc_time = CGraphics::GetSecondsMod900();
break;
}
case EScriptObjectMessage::Deactivate:
RemoveEmitter();
break;
case EScriptObjectMessage::Deleted: // 34
{
RemoveEmitter();
2019-02-08 07:56:54 +00:00
if (HasModelData() && !x64_modelData->IsNull())
if (CAnimData* aData = x64_modelData->GetAnimationData())
2019-02-08 07:56:54 +00:00
aData->GetParticleDB().DeleteAllLights(mgr);
2018-12-08 05:30:43 +00:00
break;
}
case EScriptObjectMessage::Registered: // 33
{
if (x98_scanObjectInfo)
AddMaterial(EMaterialTypes::Scannable, mgr);
else
RemoveMaterial(EMaterialTypes::Scannable, mgr);
2016-04-22 20:22:45 +00:00
if (HasModelData() && x64_modelData->HasAnimData()) {
2018-12-08 05:30:43 +00:00
TAreaId aid = GetAreaId();
x64_modelData->GetAnimationData()->InitializeEffects(mgr, aid, x64_modelData->GetScale());
2018-05-18 04:16:33 +00:00
}
2018-12-08 05:30:43 +00:00
break;
}
case EScriptObjectMessage::UpdateSplashInhabitant: // 37
SetInFluid(true, uid);
break;
case EScriptObjectMessage::RemoveSplashInhabitant: // 39
SetInFluid(false, kInvalidUniqueId);
break;
case EScriptObjectMessage::InitializedInArea: // 35
{
for (const SConnection& conn : x20_conns) {
if (conn.x0_state != EScriptObjectState::Default)
continue;
const CActor* act = TCastToConstPtr<CActor>(mgr.GetObjectById(mgr.GetIdForScript(conn.x8_objId)));
if (act && xc6_nextDrawNode == kInvalidUniqueId)
xc6_nextDrawNode = act->GetUniqueId();
2018-05-18 04:16:33 +00:00
}
2018-12-08 05:30:43 +00:00
break;
}
default:
break;
}
CEntity::AcceptScriptMsg(msg, uid, mgr);
}
void CActor::PreRender(CStateManager& mgr, const zeus::CFrustum& planes) {
if (!x64_modelData || x64_modelData->IsNull())
return;
xe4_30_outOfFrustum = !planes.aabbFrustumTest(x9c_renderBounds);
if (!xe4_30_outOfFrustum) {
xe7_28_worldLightingDirty = true;
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;
2016-04-29 10:08:46 +00:00
}
2018-02-05 06:56:09 +00:00
2018-12-08 05:30:43 +00:00
if (xe5_25_shadowDirty && xe5_24_shadowEnabled && x94_simpleShadow) {
x94_simpleShadow->Calculate(x64_modelData->GetBounds(), x34_transform, mgr);
xe5_25_shadowDirty = false;
}
2018-02-05 06:56:09 +00:00
2018-12-08 05:30:43 +00:00
if (xe4_31_calculateLighting && x90_actorLights) {
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;
2018-02-05 06:56:09 +00:00
}
2018-12-08 05:30:43 +00:00
x90_actorLights->BuildDynamicLightList(mgr, bounds);
}
}
2018-02-05 06:56:09 +00:00
2018-12-08 05:30:43 +00:00
if (x64_modelData->HasAnimData())
x64_modelData->GetAnimationData()->PreRender();
2018-12-08 05:30:43 +00:00
} else {
if (xe4_29_actorLightsDirty) {
xe4_29_actorLightsDirty = false;
xe5_25_shadowDirty = true;
2018-02-05 06:56:09 +00:00
}
2018-12-08 05:30:43 +00:00
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
}
2018-12-08 05:30:43 +00:00
}
}
void CActor::AddToRenderer(const zeus::CFrustum& planes, CStateManager& mgr) {
if (!x64_modelData || x64_modelData->IsNull()) {
2018-12-08 05:30:43 +00:00
return;
}
if (xe6_29_renderParticleDBInside) {
2018-12-08 05:30:43 +00:00
x64_modelData->RenderParticles(planes);
}
2018-02-05 06:56:09 +00:00
2018-12-08 05:30:43 +00:00
if (!xe4_30_outOfFrustum) {
if (CanRenderUnsorted(mgr)) {
2018-12-08 05:30:43 +00:00
Render(mgr);
} else {
2018-12-08 05:30:43 +00:00
EnsureRendered(mgr);
}
2018-12-08 05:30:43 +00:00
}
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())) {
2018-12-08 05:30:43 +00:00
g_Renderer->AddDrawable(x94_simpleShadow.get(), x94_simpleShadow->GetTransform().origin,
x94_simpleShadow->GetBounds(), 1, CBooRenderer::EDrawableSorting::SortedCallback);
}
2018-12-08 05:30:43 +00:00
}
void CActor::DrawTouchBounds() const {
// Empty
}
void CActor::RenderInternal(const CStateManager& mgr) const {
2020-01-21 04:00:40 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP(
2020-04-11 22:51:39 +00:00
fmt::format(FMT_STRING("CActor::RenderInternal {} {} {}"), x8_uid, xc_editorId, x10_name).c_str(), zeus::skOrange);
2019-07-21 08:42:52 +00:00
2018-12-08 05:30:43 +00:00
CModelData::EWhichModel which = CModelData::GetRenderingModel(mgr);
if (which == CModelData::EWhichModel::ThermalHot) {
if (x64_modelData->GetSortThermal()) {
float addMag;
float mulMag = 1.f;
if (xd0_damageMag <= 1.f) {
mulMag = xd0_damageMag;
addMag = 0.f;
} else if (xd0_damageMag < 2.f) {
addMag = xd0_damageMag - 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);
2021-05-26 15:11:21 +00:00
if (m_debugSelected) {
addColor += m_debugAddColor;
}
2018-12-08 05:30:43 +00:00
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);
2021-05-26 15:11:21 +00:00
if (m_debugSelected) {
flags.addColor += m_debugAddColor;
}
2018-12-08 05:30:43 +00:00
x64_modelData->Render(mgr, x34_transform, x90_actorLights.get(), flags);
return;
2018-02-05 06:56:09 +00:00
}
2018-12-08 05:30:43 +00:00
}
2021-05-26 15:11:21 +00:00
CModelFlags flags = xb4_drawFlags;
if (m_debugSelected) {
flags.addColor += m_debugAddColor;
}
x64_modelData->Render(which, x34_transform, x90_actorLights.get(), flags);
2018-12-08 05:30:43 +00:00
}
2018-02-05 06:56:09 +00:00
2018-12-08 05:30:43 +00:00
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));
}
void CActor::Render(CStateManager& mgr) {
2018-12-08 05:30:43 +00:00
if (x64_modelData && !x64_modelData->IsNull()) {
bool renderPrePostParticles = xe6_29_renderParticleDBInside && x64_modelData && x64_modelData->HasAnimData();
if (renderPrePostParticles)
x64_modelData->GetAnimationData()->GetParticleDB().RenderSystemsToBeDrawnFirst();
2018-12-08 05:30:43 +00:00
if (xe7_27_enableRender) {
if (xe5_31_pointGeneratorParticles)
mgr.SetupParticleHook(*this);
if (xe5_29_globalTimeProvider) {
RenderInternal(mgr);
} else {
2020-01-21 04:00:40 +00:00
const float timeSince = CGraphics::GetSecondsMod900() - xbc_time;
const float tpTime = timeSince - std::floor(timeSince / 900.f) * 900.f;
2018-12-08 05:30:43 +00:00
CTimeProvider tp(tpTime);
RenderInternal(mgr);
}
if (xe5_31_pointGeneratorParticles) {
CSkinnedModel::ClearPointGeneratorFunc();
2018-12-13 07:39:16 +00:00
mgr.GetActorModelParticles()->Render(mgr, *this);
2018-12-08 05:30:43 +00:00
}
2018-02-05 06:56:09 +00:00
}
2018-12-08 05:30:43 +00:00
if (renderPrePostParticles)
x64_modelData->GetAnimationData()->GetParticleDB().RenderSystemsToBeDrawnLast();
2018-12-08 05:30:43 +00:00
}
DrawTouchBounds();
}
2018-12-08 05:30:43 +00:00
bool CActor::CanRenderUnsorted(const CStateManager& mgr) const {
if (x64_modelData && x64_modelData->HasAnimData() &&
x64_modelData->GetAnimationData()->GetParticleDB().AreAnySystemsDrawnWithModel() && xe6_29_renderParticleDBInside)
return false;
2018-12-08 05:30:43 +00:00
else if (xe5_30_renderUnsorted || IsModelOpaque(mgr))
return true;
return false;
}
2018-12-08 05:30:43 +00:00
void CActor::CalculateRenderBounds() {
if (x64_modelData && (x64_modelData->GetAnimationData() || x64_modelData->GetNormalModel()))
2018-12-08 05:30:43 +00:00
x9c_renderBounds = x64_modelData->GetBounds(x34_transform);
else
x9c_renderBounds = zeus::CAABox(x34_transform.origin, x34_transform.origin);
}
2017-08-20 05:23:22 +00:00
CHealthInfo* CActor::HealthInfo(CStateManager&) { return nullptr; }
2018-12-08 05:30:43 +00:00
const CDamageVulnerability* CActor::GetDamageVulnerability() const {
return &CDamageVulnerability::NormalVulnerabilty();
}
const CDamageVulnerability* CActor::GetDamageVulnerability(const zeus::CVector3f&, const zeus::CVector3f&,
2018-12-08 05:30:43 +00:00
const CDamageInfo&) const {
return GetDamageVulnerability();
}
std::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); }
2018-12-08 05:30:43 +00:00
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();
const 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;
}
void CActor::RemoveEmitter() {
if (x8c_loopingSfxHandle) {
CSfxManager::RemoveEmitter(x8c_loopingSfxHandle);
x88_sfxId = -1;
x8c_loopingSfxHandle.reset();
}
2016-04-29 10:08:46 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::SetVolume(float vol) {
if (x8c_loopingSfxHandle)
CSfxManager::UpdateEmitter(x8c_loopingSfxHandle, GetTranslation(), zeus::skZero3f, vol);
2018-12-08 05:30:43 +00:00
xd4_maxVol = vol;
2017-07-14 05:14:19 +00:00
}
zeus::CTransform CActor::GetScaledLocatorTransform(std::string_view segName) const {
2018-12-08 05:30:43 +00:00
return x64_modelData->GetScaledLocatorTransform(segName);
2016-10-31 22:56:44 +00:00
}
zeus::CTransform CActor::GetLocatorTransform(std::string_view segName) const {
2018-12-08 05:30:43 +00:00
return x64_modelData->GetLocatorTransform(segName);
2016-10-31 22:56:44 +00:00
}
EWeaponCollisionResponseTypes CActor::GetCollisionResponseType(const zeus::CVector3f&, const zeus::CVector3f&,
2018-12-08 05:30:43 +00:00
const CWeaponMode&, EProjectileAttrib) const {
return EWeaponCollisionResponseTypes::OtherProjectile;
2016-05-03 08:27:28 +00:00
}
void CActor::FluidFXThink(CActor::EFluidState, CScriptWater&, CStateManager&) {}
2018-12-08 05:30:43 +00:00
void CActor::OnScanStateChanged(EScanState state, CStateManager& mgr) {
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-12-08 05:30:43 +00:00
void CActor::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType event, float dt) {
if (event == EUserEventType::LoopedSoundStop)
RemoveEmitter();
2018-01-15 12:36:04 +00:00
}
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, EMaterialTypes t4,
2018-12-08 05:30:43 +00:00
CStateManager& mgr) {
x68_material.Remove(t1);
RemoveMaterial(t2, t3, t4, mgr);
2016-04-22 20:22:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, CStateManager& mgr) {
x68_material.Remove(t1);
RemoveMaterial(t2, t3, mgr);
2016-04-22 20:22:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, CStateManager& mgr) {
x68_material.Remove(t1);
RemoveMaterial(t2, mgr);
2018-01-15 12:36:04 +00:00
}
2016-04-22 20:22:45 +00:00
2018-12-08 05:30:43 +00:00
void CActor::RemoveMaterial(EMaterialTypes t, CStateManager& mgr) {
x68_material.Remove(t);
mgr.UpdateObjectInLists(*this);
2016-04-22 20:22:45 +00:00
}
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, EMaterialTypes t4, EMaterialTypes t5,
2018-12-08 05:30:43 +00:00
CStateManager& mgr) {
x68_material.Add(t1);
AddMaterial(t2, t3, t4, t5, mgr);
2016-04-22 20:22:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, EMaterialTypes t4,
CStateManager& mgr) {
x68_material.Add(t1);
AddMaterial(t2, t3, t4, mgr);
2016-04-22 20:22:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, CStateManager& mgr) {
x68_material.Add(t1);
AddMaterial(t2, t3, mgr);
2016-04-22 20:22:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, CStateManager& mgr) {
x68_material.Add(t1);
AddMaterial(t2, mgr);
2016-04-22 20:22:45 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::AddMaterial(EMaterialTypes type, CStateManager& mgr) {
x68_material.Add(type);
mgr.UpdateObjectInLists(*this);
2016-04-19 00:17:49 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::AddMaterial(const CMaterialList& l) { x68_material.Add(l); }
2017-03-26 04:12:06 +00:00
2019-11-09 23:48:46 +00:00
void CActor::CreateShadow(bool enabled) {
if (enabled) {
2018-12-08 05:30:43 +00:00
_CreateShadow();
if (!xe5_24_shadowEnabled && x94_simpleShadow)
xe5_25_shadowDirty = true;
}
2019-11-09 23:48:46 +00:00
xe5_24_shadowEnabled = enabled;
2017-02-03 23:32:15 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::_CreateShadow() {
if (!x94_simpleShadow && x64_modelData && (x64_modelData->HasAnimData() || x64_modelData->HasNormalModel())) {
x94_simpleShadow = std::make_unique<CSimpleShadow>(1.f, 1.f, 20.f, 0.05f);
}
2017-02-03 23:32:15 +00:00
}
2019-06-01 03:41:01 +00:00
void CActor::_CreateReflectionCube() {
2019-06-06 00:07:50 +00:00
if (hecl::com_cubemaps->toBoolean()) {
CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
m_reflectionCube = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS);
return true;
} BooTrace);
}
2019-06-01 03:41:01 +00:00
}
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
2018-12-08 05:30:43 +00:00
void CActor::SetInFluid(bool in, TUniqueId uid) {
if (in) {
xe6_24_fluidCounter += 1;
xc4_fluidId = uid;
} else {
if (!xe6_24_fluidCounter)
return;
2016-05-03 08:27:28 +00:00
2018-12-08 05:30:43 +00:00
xe6_24_fluidCounter -= 1;
if (xe6_24_fluidCounter == 0)
xc4_fluidId = kInvalidUniqueId;
}
2016-05-03 08:27:28 +00:00
}
bool CActor::HasModelData() const { return bool(x64_modelData); }
2016-05-03 08:27:28 +00:00
2018-12-08 05:30:43 +00:00
void CActor::SetSoundEventPitchBend(s32 val) {
xe6_30_enablePitchBend = true;
xc0_pitchBend = val / 8192.f - 1.f;
if (!x8c_loopingSfxHandle)
return;
2016-05-03 08:27:28 +00:00
2018-12-08 05:30:43 +00:00
CSfxManager::PitchBend(x8c_loopingSfxHandle, xc0_pitchBend);
2016-04-29 10:08:46 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::SetRotation(const zeus::CQuaternion& q) {
x34_transform = q.toTransform(x34_transform.origin);
xe4_27_notInSortedLists = true;
xe4_28_transformDirty = true;
xe4_29_actorLightsDirty = true;
2017-01-21 06:03:37 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::SetTranslation(const zeus::CVector3f& tr) {
x34_transform.origin = tr;
xe4_27_notInSortedLists = true;
xe4_28_transformDirty = true;
xe4_29_actorLightsDirty = true;
2016-09-01 04:10:08 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::SetTransform(const zeus::CTransform& tr) {
x34_transform = tr;
xe4_27_notInSortedLists = true;
xe4_28_transformDirty = true;
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
void CActor::EnsureRendered(const CStateManager& mgr) {
const zeus::CAABox aabb = GetSortingBounds(mgr);
2018-12-08 05:30:43 +00:00
EnsureRendered(mgr, aabb.closestPointAlongVector(CGraphics::g_ViewMatrix.basis[1]), aabb);
}
void CActor::EnsureRendered(const CStateManager& stateMgr, const zeus::CVector3f& pos, const zeus::CAABox& aabb) {
2018-12-08 05:30:43 +00:00
if (x64_modelData) {
x64_modelData->RenderUnsortedParts(x64_modelData->GetRenderingModel(stateMgr), x34_transform, x90_actorLights.get(),
xb4_drawFlags);
}
stateMgr.AddDrawableActor(*this, pos, aabb);
}
void CActor::UpdateSfxEmitters() {
for (CSfxHandle& sfx : xd8_nonLoopingSfxHandles)
CSfxManager::UpdateEmitter(sfx, x34_transform.origin, zeus::skZero3f, xd4_maxVol);
2018-12-08 05:30:43 +00:00
}
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) {
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::skZero3f;
2018-12-08 05:30:43 +00:00
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::skZero3f, maxVol);
2018-12-08 05:30:43 +00:00
} 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);
}
2017-06-03 06:03:07 +00:00
}
2018-12-08 05:30:43 +00:00
} else {
CSfxHandle handle;
if (nonEmitter)
handle = CSfxManager::SfxStart(id, 1.f, 0.f, useAcoustics, 0x7f, false, aid);
2017-06-03 06:03:07 +00:00
else
2018-12-08 05:30:43 +00:00
handle = CSfxManager::AddEmitter(parms, useAcoustics, 0x7f, false, aid);
2017-06-03 06:03:07 +00:00
2018-12-08 05:30:43 +00:00
if (continuousUpdate) {
xd8_nonLoopingSfxHandles[xe4_24_nextNonLoopingSfxHandle] = handle;
xe4_24_nextNonLoopingSfxHandle = (xe4_24_nextNonLoopingSfxHandle + 1) % xd8_nonLoopingSfxHandles.size();
2017-06-03 06:03:07 +00:00
}
2018-12-08 05:30:43 +00:00
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);
}
2017-06-03 06:03:07 +00:00
2018-12-08 05:30:43 +00:00
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);
}
}
2017-06-03 06:03:07 +00:00
2018-12-08 05:30:43 +00:00
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->GetAnimationData()->GetParticleDB().SetParticleEffectState(poi.GetString(), true, mgr);
2017-06-03 06:03:07 +00:00
}
2018-12-08 05:30:43 +00:00
}
return deltas;
2017-02-11 00:52:52 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::SetActorLights(std::unique_ptr<CActorLights>&& lights) {
x90_actorLights = std::move(lights);
xe4_31_calculateLighting = true;
}
2017-03-05 07:57:12 +00:00
2018-12-08 05:30:43 +00:00
bool CActor::CanDrawStatic() const {
if (!x30_24_active)
return false;
2017-03-05 07:57:12 +00:00
2018-12-08 05:30:43 +00:00
if (x64_modelData && x64_modelData->HasNormalModel())
return xb4_drawFlags.x0_blendMode <= 4;
2017-03-05 07:57:12 +00:00
2018-12-08 05:30:43 +00:00
return false;
2017-03-05 07:57:12 +00:00
}
2017-04-02 03:03:37 +00:00
2018-12-08 05:30:43 +00:00
const CScannableObjectInfo* CActor::GetScannableObjectInfo() const {
if (!x98_scanObjectInfo || !x98_scanObjectInfo.IsLoaded())
return nullptr;
return x98_scanObjectInfo.GetObj();
2017-04-02 03:03:37 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::SetCalculateLighting(bool c) {
if (!x90_actorLights)
x90_actorLights = std::make_unique<CActorLights>(8, zeus::skZero3f, 4, 4, false, false, false, 0.1f);
2018-12-08 05:30:43 +00:00
xe4_31_calculateLighting = c;
}
2017-07-10 04:55:51 +00:00
2018-12-08 05:30:43 +00:00
float CActor::GetAverageAnimVelocity(int anim) const {
if (HasModelData() && GetModelData()->HasAnimData())
return GetModelData()->GetAnimationData()->GetAverageVelocity(anim);
return 0.f;
2017-07-10 04:55:51 +00:00
}
2017-08-18 01:30:15 +00:00
2018-12-08 05:30:43 +00:00
void CActor::SetModelData(std::unique_ptr<CModelData>&& mData) {
if (mData->IsNull())
x64_modelData.reset();
else
x64_modelData = std::move(mData);
2017-08-18 01:30:15 +00:00
}
2018-12-08 05:30:43 +00:00
void CActor::SetMuted(bool muted) {
xe5_26_muted = muted;
RemoveEmitter();
}
2018-11-17 05:05:57 +00:00
2018-12-08 05:30:43 +00:00
void CActor::MoveScannableObjectInfoToActor(CActor* act, CStateManager& mgr) {
if (!act)
return;
2018-11-17 05:05:57 +00:00
2019-01-05 03:28:02 +00:00
act->x98_scanObjectInfo = x98_scanObjectInfo;
x98_scanObjectInfo = TLockedToken<CScannableObjectInfo>();
2018-12-08 05:30:43 +00:00
act->AddMaterial(EMaterialTypes::Scannable, mgr);
RemoveMaterial(EMaterialTypes::Scannable, mgr);
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce