A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectHitTable.cc
1#include "ObjectHitTable.hh"
2
3#include "game/system/ResourceManager.hh"
4
5#include <egg/util/Stream.hh>
6
7namespace Field {
8
10ObjectHitTable::ObjectHitTable(const char *filename) {
11 size_t size;
12 void *file =
13 System::ResourceManager::Instance()->getFile(filename, &size, System::ArchiveId::Core);
14
15 EGG::RamStream stream = EGG::RamStream(file, size);
16
17 m_count = stream.read_s16();
18 m_fieldCount = stream.read_s16();
19 m_reactions = std::span<s16>(new s16[m_count], m_count);
20
21 for (auto &reaction : m_reactions) {
22 stream.skip(0x2);
23 reaction = stream.read_s16();
24 stream.skip(m_fieldCount * 2 - 2);
25 }
26
27 m_slots = reinterpret_cast<const s16 *>(stream.dataAtIndex());
28}
29
31ObjectHitTable::~ObjectHitTable() {
32 delete m_reactions.data();
33}
34
35Kart::Reaction ObjectHitTable::reaction(s16 i) const {
36 ASSERT(i != -1);
37 ASSERT(i < m_count);
38 return static_cast<Kart::Reaction>(m_reactions[i]);
39}
40
41s16 ObjectHitTable::slot(ObjectId id) const {
42 constexpr size_t SLOT_COUNT = 0x2f4;
43
44 size_t i = static_cast<std::underlying_type_t<ObjectId>>(id);
45 return i < SLOT_COUNT ? parse<s16>(m_slots[i]) : -1;
46}
47
48} // namespace Field
A stream of data stored in memory.
Definition Stream.hh:64
Pertains to collision.