A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
Archive.cc
1#include "Archive.hh"
2
3#include <algorithm>
4#include <cstddef>
5
6namespace EGG {
7
12 auto iter = std::find(s_archiveList.begin(), s_archiveList.end(), this);
13 if (iter != s_archiveList.end()) {
14 s_archiveList.erase(iter);
15 }
16}
17
19void Archive::unmount() {
20 if (--m_refCount <= 0) {
21 delete this;
22 }
23}
24
26s32 Archive::convertPathToEntryId(const char *path) const {
27 return m_handle.convertPathToEntryId(path);
28}
29
31void *Archive::getFileFast(s32 entryId, Abstract::ArchiveHandle::FileInfo &info) const {
32 m_handle.open(entryId, info);
33 return m_handle.getFileAddress(info);
34}
35
40Archive *Archive::FindArchive(void *archiveStart) {
41 ASSERT(archiveStart);
42
43 for (auto iter = s_archiveList.begin(); iter != s_archiveList.end(); ++iter) {
44 if ((*iter)->m_handle.startAddress() == archiveStart) {
45 return *iter;
46 }
47 }
48
49 return nullptr;
50}
51
56Archive *Archive::Mount(void *archiveStart) {
57 Archive *archive = FindArchive(archiveStart);
58
59 if (!archive) {
60 // Create a new archive and add it to the list
61 archive = new Archive(archiveStart);
62 s_archiveList.push_back(archive);
63 } else {
64 // It already exists, increase the reference count
65 archive->m_refCount++;
66 }
67
68 return archive;
69}
70
72Archive::Archive(void *archiveStart) : m_handle(archiveStart) {}
73
74std::list<Archive *> Archive::s_archiveList;
75
76} // namespace EGG
static std::list< Archive * > s_archiveList
The linked list of all mounted archives.
Definition Archive.hh:27
static Archive * FindArchive(void *archiveStart)
Checks to see if a given archive is already mounted.
Definition Archive.cc:40
~Archive()
Removes the archive from the static list.
Definition Archive.cc:11
static Archive * Mount(void *archiveStart)
Creates a new Archive object or increments the ref count for an already existing Archive.
Definition Archive.cc:56
EGG core library.
Definition Archive.cc:6