Skip to content

Commit

Permalink
Refactor SyncProperty and Copy macros (#241)
Browse files Browse the repository at this point in the history
* begin syncprop macro refactoring

* start refactoring SYNC_PROP_ACTION in TUs

* finish replacing all SYNC_PROP_ACTIONs

* refactor sync prop method to sync prop set

* begin copy refactoring

* copy macros are pain

* refactor most copy methods

* finish copy refactoring

---------

Co-authored-by: rjkiv <[email protected]>
  • Loading branch information
rjkiv and rjkiv authored Jun 4, 2024
1 parent ca21ec6 commit bfb0f29
Show file tree
Hide file tree
Showing 68 changed files with 430 additions and 418 deletions.
6 changes: 3 additions & 3 deletions src/system/char/CharBoneOffset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ void CharBoneOffset::Load(BinStream& bs){

BEGIN_COPYS(CharBoneOffset)
COPY_SUPERCLASS(Hmx::Object)
GET_COPY(CharBoneOffset)
BEGIN_COPY_CHECKED
CREATE_COPY(CharBoneOffset)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mDest)
COPY_MEMBER(mOffset)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharBoneOffset)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharBoneTwist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ void CharBoneTwist::Load(BinStream& bs){
BEGIN_COPYS(CharBoneTwist)
COPY_SUPERCLASS(Hmx::Object)
COPY_SUPERCLASS(CharWeightable)
GET_COPY(CharBoneTwist)
BEGIN_COPY_CHECKED
CREATE_COPY(CharBoneTwist)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mBone)
COPY_MEMBER(mTargets)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharBoneTwist)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharEyeDartRuleset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ void CharEyeDartRuleset::Load(BinStream& bs){

BEGIN_COPYS(CharEyeDartRuleset)
COPY_SUPERCLASS(Hmx::Object)
GET_COPY(CharEyeDartRuleset)
BEGIN_COPY_CHECKED
CREATE_COPY(CharEyeDartRuleset)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mData.mMinRadius)
// COPY_MEMBER(mData.mMaxRadius)
mData.mMaxRadius = c->mData.mMinRadius;
Expand All @@ -55,7 +55,7 @@ BEGIN_COPYS(CharEyeDartRuleset)
COPY_MEMBER(mData.mMaxSecsBetweenSequences)
COPY_MEMBER(mData.mScaleWithDistance)
COPY_MEMBER(mData.mReferenceDistance)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_PROPSYNCS(CharEyeDartRuleset)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharForeTwist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ void CharForeTwist::Load(BinStream& bs){

BEGIN_COPYS(CharForeTwist)
COPY_SUPERCLASS(Hmx::Object)
GET_COPY(CharForeTwist)
BEGIN_COPY_CHECKED
CREATE_COPY(CharForeTwist)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mOffset)
COPY_MEMBER(mHand)
COPY_MEMBER(mTwist2)
COPY_MEMBER(mBias)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharForeTwist)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharGuitarString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ void CharGuitarString::Load(BinStream& bs){

BEGIN_COPYS(CharGuitarString)
COPY_SUPERCLASS(Hmx::Object)
GET_COPY(CharGuitarString)
BEGIN_COPY_CHECKED
CREATE_COPY(CharGuitarString)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mTarget)
COPY_MEMBER(mNut)
COPY_MEMBER(mBridge)
COPY_MEMBER(mBend)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharGuitarString)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharIKScale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ void CharIKScale::Load(BinStream& bs){
BEGIN_COPYS(CharIKScale)
COPY_SUPERCLASS(Hmx::Object)
COPY_SUPERCLASS(CharWeightable)
GET_COPY(CharIKScale)
BEGIN_COPY_CHECKED
CREATE_COPY(CharIKScale)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mDest)
COPY_MEMBER(mScale)
COPY_MEMBER(mSecondaryTargets)
COPY_MEMBER(mAutoWeight)
COPY_MEMBER(mBottomHeight)
COPY_MEMBER(mTopHeight)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharIKScale)
Expand Down
12 changes: 6 additions & 6 deletions src/system/char/CharIKSliderMidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ void CharIKSliderMidi::Load(BinStream& bs){
BEGIN_COPYS(CharIKSliderMidi)
COPY_SUPERCLASS(Hmx::Object)
COPY_SUPERCLASS(CharWeightable)
GET_COPY(CharIKSliderMidi)
BEGIN_COPY_CHECKED
CREATE_COPY(CharIKSliderMidi)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mTarget)
COPY_MEMBER(mFirstSpot)
COPY_MEMBER(mSecondSpot)
COPY_MEMBER(mTolerance)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharIKSliderMidi)
Expand All @@ -66,9 +66,9 @@ BEGIN_HANDLERS(CharIKSliderMidi)
END_HANDLERS

BEGIN_PROPSYNCS(CharIKSliderMidi)
SYNC_PROP_ACTION(target, mTarget, kPropSize|kPropGet, SetupTransforms())
SYNC_PROP_ACTION(first_spot, mFirstSpot, kPropSize|kPropGet, SetupTransforms())
SYNC_PROP_ACTION(second_spot, mSecondSpot, kPropSize|kPropGet, SetupTransforms())
SYNC_PROP_MODIFY(target, mTarget, SetupTransforms())
SYNC_PROP_MODIFY(first_spot, mFirstSpot, SetupTransforms())
SYNC_PROP_MODIFY(second_spot, mSecondSpot, SetupTransforms())
SYNC_PROP(tolerance, mTolerance)
SYNC_SUPERCLASS(CharWeightable)
END_PROPSYNCS
10 changes: 5 additions & 5 deletions src/system/char/CharMirror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ void CharMirror::Load(BinStream& bs){
BEGIN_COPYS(CharMirror)
COPY_SUPERCLASS(Hmx::Object)
COPY_SUPERCLASS(CharWeightable)
GET_COPY(CharMirror)
BEGIN_COPY_CHECKED
CREATE_COPY(CharMirror)
BEGIN_COPYING_MEMBERS
SetMirrorServo(c->mMirrorServo);
SetServo(c->mServo);
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharMirror)
Expand All @@ -54,7 +54,7 @@ BEGIN_HANDLERS(CharMirror)
END_HANDLERS

BEGIN_PROPSYNCS(CharMirror)
SYNC_PROP_METHOD(servo, (Hmx::Object*)mServo, SetServo(_val.Obj<CharServoBone>(0)));
SYNC_PROP_METHOD(mirror_servo, (Hmx::Object*)mMirrorServo, SetMirrorServo(_val.Obj<CharServoBone>(0)));
SYNC_PROP_SET(servo, (Hmx::Object*)mServo, SetServo(_val.Obj<CharServoBone>(0)));
SYNC_PROP_SET(mirror_servo, (Hmx::Object*)mMirrorServo, SetMirrorServo(_val.Obj<CharServoBone>(0)));
SYNC_SUPERCLASS(CharWeightable);
END_PROPSYNCS
6 changes: 3 additions & 3 deletions src/system/char/CharNeckTwist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ void CharNeckTwist::Load(BinStream& bs){

BEGIN_COPYS(CharNeckTwist)
COPY_SUPERCLASS(Hmx::Object)
GET_COPY(CharNeckTwist)
BEGIN_COPY_CHECKED
CREATE_COPY(CharNeckTwist)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mHead)
COPY_MEMBER(mTwist)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharNeckTwist)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharPosConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ void CharPosConstraint::Load(BinStream& bs){

BEGIN_COPYS(CharPosConstraint)
COPY_SUPERCLASS(Hmx::Object)
GET_COPY(CharPosConstraint)
BEGIN_COPY_CHECKED
CREATE_COPY(CharPosConstraint)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mTargets)
COPY_MEMBER(mSrc)
COPY_MEMBER(mBox)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharPosConstraint)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharSleeve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void CharSleeve::Load(BinStream& bs){

BEGIN_COPYS(CharSleeve)
COPY_SUPERCLASS(Hmx::Object)
GET_COPY(CharSleeve)
BEGIN_COPY_CHECKED
CREATE_COPY(CharSleeve)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mSleeve)
COPY_MEMBER(mTopSleeve)
COPY_MEMBER(mInertia)
Expand All @@ -53,7 +53,7 @@ BEGIN_COPYS(CharSleeve)
COPY_MEMBER(mRange)
COPY_MEMBER(mNegLength)
COPY_MEMBER(mPosLength)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharSleeve)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharTransCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ void CharTransCopy::Load(BinStream& bs){

BEGIN_COPYS(CharTransCopy)
COPY_SUPERCLASS(Hmx::Object)
GET_COPY(CharTransCopy)
BEGIN_COPY_CHECKED
CREATE_COPY(CharTransCopy)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mSrc)
COPY_MEMBER(mDest)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharTransCopy)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharUpperTwist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void CharUpperTwist::Load(BinStream& bs){

BEGIN_COPYS(CharUpperTwist)
COPY_SUPERCLASS(Hmx::Object)
GET_COPY(CharUpperTwist)
BEGIN_COPY_CHECKED
CREATE_COPY(CharUpperTwist)
BEGIN_COPYING_MEMBERS
COPY_MEMBER(mTwist2)
COPY_MEMBER(mUpperArm)
COPY_MEMBER(mTwist1)
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharUpperTwist)
Expand Down
6 changes: 3 additions & 3 deletions src/system/char/CharWeightable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ void CharWeightable::Load(BinStream& bs){
}

BEGIN_COPYS(CharWeightable)
GET_COPY(CharWeightable)
BEGIN_COPY_CHECKED
CREATE_COPY(CharWeightable)
BEGIN_COPYING_MEMBERS
if(ty == kCopyShallow){
mWeightOwner = c->mWeightOwner.mPtr;
}
else {
mWeightOwner = this;
mWeight = c->mWeightOwner->mWeight;
}
END_COPY_CHECKED
END_COPYING_MEMBERS
END_COPYS

BEGIN_HANDLERS(CharWeightable)
Expand Down
58 changes: 44 additions & 14 deletions src/system/obj/ObjMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,40 +128,62 @@ bool PropSync(objType& o, DataNode& _val, DataArray* _prop, int _i, PropOp _op){
#define SYNC_PROP(symbol, member) \
if(sym == symbol) return PropSync(member, _val, _prop, _i + 1, _op);

#define SYNC_PROP_METHOD(symbol, member, method) \
// TODO: make specific sync macros for objects and bitfields?

// for propsyncs that do something extra if the prop op is specifically kPropSet
#define SYNC_PROP_SET(symbol, member, func) \
if(sym == symbol){ \
if(_op == kPropSet) method; \
if(_op == kPropSet){ \
func; \
} \
else { \
if(_op == (PropOp)0x40) return false; \
_val = DataNode(member); \
} \
return true; \
}

#define SYNC_PROP_ACTION(symbol, member, opmask, action) \
// for propsyncs that do NOT use size or get - aka, any combo of set, insert, remove, and handle is used
#define SYNC_PROP_MODIFY(symbol, member, func) \
if(sym == symbol){ \
bool synced = PropSync(member, _val, _prop, _i + 1, _op); \
if(!synced) return false; \
else { \
if(!(_op & (opmask))){ \
action; \
if(!(_op & (kPropSize|kPropGet))){ \
func; \
} \
return true; \
} \
}

// for SYNC_PROP_MODIFY uses where the condition order is flipped
// if you know how to make this macro and SYNC_PROP_MODIFY into one singular macro,
// while still matching every instance of SYNC_PROP_MODIFY being used regardless of condition order,
// by all means please do so, because idk how to do it here
#define SYNC_PROP_MODIFY_ALT(symbol, member, func) \
if(sym == symbol){ \
bool synced = PropSync(member, _val, _prop, _i + 1, _op); \
if(synced){ \
if(!(_op & (kPropSize|kPropGet))){ \
func; \
} \
return true; \
} \
else return false; \
}

#define SYNC_PROP_STATIC(symbol, member) { \
NEW_STATIC_SYMBOL(symbol) \
SYNC_PROP(_s, member) \
}

#define SYNC_PROP_ACTION_STATIC(symbol, member, opmask, action) { \
#define SYNC_PROP_MODIFY_STATIC(symbol, member, func) { \
NEW_STATIC_SYMBOL(symbol) \
SYNC_PROP_ACTION(_s, member, opmask, action) \
SYNC_PROP_MODIFY(_s, member, func) \
}

#define SYNC_SUPERCLASS(parent) \
return parent::SyncProperty(_val, _prop, _i, _op);
if(parent::SyncProperty(_val, _prop, _i, _op)) return true;

#define END_PROPSYNCS \
return false; \
Expand Down Expand Up @@ -192,20 +214,28 @@ void objType::Copy(const Hmx::Object* o, Hmx::Object::CopyType ty){
#define COPY_SUPERCLASS(parent) \
parent::Copy(o, ty);

#define GET_COPY(objType) \
#define CREATE_COPY(objType) \
const objType* c = dynamic_cast<const objType*>(o);

#define GET_COPY_AND_ASSERT(objType, line_num) \
const objType* c = dynamic_cast<const objType*>(o); \
MILO_ASSERT(c, line_num);
// copy macro where you specify the variable name (used in asserts in some copy methods)
#define CREATE_COPY_AS(objType, var_name) \
const objType* var_name = dynamic_cast<const objType*>(o);

#define BEGIN_COPY_CHECKED \
#define BEGIN_COPYING_MEMBERS \
if(c){

// copy macro where you specify the variable name (used in asserts in some copy methods)
#define BEGIN_COPYING_MEMBERS_FROM(copy_name) \
if(copy_name){

#define COPY_MEMBER(mem) \
mem = c->mem;

#define END_COPY_CHECKED \
// copy macro where you specify the variable name (used in asserts in some copy methods)
#define COPY_MEMBER_FROM(copy_name, member) \
member = copy_name->member;

#define END_COPYING_MEMBERS \
}

#define END_COPYS \
Expand Down
2 changes: 1 addition & 1 deletion src/system/rndobj/Anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ DataNode RndAnimatable::OnConvertFrames(DataArray* arr){

BEGIN_PROPSYNCS(RndAnimatable);
SYNC_PROP(rate, (int&)mRate);
SYNC_PROP_ACTION(frame, mFrame, kPropGet|kPropSize, SetFrame(mFrame, 1.0f));
SYNC_PROP_MODIFY(frame, mFrame, SetFrame(mFrame, 1.0f));
END_PROPSYNCS;

AnimTask::AnimTask(RndAnimatable* anim, float start, float end, float fpu, bool loop, float blend) :
Expand Down
Loading

0 comments on commit bfb0f29

Please sign in to comment.