summaryrefslogtreecommitdiff
path: root/src/engine/World.cpp
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2024-11-14 23:32:55 -0700
committerGitHub <noreply@github.com>2024-11-14 23:32:55 -0700
commit475f167bb2803999c5116bc285601d1f9a05d7de (patch)
tree859fec292c5c9807cc9690ebf4f0600f558b6063 /src/engine/World.cpp
parent4fbb031dd95f2a84e73fbca269f517e98808d293 (diff)
[modding] Big Update PR (#118)
* Implement kart vehicle * Fix menu CC * Actors * variable framerate * Implement Actors vector * Fix water & scrolling textures * Finish ACoin * Refactor finishline * Refactor mtx to vector * Fix refactored screen code bugs * Fix playlist bug * Switching courses working now * Fix podium ceremony * Mostly Fix Demo and Credits * Credits Load Actors and Textures * Fix credits * Formatting * Update lus and torch * Fix water features * Fix crabs * Combine function * Fix wheels * Add Moon Jump Cheat * Wheel Change * Fix smoke due to wheel change * Fix screens for wheels * Fix transparency * Fix staff ghost * Fix lakitu transition widescreen * Rename and export credits text * Fixes --------- Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com>
Diffstat (limited to 'src/engine/World.cpp')
-rw-r--r--src/engine/World.cpp57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/engine/World.cpp b/src/engine/World.cpp
index 01c6f13bd..a5bbd6cdf 100644
--- a/src/engine/World.cpp
+++ b/src/engine/World.cpp
@@ -9,6 +9,7 @@
#include "vehicles/Bus.h"
#include "vehicles/TankerTruck.h"
#include "vehicles/Car.h"
+#include "vehicles/OBombKart.h"
#include "TrainCrossing.h"
#include <memory>
@@ -75,7 +76,7 @@ void World::AddCar(f32 speedA, f32 speedB, TrackWaypoint* path, uint32_t waypoin
cars++;
}
-void World::ResetVehicles(void) {
+void World::ClearVehicles(void) {
trains = trucks = busses = tankerTrucks = cars = boats = 0;
Vehicles.clear();
}
@@ -86,6 +87,10 @@ TrainCrossing* World::AddCrossing(Vec3f position, u32 waypointMin, u32 waypointM
return crossing.get();
}
+void World::AddBombKart(Vec3f pos, TrackWaypoint* waypoint, uint16_t waypointIndex, uint16_t state, f32 unk_3C) {
+ BombKarts.push_back(std::make_unique<OBombKart>(pos, waypoint, waypointIndex, state, unk_3C));
+}
+
u32 World::GetCupIndex() {
return this->CupIndex;
}
@@ -164,28 +169,52 @@ Object* World::AddObject(std::unique_ptr<GameObject> object) {
return &rawPtr->o;
}
-AActor* World::AddActor(std::unique_ptr<AActor> actor) {
- AActor* rawPtr = actor.get();
- Actors.push_back(std::move(actor));
- return rawPtr;
+AActor* World::AddActor(AActor* actor) {
+ Actors.push_back(actor);
+ return Actors.back();
}
-void World::TickActors() {
- for (auto& actor : Actors) {
- actor->Tick();
- }
+struct Actor* World::AddBaseActor() {
+ Actors.push_back(new AActor());
+ // Skip C++ vtable to access variables in C
+ return reinterpret_cast<struct Actor*>(reinterpret_cast<char*>(Actors.back()) + sizeof(void*));
+}
+
+/**
+ * Converts a C struct Actor* to its C++ AActor class
+ */
+AActor* World::ConvertActorToAActor(Actor* actor) {
+ // Move the ptr back so that it points at the vtable.
+ // Which is the initial item in the class, or in other words
+ // Point to the class.
+ return reinterpret_cast<AActor*>((char*)actor - sizeof(void*));
}
-void World::DrawActors(Camera* camera) {
- for (auto& actor : Actors) {
- actor->Draw(camera);
+/**
+ * Converts a C++ AActor class to a C Actor* struct.
+ */
+Actor* World::ConvertAActorToActor(AActor* actor) {
+ // Move the ptr forward past the vtable.
+ // This allows C to access the class variables like a normal Actor* struct.
+ return reinterpret_cast<Actor*>((char*)actor + sizeof(void*));
+}
+
+AActor* World::GetActor(size_t index) {
+ return Actors[index];
+}
+
+void World::TickActors() {
+ for (AActor* actor : Actors) {
+ if (actor->IsMod()) {
+ actor->Tick();
+ }
}
}
void RemoveExpiredActors() {
- //Actors.erase(
+ // Actors.erase(
// std::remove_if(Actors.begin(), Actors.end(),
- // [](const std::unique_ptr<AActor>& actor) { return actor->uuid == 0; }), // Example condition
+ // [](const std::unique_ptr<AActor>& actor) { return actor->uuid == 0; }),
// Actors.end());
}