From a79bc72b05c538759debc7af00b5dc164b969714 Mon Sep 17 00:00:00 2001 From: Austin Date: Tue, 3 Dec 2019 20:53:07 -0800 Subject: [PATCH 1/3] Change block registry to singleton --- Phoenix/.DS_Store | Bin 0 -> 6148 bytes Phoenix/Client/Source/main.cpp | 8 ++++---- Phoenix/Core/Include/Core/Voxels/Blocks.hpp | 9 +++++++-- Phoenix/Core/Source/Voxels/Blocks.cpp | 12 ++++++++---- Phoenix/Server/Source/main.cpp | 10 ++++++---- 5 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 Phoenix/.DS_Store diff --git a/Phoenix/.DS_Store b/Phoenix/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..83f7374adc89c41d5f9f7097c6e74b8a5558e6f1 GIT binary patch literal 6148 zcmeHKQH#?+5T3n@bz4#UAe{J=7r}>98m!)f2%&dA94H78eNeeeZ193HdnD;qt(Cm^ zEA$WeTl@k39Q|f@m8MnUUPQ_c%zTsGnN9Z#JJTg1F`A46qCOExD5KYd`Hk>A>xyjH z5uOx!je_d^T)jwgm8?X&0mp!2;D2L)&u)iyDW{B5YM);&3U{E_zH8Axy%n2Gt7CiC zzb40dR@H;SH?gtlo#~vFvL}1zd(WdIHI3@Ho>Zf_e9BJ`NqRXQYUBQ6d})^WW`ubM`}`xE4@x+CZz1j?m_>`Y<4{ehPSr;;V_tQ`?H;$ z0sNb{=ku=Ix*FWwKYac6-R%AR!zaBF5-3?(E?WEvpW(E&c@mXHu8Nl!=bQ_m>jA~| z3WVJUZ57qf8?bL$<&Ww60$rrfL$0Ed(uFdKII*=9*P#fjmvq8*DfZ*vV%PbTEKsua zNx+DcQ!`)>fIN5VOqbvoa15+F16&_`C}U``F{n!ijJ^T@Jq&As&wY<`e2byQ#vo=O z!lVLCs<2lKVbU?~+qlqTW6-3Nu$K>E-z@A6Md-IgetInstance(); + registry->registerBlock("core:dirt", "Dirt"); + registry->registerBlock("core:cobble", "CobbleStone"); + registry->registerBlock("core:stone", "Stone"); // TODO: Replace these manual calls to register blocks with a call to run lua files based on what modules need loaded // ===== Launch renderer outputting to main window ===== diff --git a/Phoenix/Core/Include/Core/Voxels/Blocks.hpp b/Phoenix/Core/Include/Core/Voxels/Blocks.hpp index 45ee42b3..0bbb46db 100644 --- a/Phoenix/Core/Include/Core/Voxels/Blocks.hpp +++ b/Phoenix/Core/Include/Core/Voxels/Blocks.hpp @@ -57,17 +57,22 @@ namespace phoenix class BlockRegistry { private: + static BlockRegistry *instance; std::vector Blocks; int i; - public: BlockRegistry(); - ~BlockRegistry(); + + public: + + static BlockRegistry *getInstance(); /// @brief Registers a block in the registry int registerBlock(const std::string& uniqueName, const std::string& displayName); + /// @brief Get the Display name for a block in the registry const std::string& getDisplayName(int blockId); + /// @brief Get the ID for a block in the registry int getBlockId(const std::string& uniqueName); }; diff --git a/Phoenix/Core/Source/Voxels/Blocks.cpp b/Phoenix/Core/Source/Voxels/Blocks.cpp index 2de222cf..0ffc5200 100644 --- a/Phoenix/Core/Source/Voxels/Blocks.cpp +++ b/Phoenix/Core/Source/Voxels/Blocks.cpp @@ -27,8 +27,7 @@ // POSSIBILITY OF SUCH DAMAGE. #include - -#include +#include using namespace phoenix::voxels; @@ -38,9 +37,14 @@ RegisteredBlock::RegisteredBlock(const std::string& unique, int id, RegisteredBlock::~RegisteredBlock() = default; -BlockRegistry::BlockRegistry() : i(0) {}; +BlockRegistry::BlockRegistry(){ i = 0;}; + +BlockRegistry *BlockRegistry::instance = 0; -BlockRegistry::~BlockRegistry() {}; +BlockRegistry *BlockRegistry::getInstance(){ + if (!instance){instance = new BlockRegistry;} + return instance; +}; int BlockRegistry::registerBlock(const std::string& uniqueName, const std::string& displayName) diff --git a/Phoenix/Server/Source/main.cpp b/Phoenix/Server/Source/main.cpp index c1a1a28d..daa520d7 100644 --- a/Phoenix/Server/Source/main.cpp +++ b/Phoenix/Server/Source/main.cpp @@ -14,10 +14,12 @@ int main(int argc, char* argv[]) // Likely a single command from Quartz that launches the logger + any other critical tools // ===== Load Voxel data / Load lua ===== - voxels::BlockRegistry registry = voxels::BlockRegistry(); - registry.registerBlock("core:dirt", "Dirt"); - registry.registerBlock("core:cobble", "CobbleStone"); - registry.registerBlock("core:stone", "Stone"); + std::cout << "Program started"; + voxels::BlockRegistry *registry = registry->getInstance(); + std::cout << "register dirt"; + registry->registerBlock("core:dirt", "Dirt"); + registry->registerBlock("core:cobble", "CobbleStone"); + registry->registerBlock("core:stone", "Stone"); // TODO: Replace these manual calls to register blocks with a call to run lua files // ===== Load save data ===== From 5df0250ce5f4432deb702aba871375e281c9d89a Mon Sep 17 00:00:00 2001 From: Austin Date: Sat, 7 Dec 2019 18:05:25 -0800 Subject: [PATCH 2/3] Implemented singleton so registry can be grabbed anywhere, Blacklegi is a god --- Phoenix/CMakeLists.txt | 1 - Phoenix/Core/Include/Core/Voxels/Blocks.hpp | 2 +- Phoenix/Core/Source/Voxels/Blocks.cpp | 8 ++++++-- Phoenix/Server/Source/main.cpp | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Phoenix/CMakeLists.txt b/Phoenix/CMakeLists.txt index 73167db6..9cd731c8 100644 --- a/Phoenix/CMakeLists.txt +++ b/Phoenix/CMakeLists.txt @@ -1,5 +1,4 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/Tools/CMake") -add_subdirectory(Client) add_subdirectory(Core) add_subdirectory(Server) diff --git a/Phoenix/Core/Include/Core/Voxels/Blocks.hpp b/Phoenix/Core/Include/Core/Voxels/Blocks.hpp index 0bbb46db..e6c19549 100644 --- a/Phoenix/Core/Include/Core/Voxels/Blocks.hpp +++ b/Phoenix/Core/Include/Core/Voxels/Blocks.hpp @@ -68,7 +68,7 @@ namespace phoenix static BlockRegistry *getInstance(); /// @brief Registers a block in the registry - int registerBlock(const std::string& uniqueName, + int registerBlock(const std::string& uniqueName, const std::string& displayName); /// @brief Get the Display name for a block in the registry const std::string& getDisplayName(int blockId); diff --git a/Phoenix/Core/Source/Voxels/Blocks.cpp b/Phoenix/Core/Source/Voxels/Blocks.cpp index 0ffc5200..1d45e056 100644 --- a/Phoenix/Core/Source/Voxels/Blocks.cpp +++ b/Phoenix/Core/Source/Voxels/Blocks.cpp @@ -37,7 +37,9 @@ RegisteredBlock::RegisteredBlock(const std::string& unique, int id, RegisteredBlock::~RegisteredBlock() = default; -BlockRegistry::BlockRegistry(){ i = 0;}; +BlockRegistry::BlockRegistry(){ + i = 0; +}; BlockRegistry *BlockRegistry::instance = 0; @@ -49,8 +51,10 @@ BlockRegistry *BlockRegistry::getInstance(){ int BlockRegistry::registerBlock(const std::string& uniqueName, const std::string& displayName) { + std::cout << std::to_string(i) + "\n"; i++; - Blocks[i] = RegisteredBlock(uniqueName, i, displayName); + RegisteredBlock temp = RegisteredBlock(uniqueName, i, displayName); + Blocks.push_back(temp); return i; }; diff --git a/Phoenix/Server/Source/main.cpp b/Phoenix/Server/Source/main.cpp index daa520d7..b8cd0886 100644 --- a/Phoenix/Server/Source/main.cpp +++ b/Phoenix/Server/Source/main.cpp @@ -14,9 +14,9 @@ int main(int argc, char* argv[]) // Likely a single command from Quartz that launches the logger + any other critical tools // ===== Load Voxel data / Load lua ===== - std::cout << "Program started"; + std::cout << "Program started \n"; voxels::BlockRegistry *registry = registry->getInstance(); - std::cout << "register dirt"; + std::cout << "register dirt \n"; registry->registerBlock("core:dirt", "Dirt"); registry->registerBlock("core:cobble", "CobbleStone"); registry->registerBlock("core:stone", "Stone"); @@ -35,6 +35,7 @@ int main(int argc, char* argv[]) }*/ // ===== Begin shutdown ===== + std::cout << "Begin Shutdown \n \n"; // Send signal for listener to terminate // Confirm map has saved From 6cf4d2b288047ad23686b8df5a243de7db982ebc Mon Sep 17 00:00:00 2001 From: Austin Date: Sat, 7 Dec 2019 19:04:04 -0800 Subject: [PATCH 3/3] implement Quartz singleton class --- Phoenix/Core/CMakeLists.txt | 4 ++-- Phoenix/Core/Include/Core/Voxels/Blocks.hpp | 9 ++++----- Phoenix/Core/Source/Voxels/Blocks.cpp | 6 +++--- Phoenix/Server/CMakeLists.txt | 4 ++-- Phoenix/Server/Source/main.cpp | 11 +++++++---- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Phoenix/Core/CMakeLists.txt b/Phoenix/Core/CMakeLists.txt index 431e9ec4..18fda6b5 100644 --- a/Phoenix/Core/CMakeLists.txt +++ b/Phoenix/Core/CMakeLists.txt @@ -8,8 +8,8 @@ add_subdirectory(Source) add_library(${PROJECT_NAME} STATIC ${phoenixSources} ${phoenixHeaders}) target_link_libraries(${PROJECT_NAME} PRIVATE QuartzEngine) -set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../Quartz/ThirdParty) -target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/../Quartz/Engine/Include) +set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../../Quartz/ThirdParty) +target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/../Engine/Include) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Include) foreach(FILE ${phoenixSources}) diff --git a/Phoenix/Core/Include/Core/Voxels/Blocks.hpp b/Phoenix/Core/Include/Core/Voxels/Blocks.hpp index e6c19549..94c08769 100644 --- a/Phoenix/Core/Include/Core/Voxels/Blocks.hpp +++ b/Phoenix/Core/Include/Core/Voxels/Blocks.hpp @@ -28,6 +28,8 @@ #pragma once +#include + #include #include @@ -54,18 +56,15 @@ namespace phoenix }; /// @brief Stores universal block definitions - class BlockRegistry + class BlockRegistry : public qz::utils::Singleton { private: - static BlockRegistry *instance; std::vector Blocks; int i; - BlockRegistry(); - public: - static BlockRegistry *getInstance(); + BlockRegistry(); /// @brief Registers a block in the registry int registerBlock(const std::string& uniqueName, diff --git a/Phoenix/Core/Source/Voxels/Blocks.cpp b/Phoenix/Core/Source/Voxels/Blocks.cpp index 1d45e056..fbb2da80 100644 --- a/Phoenix/Core/Source/Voxels/Blocks.cpp +++ b/Phoenix/Core/Source/Voxels/Blocks.cpp @@ -41,12 +41,12 @@ BlockRegistry::BlockRegistry(){ i = 0; }; -BlockRegistry *BlockRegistry::instance = 0; +//BlockRegistry *BlockRegistry::instance = 0; -BlockRegistry *BlockRegistry::getInstance(){ +/*BlockRegistry *BlockRegistry::getInstance(){ if (!instance){instance = new BlockRegistry;} return instance; -}; +};*/ int BlockRegistry::registerBlock(const std::string& uniqueName, const std::string& displayName) diff --git a/Phoenix/Server/CMakeLists.txt b/Phoenix/Server/CMakeLists.txt index 29ab8a61..3300a0da 100644 --- a/Phoenix/Server/CMakeLists.txt +++ b/Phoenix/Server/CMakeLists.txt @@ -8,8 +8,8 @@ add_subdirectory(Source) add_executable(${PROJECT_NAME} ${serverSources} ${serverHeaders}) target_link_libraries(${PROJECT_NAME} PRIVATE Phoenix) -set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../Quartz/ThirdParty) -target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/SDL2/include ${dependencies}/../Quartz/Engine/Include ${dependencies}/luamod/include ${dependencies}/imgui/include) +set(dependencies ${CMAKE_CURRENT_LIST_DIR}/../../Quartz/ThirdParty) +target_include_directories(${PROJECT_NAME} PRIVATE ${dependencies}/SDL2/include ${dependencies}/../Engine/Include ${dependencies}/luamod/include ${dependencies}/imgui/include) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Include) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../Core/Include) diff --git a/Phoenix/Server/Source/main.cpp b/Phoenix/Server/Source/main.cpp index b8cd0886..dd129429 100644 --- a/Phoenix/Server/Source/main.cpp +++ b/Phoenix/Server/Source/main.cpp @@ -15,13 +15,16 @@ int main(int argc, char* argv[]) // ===== Load Voxel data / Load lua ===== std::cout << "Program started \n"; - voxels::BlockRegistry *registry = registry->getInstance(); + //voxels::BlockRegistry *registry = registry->get(); std::cout << "register dirt \n"; - registry->registerBlock("core:dirt", "Dirt"); - registry->registerBlock("core:cobble", "CobbleStone"); - registry->registerBlock("core:stone", "Stone"); + voxels::BlockRegistry::get()->registerBlock("core:dirt", "Dirt"); + voxels::BlockRegistry::get()->registerBlock("core:cobble", "CobbleStone"); + voxels::BlockRegistry::get()->registerBlock("core:stone", "Stone"); // TODO: Replace these manual calls to register blocks with a call to run lua files + std::cout << voxels::BlockRegistry::get()->getDisplayName(1); + std::cout << std::to_string(voxels::BlockRegistry::get()->getBlockId("core::dirt")); + // ===== Load save data ===== // Save::Load(argv[0]) //This will detect internally if a new map needs generated based on if save exists