Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
MapdataCheckPath.cc
1
#include "game/system/map/MapdataCheckPath.hh"
2
3
namespace
Kinoko::System
{
4
6
MapdataCheckPath::MapdataCheckPath(
const
SData *data) : m_rawData(data), m_depth(-1) {
7
EGG::RamStream stream = EGG::RamStream(data,
sizeof
(SData));
8
read(stream);
9
m_oneOverCount = 1.0f / m_size;
10
}
11
12
void
MapdataCheckPath::read(EGG::Stream &stream) {
13
m_start = stream.read_u8();
14
m_size = stream.read_u8();
15
for
(
auto
&prev : m_prev) {
16
prev = stream.read_u8();
17
}
18
19
for
(
auto
&next : m_next) {
20
next = stream.read_u8();
21
}
22
}
23
27
void
MapdataCheckPath::findDepth
(s8 depth,
const
MapdataCheckPathAccessor
&accessor) {
28
if
(
m_depth
!= -1) {
29
return
;
30
}
31
32
m_depth
= depth;
33
34
for
(
auto
&nextID :
m_next
) {
35
if
(nextID == 0xFF) {
36
continue
;
37
}
38
39
accessor.get(nextID)->
findDepth
(depth + 1, accessor);
40
}
41
}
42
44
MapdataCheckPathAccessor::MapdataCheckPathAccessor(
const
MapSectionHeader
*header)
45
:
MapdataAccessorBase
<
MapdataCheckPath
,
MapdataCheckPath
::SData>(header) {
46
init(
reinterpret_cast<
const
MapdataCheckPath::SData
*
>
(m_sectionHeader + 1),
47
parse<u16>(m_sectionHeader->count));
48
49
if
(m_entryCount == 0) {
50
return
;
51
}
52
53
// Maximum number of paths one could traverse through in a lap
54
s8 maxDepth = -1;
55
get(0)->findDepth(0, *
this
);
56
57
for
(
size_t
i = 0; i < size(); ++i) {
58
maxDepth = std::max(maxDepth, get(i)->depth());
59
}
60
61
m_lapProportion = 1.0f / (maxDepth + 1.0f);
62
}
63
64
MapdataCheckPathAccessor::~MapdataCheckPathAccessor() =
default
;
65
67
MapdataCheckPath
*MapdataCheckPathAccessor::findCheckpathForCheckpoint(u16 checkpointId)
const
{
68
for
(
size_t
i = 0; i < size(); ++i) {
69
MapdataCheckPath *checkpath = get(i);
70
if
(checkpath->isPointInPath(checkpointId)) {
71
return
checkpath;
72
}
73
}
74
75
return
nullptr
;
76
}
77
78
f32 MapdataCheckPathAccessor::lapProportion()
const
{
79
return
m_lapProportion
;
80
}
81
82
}
// namespace Kinoko::System
Kinoko::System::MapdataAccessorBase
Definition
MapdataAccessorBase.hh:15
Kinoko::System::MapdataCheckPathAccessor
Definition
MapdataCheckPath.hh:72
Kinoko::System::MapdataCheckPathAccessor::m_lapProportion
f32 m_lapProportion
Minimum proportion of a lap a checkpath can be. Calculated as 1/(maxDepth+1).
Definition
MapdataCheckPath.hh:90
Kinoko::System::MapdataCheckPath
Definition
MapdataCheckPath.hh:11
Kinoko::System::MapdataCheckPath::findDepth
void findDepth(s8 depth, const MapdataCheckPathAccessor &accessor)
Performs DFS to calculate m_depth for all subsequent checkpaths.
Definition
MapdataCheckPath.cc:27
Kinoko::System::MapdataCheckPath::m_depth
s8 m_depth
Definition
MapdataCheckPath.hh:66
Kinoko::System::MapdataCheckPath::m_next
std::array< u8, MAX_NEIGHBORS > m_next
Indices of next connected checkpaths.
Definition
MapdataCheckPath.hh:65
Kinoko::System
High-level handling for generic system operations, such as input reading, race configuration,...
Definition
CourseMap.cc:5
Kinoko::System::MapSectionHeader
Definition
MapdataAccessorBase.hh:9
Kinoko::System::MapdataCheckPath::SData
Definition
MapdataCheckPath.hh:13
game
system
map
MapdataCheckPath.cc
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0