mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 06:34:36 +00:00
Improvements to SimDictionary for when you have a large number of objects in the game. Under light load (i.e. under 5000 objects) this code actually runs slower that the stock simdictionary. When you exceed 5000 objects, the template class actually runs faster and more consistently.
This commit is contained in:
parent
378a933894
commit
a91e5a2590
4 changed files with 116 additions and 17 deletions
|
|
@ -33,8 +33,37 @@
|
|||
#include "platform/threads/mutex.h"
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "TorqueConfig.h"
|
||||
|
||||
|
||||
class SimObject;
|
||||
|
||||
#include "core/strings/stringFunctions.h"
|
||||
|
||||
struct my_hash {
|
||||
inline size_t operator()(const char* val) const
|
||||
{
|
||||
return (long)val;
|
||||
}
|
||||
};
|
||||
|
||||
struct eqstr {
|
||||
inline bool operator()(const char *s1, const char *s2) const {
|
||||
return dStrcmp(s1, s2) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifndef USE_CLASSIC_SIMDICTIONARY
|
||||
typedef std::unordered_map<const char * , SimObject*, my_hash, eqstr> StringDictDef;
|
||||
typedef std::unordered_map<U32 ,SimObject*> U32DictDef;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// Map of names to SimObjects
|
||||
///
|
||||
|
|
@ -42,6 +71,7 @@ class SimObject;
|
|||
/// for fast removal of an object given object*
|
||||
class SimNameDictionary
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
enum
|
||||
{
|
||||
DefaultTableSize = 29
|
||||
|
|
@ -50,9 +80,13 @@ class SimNameDictionary
|
|||
SimObject **hashTable; // hash the pointers of the names...
|
||||
S32 hashTableSize;
|
||||
S32 hashEntryCount;
|
||||
|
||||
#else
|
||||
StringDictDef root;
|
||||
#endif
|
||||
void *mutex;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
void insert(SimObject* obj);
|
||||
void remove(SimObject* obj);
|
||||
|
|
@ -64,6 +98,7 @@ public:
|
|||
|
||||
class SimManagerNameDictionary
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
enum
|
||||
{
|
||||
DefaultTableSize = 29
|
||||
|
|
@ -73,8 +108,14 @@ class SimManagerNameDictionary
|
|||
S32 hashTableSize;
|
||||
S32 hashEntryCount;
|
||||
|
||||
void *mutex;
|
||||
|
||||
#else
|
||||
|
||||
|
||||
StringDictDef root;
|
||||
|
||||
#endif
|
||||
void *mutex;
|
||||
public:
|
||||
void insert(SimObject* obj);
|
||||
void remove(SimObject* obj);
|
||||
|
|
@ -91,13 +132,16 @@ public:
|
|||
/// for fast removal of an object given object*
|
||||
class SimIdDictionary
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
enum
|
||||
{
|
||||
DefaultTableSize = 4096,
|
||||
TableBitMask = 4095
|
||||
};
|
||||
SimObject *table[DefaultTableSize];
|
||||
|
||||
#else
|
||||
U32DictDef root;
|
||||
#endif
|
||||
void *mutex;
|
||||
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue