diff --git a/src/libRender/CMakeLists.txt b/src/libRender/CMakeLists.txt index cf02a5cbf12b70400548b2953e8e9df3ce78d4f9..d43a3c565c0ce28ae07af877fe45013d0fbd90a9 100644 --- a/src/libRender/CMakeLists.txt +++ b/src/libRender/CMakeLists.txt @@ -183,7 +183,7 @@ set(resources # std::uuid dependency # Note, follow the progress of integration of uuid generator in the C++ std lib. When supported by std, remove this dependency set(UUID_BUILD_TESTS OFF) -set(UUID_SYSTEM_GENERATOR ON) +set(UUID_SYSTEM_GENERATOR OFF) set(UUID_USING_CXX20_SPAN OFF) # change this when going to C++20 as language standard for Radium libs add_subdirectory(Dependencies/stduuid) add_library(std::uuid ALIAS stduuid) @@ -356,6 +356,7 @@ target_link_libraries( PUBLIC Radium::Core NodeEditor::nodes + std::uuid ${Qt_LIBRARIES} ${libName} # make this PRIVATE ? ) diff --git a/src/libRender/RadiumNBR/NodeGraph/Node.cpp b/src/libRender/RadiumNBR/NodeGraph/Node.cpp index da71325dc5b132fb4bcd15a755b6aacf2af944c6..5907479024ec87bd3affa0bbd8084836bfeb9a72 100644 --- a/src/libRender/RadiumNBR/NodeGraph/Node.cpp +++ b/src/libRender/RadiumNBR/NodeGraph/Node.cpp @@ -3,15 +3,32 @@ #include <Core/Utils/Log.hpp> using namespace Ra::Core::Utils; +bool Node::s_uuidGeneratorInitialized {false}; +uuids::uuid_random_generator* Node::s_uidGenerator{nullptr}; +void Node::createUuidGenerator() { + std::random_device rd; + auto seed_data = std::array<int, std::mt19937::state_size> {}; + std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd)); + std::seed_seq seq(std::begin(seed_data), std::end(seed_data)); + std::mt19937 generator(seq); + s_uidGenerator = new uuids::uuid_random_generator(generator); + s_uuidGeneratorInitialized = true; +} + /// Generates the uuid of the node void Node::generateUuid() { - m_uuid = uuids::uuid_system_generator{}(); + if (!s_uuidGeneratorInitialized) { + createUuidGenerator(); + } + m_uuid = (*s_uidGenerator)(); } /// Gets the UUID of the node as a string std::string Node::getUuid() const { if ( m_uuid.is_nil() ) { // generates the uuid (need to remove const attribute ... const_cast<Node*>(this)->generateUuid(); + std::string guuid = "{" + uuids::to_string(m_uuid) + "}"; + std::cout << "###*** UUId generated for node" << getName() << " : " << guuid << std::endl; } std::string struuid = "{" + uuids::to_string(m_uuid) + "}"; return struuid; diff --git a/src/libRender/RadiumNBR/NodeGraph/Node.hpp b/src/libRender/RadiumNBR/NodeGraph/Node.hpp index fd71316c14b15bd0563e0d4c6b12c0410f38d632..2542d159d80b2365e1c18cb357dec9a917a15974 100644 --- a/src/libRender/RadiumNBR/NodeGraph/Node.hpp +++ b/src/libRender/RadiumNBR/NodeGraph/Node.hpp @@ -231,4 +231,9 @@ class NodeBasedRenderer_LIBRARY_API Node /// Additional data on the node, added by application or gui or ... nlohmann::json m_extraJsonData; + + /// generator for uuid + static bool s_uuidGeneratorInitialized; + static uuids::uuid_random_generator* s_uidGenerator; + static void createUuidGenerator(); };