Skip to content

Commit

Permalink
Initialize RTTI's mInitMembers object with 'this' by default, removin…
Browse files Browse the repository at this point in the history
…g the need to initialize it in every RTTI-able object.
  • Loading branch information
jonesmz authored and BearishSun committed Apr 10, 2018
1 parent d6359b0 commit d912535
Show file tree
Hide file tree
Showing 59 changed files with 78 additions and 368 deletions.
16 changes: 2 additions & 14 deletions Documentation/Manuals/User/serializingObjects.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,11 @@ public:
BS_RTTI_MEMBER_PLAIN(myString, 2)
BS_END_RTTI_MEMBERS
MyComponentRTTI()
:mInitMembers(this)
{ }
// ...
};
~~~~~~~~~~~~~

Field definition portion of the RTTI type always begins with the @ref bs::BS_BEGIN_RTTI_MEMBERS "BS_BEGIN_RTTI_MEMBERS" macro, and ends with the @ref bs::BS_END_RTTI_MEMBERS "BS_END_RTTI_MEMBERS". If field definition is provided you must also provide a constructor that initializes the *mInitMembers* with the *this* pointer.
Field definition portion of the RTTI type always begins with the @ref bs::BS_BEGIN_RTTI_MEMBERS "BS_BEGIN_RTTI_MEMBERS" macro, and ends with the @ref bs::BS_END_RTTI_MEMBERS "BS_END_RTTI_MEMBERS".

The field members themselves are defined by calling macros starting with BS_RTTI_MEMBER_*. The macro expects the name of the field it describes, as well as a unique ID of the field. The suffix of the BS_RTTI_MEMBER_* macro depends on the type of the field being added. There are three different types:
- @ref bs::BS_RTTI_MEMBER_PLAIN "BS_RTTI_MEMBER_PLAIN" - Field containing basic data types like ints, floats, strings or other types that can be just trivially copied during serialization/deserialization.
Expand Down Expand Up @@ -191,10 +187,6 @@ public:
BS_RTTI_MEMBER_REFL(mesh, 6)
BS_END_RTTI_MEMBERS
MyComponentRTTI()
:mInitMembers(this)
{ }
// ...
};
~~~~~~~~~~~~~
Expand Down Expand Up @@ -233,10 +225,6 @@ public:
BS_RTTI_MEMBER_REFL_ARRAY(meshes, 2)
BS_END_RTTI_MEMBERS
MyComponentRTTI()
:mInitMembers(this)
{ }
// ...
};
~~~~~~~~~~~~~
Expand Down Expand Up @@ -270,4 +258,4 @@ UINT8* data = ms.encode(myObject.get(), size);
SPtr<IReflectable> myObjectCopy2 = ms.decode(data, size);
bs_free(data);
~~~~~~~~~~~~~
~~~~~~~~~~~~~
8 changes: 1 addition & 7 deletions Source/Foundation/bsfCore/Private/RTTI/BsAnimationClipRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ namespace bs
BS_RTTI_MEMBER_PLAIN_NAMED(rootMotionRot, mRootMotion->rotation, 9)
BS_END_RTTI_MEMBERS
public:
AnimationClipRTTI()
:mInitMembers(this)
{

}

void onDeserializationEnded(IReflectable* obj, const UnorderedMap<String, UINT64>& params) override
{
AnimationClip* clip = static_cast<AnimationClip*>(obj);
Expand All @@ -110,4 +104,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ namespace bs
BS_RTTI_MEMBER_PLAIN(mBitDepth, 3)
BS_END_RTTI_MEMBERS
public:
AudioClipImportOptionsRTTI()
:mInitMembers(this)
{ }

/** @copydoc RTTIType::getRTTIName */
const String& getRTTIName() override
{
Expand All @@ -49,4 +45,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
3 changes: 1 addition & 2 deletions Source/Foundation/bsfCore/Private/RTTI/BsAudioClipRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace bs

public:
AudioClipRTTI()
:mInitMembers(this)
{
addDataBlockField("mData", 6, &AudioClipRTTI::getData, &AudioClipRTTI::setData, 0);
}
Expand Down Expand Up @@ -78,4 +77,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
4 changes: 0 additions & 4 deletions Source/Foundation/bsfCore/Private/RTTI/BsAudioListenerRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ namespace bs
BS_END_RTTI_MEMBERS

public:
AudioListenerRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "AudioListener";
Expand Down
4 changes: 0 additions & 4 deletions Source/Foundation/bsfCore/Private/RTTI/BsAudioSourceRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ namespace bs
BS_RTTI_MEMBER_PLAIN(mAttenuation, 10)
BS_END_RTTI_MEMBERS
public:
AudioSourceRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "AudioSource";
Expand Down
6 changes: 1 addition & 5 deletions Source/Foundation/bsfCore/Private/RTTI/BsCAnimationRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ namespace bs
BS_RTTI_MEMBER_PLAIN(mBounds, 5)
BS_END_RTTI_MEMBERS
public:
CAnimationRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CAnimation";
Expand All @@ -48,4 +44,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ namespace bs
BS_RTTI_MEMBER_REFLPTR(mInternal, 0)
BS_END_RTTI_MEMBERS
public:
CAudioListenerRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CAudioListener";
Expand All @@ -43,4 +39,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
6 changes: 1 addition & 5 deletions Source/Foundation/bsfCore/Private/RTTI/BsCAudioSourceRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ namespace bs
BS_RTTI_MEMBER_PLAIN(mAttenuation, 8)
BS_END_RTTI_MEMBERS
public:
CAudioSourceRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CAudioSource";
Expand All @@ -51,4 +47,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
6 changes: 1 addition & 5 deletions Source/Foundation/bsfCore/Private/RTTI/BsCBoneRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ namespace bs
BS_RTTI_MEMBER_PLAIN(mBoneName, 0)
BS_END_RTTI_MEMBERS
public:
CBoneRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CBone";
Expand All @@ -43,4 +39,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
6 changes: 1 addition & 5 deletions Source/Foundation/bsfCore/Private/RTTI/BsCBoxColliderRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ namespace bs
BS_RTTI_MEMBER_PLAIN(mExtents, 0)
BS_END_RTTI_MEMBERS
public:
CBoxColliderRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CBoxCollider";
Expand All @@ -44,4 +40,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ namespace bs
BS_RTTI_MEMBER_PLAIN(mHalfHeight, 2)
BS_END_RTTI_MEMBERS
public:
CCapsuleColliderRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CCapsuleCollider";
Expand All @@ -46,4 +42,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ namespace bs
BS_END_RTTI_MEMBERS

public:
CCharacterControllerRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CCharacterController";
Expand All @@ -55,4 +51,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
6 changes: 1 addition & 5 deletions Source/Foundation/bsfCore/Private/RTTI/BsCColliderRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ namespace bs
BS_RTTI_MEMBER_PLAIN(mCollisionReportMode, 8)
BS_END_RTTI_MEMBERS
public:
CColliderRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CCollider";
Expand All @@ -51,4 +47,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
13 changes: 6 additions & 7 deletions Source/Foundation/bsfCore/Private/RTTI/BsCD6JointRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ namespace bs

public:
CD6JointRTTI()
:mInitMembers(this)
{
addPlainArrayField("mMotion", 0, &CD6JointRTTI::getMotion, &CD6JointRTTI::getMotionCount,
addPlainArrayField("mMotion", 0, &CD6JointRTTI::getMotion, &CD6JointRTTI::getMotionCount,
&CD6JointRTTI::setMotion, &CD6JointRTTI::setMotionCount);
addPlainArrayField("mDriveStiffnes", 1, &CD6JointRTTI::getDriveStiffness, &CD6JointRTTI::getDriveCount,
addPlainArrayField("mDriveStiffnes", 1, &CD6JointRTTI::getDriveStiffness, &CD6JointRTTI::getDriveCount,
&CD6JointRTTI::setDriveStiffness, &CD6JointRTTI::setDriveCount);
addPlainArrayField("mDriveDamping", 2, &CD6JointRTTI::getDriveDamping, &CD6JointRTTI::getDriveCount,
addPlainArrayField("mDriveDamping", 2, &CD6JointRTTI::getDriveDamping, &CD6JointRTTI::getDriveCount,
&CD6JointRTTI::setDriveDamping, &CD6JointRTTI::setDriveCount);
addPlainArrayField("mDriveForceLimit", 3, &CD6JointRTTI::getDriveForceLimit, &CD6JointRTTI::getDriveCount,
addPlainArrayField("mDriveForceLimit", 3, &CD6JointRTTI::getDriveForceLimit, &CD6JointRTTI::getDriveCount,
&CD6JointRTTI::setDriveForceLimit, &CD6JointRTTI::setDriveCount);
addPlainArrayField("mDriveAcceleartion", 4, &CD6JointRTTI::getDriveAcceleration, &CD6JointRTTI::getDriveCount,
addPlainArrayField("mDriveAcceleartion", 4, &CD6JointRTTI::getDriveAcceleration, &CD6JointRTTI::getDriveCount,
&CD6JointRTTI::setDriveAcceleration, &CD6JointRTTI::setDriveCount);
}

Expand All @@ -98,4 +97,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ namespace bs
BS_END_RTTI_MEMBERS

public:
CDistanceJointRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CDistanceJoint";
Expand All @@ -49,4 +45,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
6 changes: 1 addition & 5 deletions Source/Foundation/bsfCore/Private/RTTI/BsCHingeJointRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ namespace bs
BS_END_RTTI_MEMBERS

public:
CHingeJointRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CHingeJoint";
Expand All @@ -54,4 +50,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
5 changes: 2 additions & 3 deletions Source/Foundation/bsfCore/Private/RTTI/BsCJointRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace bs
BS_RTTI_MEMBER_PLAIN_NAMED(mRotationB, mRotations[1], 5)
BS_END_RTTI_MEMBERS

float& getBreakForce(OwnerType* obj) { return obj->mDesc.breakForce; }
float& getBreakForce(OwnerType* obj) { return obj->mDesc.breakForce; }
void setBreakForce(OwnerType* obj, float& val) { obj->mDesc.breakForce = val; }

float& getBreakTorque(OwnerType* obj) { return obj->mDesc.breakTorque; }
Expand All @@ -37,7 +37,6 @@ namespace bs

public:
CJointRTTI()
:mInitMembers(this)
{
addPlainField("BreakForce", 6, &CJointRTTI::getBreakForce, &CJointRTTI::setBreakForce);
addPlainField("BreakTorque", 7, &CJointRTTI::getBreakTorque, &CJointRTTI::setBreakTorque);
Expand All @@ -64,4 +63,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ namespace bs
BS_END_RTTI_MEMBERS

public:
CLightProbeVolumeRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CLightProbeVolume";
Expand All @@ -45,4 +41,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
6 changes: 1 addition & 5 deletions Source/Foundation/bsfCore/Private/RTTI/BsCMeshColliderRTTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ namespace bs
BS_RTTI_MEMBER_REFL(mMesh, 0)
BS_END_RTTI_MEMBERS
public:
CMeshColliderRTTI()
:mInitMembers(this)
{ }

const String& getRTTIName() override
{
static String name = "CMeshCollider";
Expand All @@ -44,4 +40,4 @@ namespace bs

/** @} */
/** @endcond */
}
}
Loading

0 comments on commit d912535

Please sign in to comment.