mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +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()
|
SimNameDictionary::SimNameDictionary()
|
||||||
{
|
{
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
hashTable = NULL;
|
hashTable = NULL;
|
||||||
#endif
|
#endif
|
||||||
mutex = Mutex::createMutex();
|
mutex = Mutex::createMutex();
|
||||||
|
|
@ -38,7 +38,7 @@ SimNameDictionary::SimNameDictionary()
|
||||||
|
|
||||||
SimNameDictionary::~SimNameDictionary()
|
SimNameDictionary::~SimNameDictionary()
|
||||||
{
|
{
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
delete[] hashTable;
|
delete[] hashTable;
|
||||||
#endif
|
#endif
|
||||||
Mutex::destroyMutex(mutex);
|
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);
|
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);
|
Mutex::lockMutex(mutex);
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
if(!hashTable)
|
if(!hashTable)
|
||||||
{
|
{
|
||||||
hashTable = new SimObject *[DefaultTableSize];
|
hashTable = new SimObject *[DefaultTableSize];
|
||||||
|
|
@ -108,7 +108,7 @@ void SimNameDictionary::insert(SimObject* obj)
|
||||||
|
|
||||||
SimObject* SimNameDictionary::find(StringTableEntry name)
|
SimObject* SimNameDictionary::find(StringTableEntry name)
|
||||||
{
|
{
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
// NULL is a valid lookup - it will always return NULL
|
// NULL is a valid lookup - it will always return NULL
|
||||||
if(!hashTable)
|
if(!hashTable)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -143,7 +143,7 @@ void SimNameDictionary::remove(SimObject* obj)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Mutex::lockMutex(mutex);
|
Mutex::lockMutex(mutex);
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
||||||
while(*walk)
|
while(*walk)
|
||||||
{
|
{
|
||||||
|
|
@ -161,7 +161,7 @@ void SimNameDictionary::remove(SimObject* obj)
|
||||||
#else
|
#else
|
||||||
const char* name = StringTable->insert(obj->objectName);
|
const char* name = StringTable->insert(obj->objectName);
|
||||||
if (root[name])
|
if (root[name])
|
||||||
root.erase(name);
|
root.erase(name);
|
||||||
#endif
|
#endif
|
||||||
Mutex::unlockMutex(mutex);
|
Mutex::unlockMutex(mutex);
|
||||||
}
|
}
|
||||||
|
|
@ -170,7 +170,7 @@ void SimNameDictionary::remove(SimObject* obj)
|
||||||
|
|
||||||
SimManagerNameDictionary::SimManagerNameDictionary()
|
SimManagerNameDictionary::SimManagerNameDictionary()
|
||||||
{
|
{
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
hashTable = new SimObject *[DefaultTableSize];
|
hashTable = new SimObject *[DefaultTableSize];
|
||||||
hashTableSize = DefaultTableSize;
|
hashTableSize = DefaultTableSize;
|
||||||
hashEntryCount = 0;
|
hashEntryCount = 0;
|
||||||
|
|
@ -182,7 +182,7 @@ SimManagerNameDictionary::SimManagerNameDictionary()
|
||||||
|
|
||||||
SimManagerNameDictionary::~SimManagerNameDictionary()
|
SimManagerNameDictionary::~SimManagerNameDictionary()
|
||||||
{
|
{
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
delete[] hashTable;
|
delete[] hashTable;
|
||||||
#endif
|
#endif
|
||||||
Mutex::destroyMutex(mutex);
|
Mutex::destroyMutex(mutex);
|
||||||
|
|
@ -194,7 +194,7 @@ void SimManagerNameDictionary::insert(SimObject* obj)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Mutex::lockMutex(mutex);
|
Mutex::lockMutex(mutex);
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
S32 idx = HashPointer(obj->objectName) % hashTableSize;
|
S32 idx = HashPointer(obj->objectName) % hashTableSize;
|
||||||
obj->nextManagerNameObject = hashTable[idx];
|
obj->nextManagerNameObject = hashTable[idx];
|
||||||
hashTable[idx] = obj;
|
hashTable[idx] = obj;
|
||||||
|
|
@ -242,7 +242,7 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
|
||||||
|
|
||||||
Mutex::lockMutex(mutex);
|
Mutex::lockMutex(mutex);
|
||||||
|
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
S32 idx = HashPointer(name) % hashTableSize;
|
S32 idx = HashPointer(name) % hashTableSize;
|
||||||
SimObject *walk = hashTable[idx];
|
SimObject *walk = hashTable[idx];
|
||||||
while(walk)
|
while(walk)
|
||||||
|
|
@ -258,7 +258,7 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
#else
|
#else
|
||||||
SimObject* f = root[StringTable->insert(name)];
|
SimObject* f = root[StringTable->insert(name)];
|
||||||
Mutex::unlockMutex(mutex);
|
Mutex::unlockMutex(mutex);
|
||||||
return f;
|
return f;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -269,7 +269,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
||||||
if(!obj->objectName)
|
if(!obj->objectName)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
Mutex::lockMutex(mutex);
|
Mutex::lockMutex(mutex);
|
||||||
|
|
||||||
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
|
||||||
|
|
@ -287,10 +287,9 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
||||||
walk = &((*walk)->nextManagerNameObject);
|
walk = &((*walk)->nextManagerNameObject);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
const char* name = StringTable->insert(obj->objectName);
|
||||||
const char* name = StringTable->insert(obj->objectName);
|
if (root[name])
|
||||||
if (root[name])
|
root.erase(name);
|
||||||
root.erase(name);
|
|
||||||
#endif
|
#endif
|
||||||
Mutex::unlockMutex(mutex);
|
Mutex::unlockMutex(mutex);
|
||||||
}
|
}
|
||||||
|
|
@ -300,7 +299,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
|
||||||
|
|
||||||
SimIdDictionary::SimIdDictionary()
|
SimIdDictionary::SimIdDictionary()
|
||||||
{
|
{
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
dMemset( table, 0, sizeof( table[ 0 ] ) * DefaultTableSize );
|
dMemset( table, 0, sizeof( table[ 0 ] ) * DefaultTableSize );
|
||||||
#endif
|
#endif
|
||||||
mutex = Mutex::createMutex();
|
mutex = Mutex::createMutex();
|
||||||
|
|
@ -316,7 +315,7 @@ SimIdDictionary::~SimIdDictionary()
|
||||||
void SimIdDictionary::insert(SimObject* obj)
|
void SimIdDictionary::insert(SimObject* obj)
|
||||||
{
|
{
|
||||||
Mutex::lockMutex(mutex);
|
Mutex::lockMutex(mutex);
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
S32 idx = obj->getId() & TableBitMask;
|
S32 idx = obj->getId() & TableBitMask;
|
||||||
obj->nextIdObject = table[idx];
|
obj->nextIdObject = table[idx];
|
||||||
AssertFatal( obj->nextIdObject != obj, "SimIdDictionary::insert - Creating Infinite Loop linking to self!" );
|
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)
|
SimObject* SimIdDictionary::find(S32 id)
|
||||||
{
|
{
|
||||||
Mutex::lockMutex(mutex);
|
Mutex::lockMutex(mutex);
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
S32 idx = id & TableBitMask;
|
S32 idx = id & TableBitMask;
|
||||||
SimObject *walk = table[idx];
|
SimObject *walk = table[idx];
|
||||||
while(walk)
|
while(walk)
|
||||||
|
|
@ -355,7 +354,7 @@ SimObject* SimIdDictionary::find(S32 id)
|
||||||
void SimIdDictionary::remove(SimObject* obj)
|
void SimIdDictionary::remove(SimObject* obj)
|
||||||
{
|
{
|
||||||
Mutex::lockMutex(mutex);
|
Mutex::lockMutex(mutex);
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
SimObject **walk = &table[obj->getId() & TableBitMask];
|
SimObject **walk = &table[obj->getId() & TableBitMask];
|
||||||
while(*walk && *walk != obj)
|
while(*walk && *walk != obj)
|
||||||
walk = &((*walk)->nextIdObject);
|
walk = &((*walk)->nextIdObject);
|
||||||
|
|
|
||||||
|
|
@ -35,38 +35,32 @@
|
||||||
|
|
||||||
#include "torqueConfig.h"
|
#include "torqueConfig.h"
|
||||||
|
|
||||||
#ifndef USE_CLASSIC_SIMDICTIONARY
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class SimObject;
|
class SimObject;
|
||||||
|
|
||||||
|
#ifdef USE_NEW_SIMDICTIONARY
|
||||||
#ifndef USE_CLASSIC_SIMDICTIONARY
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "core/strings/stringFunctions.h"
|
#include "core/strings/stringFunctions.h"
|
||||||
|
|
||||||
struct DictionaryHash
|
struct DictionaryHash
|
||||||
{
|
{
|
||||||
inline size_t operator()(const char* val) const
|
inline size_t operator()(const char* val) const
|
||||||
{
|
{
|
||||||
return (long)val;
|
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
|
struct eqstr
|
||||||
typedef std::unordered_map<const char * , SimObject*, DictionaryHash, eqstr> StringDictDef;
|
{
|
||||||
typedef std::unordered_map<U32 ,SimObject*> U32DictDef;
|
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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -78,7 +72,7 @@ typedef std::unordered_map<U32 ,SimObject*> U32DictDef;
|
||||||
/// for fast removal of an object given object*
|
/// for fast removal of an object given object*
|
||||||
class SimNameDictionary
|
class SimNameDictionary
|
||||||
{
|
{
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
DefaultTableSize = 29
|
DefaultTableSize = 29
|
||||||
|
|
@ -90,10 +84,9 @@ class SimNameDictionary
|
||||||
#else
|
#else
|
||||||
StringDictDef root;
|
StringDictDef root;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *mutex;
|
void *mutex;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void insert(SimObject* obj);
|
void insert(SimObject* obj);
|
||||||
void remove(SimObject* obj);
|
void remove(SimObject* obj);
|
||||||
|
|
@ -105,7 +98,7 @@ public:
|
||||||
|
|
||||||
class SimManagerNameDictionary
|
class SimManagerNameDictionary
|
||||||
{
|
{
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
DefaultTableSize = 29
|
DefaultTableSize = 29
|
||||||
|
|
@ -114,15 +107,12 @@ class SimManagerNameDictionary
|
||||||
SimObject **hashTable; // hash the pointers of the names...
|
SimObject **hashTable; // hash the pointers of the names...
|
||||||
S32 hashTableSize;
|
S32 hashTableSize;
|
||||||
S32 hashEntryCount;
|
S32 hashEntryCount;
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
StringDictDef root;
|
StringDictDef root;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *mutex;
|
void *mutex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void insert(SimObject* obj);
|
void insert(SimObject* obj);
|
||||||
void remove(SimObject* obj);
|
void remove(SimObject* obj);
|
||||||
|
|
@ -139,7 +129,7 @@ public:
|
||||||
/// for fast removal of an object given object*
|
/// for fast removal of an object given object*
|
||||||
class SimIdDictionary
|
class SimIdDictionary
|
||||||
{
|
{
|
||||||
#ifdef USE_CLASSIC_SIMDICTIONARY
|
#ifndef USE_NEW_SIMDICTIONARY
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
DefaultTableSize = 4096,
|
DefaultTableSize = 4096,
|
||||||
|
|
@ -149,6 +139,7 @@ class SimIdDictionary
|
||||||
#else
|
#else
|
||||||
U32DictDef root;
|
U32DictDef root;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *mutex;
|
void *mutex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,6 @@
|
||||||
//general, the information here is global for your entire codebase, applying
|
//general, the information here is global for your entire codebase, applying
|
||||||
//not only to your game proper, but also to all of your tools.
|
//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.
|
/// What's the name of your application? Used in a variety of places.
|
||||||
#define TORQUE_APP_NAME "Empty"
|
#define TORQUE_APP_NAME "Empty"
|
||||||
|
|
||||||
|
|
@ -59,6 +52,11 @@
|
||||||
#define TORQUE_DISABLE_MEMORY_MANAGER
|
#define TORQUE_DISABLE_MEMORY_MANAGER
|
||||||
#endif
|
#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 me if you want to disable the virtual mount system.
|
||||||
//#define TORQUE_DISABLE_VIRTUAL_MOUNT_SYSTEM
|
//#define TORQUE_DISABLE_VIRTUAL_MOUNT_SYSTEM
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,6 @@
|
||||||
//general, the information here is global for your entire codebase, applying
|
//general, the information here is global for your entire codebase, applying
|
||||||
//not only to your game proper, but also to all of your tools.
|
//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.
|
/// What's the name of your application? Used in a variety of places.
|
||||||
#define TORQUE_APP_NAME "Full"
|
#define TORQUE_APP_NAME "Full"
|
||||||
|
|
||||||
|
|
@ -59,6 +52,11 @@
|
||||||
#define TORQUE_DISABLE_MEMORY_MANAGER
|
#define TORQUE_DISABLE_MEMORY_MANAGER
|
||||||
#endif
|
#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 me if you want to disable the virtual mount system.
|
||||||
//#define TORQUE_DISABLE_VIRTUAL_MOUNT_SYSTEM
|
//#define TORQUE_DISABLE_VIRTUAL_MOUNT_SYSTEM
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue