-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
206 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# Set the minimum required CMake version | ||
cmake_minimum_required(VERSION 3.12) | ||
|
||
project(components_lib) | ||
|
||
file(GLOB_RECURSE COMPONENTS_SRC_FILES "*.cpp" "*.h") | ||
file(GLOB_RECURSE COMPONENTS_CPP_FILES "*.cpp") | ||
file(GLOB_RECURSE COMPONENTS_H_FILES "*.h") | ||
|
||
add_library(${PROJECT_NAME} ${COMPONENTS_SRC_FILES}) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE GOOP_RENDERER_VULKAN) | ||
if (COMPONENTS_CPP_FILES) | ||
add_library(${PROJECT_NAME} ${COMPONENTS_CPP_FILES} ${COMPONENTS_H_FILES}) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE GOOP_RENDERER_VULKAN) | ||
else() | ||
add_library(${PROJECT_NAME} INTERFACE) | ||
target_sources(${PROJECT_NAME} INTERFACE ${COMPONENTS_H_FILES}) | ||
endif() | ||
|
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
#include "TestCustomComp.h" | ||
#include <goop/Components.h> | ||
#include <map> | ||
|
||
static std::map<std::string, std::function<goop::CustomComponent*(entt::entity, goop::Scene*)>> | ||
customComponentMap; | ||
static std::map<std::string, std::function<goop::CustomComponent*(entt::entity, goop::Scene*)>> customComponentMap; | ||
|
||
#define REGISTER_CUSTOM_COMPONENT(name, type) \ | ||
static goop::CustomComponent* create##type(entt::entity e, goop::Scene* s) \ | ||
{ \ | ||
return new type(goop::Entity(e, s)); \ | ||
} \ | ||
static bool registered##type = []() \ | ||
{ \ | ||
customComponentMap[name] = create##type; \ | ||
return true; \ | ||
}() | ||
#define REGISTER_CUSTOM_COMPONENT(name, type) \ | ||
static goop::CustomComponent* create##type(entt::entity e, goop::Scene* s) \ | ||
{ \ | ||
return new type(goop::Entity(e, s)); \ | ||
} \ | ||
static bool registered##type = []() \ | ||
{ \ | ||
customComponentMap[name] = create##type; \ | ||
return true; \ | ||
}() | ||
|
||
REGISTER_CUSTOM_COMPONENT("TestCustomComp", TestCustomComp); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
#!/bin/bash | ||
|
||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 ClassName" | ||
exit 1 | ||
fi | ||
|
||
CLASS_NAME="$1" | ||
HEADER_FILE="${CLASS_NAME}.h" | ||
CPP_FILE="${CLASS_NAME}.cpp" | ||
|
||
echo "Creating C++ class: ${CLASS_NAME}..." | ||
|
||
# Generate header file | ||
cat <<EOF >"${HEADER_FILE}" | ||
#pragma once | ||
#include <goop/Components.h> | ||
class ${CLASS_NAME} : public goop::CustomComponent | ||
{ | ||
public: | ||
${CLASS_NAME}(goop::Entity e) : goop::CustomComponent(e) {} | ||
void init() final; | ||
void update(float dt) final; | ||
private: | ||
}; | ||
EOF | ||
|
||
echo "Created ${HEADER_FILE}" | ||
|
||
# Generate cpp file | ||
cat <<EOF >"${CPP_FILE}" | ||
#include "${HEADER_FILE}" | ||
void ${CLASS_NAME}::init() | ||
{ | ||
// Implement initialization | ||
} | ||
void ${CLASS_NAME}::update(float dt) | ||
{ | ||
// Implement update | ||
} | ||
EOF | ||
|
||
echo "Created ${CPP_FILE}" | ||
echo "C++ class '${CLASS_NAME}' created successfully!" | ||
|
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,68 @@ | ||
#!/bin/bash | ||
|
||
# Get the directory of the script | ||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
||
# Move to the script's directory | ||
cd "$script_dir" || exit | ||
|
||
# Find .cpp files | ||
shopt -s nullglob | ||
cpp_files=("$script_dir"/*.cpp) | ||
shopt -u nullglob | ||
|
||
# Start by creating or clearing CustomComponents.h | ||
echo -n >CustomComponents.h | ||
|
||
# Check if there are no .cpp files | ||
if [ ${#cpp_files[@]} -eq 0 ]; then | ||
echo "No .cpp files found in the directory." | ||
echo "#include <goop/Components.h>" >>CustomComponents.h | ||
echo "#include <map>" >>CustomComponents.h | ||
echo >>CustomComponents.h | ||
echo "static std::map<std::string, std::function<goop::CustomComponent*(entt::entity, goop::Scene*)>> customComponentMap;" >>CustomComponents.h | ||
echo >>CustomComponents.h | ||
echo "#define REGISTER_CUSTOM_COMPONENT(name, type) \\" >>CustomComponents.h | ||
echo " static goop::CustomComponent* create##type(entt::entity e, goop::Scene* s) \\" >>CustomComponents.h | ||
echo " { \\" >>CustomComponents.h | ||
echo " return new type(goop::Entity(e, s)); \\" >>CustomComponents.h | ||
echo " } \\" >>CustomComponents.h | ||
echo " static bool registered##type = []() \\" >>CustomComponents.h | ||
echo " { \\" >>CustomComponents.h | ||
echo " customComponentMap[name] = create##type; \\" >>CustomComponents.h | ||
echo " return true; \\" >>CustomComponents.h | ||
echo " }()" >>CustomComponents.h | ||
echo >>CustomComponents.h | ||
exit 0 | ||
fi | ||
|
||
|
||
# Add #includes | ||
for file in "${cpp_files[@]}"; do | ||
filename=$(basename "$file" .cpp) | ||
echo "#include \"$filename.h\"" >>CustomComponents.h | ||
done | ||
|
||
echo "#include <goop/Components.h>" >>CustomComponents.h | ||
echo "#include <map>" >>CustomComponents.h | ||
echo >>CustomComponents.h | ||
echo "static std::map<std::string, std::function<goop::CustomComponent*(entt::entity, goop::Scene*)>> customComponentMap;" >>CustomComponents.h | ||
echo >>CustomComponents.h | ||
echo "#define REGISTER_CUSTOM_COMPONENT(name, type) \\" >>CustomComponents.h | ||
echo " static goop::CustomComponent* create##type(entt::entity e, goop::Scene* s) \\" >>CustomComponents.h | ||
echo " { \\" >>CustomComponents.h | ||
echo " return new type(goop::Entity(e, s)); \\" >>CustomComponents.h | ||
echo " } \\" >>CustomComponents.h | ||
echo " static bool registered##type = []() \\" >>CustomComponents.h | ||
echo " { \\" >>CustomComponents.h | ||
echo " customComponentMap[name] = create##type; \\" >>CustomComponents.h | ||
echo " return true; \\" >>CustomComponents.h | ||
echo " }()" >>CustomComponents.h | ||
echo >>CustomComponents.h | ||
|
||
# Register components | ||
for file in "${cpp_files[@]}"; do | ||
filename=$(basename "$file" .cpp) | ||
echo "REGISTER_CUSTOM_COMPONENT(\"$filename\", $filename);" >>CustomComponents.h | ||
done | ||
|
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