A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ResourceManager.cc
1#include "ResourceManager.hh"
2
3#include "game/system/RaceConfig.hh"
4
5namespace System {
6
7#define ARCHIVE_COUNT 2
8
9static const char *const RESOURCE_PATHS[] = {
10 "/Race/Common",
11 nullptr,
12};
13
15void *ResourceManager::getFile(const char *filename, size_t *size, ArchiveId id) {
16 s32 idx = static_cast<s32>(id);
17 return m_archives[idx]->isLoaded() ? m_archives[idx]->getFile(filename, size) : nullptr;
18}
19
21void *ResourceManager::getBsp(Vehicle vehicle, size_t *size) {
22 char buffer[32];
23
24 const char *name = GetVehicleName(vehicle);
25 snprintf(buffer, sizeof(buffer), "/bsp/%s.bsp", name);
26
27 return m_archives[0]->isLoaded() ? m_archives[0]->getFile(buffer, size) : nullptr;
28}
29
31MultiDvdArchive *ResourceManager::load(s32 idx, const char *filename) {
32 // Course has a dedicated load function, so we do not want it here
33 ASSERT(idx != 1);
34
35 if (!filename) {
36 filename = RESOURCE_PATHS[idx];
37 }
38
39 if (!m_archives[idx]->isLoaded() && filename) {
40 m_archives[idx]->load(filename);
41 }
42
43 return m_archives[idx];
44}
45
47MultiDvdArchive *ResourceManager::load(Course courseId) {
48 char buffer[256];
49 snprintf(buffer, sizeof(buffer), "Race/Course/%s", COURSE_NAMES[static_cast<s32>(courseId)]);
50 m_archives[1]->load(buffer);
51 return m_archives[1];
52}
53
55void ResourceManager::unmount(MultiDvdArchive *archive) {
56 archive->unmount();
57}
58
60ResourceManager *ResourceManager::CreateInstance() {
61 ASSERT(!s_instance);
62 s_instance = new ResourceManager;
63 return s_instance;
64}
65
67void ResourceManager::DestroyInstance() {
68 ASSERT(s_instance);
69 auto *instance = s_instance;
70 s_instance = nullptr;
71 delete instance;
72}
73
75ResourceManager::ResourceManager() {
76 m_archives = new MultiDvdArchive *[ARCHIVE_COUNT];
77 for (u8 i = 0; i < ARCHIVE_COUNT; i++) {
78 m_archives[i] = Create(i);
79 }
80}
81
83ResourceManager::~ResourceManager() {
84 if (s_instance) {
85 s_instance = nullptr;
86 WARN("ResourceManager instance not explicitly handled!");
87 }
88}
89
91MultiDvdArchive *ResourceManager::Create(u8 i) {
92 switch (i) {
93 default:
94 return new MultiDvdArchive;
95 }
96}
97
98ResourceManager *ResourceManager::s_instance = nullptr;
99
100} // namespace System
High-level handling for generic system operations, such as input reading, race configuration,...
Definition CourseMap.cc:5