Skip to content

Commit

Permalink
Merge pull request #3 from robojumper/mAng_flindba
Browse files Browse the repository at this point in the history
Fix mAng3_c copy assignment, clean up list node templates
  • Loading branch information
robojumper authored Jun 27, 2024
2 parents 332f006 + 5848321 commit 8acccaf
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 90 deletions.
4 changes: 2 additions & 2 deletions config/SOUE01/rels/d_a_t_wood_areaNP/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ __dt__27sFState_c<14dAcTWoodArea_c>Fv = .text:0x000001C0; // type:function size:
__dt__30sFStateFct_c<14dAcTWoodArea_c>Fv = .text:0x00000220; // type:function size:0x6C
__dt__83sStateMgr_c<14dAcTWoodArea_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000290; // type:function size:0xA0
__dt__53sFStateMgr_c<14dAcTWoodArea_c,20sStateMethodUsr_FI_c>Fv = .text:0x00000330; // type:function size:0xA4
__ct__14fLiNdBa_Wood_cFv = .text:0x000003E0; // type:function size:0x14
__dt__14fLiNdBa_Wood_cFv = .text:0x00000400; // type:function size:0x58
__ct__24dAcRef_c<12dAcObjBase_c>Fv = .text:0x000003E0; // type:function size:0x14
__dt__24dAcRef_c<12dAcObjBase_c>Fv = .text:0x00000400; // type:function size:0x58
actorCreate__14dAcTWoodArea_cFv = .text:0x00000460; // type:function size:0x9C
changeState__83sStateMgr_c<14dAcTWoodArea_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>FRC12sStateIDIf_c = .text:0x00000500; // type:function size:0x10
actorPostCreate__14dAcTWoodArea_cFv = .text:0x00000510; // type:function size:0x64
Expand Down
6 changes: 3 additions & 3 deletions config/SOUE01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,10 @@ getParams2Lower__9dAcBase_cFv = .text:0x8002D010; // type:function size:0xC
findActor__9dAcBase_cFPcP9dAcBase_c = .text:0x8002D020; // type:function size:0x74
searchActor__9dAcBase_cFP9dAcBase_c = .text:0x8002D0A0; // type:function size:0x88
forEveryActor__9dAcBase_cFPFP9dAcBase_cP9dAcBase_c_PvP9dAcBase_c = .text:0x8002D130; // type:function size:0x5C
getXZAngleToPlayer__9dAcBase_cFPs = .text:0x8002D190; // type:function size:0x3C
getXZAngleToPlayer__9dAcBase_cFv = .text:0x8002D190; // type:function size:0x3C
getDistanceToActor__9dAcBase_cFP9dAcBase_cfPf = .text:0x8002D1D0; // type:function size:0xB8
getDistanceAndAngleToActor__9dAcBase_cFP9dAcBase_cfssPfPsPs = .text:0x8002D290; // type:function size:0x148
isWithinPlayerRadius__9dAcBase_cFf = .text:0x8002D3E0; // type:function size:0x5C
isWithinPlayerRadius__9dAcBase_cCFf = .text:0x8002D3E0; // type:function size:0x5C
getDistanceAndAngleToPlayer__9dAcBase_cFfssPfPsPs = .text:0x8002D440; // type:function size:0x2C
getDistToPlayer__9dAcBase_cFv = .text:0x8002D470; // type:function size:0x30
getSquareDistToPlayer__9dAcBase_cFv = .text:0x8002D4A0; // type:function size:0x10
Expand All @@ -1086,7 +1086,7 @@ FUN_8002d830__9dAcBase_cFv = .text:0x8002D830; // type:function size:0x28
FUN_8002d860__9dAcBase_cFv = .text:0x8002D860; // type:function size:0x20
getSoundSource__9dAcBase_cFv = .text:0x8002D880; // type:function size:0x8
FUN_8002d890__9dAcBase_cFv = .text:0x8002D890; // type:function size:0x88
setActorRef__9dAcBase_cFP7dBase_c = .text:0x8002D920; // type:function size:0x8
setActorRef__9dAcBase_cFP9dAcBase_c = .text:0x8002D920; // type:function size:0x8
setEnemyDefeatFlag__9dAcBase_cFv = .text:0x8002D930; // type:function size:0x10
changeLoadedEntitiesWithSet__9dAcBase_cFv = .text:0x8002D940; // type:function size:0x14
changeLoadedEntitiesNoSet__9dAcBase_cFv = .text:0x8002D960; // type:function size:0x14
Expand Down
46 changes: 40 additions & 6 deletions include/d/a/d_a_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,41 @@ struct SoundInfo {
SoundInfo *prev;
};

/**
* A list node that will automatically unlink upon destruction.
*/
class dAcRefBase_c : public fLiNdBa_c {
public:
dAcRefBase_c(fBase_c *owner) : fLiNdBa_c(owner) {}
~dAcRefBase_c() {
unlink();
}
};

/**
* A type-safe list node that can hold a specific actor reference.
* Unlinks upon destruction. This setup is inferred from
* double null checks in inline dtors and instantiated ctors/dtors
* for arrays of these nodes in classes.
*/
template <typename T>
class dAcRef_c : dAcRefBase_c {
public:
dAcRef_c(T *owner) : dAcRefBase_c(owner) {}
dAcRef_c() : dAcRefBase_c(nullptr) {}
~dAcRef_c() {}

void link(T *ref) {
fLiNdBa_c::link(ref);
}
void unlink() {
fLiNdBa_c::unlink();
}
T *get() {
return static_cast<T *>(p_owner);
}
};

template <typename T, int offset>
struct TList {
T *GetOffset() {
Expand Down Expand Up @@ -61,7 +96,7 @@ class dAcBase_c : public dBase_c {
/* 0xC0 */ mVec3_c position;
/* 0xCC */ mVec3_c scale;
/* 0xD8 */ u32 actor_properties;
/* 0xDC */ fLiNdBa_c actor_node;
/* 0xDC */ dAcRef_c<dAcBase_c> actor_node;
/* 0xE8 */ u32 field_0xe8;
/* 0xEC */ s8 roomid;
/* 0xED */ u8 actor_subtype;
Expand Down Expand Up @@ -117,7 +152,7 @@ class dAcBase_c : public dBase_c {
return position - other.position;
}

f32 getSquareDistanceTo(const mVec3_c &point) {
f32 getSquareDistanceTo(const mVec3_c &point) const {
mVec3_c diff = position - point;
return diff.x * diff.x + diff.z * diff.z;
}
Expand Down Expand Up @@ -148,14 +183,13 @@ class dAcBase_c : public dBase_c {
/* 8002d0a0 */ static dAcBase_c *searchActor(dAcBase_c *parent);
// Kinda performs the code of the first param on every actor (second param is optional parent)
/* 8002d130 */ static void forEveryActor(void *func(dAcBase_c *, dAcBase_c *), dAcBase_c *parent);
// Not really static, but we currently dont have a type for the return (not just simply a s16)
/* 8002d190 */ mAng getXZAngleToPlayer(s16 *angle);
/* 8002d190 */ mAng getXZAngleToPlayer();
// returns true if under the distThresh, False if not. the actual distance is returned in outDist
/* 8002d1d0 */ bool getDistanceToActor(dAcBase_c *actor, f32 distThresh, f32 *outDist);
// same concept as above
/* 8002d290 */ bool getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16 yAngle, s16 xAngle,
f32 *outDist, s16 *outDiffAngleY, s16 *outDiffAngleX);
/* 8002d3e0 */ bool isWithinPlayerRadius(f32 radius);
/* 8002d3e0 */ bool isWithinPlayerRadius(f32 radius) const;
/* 8002d440 */ bool getDistanceAndAngleToPlayer(f32 distThresh, s16 yAngle, s16 xAngle, f32 *outDist,
s16 *outDiffAngleY, s16 *outDiffAngleX);
/* 8002d470 */ f32 getDistToPlayer();
Expand Down Expand Up @@ -183,7 +217,7 @@ class dAcBase_c : public dBase_c {
// End of SoundSource stuff

/* 8002d890 */ void FUN_8002d890();
/* 8002d920 */ void setActorRef(dBase_c *);
/* 8002d920 */ void setActorRef(dAcBase_c *);
// next three funcs are related
/* 8002d930 */ void setEnemyDefeatFlag();
/* 8002d940 */ void changeLoadedEntitiesWithSet();
Expand Down
46 changes: 46 additions & 0 deletions include/d/a/d_a_t_wood_area.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef D_A_T_WOOD_AREA_H
#define D_A_T_WOOD_AREA_H

#include <d/a/obj/d_a_obj_base.h>
#include <d/d_player.h>
#include <f/f_list_nd.h>
#include <s/s_State.hpp>
#include <s/s_StateMgr.hpp>

class dAcTWoodArea_c : public dAcObjBase_c {
public:
dAcTWoodArea_c() : mStateMgr(*this, sStateID::null) {}
virtual ~dAcTWoodArea_c() {}
virtual int actorCreate() override;
virtual int actorPostCreate() override;
virtual int actorExecute() override;
virtual int draw() override;
virtual int doDelete() override;

STATE_FUNC_DECLARE(dAcTWoodArea_c, Init);
STATE_FUNC_DECLARE(dAcTWoodArea_c, Wait);

void attachCloseObjects(ProfileName profID);
void dropItems();
bool attachObject(dAcObjBase_c *obj);

f32 getAttachRadius() {
return scale.x * scaleX;
}
f32 getAttachRadiusSquare() {
return getAttachRadius() * getAttachRadius();
}
f32 getAttachHeight() {
return scale.y * scaleY;
}

static const f32 scaleX;
static const f32 scaleY;

private:
STATE_MGR_DECLARE(dAcTWoodArea_c);

dAcRef_c<dAcObjBase_c> mRefs[8];
};

#endif
2 changes: 1 addition & 1 deletion include/d/d_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class dBase_c : public fBase_c {
/* 800508f0 */ virtual void postExecute(MAIN_STATE_e state);
/* 80050920 */ virtual int preDraw();
/* 80050860 */ virtual void postDraw(MAIN_STATE_e state);
/* 8002c530 */ virtual ~dBase_c();
/* 8002c530 */ virtual ~dBase_c() {}

public:
/* 80050980 */ static void resetFlags();
Expand Down
10 changes: 3 additions & 7 deletions include/d/tg/d_t_tumble_weed.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
#include <s/s_State.hpp>
#include <s/s_StateMgr.hpp>

class fLiNdTumbleweed_c : public fLiNdBaAutoUnlink_c {
public:
fLiNdTumbleweed_c(fBase_c *owner) : fLiNdBaAutoUnlink_c(owner) {}
u16 someField;
};

class dTgTumbleWeed_c : public dTg_c {
public:
dTgTumbleWeed_c() : mStateMgr(*this, sStateID::null), childTumbleweed(nullptr) {}
Expand All @@ -35,7 +29,9 @@ class dTgTumbleWeed_c : public dTg_c {
u16 tumbleweedTimer;
u16 padding;
u16 windTimer;
fLiNdTumbleweed_c childTumbleweed;
// TODO dAcObjTumbleWeed
dAcRef_c<dAcBase_c> childTumbleweed;
u16 someField;
};

#endif
6 changes: 0 additions & 6 deletions include/f/f_list_nd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,4 @@ class fLiNdBa_c : public cListNd_c {
fBase_c *p_owner;
};

class fLiNdBaAutoUnlink_c : public fLiNdBa_c {
public:
fLiNdBaAutoUnlink_c(fBase_c *owner) : fLiNdBa_c(owner) {}
~fLiNdBaAutoUnlink_c() { unlink(); }
};

#endif
16 changes: 15 additions & 1 deletion include/m/m_angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
struct mAng {
mAng() {}
mAng(s16 s) : mVal(s) {}

mAng(const mAng &other) : mVal(other.mVal) {}
operator s16() const {
return mVal;
}
s32 step(s16 target, s32 steps, s16 max, s16 min);

s16 mVal;
Expand All @@ -18,6 +21,17 @@ class mAng3_c {

mAng3_c(s16 fx, s16 fy, s16 fz) : x(fx), y(fy), z(fz) {}

mAng3_c(const mAng3_c &r) {
*this = r;
}

mAng3_c &operator=(const mAng3_c &r) {
x = r.x;
y = r.y;
z = r.z;
return *this;
}

void set(s16 fx, s16 fy, s16 fz) {
x = fx;
y = fy;
Expand Down
56 changes: 5 additions & 51 deletions src/REL/d/a/d_a_t_wood_area.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,4 @@
#include <d/a/obj/d_a_obj_base.h>
#include <d/d_player.h>
#include <f/f_list_nd.h>
#include <s/s_State.hpp>
#include <s/s_StateMgr.hpp>

// Look I don't know why these levels of subclasses work
class fLiNdBa_Wood_c : public fLiNdBaAutoUnlink_c {
public:
fLiNdBa_Wood_c() : fLiNdBaAutoUnlink_c(nullptr) {}
};

class dAcTWoodArea_c : public dAcObjBase_c {
public:
dAcTWoodArea_c() : mStateMgr(*this, sStateID::null) {}
virtual ~dAcTWoodArea_c() {}
virtual int actorCreate() override;
virtual int actorPostCreate() override;
virtual int actorExecute() override;
virtual int draw() override;
virtual int doDelete() override;

void attachCloseObjects(ProfileName profID);
void dropItems();
bool attachObject(dAcObjBase_c *obj);

f32 getAttachRadius() {
return scale.x * scaleX;
}
f32 getAttachRadiusSquare() {
return getAttachRadius() * getAttachRadius();
}

f32 getAttachHeight() {
return scale.y * scaleY;
}

STATE_FUNC_DECLARE(dAcTWoodArea_c, Init);
STATE_FUNC_DECLARE(dAcTWoodArea_c, Wait);

static const f32 scaleX;
static const f32 scaleY;

private:
STATE_MGR_DECLARE(dAcTWoodArea_c);

fLiNdBa_Wood_c mRefs[8];
};
#include <d/a/d_a_t_wood_area.h>

const f32 dAcTWoodArea_c::scaleX = 100.0f;
const f32 dAcTWoodArea_c::scaleY = 100.0f;
Expand Down Expand Up @@ -101,6 +54,7 @@ extern "C" void fn_800298B0(u16, mVec3_c *, mAng3_c *, u32, u32, u32, u32, u32);
extern u16 PARTICLE_RESOURCE_ID_MAPPING[];

void dAcTWoodArea_c::initializeState_Wait() {}

void dAcTWoodArea_c::executeState_Wait() {
if (dPlayer::LINK != nullptr && (dPlayer::LINK->someFlags & 0x2000)) {
// This is a bit messed up
Expand Down Expand Up @@ -141,8 +95,8 @@ void dAcTWoodArea_c::attachCloseObjects(ProfileName profID) {

void dAcTWoodArea_c::dropItems() {
for (int i = 0; i < 8; i++) {
if (mRefs[i].p_owner != nullptr) {
if (static_cast<dAcObjBase_c *>(mRefs[i].p_owner)->drop()) {
if (mRefs[i].get() != nullptr) {
if (mRefs[i].get()->drop()) {
mRefs[i].unlink();
}
}
Expand All @@ -151,7 +105,7 @@ void dAcTWoodArea_c::dropItems() {

bool dAcTWoodArea_c::attachObject(dAcObjBase_c *obj) {
for (int i = 0; i < 8; i++) {
if (mRefs[i].p_owner == nullptr) {
if (mRefs[i].get() == nullptr) {
mRefs[i].link(obj);
return true;
}
Expand Down
16 changes: 7 additions & 9 deletions src/REL/d/t/d_t_tumble_weed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ void dTgTumbleWeed_c::executeState_AreaIn() {
}
void dTgTumbleWeed_c::finalizeState_AreaIn() {}

extern "C" void fn_475_1B00(fBase_c *, mVec3_c&);
extern "C" void fn_475_1B00(fBase_c *, mVec3_c &);
void dTgTumbleWeed_c::initializeState_Wind() {
mVec3_c vec;
getWind(&vec);
if (childTumbleweed.p_owner != nullptr) {
fn_475_1B00(childTumbleweed.p_owner, vec);
if (childTumbleweed.get() != nullptr) {
fn_475_1B00(childTumbleweed.get(), vec);
}
}

Expand All @@ -94,7 +94,7 @@ void dTgTumbleWeed_c::finalizeState_Wind() {}

bool dTgTumbleWeed_c::shouldSpawnTumbleweed() {
bool spawnAllowed = false;
if (childTumbleweed.p_owner == nullptr && cM::rnd() <= 0.8f) {
if (childTumbleweed.get() == nullptr && cM::rnd() <= 0.8f) {
spawnAllowed = true;
}

Expand All @@ -105,10 +105,8 @@ bool dTgTumbleWeed_c::shouldSpawnTumbleweed() {
return false;
}


bool dTgTumbleWeed_c::shouldDoWind() {
return childTumbleweed.p_owner != nullptr && cM::rnd() <= 0.5f;
}
void dTgTumbleWeed_c::doSpawnTumbleweed() {
return childTumbleweed.get() != nullptr && cM::rnd() <= 0.5f;
}
void dTgTumbleWeed_c::getWind(mVec3_c*) {}
void dTgTumbleWeed_c::doSpawnTumbleweed() {}
void dTgTumbleWeed_c::getWind(mVec3_c *) {}
8 changes: 4 additions & 4 deletions src/d/a/d_a_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dAcBase_c::dAcBase_c()
}

// 8002c530
dBase_c::~dBase_c() {}
// dBase_c::~dBase_c() {}

dAcBase_c::~dAcBase_c() {}

Expand Down Expand Up @@ -327,7 +327,7 @@ void dAcBase_c::forEveryActor(void *func(dAcBase_c *, dAcBase_c *), dAcBase_c *p
}

// 8002d190
mAng dAcBase_c::getXZAngleToPlayer(s16 *angle) {
mAng dAcBase_c::getXZAngleToPlayer() {
return targetAngleY(&this->position, &dPlayer::LINK->position);
}

Expand Down Expand Up @@ -392,7 +392,7 @@ bool dAcBase_c::getDistanceAndAngleToActor(dAcBase_c *actor, f32 distThresh, s16
}

// 8002d3e0
bool dAcBase_c::isWithinPlayerRadius(f32 radius) {
bool dAcBase_c::isWithinPlayerRadius(f32 radius) const {
f32 dist_diff = getSquareDistanceTo(dPlayer::LINK->position);
return dist_diff < radius * radius;
}
Expand Down Expand Up @@ -462,7 +462,7 @@ SoundSource *dAcBase_c::getSoundSource() {
void dAcBase_c::FUN_8002d890() {}

// current name is Global__setActorRef
void dAcBase_c::setActorRef(dBase_c *ref) {
void dAcBase_c::setActorRef(dAcBase_c *ref) {
actor_node.link(ref);
}

Expand Down

0 comments on commit 8acccaf

Please sign in to comment.