Switch HalfLife2 off KTrie (bug 5884 part 7, r=ds).
This commit is contained in:
parent
0b8e2fd5c9
commit
3850765759
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* vim: set ts=4 sw=4 tw=99 noet :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||
@ -76,51 +76,17 @@ ConVar *sv_lan = NULL;
|
||||
static void *g_EntList = NULL;
|
||||
static int entInfoOffset = -1;
|
||||
|
||||
namespace SourceHook
|
||||
{
|
||||
template<>
|
||||
int HashFunction<datamap_t *>(datamap_t * const &k)
|
||||
{
|
||||
return reinterpret_cast<int>(k);
|
||||
}
|
||||
|
||||
template<>
|
||||
int Compare<datamap_t *>(datamap_t * const &k1, datamap_t * const &k2)
|
||||
{
|
||||
return (k1-k2);
|
||||
}
|
||||
}
|
||||
|
||||
CHalfLife2::CHalfLife2()
|
||||
{
|
||||
m_pClasses = sm_trie_create();
|
||||
}
|
||||
|
||||
CHalfLife2::~CHalfLife2()
|
||||
{
|
||||
sm_trie_destroy(m_pClasses);
|
||||
for (NameHashSet<DataTableInfo *>::iterator iter = m_Classes.iter(); !iter.empty(); iter.next())
|
||||
delete *iter;
|
||||
|
||||
List<DataTableInfo *>::iterator iter;
|
||||
DataTableInfo *pInfo;
|
||||
for (iter=m_Tables.begin(); iter!=m_Tables.end(); iter++)
|
||||
{
|
||||
pInfo = (*iter);
|
||||
delete pInfo;
|
||||
}
|
||||
|
||||
m_Tables.clear();
|
||||
|
||||
THash<datamap_t *, DataMapTrie>::iterator h_iter;
|
||||
for (h_iter=m_Maps.begin(); h_iter!=m_Maps.end(); h_iter++)
|
||||
{
|
||||
if (h_iter->val.trie)
|
||||
{
|
||||
delete h_iter->val.trie;
|
||||
h_iter->val.trie = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
m_Maps.clear();
|
||||
for (DataTableMap::iterator iter = m_Maps.iter(); !iter.empty(); iter.next())
|
||||
delete iter->value;
|
||||
}
|
||||
|
||||
#if SOURCE_ENGINE != SE_DARKMESSIAH
|
||||
@ -379,36 +345,29 @@ ServerClass *CHalfLife2::FindServerClass(const char *classname)
|
||||
DataTableInfo *pInfo = _FindServerClass(classname);
|
||||
|
||||
if (!pInfo)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pInfo->sc;
|
||||
}
|
||||
|
||||
DataTableInfo *CHalfLife2::_FindServerClass(const char *classname)
|
||||
{
|
||||
DataTableInfo *pInfo = NULL;
|
||||
|
||||
if (!sm_trie_retrieve(m_pClasses, classname, (void **)&pInfo))
|
||||
DataTableInfo *pInfo;
|
||||
if (!m_Classes.retrieve(classname, &pInfo))
|
||||
{
|
||||
ServerClass *sc = gamedll->GetAllServerClasses();
|
||||
while (sc)
|
||||
{
|
||||
if (strcmp(classname, sc->GetName()) == 0)
|
||||
{
|
||||
pInfo = new DataTableInfo;
|
||||
pInfo->sc = sc;
|
||||
sm_trie_insert(m_pClasses, classname, pInfo);
|
||||
m_Tables.push_back(pInfo);
|
||||
pInfo = new DataTableInfo(sc);
|
||||
m_Classes.insert(classname, pInfo);
|
||||
break;
|
||||
}
|
||||
sc = sc->m_pNext;
|
||||
}
|
||||
if (!pInfo)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return pInfo;
|
||||
@ -424,7 +383,7 @@ bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((prop = pInfo->lookup.retrieve(offset)) == NULL)
|
||||
if (!pInfo->lookup.retrieve(offset, info))
|
||||
{
|
||||
sm_sendprop_info_t temp_info;
|
||||
|
||||
@ -436,10 +395,6 @@ bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_
|
||||
pInfo->lookup.insert(offset, temp_info);
|
||||
*info = temp_info;
|
||||
}
|
||||
else
|
||||
{
|
||||
*info = *prop;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -470,32 +425,21 @@ typedescription_t *CHalfLife2::FindInDataMap(datamap_t *pMap, const char *offset
|
||||
|
||||
bool CHalfLife2::FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatable_info_t *pDataTable)
|
||||
{
|
||||
DataMapTrie &val = m_Maps[pMap];
|
||||
DataTableMap::Insert i = m_Maps.findForAdd(pMap);
|
||||
if (!i.found())
|
||||
m_Maps.add(i, pMap, new DataMapCache());
|
||||
|
||||
if (!val.trie)
|
||||
DataMapCache *cache = i->value;
|
||||
|
||||
sm_datatable_info_t *pNewTable;
|
||||
if (!cache->retrieve(offset, pDataTable))
|
||||
{
|
||||
val.trie = new KTrie<sm_datatable_info_t>;
|
||||
}
|
||||
|
||||
sm_datatable_info_t * pNewTable = val.trie->retrieve(offset);
|
||||
|
||||
if (!pNewTable)
|
||||
{
|
||||
if (UTIL_FindDataMapInfo(pMap, offset, pDataTable))
|
||||
{
|
||||
val.trie->insert(offset, *pDataTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
pDataTable->prop = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*pDataTable = *pNewTable;
|
||||
if (!UTIL_FindDataMapInfo(pMap, offset, pDataTable))
|
||||
return false;
|
||||
cache->insert(offset, *pDataTable);
|
||||
}
|
||||
|
||||
return (pDataTable->prop != NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* vim: set ts=4 sw=4 tw=99 noet :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||
@ -35,8 +35,10 @@
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <sh_tinyhash.h>
|
||||
#include <sm_trie_tpl.h>
|
||||
#include "sm_trie.h"
|
||||
#include <am-utility.h>
|
||||
#include <am-hashmap.h>
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sm_namehashset.h>
|
||||
#include "sm_globals.h"
|
||||
#include "sm_queue.h"
|
||||
#include <IGameHelpers.h>
|
||||
@ -59,16 +61,38 @@ using namespace SourceMod;
|
||||
|
||||
struct DataTableInfo
|
||||
{
|
||||
struct SendPropPolicy
|
||||
{
|
||||
static inline bool matches(const char *name, const sm_sendprop_info_t &info)
|
||||
{
|
||||
return strcmp(name, info.prop->GetName()) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
static inline bool matches(const char *name, const DataTableInfo *info)
|
||||
{
|
||||
return strcmp(name, info->sc->GetName()) == 0;
|
||||
}
|
||||
|
||||
DataTableInfo(ServerClass *sc)
|
||||
: sc(sc)
|
||||
{
|
||||
}
|
||||
|
||||
ServerClass *sc;
|
||||
KTrie<sm_sendprop_info_t> lookup;
|
||||
NameHashSet<sm_sendprop_info_t, SendPropPolicy> lookup;
|
||||
};
|
||||
|
||||
struct DataMapTrie
|
||||
struct DataMapCachePolicy
|
||||
{
|
||||
DataMapTrie() : trie(NULL) {}
|
||||
KTrie<sm_datatable_info_t> *trie;
|
||||
static inline bool matches(const char *name, const sm_datatable_info_t &info)
|
||||
{
|
||||
return strcmp(name, info.prop->fieldName) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef NameHashSet<sm_datatable_info_t, DataMapCachePolicy> DataMapCache;
|
||||
|
||||
struct DelayedFakeCliCmd
|
||||
{
|
||||
String cmd;
|
||||
@ -169,9 +193,10 @@ private:
|
||||
void InitLogicalEntData();
|
||||
void InitCommandLine();
|
||||
private:
|
||||
Trie *m_pClasses;
|
||||
List<DataTableInfo *> m_Tables;
|
||||
THash<datamap_t *, DataMapTrie> m_Maps;
|
||||
typedef ke::HashMap<datamap_t *, DataMapCache *, ke::PointerPolicy<datamap_t> > DataTableMap;
|
||||
|
||||
NameHashSet<DataTableInfo *> m_Classes;
|
||||
DataTableMap m_Maps;
|
||||
int m_MsgTextMsg;
|
||||
int m_HinTextMsg;
|
||||
int m_SayTextMsg;
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <ILibrarySys.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <sm_trie_tpl.h>
|
||||
#include "common_logic.h"
|
||||
#include <IPluginSys.h>
|
||||
#include <IRootConsoleMenu.h>
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <sm_trie_tpl.h>
|
||||
#include <ISourceMod.h>
|
||||
#include "common_logic.h"
|
||||
#include "ShareSys.h"
|
||||
|
@ -98,6 +98,7 @@ class HashMap : public AllocPolicy
|
||||
|
||||
typedef typename Internal::Result Result;
|
||||
typedef typename Internal::Insert Insert;
|
||||
typedef typename Internal::iterator iterator;
|
||||
|
||||
template <typename Lookup>
|
||||
Result find(const Lookup &key) {
|
||||
@ -131,6 +132,10 @@ class HashMap : public AllocPolicy
|
||||
return table_.add(i);
|
||||
}
|
||||
|
||||
iterator iter() {
|
||||
return iterator(&table_);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
table_.clear();
|
||||
}
|
||||
@ -143,6 +148,17 @@ class HashMap : public AllocPolicy
|
||||
Internal table_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct PointerPolicy
|
||||
{
|
||||
static inline uint32_t hash(T *p) {
|
||||
return HashPointer(p);
|
||||
}
|
||||
static inline bool matches(T *p1, T *p2) {
|
||||
return p1 == p2;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // _include_amtl_hashmap_h_
|
||||
|
@ -472,7 +472,10 @@ class HashTable : public AllocPolicy
|
||||
table_->removeEntry(*i_);
|
||||
}
|
||||
|
||||
const Payload &operator *() const {
|
||||
Payload *operator ->() const {
|
||||
return &i_->payload();
|
||||
}
|
||||
Payload &operator *() const {
|
||||
return i_->payload();
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,7 @@ public:
|
||||
|
||||
typedef typename Internal::Result Result;
|
||||
typedef typename Internal::Insert Insert;
|
||||
typedef typename Internal::iterator iterator;
|
||||
|
||||
bool retrieve(const char *aKey, T *value)
|
||||
{
|
||||
@ -147,6 +148,11 @@ public:
|
||||
table_.clear();
|
||||
}
|
||||
|
||||
iterator iter()
|
||||
{
|
||||
return iterator(&table_);
|
||||
}
|
||||
|
||||
private:
|
||||
Internal table_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user