Switch TopMenus off KTrie (bug 5884 part 16, r=ds).

This commit is contained in:
David Anderson 2013-08-25 12:20:38 -07:00
parent 8e99b342a4
commit 51dc097266
3 changed files with 20 additions and 30 deletions

View File

@ -1,5 +1,5 @@
/**
* vim: set ts=4 :
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod TopMenus Extension
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
@ -169,7 +169,7 @@ unsigned int TopMenu::AddToMenu2(const char *name,
{
return 0;
}
else if (m_ObjLookup.retrieve(name) != NULL)
else if (m_ObjLookup.contains(name))
{
return 0;
}
@ -483,13 +483,8 @@ void TopMenu::OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsi
topmenu_object_t *obj;
topmenu_player_t *pClient = &m_clients[client];
topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name);
if (pObject == NULL)
{
if (!m_ObjLookup.retrieve(item_name, &obj))
return;
}
obj = *pObject;
/* We now have the object... what do we do with it? */
if (obj->type == TopMenuObject_Category)
@ -532,13 +527,8 @@ void TopMenu::OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, uns
}
topmenu_object_t *obj;
topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name);
if (pObject == NULL)
{
if (!m_ObjLookup.retrieve(item_name, &obj))
return;
}
obj = *pObject;
/* If the category has nothing to display, disable it. */
if (obj->type == TopMenuObject_Category)
@ -583,13 +573,8 @@ unsigned int TopMenu::OnMenuDisplayItem(IBaseMenu *menu,
}
topmenu_object_t *obj;
topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name);
if (pObject == NULL)
{
if (!m_ObjLookup.retrieve(item_name, &obj))
return 0;
}
obj = *pObject;
/* Ask the object to render the text for this client */
char renderbuf[64];
@ -1134,17 +1119,12 @@ SMCResult TopMenu::ReadSMC_LeavingSection(const SMCStates *states)
unsigned int TopMenu::FindCategory(const char *name)
{
topmenu_object_t **p_obj = m_ObjLookup.retrieve(name);
if (!p_obj)
{
topmenu_object_t *obj;
if (!m_ObjLookup.retrieve(name, &obj))
return 0;
}
topmenu_object_t *obj = *p_obj;
if (obj->type != TopMenuObject_Category)
{
return 0;
}
return obj->object_id;
}

View File

@ -1,5 +1,5 @@
/**
* vim: set ts=4 :
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod TopMenus Extension
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
@ -34,10 +34,10 @@
#include <sh_list.h>
#include <sh_vector.h>
#include <sm_trie_tpl.h>
#include <ITopMenus.h>
#include "smsdk_ext.h"
#include "sm_memtable.h"
#include <sm_namehashset.h>
using namespace SourceHook;
using namespace SourceMod;
@ -72,6 +72,11 @@ struct topmenu_object_t
bool is_free; /** Free or not? */
char info[255]; /** Info string */
unsigned int cat_id; /** Set if a category */
static inline bool matches(const char *name, const topmenu_object_t *topmenu)
{
return strcmp(name, topmenu->name) == 0;
}
};
struct topmenu_category_t
@ -173,7 +178,7 @@ private:
CVector<unsigned int> m_UnsortedCats; /* Un-sorted categories */
CVector<topmenu_category_t *> m_Categories; /* Category array */
CVector<topmenu_object_t *> m_Objects; /* Object array */
KTrie<topmenu_object_t *> m_ObjLookup; /* Object lookup trie */
NameHashSet<topmenu_object_t *> m_ObjLookup; /* Object lookup trie */
unsigned int m_SerialNo; /* Serial number for updating */
ITopMenuObjectCallbacks *m_pTitle; /* Title callbacks */
int m_max_clients; /* Maximum number of clients */

View File

@ -148,6 +148,11 @@ public:
table_.clear();
}
size_t mem_usage() const
{
return table_.estimateMemoryUse();
}
iterator iter()
{
return iterator(&table_);