Finish impl Courses as unique_ptr

This commit is contained in:
MegaMech
2025-05-23 15:46:40 -06:00
parent db68d0b1c5
commit bf28a20d05
7 changed files with 107 additions and 92 deletions
+4 -4
View File
@@ -1644,7 +1644,7 @@ void update_object(void) {
// func_80074EE8(); // Grand prix balloons
//}
func_80076F2C();
if ((s16) GetCourse() != GetFrappeSnowland()) {
if (!IsFrappeSnowland()) {
update_leaf();
}
}
@@ -3638,7 +3638,7 @@ void func_800608E0(Player* player, s16 arg1, UNUSED s32 arg2, s8 arg3, UNUSED s8
var_f0 = 0.0f;
}
sp4C = (D_801652A0[arg3] - player->pos[1]) - 3.0f;
if ((player->unk_0DE & 1) && (IsKoopaTroopaBeach())) {
if ((player->unk_0DE & 1) && (!IsKoopaTroopaBeach())) {
var_f0 = 2.5f;
sp4C = (f32) ((f64) (D_801652A0[arg3] - player->pos[1]) + 0.1);
}
@@ -3658,7 +3658,7 @@ void func_800608E0(Player* player, s16 arg1, UNUSED s32 arg2, s8 arg3, UNUSED s8
}
void func_80060B14(Player* player, s16 arg1, s32 arg2, s8 arg3, s8 arg4) {
if ((GetCourse() != GetSkyscraper()) && (!IsRainbowRoad())) {
if ((!IsSkyscraper()) && (!IsRainbowRoad())) {
if ((arg1 == 0) && ((player->unk_258[arg2].unk_01E > 0) || (player->unk_258[arg2].unk_01C == 0))) {
func_800608E0(player, arg1, arg2, arg3, arg4);
} else if (player->unk_258[arg2].unk_01E > 0) {
@@ -4628,7 +4628,7 @@ void func_80064184(Player* player, s16 arg1, s8 arg2, UNUSED s8 arg3) {
f32 sp3C;
sp40 = D_801652A0[arg2] - player->pos[1] - 3.0f;
if (((player->unk_0DE & 1) != 0) && (IsKoopaTroopaBeach())) {
if (((player->unk_0DE & 1) != 0) && (!IsKoopaTroopaBeach())) {
sp40 = D_801652A0[arg2] - player->pos[1] + 0.1;
}
+4 -13
View File
@@ -26,8 +26,10 @@ World::World() {}
Course* CurrentCourse;
Cup* CurrentCup;
void World::AddCourse(std::unique_ptr<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,17 +99,6 @@ void World::SetCourse(const char* name) {
std::runtime_error("SetCourse() Course name not found in Courses list");
}
template<typename T>
void World::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 World::NextCourse() {
if (CourseIndex < Courses.size() - 1) {
CourseIndex++;
+10 -2
View File
@@ -53,7 +53,7 @@ class World {
public:
explicit World();
void AddCourse(std::unique_ptr<Course> course);
Course* AddCourse(std::unique_ptr<Course> course);
AActor* AddActor(AActor* actor);
struct Actor* AddBaseActor();
@@ -95,7 +95,15 @@ public:
// These are only for browsing through the course list
void SetCourse(const char*);
template<typename T>
void SetCourseByType();
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);
+1 -1
View File
@@ -1778,7 +1778,7 @@ void func_8002C4F8(Player* player, s8 arg1) {
if ((player->unk_0DE & 4) != 4) {
player->unk_0DE |= 8;
player->unk_0DE |= 4;
if ((IsKoopaTroopaBeach()) && (GetCourse() != GetSkyscraper()) &&
if ((!IsKoopaTroopaBeach()) && (!IsSkyscraper()) &&
(!IsRainbowRoad()) && ((player->type & PLAYER_HUMAN) == PLAYER_HUMAN)) {
if ((IsBowsersCastle()) || (IsBigDonut())) {
func_800C9060((u8) arg1, 0x1900801CU);
+51 -62
View File
@@ -69,29 +69,7 @@ extern "C" void Timer_Update();
// Create the world instance
World gWorldInstance;
// auto gMarioRaceway;
// ChocoMountain* gChocoMountain;
// BowsersCastle* gBowsersCastle;
// BansheeBoardwalk* gBansheeBoardwalk;
// YoshiValley* gYoshiValley;
// FrappeSnowland* gFrappeSnowland;
// KoopaTroopaBeach* gKoopaTroopaBeach;
// RoyalRaceway* gRoyalRaceway;
// LuigiRaceway* gLuigiRaceway;
// MooMooFarm* gMooMooFarm;
// ToadsTurnpike* gToadsTurnpike;
// KalimariDesert* gKalimariDesert;
// SherbetLand* gSherbetLand;
// RainbowRoad* gRainbowRoad;
// WarioStadium* gWarioStadium;
// BlockFort* gBlockFort;
// Skyscraper* gSkyscraper;
// DoubleDeck* gDoubleDeck;
// DKJungle* gDkJungle;
// BigDonut* gBigDonut;
// PodiumCeremony* gPodiumCeremony;
// Harbour* gHarbour;
// TestCourse* gTestCourse;
std::unique_ptr<PodiumCeremony> gPodiumCeremony;
Cup* gMushroomCup;
Cup* gFlowerCup;
@@ -134,47 +112,58 @@ void CustomEngineInit() {
// gTestCourse = new TestCourse();
/* Add all courses to the global course list */
gWorldInstance.AddCourse(std::make_unique<MarioRaceway>());
gWorldInstance.AddCourse(std::make_unique<ChocoMountain>());
gWorldInstance.AddCourse(std::make_unique<BowsersCastle>());
gWorldInstance.AddCourse(std::make_unique<BansheeBoardwalk>());
gWorldInstance.AddCourse(std::make_unique<YoshiValley>());
gWorldInstance.AddCourse(std::make_unique<FrappeSnowland>());
gWorldInstance.AddCourse(std::make_unique<KoopaTroopaBeach>());
gWorldInstance.AddCourse(std::make_unique<RoyalRaceway>());
gWorldInstance.AddCourse(std::make_unique<LuigiRaceway>());
gWorldInstance.AddCourse(std::make_unique<MooMooFarm>());
gWorldInstance.AddCourse(std::make_unique<ToadsTurnpike>());
gWorldInstance.AddCourse(std::make_unique<KalimariDesert>());
gWorldInstance.AddCourse(std::make_unique<SherbetLand>());
gWorldInstance.AddCourse(std::make_unique<RainbowRoad>());
gWorldInstance.AddCourse(std::make_unique<WarioStadium>());
gWorldInstance.AddCourse(std::make_unique<BlockFort>());
gWorldInstance.AddCourse(std::make_unique<Skyscraper>());
gWorldInstance.AddCourse(std::make_unique<DoubleDeck>());
gWorldInstance.AddCourse(std::make_unique<DKJungle>());
gWorldInstance.AddCourse(std::make_unique<BigDonut>());
gWorldInstance.AddCourse(std::make_unique<PodiumCeremony>());
gWorldInstance.AddCourse(std::make_unique<Harbour>());
gWorldInstance.AddCourse(std::make_unique<TestCourse>());
Course* mario = gWorldInstance.AddCourse(std::make_unique<MarioRaceway>());
Course* choco = gWorldInstance.AddCourse(std::make_unique<ChocoMountain>());
Course* bowser = gWorldInstance.AddCourse(std::make_unique<BowsersCastle>());
Course* banshee = gWorldInstance.AddCourse(std::make_unique<BansheeBoardwalk>());
Course* yoshi = gWorldInstance.AddCourse(std::make_unique<YoshiValley>());
Course* frappe = gWorldInstance.AddCourse(std::make_unique<FrappeSnowland>());
Course* koopa = gWorldInstance.AddCourse(std::make_unique<KoopaTroopaBeach>());
Course* royal = gWorldInstance.AddCourse(std::make_unique<RoyalRaceway>());
Course* luigi = gWorldInstance.AddCourse(std::make_unique<LuigiRaceway>());
Course* mooMoo = gWorldInstance.AddCourse(std::make_unique<MooMooFarm>());
Course* toads = gWorldInstance.AddCourse(std::make_unique<ToadsTurnpike>());
Course* kalimari = gWorldInstance.AddCourse(std::make_unique<KalimariDesert>());
Course* sherbet = gWorldInstance.AddCourse(std::make_unique<SherbetLand>());
Course* rainbow = gWorldInstance.AddCourse(std::make_unique<RainbowRoad>());
Course* wario = gWorldInstance.AddCourse(std::make_unique<WarioStadium>());
Course* block = gWorldInstance.AddCourse(std::make_unique<BlockFort>());
Course* skyscraper = gWorldInstance.AddCourse(std::make_unique<Skyscraper>());
Course* doubleDeck = gWorldInstance.AddCourse(std::make_unique<DoubleDeck>());
Course* dkJungle = gWorldInstance.AddCourse(std::make_unique<DKJungle>());
Course* bigDonut = gWorldInstance.AddCourse(std::make_unique<BigDonut>());
Course* harbour = gWorldInstance.AddCourse(std::make_unique<Harbour>());
Course* testCourse = gWorldInstance.AddCourse(std::make_unique<TestCourse>());
// gMushroomCup = new Cup("mk:mushroom_cup", "mushroom cup",
// std::vector<Course*>{ gLuigiRaceway, gMooMooFarm, gKoopaTroopaBeach, gKalimariDesert });
// gFlowerCup = new Cup("mk:flower_cup", "flower cup",
// std::vector<Course*>{ gToadsTurnpike, gFrappeSnowland, gChocoMountain, gMarioRaceway });
// gStarCup = new Cup("mk:star_cup", "star cup",
// std::vector<Course*>{ gWarioStadium, gSherbetLand, gRoyalRaceway, gBowsersCastle });
// gSpecialCup = new Cup("mk:special_cup", "special cup",
// std::vector<Course*>{ gDkJungle, gYoshiValley, gBansheeBoardwalk, gRainbowRoad });
// gBattleCup =
// new Cup("mk:battle_cup", "battle", std::vector<Course*>{ gBigDonut, gBlockFort, gDoubleDeck, gSkyscraper });
gPodiumCeremony = std::make_unique<PodiumCeremony>();
// Construct cups with vectors of Course* (non-owning references)
gMushroomCup = new Cup("mk:mushroom_cup", "Mushroom Cup", {
luigi, mooMoo, koopa, kalimari
});
gFlowerCup = new Cup("mk:flower_cup", "Flower Cup", {
toads, frappe, choco, mario
});
gStarCup = new Cup("mk:star_cup", "Star Cup", {
wario, sherbet, royal, bowser
});
gSpecialCup = new Cup("mk:special_cup", "Special Cup", {
dkJungle, yoshi, banshee, rainbow
});
gBattleCup = new Cup("mk:battle_cup", "Battle Cup", {
bigDonut, block, doubleDeck, skyscraper
});
/* Instantiate Cups */
// gWorldInstance.AddCup(gMushroomCup);
// gWorldInstance.AddCup(gFlowerCup);
// gWorldInstance.AddCup(gStarCup);
// gWorldInstance.AddCup(gSpecialCup);
// gWorldInstance.AddCup(gBattleCup);
gWorldInstance.AddCup(gMushroomCup);
gWorldInstance.AddCup(gFlowerCup);
gWorldInstance.AddCup(gStarCup);
gWorldInstance.AddCup(gSpecialCup);
gWorldInstance.AddCup(gBattleCup);
/* Set default course; mario raceway */
SelectMarioRaceway();
@@ -767,7 +756,7 @@ void SelectSkyscraper() { gWorldInstance.SetCourseByType<Skyscraper>();
void SelectDoubleDeck() { gWorldInstance.SetCourseByType<DoubleDeck>(); }
void SelectDkJungle() { gWorldInstance.SetCourseByType<DKJungle>(); }
void SelectBigDonut() { gWorldInstance.SetCourseByType<BigDonut>(); }
void SelectPodiumCeremony() { gWorldInstance.SetCourseByType<PodiumCeremony>(); }
void SelectPodiumCeremony() { gWorldInstance.CurrentCourse = gPodiumCeremony.get(); }
// clang-format on
void* GetMushroomCup(void) {
+22
View File
@@ -177,6 +177,28 @@ bool IsDkJungle();
bool IsBigDonut();
bool IsPodiumCeremony();
void SelectMarioRaceway();
void SelectLuigiRaceway();
void SelectChocoMountain();
void SelectBowsersCastle();
void SelectBansheeBoardwalk();
void SelectYoshiValley();
void SelectFrappeSnowland();
void SelectKoopaTroopaBeach();
void SelectRoyalRaceway();
void SelectMooMooFarm();
void SelectToadsTurnpike();
void SelectKalimariDesert();
void SelectSherbetLand();
void SelectRainbowRoad();
void SelectWarioStadium();
void SelectBlockFort();
void SelectSkyscraper();
void SelectDoubleDeck();
void SelectDkJungle();
void SelectBigDonut();
void SelectPodiumCeremony();
void* GetMushroomCup(void);
void* GetFlowerCup(void);
+15 -10
View File
@@ -147,12 +147,13 @@ namespace Editor {
}
}
// When resetting the known content, we need to also pop the custom courses
// out of World::Courses vector. Otherwise, duplicate courses would show up for users.
void ContentBrowserWindow::RemoveCustomTracksFromTrackList() {
for (auto& track : Tracks) {
auto it = gWorldInstance.Courses.begin();
while (it != gWorldInstance.Courses.end()) {
if (track.course == *it) {
delete *it;
if (track.course == it->get()) {
it = gWorldInstance.Courses.erase(it);
} else {
++it;
@@ -233,27 +234,31 @@ namespace Editor {
std::string name = dir.substr(dir.find_last_of('/') + 1);
std::string sceneFile = dir + "/scene.json";
std::string minimapFile = dir + "/minimap.png";
// The track has a valid scene file
if (manager->HasFile(sceneFile)) {
auto archive = manager->GetArchiveFromFile(sceneFile);
Course* course = new Course();
auto course = std::make_unique<Course>();
course->LoadO2R(dir);
gWorldInstance.Courses.push_back(course);
LoadLevel(archive, course, sceneFile);
LoadMinimap(archive, course, minimapFile);
Tracks.push_back({course, sceneFile, name, dir, archive});
} else {
gWorldInstance.Courses.push_back(std::move(course));
LoadLevel(archive, course.get(), sceneFile);
LoadMinimap(archive, course.get(), minimapFile);
Tracks.push_back({course.get(), sceneFile, name, dir, archive});
} else { // The track does not have a valid scene file
const std::string file = dir + "/data_track_sections";
// If the track has a data_track_sections file,
// then it must at least be a valid track.
// So lets add it as an uninitialized track.
if (manager->HasFile(file)) {
Course* course = new Course();
auto course = std::make_unique<Course>();
course->Id = (std::string("mods:") + name).c_str();
course->Props.SetText(course->Props.Name, name.c_str(), sizeof(course->Props.Name));
course->Props.SetText(course->Props.DebugName, name.c_str(), sizeof(course->Props.Name));
auto archive = manager->GetArchiveFromFile(file);
Tracks.push_back({course, "", name, dir, archive});
Tracks.push_back({course.get(), "", name, dir, archive});
} else {
printf("ContentBrowser.cpp: Track '%s' missing required track files. Cannot add to game\n Missing %s/data_track_sections file\n", name.c_str(), dir.c_str());
}