CSnakeWeedSwarm: Rendering & state fixes

This commit is contained in:
Luke Street 2020-03-01 02:52:17 -05:00
parent f064bc2f7b
commit 17b9813b3e
3 changed files with 36 additions and 44 deletions

View File

@ -80,10 +80,10 @@ void CSnakeWeedSwarm::Accept(urde::IVisitor& visitor) { visitor.Visit(this); }
void CSnakeWeedSwarm::AllocateSkinnedModels(CStateManager& mgr, CModelData::EWhichModel which) { void CSnakeWeedSwarm::AllocateSkinnedModels(CStateManager& mgr, CModelData::EWhichModel which) {
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
x1b0_modelData[i]->EnableLooping(true); const auto& modelData = x1b0_modelData[i];
x1b0_modelData[i]->AdvanceAnimation(x1b0_modelData[i]->GetAnimationData()->GetAnimTimeRemaining("Whole Body"sv) * modelData->EnableLooping(true);
(i * 0.25f), modelData->AdvanceAnimation(modelData->GetAnimationData()->GetAnimTimeRemaining("Whole Body"sv) * (i * 0.25f), mgr,
mgr, x4_areaId, true); x4_areaId, true);
} }
x1c4_which = which; x1c4_which = which;
} }
@ -109,8 +109,8 @@ void CSnakeWeedSwarm::PreRender(CStateManager& mgr, const zeus::CFrustum& frustu
} }
SetCalculateLighting(false); SetCalculateLighting(false);
for (int i = 0; i < 4; ++i) { for (const auto& modelData : x1b0_modelData) {
x1b0_modelData[i]->GetAnimationData()->PreRender(); modelData->GetAnimationData()->PreRender();
} }
if (x90_actorLights && x140_24_hasGround) { if (x90_actorLights && x140_24_hasGround) {
bool buildLights = false; bool buildLights = false;
@ -145,7 +145,7 @@ void CSnakeWeedSwarm::AddToRenderer(const zeus::CFrustum& frustum, const CStateM
g_Renderer->AddParticleGen(*x1f4_particleGen2); g_Renderer->AddParticleGen(*x1f4_particleGen2);
if (x90_actorLights) { if (x90_actorLights) {
for (auto modelData : x1b0_modelData) { for (const auto& modelData : x1b0_modelData) {
x90_actorLights->ActivateLights(*modelData->PickAnimatedModel(x1c4_which).GetModelInst()); x90_actorLights->ActivateLights(*modelData->PickAnimatedModel(x1c4_which).GetModelInst());
} }
} else { } else {
@ -165,7 +165,7 @@ void CSnakeWeedSwarm::Touch(CActor& actor, CStateManager& mgr) {
HandleRadiusDamage(x100_weaponDamageRadius, mgr, proj->GetTransform().origin); HandleRadiusDamage(x100_weaponDamageRadius, mgr, proj->GetTransform().origin);
} }
if (TCastToPtr<CPlayer> player = actor) { if (TCastToPtr<CPlayer> player = actor) {
for (auto boid : x134_boids) { for (const auto& boid : x134_boids) {
float m = (boid.GetPosition() - player->GetTransform().origin).magnitude(); float m = (boid.GetPosition() - player->GetTransform().origin).magnitude();
if (m < x104_ && boid.GetState() == EBoidState::Raised) { if (m < x104_ && boid.GetState() == EBoidState::Raised) {
mgr.SendScriptMsg(player, kInvalidUniqueId, EScriptObjectMessage::InSnakeWeed); mgr.SendScriptMsg(player, kInvalidUniqueId, EScriptObjectMessage::InSnakeWeed);
@ -177,13 +177,12 @@ void CSnakeWeedSwarm::Touch(CActor& actor, CStateManager& mgr) {
void CSnakeWeedSwarm::HandleRadiusDamage(float radius, CStateManager& mgr, const zeus::CVector3f& pos) { void CSnakeWeedSwarm::HandleRadiusDamage(float radius, CStateManager& mgr, const zeus::CVector3f& pos) {
float radiusSquared = radius * radius; float radiusSquared = radius * radius;
for (auto boid : x134_boids) { for (auto& boid : x134_boids) {
const zeus::CVector3f& boidPosition = boid.GetPosition(); const zeus::CVector3f& boidPosition = boid.GetPosition();
if ((boidPosition - pos).magSquared() < radiusSquared && if ((boidPosition - pos).magSquared() < radiusSquared &&
(boid.GetState() == EBoidState::Raised || boid.GetState() == EBoidState::x1)) { (boid.GetState() == EBoidState::Raised || boid.GetState() == EBoidState::Raising)) {
boid.SetState(EBoidState::x3); boid.SetState(EBoidState::x3);
float random = mgr.GetActiveRandom()->Float(); boid.Set_x18(x118_ * mgr.GetActiveRandom()->Float() + x114_);
boid.Set_x18(x118_ * random + x114_);
CSfxManager::AddEmitter(x1d2_sfx2, boidPosition, zeus::skZero3f, true, false, 0x7f, x4_areaId); CSfxManager::AddEmitter(x1d2_sfx2, boidPosition, zeus::skZero3f, true, false, 0x7f, x4_areaId);
EmitParticles1(boidPosition); EmitParticles1(boidPosition);
} }
@ -218,13 +217,13 @@ void CSnakeWeedSwarm::Think(float dt, CStateManager& mgr) {
if (x140_25_modelAssetDirty && x1c4_which != model) if (x140_25_modelAssetDirty && x1c4_which != model)
AllocateSkinnedModels(mgr, model); AllocateSkinnedModels(mgr, model);
for (int i = 0; i < 4; ++i) { for (const auto& modelData : x1b0_modelData) {
x1b0_modelData[i]->GetAnimationData()->SetPlaybackRate(1.f); modelData->GetAnimationData()->SetPlaybackRate(1.f);
x1b0_modelData[i]->AdvanceAnimation(dt, mgr, x4_areaId, true); modelData->AdvanceAnimation(dt, mgr, x4_areaId, true);
} }
int raisedBoids = 0; int raisedBoids = 0;
for (auto boid : x134_boids) { for (auto& boid : x134_boids) {
const zeus::CVector3f& pos = boid.GetPosition(); const zeus::CVector3f& pos = boid.GetPosition();
EBoidState state = boid.GetState(); EBoidState state = boid.GetState();
if (state == EBoidState::Raised) { if (state == EBoidState::Raised) {
@ -232,32 +231,27 @@ void CSnakeWeedSwarm::Think(float dt, CStateManager& mgr) {
if (x1f4_particleGen2 && emitParticle) { if (x1f4_particleGen2 && emitParticle) {
EmitParticles2(pos); EmitParticles2(pos);
} }
} else if (state == EBoidState::x1) { } else if (state == EBoidState::Raising) {
float x14 = boid.Get_x14() - dt * boid.Get_x18(); boid.Set_x14(boid.Get_x14() - dt * boid.Get_x18());
if (x14 <= 0.f) { if (boid.Get_x14() <= 0.f) {
boid.Set_x14(0.f); boid.Set_x14(0.f);
boid.SetState(EBoidState::Raised); boid.SetState(EBoidState::Raised);
} else {
boid.Set_x14(x14);
} }
} else if (state == EBoidState::x2) { } else if (state == EBoidState::x2) {
float x10 = boid.Get_x10() - dt; boid.Set_x10(boid.Get_x10() - dt);
boid.Set_x10(x10); if (boid.Get_x10() <= 0.f) {
if (x10 <= 0.f) { boid.SetState(EBoidState::Raising);
boid.SetState(EBoidState::x1);
CSfxManager::AddEmitter(x1d4_sfx3, pos, zeus::skZero3f, true, false, 0x7f, x4_areaId); CSfxManager::AddEmitter(x1d4_sfx3, pos, zeus::skZero3f, true, false, 0x7f, x4_areaId);
EmitParticles1(pos); EmitParticles1(pos);
} }
} else if (state == EBoidState::x3) { } else if (state == EBoidState::x3) {
float x14 = dt * boid.Get_x18() + boid.Get_x14(); boid.Set_x14(dt * boid.Get_x18() + boid.Get_x14());
float max = x110_ * boid.Get_x20(); float max = x110_ * boid.Get_x20();
if (x14 >= max) { if (boid.Get_x14() >= max) {
boid.Set_x14(max); boid.Set_x14(max);
float random = mgr.GetActiveRandom()->Float(); float random = mgr.GetActiveRandom()->Float();
boid.Set_x10(x10c_ * random + x108_); boid.Set_x10(x10c_ * random + x108_);
boid.SetState(EBoidState::x2); boid.SetState(EBoidState::x2);
} else {
boid.Set_x14(x14);
} }
} }
} }
@ -344,9 +338,8 @@ bool CSnakeWeedSwarm::CreateBoid(const zeus::CVector3f& vec, CStateManager& mgr)
const CRayCastResult& result = mgr.RayStaticIntersection(pos, zeus::skDown, 2.f * xf8_height, matFilter); const CRayCastResult& result = mgr.RayStaticIntersection(pos, zeus::skDown, 2.f * xf8_height, matFilter);
if (result.IsValid() && result.GetPlane().normal().dot(zeus::skUp) > x11c_) { if (result.IsValid() && result.GetPlane().normal().dot(zeus::skUp) > x11c_) {
const zeus::CVector3f& boidPosition = result.GetPoint() - zeus::CVector3f(0.f, 0.f, x128_); const zeus::CVector3f& boidPosition = result.GetPoint() - zeus::CVector3f(0.f, 0.f, x128_);
float random = mgr.GetActiveRandom()->Float(); x134_boids.push_back(
const CBoid boid(boidPosition, x110_, x114_ + x118_, (x124_ - x120_) * random + x120_); {boidPosition, x110_, x114_ + x118_, (x124_ - x120_) * mgr.GetActiveRandom()->Float() + x120_});
x134_boids.push_back(boid);
return true; return true;
} }
return false; return false;
@ -380,7 +373,7 @@ void CSnakeWeedSwarm::CalculateTouchBounds() {
x144_touchBounds = zeus::CAABox(GetTransform().origin, GetTransform().origin); x144_touchBounds = zeus::CAABox(GetTransform().origin, GetTransform().origin);
} else { } else {
x144_touchBounds = zeus::skInvertedBox; x144_touchBounds = zeus::skInvertedBox;
for (auto boid : x134_boids) { for (const auto& boid : x134_boids) {
x144_touchBounds.accumulateBounds(boid.GetPosition() - x100_weaponDamageRadius); x144_touchBounds.accumulateBounds(boid.GetPosition() - x100_weaponDamageRadius);
x144_touchBounds.accumulateBounds(boid.GetPosition() + x100_weaponDamageRadius); x144_touchBounds.accumulateBounds(boid.GetPosition() + x100_weaponDamageRadius);
} }
@ -410,7 +403,7 @@ void CSnakeWeedSwarm::EmitParticles2(const zeus::CVector3f& pos) {
void CSnakeWeedSwarm::RenderBoid(u32 idx, const CBoid& boid, u32& posesToBuild) const { void CSnakeWeedSwarm::RenderBoid(u32 idx, const CBoid& boid, u32& posesToBuild) const {
const u32 modelIdx = idx & 3; const u32 modelIdx = idx & 3;
auto modelData = x1b0_modelData[modelIdx]; const auto& modelData = x1b0_modelData[modelIdx];
CSkinnedModel& model = modelData->PickAnimatedModel(x1c4_which); CSkinnedModel& model = modelData->PickAnimatedModel(x1c4_which);
const CModelFlags useFlags(0, 0, 3, zeus::skWhite); const CModelFlags useFlags(0, 0, 3, zeus::skWhite);
if (posesToBuild & 1 << modelIdx) { if (posesToBuild & 1 << modelIdx) {
@ -418,12 +411,11 @@ void CSnakeWeedSwarm::RenderBoid(u32 idx, const CBoid& boid, u32& posesToBuild)
modelData->GetAnimationData()->BuildPose(); modelData->GetAnimationData()->BuildPose();
model.Calculate(modelData->GetAnimationData()->GetPose(), useFlags, {}, nullptr); model.Calculate(modelData->GetAnimationData()->GetPose(), useFlags, {}, nullptr);
} }
// printf("rendering boid with x14 %f\n", boid->Get_x14());
const zeus::CTransform& xf = const zeus::CTransform& xf =
zeus::CTransform::Translate(boid.GetPosition() /*- zeus::CVector3f(0.f, 0.f, boid.Get_x14())*/) * zeus::CTransform::Translate(boid.GetPosition() - zeus::CVector3f(0.f, 0.f, boid.Get_x14())) *
zeus::CTransform::Scale(boid.Get_x20()); zeus::CTransform::Scale(boid.Get_x20());
g_Renderer->SetModelMatrix(xf); CGraphics::SetModelMatrix(xf);
model.Draw(useFlags); modelData->GetAnimationData()->Render(model, useFlags, {}, nullptr);
} }
void CSnakeWeedSwarm::ApplyRadiusDamage(const zeus::CVector3f& pos, const CDamageInfo& info, CStateManager& mgr) { void CSnakeWeedSwarm::ApplyRadiusDamage(const zeus::CVector3f& pos, const CDamageInfo& info, CStateManager& mgr) {

View File

@ -12,7 +12,7 @@ class CSnakeWeedSwarm : public CActor {
public: public:
enum class EBoidState : u32 { enum class EBoidState : u32 {
Raised = 0, Raised = 0,
x1 = 1, Raising = 1,
x2 = 2, x2 = 2,
x3 = 3, x3 = 3,
}; };
@ -35,7 +35,7 @@ public:
public: public:
constexpr CBoid(const zeus::CVector3f& pos, float f1, float f2, float f3) constexpr CBoid(const zeus::CVector3f& pos, float f1, float f2, float f3)
: x0_pos(pos), xc_state(EBoidState::x1), x14_(f1), x18_(f2), x20_(f3) {} : x0_pos(pos), xc_state(EBoidState::Raising), x14_(f1), x18_(f2), x20_(f3) {}
constexpr const zeus::CVector3f& GetPosition() const { return x0_pos; } constexpr const zeus::CVector3f& GetPosition() const { return x0_pos; }
constexpr EBoidState GetState() const { return xc_state; } constexpr EBoidState GetState() const { return xc_state; }
@ -43,7 +43,7 @@ public:
constexpr float Get_x14() const { return x14_; } constexpr float Get_x14() const { return x14_; }
constexpr float Get_x18() const { return x18_; } constexpr float Get_x18() const { return x18_; }
constexpr float Get_x20() const { return x20_; } constexpr float Get_x20() const { return x20_; }
constexpr void SetState(EBoidState v) { xc_state = v; } void SetState(EBoidState v) { xc_state = v; fmt::print(fmt("Setting boid state {}"), v); }
constexpr void Set_x10(float v) { x10_ = v; } constexpr void Set_x10(float v) { x10_ = v; }
constexpr void Set_x14(float v) { x14_ = v; } constexpr void Set_x14(float v) { x14_ = v; }
constexpr void Set_x18(float v) { x18_ = v; } constexpr void Set_x18(float v) { x18_ = v; }

View File

@ -3054,9 +3054,9 @@ CEntity* ScriptLoader::LoadSnakeWeedSwarm(CStateManager& mgr, CInputStream& in,
u32 w1 = in.readUint32Big(); u32 w1 = in.readUint32Big();
u32 w2 = in.readUint32Big(); u32 w2 = in.readUint32Big();
u32 w3 = in.readUint32Big(); u32 w3 = in.readUint32Big();
CAssetId w4 = (propCount < 29 ? -1 : in.readUint32Big()); CAssetId w4 = (propCount < 29 ? CAssetId() : in.readUint32Big());
u32 w5 = (propCount < 29 ? -1 : in.readUint32Big()); u32 w5 = (propCount < 29 ? 0 : in.readUint32Big());
CAssetId w6 = (propCount < 29 ? -1 : in.readUint32Big()); CAssetId w6 = (propCount < 29 ? CAssetId() : in.readUint32Big());
float f16 = (propCount < 29 ? 0.f : in.readFloatBig()); float f16 = (propCount < 29 ? 0.f : in.readFloatBig());
CAnimRes animRes(animParms.GetACSFile(), animParms.GetCharacter(), zeus::skOne3f, animParms.GetInitialAnimation(), CAnimRes animRes(animParms.GetACSFile(), animParms.GetCharacter(), zeus::skOne3f, animParms.GetInitialAnimation(),