diff --git a/engine/includes/platform.h b/engine/includes/platform.h index ab58f47ed..18f8928f2 100644 --- a/engine/includes/platform.h +++ b/engine/includes/platform.h @@ -2,7 +2,7 @@ #include #define THUNDER_MAIN() \ - int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { \ + int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow) { \ int result = 0; \ int w_argc = 0; \ LPWSTR *w_argv = CommandLineToArgvW(GetCommandLineW(), &w_argc); \ diff --git a/engine/src/editor/assetconverter.cpp b/engine/src/editor/assetconverter.cpp index 3289edcbc..87802b3fa 100644 --- a/engine/src/editor/assetconverter.cpp +++ b/engine/src/editor/assetconverter.cpp @@ -2,7 +2,6 @@ #include #include -#include // Icon related #include #include @@ -19,6 +18,8 @@ #include #include +#include + namespace { const char *gMd5("md5"); const char *gVersion("version"); @@ -311,7 +312,7 @@ ResourceSystem::ResourceInfo AssetConverterSettings::subItem(const TString &key, } if(create) { ResourceSystem::ResourceInfo info; - info.uuid = QUuid::createUuid().toString().toStdString(); + info.uuid = Uuid::createUuid().toString(); info.md5 = m_info.md5; return info; } diff --git a/engine/src/editor/assetmanager.cpp b/engine/src/editor/assetmanager.cpp index f9c67ea74..4d29847fe 100644 --- a/engine/src/editor/assetmanager.cpp +++ b/engine/src/editor/assetmanager.cpp @@ -1,16 +1,20 @@ #include "assetmanager.h" #include -#include #include #include "config.h" #include +#include + +#include #include "editor/assetconverter.h" #include "editor/nativecodebuilder.h" #include "editor/baseassetprovider.h" +#include "editor/projectsettings.h" +#include "editor/pluginmanager.h" #include "components/actor.h" @@ -25,11 +29,6 @@ #include "converters/mapconverter.h" #include "converters/controlschemeconverter.h" -#include "editor/projectsettings.h" -#include "editor/pluginmanager.h" - -#include "log.h" - #define INDEX_VERSION 2 namespace { @@ -264,7 +263,7 @@ void AssetManager::makePrefab(const TString &source, const TString &target) { AssetConverterSettings *settings = converter->createSettings(); settings->setSource(path); - settings->info().uuid = QUuid::createUuid().toString().toStdString(); + settings->info().uuid = Uuid::createUuid().toString(); m_converterSettings[path] = settings; converter->makePrefab(actor, settings); @@ -316,7 +315,7 @@ AssetConverterSettings *AssetManager::fetchSettings(const TString &source) { CodeBuilder *currentBuilder = m_projectManager->currentBuilder(); CodeBuilder *builder = nullptr; for(auto it : m_builders) { - if(dynamic_cast(it) == nullptr || it == currentBuilder) { + if(it && (dynamic_cast(it) == nullptr || it == currentBuilder)) { for(auto &s : it->suffixes()) { if(s == suffix) { builder = it; @@ -338,7 +337,7 @@ AssetConverterSettings *AssetManager::fetchSettings(const TString &source) { settings->setSource(source); if(!settings->loadSettings()) { - settings->info().uuid = QUuid::createUuid().toString().toStdString(); + settings->info().uuid = Uuid::createUuid().toString(); } m_converterSettings[path] = settings; diff --git a/engine/src/editor/baseassetprovider.cpp b/engine/src/editor/baseassetprovider.cpp index 54d3ef634..96b0d00fb 100644 --- a/engine/src/editor/baseassetprovider.cpp +++ b/engine/src/editor/baseassetprovider.cpp @@ -2,7 +2,6 @@ #include #include -#include #include "editor/projectsettings.h" #include "editor/assetmanager.h" diff --git a/engine/src/editor/projectsettings.cpp b/engine/src/editor/projectsettings.cpp index cf3ae8ed6..6a54638ed 100644 --- a/engine/src/editor/projectsettings.cpp +++ b/engine/src/editor/projectsettings.cpp @@ -1,6 +1,5 @@ #include "projectsettings.h" -#include #include #include @@ -9,6 +8,7 @@ #include #include +#include #include "config.h" @@ -103,7 +103,7 @@ void ProjectSettings::loadSettings() { VariantMap object = Json::load(file.readAll()).toMap(); file.close(); - m_projectId = QUuid::createUuid().toString().toStdString(); + m_projectId = Uuid::createUuid().toString(); for(const auto &it : object) { TString name = it.first; diff --git a/modules/editor/shadertools/converter/shadergraph.cpp b/modules/editor/shadertools/converter/shadergraph.cpp index 3ebef8a99..55fc7cd0c 100644 --- a/modules/editor/shadertools/converter/shadergraph.cpp +++ b/modules/editor/shadertools/converter/shadergraph.cpp @@ -1,12 +1,7 @@ #include "shadergraph.h" -#include - -#include - #include -#include #include #include @@ -17,6 +12,7 @@ #include #include +#include #include #include "functions/camera.h" @@ -272,8 +268,8 @@ void ShaderGraph::scanForCustomFunctions() { QFile file(filePath); if(file.open(QFile::ReadOnly | QFile::Text)) { pugi::xml_document doc; - if(doc.load_string(file.readAll().data()).status == pugi::status_ok) { - + QByteArray data = file.readAll(); + if(doc.load_string(data.data()).status == pugi::status_ok) { pugi::xml_node function = doc.document_element(); const char *name = function.attribute("name").as_string(); @@ -764,15 +760,15 @@ Texture *ShaderGraph::preview(GraphNode *node) { } if(dynamic_cast(node) == nullptr && node != m_rootNode) { - QString name = QUuid::createUuid().toString(); + TString name(Uuid::createUuid().toString()); PreviewData data; - data.texture = Engine::objectCreate((name + "_tex").toStdString()); + data.texture = Engine::objectCreate(name + "_tex"); data.texture->setFormat(Texture::RGBA8); data.texture->setFlags(Texture::Render); data.texture->resize(150, 150); - data.target = Engine::objectCreate((name + "_rt").toStdString()); + data.target = Engine::objectCreate(name + "_rt"); data.target->setColorAttachment(0, data.texture); data.target->setClearFlags(RenderTarget::ClearColor); diff --git a/thirdparty/next/inc/os/uuid.h b/thirdparty/next/inc/os/uuid.h new file mode 100644 index 000000000..002b80788 --- /dev/null +++ b/thirdparty/next/inc/os/uuid.h @@ -0,0 +1,50 @@ +/* + This file is part of Thunder Next. + + Thunder Next is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + Thunder Next is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with Thunder Next. If not, see . + + Copyright: 2008-2025 Evgeniy Prikazchikov +*/ + +#ifndef UUID_H +#define UUID_H + +#include +#include + +class NEXT_LIBRARY_EXPORT Uuid { +public: + Uuid(); + + explicit Uuid(const TString &uuid); + + static Uuid createUuid(); + + bool isNull() const; + + TString toString() const; + + ByteArray toByteArray() const; + + bool operator== (const Uuid &other) const; + + bool operator!= (const Uuid &other) const; + + bool operator< (const Uuid &other) const; + +private: + std::array data; + +}; + +#endif // UUID_H diff --git a/thirdparty/next/src/os/uuid.cpp b/thirdparty/next/src/os/uuid.cpp new file mode 100644 index 000000000..fcdf9f520 --- /dev/null +++ b/thirdparty/next/src/os/uuid.cpp @@ -0,0 +1,99 @@ +#include "uuid.h" + +#include +#include +#include +#include + +#include + +Uuid::Uuid() : + data{} { + +} + +Uuid::Uuid(const TString &uuid) { + size_t pos = 0; + for(size_t i = 0; i < uuid.length(); ++i) { + if(uuid.at(i) == '-' || uuid.at(i) == '{') continue; + + if(i + 1 >= uuid.length() || pos == 15) { + break; + } + + TString byteStr = uuid.mid(i, 2); + data[pos++] = static_cast(std::stoi(byteStr.toStdString(), nullptr, 16)); + i++; + } +} + +Uuid Uuid::createUuid() { + static std::random_device rd; + static std::mt19937 gen(rd()); + static std::uniform_int_distribution dis(0, 255); + + Uuid result; + for(auto &byte : result.data) { + byte = dis(gen); + } + + // Set version (4) and variant (10) + result.data[6] = (result.data[6] & 0x0F) | 0x40; // version 4 + result.data[8] = (result.data[8] & 0x3F) | 0x80; // variant RFC 4122 + + return result; +} + +bool Uuid::isNull() const { + return std::all_of(data.begin(), data.end(), [](uint8_t byte) { return byte == 0; }); +} + +TString Uuid::toString() const { + std::ostringstream oss; + oss << std::hex << std::setfill('0'); + + oss << '{'; + for(uint8_t i = 0; i < 4; ++i) { + oss << std::setw(2) << static_cast(data[i]); + } + oss << '-'; + + for(uint8_t i = 4; i < 6; ++i) { + oss << std::setw(2) << static_cast(data[i]); + } + oss << '-'; + + // time_hi_and_version (2 bytes) + for(uint8_t i = 6; i < 8; ++i) { + oss << std::setw(2) << static_cast(data[i]); + } + oss << '-'; + + for(uint8_t i = 8; i < 10; ++i) { + oss << std::setw(2) << static_cast(data[i]); + } + oss << '-'; + + for(uint8_t i = 10; i < 16; ++i) { + oss << std::setw(2) << static_cast(data[i]); + } + oss << '}'; + + return oss.str(); +} + +ByteArray Uuid::toByteArray() const { + return ByteArray(data.begin(), data.end()); +} + +bool Uuid::operator== (const Uuid &other) const { + return data == other.data; +} + +bool Uuid::operator!= (const Uuid &other) const { + return !(*this == other); +} + +bool Uuid::operator< (const Uuid &other) const { + return data < other.data; +}