Runtime/Graphics: Replace bitfield unions with constructor initializers

This commit is contained in:
Luke Street 2020-04-10 15:03:15 -04:00
parent 496bb3e624
commit 4a3ce8453f
14 changed files with 110 additions and 131 deletions

View File

@ -18,20 +18,22 @@ s32 CActorLights::sFrameSchedulerCount = 0;
CActorLights::CActorLights(u32 areaUpdateFramePeriod, const zeus::CVector3f& actorPosBias, int maxDynamicLights,
int maxAreaLights, bool ambientChannelOverflow, bool layer2, bool disableWorldLights,
float positionUpdateThreshold)
: x2a8_areaUpdateFramePeriod(areaUpdateFramePeriod)
: x298_24_dirty(true)
, x298_25_castShadows(true)
, x298_26_hasAreaLights(false)
, x298_27_findShadowLight(false)
, x298_28_inArea(!disableWorldLights && maxAreaLights > 0)
, x298_29_ambienceGenerated(ambientChannelOverflow)
, x298_30_layer2(layer2)
, x298_31_disableWorldLights(disableWorldLights)
, x299_24_inBrightLight(true)
, x299_25_useBrightLightLag(false)
, x299_26_ambientOnly(false)
, x2a8_areaUpdateFramePeriod(areaUpdateFramePeriod)
, x2ac_actorPosBias(actorPosBias)
, x2b8_maxAreaLights(maxAreaLights)
, x2bc_maxDynamicLights(maxDynamicLights)
, x2cc_actorPositionDeltaUpdateThreshold(positionUpdateThreshold * positionUpdateThreshold) {
x298_24_dirty = true;
x298_25_castShadows = true;
x298_28_inArea = !disableWorldLights && maxAreaLights > 0;
x298_29_ambienceGenerated = ambientChannelOverflow;
x298_30_layer2 = layer2;
x298_31_disableWorldLights = disableWorldLights;
x299_24_inBrightLight = true;
sFrameSchedulerCount++;
sFrameSchedulerCount &= 7;
}

View File

@ -20,23 +20,17 @@ class CActorLights {
std::vector<CLight> x144_dynamicLights;
zeus::CColor x288_ambientColor = zeus::skBlack;
TAreaId x294_aid = kInvalidAreaId;
union {
struct {
bool x298_24_dirty : 1;
bool x298_25_castShadows : 1;
bool x298_26_hasAreaLights : 1;
bool x298_27_findShadowLight : 1;
bool x298_28_inArea : 1;
bool x298_29_ambienceGenerated : 1;
bool x298_30_layer2 : 1;
bool x298_31_disableWorldLights : 1;
bool x299_24_inBrightLight : 1;
bool x299_25_useBrightLightLag : 1;
bool x299_26_ambientOnly : 1;
};
u16 _dummy = 0;
};
bool x298_24_dirty : 1;
bool x298_25_castShadows : 1;
bool x298_26_hasAreaLights : 1;
bool x298_27_findShadowLight : 1;
bool x298_28_inArea : 1;
bool x298_29_ambienceGenerated : 1;
bool x298_30_layer2 : 1;
bool x298_31_disableWorldLights : 1;
bool x299_24_inBrightLight : 1;
bool x299_25_useBrightLightLag : 1;
bool x299_26_ambientOnly : 1;
bool x29a_findNearestDynamicLights = false;
s32 x29c_shadowLightArrIdx = -1;
s32 x2a0_shadowLightIdx = -1;

View File

@ -45,9 +45,9 @@ CAnimData::CAnimData(CAssetId id, const CCharacterInfo& character, int defaultAn
const std::weak_ptr<CAnimSysContext>& ctx, std::shared_ptr<CAnimationManager> animMgr,
std::shared_ptr<CTransitionManager> transMgr, TLockedToken<CCharacterFactory> charFactory,
int drawInstCount)
: x0_charFactory(std::move(charFactory))
: x0_charFactory(charFactory)
, xc_charInfo(character)
, xcc_layoutData(std::move(layout))
, xcc_layoutData(layout)
, xd8_modelData(std::move(model))
, xfc_animCtx(ctx.lock())
, x100_animMgr(std::move(animMgr))
@ -55,6 +55,14 @@ CAnimData::CAnimData(CAssetId id, const CCharacterInfo& character, int defaultAn
, x1fc_transMgr(std::move(transMgr))
, x204_charIdx(charIdx)
, x208_defaultAnim(defaultAnim)
, x220_24_animating(false)
, x220_25_loop(false)
, x220_26_aligningPos(false)
, x220_27_(false)
, x220_28_(false)
, x220_29_animationJustStarted(false)
, x220_30_poseBuilt(false)
, x220_31_poseCached(false)
, x224_pose(layout->GetSegIdList().GetList().size())
, x2fc_poseBuilder(CLayoutDescription{layout})
, m_drawInstCount(drawInstCount) {

View File

@ -124,21 +124,14 @@ private:
u32 x214_passedParticleCount = 0;
u32 x218_passedSoundCount = 0;
s32 x21c_particleLightIdx = 0;
union {
u32 x220_flags = 0;
struct {
bool x220_24_animating : 1;
bool x220_25_loop : 1;
bool x220_26_aligningPos : 1;
bool x220_27_ : 1;
bool x220_28_ : 1;
bool x220_29_animationJustStarted : 1;
bool x220_30_poseBuilt : 1;
bool x220_31_poseCached : 1;
};
};
bool x220_24_animating : 1;
bool x220_25_loop : 1;
bool x220_26_aligningPos : 1;
bool x220_27_ : 1;
bool x220_28_ : 1;
bool x220_29_animationJustStarted : 1;
bool x220_30_poseBuilt : 1;
bool x220_31_poseCached : 1;
CPoseAsTransforms x224_pose;
CHierarchyPoseBuilder x2fc_poseBuilder;

View File

@ -12,8 +12,15 @@
namespace urde {
CBodyController::CBodyController(CActor& actor, float turnSpeed, EBodyType bodyType)
: x0_actor(actor), x2a4_bodyStateInfo(actor, bodyType), x2f4_bodyType(bodyType), x2fc_turnSpeed(turnSpeed) {
x300_28_playDeathAnims = true;
: x0_actor(actor)
, x2a4_bodyStateInfo(actor, bodyType)
, x2f4_bodyType(bodyType)
, x2fc_turnSpeed(turnSpeed)
, x300_24_animationOver(false)
, x300_25_active(false)
, x300_26_frozen(false)
, x300_27_hasBeenFrozen(false)
, x300_28_playDeathAnims(true) {
x2a4_bodyStateInfo.x18_bodyController = this;
}

View File

@ -28,16 +28,11 @@ class CBodyController {
EBodyType x2f4_bodyType;
s32 x2f8_curAnim = -1;
float x2fc_turnSpeed;
union {
struct {
bool x300_24_animationOver : 1;
bool x300_25_active : 1;
bool x300_26_frozen : 1;
bool x300_27_hasBeenFrozen : 1;
bool x300_28_playDeathAnims : 1;
};
u32 _dummy = 0;
};
bool x300_24_animationOver : 1;
bool x300_25_active : 1;
bool x300_26_frozen : 1;
bool x300_27_hasBeenFrozen : 1;
bool x300_28_playDeathAnims : 1;
float x304_intoFreezeDur = 0.f;
float x308_frozenDur = 0.f;
float x30c_breakoutDur = 0.f;

View File

@ -202,22 +202,23 @@ class CBSJump : public CBodyState {
zeus::CVector3f xc_waypoint1;
zeus::CVector3f x18_velocity;
zeus::CVector3f x24_waypoint2;
union {
struct {
bool x30_24_bodyForceSet : 1;
bool x30_25_wallJump : 1;
bool x30_26_wallBounceRight : 1;
bool x30_27_wallBounceComplete : 1;
bool x30_28_startInJumpLoop : 1;
};
u32 _dummy = 0;
};
bool x30_24_bodyForceSet : 1;
bool x30_25_wallJump : 1;
bool x30_26_wallBounceRight : 1;
bool x30_27_wallBounceComplete : 1;
bool x30_28_startInJumpLoop : 1;
pas::EAnimationState GetBodyStateTransition(float dt, const CBodyController& bc) const;
bool CheckForWallJump(CBodyController& bc, CStateManager& mgr);
void CheckForLand(CBodyController& bc, CStateManager& mgr);
void PlayJumpLoop(CStateManager& mgr, CBodyController& bc);
public:
CBSJump()
: x30_24_bodyForceSet(false)
, x30_25_wallJump(false)
, x30_26_wallBounceRight(false)
, x30_27_wallBounceComplete(false)
, x30_28_startInJumpLoop(false) {}
bool IsMoving() const override { return true; }
bool ApplyHeadTracking() const override { return false; }
bool CanShoot() const override;
@ -277,17 +278,13 @@ public:
};
class CBSScripted : public CBodyState {
union {
struct {
bool x4_24_loopAnim : 1;
bool x4_25_timedLoop : 1;
};
u32 _dummy = 0;
};
bool x4_24_loopAnim : 1;
bool x4_25_timedLoop : 1;
float x8_remTime = 0.f;
pas::EAnimationState GetBodyStateTransition(float dt, const CBodyController& bc) const;
public:
CBSScripted() : x4_24_loopAnim(false), x4_25_timedLoop(false) {}
bool ApplyHeadTracking() const override { return false; }
void Start(CBodyController& bc, CStateManager& mgr) override;
pas::EAnimationState UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) override;
@ -313,13 +310,8 @@ class CBSWallHang : public CBodyState {
pas::EWallHangState x4_state = pas::EWallHangState::Invalid;
TUniqueId x8_wpId = kInvalidUniqueId;
zeus::CVector3f xc_launchVel;
union {
struct {
bool x18_24_launched : 1;
bool x18_25_needsExit : 1;
};
u32 _dummy = 0;
};
bool x18_24_launched : 1;
bool x18_25_needsExit : 1;
pas::EAnimationState GetBodyStateTransition(float dt, const CBodyController& bc) const;
void FixInPlace(CBodyController& bc);
bool CheckForLand(CBodyController& bc, CStateManager& mgr);
@ -327,6 +319,7 @@ class CBSWallHang : public CBodyState {
void SetLaunchVelocity(CBodyController& bc);
public:
CBSWallHang() : x18_24_launched(false), x18_25_needsExit(false) {}
bool IsMoving() const override { return true; }
bool CanShoot() const override { return x4_state == pas::EWallHangState::WallHang; }
bool IsInAir(const CBodyController& bc) const override;

View File

@ -15,6 +15,8 @@ CBoneTracking::CBoneTracking(const CAnimData& animData, std::string_view bone,
: x14_segId(animData.GetCharLayoutInfo().GetSegIdFromString(bone))
, x1c_maxTrackingAngle(maxTrackingAngle)
, x20_angSpeed(angSpeed)
, x36_24_active(false)
, x36_25_hasTrackedRotation(false)
, x36_26_noParent(True(flags & EBoneTrackingFlags::NoParent))
, x36_27_noParentOrigin(True(flags & EBoneTrackingFlags::NoParentOrigin))
, x36_28_noHorizontalAim(True(flags & EBoneTrackingFlags::NoHorizontalAim))
@ -107,4 +109,4 @@ void CBoneTracking::UnsetTarget() { x34_target = kInvalidUniqueId; }
void CBoneTracking::SetTargetPosition(const zeus::CVector3f& targetPos) { x24_targetPosition = targetPos; }
void CBoneTracking::SetNoHorizontalAim(bool b) { x36_28_noHorizontalAim = b; }
} // namespace urde
} // namespace urde

View File

@ -33,17 +33,12 @@ class CBoneTracking {
float x20_angSpeed;
std::optional<zeus::CVector3f> x24_targetPosition;
TUniqueId x34_target = kInvalidUniqueId;
union {
struct {
bool x36_24_active : 1;
bool x36_25_hasTrackedRotation : 1;
bool x36_26_noParent : 1;
bool x36_27_noParentOrigin : 1;
bool x36_28_noHorizontalAim : 1;
bool x36_29_parentIk : 1;
};
u32 _dummy = 0;
};
bool x36_24_active : 1;
bool x36_25_hasTrackedRotation : 1;
bool x36_26_noParent : 1;
bool x36_27_noParentOrigin : 1;
bool x36_28_noHorizontalAim : 1;
bool x36_29_parentIk : 1;
public:
CBoneTracking(const CAnimData& animData, std::string_view bone,
@ -60,4 +55,4 @@ public:
void SetNoHorizontalAim(bool b);
};
} // namespace urde
} // namespace urde

View File

@ -21,16 +21,10 @@ class CIkChain {
zeus::CQuaternion x24_holdRot;
zeus::CVector3f x34_holdPos;
float x40_time = 0.f;
union {
struct {
bool x44_24_activated : 1;
};
u32 x44_dummy = 0;
};
bool x44_24_activated : 1;
public:
CIkChain() = default;
CIkChain() : x44_24_activated(false) {}
bool GetActive() const { return x44_24_activated; }
void Update(float);

View File

@ -25,14 +25,16 @@ CModelData::~CModelData() = default;
CModelData::CModelData() {}
CModelData CModelData::CModelDataNull() { return CModelData(); }
CModelData::CModelData(const CStaticRes& res, int instCount) : x0_scale(res.GetScale()), m_drawInstCount(instCount) {
CModelData::CModelData(const CStaticRes& res, int instCount)
: x0_scale(res.GetScale()), x14_24_renderSorted(false), x14_25_sortThermal(false), m_drawInstCount(instCount) {
x1c_normalModel = g_SimplePool->GetObj({SBIG('CMDL'), res.GetId()});
if (!x1c_normalModel)
Log.report(logvisor::Fatal, fmt("unable to find CMDL {}"), res.GetId());
m_normalModelInst = x1c_normalModel->MakeNewInstance(0, instCount);
}
CModelData::CModelData(const CAnimRes& res, int instCount) : x0_scale(res.GetScale()), m_drawInstCount(instCount) {
CModelData::CModelData(const CAnimRes& res, int instCount)
: x0_scale(res.GetScale()), x14_24_renderSorted(false), x14_25_sortThermal(false), m_drawInstCount(instCount) {
TToken<CCharacterFactory> factory = g_CharFactoryBuilder->GetFactory(res);
x10_animData =
factory->CreateCharacter(res.GetCharacterNodeId(), res.CanLoop(), factory, res.GetDefaultAnim(), instCount);
@ -76,13 +78,13 @@ bool CModelData::IsLoaded(int shaderIdx) const {
}
u32 CModelData::GetNumMaterialSets() const {
if (x10_animData)
return x10_animData->GetModelData()->GetModel()->GetNumMaterialSets();
if (x10_animData)
return x10_animData->GetModelData()->GetModel()->GetNumMaterialSets();
if (x1c_normalModel)
return x1c_normalModel->GetNumMaterialSets();
if (x1c_normalModel)
return x1c_normalModel->GetNumMaterialSets();
return 1;
return 1;
}
CModelData::EWhichModel CModelData::GetRenderingModel(const CStateManager& stateMgr) {

View File

@ -62,13 +62,8 @@ class CModelData {
zeus::CVector3f x0_scale;
bool xc_ = false;
std::unique_ptr<CAnimData> x10_animData;
union {
struct {
bool x14_24_renderSorted : 1;
bool x14_25_sortThermal : 1;
};
u32 _flags = 0;
};
bool x14_24_renderSorted : 1;
bool x14_25_sortThermal : 1;
zeus::CColor x18_ambientColor;
TLockedToken<CModel> x1c_normalModel;

View File

@ -59,11 +59,15 @@ void CRagDoll::CRagDollPlaneConstraint::Update() {
}
CRagDoll::CRagDoll(float normalGravity, float floatingGravity, float overTime, u32 flags)
: x44_normalGravity(normalGravity), x48_floatingGravity(floatingGravity), x50_overTimer(overTime) {
x68_27_continueSmallMovements = bool(flags & 0x1);
x68_28_noOverTimer = bool(flags & 0x2);
x68_29_noAiCollision = bool(flags & 0x4);
}
: x44_normalGravity(normalGravity)
, x48_floatingGravity(floatingGravity)
, x50_overTimer(overTime)
, x68_24_prevMovingSlowly(false)
, x68_25_over(false)
, x68_26_primed(false)
, x68_27_continueSmallMovements(bool(flags & 0x1))
, x68_28_noOverTimer(bool(flags & 0x2))
, x68_29_noAiCollision(bool(flags & 0x4)) {}
void CRagDoll::AccumulateForces(float dt, float waterTop) {
float fps = 1.f / dt;

View File

@ -94,17 +94,12 @@ protected:
float x54_impactVel = 0.f;
zeus::CVector3f x58_averageVel;
float x64_angTimer = 0.f;
union {
struct {
bool x68_24_prevMovingSlowly : 1;
bool x68_25_over : 1;
bool x68_26_primed : 1;
bool x68_27_continueSmallMovements : 1;
bool x68_28_noOverTimer : 1;
bool x68_29_noAiCollision : 1;
};
u32 _dummy = 0;
};
bool x68_24_prevMovingSlowly : 1;
bool x68_25_over : 1;
bool x68_26_primed : 1;
bool x68_27_continueSmallMovements : 1;
bool x68_28_noOverTimer : 1;
bool x68_29_noAiCollision : 1;
void AccumulateForces(float dt, float waterTop);
void SetNumParticles(int num) { x4_particles.reserve(num); }
void AddParticle(CSegId id, const zeus::CVector3f& prevPos, const zeus::CVector3f& curPos, float radius);