Skip to content

Commit

Permalink
Removed fixed limit on the number of decorations that can be attached…
Browse files Browse the repository at this point in the history
… to a surface_t.
  • Loading branch information
danij committed Dec 16, 2007
1 parent 31e5b41 commit c11fa5f
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 27 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/def_data.h
Expand Up @@ -484,7 +484,7 @@ extern "C" {
} ded_decorlight_t;

// There is a fixed number of light decorations in each decoration.
#define DED_DECOR_NUM_LIGHTS MAX_SURFACE_DECORATIONS
#define DED_DECOR_NUM_LIGHTS 16

typedef struct ded_decor_s {
ded_string_t surface; // Texture or flat name.
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/mapdata.hs
Expand Up @@ -161,7 +161,8 @@ struct surface
FLOAT float[4] rgba // Surface color tint
- float[4] oldrgba
- short frameflags
- surfacedecor_t decorations[MAX_SURFACE_DECORATIONS]
- uint numdecorations
- surfacedecor_t *decorations
end

internal
Expand Down
2 changes: 0 additions & 2 deletions doomsday/engine/portable/include/p_mapdata.h
Expand Up @@ -42,8 +42,6 @@
#include "m_nodepile.h"
#include "m_vector.h"

#define MAX_SURFACE_DECORATIONS 16

#define GET_VERTEX_IDX(vtx) ((vtx) - vertexes)
#define GET_LINE_IDX(li) ((li) - lines)
#define GET_SIDE_IDX(si) ((si) - sides)
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/p_maptypes.h
Expand Up @@ -153,7 +153,8 @@ typedef struct surface_s {
float rgba[4]; // Surface color tint
float oldrgba[4];
short frameflags;
surfacedecor_t decorations[MAX_SURFACE_DECORATIONS];
unsigned int numdecorations;
surfacedecor_t *decorations;
} surface_t;

typedef enum {
Expand Down
4 changes: 4 additions & 0 deletions doomsday/engine/portable/include/r_world.h
Expand Up @@ -69,6 +69,10 @@ void R_OrderVertices(const line_t *line, const sector_t *sector,
plane_t *R_NewPlaneForSector(sector_t *sec);
void R_DestroyPlaneOfSector(uint id, sector_t *sec);

void R_CreateSurfaceDecoration(surface_t *suf, float pos[3],
ded_decorlight_t *def);
void R_ClearSurfaceDecorations(surface_t *suf);

void R_UpdateWatchedPlanes(watchedplanelist_t *wpl);
void R_InterpolateWatchedPlanes(watchedplanelist_t *wpl,
boolean resetNextViewer);
Expand Down
5 changes: 5 additions & 0 deletions doomsday/engine/portable/src/dam_file.c
Expand Up @@ -514,6 +514,8 @@ static void readSide(const gamemap_t *map, uint idx)
suf->rgba[CG] = readFloat();
suf->rgba[CB] = readFloat();
suf->rgba[CA] = readFloat();
suf->decorations = NULL;
suf->numdecorations = 0;
}
secIdx = readLong();
s->sector = (secIdx == 0? NULL : &map->sectors[secIdx -1]);
Expand Down Expand Up @@ -683,6 +685,9 @@ static void readSector(const gamemap_t *map, uint idx)
p->soundorg.pos[VX] = readFloat();
p->soundorg.pos[VY] = readFloat();
p->soundorg.pos[VZ] = readFloat();

p->surface.decorations = NULL;
p->surface.numdecorations = 0;
}

s->skyfix[PLN_FLOOR].offset = readFloat();
Expand Down
52 changes: 52 additions & 0 deletions doomsday/engine/portable/src/r_world.c
Expand Up @@ -265,6 +265,8 @@ plane_t *R_NewPlaneForSector(sector_t *sec)
suf->rgba[i] = 1;
suf->flags = 0;
suf->offset[VX] = suf->offset[VY] = 0;
suf->decorations = NULL;
suf->numdecorations = 0;

// Set normal.
suf->normal[VX] = 0;
Expand Down Expand Up @@ -324,6 +326,56 @@ void R_DestroyPlaneOfSector(uint id, sector_t *sec)
sec->planes = newList;
}

void R_CreateSurfaceDecoration(surface_t *suf, float pos[3],
ded_decorlight_t *def)
{
uint i;
surfacedecor_t *d, *s, *decorations;

if(!suf || !def)
return;

decorations =
Z_Malloc(sizeof(*decorations) * (++suf->numdecorations),
PU_LEVEL, 0);

if(suf->numdecorations > 1)
{ // Copy the existing decorations.
for(i = 0; i < suf->numdecorations - 1; ++i)
{
d = &decorations[i];
s = &suf->decorations[i];

d->pos[VX] = s->pos[VX];
d->pos[VY] = s->pos[VY];
d->pos[VZ] = s->pos[VZ];
d->def = s->def;
}

Z_Free(suf->decorations);
}

// Add the new decoration.
d = &decorations[suf->numdecorations - 1];
d->pos[VX] = pos[VX];
d->pos[VY] = pos[VY];
d->pos[VZ] = pos[VZ];
d->def = def;

suf->decorations = decorations;
}

void R_ClearSurfaceDecorations(surface_t *suf)
{
if(!suf)
return;

if(suf->decorations)
Z_Free(suf->decorations);
suf->decorations = NULL;
suf->numdecorations = 0;
}

#ifdef _MSC_VER
# pragma optimize("g", off)
#endif
Expand Down
31 changes: 9 additions & 22 deletions doomsday/engine/portable/src/rend_decor.c
Expand Up @@ -368,7 +368,7 @@ static void projectSurfaceDecorations(const surface_t *suf,
{
uint i;

for(i = 0; i < MAX_SURFACE_DECORATIONS; ++i)
for(i = 0; i < suf->numdecorations; ++i)
{
float brightMul;
const surfacedecor_t *d = &suf->decorations[i];
Expand Down Expand Up @@ -416,7 +416,7 @@ static void decorateLineSection(const line_t *line, side_t *side,
float posBase[2], delta[2], pos[3];
float surfTexW, surfTexH, patternW, patternH;
int skip[2];
uint i, n;
uint i;
texinfo_t *texinfo;

// Let's see which sidedef is present.
Expand All @@ -438,6 +438,8 @@ static void decorateLineSection(const line_t *line, side_t *side,
surfaceNormal[VZ] = -delta[VX] / line->length;
surfaceNormal[VY] = 0;

R_ClearSurfaceDecorations(suf);

// Height of the section.
lh = top - bottom;

Expand All @@ -449,7 +451,7 @@ static void decorateLineSection(const line_t *line, side_t *side,
surfTexH = texinfo->height;

// Generate a number of lights.
for(i = 0, n = 0; i < DED_DECOR_NUM_LIGHTS; ++i)
for(i = 0; i < DED_DECOR_NUM_LIGHTS; ++i)
{
lightDef = def->lights + i;

Expand Down Expand Up @@ -483,14 +485,7 @@ static void decorateLineSection(const line_t *line, side_t *side,
pos[VY] = posBase[VY] + delta[VY] * s / line->length;
pos[VZ] = top - t;

if(n < MAX_SURFACE_DECORATIONS)
{
suf->decorations[n].pos[VX] = pos[VX];
suf->decorations[n].pos[VY] = pos[VY];
suf->decorations[n].pos[VZ] = pos[VZ];
suf->decorations[n].def = lightDef;
n++;
}
R_CreateSurfaceDecoration(suf, pos, lightDef);
}
}
}
Expand Down Expand Up @@ -768,7 +763,6 @@ static void decoratePlane(const sector_t *sec, plane_t *pln,

if(suf->flags & SUF_UPDATE_DECORATIONS)
{
uint n;
float pos[3], tileSize = 64;
int skip[2];
ded_decorlight_t *lightDef;
Expand All @@ -777,10 +771,10 @@ static void decoratePlane(const sector_t *sec, plane_t *pln,
surfaceNormal[VY] = suf->normal[VY];
surfaceNormal[VZ] = suf->normal[VZ];

memset(suf->decorations, 0, sizeof(suf->decorations));
R_ClearSurfaceDecorations(suf);

// Generate a number of lights.
for(i = 0, n = 0; i < DED_DECOR_NUM_LIGHTS; ++i)
for(i = 0; i < DED_DECOR_NUM_LIGHTS; ++i)
{
lightDef = &def->lights[i];

Expand Down Expand Up @@ -823,14 +817,7 @@ static void decoratePlane(const sector_t *sec, plane_t *pln,
pos[VZ] =
pln->visheight + lightDef->elevation * surfaceNormal[VZ];

if(n < MAX_SURFACE_DECORATIONS)
{
suf->decorations[n].pos[VX] = pos[VX];
suf->decorations[n].pos[VY] = pos[VY];
suf->decorations[n].pos[VZ] = pos[VZ];
suf->decorations[n].def = lightDef;
n++;
}
R_CreateSurfaceDecoration(suf, pos, lightDef);
}
}
}
Expand Down

0 comments on commit c11fa5f

Please sign in to comment.