Add function to create custom v8 UUIDs that use date&time for the first 6 byte in a human-readable form
This commit is contained in:
2
3rdParty/libstud-uuid/CMakeLists.txt
vendored
2
3rdParty/libstud-uuid/CMakeLists.txt
vendored
@@ -1,7 +1,7 @@
|
|||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
if(NOT DEFINED LIBSTUD_REPO)
|
if(NOT DEFINED LIBSTUD_REPO)
|
||||||
set(LIBSTUD_REPO https://github.com/GeorgH93/libstud-uuid.git)
|
set(LIBSTUD_REPO https://git.madvoxel.net/Mirrors/libstud-uuid.git)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
|
|||||||
49
openVulkanoCpp/Base/UUID.cpp
Normal file
49
openVulkanoCpp/Base/UUID.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "UUID.hpp"
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
namespace OpenVulkano
|
||||||
|
{
|
||||||
|
UUID GenerateTimePrefixedCustomUUID()
|
||||||
|
{
|
||||||
|
UUID uuid = UUID::generate();
|
||||||
|
|
||||||
|
uuid.time_low = 0;
|
||||||
|
uuid.time_mid = 0;
|
||||||
|
time_t now = time(nullptr);
|
||||||
|
struct tm* timeinfo = localtime(&now);
|
||||||
|
|
||||||
|
// Extract time components
|
||||||
|
uint32_t year = timeinfo->tm_year % 100; // Get last two digits of year
|
||||||
|
uint32_t month = timeinfo->tm_mon + 1; // Month is 0-based
|
||||||
|
uint32_t day = timeinfo->tm_mday;
|
||||||
|
uint32_t hour = timeinfo->tm_hour;
|
||||||
|
uint16_t minute = timeinfo->tm_min;
|
||||||
|
uint16_t second = timeinfo->tm_sec;
|
||||||
|
|
||||||
|
// Each decimal digit takes 4 bits in the final hex number
|
||||||
|
uuid.time_low |= (year / 10) << 28;
|
||||||
|
uuid.time_low |= (year % 10) << 24;
|
||||||
|
uuid.time_low |= (month / 10) << 20;
|
||||||
|
uuid.time_low |= (month % 10) << 16;
|
||||||
|
uuid.time_low |= (day / 10) << 12;
|
||||||
|
uuid.time_low |= (day % 10) << 8;
|
||||||
|
uuid.time_low |= (hour / 10) << 4;
|
||||||
|
uuid.time_low |= (hour % 10) << 0;
|
||||||
|
uuid.time_mid |= (minute / 10) << 12;
|
||||||
|
uuid.time_mid |= (minute % 10) << 8;
|
||||||
|
uuid.time_mid |= (second / 10) << 4;
|
||||||
|
uuid.time_mid |= (second % 10) << 0;
|
||||||
|
|
||||||
|
// Set version to custom
|
||||||
|
uuid.time_hiv &= ~(static_cast<uint16_t>(uuid.version()) << 12);
|
||||||
|
uuid.time_hiv |= 8 << 12;
|
||||||
|
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,4 +11,6 @@
|
|||||||
namespace OpenVulkano
|
namespace OpenVulkano
|
||||||
{
|
{
|
||||||
typedef stud::uuid UUID;
|
typedef stud::uuid UUID;
|
||||||
|
|
||||||
|
UUID GenerateTimePrefixedCustomUUID();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user