Skip to content

Commit

Permalink
Continued work on the materials system. Don't forget to rebuild resou…
Browse files Browse the repository at this point in the history
…rces (packres) as the games' DED files have changed:

* Material definitions are now read in release builds.
* Enhanced Material definitions so they can be used to patch automatically generated materials (not all paramaters need to be specified). Relaxed lookup rules when patching; a material group need not be specified. If no group is specified do a priority order search when looking for the material to be patched.
* Removed the Glow block from Decoration definitions, now that we have Material definitions this is unnecessary.
* Converted the Decoration definitions for glowing flats/textures to Material definitions.
  • Loading branch information
danij committed Jan 4, 2009
1 parent 61b3269 commit da4ba76
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 227 deletions.
1 change: 0 additions & 1 deletion doomsday/engine/portable/include/def_data.h
Expand Up @@ -488,7 +488,6 @@ typedef struct ded_decormodel_s {
typedef struct ded_decor_s {
ded_string_t materialName;
materialgroup_t materialGroup;
int glow;
ded_flags_t flags;
ded_decorlight_t lights[DED_DECOR_NUM_LIGHTS];
ded_decormodel_t models[DED_DECOR_NUM_MODELS];
Expand Down
1 change: 0 additions & 1 deletion doomsday/engine/portable/src/def_data.c
Expand Up @@ -540,7 +540,6 @@ int DED_AddDecoration(ded_t *ded)
int i;

// Init some default values.
decor->glow = 0;
for(i = 0; i < DED_DECOR_NUM_LIGHTS; ++i)
{
// The color (0,0,0) means the light is not active.
Expand Down
32 changes: 15 additions & 17 deletions doomsday/engine/portable/src/def_main.c
Expand Up @@ -905,23 +905,21 @@ void Def_Read(void)
for(i = 0; i < defs.count.materials.num; ++i)
{
ded_material_t* def = &defs.materials[i];
materialtex_t* mTex = NULL;

if(def->layers[0].type == -1)
continue; // Unused.

// Sanity checks:
if(def->width < 0)
def->width = -def->width;
def->width = MAX_OF(1, def->width);
if(def->height < 0)
def->height = -def->height;
def->height = MAX_OF(1, def->height);

mTex = R_GetMaterialTex(def->layers[0].name, def->layers[0].type);

R_MaterialCreate(def->name, def->width, def->height, def->flags, mTex,
def->group);
materialtex_t* mTex = NULL; // No change.
float width = -1, height = -1; // No change.
materialgroup_t groupNum = MG_ANY; // No change.

// Sanitize so that when updating we only change what is requested.
if(def->width > 0)
width = MAX_OF(1, def->width);
if(def->height > 0)
height = MAX_OF(1, def->height);
if(def->layers[0].type != -1) // Not unused.
mTex = R_GetMaterialTex(def->layers[0].name, def->layers[0].type);
if(def->group != MG_ANY)
groupNum = def->group;

R_MaterialCreate(def->name, width, height, def->flags, mTex, groupNum);
}

// Dynamic lights. Update the sprite numbers.
Expand Down
15 changes: 1 addition & 14 deletions doomsday/engine/portable/src/def_read.c
Expand Up @@ -995,7 +995,6 @@ static int DED_ReadData(ded_t* ded, char* buffer, const char* sourceFile)
prevLightDefIdx = idx;
}

#if _DEBUG
if(ISTOKEN("Material"))
{
uint layer;
Expand Down Expand Up @@ -1048,7 +1047,7 @@ static int DED_ReadData(ded_t* ded, char* buffer, const char* sourceFile)
}
prevMaterialDefIdx = idx;
}
#endif

if(ISTOKEN("Model"))
{
uint sub;
Expand Down Expand Up @@ -1737,18 +1736,6 @@ static int DED_ReadData(ded_t* ded, char* buffer, const char* sourceFile)
READSTR(decor->materialName)
decor->materialGroup = MG_FLATS;
}
else if(ISLABEL("Glow"))
{
decor->glow = true;
FINDBEGIN;
for(;;)
{
READLABEL;
// No paramaters yet.
CHECKSC;
}
sub++;
}
else if(ISLABEL("Model"))
{
ded_decormodel_t *dm = &decor->models[sub];
Expand Down
70 changes: 47 additions & 23 deletions doomsday/engine/portable/src/r_materials.c
Expand Up @@ -613,14 +613,15 @@ materialtex_t* R_GetMaterialTexByNum(int ofTypeID, materialtextype_t type)
* @param flags MATF_* material flags
* @param mTex Texture to use with this material.
* @param group MG_* material group.
* MG_ANY is only valid when updating an existing material.
*
* @return The created material, ELSE @c NULL.
*/
material_t* R_MaterialCreate(const char* rawName, short width, short height,
byte flags, materialtex_t* mTex,
materialgroup_t groupNum)
{
materialnum_t i;
materialnum_t oldMat;
material_t* mat;
int n;
uint hash;
Expand All @@ -641,33 +642,50 @@ Con_Message("R_MaterialCreate: Warning, attempted to create material with "
return NULL;
}

if(!isValidMaterialGroup(groupNum))
{
#if _DEBUG
Con_Message("R_MaterialCreate: Warning, attempted to create material in "
"unknown group '%i'.\n", (int) groupNum);
return NULL;
#endif
}

// Prepare 'name'.
for(n = 0; *rawName && n < 8; ++n, rawName++)
name[n] = tolower(*rawName);
name[n] = '\0';
hash = hashForName(name);

// Check if we've already created a material for this.
if((i = getMaterialNumForName(name, hash, groupNum)))
if(groupNum == MG_ANY)
{ // Caller doesn't care which group. This is only valid if we can
// find a material by this name using a priority search order.
oldMat = getMaterialNumForName(name, hash, MG_SPRITES);
if(!oldMat)
oldMat = getMaterialNumForName(name, hash, MG_TEXTURES);
if(!oldMat)
oldMat = getMaterialNumForName(name, hash, MG_FLATS);
}
else
{
materialbind_t* mb = &materialBinds[i - 1];
if(!isValidMaterialGroup(groupNum))
{
#if _DEBUG
Con_Message("R_MaterialCreate: Warning, attempted to create material in "
"unknown group '%i'.\n", (int) groupNum);
#endif
return NULL;
}

oldMat = getMaterialNumForName(name, hash, groupNum);
}

if(oldMat)
{ // We are updating an existing material.
materialbind_t* mb = &materialBinds[oldMat - 1];

mat = mb->mat;

// Update the (possibly new) meta data.
mat->tex = mTex;
if(mTex)
mat->tex = mTex;
mat->flags = flags;
mat->width = width;
mat->height = height;
if(width > 0)
mat->width = width;
if(height > 0)
mat->height = height;
mat->inAnimGroup = false;
mat->current = mat->next = mat;
mat->inter = 0;
Expand All @@ -679,7 +697,19 @@ Con_Message("R_MaterialCreate: Warning, attempted to create material in "
return mat; // Yep, return it.
}

// A new material.
if(groupNum == MG_ANY)
{
#if _DEBUG
Con_Message("R_MaterialCreate: Warning, attempted to create material "
"without groupNum.\n");
#endif
return NULL;
}

/**
* A new material.
*/

mat = Z_BlockNewElement(materialsBlockSet);
memset(mat, 0, sizeof(*mat));
mat->group = groupNum;
Expand Down Expand Up @@ -782,13 +812,7 @@ materialtexinst_t* R_MaterialPrepare(struct material_s* mat, int flags,

// We need to update the assocated enhancements.
// Material decorations.
mat->flags &= ~MATF_GLOW;
if((mat->decoration = Def_GetDecoration(mat, tmpResult == 2)))
{
// A glowing material?
if(mat->decoration->glow)
mat->flags |= MATF_GLOW;
}
mat->decoration = Def_GetDecoration(mat, tmpResult == 2);

// Surface reflection.
{
Expand Down
66 changes: 32 additions & 34 deletions doomsday/plugins/jdoom/defs/doom1lights.ded
Expand Up @@ -21,23 +21,22 @@ SkipIf doom2-tnt;
#
# Glowing flats:
#
Decoration {
Flags = ext;
Flat = "LAVA1";
Glow {
};
}

* Decoration { Flat = "LAVA2"; }
* Decoration { Flat = "LAVA3"; }
* Decoration { Flat = "LAVA4"; }
* Decoration { Flat = "NUKAGE1"; }
* Decoration { Flat = "NUKAGE2"; }
* Decoration { Flat = "NUKAGE3"; }
* Decoration { Flat = "FWATER1"; }
* Decoration { Flat = "FWATER2"; }
* Decoration { Flat = "FWATER3"; }
* Decoration { Flat = "FWATER4"; }
Material {
Name = "LAVA1";
Group = flats;
Flags = glow;
}

* Material { Name = "LAVA2"; }
* Material { Name = "LAVA3"; }
* Material { Name = "LAVA4"; }
* Material { Name = "NUKAGE1"; }
* Material { Name = "NUKAGE2"; }
* Material { Name = "NUKAGE3"; }
* Material { Name = "FWATER1"; }
* Material { Name = "FWATER2"; }
* Material { Name = "FWATER3"; }
* Material { Name = "FWATER4"; }

#
# Flats:
Expand Down Expand Up @@ -102,23 +101,22 @@ Copy Decoration {
#
# Glowing textures:
#
Decoration {
Flags = ext;
Texture = "FIREBLU1";
Glow {
};
}

* Decoration { Texture = "FIREBLU2"; }
* Decoration { Texture = "FIRELAVA"; }
* Decoration { Texture = "FIRELAV2"; }
* Decoration { Texture = "FIRELAV3"; }
* Decoration { Texture = "FIREMAG1"; }
* Decoration { Texture = "FIREMAG2"; }
* Decoration { Texture = "FIREMAG3"; }
* Decoration { Texture = "FIREWALL"; }
* Decoration { Texture = "FIREWALA"; }
* Decoration { Texture = "FIREWALB"; }
Material {
Name = "FIREBLU1";
Group = textures;
Flags = glow;
}

* Material { Name = "FIREBLU2"; }
* Material { Name = "FIRELAVA"; }
* Material { Name = "FIRELAV2"; }
* Material { Name = "FIRELAV3"; }
* Material { Name = "FIREMAG1"; }
* Material { Name = "FIREMAG2"; }
* Material { Name = "FIREMAG3"; }
* Material { Name = "FIREWALL"; }
* Material { Name = "FIREWALA"; }
* Material { Name = "FIREWALB"; }

Decoration {
Texture = "COMP2";
Expand Down
58 changes: 28 additions & 30 deletions doomsday/plugins/jdoom/defs/doom2-plutlights.ded
Expand Up @@ -20,41 +20,39 @@ SkipIf Not doom2-plut;
#
# Glowing flats:
#
Decoration {
Flags = ext;
Flat = "LAVA1";
Glow {
};
Material {
Name = "LAVA1";
Group = flats;
Flags = glow;
}

* Decoration { Flat = "LAVA2"; }
* Decoration { Flat = "LAVA3"; }
* Decoration { Flat = "LAVA4"; }
* Decoration { Flat = "NUKAGE1"; }
* Decoration { Flat = "NUKAGE2"; }
* Decoration { Flat = "NUKAGE3"; }
* Decoration { Flat = "FWATER1"; }
* Decoration { Flat = "FWATER2"; }
* Decoration { Flat = "FWATER3"; }
* Decoration { Flat = "FWATER4"; }
* Material { Name = "LAVA2"; }
* Material { Name = "LAVA3"; }
* Material { Name = "LAVA4"; }
* Material { Name = "NUKAGE1"; }
* Material { Name = "NUKAGE2"; }
* Material { Name = "NUKAGE3"; }
* Material { Name = "FWATER1"; }
* Material { Name = "FWATER2"; }
* Material { Name = "FWATER3"; }
* Material { Name = "FWATER4"; }

#
# Glowing textures:
#
Decoration {
Flags = ext;
Texture = "FIREBLU1";
Glow {
};
Mterial {
Name = "FIREBLU1";
Group = textures;
Flags = glow;
}

* Decoration { Texture = "FIREBLU2"; }
* Decoration { Texture = "FIRELAVA"; }
* Decoration { Texture = "FIRELAV2"; }
* Decoration { Texture = "FIRELAV3"; }
* Decoration { Texture = "FIREMAG1"; }
* Decoration { Texture = "FIREMAG2"; }
* Decoration { Texture = "FIREMAG3"; }
* Decoration { Texture = "FIREWALL"; }
* Decoration { Texture = "FIREWALA"; }
* Decoration { Texture = "FIREWALB"; }
* Material { Name = "FIREBLU2"; }
* Material { Name = "FIRELAVA"; }
* Material { Name = "FIRELAV2"; }
* Material { Name = "FIRELAV3"; }
* Material { Name = "FIREMAG1"; }
* Material { Name = "FIREMAG2"; }
* Material { Name = "FIREMAG3"; }
* Material { Name = "FIREWALL"; }
* Material { Name = "FIREWALA"; }
* Material { Name = "FIREWALB"; }

0 comments on commit da4ba76

Please sign in to comment.