Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/includes/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <Windows.h>

#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); \
Expand Down
5 changes: 3 additions & 2 deletions engine/src/editor/assetconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <QFile>
#include <QCryptographicHash>
#include <QUuid>
// Icon related
#include <QtSvg/QSvgRenderer>
#include <QPainter>
Expand All @@ -19,6 +18,8 @@
#include <url.h>
#include <file.h>

#include <os/uuid.h>

namespace {
const char *gMd5("md5");
const char *gVersion("version");
Expand Down Expand Up @@ -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;
}
Expand Down
17 changes: 8 additions & 9 deletions engine/src/editor/assetmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#include "assetmanager.h"

#include <QDir>
#include <QUuid>
#include <QMessageBox>

#include "config.h"

#include <json.h>
#include <log.h>

#include <os/uuid.h>

#include "editor/assetconverter.h"
#include "editor/nativecodebuilder.h"
#include "editor/baseassetprovider.h"
#include "editor/projectsettings.h"
#include "editor/pluginmanager.h"

#include "components/actor.h"

Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<NativeCodeBuilder *>(it) == nullptr || it == currentBuilder) {
if(it && (dynamic_cast<NativeCodeBuilder *>(it) == nullptr || it == currentBuilder)) {
for(auto &s : it->suffixes()) {
if(s == suffix) {
builder = it;
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion engine/src/editor/baseassetprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <QDirIterator>
#include <QFileSystemWatcher>
#include <QUuid>

#include "editor/projectsettings.h"
#include "editor/assetmanager.h"
Expand Down
4 changes: 2 additions & 2 deletions engine/src/editor/projectsettings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "projectsettings.h"

#include <QUuid>
#include <QDir>

#include <QCoreApplication>
Expand All @@ -9,6 +8,7 @@

#include <log.h>
#include <json.h>
#include <os/uuid.h>

#include "config.h"

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 6 additions & 10 deletions modules/editor/shadertools/converter/shadergraph.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#include "shadergraph.h"

#include <QUuid>

#include <QStack>

#include <QDirIterator>

#include <sstream>
#include <algorithm>

#include <commandbuffer.h>
Expand All @@ -17,6 +12,7 @@
#include <editor/projectsettings.h>

#include <systems/resourcesystem.h>
#include <os/uuid.h>
#include <url.h>

#include "functions/camera.h"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -764,15 +760,15 @@ Texture *ShaderGraph::preview(GraphNode *node) {
}

if(dynamic_cast<NodeGroup *>(node) == nullptr && node != m_rootNode) {
QString name = QUuid::createUuid().toString();
TString name(Uuid::createUuid().toString());

PreviewData data;
data.texture = Engine::objectCreate<Texture>((name + "_tex").toStdString());
data.texture = Engine::objectCreate<Texture>(name + "_tex");
data.texture->setFormat(Texture::RGBA8);
data.texture->setFlags(Texture::Render);
data.texture->resize(150, 150);

data.target = Engine::objectCreate<RenderTarget>((name + "_rt").toStdString());
data.target = Engine::objectCreate<RenderTarget>(name + "_rt");
data.target->setColorAttachment(0, data.texture);
data.target->setClearFlags(RenderTarget::ClearColor);

Expand Down
50 changes: 50 additions & 0 deletions thirdparty/next/inc/os/uuid.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

Copyright: 2008-2025 Evgeniy Prikazchikov
*/

#ifndef UUID_H
#define UUID_H

#include <astring.h>
#include <array>

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<uint8_t, 16> data;

};

#endif // UUID_H
99 changes: 99 additions & 0 deletions thirdparty/next/src/os/uuid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "uuid.h"

#include <random>
#include <iomanip>
#include <sstream>
#include <algorithm>

#include <astring.h>

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<uint8_t>(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<uint32_t> 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<int>(data[i]);
}
oss << '-';

for(uint8_t i = 4; i < 6; ++i) {
oss << std::setw(2) << static_cast<int>(data[i]);
}
oss << '-';

// time_hi_and_version (2 bytes)
for(uint8_t i = 6; i < 8; ++i) {
oss << std::setw(2) << static_cast<int>(data[i]);
}
oss << '-';

for(uint8_t i = 8; i < 10; ++i) {
oss << std::setw(2) << static_cast<int>(data[i]);
}
oss << '-';

for(uint8_t i = 10; i < 16; ++i) {
oss << std::setw(2) << static_cast<int>(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;
}
Loading