Navigation Menu

Skip to content

Commit

Permalink
Refactor|EntityDatabase: EntityDatabase now a C++ class; allocated wi…
Browse files Browse the repository at this point in the history
…th Map
  • Loading branch information
danij-deng committed Jun 9, 2013
1 parent 70d4f75 commit f2b26fe
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 222 deletions.
102 changes: 61 additions & 41 deletions doomsday/client/include/world/entitydatabase.h
@@ -1,19 +1,6 @@
/**
* @file entitydatabase.h
* Entity property value database. @ingroup world
/** @file world/entitydatabase.h World entity property database.
*
* The EntityDatabase is used in the process of transferring mobj spawn spot
* information and stuff like line action specials from the wad map loader
* plugin via the engine, through to the game plugin.
*
* The primary reason for its existence is that the engine does not know about
* the game specific properties of the map data types. The engine does not care
* at all about the values or indeed even what properties are registered; it is
* simply a way of piping information from one part of the system to another.
*
* @todo C++ allows making this even more generic: a set/map of polymorphic objects.
*
* @author Copyright &copy; 2007-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2007-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -30,43 +17,76 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_MAP_ENTITYDATABASE_H
#define LIBDENG_MAP_ENTITYDATABASE_H
#ifndef DENG_WORLD_ENTITYDATABASE_H
#define DENG_WORLD_ENTITYDATABASE_H

#include "api_mapedit.h" // valuetype_t
#include <de/libdeng2.h>
#include <de/Error>

#ifdef __cplusplus
class PropertyValue;
#include "api_mapedit.h" // valuetype_t
#include "world/propertyvalue.h"
#include "world/p_mapdata.h"

extern "C" {
#endif
namespace de {

/**
* C Wrapper API:
* An EntityDatabase is used in the process of transferring mobj spawn spot
* information and stuff like line action specials from the wad map loader
* plugin via the engine, through to the game plugin.
*
* The primary reason for its existence is that the engine does not know about
* the game specific properties of the map data types. The engine does not care
* at all about the values or indeed even what properties are registered; it is
* simply a way of piping information from one part of the system to another.
*
* @todo C++ allows making this more generic: a set/map of polymorphic objects
* e.g., QVariant.
*/
class EntityDatabase
{
public:
EntityDatabase();

struct mapentitydef_s;
struct mapentitypropertydef_s;

struct entitydatabase_s;
typedef struct entitydatabase_s EntityDatabase;

EntityDatabase* EntityDatabase_New(void);
/// @return Total number of entities by definition @a entityDef.
uint entityCount(MapEntityDef const *entityDef);

void EntityDatabase_Delete(EntityDatabase* db);
/**
* Returns @c true iff an entity with definition @a entityDef and
* @a elementIndex is known/present.
*/
bool hasEntity(MapEntityDef const *entityDef, int elementIndex);

uint EntityDatabase_EntityCount(EntityDatabase* db, struct mapentitydef_s* entityDef);
/**
* Lookup a known entity element property value in the database.
*
* @param def Definition of the property to lookup an element value for.
* @param elementIndex Unique element index of the value to lookup.
*
* @return The found PropertyValue.
*/
PropertyValue const &property(MapEntityPropertyDef const *def, int elementIndex);

boolean EntityDatabase_HasEntity(EntityDatabase* db, struct mapentitydef_s* entityDef, int elementIndex);
/**
* Replace/add a value for a known entity element property to the database.
*
* @param def Definition of the property to add an element value for.
* @param elementIndex Unique element index for the value.
* @param value The new PropertyValue. Ownership passes to this database.
*/
void setProperty(MapEntityPropertyDef const *def, int elementIndex,
PropertyValue *value);

#ifdef __cplusplus
PropertyValue const* EntityDatabase_Property(EntityDatabase* db, struct mapentitypropertydef_s* propertyDef, int elementIndex);
#endif
/// @copydoc setProperty
inline void setProperty(MapEntityPropertyDef const *def, int elementIndex,
valuetype_t valueType, void *valueAdr)
{
setProperty(def, elementIndex, BuildPropertyValue(valueType, valueAdr));
}

boolean EntityDatabase_SetProperty(EntityDatabase* db, struct mapentitypropertydef_s* propertyDef, int elementIndex, valuetype_t valueType, void* valueAdr);
private:
DENG2_PRIVATE(d)
};

#ifdef __cplusplus
} // extern "C"
#endif
} // namespace de

#endif // LIBDENG_MAP_ENTITYDATABASE_H
#endif // DENG_WORLD_ENTITYDATABASE_H
7 changes: 3 additions & 4 deletions doomsday/client/include/world/map.h
Expand Up @@ -24,7 +24,6 @@
#include <QList>
#include <QSet>

#include "EntityDatabase"
#include "m_nodepile.h"
#include "p_particle.h"
#include "Polyobj"
Expand Down Expand Up @@ -69,6 +68,7 @@ struct clpolyobj_s;

namespace de {

class EntityDatabase;
#ifdef __CLIENT__
class LightGrid;
#endif
Expand Down Expand Up @@ -131,9 +131,6 @@ class Map
struct clpolyobj_s *clActivePolyobjs[CLIENT_MAX_MOVERS];
#endif

/// Map entities and element properties (things, line specials, etc...).
EntityDatabase *entityDatabase;

public:
nodepile_t mobjNodes, lineNodes; // All kinds of wacky links.
nodeindex_t *lineLinks; // Indices to roots.
Expand Down Expand Up @@ -480,6 +477,8 @@ class Map
*/
void unlinkPolyobj(Polyobj &polyobj);

EntityDatabase &entityDatabase() const;

/**
* Retrieve a pointer to the Generators collection for the map. If no collection
* has yet been constructed a new empty collection will be initialized.
Expand Down
13 changes: 0 additions & 13 deletions doomsday/client/include/world/p_mapdata.h
Expand Up @@ -116,19 +116,6 @@ MapEntityDef *P_MapEntityDefByName(char const *name);
*/
AutoStr *P_NameForMapEntityDef(MapEntityDef *def);

#ifdef __cplusplus
} // extern "C"
#endif

#include "../EntityDatabase"

#ifdef __cplusplus
extern "C" {
#endif

boolean P_SetMapEntityProperty(EntityDatabase *db, MapEntityPropertyDef *propertyDef,
int elementIndex, valuetype_t valueType, void* valueAdr);

/**
* To be called to initialize the game map object defs.
*/
Expand Down
7 changes: 4 additions & 3 deletions doomsday/client/src/world/api_map.cpp
Expand Up @@ -35,6 +35,7 @@
#include "api_map.h"

#include "world/dmuargs.h"
#include "world/entitydatabase.h"
#include "world/world.h"

#ifdef __CLIENT__
Expand Down Expand Up @@ -1532,9 +1533,9 @@ DENG_EXTERN_C boolean P_LoadMap(char const *uriCString)
#undef P_CountMapObjs
DENG_EXTERN_C uint P_CountMapObjs(int entityId)
{
if(!App_World().hasMap() || !App_World().map().entityDatabase) return 0;
EntityDatabase *db = App_World().map().entityDatabase;
return EntityDatabase_EntityCount(db, P_MapEntityDef(entityId));
if(!App_World().hasMap()) return 0;
EntityDatabase &entities = App_World().map().entityDatabase();
return entities.entityCount(P_MapEntityDef(entityId));
}

// p_mapdata.cpp
Expand Down
16 changes: 13 additions & 3 deletions doomsday/client/src/world/api_mapedit.cpp
Expand Up @@ -27,6 +27,7 @@

#include "Materials"

#include "world/entitydatabase.h"
#include "world/p_mapdata.h"
#include "world/map.h"

Expand Down Expand Up @@ -403,7 +404,7 @@ int MPE_PolyobjCreate(int *lines, int lineCount, int tag, int sequenceType,

#undef MPE_GameObjProperty
boolean MPE_GameObjProperty(char const *entityName, int elementIndex,
char const *propertyName, valuetype_t type, void *valueAdr)
char const *propertyName, valuetype_t valueType, void *valueAdr)
{
LOG_AS("MPE_GameObjProperty");

Expand All @@ -429,8 +430,17 @@ boolean MPE_GameObjProperty(char const *entityName, int elementIndex,
return false;
}

return P_SetMapEntityProperty(editMap->entityDatabase,
propertyDef, elementIndex, type, valueAdr);
try
{
EntityDatabase &entities = editMap->entityDatabase();
entities.setProperty(propertyDef, elementIndex, valueType, valueAdr);
return true;
}
catch(Error const &er)
{
LOG_WARNING("%s. Ignoring.") << er.asText();
}
return false;
}

// p_data.cpp
Expand Down

0 comments on commit f2b26fe

Please sign in to comment.