Make ResourceId::id member private, add ResourceId::Null()

This commit is contained in:
baldurk
2017-03-30 18:30:23 +01:00
parent ce4a99b7b8
commit 1be8c70da6
4 changed files with 26 additions and 6 deletions
+3 -1
View File
@@ -53,7 +53,9 @@ struct ToStr
{
// super inefficient to convert to qstr then std::string then back to qstr
// but this is just a temporary measure
return QString::number(el.id).toStdString();
uint64_t num = 0;
memcpy(&num, &el, sizeof(num));
return QString::number(num).toStdString();
}
static std::string Get(const ReplayStatus &el)
+17 -3
View File
@@ -117,19 +117,33 @@ typedef void *(RENDERDOC_CC *pRENDERDOC_AllocArrayMem)(uint64_t sz);
#include "basic_types.h"
#ifdef RENDERDOC_EXPORTS
struct ResourceId;
namespace ResourceIDGen
{
// the only function allowed access to ResourceId internals, for allocating a new ID
ResourceId GetNewUniqueID();
};
#endif
// We give every resource a globally unique ID so that we can differentiate
// between two textures allocated in the same memory (after the first is freed)
//
// it's a struct around a uint64_t to aid in template selection
struct ResourceId
{
uint64_t id;
ResourceId() : id() {}
ResourceId(uint64_t val, bool) { id = val; }
inline static ResourceId Null() { return ResourceId(); }
bool operator==(const ResourceId u) const { return id == u.id; }
bool operator!=(const ResourceId u) const { return id != u.id; }
bool operator<(const ResourceId u) const { return id < u.id; }
private:
uint64_t id;
#ifdef RENDERDOC_EXPORTS
friend ResourceId ResourceIDGen::GetNewUniqueID();
#endif
};
#include "capture_options.h"
+3 -1
View File
@@ -31,7 +31,9 @@ static volatile int64_t globalIDCounter = 1;
ResourceId GetNewUniqueID()
{
return ResourceId(Atomic::Inc64(&globalIDCounter), true);
ResourceId ret;
ret.id = Atomic::Inc64(&globalIDCounter);
return ret;
}
void SetReplayResourceIDs()
+3 -1
View File
@@ -41,7 +41,9 @@ string ToStrHelper<false, ResourceId>::Get(const ResourceId &el)
{
char tostrBuf[256] = {0};
StringFormat::snprintf(tostrBuf, 255, "ResID_%llu", el.id);
RDCCOMPILE_ASSERT(sizeof(el) == sizeof(uint64_t), "ResourceId is no longer 1:1 with uint64_t");
StringFormat::snprintf(tostrBuf, 255, "ResID_%llu", (uint64_t &)el);
return tostrBuf;
}