mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-01 18:45:13 +00:00
Tweaks so I'm happy with it.
* Change #define usage * Fix tabs
This commit is contained in:
parent
26c5451593
commit
116276a105
4 changed files with 54 additions and 68 deletions
|
|
@ -30,7 +30,7 @@ extern U32 HashPointer(StringTableEntry e);
|
|||
|
||||
SimNameDictionary::SimNameDictionary()
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
hashTable = NULL;
|
||||
#endif
|
||||
mutex = Mutex::createMutex();
|
||||
|
|
@ -38,7 +38,7 @@ SimNameDictionary::SimNameDictionary()
|
|||
|
||||
SimNameDictionary::~SimNameDictionary()
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
delete[] hashTable;
|
||||
#endif
|
||||
Mutex::destroyMutex(mutex);
|
||||
|
|
@ -55,7 +55,7 @@ void SimNameDictionary::insert(SimObject* obj)
|
|||
Con::warnf("Warning! You have a duplicate datablock name of %s. This can cause problems. You should rename one of them.", obj->objectName);
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
if(!hashTable)
|
||||
{
|
||||
hashTable = new SimObject *[DefaultTableSize];
|
||||
|
|
@ -108,7 +108,7 @@ void SimNameDictionary::insert(SimObject* obj)
|
|||
|
||||
SimObject* SimNameDictionary::find(StringTableEntry name)
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
// NULL is a valid lookup - it will always return NULL
|
||||
if(!hashTable)
|
||||
return NULL;
|
||||
|
|
@ -143,7 +143,7 @@ void SimNameDictionary::remove(SimObject* obj)
|
|||
return;
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
||||
while(*walk)
|
||||
{
|
||||
|
|
@ -161,7 +161,7 @@ void SimNameDictionary::remove(SimObject* obj)
|
|||
#else
|
||||
const char* name = StringTable->insert(obj->objectName);
|
||||
if (root[name])
|
||||
root.erase(name);
|
||||
root.erase(name);
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ void SimNameDictionary::remove(SimObject* obj)
|
|||
|
||||
SimManagerNameDictionary::SimManagerNameDictionary()
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
hashTable = new SimObject *[DefaultTableSize];
|
||||
hashTableSize = DefaultTableSize;
|
||||
hashEntryCount = 0;
|
||||
|
|
@ -182,7 +182,7 @@ SimManagerNameDictionary::SimManagerNameDictionary()
|
|||
|
||||
SimManagerNameDictionary::~SimManagerNameDictionary()
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
delete[] hashTable;
|
||||
#endif
|
||||
Mutex::destroyMutex(mutex);
|
||||
|
|
@ -194,7 +194,7 @@ void SimManagerNameDictionary::insert(SimObject* obj)
|
|||
return;
|
||||
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = HashPointer(obj->objectName) % hashTableSize;
|
||||
obj->nextManagerNameObject = hashTable[idx];
|
||||
hashTable[idx] = obj;
|
||||
|
|
@ -242,7 +242,7 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
|
|||
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = HashPointer(name) % hashTableSize;
|
||||
SimObject *walk = hashTable[idx];
|
||||
while(walk)
|
||||
|
|
@ -258,7 +258,7 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
|
|||
|
||||
return NULL;
|
||||
#else
|
||||
SimObject* f = root[StringTable->insert(name)];
|
||||
SimObject* f = root[StringTable->insert(name)];
|
||||
Mutex::unlockMutex(mutex);
|
||||
return f;
|
||||
#endif
|
||||
|
|
@ -269,7 +269,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
|||
if(!obj->objectName)
|
||||
return;
|
||||
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
Mutex::lockMutex(mutex);
|
||||
|
||||
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
||||
|
|
@ -287,10 +287,9 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
|||
walk = &((*walk)->nextManagerNameObject);
|
||||
}
|
||||
#else
|
||||
|
||||
const char* name = StringTable->insert(obj->objectName);
|
||||
if (root[name])
|
||||
root.erase(name);
|
||||
const char* name = StringTable->insert(obj->objectName);
|
||||
if (root[name])
|
||||
root.erase(name);
|
||||
#endif
|
||||
Mutex::unlockMutex(mutex);
|
||||
}
|
||||
|
|
@ -300,7 +299,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
|||
|
||||
SimIdDictionary::SimIdDictionary()
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
dMemset( table, 0, sizeof( table[ 0 ] ) * DefaultTableSize );
|
||||
#endif
|
||||
mutex = Mutex::createMutex();
|
||||
|
|
@ -316,7 +315,7 @@ SimIdDictionary::~SimIdDictionary()
|
|||
void SimIdDictionary::insert(SimObject* obj)
|
||||
{
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = obj->getId() & TableBitMask;
|
||||
obj->nextIdObject = table[idx];
|
||||
AssertFatal( obj->nextIdObject != obj, "SimIdDictionary::insert - Creating Infinite Loop linking to self!" );
|
||||
|
|
@ -330,7 +329,7 @@ void SimIdDictionary::insert(SimObject* obj)
|
|||
SimObject* SimIdDictionary::find(S32 id)
|
||||
{
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
S32 idx = id & TableBitMask;
|
||||
SimObject *walk = table[idx];
|
||||
while(walk)
|
||||
|
|
@ -355,7 +354,7 @@ SimObject* SimIdDictionary::find(S32 id)
|
|||
void SimIdDictionary::remove(SimObject* obj)
|
||||
{
|
||||
Mutex::lockMutex(mutex);
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
SimObject **walk = &table[obj->getId() & TableBitMask];
|
||||
while(*walk && *walk != obj)
|
||||
walk = &((*walk)->nextIdObject);
|
||||
|
|
|
|||
|
|
@ -35,38 +35,32 @@
|
|||
|
||||
#include "torqueConfig.h"
|
||||
|
||||
#ifndef USE_CLASSIC_SIMDICTIONARY
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#endif
|
||||
|
||||
class SimObject;
|
||||
|
||||
|
||||
#ifndef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifdef USE_NEW_SIMDICTIONARY
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "core/strings/stringFunctions.h"
|
||||
|
||||
struct DictionaryHash
|
||||
struct DictionaryHash
|
||||
{
|
||||
inline size_t operator()(const char* val) const
|
||||
{
|
||||
return (long)val;
|
||||
}
|
||||
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;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef USE_CLASSIC_SIMDICTIONARY
|
||||
typedef std::unordered_map<const char * , SimObject*, DictionaryHash, eqstr> StringDictDef;
|
||||
typedef std::unordered_map<U32 ,SimObject*> U32DictDef;
|
||||
struct eqstr
|
||||
{
|
||||
inline bool operator()(const char *s1, const char *s2) const
|
||||
{
|
||||
return dStrcmp(s1, s2) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::unordered_map<const char *, SimObject*, DictionaryHash, eqstr> StringDictDef;
|
||||
typedef std::unordered_map<U32, SimObject*> U32DictDef;
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -78,7 +72,7 @@ typedef std::unordered_map<U32 ,SimObject*> U32DictDef;
|
|||
/// for fast removal of an object given object*
|
||||
class SimNameDictionary
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
enum
|
||||
{
|
||||
DefaultTableSize = 29
|
||||
|
|
@ -90,10 +84,9 @@ class SimNameDictionary
|
|||
#else
|
||||
StringDictDef root;
|
||||
#endif
|
||||
|
||||
void *mutex;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
void insert(SimObject* obj);
|
||||
void remove(SimObject* obj);
|
||||
|
|
@ -105,7 +98,7 @@ public:
|
|||
|
||||
class SimManagerNameDictionary
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
enum
|
||||
{
|
||||
DefaultTableSize = 29
|
||||
|
|
@ -114,15 +107,12 @@ class SimManagerNameDictionary
|
|||
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);
|
||||
|
|
@ -139,7 +129,7 @@ public:
|
|||
/// for fast removal of an object given object*
|
||||
class SimIdDictionary
|
||||
{
|
||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
||||
#ifndef USE_NEW_SIMDICTIONARY
|
||||
enum
|
||||
{
|
||||
DefaultTableSize = 4096,
|
||||
|
|
@ -149,6 +139,7 @@ class SimIdDictionary
|
|||
#else
|
||||
U32DictDef root;
|
||||
#endif
|
||||
|
||||
void *mutex;
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -31,13 +31,6 @@
|
|||
//general, the information here is global for your entire codebase, applying
|
||||
//not only to your game proper, but also to all of your tools.
|
||||
|
||||
//If you plan to have less than 5000 objects use the Classic SimDictionary, if you plan to have more than
|
||||
//5000 objects use the new SimDictionary.
|
||||
|
||||
//The improved SIMDICTIONARY uses C++ 11 and is designed for games where
|
||||
//there are over 10000 simobjects active normally.
|
||||
//To enable the new SIMDICTIONARY just comment out the line below.
|
||||
#define USE_CLASSIC_SIMDICTIONARY
|
||||
/// What's the name of your application? Used in a variety of places.
|
||||
#define TORQUE_APP_NAME "Empty"
|
||||
|
||||
|
|
@ -59,6 +52,11 @@
|
|||
#define TORQUE_DISABLE_MEMORY_MANAGER
|
||||
#endif
|
||||
|
||||
/// The improved SimDictionary uses C++11 and is designed for games where
|
||||
/// there are over 10000 simobjects active normally. To enable the new
|
||||
/// SimDictionary just uncomment the line below.
|
||||
//#define USE_NEW_SIMDICTIONARY
|
||||
|
||||
/// Define me if you want to disable the virtual mount system.
|
||||
//#define TORQUE_DISABLE_VIRTUAL_MOUNT_SYSTEM
|
||||
|
||||
|
|
|
|||
|
|
@ -31,13 +31,6 @@
|
|||
//general, the information here is global for your entire codebase, applying
|
||||
//not only to your game proper, but also to all of your tools.
|
||||
|
||||
//If you plan to have less than 5000 objects use the Classic SimDictionary, if you plan to have more than
|
||||
//5000 objects use the new SimDictionary.
|
||||
|
||||
//The improved SIMDICTIONARY uses C++ 11 and is designed for games where
|
||||
//there are over 10000 simobjects active normally.
|
||||
//To enable the new SIMDICTIONARY just comment out the line below.
|
||||
#define USE_CLASSIC_SIMDICTIONARY
|
||||
/// What's the name of your application? Used in a variety of places.
|
||||
#define TORQUE_APP_NAME "Full"
|
||||
|
||||
|
|
@ -59,6 +52,11 @@
|
|||
#define TORQUE_DISABLE_MEMORY_MANAGER
|
||||
#endif
|
||||
|
||||
/// The improved SimDictionary uses C++11 and is designed for games where
|
||||
/// there are over 10000 simobjects active normally. To enable the new
|
||||
/// SimDictionary just uncomment the line below.
|
||||
//#define USE_NEW_SIMDICTIONARY
|
||||
|
||||
/// Define me if you want to disable the virtual mount system.
|
||||
//#define TORQUE_DISABLE_VIRTUAL_MOUNT_SYSTEM
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue