Merge pull request #3 from robojumper/mAng_flindba

Fix mAng3_c copy assignment, clean up list node templates
This commit is contained in:
robojumper
2024-06-27 23:42:48 +02:00
committed by GitHub
11 changed files with 126 additions and 90 deletions
+40 -6
View File
@@ -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() {
@@ -61,7 +96,7 @@ public:
/* 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;
@@ -117,7 +152,7 @@ public:
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;
}
@@ -148,14 +183,13 @@ public:
/* 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();
@@ -183,7 +217,7 @@ public:
// 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();
+46
View File
@@ -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
+1 -1
View File
@@ -16,7 +16,7 @@ public:
/* 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();
+3 -7
View File
@@ -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) {}
@@ -35,7 +29,9 @@ private:
u16 tumbleweedTimer;
u16 padding;
u16 windTimer;
fLiNdTumbleweed_c childTumbleweed;
// TODO dAcObjTumbleWeed
dAcRef_c<dAcBase_c> childTumbleweed;
u16 someField;
};
#endif
-6
View File
@@ -28,10 +28,4 @@ public:
fBase_c *p_owner;
};
class fLiNdBaAutoUnlink_c : public fLiNdBa_c {
public:
fLiNdBaAutoUnlink_c(fBase_c *owner) : fLiNdBa_c(owner) {}
~fLiNdBaAutoUnlink_c() { unlink(); }
};
#endif
+15 -1
View File
@@ -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;
@@ -18,6 +21,17 @@ public:
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;