mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Use std::vector<CName> instead of array, adjust variable name
This commit is contained in:
parent
ce54a0d075
commit
4a023342b7
|
@ -3,6 +3,7 @@
|
|||
#include <base/hash_ctxt.h>
|
||||
#include <engine/shared/packer.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
|
||||
static const CUuid TEEWORLDS_NAMESPACE = {{// "e05ddaaa-c4e6-4cfb-b642-5d48e80c0029"
|
||||
|
@ -100,29 +101,28 @@ static int GetID(int Index)
|
|||
|
||||
void CUuidManager::RegisterName(int ID, const char *pName)
|
||||
{
|
||||
int Index = GetIndex(ID);
|
||||
dbg_assert(Index == m_aNames.size(), "names must be registered with increasing ID");
|
||||
dbg_assert(GetIndex(ID) == (int)m_vNames.size(), "names must be registered with increasing ID");
|
||||
CName Name;
|
||||
Name.m_pName = pName;
|
||||
Name.m_Uuid = CalculateUuid(pName);
|
||||
dbg_assert(LookupUuid(Name.m_Uuid) == -1, "duplicate uuid");
|
||||
|
||||
m_aNames.add(Name);
|
||||
m_vNames.push_back(Name);
|
||||
|
||||
CNameIndexed NameIndexed;
|
||||
NameIndexed.m_Uuid = Name.m_Uuid;
|
||||
NameIndexed.m_ID = GetIndex(ID);
|
||||
m_aNamesSorted.insert(std::lower_bound(m_aNamesSorted.begin(), m_aNamesSorted.end(), NameIndexed), NameIndexed);
|
||||
m_vNamesSorted.insert(std::lower_bound(m_vNamesSorted.begin(), m_vNamesSorted.end(), NameIndexed), NameIndexed);
|
||||
}
|
||||
|
||||
CUuid CUuidManager::GetUuid(int ID) const
|
||||
{
|
||||
return m_aNames[GetIndex(ID)].m_Uuid;
|
||||
return m_vNames[GetIndex(ID)].m_Uuid;
|
||||
}
|
||||
|
||||
const char *CUuidManager::GetName(int ID) const
|
||||
{
|
||||
return m_aNames[GetIndex(ID)].m_pName;
|
||||
return m_vNames[GetIndex(ID)].m_pName;
|
||||
}
|
||||
|
||||
int CUuidManager::LookupUuid(CUuid Uuid) const
|
||||
|
@ -130,7 +130,7 @@ int CUuidManager::LookupUuid(CUuid Uuid) const
|
|||
CNameIndexed Needle;
|
||||
Needle.m_Uuid = Uuid;
|
||||
Needle.m_ID = 0;
|
||||
auto Range = std::equal_range(m_aNamesSorted.begin(), m_aNamesSorted.end(), Needle);
|
||||
auto Range = std::equal_range(m_vNamesSorted.begin(), m_vNamesSorted.end(), Needle);
|
||||
if(std::distance(Range.first, Range.second) == 1)
|
||||
{
|
||||
return GetID(Range.first->m_ID);
|
||||
|
@ -140,7 +140,7 @@ int CUuidManager::LookupUuid(CUuid Uuid) const
|
|||
|
||||
int CUuidManager::NumUuids() const
|
||||
{
|
||||
return m_aNames.size();
|
||||
return m_vNames.size();
|
||||
}
|
||||
|
||||
int CUuidManager::UnpackUuid(CUnpacker *pUnpacker) const
|
||||
|
@ -168,10 +168,10 @@ void CUuidManager::PackUuid(int ID, CPacker *pPacker) const
|
|||
|
||||
void CUuidManager::DebugDump() const
|
||||
{
|
||||
for(int i = 0; i < m_aNames.size(); i++)
|
||||
for(const auto &Name : m_vNames)
|
||||
{
|
||||
char aBuf[UUID_MAXSTRSIZE];
|
||||
FormatUuid(m_aNames[i].m_Uuid, aBuf, sizeof(aBuf));
|
||||
dbg_msg("uuid", "%s %s", aBuf, m_aNames[i].m_pName);
|
||||
FormatUuid(Name.m_Uuid, aBuf, sizeof(aBuf));
|
||||
dbg_msg("uuid", "%s %s", aBuf, Name.m_pName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#ifndef ENGINE_SHARED_UUID_MANAGER_H
|
||||
#define ENGINE_SHARED_UUID_MANAGER_H
|
||||
|
||||
#include <base/tl/array.h>
|
||||
#include <vector>
|
||||
|
||||
#include <base/system.h>
|
||||
|
||||
enum
|
||||
{
|
||||
UUID_MAXSTRSIZE = 37, // 12345678-0123-5678-0123-567890123456
|
||||
|
@ -50,8 +51,8 @@ class CUnpacker;
|
|||
|
||||
class CUuidManager
|
||||
{
|
||||
array<CName> m_aNames;
|
||||
std::vector<CNameIndexed> m_aNamesSorted;
|
||||
std::vector<CName> m_vNames;
|
||||
std::vector<CNameIndexed> m_vNamesSorted;
|
||||
|
||||
public:
|
||||
void RegisterName(int ID, const char *pName);
|
||||
|
|
Loading…
Reference in a new issue