-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
denis
authored and
denis
committed
Nov 10, 2024
1 parent
c3e3e4c
commit 003f76e
Showing
15 changed files
with
216 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
#include <map> | ||
#include <memory> | ||
#include <functional> | ||
#include <string> | ||
#include "../../Engine/include/Components/Component.h" | ||
|
||
namespace Prisma | ||
{ | ||
class Factory | ||
{ | ||
public: | ||
using Creator = std::function<std::shared_ptr<Prisma::Component>()>; | ||
|
||
// Method to register a class type with a name | ||
static void registerClass(const std::string& className, Creator creator) | ||
{ | ||
getRegistry()[className] = creator; | ||
} | ||
|
||
// Method to create an instance of a class by name | ||
static std::shared_ptr<Prisma::Component> createInstance(const std::string& className) | ||
{ | ||
auto it = getRegistry().find(className); | ||
if (it != getRegistry().end()) | ||
{ | ||
return it->second(); | ||
} | ||
return nullptr; // Return null if class name not found | ||
} | ||
|
||
// Registry storing class name to creator function mappings | ||
static std::unordered_map<std::string, Creator>& getRegistry() | ||
{ | ||
static std::unordered_map<std::string, Creator> registry; | ||
return registry; | ||
} | ||
}; | ||
|
||
// Helper template to register classes | ||
template <typename T> | ||
class Registrar | ||
{ | ||
public: | ||
explicit Registrar(const std::string& className) | ||
{ | ||
Factory::registerClass(className, []() -> std::shared_ptr<Prisma::Component> | ||
{ | ||
return std::make_shared<T>(); | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
#include "RegisterComponent.h" | ||
#include "../../Engine/include/Components/PhysicsMeshComponent.h" | ||
#include "../../Engine/include/Components/CloudComponent.h" | ||
#include "../../Engine/include/Components/CullingComponent.h" | ||
|
||
namespace Prisma | ||
{ | ||
class RegisterData | ||
{ | ||
public: | ||
void init(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.