A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
AnmObj.hh
1#pragma once
2
3#include <Common.hh>
4
5// Credit: kiwi515/ogws
6
7namespace Kinoko::Abstract::g3d {
8
9enum class AnmPolicy : u32 {
10 OneTime = 0,
11 Loop = 1,
12 Max = 2,
13};
14
15[[nodiscard]] f32 PlayPolicy_Onetime(f32 start, f32 end, f32 frame);
16[[nodiscard]] f32 PlayPolicy_Loop(f32 start, f32 end, f32 frame);
17
18typedef f32 (*PlayPolicyFunc)(f32 start, f32 end, f32 frame);
19
20[[nodiscard]] inline PlayPolicyFunc GetAnmPlayPolicy(AnmPolicy policy) {
21 constexpr size_t count = static_cast<size_t>(AnmPolicy::Max);
22 static constexpr PlayPolicyFunc POLICY_TABLE[count] = {
23 PlayPolicy_Onetime,
24 PlayPolicy_Loop,
25 };
26
27 size_t idx = static_cast<size_t>(policy);
28 ASSERT(idx < count);
29 return POLICY_TABLE[idx];
30}
31
32class FrameCtrl {
33 friend class Host::Context;
34
35public:
36 FrameCtrl(f32 start, f32 end, PlayPolicyFunc policy)
37 : m_frame(0.0f), m_updateRate(1.0f), m_startFrame(start), m_endFrame(end),
38 m_playPolicy(policy) {
39 ASSERT(m_playPolicy);
40 }
41
42 void updateFrame() {
43 setFrame(m_updateRate * s_baseUpdateRate + m_frame);
44 }
45
47 [[nodiscard]] f32 frame() const {
48 return m_frame;
49 }
50
51 [[nodiscard]] f32 rate() const {
52 return m_updateRate;
53 }
54
55 [[nodiscard]] PlayPolicyFunc playPolicy() const {
56 return m_playPolicy;
57 }
59
61 void setFrame(f32 frame) {
62 m_frame = m_playPolicy(m_startFrame, m_endFrame, frame);
63 }
64
65 void setRate(f32 rate) {
66 m_updateRate = rate;
67 }
68
69 void setPlayPolicy(PlayPolicyFunc func) {
70 ASSERT(func);
71 m_playPolicy = func;
72 }
74
75private:
76 f32 m_frame;
77 f32 m_updateRate;
78 f32 m_startFrame;
79 f32 m_endFrame;
80 PlayPolicyFunc m_playPolicy;
81
82 static f32 s_baseUpdateRate;
83};
84
85} // namespace Kinoko::Abstract::g3d
This header houses common data types such as our integral types and enums.
Contexts can be used to restore a previous memory state for the current session.
Definition Context.hh:70