Skip to content

Commit

Permalink
Changed: Any material can now be flagged as "sky-masking" resolving t…
Browse files Browse the repository at this point in the history
…he previous limitation which allowed only one material and it had to be a flat. Needed for jDoom64 which has no flats and has multiple sky mask textures.
  • Loading branch information
danij committed Dec 3, 2008
1 parent ef0f477 commit 00957ea
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 125 deletions.
8 changes: 6 additions & 2 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -239,8 +239,6 @@ enum {
DD_GAME_DMUAPI_VER, // Version of the DMU API the game is using.

// Non-integer/special values for Set/Get
DD_SKYMASKMATERIAL_NAME = 0x4000,
DD_SKYMASKMATERIAL_NUM,
DD_TRANSLATIONTABLES_ADDRESS,
DD_TRACE_ADDRESS, // divline 'trace' used by PathTraverse.
DD_SPRITE_REPLACEMENT, // Sprite <-> model replacement.
Expand Down Expand Up @@ -1051,10 +1049,16 @@ typedef enum materialgroup_e {
NUM_MATERIAL_GROUPS
} materialgroup_t;

// Material flags:
#define MATF_NO_DRAW 0x1 // Material should never be drawn.
#define MATF_GLOW 0x2 // Glowing material.
#define MATF_SKYMASK 0x4 // Sky-mask surfaces using this material.

typedef struct {
materialnum_t num;
int group;
int width, height;
byte flags;
} materialinfo_t;

// Animation group flags.
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/api/doomsday.def
@@ -1,7 +1,7 @@
NAME "DOOMSDAY"

; Highest ordinal is currently
; --> 438 <--
; --> 439 <--
; Other free ordinals:
; 43 formerly P_RegisterPlayerControl
; 44 formerly B_FormEventString
Expand Down Expand Up @@ -322,6 +322,7 @@ EXPORTS
R_MaterialCheckNumForIndex @438 NONAME
R_MaterialNumForIndex @437 NONAME
R_MaterialPrecache @436 NONAME
R_MaterialSetSkyMask @439 NONAME
R_PointToAngle2 @101 NONAME
R_PointInSubsector @102 NONAME
R_CreateAnimGroup @241 NONAME
Expand Down
3 changes: 3 additions & 0 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -410,7 +410,10 @@ extern "C" {
materialnum_t R_MaterialNumForIndex(uint idx, materialgroup_t group);
const char* R_MaterialNameForNum(materialnum_t num);
boolean R_MaterialIsCustom(materialnum_t num);

boolean R_MaterialGetInfo(materialnum_t num, materialinfo_t* info);
void R_MaterialSetSkyMask(materialnum_t num, boolean yes);

void R_MaterialPrecache(materialnum_t num);

int R_CreateAnimGroup(int flags);
Expand Down
5 changes: 1 addition & 4 deletions doomsday/engine/portable/include/r_materials.h
Expand Up @@ -50,10 +50,6 @@ typedef struct materialtex_s {
void* instances;
} materialtex_t;

// Material flags:
#define MATF_NO_DRAW 0x1 // Material should never be drawn.
#define MATF_GLOW 0x2 // Glowing material.

typedef struct material_s {
// Material def:
byte flags; // MATF_* flags
Expand Down Expand Up @@ -108,6 +104,7 @@ void R_MaterialSetTranslation(material_t* mat,
boolean R_MaterialGetInfo(materialnum_t num, materialinfo_t* info);
const ded_decor_t* R_MaterialGetDecoration(material_t* mat);
const ded_ptcgen_t* R_MaterialGetPtcGen(material_t* mat);
void R_MaterialSetSkyMask(materialnum_t num, boolean yes);

// Lookup:
material_t* R_GetMaterial(int ofTypeID, materialgroup_t group);
Expand Down
29 changes: 0 additions & 29 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -109,8 +109,6 @@ extern int gameDataFormat;
extern int gameDrawHUD;
extern int symbolicEchoMode;

extern material_t* skyMaskMaterial;

// PUBLIC DATA DEFINITIONS -------------------------------------------------

directory_t ddRuntimeDir, ddBinDir;
Expand Down Expand Up @@ -884,9 +882,6 @@ int DD_GetInteger(int ddvalue)
case DD_WINDOW_HEIGHT:
return theWindow->height;

case DD_SKYMASKMATERIAL_NUM:
return R_GetMaterialNum(skyMaskMaterial);

default:
break;
}
Expand Down Expand Up @@ -927,13 +922,6 @@ void* DD_GetVariable(int ddvalue)
case DD_GAME_EXPORTS:
return &gx;

case DD_SKYMASKMATERIAL_NUM:
{
static materialnum_t num;
num = R_GetMaterialNum(skyMaskMaterial);
return &num;
}

case DD_VIEWX:
return &viewX;

Expand Down Expand Up @@ -1148,23 +1136,6 @@ void DD_SetVariable(int ddvalue, void *parm)
mapGravity = *(float*) parm;
return;

case DD_SKYMASKMATERIAL_NAME:
{
materialnum_t mat;
char name[9];
size_t len;

len = strlen(parm);
if(len > 8)
len = 8;
strncpy(name, parm, len);
name[len] = '\0';

if((mat = R_MaterialNumForName(name, MG_ANY)))
skyMaskMaterial = R_GetMaterialByNum(mat);
}
return;

case DD_PSPRITE_OFFSET_X:
pspOffset[VX] = *(float*) parm;
return;
Expand Down
4 changes: 1 addition & 3 deletions doomsday/engine/portable/src/r_main.c
Expand Up @@ -99,8 +99,6 @@ fixed_t* fineCosine = &finesine[FINEANGLES / 4];
int extraLight; // Bumped light from gun blasts.
float extraLightDelta;

material_t* skyMaskMaterial = NULL;

float frameTimePos; // 0...1: fractional part for sharp game tics.

int loadInStartupMode = false;
Expand Down Expand Up @@ -155,7 +153,7 @@ void R_InitSkyMap(void)
*/
boolean R_IsSkySurface(const surface_t* suf)
{
if(suf && suf->material == skyMaskMaterial)
if(suf && suf->material && (suf->material->flags & MATF_SKYMASK))
return true;

return false;
Expand Down
14 changes: 14 additions & 0 deletions doomsday/engine/portable/src/r_materials.c
Expand Up @@ -1207,10 +1207,24 @@ boolean R_MaterialGetInfo(materialnum_t num, materialinfo_t* info)
info->group = mat->group;
info->width = (int) mat->width;
info->height = (int) mat->height;
info->flags = mat->flags;

return true;
}

void R_MaterialSetSkyMask(materialnum_t num, boolean yes)
{
material_t* mat;

if(!(mat = R_GetMaterialByNum(num)))
return;

if(yes)
mat->flags |= MATF_SKYMASK;
else
mat->flags &= ~MATF_SKYMASK;
}

/**
* Deletes a texture (not for rawlumptexs' etc.).
*/
Expand Down
38 changes: 21 additions & 17 deletions doomsday/engine/portable/src/rend_sky.c
Expand Up @@ -304,31 +304,35 @@ void Rend_SkyRenderer(int hemi)
static void setupFadeout(skylayer_t* slayer)
{
int flags = TEXF_LOAD_AS_SKY;
materialtexinst_t* texInst;

if(slayer->flags & SLF_MASKED)
flags |= TEXF_TEX_ZEROMASK;

// Ensure we have up to date info on the material tex.
texInst = R_MaterialPrepare(slayer->mat->current, flags, NULL, NULL, NULL);
if(texInst)
if(slayer->mat)
{
int i;

slayer->fadeout.rgb[CR] = texInst->topColor[CR];
slayer->fadeout.rgb[CG] = texInst->topColor[CG];
slayer->fadeout.rgb[CB] = texInst->topColor[CB];
materialtexinst_t* texInst =
R_MaterialPrepare(slayer->mat->current, flags, NULL, NULL, NULL);

// Determine if it should be used.
for(slayer->fadeout.use = false, i = 0; i < 3; ++i)
if(slayer->fadeout.rgb[i] > slayer->fadeout.limit)
{
// Colored fadeout is needed.
slayer->fadeout.use = true;
break;
}
if(texInst)
{
int i;

slayer->fadeout.rgb[CR] = texInst->topColor[CR];
slayer->fadeout.rgb[CG] = texInst->topColor[CG];
slayer->fadeout.rgb[CB] = texInst->topColor[CB];

// Determine if it should be used.
for(slayer->fadeout.use = false, i = 0; i < 3; ++i)
if(slayer->fadeout.rgb[i] > slayer->fadeout.limit)
{
// Colored fadeout is needed.
slayer->fadeout.use = true;
break;
}

return;
return;
}
}

// An invalid texture, default to black.
Expand Down
20 changes: 19 additions & 1 deletion doomsday/plugins/common/src/g_game.c
Expand Up @@ -503,7 +503,25 @@ void G_CommonPostInit(void)
XG_Register(); // Register XG classnames.
#endif

DD_SetVariable(DD_SKYMASKMATERIAL_NAME, SKYFLATNAME);
// Inform the engine which materials to sky-mask.
#if __JDOOM64__
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYA", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYB", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYC", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYD", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYE", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYF", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYG", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYH", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYI", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYJ", MG_TEXTURES), true);
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKYK", MG_TEXTURES), true);
#elif __JHEXEN__
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKY", MG_FLATS), true);
#else
R_MaterialSetSkyMask(R_MaterialNumForName("F_SKY1", MG_FLATS), true);
#endif

R_SetViewSize(cfg.screenBlocks);
R_SetBorderGfx(borderLumps);

Expand Down
26 changes: 15 additions & 11 deletions doomsday/plugins/common/src/p_map.c
Expand Up @@ -1516,24 +1516,22 @@ boolean PTR_ShootTraverse(intercept_t* in)
if(backSec)
{
float fFloor, bFloor, fCeil, bCeil;
boolean skyFloor, skyCeil;
materialinfo_t info;

// Is it a sky hack wall? If the hitpoint is beyond the visible
// surface, no puff must be shown.
skyCeil = P_GetIntp(frontSec, DMU_CEILING_MATERIAL) ==
SKYMASKMATERIAL;
R_MaterialGetInfo(P_GetIntp(frontSec, DMU_CEILING_MATERIAL), &info);
fCeil = P_GetFloatp(frontSec, DMU_CEILING_HEIGHT);
bCeil = P_GetFloatp(backSec, DMU_CEILING_HEIGHT);

if(skyCeil && (pos[VZ] > fCeil || pos[VZ] > bCeil))
if((info.flags & MATF_SKYMASK) && (pos[VZ] > fCeil || pos[VZ] > bCeil))
return false;

skyFloor = P_GetIntp(backSec, DMU_FLOOR_MATERIAL) ==
SKYMASKMATERIAL;
R_MaterialGetInfo(P_GetIntp(backSec, DMU_FLOOR_MATERIAL), &info);
fFloor = P_GetFloatp(frontSec, DMU_FLOOR_HEIGHT);
bFloor = P_GetFloatp(backSec, DMU_FLOOR_HEIGHT);

if(skyFloor && (pos[VZ] < fFloor || pos[VZ] < bFloor))
if((info.flags & MATF_SKYMASK) && (pos[VZ] < fFloor || pos[VZ] < bFloor))
return false;
}

Expand All @@ -1548,6 +1546,8 @@ boolean PTR_ShootTraverse(intercept_t* in)

if(d[VZ] != 0)
{
materialinfo_t info;

contact = R_PointInSubsector(pos[VX], pos[VY]);
step = P_ApproxDistance3(d[VX], d[VY], d[VZ]);
stepv[VX] = d[VX] / step;
Expand All @@ -1573,11 +1573,15 @@ boolean PTR_ShootTraverse(intercept_t* in)
cBottom = cFloor + 4;
divisor = 2;

R_MaterialGetInfo(P_GetIntp(contact, DMU_CEILING_MATERIAL), &info);

// We must not hit a sky plane.
if((pos[VZ] > cTop &&
P_GetIntp(contact, DMU_CEILING_MATERIAL) == SKYMASKMATERIAL) ||
(pos[VZ] < cBottom &&
P_GetIntp(contact, DMU_FLOOR_MATERIAL) == SKYMASKMATERIAL))
if(pos[VZ] > cTop && (info.flags & MATF_SKYMASK))
return false;

R_MaterialGetInfo(P_GetIntp(contact, DMU_FLOOR_MATERIAL), &info);

if(pos[VZ] < cBottom && (info.flags & MATF_SKYMASK))
return false;

// Find the approximate hitpoint by stepping back and
Expand Down
4 changes: 0 additions & 4 deletions doomsday/plugins/jdoom/include/doomdef.h
Expand Up @@ -253,8 +253,4 @@ enum { VX, VY, VZ }; // Vertex indices.
#define DISPLAYPLAYER (Get(DD_DISPLAYPLAYER))

#define GAMETIC (*((timespan_t*) DD_GetVariable(DD_GAMETIC)))

#define SKYMASKMATERIAL (Get(DD_SKYMASKMATERIAL_NUM))
#define SKYFLATNAME ("F_SKY1")

#endif
28 changes: 20 additions & 8 deletions doomsday/plugins/jdoom/src/p_mobj.c
Expand Up @@ -275,8 +275,11 @@ void P_MobjMoveXY(mobj_t *mo)
if(ceilingLine &&
(backSec = P_GetPtrp(ceilingLine, DMU_BACK_SECTOR)))
{
if(P_GetIntp(backSec,
DMU_CEILING_MATERIAL) == SKYMASKMATERIAL &&
materialinfo_t info;

R_MaterialGetInfo(P_GetIntp(backSec, DMU_CEILING_MATERIAL), &info);

if((info.flags & MATF_SKYMASK) &&
mo->pos[VZ] > P_GetFloatp(backSec, DMU_CEILING_HEIGHT))
{
P_MobjRemove(mo, false);
Expand All @@ -287,8 +290,11 @@ void P_MobjMoveXY(mobj_t *mo)
if(floorLine &&
(backSec = P_GetPtrp(floorLine, DMU_BACK_SECTOR)))
{
if(P_GetIntp(backSec,
DMU_FLOOR_MATERIAL) == SKYMASKMATERIAL &&
materialinfo_t info;

R_MaterialGetInfo(P_GetIntp(backSec, DMU_FLOOR_MATERIAL), &info);

if((info.flags & MATF_SKYMASK) &&
mo->pos[VZ] < P_GetFloatp(backSec, DMU_FLOOR_HEIGHT))
{
P_MobjRemove(mo, false);
Expand Down Expand Up @@ -567,9 +573,12 @@ void P_MobjMoveZ(mobj_t* mo)

if(!((mo->flags ^ MF_MISSILE) & (MF_MISSILE | MF_NOCLIP)))
{
materialinfo_t info;

R_MaterialGetInfo(P_GetIntp(mo->subsector, DMU_FLOOR_MATERIAL), &info);

// Don't explode against sky.
if(P_GetIntp(mo->subsector, DMU_FLOOR_MATERIAL) ==
SKYMASKMATERIAL)
if(info.flags & MATF_SKYMASK)
{
P_MobjRemove(mo, false);
}
Expand All @@ -595,9 +604,12 @@ void P_MobjMoveZ(mobj_t* mo)

if(!((mo->flags ^ MF_MISSILE) & (MF_MISSILE | MF_NOCLIP)))
{
materialinfo_t info;

R_MaterialGetInfo(P_GetIntp(mo->subsector, DMU_CEILING_MATERIAL), &info);

// Don't explode against sky.
if(P_GetIntp(mo->subsector, DMU_CEILING_MATERIAL) ==
SKYMASKMATERIAL)
if(info.flags & MATF_SKYMASK)
{
P_MobjRemove(mo, false);
}
Expand Down
3 changes: 0 additions & 3 deletions doomsday/plugins/jdoom64/include/doomdef.h
Expand Up @@ -250,9 +250,6 @@ enum { VX, VY, VZ }; // Vertex indices.

#define GAMETIC (*((timespan_t*) DD_GetVariable(DD_GAMETIC)))

#define SKYMASKMATERIAL (Get(DD_SKYMASKMATERIAL_NUM))
#define SKYFLATNAME ("F_SKY1")

#define SFXVOLUME (Get(DD_SFX_VOLUME) / 17)
#define MUSICVOLUME (Get(DD_MUSIC_VOLUME) / 17)

Expand Down

0 comments on commit 00957ea

Please sign in to comment.