Skip to content

Commit

Permalink
API: Standardized map element indices across all APIs
Browse files Browse the repository at this point in the history
It appears we had accumulated various different representations for
map element indices. Some indexes were 1-based, some APIs used
unsigned integers, etc... As we breaking API compatibility for this
release now is a good time to address this issue and apply a global
standard.

All map element indexes are now 0-based and all indices specified to
public APIs are represented with the platform's signed, integer type.

MapElement now stores an indexInArchive in addition to indexInMap.
This being the index of the relevant map element/definition from the
"archived" map (e.g., in id tech 1 format). The in-archive index is
specified when transferring the map element using the map edit API.

The old DD_SECTOR_COUNT (etc...) engine constants have been replaced
with a new DMU API P_Count() function.

Also, the WAD Map Converter plugin now uses the same representation.
  • Loading branch information
danij-deng committed Apr 21, 2013
1 parent 31f10cf commit 81b3a40
Show file tree
Hide file tree
Showing 84 changed files with 875 additions and 1,073 deletions.
96 changes: 52 additions & 44 deletions doomsday/api/api_map.h
Expand Up @@ -270,7 +270,7 @@ DENG_API_TYPEDEF(Map)
* @param id Unique identifier of the Polyobj to be found.
* @return Found Polyobj instance else @c NULL.
*/
struct polyobj_s* (*PO_PolyobjByID)(uint id);
struct polyobj_s* (*PO_PolyobjByID)(int id);

/**
* Lookup a Polyobj on the current map by tag.
Expand Down Expand Up @@ -380,9 +380,16 @@ DENG_API_TYPEDEF(Map)
*/
int (*GetType)(MapElementPtrConst ptr);

unsigned int (*ToIndex)(MapElementPtrConst ptr);
void* (*ToPtr)(int type, uint index);
int (*Callback)(int type, uint index, void* context, int (*callback)(MapElementPtr p, void* ctx));
int (*ToIndex)(MapElementPtrConst ptr);
void* (*ToPtr)(int type, int index);

/**
* Returns the total number of DMU objects of @a type. For example, if the
* type is @c DMU_LINE then the total number of map Lines is returned.
*/
int (*Count)(int type);

int (*Callback)(int type, int index, void* context, int (*callback)(MapElementPtr p, void* ctx));
int (*Callbackp)(int type, MapElementPtr ptr, void* context, int (*callback)(MapElementPtr p, void* ctx));
int (*Iteratep)(MapElementPtr ptr, uint prop, void* context, int (*callback) (MapElementPtr p, void* ctx));

Expand All @@ -394,31 +401,31 @@ DENG_API_TYPEDEF(Map)

// Map Entities
uint (*CountGameMapObjs)(int entityId);
byte (*GetGMOByte)(int entityId, uint elementIndex, int propertyId);
short (*GetGMOShort)(int entityId, uint elementIndex, int propertyId);
int (*GetGMOInt)(int entityId, uint elementIndex, int propertyId);
fixed_t (*GetGMOFixed)(int entityId, uint elementIndex, int propertyId);
angle_t (*GetGMOAngle)(int entityId, uint elementIndex, int propertyId);
float (*GetGMOFloat)(int entityId, uint elementIndex, int propertyId);
byte (*GetGMOByte)(int entityId, int elementIndex, int propertyId);
short (*GetGMOShort)(int entityId, int elementIndex, int propertyId);
int (*GetGMOInt)(int entityId, int elementIndex, int propertyId);
fixed_t (*GetGMOFixed)(int entityId, int elementIndex, int propertyId);
angle_t (*GetGMOAngle)(int entityId, int elementIndex, int propertyId);
float (*GetGMOFloat)(int entityId, int elementIndex, int propertyId);

/* index-based write functions */
void (*SetBool)(int type, uint index, uint prop, boolean param);
void (*SetByte)(int type, uint index, uint prop, byte param);
void (*SetInt)(int type, uint index, uint prop, int param);
void (*SetFixed)(int type, uint index, uint prop, fixed_t param);
void (*SetAngle)(int type, uint index, uint prop, angle_t param);
void (*SetFloat)(int type, uint index, uint prop, float param);
void (*SetDouble)(int type, uint index, uint prop, double param);
void (*SetPtr)(int type, uint index, uint prop, void* param);

void (*SetBoolv)(int type, uint index, uint prop, boolean* params);
void (*SetBytev)(int type, uint index, uint prop, byte* params);
void (*SetIntv)(int type, uint index, uint prop, int* params);
void (*SetFixedv)(int type, uint index, uint prop, fixed_t* params);
void (*SetAnglev)(int type, uint index, uint prop, angle_t* params);
void (*SetFloatv)(int type, uint index, uint prop, float* params);
void (*SetDoublev)(int type, uint index, uint prop, double* params);
void (*SetPtrv)(int type, uint index, uint prop, void* params);
void (*SetBool)(int type, int index, uint prop, boolean param);
void (*SetByte)(int type, int index, uint prop, byte param);
void (*SetInt)(int type, int index, uint prop, int param);
void (*SetFixed)(int type, int index, uint prop, fixed_t param);
void (*SetAngle)(int type, int index, uint prop, angle_t param);
void (*SetFloat)(int type, int index, uint prop, float param);
void (*SetDouble)(int type, int index, uint prop, double param);
void (*SetPtr)(int type, int index, uint prop, void* param);

void (*SetBoolv)(int type, int index, uint prop, boolean* params);
void (*SetBytev)(int type, int index, uint prop, byte* params);
void (*SetIntv)(int type, int index, uint prop, int* params);
void (*SetFixedv)(int type, int index, uint prop, fixed_t* params);
void (*SetAnglev)(int type, int index, uint prop, angle_t* params);
void (*SetFloatv)(int type, int index, uint prop, float* params);
void (*SetDoublev)(int type, int index, uint prop, double* params);
void (*SetPtrv)(int type, int index, uint prop, void* params);

/* pointer-based write functions */
void (*SetBoolp)(MapElementPtr ptr, uint prop, boolean param);
Expand All @@ -440,23 +447,23 @@ DENG_API_TYPEDEF(Map)
void (*SetPtrpv)(MapElementPtr ptr, uint prop, void* params);

/* index-based read functions */
boolean (*GetBool)(int type, uint index, uint prop);
byte (*GetByte)(int type, uint index, uint prop);
int (*GetInt)(int type, uint index, uint prop);
fixed_t (*GetFixed)(int type, uint index, uint prop);
angle_t (*GetAngle)(int type, uint index, uint prop);
float (*GetFloat)(int type, uint index, uint prop);
double (*GetDouble)(int type, uint index, uint prop);
void* (*GetPtr)(int type, uint index, uint prop);

void (*GetBoolv)(int type, uint index, uint prop, boolean* params);
void (*GetBytev)(int type, uint index, uint prop, byte* params);
void (*GetIntv)(int type, uint index, uint prop, int* params);
void (*GetFixedv)(int type, uint index, uint prop, fixed_t* params);
void (*GetAnglev)(int type, uint index, uint prop, angle_t* params);
void (*GetFloatv)(int type, uint index, uint prop, float* params);
void (*GetDoublev)(int type, uint index, uint prop, double* params);
void (*GetPtrv)(int type, uint index, uint prop, void* params);
boolean (*GetBool)(int type, int index, uint prop);
byte (*GetByte)(int type, int index, uint prop);
int (*GetInt)(int type, int index, uint prop);
fixed_t (*GetFixed)(int type, int index, uint prop);
angle_t (*GetAngle)(int type, int index, uint prop);
float (*GetFloat)(int type, int index, uint prop);
double (*GetDouble)(int type, int index, uint prop);
void* (*GetPtr)(int type, int index, uint prop);

void (*GetBoolv)(int type, int index, uint prop, boolean* params);
void (*GetBytev)(int type, int index, uint prop, byte* params);
void (*GetIntv)(int type, int index, uint prop, int* params);
void (*GetFixedv)(int type, int index, uint prop, fixed_t* params);
void (*GetAnglev)(int type, int index, uint prop, angle_t* params);
void (*GetFloatv)(int type, int index, uint prop, float* params);
void (*GetDoublev)(int type, int index, uint prop, double* params);
void (*GetPtrv)(int type, int index, uint prop, void* params);

/* pointer-based read functions */
boolean (*GetBoolp)(MapElementPtr ptr, uint prop);
Expand Down Expand Up @@ -537,6 +544,7 @@ DENG_API_T(Map);
#define DMU_GetType _api_Map.GetType
#define P_ToIndex _api_Map.ToIndex
#define P_ToPtr _api_Map.ToPtr
#define P_Count _api_Map.Count
#define P_Callback _api_Map.Callback
#define P_Callbackp _api_Map.Callbackp
#define P_Iteratep _api_Map.Iteratep
Expand Down
47 changes: 27 additions & 20 deletions doomsday/api/api_mapedit.h
Expand Up @@ -76,25 +76,30 @@ DENG_API_TYPEDEF(MPE)
/**
* Create a new vertex in currently loaded editable map.
*
* @param x X map space coordinate of the new vertex.
* @param y Y map space coordinate of the new vertex.
* @param x X map space coordinate of the new vertex.
* @param y Y map space coordinate of the new vertex.
* @param archiveIndex Archive index for the vertex. Set to @c -1 if
* not relevant/known.
*
* @return Index number of the newly created vertex else @c =0 if the vertex
* could not be created for some reason.
* @return Index number of the newly created vertex; otherwise @c -1 if
* the vertex could not be created for some reason.
*/
uint (*VertexCreate)(coord_t x, coord_t y);
int (*VertexCreate)(coord_t x, coord_t y, int archiveIndex);

/**
* Create many new vertices in the currently loaded editable map.
*
* @param num Number of vertexes to be created.
* @param values Array containing the coordinates for all vertexes to be
* created [v0:X, vo:Y, v1:X, v1:Y, ..]
* @param indices If not @c =NULL, the indices of the newly created vertexes
* will be written back here.
* @param num Number of vertexes to be created.
* @param values Array containing the coordinates for all vertexes
* to be created [v0:X, vo:Y, v1:X, v1:Y, ..]
* @param archiveIndices Array containing the archive indices for each
* vertex. Can be @c 0.
* @param indices If not @c 0, the indices of the newly created
* vertexes will be written back here.
* @return @c =true iff all vertexes were created successfully.
*/
boolean (*VertexCreatev)(size_t num, coord_t* values, uint* indices);
boolean (*VertexCreatev)(size_t num, coord_t *values,
int *archiveIndices, int *indices);

/**
* Create a new line in the editable map.
Expand All @@ -106,15 +111,17 @@ DENG_API_TYPEDEF(MPE)
* @param frontSide Idx of the front side.
* @param backSide Idx of the back side.
* @param flags DDLF_* flags.
* @param archiveIndex Archive index for the line. Set to @c -1 if
* not relevant/known.
*
* @return Index of the newly created line else @c 0 if there was an error.
* @return Index of the newly created line else @c -1 if there was an error.
*/
uint (*LineCreate)(uint v1, uint v2, uint frontSector, uint backSector, int flags);
void (*LineAddSide)(uint line, int side, short flags, const ddstring_t* topMaterial, float topOffsetX, float topOffsetY, float topRed, float topGreen, float topBlue, const ddstring_t* middleMaterial, float middleOffsetX, float middleOffsetY, float middleRed, float middleGreen, float middleBlue, float middleAlpha, const ddstring_t* bottomMaterial, float bottomOffsetX, float bottomOffsetY, float bottomRed, float bottomGreen, float bottomBlue, uint sideDefArchiveIndex);
uint (*SectorCreate)(float lightlevel, float red, float green, float blue);
uint (*PlaneCreate)(uint sector, coord_t height, const ddstring_t* materialUri, float matOffsetX, float matOffsetY, float r, float g, float b, float a, float normalX, float normalY, float normalZ);
uint (*PolyobjCreate)(uint* lines, uint linecount, int tag, int sequenceType, coord_t originX, coord_t originY);
boolean (*GameObjProperty)(const char* objName, uint idx, const char* propName, valuetype_t type, void* data);
int (*LineCreate)(int v1, int v2, int frontSector, int backSector, int flags, int archiveIndex);
void (*LineAddSide)(int line, int side, short flags, const ddstring_t* topMaterial, float topOffsetX, float topOffsetY, float topRed, float topGreen, float topBlue, const ddstring_t* middleMaterial, float middleOffsetX, float middleOffsetY, float middleRed, float middleGreen, float middleBlue, float middleAlpha, const ddstring_t* bottomMaterial, float bottomOffsetX, float bottomOffsetY, float bottomRed, float bottomGreen, float bottomBlue, int archiveIndex);
int (*SectorCreate)(float lightlevel, float red, float green, float blue, int archiveIndex);
int (*PlaneCreate)(int sector, coord_t height, const ddstring_t* materialUri, float matOffsetX, float matOffsetY, float r, float g, float b, float a, float normalX, float normalY, float normalZ, int archiveIndex);
int (*PolyobjCreate)(int* lines, int linecount, int tag, int sequenceType, coord_t originX, coord_t originY, int archiveIndex);
boolean (*GameObjProperty)(const char* objName, int idx, const char* propName, valuetype_t type, void* data);
}
DENG_API_T(MPE);

Expand All @@ -125,8 +132,8 @@ DENG_API_T(MPE);
#define MPE_End _api_MPE.End
#define MPE_VertexCreate _api_MPE.VertexCreate
#define MPE_VertexCreatev _api_MPE.VertexCreatev
#define MPE_LineCreate _api_MPE.LineCreate
#define MPE_LineAddSide _api_MPE.LineAddSide
#define MPE_LineCreate _api_MPE.LineCreate
#define MPE_LineAddSide _api_MPE.LineAddSide
#define MPE_SectorCreate _api_MPE.SectorCreate
#define MPE_PlaneCreate _api_MPE.PlaneCreate
#define MPE_PolyobjCreate _api_MPE.PolyobjCreate
Expand Down
9 changes: 1 addition & 8 deletions doomsday/api/dd_share.h
Expand Up @@ -237,13 +237,6 @@ enum {
DD_WINDOW_HANDLE,
DD_DYNLIGHT_TEXTURE,
DD_GAME_EXPORTS,
DD_SECTOR_COUNT,
DD_LINE_COUNT,
DD_SIDE_COUNT,
DD_VERTEX_COUNT,
DD_HEDGE_COUNT,
DD_BSPLEAF_COUNT,
DD_BSPNODE_COUNT,
DD_POLYOBJ_COUNT,
DD_XGFUNC_LINK, ///< XG line classes
DD_SHARED_FIXED_TRIGGER_OBSOLETE, ///< obsolete
Expand Down Expand Up @@ -707,7 +700,7 @@ enum { MX, MY, MZ };
DD_BASE_DDMOBJ_ELEMENTS() \
\
BspLeaf *bspLeaf; /* bspLeaf in which this resides */ \
unsigned int idx; /* Idx of polyobject. */ \
int _indexInMap; \
int tag; /* Reference tag. */ \
int validCount; \
AABoxd aaBox; \
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/include/map/bsp/hedgeintercept.h
Expand Up @@ -60,11 +60,11 @@ struct HEdgeIntercept
static void DebugPrint(HEdgeIntercept const &inst)
{
LOG_INFO("Vertex #%i [x:%f, y:%f] beforeSector: #%d afterSector: #%d %s")
<< (inst.vertex->origIndex() - 1)
<< inst.vertex->indexInMap()
<< inst.vertex->origin()[VX]
<< inst.vertex->origin()[VY]
<< (inst.before? inst.before->origIndex() : -1)
<< (inst.after? inst.after->origIndex() : -1)
<< (inst.before? inst.before->indexInMap() : -1)
<< (inst.after? inst.after->indexInMap() : -1)
<< (inst.selfRef? "SELFREF" : "");
})
};
Expand Down
9 changes: 1 addition & 8 deletions doomsday/client/include/map/bspleaf.h
Expand Up @@ -206,13 +206,6 @@ class BspLeaf : public de::MapElement
*/
vec2d_t const &worldGridOffset() const;

/**
* Returns the original index of the BSP leaf.
*/
uint origIndex() const;

void setOrigIndex(uint newOrigIndex);

/**
* Returns the @em validCount of the BSP leaf. Used by some legacy iteration
* algorithms for marking leafs as processed/visited.
Expand Down Expand Up @@ -250,7 +243,7 @@ class BspLeaf : public de::MapElement
*
* @param groupId Geometry group identifier for the bias surface.
*/
biassurface_t &biasSurfaceForGeometryGroup(uint groupId);
biassurface_t &biasSurfaceForGeometryGroup(int groupId);

/**
* Returns the first ShadowLink associated with the BSP leaf; otherwise @c 0.
Expand Down
7 changes: 0 additions & 7 deletions doomsday/client/include/map/bspnode.h
Expand Up @@ -156,13 +156,6 @@ class BspNode : public de::MapElement

inline void setLeftAABox(AABoxd const *newAABox) { setChildAABox(LEFT, newAABox); }

/**
* Returns the original index of the BSP node.
*/
uint origIndex() const;

void setOrigIndex(uint newIndex);

private:
DENG2_PRIVATE(d)
};
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/include/map/entitydatabase.h
Expand Up @@ -57,13 +57,13 @@ void EntityDatabase_Delete(EntityDatabase* db);

uint EntityDatabase_EntityCount(EntityDatabase* db, struct mapentitydef_s* entityDef);

boolean EntityDatabase_HasEntity(EntityDatabase* db, struct mapentitydef_s* entityDef, uint elementIndex);
boolean EntityDatabase_HasEntity(EntityDatabase* db, struct mapentitydef_s* entityDef, int elementIndex);

#ifdef __cplusplus
PropertyValue const* EntityDatabase_Property(EntityDatabase* db, struct mapentitypropertydef_s* propertyDef, uint elementIndex);
PropertyValue const* EntityDatabase_Property(EntityDatabase* db, struct mapentitypropertydef_s* propertyDef, int elementIndex);
#endif

boolean EntityDatabase_SetProperty(EntityDatabase* db, struct mapentitypropertydef_s* propertyDef, uint elementIndex, valuetype_t valueType, void* valueAdr);
boolean EntityDatabase_SetProperty(EntityDatabase* db, struct mapentitypropertydef_s* propertyDef, int elementIndex, valuetype_t valueType, void* valueAdr);

#ifdef __cplusplus
} // extern "C"
Expand Down

0 comments on commit 81b3a40

Please sign in to comment.