summaryrefslogtreecommitdiff
path: root/src/engine/Registry.cpp
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2025-11-09 19:07:44 -0700
committerGitHub <noreply@github.com>2025-11-09 19:07:44 -0700
commitde9c5d510175bba11ab8704e67be3a3a94f9149e (patch)
tree34c42dbfe9f2a6eb5fbce5f6a31b532ff2a3f243 /src/engine/Registry.cpp
parent760fa3bf5226c2a6052a5d4d53fd0e27f2911e60 (diff)
Implement SpawnParams struct (#536)
* Impl SpawnParams * Added json submodule * Update json * Update * Works * Remove comment * Works refactor * Snowman and thwomp working * Impl hot air balloon * More progress * All OObjects are done * cleanup * Refactor 2Dpath to normal path * Update nlohmann json & fix compile * Rest of actors * MORE CHANGES * Finish actors * Done PR, some fix to collision viewer * Impl falling rocks * Add const * wip editor refactor * Property work * continue * Overridable editor properties * Actor saving/loading works now * Fix light alignment * Clarification * Impl penguin * params impl signs * properties impl falling rock * More property impls * impl air balloon * Add spawnParams to OObject Translate * Snowman translate better * impl hedgehog properly * properties impl trophy * thwomp progress * Finish impl properties * Fix compile * Fix cursor collisions * Move registered actors * Rename pathPoint XYZ to xyz * Fix editor pause bug * Clean up * Review comments * Remove SpawnParams struct from actor classes * Rename * Player Label First Iteration * Work now * Working 3d text * Fix boo bug * Finish AText actor * Fix spawnparams compile * Register AText * Finish Text Actor * Fix thwomp interpolation * Fix compile * Fix crab and hedgehog * Fix loading flagpole * Fix Hot Air Balloon * Turn zbuffer on for AText * Update --------- Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com>
Diffstat (limited to 'src/engine/Registry.cpp')
-rw-r--r--src/engine/Registry.cpp91
1 files changed, 32 insertions, 59 deletions
diff --git a/src/engine/Registry.cpp b/src/engine/Registry.cpp
index 0ea05c9d5..9a68264d8 100644
--- a/src/engine/Registry.cpp
+++ b/src/engine/Registry.cpp
@@ -1,59 +1,32 @@
-// #include <vector>
-// #include <functional>
-// #include <iostream>
-// #include <map>
-
-// #include "Registry.h"
-// #include "Course.h"
-// #include "port/Game.h"
-
-// template <class T> Registry<T>::Registry() {
-// }
-
-// template <class T> void Registry<T>::Add(std::string id, std::function<T*()> fn) {
-// // need to handle duplicate registration
-// ContentVault[id] = fn;
-// }
-
-// template <class T>
-// void Registry<T>::AddArgs(std::string id) {
-// ArgsVault[id] = [](Args&&... args) -> T* {
-// return new T(std::forward<Args>(args)...);
-// };
-// }
-
-// template <class T>
-// T* Registry<T>::Get(std::string id) {
-// auto it = ContentVault.find(id);
-// if (it != ContentVault.end()) {
-// return it->second();
-// }
-// return nullptr;
-// }
-
-// // Available Registries
-// Registry<Course> Courses;
-// Registry<Cup> Cups;
-// Registry<AActor> Actors;
-
-// void AddCourse(std::string id, Course* course) {
-// Courses.Add(id, [course]() { return course; });
-// course->Id = id;
-// }
-
-// void AddCup(std::string id, Cup* cup) {
-// Cups.Add(id, [cup]() { return cup; });
-// //cup->Id = id;
-// }
-
-// void AddActor(std::string id, AActor* actor) {
-// Actors.Add(id, [actor]() { return actor; });
-// }
-
-// void AddStockContent() {
-// AddActor("mk:banana", new AMarioSign({0, 0, 0}));
-// }
-
-// template class Registry<Course>;
-// template class Registry<Cup>;
-// template class Registry<AActor>;
+#include <functional>
+#include <unordered_map>
+#include <string>
+
+#include "Registry.h"
+#include "engine/CoreMath.h"
+
+extern "C" {
+#include "actors.h"
+#include "actor_types.h"
+}
+
+std::unordered_map<std::string, ActorRegistryEntry> gActorRegistry;
+
+void RegisterActor(const std::string& name,
+ std::function<void(const SpawnParams&)> spawnFunc)
+{
+ gActorRegistry[name] = { spawnFunc };
+}
+
+void Registry_SpawnActor(SpawnParams& params) {
+ auto it = gActorRegistry.find(params.Name);
+ if (it != gActorRegistry.end() && it->second.spawnFunc) {
+ printf("[Registry] Spawned %s\n", params.Name.c_str());
+ it->second.spawnFunc(params);
+ }
+}
+
+// @arg name Must be a resource name such as mk:car
+bool Registry_Find(const std::string& name) {
+ return gActorRegistry.find(name) != gActorRegistry.end();
+}