vkdoom_m/src/name.cpp
Randy Heit 01a41a6f13 - Made loading of Build's palette.dat automatic if it's found inside a loaded
group file, but the -bpal parameter remains for now.
- Made loading of Build art tiles automatic if they are found inside a group
  file. Removed the corresponding command-line parameter.
- Added support for Ken Silverman's group files.


SVN r72 (trunk)
2006-05-02 04:38:12 +00:00

74 lines
1.4 KiB
C++

#include <string.h>
#include "name.h"
#include "c_dispatch.h"
// Define the predefined names.
static const char *PredefinedNames[] =
{
#define xx(n) #n,
#include "namedef.h"
#undef xx
};
int name::Buckets[name::HASH_SIZE];
TArray<name::MainName> name::NameArray;
bool name::Inited;
name::MainName::MainName (int next)
: NextHash(next)
{
}
int name::FindName (const char *text, bool noCreate)
{
if (!Inited) InitBuckets ();
if (text == NULL)
{
return 0;
}
int hash = MakeKey (text) % HASH_SIZE;
int scanner = Buckets[hash];
// See if the name already exists.
while (scanner >= 0)
{
if (stricmp (NameArray[scanner].Text.GetChars(), text) == 0)
{
return scanner;
}
scanner = NameArray[scanner].NextHash;
}
// If we get here, then the name does not exist.
if (noCreate)
{
return 0;
}
// Assigning the string to the name after pushing it avoids needless
// manipulation of the string pool.
MainName entry (Buckets[hash]);
unsigned int index = NameArray.Push (entry);
NameArray[index].Text = text;
Buckets[hash] = index;
return index;
}
void name::InitBuckets ()
{
size_t i;
Inited = true;
for (i = 0; i < HASH_SIZE; ++i)
{
Buckets[i] = -1;
}
// Register built-in names. 'None' must be name 0.
for (i = 0; i < countof(PredefinedNames); ++i)
{
FindName (PredefinedNames[i], false);
}
}