A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ItemDirector.cc
1#include "ItemDirector.hh"
2
3#include "game/system/RaceConfig.hh"
4
5namespace Item {
6
8void ItemDirector::init() {
9 for (auto &kart : m_karts) {
10 kart.inventory().setItem(ItemId::TRIPLE_MUSHROOM);
11 }
12}
13
15void ItemDirector::calc() {
16 for (auto &kart : m_karts) {
17 kart.calc();
18 }
19}
20
22ItemDirector *ItemDirector::CreateInstance() {
23 ASSERT(!s_instance);
24 s_instance = new ItemDirector;
25 return s_instance;
26}
27
29void ItemDirector::DestroyInstance() {
30 ASSERT(s_instance);
31 auto *instance = s_instance;
32 s_instance = nullptr;
33 delete instance;
34}
35
37ItemDirector::ItemDirector() {
38 size_t playerCount = System::RaceConfig::Instance()->raceScenario().playerCount;
39 m_karts = std::span<KartItem>(new KartItem[playerCount], playerCount);
40
41 for (size_t i = 0; i < playerCount; ++i) {
42 m_karts[i].init(i);
43 }
44}
45
47ItemDirector::~ItemDirector() {
48 if (s_instance) {
49 s_instance = nullptr;
50 WARN("ItemDirector instance not explicitly handled!");
51 }
52
53 delete[] m_karts.data();
54}
55
56ItemDirector *ItemDirector::s_instance = nullptr;
57
58} // namespace Item
State management for item usage.
Definition KartItem.hh:13
Pertains to item handling.