Switch smn_maplists off KTrie (bug 5884 part 4, r=ds).
This commit is contained in:
parent
414440589e
commit
a8ab617ee9
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* vim: set ts=4 :
|
* vim: set ts=4 sw=4 tw=99 noet :
|
||||||
* =============================================================================
|
* =============================================================================
|
||||||
* SourceMod
|
* SourceMod
|
||||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sh_list.h>
|
#include <sh_list.h>
|
||||||
#include <sm_trie_tpl.h>
|
#include <sm_namehashset.h>
|
||||||
#include "common_logic.h"
|
#include "common_logic.h"
|
||||||
#include "CellArray.h"
|
#include "CellArray.h"
|
||||||
#include <IGameHelpers.h>
|
#include <IGameHelpers.h>
|
||||||
@ -50,6 +50,11 @@ struct maplist_info_t
|
|||||||
time_t last_modified_time;
|
time_t last_modified_time;
|
||||||
CellArray *pArray;
|
CellArray *pArray;
|
||||||
int serial;
|
int serial;
|
||||||
|
|
||||||
|
static inline bool matches(const char *key, const maplist_info_t *value)
|
||||||
|
{
|
||||||
|
return strcmp(value->name, key) == 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAPLIST_FLAG_MAPSFOLDER (1<<0) /**< On failure, use all maps in the maps folder. */
|
#define MAPLIST_FLAG_MAPSFOLDER (1<<0) /**< On failure, use all maps in the maps folder. */
|
||||||
@ -124,9 +129,9 @@ public:
|
|||||||
void AddOrUpdateDefault(const char *name, const char *file)
|
void AddOrUpdateDefault(const char *name, const char *file)
|
||||||
{
|
{
|
||||||
char path[PLATFORM_MAX_PATH];
|
char path[PLATFORM_MAX_PATH];
|
||||||
maplist_info_t *pMapList, **ppMapList;
|
maplist_info_t *pMapList;
|
||||||
|
|
||||||
if ((ppMapList = m_ListLookup.retrieve(name)) == NULL)
|
if (!m_ListLookup.retrieve(name, &pMapList))
|
||||||
{
|
{
|
||||||
pMapList = new maplist_info_t;
|
pMapList = new maplist_info_t;
|
||||||
pMapList->bIsCompat = true;
|
pMapList->bIsCompat = true;
|
||||||
@ -141,21 +146,15 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMapList = *ppMapList;
|
|
||||||
|
|
||||||
/* Don't modify if it's from the config file */
|
/* Don't modify if it's from the config file */
|
||||||
if (!pMapList->bIsCompat)
|
if (!pMapList->bIsCompat)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
g_pSM->BuildPath(Path_Game, path, sizeof(path), "%s", file);
|
g_pSM->BuildPath(Path_Game, path, sizeof(path), "%s", file);
|
||||||
|
|
||||||
/* If the path matches, don't reset the serial/time */
|
/* If the path matches, don't reset the serial/time */
|
||||||
if (strcmp(path, pMapList->path) == 0)
|
if (strcmp(path, pMapList->path) == 0)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
smcore.strncopy(pMapList->path, path, sizeof(pMapList->path));
|
smcore.strncopy(pMapList->path, path, sizeof(pMapList->path));
|
||||||
pMapList->bIsPath = true;
|
pMapList->bIsPath = true;
|
||||||
@ -230,7 +229,7 @@ public:
|
|||||||
List<maplist_info_t *>::iterator iter = compat.begin();
|
List<maplist_info_t *>::iterator iter = compat.begin();
|
||||||
while (iter != compat.end())
|
while (iter != compat.end())
|
||||||
{
|
{
|
||||||
if (m_ListLookup.retrieve((*iter)->name) != NULL)
|
if (m_ListLookup.contains((*iter)->name))
|
||||||
{
|
{
|
||||||
/* The compatibility shim is no longer needed. */
|
/* The compatibility shim is no longer needed. */
|
||||||
delete (*iter)->pArray;
|
delete (*iter)->pArray;
|
||||||
@ -321,7 +320,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (m_pCurMapList != NULL
|
if (m_pCurMapList != NULL
|
||||||
&& m_pCurMapList->path[0] != '\0'
|
&& m_pCurMapList->path[0] != '\0'
|
||||||
&& m_ListLookup.retrieve(m_pCurMapList->name) == NULL)
|
&& !m_ListLookup.contains(m_pCurMapList->name))
|
||||||
{
|
{
|
||||||
m_ListLookup.insert(m_pCurMapList->name, m_pCurMapList);
|
m_ListLookup.insert(m_pCurMapList->name, m_pCurMapList);
|
||||||
m_MapLists.push_back(m_pCurMapList);
|
m_MapLists.push_back(m_pCurMapList);
|
||||||
@ -490,19 +489,13 @@ private:
|
|||||||
bool GetMapList(CellArray **ppArray, const char *name, int *pSerial)
|
bool GetMapList(CellArray **ppArray, const char *name, int *pSerial)
|
||||||
{
|
{
|
||||||
time_t last_time;
|
time_t last_time;
|
||||||
maplist_info_t *pMapList, **ppMapList;
|
maplist_info_t *pMapList;
|
||||||
|
|
||||||
if ((ppMapList = m_ListLookup.retrieve(name)) == NULL)
|
if (!m_ListLookup.retrieve(name, &pMapList))
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
pMapList = *ppMapList;
|
|
||||||
|
|
||||||
if (!pMapList->bIsPath)
|
if (!pMapList->bIsPath)
|
||||||
{
|
|
||||||
return GetMapList(ppArray, pMapList->path, pSerial);
|
return GetMapList(ppArray, pMapList->path, pSerial);
|
||||||
}
|
|
||||||
|
|
||||||
/* If it is a path, and the path is "*", assume all files must be used. */
|
/* If it is a path, and the path is "*", assume all files must be used. */
|
||||||
if (strcmp(pMapList->path, "*") == 0)
|
if (strcmp(pMapList->path, "*") == 0)
|
||||||
@ -598,7 +591,7 @@ private:
|
|||||||
char m_ConfigFile[PLATFORM_MAX_PATH];
|
char m_ConfigFile[PLATFORM_MAX_PATH];
|
||||||
time_t m_ConfigLastChanged;
|
time_t m_ConfigLastChanged;
|
||||||
ConVar *m_pMapCycleFile;
|
ConVar *m_pMapCycleFile;
|
||||||
KTrie<maplist_info_t *> m_ListLookup;
|
NameHashSet<maplist_info_t *> m_ListLookup;
|
||||||
List<maplist_info_t *> m_MapLists;
|
List<maplist_info_t *> m_MapLists;
|
||||||
MapListState m_CurState;
|
MapListState m_CurState;
|
||||||
unsigned int m_IgnoreLevel;
|
unsigned int m_IgnoreLevel;
|
||||||
|
@ -125,6 +125,13 @@ public:
|
|||||||
return table_.add(i, value);
|
return table_.add(i, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool contains(const char *aKey)
|
||||||
|
{
|
||||||
|
CharsAndLength key(aKey);
|
||||||
|
Result r = table_.find(aKey);
|
||||||
|
return r.found();
|
||||||
|
}
|
||||||
|
|
||||||
bool remove(const char *aKey)
|
bool remove(const char *aKey)
|
||||||
{
|
{
|
||||||
CharsAndLength key(aKey);
|
CharsAndLength key(aKey);
|
||||||
@ -135,6 +142,11 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear()
|
||||||
|
{
|
||||||
|
table_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Internal table_;
|
Internal table_;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user