Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
BoxColManager.hh
1
#pragma once
2
3
#include <egg/core/BitFlag.hh>
4
#include <egg/math/Vector.hh>
5
6
namespace
Kinoko {
7
8
namespace
Host
{
9
10
class
Context
;
11
12
}
// namespace Host
13
14
namespace
Kart
{
15
16
class
KartObject
;
17
18
}
// namespace Kart
19
20
namespace
Field
{
21
22
class
ObjectCollidable;
23
class
ObjectDrivable;
24
28
enum class
eBoxColFlag
{
29
Driver = 0,
30
Object = 3,
31
Drivable = 4,
32
PermRecalcAABB
= 8,
33
Intangible
= 9,
34
Active = 10,
35
TempRecalcAABB
= 11,
36
};
37
typedef
EGG::TBitFlag<u32, eBoxColFlag>
BoxColFlag;
38
40
struct
BoxColUnit {
41
BoxColUnit();
42
~BoxColUnit();
43
44
void
init(f32 radius, f32 maxSpeed,
const
EGG::Vector3f
*pos,
const
BoxColFlag &flag,
45
void
*userData);
46
void
makeInactive();
47
void
resize(f32 radius, f32 maxSpeed);
48
void
reinsert();
49
void
search(
const
BoxColFlag &flag);
50
51
const
EGG::Vector3f
*m_pos;
52
f32 m_radius;
53
f32 m_range;
54
BoxColFlag m_flag;
55
void
*m_userData;
56
s16 m_highPointIdx;
57
s16 m_lowPointIdx;
58
f32 m_xMax;
59
f32 m_xMin;
60
};
61
62
struct
BoxColLowPoint
{
63
f32 z;
64
u8 highPoint;
65
u8 unitID;
66
};
67
68
struct
BoxColHighPoint
{
69
f32 z;
70
u8 lowPoint;
71
u8 minLowPoint;
72
};
73
75
class
BoxColManager
:
EGG::Disposer
{
76
friend
class
Host::Context
;
77
78
public
:
79
BoxColManager
();
80
~BoxColManager
()
override
;
81
82
void
clear();
83
void
calc
();
84
85
[[nodiscard]]
ObjectCollidable
*getNextObject();
86
[[nodiscard]]
ObjectDrivable
*getNextDrivable();
87
88
void
resetIterators();
89
90
[[nodiscard]]
BoxColUnit
*insertDriver(f32 radius, f32 maxSpeed,
const
EGG::Vector3f
*pos,
91
bool
alwaysRecalc,
Kart::KartObject
*kartObject);
92
[[nodiscard]]
BoxColUnit
*insertObject(f32 radius, f32 maxSpeed,
const
EGG::Vector3f
*pos,
93
bool
alwaysRecalc,
void
*userData);
94
[[nodiscard]]
BoxColUnit
*insertDrivable(f32 radius, f32 maxSpeed,
const
EGG::Vector3f
*pos,
95
bool
alwaysRecalc,
void
*userData);
96
97
void
reinsertUnit(
BoxColUnit
*unit);
98
void
remove(
BoxColUnit
*&unit);
99
void
search(
BoxColUnit
*unit,
const
BoxColFlag &flag);
100
void
search(f32 radius,
const
EGG::Vector3f
&pos,
const
BoxColFlag &flag);
101
102
[[nodiscard]]
bool
isSphereInSpatialCache(f32 radius,
const
EGG::Vector3f
&pos,
103
const
BoxColFlag &flag)
const
;
104
105
static
BoxColManager
*CreateInstance();
106
static
void
DestroyInstance();
107
[[nodiscard]]
static
BoxColManager
*Instance();
108
109
private
:
110
[[nodiscard]]
void
*
getNextImpl
(s32 &
id
,
const
BoxColFlag &flag);
111
void
iterate(s32 &iter,
const
BoxColFlag &flag);
112
[[nodiscard]]
BoxColUnit
*insert(f32 radius, f32 maxSpeed,
const
EGG::Vector3f
*pos,
113
const
BoxColFlag &flag,
void
*userData);
114
void
searchImpl(
BoxColUnit
*unit,
const
BoxColFlag &flag);
115
void
searchImpl(f32 radius,
const
EGG::Vector3f
&pos,
const
BoxColFlag &flag);
116
117
static
constexpr
size_t
MAX_UNIT_COUNT = 0x100;
118
119
std::array<BoxColHighPoint, MAX_UNIT_COUNT>
m_highPoints
;
120
std::array<BoxColLowPoint, MAX_UNIT_COUNT>
m_lowPoints
;
121
std::array<BoxColUnit, MAX_UNIT_COUNT>
m_unitPool
;
122
std::array<BoxColUnit *, MAX_UNIT_COUNT>
m_units
;
123
125
std::array<u32, MAX_UNIT_COUNT>
m_unitIDs
;
126
127
s32 m_unitCount;
128
s32 m_nextUnitID;
129
s32 m_nextObjectID;
130
s32 m_nextDrivableID;
131
s32 m_maxID;
132
BoxColUnit
*m_cacheQueryUnit;
133
EGG::Vector3f
m_cachePoint;
134
f32 m_cacheRadius;
135
BoxColFlag m_cacheFlag;
136
137
static
BoxColManager
*s_instance;
138
};
139
140
}
// namespace Field
141
142
}
// namespace Kinoko
Kinoko::EGG::Disposer
An interface for ensuring certain structures and classes are destroyed with the heap.
Definition
Disposer.hh:11
Kinoko::Field::BoxColManager::getNextImpl
void * getNextImpl(s32 &id, const BoxColFlag &flag)
Helper function since the getters share all code except the flag.
Definition
BoxColManager.cc:356
Kinoko::Field::BoxColManager::m_units
std::array< BoxColUnit *, MAX_UNIT_COUNT > m_units
Units within our search bounds.
Definition
BoxColManager.hh:122
Kinoko::Field::BoxColManager::m_unitPool
std::array< BoxColUnit, MAX_UNIT_COUNT > m_unitPool
Where all the units live.
Definition
BoxColManager.hh:121
Kinoko::Field::BoxColManager::m_highPoints
std::array< BoxColHighPoint, MAX_UNIT_COUNT > m_highPoints
A unit's rightmost Z-axis point.
Definition
BoxColManager.hh:119
Kinoko::Field::BoxColManager::m_lowPoints
std::array< BoxColLowPoint, MAX_UNIT_COUNT > m_lowPoints
A unit's leftmost Z-axis point;.
Definition
BoxColManager.hh:120
Kinoko::Field::BoxColManager::m_unitIDs
std::array< u32, MAX_UNIT_COUNT > m_unitIDs
Specifies what unit to retrieve from the pool during allocation.
Definition
BoxColManager.hh:125
Kinoko::Field::BoxColManager::BoxColManager
BoxColManager()
Creates two intangible units to represent the spatial bounds.
Definition
BoxColManager.cc:55
Kinoko::Field::BoxColManager::calc
void calc()
Recalculate the bounds of all active units having PermRecalcAABB or TempRecalcAABB flag,...
Definition
BoxColManager.cc:94
Kinoko::Field::ObjectCollidable
Definition
ObjectCollidable.hh:18
Kinoko::Field::ObjectDrivable
Definition
ObjectDrivable.hh:9
Kinoko::Host::Context
Contexts can be used to restore a previous memory state for the current session.
Definition
Context.hh:71
Kinoko::Kart::KartObject
The highest level abstraction for a kart.
Definition
KartObject.hh:11
Kinoko::Field
Pertains to collision.
Definition
BoxColManager.cc:10
Kinoko::Field::eBoxColFlag
eBoxColFlag
A bitfield that represents the state and type of a given BoxColUnit.
Definition
BoxColManager.hh:28
Kinoko::Field::eBoxColFlag::TempRecalcAABB
@ TempRecalcAABB
Only recalculate once.
Definition
BoxColManager.hh:35
Kinoko::Field::eBoxColFlag::PermRecalcAABB
@ PermRecalcAABB
Recalculate this unit's spatial indexing every frame.
Definition
BoxColManager.hh:32
Kinoko::Field::eBoxColFlag::Intangible
@ Intangible
Ignore collision with the unit.
Definition
BoxColManager.hh:33
Kinoko::Host
Represents the host application.
Definition
HeapCommon.hh:11
Kinoko::Kart
Pertains to kart-related functionality.
Definition
BoxColManager.hh:14
Kinoko::EGG::TBitFlag
Wrapper around an integral type with an enum corresponding to its bits.
Definition
BitFlag.hh:23
Kinoko::EGG::Vector3f
A 3D float vector.
Definition
Vector.hh:107
Kinoko::Field::BoxColHighPoint
Definition
BoxColManager.hh:68
Kinoko::Field::BoxColLowPoint
Definition
BoxColManager.hh:62
Kinoko::Field::BoxColUnit
A representation of the boundaries of an entity that has dynamic collision.
Definition
BoxColManager.hh:40
game
field
BoxColManager.hh
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0