Skip to content

Commit

Permalink
Wad Map Converter|Refactor: Use an instance of StringPool for the mat…
Browse files Browse the repository at this point in the history
…erial dictionary

Also fixed missing material logging during map conversion.

Todo: Also use a material dictionary on the engine side of the MPE
interface to avoid repeatedly resolving URIs again and again...
  • Loading branch information
danij-deng committed Jul 24, 2012
1 parent e414b1d commit 133c329
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 278 deletions.
4 changes: 2 additions & 2 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -313,10 +313,10 @@ boolean MPE_End(void);

uint MPE_VertexCreate(coord_t x, coord_t y);
boolean MPE_VertexCreatev(size_t num, coord_t* values, uint* indices);
uint MPE_SidedefCreate(short flags, materialid_t topMaterial, float topOffsetX, float topOffsetY, float topRed, float topGreen, float topBlue, materialid_t middleMaterial, float middleOffsetX, float middleOffsetY, float middleRed, float middleGreen, float middleBlue, float middleAlpha, materialid_t bottomMaterial, float bottomOffsetX, float bottomOffsetY, float bottomRed, float bottomGreen, float bottomBlue);
uint MPE_SidedefCreate(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 MPE_LinedefCreate(uint v1, uint v2, uint frontSector, uint backSector, uint frontSide, uint backSide, int flags);
uint MPE_SectorCreate(float lightlevel, float red, float green, float blue);
uint MPE_PlaneCreate(uint sector, coord_t height, materialid_t materialId, float matOffsetX, float matOffsetY, float r, float g, float b, float a, float normalX, float normalY, float normalZ);
uint MPE_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 MPE_PolyobjCreate(uint* lines, uint linecount, int tag, int sequenceType, coord_t originX, coord_t originY);
boolean MPE_GameObjProperty(const char* objName, uint idx, const char* propName, valuetype_t type, void* data);
///@}
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/include/edit_map.h
Expand Up @@ -89,9 +89,9 @@ uint MPE_VertexCreate(coord_t x, coord_t y);
boolean MPE_VertexCreatev(size_t num, coord_t* values, uint* indices);

uint MPE_SidedefCreate(short flags,
materialid_t topMaterial, float topOffsetX, float topOffsetY, float topRed, float topGreen, float topBlue,
materialid_t middleMaterial, float middleOffsetX, float middleOffsetY, float middleRed, float middleGreen, float middleBlue, float middleAlpha,
materialid_t bottomMaterial, float bottomOffsetX, float bottomOffsetY, float bottomRed, float bottomGreen, float bottomBlue);
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);

/**
* Create a new linedef in the editable map.
Expand All @@ -112,7 +112,7 @@ uint MPE_LinedefCreate(uint v1, uint v2, uint frontSector, uint backSector,

uint MPE_SectorCreate(float lightlevel, float red, float green, float blue);
uint MPE_PlaneCreate(uint sector, coord_t height,
materialid_t material,
const ddstring_t* material,
float matOffsetX, float matOffsetY,
float r, float g, float b, float a,
float normalX, float normalY, float normalZ);
Expand Down
10 changes: 5 additions & 5 deletions doomsday/engine/portable/include/p_mapdata.h
Expand Up @@ -225,17 +225,17 @@ const char* P_MapSourceFile(const char* uri);
*/
boolean P_LoadMap(const char* uri);

void P_RegisterUnknownTexture(const char* name, boolean planeTex);
void P_RegisterMissingMaterial(const char* materialUri);

/**
* Announce any bad texture names we came across when loading the map.
* Announce any missing materials we came across when loading the map.
*/
void P_PrintMissingTextureList(void);
void P_PrintMissingMaterialList(void);

/**
* Frees memory we allocated for bad texture name collection.
* Clear the missing material list.
*/
void P_FreeBadTexList(void);
void P_ClearMissingMaterialList(void);

/**
* To be called to initialize the game map object defs.
Expand Down
50 changes: 39 additions & 11 deletions doomsday/engine/portable/src/edit_map.c
Expand Up @@ -1815,8 +1815,8 @@ boolean MPE_End(void)
GameMap_InitMobjBlockmap(gamemap, min, max);
GameMap_InitPolyobjBlockmap(gamemap, min, max);

// Announce any bad texture names we came across when loading the map.
P_PrintMissingTextureList();
// Announce any missing materials we encountered during the conversion.
P_PrintMissingMaterialList();

/**
* Build a BSP for this map.
Expand Down Expand Up @@ -1875,7 +1875,7 @@ boolean MPE_End(void)
S_DetermineBspLeafsAffectingSectorReverb(gamemap);
prepareBspLeafs(gamemap);

P_FreeBadTexList();
P_ClearMissingMaterialList();

editMapInited = false;

Expand Down Expand Up @@ -1966,10 +1966,38 @@ boolean MPE_VertexCreatev(size_t num, coord_t* values, uint* indices)
return true;
}

uint MPE_SidedefCreate(short flags, materialid_t topMaterial,
static void assignSurfaceMaterial(Surface* suf, const ddstring_t* materialUri)
{
materialid_t id = NOMATERIALID;

DENG_ASSERT(suf);

/// @todo Avoid repeatedly resolving URIs with a dictionary (another StringPool?).
if(materialUri && !Str_IsEmpty(materialUri))
{
// First try the preferred namespace, then any.
id = Materials_ResolveUriCString2(Str_Text(materialUri), true/*quiet please*/);
if(id == NOMATERIALID)
{
Uri* tmp = Uri_NewWithPath2(Str_Text(materialUri), RC_NULL);
Uri_SetScheme(tmp, "");
id = Materials_ResolveUri(tmp);
Uri_Delete(tmp);
}

if(id == NOMATERIALID)
{
P_RegisterMissingMaterial(Str_Text(materialUri));
}
}

Surface_SetMaterial(suf, Materials_ToMaterial(id));
}

uint MPE_SidedefCreate(short flags, const ddstring_t* topMaterial,
float topOffsetX, float topOffsetY, float topRed, float topGreen, float topBlue,
materialid_t middleMaterial, float middleOffsetX, float middleOffsetY, float middleRed,
float middleGreen, float middleBlue, float middleAlpha, materialid_t bottomMaterial,
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)
{
Expand All @@ -1980,15 +2008,15 @@ uint MPE_SidedefCreate(short flags, materialid_t topMaterial,
s = createSide();
s->flags = flags;

Surface_SetMaterial(&s->SW_topsurface, Materials_ToMaterial(topMaterial));
assignSurfaceMaterial(&s->SW_topsurface, topMaterial);
Surface_SetMaterialOrigin(&s->SW_topsurface, topOffsetX, topOffsetY);
Surface_SetColorAndAlpha(&s->SW_topsurface, topRed, topGreen, topBlue, 1);

Surface_SetMaterial(&s->SW_middlesurface, Materials_ToMaterial(middleMaterial));
assignSurfaceMaterial(&s->SW_middlesurface, middleMaterial);
Surface_SetMaterialOrigin(&s->SW_middlesurface, middleOffsetX, middleOffsetY);
Surface_SetColorAndAlpha(&s->SW_middlesurface, middleRed, middleGreen, middleBlue, middleAlpha);

Surface_SetMaterial(&s->SW_bottomsurface, Materials_ToMaterial(bottomMaterial));
assignSurfaceMaterial(&s->SW_bottomsurface, bottomMaterial);
Surface_SetMaterialOrigin(&s->SW_bottomsurface, bottomOffsetX, bottomOffsetY);
Surface_SetColorAndAlpha(&s->SW_bottomsurface, bottomRed, bottomGreen, bottomBlue, 1);

Expand Down Expand Up @@ -2076,7 +2104,7 @@ uint MPE_LinedefCreate(uint v1, uint v2, uint frontSector, uint backSector,
return l->buildData.index;
}

uint MPE_PlaneCreate(uint sector, coord_t height, materialid_t material, float matOffsetX,
uint MPE_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)
{
Plane** newList, *pln;
Expand All @@ -2092,7 +2120,7 @@ uint MPE_PlaneCreate(uint sector, coord_t height, materialid_t material, float m
pln->surface.owner = (void*) pln;
pln->height = height;

Surface_SetMaterial(&pln->surface, Materials_ToMaterial(material));
assignSurfaceMaterial(&pln->surface, materialUri);
Surface_SetColorAndAlpha(&pln->surface, r, g, b, a);
Surface_SetMaterialOrigin(&pln->surface, matOffsetX, matOffsetY);

Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/portable/src/materials.c
Expand Up @@ -894,7 +894,7 @@ materialid_t Materials_ResolveUri2(const Uri* uri, boolean quiet)
return NOMATERIALID;
}

/// \note Part of the Doomsday public API.
/// @note Part of the Doomsday public API.
materialid_t Materials_ResolveUri(const Uri* uri)
{
return Materials_ResolveUri2(uri, !(verbose >= 1)/*log warnings if verbose*/);
Expand All @@ -912,7 +912,7 @@ materialid_t Materials_ResolveUriCString2(const char* path, boolean quiet)
return NOMATERIALID;
}

/// \note Part of the Doomsday public API.
/// @note Part of the Doomsday public API.
materialid_t Materials_ResolveUriCString(const char* path)
{
return Materials_ResolveUriCString2(path, !(verbose >= 1)/*log warnings if verbose*/);
Expand All @@ -931,7 +931,7 @@ ddstring_t* Materials_ComposePath(materialid_t id)
return composePathForDirectoryNode(MaterialBind_DirectoryNode(bind), MATERIALS_PATH_DELIMITER);
}

/// \note Part of the Doomsday public API.
/// @note Part of the Doomsday public API.
Uri* Materials_ComposeUri(materialid_t id)
{
materialbind_t* bind = getMaterialBindForId(id);
Expand Down
99 changes: 42 additions & 57 deletions doomsday/engine/portable/src/p_data.c
Expand Up @@ -36,12 +36,10 @@
#include "rend_bias.h"
#include "m_bams.h"

// Bad texture record.
typedef struct {
char* name;
boolean planeTex;
uint count;
} badtex_t;
ddstring_t uri;
uint count; ///< Number of times this has been found missing.
} missingmaterialrecord_t;

extern boolean mapSetup;

Expand All @@ -62,10 +60,10 @@ BspNode** bspNodes = NULL;

GameMap* theMap = NULL;

// Bad texture list
static uint numBadTexNames = 0;
static uint maxBadTexNames = 0;
static badtex_t* badTexNames = NULL;
// Missing material list.
static uint missingMaterialsSize;
static uint missingMaterialsMaxSize;
static missingmaterialrecord_t* missingMaterials;

// Game-specific, map object type definitions.
static uint numGameMapObjDefs;
Expand Down Expand Up @@ -261,80 +259,67 @@ boolean P_LoadMap(const char* uriCString)
return false;
}

void P_RegisterUnknownTexture(const char *name, boolean planeTex)
void P_RegisterMissingMaterial(const char* materialUri)
{
uint i;
char namet[9];
boolean known = false;

namet[8] = 0;
memcpy(namet, name, 8);
if(!materialUri || !materialUri[0]) return;

// Do we already know about it?
if(numBadTexNames > 0)
if(missingMaterialsSize > 0)
{
for(i = 0; i < numBadTexNames && !known; ++i)
uint i;
for(i = 0; i < missingMaterialsSize; ++i)
{
if(!strcmp(badTexNames[i].name, namet) &&
badTexNames[i].planeTex == planeTex)
if(!Str_CompareIgnoreCase(&missingMaterials[i].uri, materialUri))
{
// Yep we already know about it.
known = true;
badTexNames[i].count++;
// Already known.
missingMaterials[i].count++;
return;
}
}
}

if(!known)
{ // A new unknown texture. Add it to the list
if(++numBadTexNames > maxBadTexNames)
{
// Allocate more memory
maxBadTexNames *= 2;
if(maxBadTexNames < numBadTexNames)
maxBadTexNames = numBadTexNames;

badTexNames = M_Realloc(badTexNames, sizeof(badtex_t)
* maxBadTexNames);
}

badTexNames[numBadTexNames -1].name = M_Malloc(strlen(namet) +1);
strcpy(badTexNames[numBadTexNames -1].name, namet);
// A new unknown texture. Add it to the list
if(++missingMaterialsSize > missingMaterialsMaxSize)
{
// Allocate more memory
missingMaterialsMaxSize *= 2;
if(missingMaterialsMaxSize < missingMaterialsSize)
missingMaterialsMaxSize = missingMaterialsSize;

badTexNames[numBadTexNames -1].planeTex = planeTex;
badTexNames[numBadTexNames -1].count = 1;
missingMaterials = M_Realloc(missingMaterials, sizeof(missingmaterialrecord_t) * missingMaterialsMaxSize);
}

Str_Set(Str_Init(&missingMaterials[missingMaterialsSize -1].uri), materialUri);
missingMaterials[missingMaterialsSize -1].count = 1;
}

void P_PrintMissingTextureList(void)
void P_PrintMissingMaterialList(void)
{
if(numBadTexNames)
if(missingMaterialsSize)
{
uint i;

Con_Message(" [110] Warning: Found %u bad texture name(s):\n", numBadTexNames);

for(i = 0; i < numBadTexNames; ++i)
Con_Message(" %4u x \"%s\"\n", badTexNames[i].count, badTexNames[i].name);
Con_Message(" [110] Warning: Found %u unknown %s:\n", missingMaterialsSize, missingMaterialsSize == 1? "material":"materials");
for(i = 0; i < missingMaterialsSize; ++i)
{
Con_Message(" %4u x \"%s\"\n", missingMaterials[i].count, Str_Text(&missingMaterials[i].uri));
}
}
}

void P_FreeBadTexList(void)
void P_ClearMissingMaterialList(void)
{
uint i;

if(badTexNames != NULL)
if(missingMaterials)
{
for(i = 0; i < numBadTexNames; ++i)
uint i;
for(i = 0; i < missingMaterialsSize; ++i)
{
M_Free(badTexNames[i].name);
badTexNames[i].name = NULL;
Str_Free(&missingMaterials[i].uri);
}

M_Free(badTexNames);
badTexNames = NULL;
M_Free(missingMaterials);
missingMaterials = NULL;

numBadTexNames = maxBadTexNames = 0;
missingMaterialsSize = missingMaterialsMaxSize = 0;
}
}

Expand Down
23 changes: 9 additions & 14 deletions doomsday/plugins/wadmapconverter/include/id1map_datatypes.h
Expand Up @@ -40,20 +40,18 @@
#define SIZEOF_SECTOR (2 * 5 + 8 * 2)
#define SIZEOF_LIGHT (1 * 6)

typedef struct materialref_s {
char name[9];
materialid_t id; // Doomsday's unique identifier for this.
} materialref_t;
// Type used to identify references to materials in the material dictionary.
typedef StringPoolId MaterialDictId;

// Line sides.
#define RIGHT 0
#define LEFT 1

typedef struct mside_s {
int16_t offset[2];
const materialref_t* topMaterial;
const materialref_t* bottomMaterial;
const materialref_t* middleMaterial;
MaterialDictId topMaterial;
MaterialDictId bottomMaterial;
MaterialDictId middleMaterial;
uint sector;
} mside_t;

Expand Down Expand Up @@ -98,8 +96,8 @@ typedef struct msector_s {
int16_t lightLevel;
int16_t type;
int16_t tag;
const materialref_t* floorMaterial;
const materialref_t* ceilMaterial;
MaterialDictId floorMaterial;
MaterialDictId ceilMaterial;

// DOOM64 format members:
int16_t d64flags;
Expand Down Expand Up @@ -156,18 +154,15 @@ typedef struct map_s {
uint numThings;
uint numLights;

coord_t* vertexes; // Array of vertex coords [v0:X, vo:Y, v1:X, v1:Y, ..]
coord_t* vertexes; ///< Array of vertex coords [v0:X, vo:Y, v1:X, v1:Y, ..]
msector_t* sectors;
mline_t* lines;
mside_t* sides;
mthing_t* things;
mpolyobj_t** polyobjs;
surfacetint_t* lights;

size_t numFlats;
materialref_t** flats;
size_t numTextures;
materialref_t** textures;
StringPool* materials; ///< Material dictionary.

byte* rejectMatrix;
void* blockMap;
Expand Down

0 comments on commit 133c329

Please sign in to comment.