Refactor World::Courses to unique_ptr (#211)

* wip course unique ptr

* Track unique_ptr : This probably compiles

* Finish impl Courses as unique_ptr

* Fix error

* Fixes

* More fixes

* Cleanup

* Remove old vars

---------

Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com>
This commit is contained in:
MegaMech
2025-05-23 16:53:14 -06:00
committed by GitHub
parent 9363e3d776
commit 2a0c0939c7
34 changed files with 403 additions and 473 deletions
+7 -5
View File
@@ -29,8 +29,10 @@ World::~World() {
Course* CurrentCourse;
Cup* CurrentCup;
void World::AddCourse(Course* course) {
gWorldInstance.Courses.push_back(course);
Course* World::AddCourse(std::unique_ptr<Course> course) {
Course* ptr = course.get();
gWorldInstance.Courses.push_back(std::move(course));
return ptr;
}
void World::AddCup(Cup* cup) {
@@ -97,7 +99,7 @@ void World::SetCourse(const char* name) {
//! @todo Use content dictionary instead
for (size_t i = 0; i < Courses.size(); i++) {
if (strcmp(Courses[i]->Props.Name, name) == 0) {
CurrentCourse = Courses[i];
CurrentCourse = Courses[i].get();
break;
}
}
@@ -110,7 +112,7 @@ void World::NextCourse() {
} else {
CourseIndex = 0;
}
gWorldInstance.CurrentCourse = Courses[CourseIndex];
gWorldInstance.CurrentCourse = Courses[CourseIndex].get();
}
void World::PreviousCourse() {
@@ -119,7 +121,7 @@ void World::PreviousCourse() {
} else {
CourseIndex = Courses.size() - 1;
}
gWorldInstance.CurrentCourse = Courses[CourseIndex];
gWorldInstance.CurrentCourse = Courses[CourseIndex].get();
}
AActor* World::AddActor(AActor* actor) {
+12 -2
View File
@@ -54,7 +54,7 @@ public:
explicit World();
~World();
void AddCourse(Course* course);
Course* AddCourse(std::unique_ptr<Course> course);
AActor* AddActor(AActor* actor);
struct Actor* AddBaseActor();
@@ -96,6 +96,16 @@ public:
// These are only for browsing through the course list
void SetCourse(const char*);
template<typename T>
void SetCourseByType() {
for (const auto& course : Courses) {
if (dynamic_cast<T*>(course.get())) {
CurrentCourse = course.get();
return;
}
}
printf("World::SetCourseByType() No course by the type found");
}
void NextCourse(void);
void PreviousCourse(void);
@@ -122,7 +132,7 @@ public:
std::vector<std::shared_ptr<TrainCrossing>> Crossings;
// Holds all available courses
std::vector<Course*> Courses;
std::vector<std::unique_ptr<Course>> Courses;
size_t CourseIndex = 0; // For browsing courses.
private:
+4 -4
View File
@@ -118,7 +118,7 @@ void OBombKart::Tick() {
return;
}
if (((Unk_4A != 1) || (GetCourse() == GetPodiumCeremony()))) {
if (((Unk_4A != 1) || (IsPodiumCeremony()))) {
newPos[0] = Pos[0];
newPos[1] = Pos[1];
newPos[2] = Pos[2];
@@ -128,7 +128,7 @@ void OBombKart::Tick() {
bounceTimer = BounceTimer;
circleTimer = CircleTimer;
if ((state != States::DISABLED) && (state != States::EXPLODE)) {
if (GetCourse() == GetPodiumCeremony()) {
if (IsPodiumCeremony()) {
if (D_8016347E == 1) {
player = gPlayerFour;
temp_f0 = newPos[0] - player->pos[0];
@@ -152,7 +152,7 @@ void OBombKart::Tick() {
if ((((temp_f0 * temp_f0) + (temp_f2 * temp_f2)) + (temp_f12 * temp_f12)) < 25.0f) {
state = States::EXPLODE;
circleTimer = 0;
if (GetCourse() == GetFrappeSnowland()) {
if (IsFrappeSnowland()) {
player->soundEffects |= 0x01000000;
} else {
player->soundEffects |= 0x400000;
@@ -346,7 +346,7 @@ void OBombKart::Draw(s32 cameraId) {
return;
}
if (GetCourse() == GetPodiumCeremony()) {
if (IsPodiumCeremony()) {
if ((_idx == 0) && (WaypointIndex < 16)) {
return;
} else {
+3 -3
View File
@@ -139,7 +139,7 @@ void OGrandPrixBalloons::func_80074924(s32 objectIndex) {
object = &gObjectList[objectIndex];
object->sizeScaling = 0.15f;
if (GetCourse() == GetMarioRaceway()) {
if (IsMarioRaceway()) {
sp2C = random_int(0x00C8U);
sp28 = random_int(_numBalloons3);
sp24 = random_int(0x0096U);
@@ -147,7 +147,7 @@ void OGrandPrixBalloons::func_80074924(s32 objectIndex) {
object->origin_pos[0] = (f32) ((((f64) Pos.x + 100.0) - (f64) sp2C) * (f64) xOrientation);
object->origin_pos[1] = (f32) (Pos.y + sp28);
object->origin_pos[2] = (f32) (((f64) Pos.z + 200.0) - (f64) sp24);
} else if (GetCourse() == GetRoyalRaceway()) {
} else if (IsRoyalRaceway()) {
sp2C = random_int(0x0168U);
sp28 = random_int(_numBalloons3);
sp24 = random_int(0x00B4U);
@@ -155,7 +155,7 @@ void OGrandPrixBalloons::func_80074924(s32 objectIndex) {
object->origin_pos[0] = (f32) ((((f64) Pos.x + 180.0) - (f64) sp2C) * (f64) xOrientation);
object->origin_pos[1] = (f32) (Pos.y + sp28);
object->origin_pos[2] = (f32) (((f64) Pos.z + 200.0) - (f64) sp24);
} else if (GetCourse() == GetLuigiRaceway()) {
} else if (IsLuigiRaceway()) {
sp2C = random_int(0x012CU);
sp28 = random_int(_numBalloons3);
sp24 = random_int(0x0096U);
+1 -1
View File
@@ -21,7 +21,7 @@ OHotAirBalloon::OHotAirBalloon(const FVector& pos) {
D_80165898 = 0;
// Spawn balloon on second lap.
if (GetCourse() == GetLuigiRaceway()) {
if (IsLuigiRaceway()) {
_visible = (bool*)&D_80165898;
} else { // Spawn balloon on race start
bool mod = true;
+2 -2
View File
@@ -297,7 +297,7 @@ void OLakitu::func_800729EC(s32 objectIndex) {
D_8018D2BC = 1;
D_8018D2A4 = 1;
if (GetCourse() != GetYoshiValley()) {
if (!IsYoshiValley()) {
for (i = 0; i < gPlayerCount; i++) {
playerHUD[i].unk_81 = temp_v1;
}
@@ -366,7 +366,7 @@ void OLakitu::func_800797AC(s32 playerId) {
objectIndex = gIndexLakituList[playerId];
player = &gPlayerOne[playerId];
//if ((GetCourse() == GetSherbetLand()) && (player->unk_0CA & 1)) {
//if ((IsSherbetLand()) && (player->unk_0CA & 1)) {
if ((CM_GetProps()->LakituTowType == LakituTowType::ICE) && (player->unk_0CA & 1)) {
init_object(objectIndex, 7);
player->unk_0CA |= 0x10;
+1 -1
View File
@@ -32,7 +32,7 @@ OTrashBin::OTrashBin(const FVector& pos, const IRotator& rotation, f32 scale, OT
init_object(_objectIndex, 0);
if (GetCourse() != GetBansheeBoardwalk()) {
if (!IsBansheeBoardwalk()) {
_drawBin = true;
}
}