summaryrefslogtreecommitdiff
path: root/src/port
diff options
context:
space:
mode:
authorMegaMech <7255464+MegaMech@users.noreply.github.com>2025-05-23 15:46:40 -0600
committerMegaMech <7255464+MegaMech@users.noreply.github.com>2025-05-23 15:46:40 -0600
commitbf28a20d05d9eeca96b4ffa943a43f9f3e4ef2c1 (patch)
treef7f3e97e126a26100fb9ebad18f640ba71fdc3e3 /src/port
parentdb68d0b1c53bd9e627c0b343870bd0633bf782d4 (diff)
Finish impl Courses as unique_ptr
Diffstat (limited to 'src/port')
-rw-r--r--src/port/Game.cpp115
-rw-r--r--src/port/Game.h22
-rw-r--r--src/port/ui/ContentBrowser.cpp25
3 files changed, 89 insertions, 73 deletions
diff --git a/src/port/Game.cpp b/src/port/Game.cpp
index d4b2dae92..d72c5f120 100644
--- a/src/port/Game.cpp
+++ b/src/port/Game.cpp
@@ -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>());
-
- // 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 });
+ 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>());
+
+ 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) {
diff --git a/src/port/Game.h b/src/port/Game.h
index 46b52fe16..36b8ee0d4 100644
--- a/src/port/Game.h
+++ b/src/port/Game.h
@@ -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);
diff --git a/src/port/ui/ContentBrowser.cpp b/src/port/ui/ContentBrowser.cpp
index 826477ea5..5390d8a9d 100644
--- a/src/port/ui/ContentBrowser.cpp
+++ b/src/port/ui/ContentBrowser.cpp
@@ -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());
}