Navigation Menu

Skip to content

Commit

Permalink
Refactor: Use the C++ interface to StringPool with the (map) entityDefs
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 6, 2012
1 parent 917bd40 commit 9001b4c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions doomsday/engine/portable/src/p_data.cpp
Expand Up @@ -49,7 +49,7 @@
using de::FS1;

// Map entity definitions.
static StringPool* entityDefs;
static de::StringPool* entityDefs;
typedef std::map<int, StringPoolId> EntityDefIdMap;
static EntityDefIdMap entityDefIdMap;

Expand Down Expand Up @@ -264,7 +264,7 @@ boolean P_LoadMap(const char* uriCString)

static int clearEntityDefsWorker(StringPoolId id, void* /*parameters*/)
{
MapEntityDef* def = static_cast<MapEntityDef*>( StringPool_UserPointer(entityDefs, id) );
MapEntityDef* def = static_cast<MapEntityDef*>( entityDefs->userPointer(id) );
DENG2_ASSERT(def);
for(uint k = 0; k < def->numProps; ++k)
{
Expand All @@ -280,8 +280,8 @@ static void clearEntityDefs(void)
{
if(!entityDefs) return;

StringPool_Iterate(entityDefs, clearEntityDefsWorker, 0/*no parameters*/);
StringPool_Delete(entityDefs); entityDefs = 0;
entityDefs->iterate(clearEntityDefsWorker, 0/*no parameters*/);
delete entityDefs; entityDefs = 0;
entityDefIdMap.clear();
}

Expand All @@ -291,7 +291,7 @@ MapEntityDef* P_MapEntityDef(int id)
if(i != entityDefIdMap.end())
{
StringPoolId id = i->second;
return static_cast<MapEntityDef*>( StringPool_UserPointer(entityDefs, id) );
return static_cast<MapEntityDef*>( entityDefs->userPointer(id) );
}
return 0; // Not found.
}
Expand All @@ -302,25 +302,25 @@ MapEntityDef* P_MapEntityDefByName(char const* _name)
{
ddstring_t name;
Str_InitStatic(&name, _name);
StringPoolId id = StringPool_IsInterned(entityDefs, &name);
return static_cast<MapEntityDef*>( StringPool_UserPointer(entityDefs, id) );
StringPoolId id = entityDefs->isInterned(&name);
return static_cast<MapEntityDef*>( entityDefs->userPointer(id) );
}
return 0; // Not found.
}

static int P_NameForMapEntityDefWorker(StringPoolId id, void* parameters)
{
MapEntityDef* def = static_cast<MapEntityDef*>( parameters );
if(StringPool_UserPointer(entityDefs, id) == def) return id;
if(entityDefs->userPointer(id) == def) return id;
return 0; // Continue iteration.
}

Str const* P_NameForMapEntityDef(MapEntityDef* def)
{
if(def)
{
StringPoolId id = StringPool_Iterate(entityDefs, P_NameForMapEntityDefWorker, def);
return StringPool_String(entityDefs, id);
StringPoolId id = entityDefs->iterate(P_NameForMapEntityDefWorker, def);
return entityDefs->string(id);
}
static de::Str zeroLengthString;
return zeroLengthString;
Expand Down Expand Up @@ -464,13 +464,13 @@ static MapEntityDef* findMapEntityDef(int identifier, const char* entityName, bo
// Have we yet to initialize the map entity definition dataset?
if(!entityDefs)
{
entityDefs = StringPool_New();
entityDefs = new de::StringPool;
}

Str name; Str_InitStatic(&name, entityName);
StringPoolId id = StringPool_Intern(entityDefs, &name);
StringPoolId id = entityDefs->intern(&name);
MapEntityDef* def = new MapEntityDef(identifier);
StringPool_SetUserPointer(entityDefs, id, def);
entityDefs->setUserPointer(id, def);

entityDefIdMap.insert(std::pair<int, StringPoolId>(identifier, id));

Expand Down

0 comments on commit 9001b4c

Please sign in to comment.