Skip to content

Commit

Permalink
xrRender/animation_motion: modernize MotionID with C++11
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Apr 14, 2023
1 parent 262588a commit dd2f60a
Showing 1 changed file with 49 additions and 21 deletions.
70 changes: 49 additions & 21 deletions src/Include/xrRender/animation_motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

struct MotionID
{
private:
typedef const MotionID* (MotionID::*unspecified_bool_type)() const;

public:
union
{
Expand All @@ -14,30 +11,61 @@ struct MotionID
u16 slot : 16; // 2
};
//. u16 val;
u32 val;
u32 val{ u32(-1) };
};

public:
MotionID() { invalidate(); }
MotionID(u16 motion_slot, u16 motion_idx) { set(motion_slot, motion_idx); }
ICF bool operator==(const MotionID& tgt) const { return tgt.val == val; }
ICF bool operator!=(const MotionID& tgt) const { return tgt.val != val; }
ICF bool operator<(const MotionID& tgt) const { return val < tgt.val; }
ICF bool operator!() const { return !valid(); }
ICF MotionID() = default;

ICF MotionID(MotionID&& other) noexcept : val(other.val)
{
other.invalidate();
}

ICF MotionID(const MotionID& other) noexcept : val(other.val) {}

ICF MotionID(u16 motion_slot, u16 motion_idx) noexcept
: idx(motion_idx), slot(motion_slot) {}

ICF MotionID& operator=(MotionID&& other) noexcept
{
val = other.val;
other.invalidate();
return *this;
}

ICF MotionID& operator=(const MotionID& other) noexcept
{
val = other.val;
return *this;
}

[[nodiscard]]
ICF bool operator==(const MotionID& tgt) const noexcept { return tgt.val == val; }

[[nodiscard]]
ICF bool operator!=(const MotionID& tgt) const noexcept { return tgt.val != val; }

[[nodiscard]]
ICF bool operator<(const MotionID& tgt) const noexcept { return val < tgt.val; }

[[nodiscard]]
ICF bool operator!() const noexcept { return !valid(); }

ICF void set(u16 motion_slot, u16 motion_idx)
{
slot = motion_slot;
idx = motion_idx;
}
ICF void invalidate() { val = u16(-1); }
ICF bool valid() const { return val != u16(-1); }
const MotionID* get() const { return this; };
ICF operator unspecified_bool_type() const
{
if (valid())
return &MotionID::get;
else
return nullptr;
// return(!valid()?0:&MotionID::get);
}

ICF void invalidate() noexcept { val = u32(-1); }

[[nodiscard]]
ICF bool valid() const noexcept { return val != u32(-1); }

[[nodiscard]]
ICF const MotionID* get() const noexcept { return this; };

[[nodiscard]]
ICF explicit operator bool() const noexcept { return valid(); }
};

0 comments on commit dd2f60a

Please sign in to comment.