A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
ObjectDirector.hh
1#pragma once
2
3#include "game/field/ObjectCollisionConvexHull.hh"
4#include "game/field/ObjectFlowTable.hh"
5#include "game/field/ObjectHitTable.hh"
6#include "game/field/obj/ObjectCollidable.hh"
7#include "game/field/obj/ObjectNoImpl.hh"
8
9#include <vector>
10
11namespace Host {
12
13class Context;
14
15} // namespace Host
16
17namespace Field {
18
20 friend class Host::Context;
21
22public:
23 void init();
24 void calc();
25 void addObject(ObjectCollidable *obj);
26 void addObjectNoImpl(ObjectNoImpl *obj);
27 void addManagedObject(ObjectCollidable *obj);
28
29 size_t checkKartObjectCollision(Kart::KartObject *kartObj,
30 ObjectCollisionConvexHull *convexHull);
31
32 [[nodiscard]] const ObjectFlowTable &flowTable() const {
33 return m_flowTable;
34 }
35
36 [[nodiscard]] const ObjectHitTable &hitTableKart() const {
37 return m_hitTableKart;
38 }
39
40 [[nodiscard]] const ObjectCollidable *collidingObject(size_t idx) const {
41 ASSERT(idx < m_collidingObjects.size());
42 return m_collidingObjects[idx];
43 }
44
45 [[nodiscard]] Kart::Reaction reaction(size_t idx) const {
46 ASSERT(idx < m_reactions.size());
47 return m_reactions[idx];
48 }
49
50 [[nodiscard]] const EGG::Vector3f &hitDepth(size_t idx) const {
51 ASSERT(idx < m_hitDepths.size());
52 return m_hitDepths[idx];
53 }
54
55 [[nodiscard]] std::vector<ObjectCollidable *> managedObjects() {
56 return m_managedObjects;
57 }
58
59 [[nodiscard]] const std::vector<ObjectCollidable *> &managedObjects() const {
60 return m_managedObjects;
61 }
62
63 static ObjectDirector *CreateInstance();
64 static void DestroyInstance();
65
66 [[nodiscard]] static ObjectDirector *Instance() {
67 return s_instance;
68 }
69
70private:
72 ~ObjectDirector() override;
73
74 void createObjects();
75 [[nodiscard]] ObjectBase *createObject(const System::MapdataGeoObj &params);
76
77 ObjectFlowTable m_flowTable;
78 ObjectHitTable m_hitTableKart;
79 ObjectHitTable m_hitTableKartObject;
80
81 std::vector<ObjectBase *> m_objects;
82 std::vector<ObjectBase *> m_calcObjects;
83 std::vector<ObjectBase *> m_collisionObjects;
84
85 static constexpr size_t MAX_UNIT_COUNT = 0x100;
86
87 std::array<ObjectCollidable *, MAX_UNIT_COUNT>
89 std::array<EGG::Vector3f, MAX_UNIT_COUNT> m_hitDepths;
90 std::array<Kart::Reaction, MAX_UNIT_COUNT> m_reactions;
91 std::vector<ObjectCollidable *> m_managedObjects;
92
93 static ObjectDirector *s_instance;
94};
95
96} // namespace Field
An interface for ensuring certain structures and classes are destroyed with the heap.
Definition Disposer.hh:11
Smallest convex shape that encloses a given set of points.
std::vector< ObjectBase * > m_objects
All objects live here.
std::vector< ObjectBase * > m_collisionObjects
Objects having collision live here too.
std::array< ObjectCollidable *, MAX_UNIT_COUNT > m_collidingObjects
Objects we are currently colliding with.
std::vector< ObjectBase * > m_calcObjects
Objects needing calc() live here too.
Contexts can be used to restore a previous memory state for the current session.
Definition Context.hh:59
The highest level abstraction for a kart.
Definition KartObject.hh:11
Pertains to collision.
Represents the host application.
Definition HeapCommon.hh:9
A 3D float vector.
Definition Vector.hh:87