Skip to content

Commit

Permalink
Fixed|Definitions: Appending layer stages to auto-generated materials
Browse files Browse the repository at this point in the history
The unlikely but possible case of the mod directive being used to
append additional layer stages to an auto-generated material def
was undefined.

Presently the most logical course of action in this situation is to
copy the property values from the previous stage at parse time.

Todo for later: Ideally the stage animation mechanism would handle
this with its own logic, whereby if a property value is undefined
for the current stage; take the last known value from an earlier
stage.
  • Loading branch information
danij-deng committed Mar 19, 2013
1 parent 60f40ac commit 86f53d2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
8 changes: 2 additions & 6 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -1014,9 +1014,7 @@ static void generateMaterialDefForTexture(TextureManifest &manifest)
startFrame++;
for(int i = 0; i < anim->count - 1; ++i)
{
int frame = startFrame + i;
// Wrap around?
if(frame >= anim->count) frame -= anim->count;
int frame = de::wrap(startFrame + i, 0, anim->count);

animFrame = &anim->frames[frame];
if(!animFrame->textureManifest) continue;
Expand Down Expand Up @@ -1132,9 +1130,7 @@ static void rebuildMaterialLayers(Material &material, ded_material_t const &def)
startFrame++;
for(int i = 0; i < grp->count.num - 1; ++i)
{
int frame = startFrame + i;
// Wrap around?
if(frame >= grp->count.num) frame -= grp->count.num;
int frame = de::wrap(startFrame + i, 0, grp->count.num);
ded_group_member_t const &gm = grp->members[frame];

if(!gm.material) continue;
Expand Down
56 changes: 36 additions & 20 deletions doomsday/client/src/def_read.cpp
Expand Up @@ -1139,12 +1139,8 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)

if(ISTOKEN("Material"))
{
boolean bModify = false;
bool bModify = false;
ded_material_t *mat, dummyMat;
uint layer = 0;
int layerStage;
uint light = 0;
int lightStage;

ReadToken();
if(!ISTOKEN("Mods"))
Expand Down Expand Up @@ -1242,8 +1238,11 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)
}
}

uint layer = 0;
uint light = 0;

FINDBEGIN;
for(;;)
forever
{
READLABEL;
// ID cannot be changed when modifying
Expand All @@ -1256,7 +1255,8 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)
RV_INT("Height", mat->height)
if(ISLABEL("Layer"))
{
layerStage = 0;
int layerStage = 0;

if(layer >= DED_MAX_MATERIAL_LAYERS)
{
SetError("Too many Material layers.");
Expand All @@ -1265,23 +1265,39 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)
}

FINDBEGIN;
for(;;)
forever
{
READLABEL;
if(ISLABEL("Stage"))
{
ded_material_layer_stage_t* st = NULL;

// Need to allocate a new stage?
if(layerStage >= mat->layers[layer].stageCount.num)
{
layerStage = DED_AddMaterialLayerStage(&mat->layers[layer]);

if(mat->autoGenerated && layerStage > 1)
{
// When adding a new stage to an autogenerated material
// initialize by copying values from the previous stage.
ded_material_layer_stage_t const
&prevSt = mat->layers[layer].stages[layerStage - 1];
ded_material_layer_stage_t
&st = mat->layers[layer].stages[layerStage];

if(prevSt.texture)
st.texture = Uri_Dup(prevSt.texture);
st.tics = prevSt.tics;
st.variance = prevSt.variance;
st.glowStrength = prevSt.glowStrength;
st.glowStrengthVariance = prevSt.glowStrengthVariance;
V2f_Copy(st.texOrigin, prevSt.texOrigin);
}
}

st = &mat->layers[layer].stages[layerStage];
ded_material_layer_stage_t *st = &mat->layers[layer].stages[layerStage];

FINDBEGIN;
for(;;)
forever
{
READLABEL;
RV_URI("Texture", &st->texture, 0) // Default to "any" scheme.
Expand All @@ -1293,16 +1309,17 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)
RV_END
CHECKSC;
}
++layerStage;
layerStage++;
}
else RV_END
CHECKSC;
}
++layer;
layer++;
}
else if(ISLABEL("Light"))
{
lightStage = 0;
int lightStage = 0;

if(light == DED_MAX_MATERIAL_DECORATIONS)
{
SetError("Too many lights in material.");
Expand All @@ -1322,7 +1339,7 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)
// Need to allocate a new stage?
if(lightStage >= dl->stageCount.num)
{
layerStage = DED_AddMaterialDecorationStage(dl);
lightStage = DED_AddMaterialDecorationStage(dl);
}

ded_decorlight_stage_t *st = &dl->stages[lightStage];
Expand Down Expand Up @@ -1360,12 +1377,12 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)
RV_END
CHECKSC;
}
++lightStage;
lightStage++;
}
else RV_END
CHECKSC;
}
++light;
light++;
}
else RV_END
CHECKSC;
Expand All @@ -1378,8 +1395,7 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)
}
else
{
// Free memory allocated for the dummy.

/// @todo fixme: Free memory allocated for the dummy.
}
}

Expand Down

0 comments on commit 86f53d2

Please sign in to comment.