From 1de411020de3833e3015aa8827c42758a6a43ab6 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Fri, 26 Jan 2024 18:23:02 -0300 Subject: [PATCH] Changes: - Implemented Lua support for side overlays - OpenGL: Fixed rendering of overlays in one-sided walls - Made edge flags into its own enumeration --- src/hardware/hw_main.c | 131 +++++++++++++++++++++-------------- src/lua_baselib.c | 1 + src/lua_libs.h | 1 + src/lua_maplib.c | 153 +++++++++++++++++++++++++++++++++++++++++ src/lua_script.c | 4 ++ src/p_setup.c | 24 +++---- src/r_defs.h | 28 +++----- src/r_segs.c | 12 ++-- 8 files changed, 267 insertions(+), 87 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 1c09227ed..bb5cb6d86 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1244,7 +1244,7 @@ static void HWR_GetExtraTextureCoords(unsigned which, fixed_t *top, fixed_t *bot fixed_t rowoffset = FixedDiv(gl_sidedef->rowoffset + gl_sidedef->overlays[which].offsety, abs(gl_sidedef->overlays[which].scaley)); - if (gl_sidedef->flags & GET_SIDEFLAG_EDGENOSKEW(which)) + if (gl_sidedef->overlays[which].flags & SIDEOVERLAYFLAG_NOSKEW) { if (IS_TOP_EDGE_TEXTURE(which)) { @@ -1357,12 +1357,13 @@ static void HWR_DoExtraTextureCut(UINT8 intersected, UINT8 which, v2d_t vs, v2d_ *worldbottom = P_GetSectorFloorZAt(gl_frontsector, v1x, v1y); *worldbottomslope = P_GetSectorFloorZAt(gl_frontsector, v2x, v2y); - sector_t *back = gl_backsector ? gl_backsector : gl_frontsector; - - *worldhigh = P_GetSectorCeilingZAt(back, v1x, v1y); - *worldhighslope = P_GetSectorCeilingZAt(back, v2x, v2y); - *worldlow = P_GetSectorFloorZAt(back, v1x, v1y); - *worldlowslope = P_GetSectorFloorZAt(back, v2x, v2y); + if (gl_backsector) + { + *worldhigh = P_GetSectorCeilingZAt(gl_backsector, v1x, v1y); + *worldhighslope = P_GetSectorCeilingZAt(gl_backsector, v2x, v2y); + *worldlow = P_GetSectorFloorZAt(gl_backsector, v1x, v1y); + *worldlowslope = P_GetSectorFloorZAt(gl_backsector, v2x, v2y); + } HWR_GetExtraTextureCoords(which, polytop, polybottom, polytopslope, polybottomslope, *worldtop, *worldbottom, *worldhigh, *worldlow, *worldtopslope, *worldbottomslope, *worldhighslope, *worldlowslope, midtexheight); } @@ -1385,10 +1386,12 @@ static void HWR_SetWallEndCoordsOffset(FOutVector wallVerts[4], float wallx2, fl wallVerts[2].z = wallVerts[1].z = wally2; } -// Draws an extra texture (sorry for the length) +// Draws an extra texture static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcliplow, float xcliphigh, UINT32 lightnum) { - INT32 texnum = R_GetTextureNum(gl_sidedef->overlays[which].texture); + side_overlay_t *overlay = &gl_sidedef->overlays[which]; + + INT32 texnum = R_GetTextureNum(overlay->texture); if (texnum <= 0 || texnum >= numtextures) return; @@ -1402,23 +1405,18 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl float flength = gl_curline->flength; - sector_t *back = gl_backsector ? gl_backsector : gl_frontsector; - fixed_t worldtop = P_GetSectorCeilingZAt(gl_frontsector, v1x, v1y); fixed_t worldtopslope = P_GetSectorCeilingZAt(gl_frontsector, v2x, v2y); fixed_t worldbottom = P_GetSectorFloorZAt(gl_frontsector, v1x, v1y); fixed_t worldbottomslope = P_GetSectorFloorZAt(gl_frontsector, v2x, v2y); - fixed_t worldhigh = P_GetSectorCeilingZAt(back, v1x, v1y); - fixed_t worldhighslope = P_GetSectorCeilingZAt(back, v2x, v2y); - fixed_t worldlow = P_GetSectorFloorZAt(back, v1x, v1y); - fixed_t worldlowslope = P_GetSectorFloorZAt(back, v2x, v2y); + fixed_t worldhigh = 0, worldhighslope = 0, worldlow = 0, worldlowslope = 0; - fixed_t texheight = FixedDiv(textureheight[texnum], abs(gl_sidedef->overlays[which].scaley)); + fixed_t texheight = FixedDiv(textureheight[texnum], abs(overlay->scaley)); INT32 repeats; - if (gl_sidedef->flags & GET_SIDEFLAG_EDGEWRAP(which)) + if (overlay->flags & SIDEOVERLAYFLAG_WRAP) { fixed_t high, low; @@ -1467,8 +1465,8 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl repeats = 1; GLMapTexture_t *grTex = HWR_GetTexture(texnum); - float xscale = FixedToFloat(gl_sidedef->overlays[which].scalex); - float yscale = FixedToFloat(gl_sidedef->overlays[which].scaley); + float xscale = FixedToFloat(overlay->scalex); + float yscale = FixedToFloat(overlay->scaley); float xcliplowbase = xcliplow; float xclipoffset = 0.0f; @@ -1479,25 +1477,43 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl // Find the wall's coordinates fixed_t midtexheight = texheight * repeats; + if (gl_backsector) + { + worldhigh = P_GetSectorCeilingZAt(gl_backsector, v1x, v1y); + worldhighslope = P_GetSectorCeilingZAt(gl_backsector, v2x, v2y); + worldlow = P_GetSectorFloorZAt(gl_backsector, v1x, v1y); + worldlowslope = P_GetSectorFloorZAt(gl_backsector, v2x, v2y); + } + HWR_GetExtraTextureCoords(which, &polytop, &polybottom, &polytopslope, &polybottomslope, worldtop, worldbottom, worldhigh, worldlow, worldtopslope, worldbottomslope, worldhighslope, worldlowslope, midtexheight); // Find where to cut it fixed_t lowcut, highcut; fixed_t lowcutslope, highcutslope; - if (IS_TOP_EDGE_TEXTURE(which)) + if (!gl_backsector) { - lowcut = worldhigh; + lowcut = worldbottom; highcut = worldtop; - lowcutslope = worldhighslope; + lowcutslope = worldbottomslope; highcutslope = worldtopslope; } else { - lowcut = worldbottom; - highcut = worldlow; - lowcutslope = worldbottomslope; - highcutslope = worldlowslope; + if (IS_TOP_EDGE_TEXTURE(which)) + { + lowcut = worldhigh; + highcut = worldtop; + lowcutslope = worldhighslope; + highcutslope = worldtopslope; + } + else + { + lowcut = worldbottom; + highcut = worldlow; + lowcutslope = worldbottomslope; + highcutslope = worldlowslope; + } } // Time to render the wall (or so you thought) @@ -1605,19 +1621,29 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl HWR_GetExtraTextureCoords(which, &polytop, &polybottom, &polytopslope, &polybottomslope, worldtop, worldbottom, worldhigh, worldlow, worldtopslope, worldbottomslope, worldhighslope, worldlowslope, midtexheight); - if (IS_TOP_EDGE_TEXTURE(which)) + if (!gl_backsector) { - lowcut = worldhigh; + lowcut = worldbottom; highcut = worldtop; - lowcutslope = worldhighslope; + lowcutslope = worldbottomslope; highcutslope = worldtopslope; } else { - lowcut = worldbottom; - highcut = worldlow; - lowcutslope = worldbottomslope; - highcutslope = worldlowslope; + if (IS_TOP_EDGE_TEXTURE(which)) + { + lowcut = worldhigh; + highcut = worldtop; + lowcutslope = worldhighslope; + highcutslope = worldtopslope; + } + else + { + lowcut = worldbottom; + highcut = worldlow; + lowcutslope = worldbottomslope; + highcutslope = worldlowslope; + } } h = polytop; @@ -1773,12 +1799,12 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl // Left side wallVerts[3].t = texturevpeg * yscale * grTex->scaleY; wallVerts[0].t = (h - l + texturevpeg) * yscale * grTex->scaleY; - wallVerts[0].s = wallVerts[3].s = ((xcliplow * xscale) + gl_sidedef->overlays[which].offsetx) * grTex->scaleX; + wallVerts[0].s = wallVerts[3].s = ((xcliplow * xscale) + overlay->offsetx) * grTex->scaleX; // Right side wallVerts[2].t = texturevpegslope * yscale * grTex->scaleY; wallVerts[1].t = (hS - lS + texturevpegslope) * yscale * grTex->scaleY; - wallVerts[2].s = wallVerts[1].s = ((xcliphigh * xscale) + gl_sidedef->overlays[which].offsetx) * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = ((xcliphigh * xscale) + overlay->offsetx) * grTex->scaleX; // set top/bottom coords // Take the texture peg into account, rather than changing the offsets past @@ -1831,10 +1857,13 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl worldbottom = P_GetSectorFloorZAt(gl_frontsector, v1x, v1y); worldbottomslope = P_GetSectorFloorZAt(gl_frontsector, v2x, v2y); - worldhigh = P_GetSectorCeilingZAt(back, v1x, v1y); - worldhighslope = P_GetSectorCeilingZAt(back, v2x, v2y); - worldlow = P_GetSectorFloorZAt(back, v1x, v1y); - worldlowslope = P_GetSectorFloorZAt(back, v2x, v2y); + if (gl_backsector) + { + worldhigh = P_GetSectorCeilingZAt(gl_backsector, v1x, v1y); + worldhighslope = P_GetSectorCeilingZAt(gl_backsector, v2x, v2y); + worldlow = P_GetSectorFloorZAt(gl_backsector, v1x, v1y); + worldlowslope = P_GetSectorFloorZAt(gl_backsector, v2x, v2y); + } HWR_GetExtraTextureCoords(which, &polytop, &polybottom, &polytopslope, &polybottomslope, worldtop, worldbottom, worldhigh, worldlow, worldtopslope, worldbottomslope, worldhighslope, worldlowslope, midtexheight); @@ -1866,12 +1895,12 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcl // Left side wallVerts[3].t = texturevpeg * yscale * grTex->scaleY; wallVerts[0].t = (h - l + texturevpeg) * yscale * grTex->scaleY; - wallVerts[0].s = wallVerts[3].s = ((xcliplow * xscale) + gl_sidedef->overlays[which].offsetx) * grTex->scaleX; + wallVerts[0].s = wallVerts[3].s = ((xcliplow * xscale) + overlay->offsetx) * grTex->scaleX; // Right side wallVerts[2].t = texturevpegslope * yscale * grTex->scaleY; wallVerts[1].t = (hS - lS + texturevpegslope) * yscale * grTex->scaleY; - wallVerts[2].s = wallVerts[1].s = ((xcliphigh * xscale) + gl_sidedef->overlays[which].offsetx) * grTex->scaleX; + wallVerts[2].s = wallVerts[1].s = ((xcliphigh * xscale) + overlay->offsetx) * grTex->scaleX; if (gl_frontsector->numlights) HWR_SplitWall(gl_frontsector, wallVerts, texnum, &Surf, FOF_CUTLEVEL, NULL, blendmode); @@ -2169,14 +2198,14 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (gl_midtexture) HWR_RenderMidtexture(gl_midtexture, cliplow, cliphigh, worldtop, worldbottom, worldhigh, worldlow, worldtopslope, worldbottomslope, worldhighslope, worldlowslope, lightnum, wallVerts); - // Render extra textures - for (unsigned i = 0; i < NUM_WALL_OVERLAYS; i++) - HWR_RenderExtraTexture(i, vs, ve, cliplow, cliphigh, lightnum); - - // Sky culling - // No longer so much a mess as before! if (!gl_curline->polyseg) // Don't do it for polyobjects { + // Render extra textures + for (unsigned i = 0; i < NUM_WALL_OVERLAYS; i++) + HWR_RenderExtraTexture(i, vs, ve, cliplow, cliphigh, lightnum); + + // Sky culling + // No longer so much a mess as before! if (gl_frontsector->ceilingpic == skyflatnum && gl_backsector->ceilingpic != skyflatnum) // don't cull if back sector is also sky { @@ -2255,12 +2284,12 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } } - // Render extra textures - for (unsigned i = 0; i < NUM_WALL_OVERLAYS; i++) - HWR_RenderExtraTexture(i, vs, ve, cliplow, cliphigh, lightnum); - if (!gl_curline->polyseg) { + // Render extra textures + HWR_RenderExtraTexture(EDGE_TEXTURE_TOP_UPPER, vs, ve, cliplow, cliphigh, lightnum); + HWR_RenderExtraTexture(EDGE_TEXTURE_BOTTOM_LOWER, vs, ve, cliplow, cliphigh, lightnum); + if (gl_frontsector->ceilingpic == skyflatnum) // It's a single-sided line with sky for its sector { wallVerts[2].y = wallVerts[3].y = FIXED_TO_FLOAT(INT32_MAX); // draw to top of map space diff --git a/src/lua_baselib.c b/src/lua_baselib.c index b70c63ece..b15f2146a 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -175,6 +175,7 @@ static const struct { {META_VERTEX, "vertex_t"}, {META_LINE, "line_t"}, {META_SIDE, "side_t"}, + {META_SIDEOVERLAY, "side_t.overlay"}, {META_SUBSECTOR, "subsector_t"}, {META_SECTOR, "sector_t"}, {META_FFLOOR, "ffloor_t"}, diff --git a/src/lua_libs.h b/src/lua_libs.h index a90d8ac7f..374fb4970 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -55,6 +55,7 @@ extern boolean ignoregameinputs; #define META_SEG "SEG_T*" #define META_NODE "NODE_T*" #endif +#define META_SIDEOVERLAY "SIDE_T*OVERLAY" #define META_SLOPE "PSLOPE_T*" #define META_VECTOR2 "VECTOR2_T" #define META_VECTOR3 "VECTOR3_T" diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 5b80d4d38..ea714ba7a 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -209,6 +209,10 @@ enum side_e { side_toptexture, side_bottomtexture, side_midtexture, + side_edge_top_upper, + side_edge_top_lower, + side_edge_bottom_upper, + side_edge_bottom_lower, side_line, side_sector, side_special, @@ -237,6 +241,10 @@ static const char *const side_opt[] = { "toptexture", "bottomtexture", "midtexture", + "edge_top_upper", + "edge_top_lower", + "edge_bottom_upper", + "edge_bottom_lower", "line", "sector", "special", @@ -1297,6 +1305,22 @@ static int side_get(lua_State *L) case side_midtexture: lua_pushinteger(L, side->midtexture); return 1; + case side_edge_top_upper: + LUA_PushUserdata(L, &side->overlays[EDGE_TEXTURE_TOP_UPPER], META_SIDEOVERLAY); + return 1; + case side_edge_top_lower: + if (side->line->backsector == NULL) + return 0; + LUA_PushUserdata(L, &side->overlays[EDGE_TEXTURE_TOP_LOWER], META_SIDEOVERLAY); + return 1; + case side_edge_bottom_upper: + if (side->line->backsector == NULL) + return 0; + LUA_PushUserdata(L, &side->overlays[EDGE_TEXTURE_BOTTOM_UPPER], META_SIDEOVERLAY); + return 1; + case side_edge_bottom_lower: + LUA_PushUserdata(L, &side->overlays[EDGE_TEXTURE_BOTTOM_LOWER], META_SIDEOVERLAY); + return 1; case side_line: LUA_PushUserdata(L, side->line, META_LINE); return 1; @@ -1352,6 +1376,10 @@ static int side_set(lua_State *L) case side_sector: case side_special: case side_text: + case side_edge_top_upper: + case side_edge_top_lower: + case side_edge_bottom_upper: + case side_edge_bottom_lower: return luaL_error(L, "side_t field " LUA_QS " cannot be set.", side_opt[field]); default: return luaL_error(L, "side_t has no field named " LUA_QS ".", lua_tostring(L, 2)); @@ -1422,6 +1450,129 @@ static int side_num(lua_State *L) return 1; } +//////////////////// +// side_overlay_t // +//////////////////// + +enum sideoverlay_e { + sideoverlay_valid = 0, + sideoverlay_texture, + sideoverlay_offsetx, + sideoverlay_offsety, + sideoverlay_scalex, + sideoverlay_scaley, + sideoverlay_noskew, + sideoverlay_wrap +}; + +static const char *const sideoverlay_opt[] = { + "valid", + "texture", + "offsetx", + "offsety", + "scalex", + "scaley", + "noskew", + "wrap", + NULL}; + +static int sideoverlay_fields_ref = LUA_NOREF; + +static int sideoverlay_get(lua_State *L) +{ + side_overlay_t *overlay = *((side_overlay_t **)luaL_checkudata(L, 1, META_SIDEOVERLAY)); + enum sideoverlay_e field = Lua_optoption(L, 2, sideoverlay_valid, sideoverlay_fields_ref); + + if (!overlay) + { + if (field == sideoverlay_valid) { + lua_pushboolean(L, 0); + return 1; + } + return luaL_error(L, "accessed side_t.overlay doesn't exist anymore."); + } + + switch(field) + { + case sideoverlay_valid: + lua_pushboolean(L, 1); + return 1; + case sideoverlay_texture: + lua_pushinteger(L, overlay->texture); + return 1; + case sideoverlay_offsetx: + lua_pushfixed(L, overlay->offsetx); + return 1; + case sideoverlay_offsety: + lua_pushfixed(L, overlay->offsety); + return 1; + case sideoverlay_scalex: + lua_pushfixed(L, overlay->scalex); + return 1; + case sideoverlay_scaley: + lua_pushfixed(L, overlay->scaley); + return 1; + case sideoverlay_noskew: + lua_pushboolean(L, overlay->flags & SIDEOVERLAYFLAG_NOSKEW); + return 1; + case sideoverlay_wrap: + lua_pushboolean(L, overlay->flags & SIDEOVERLAYFLAG_WRAP); + return 1; + } + return 0; +} + +static int sideoverlay_set(lua_State *L) +{ + side_overlay_t *overlay = *((side_overlay_t **)luaL_checkudata(L, 1, META_SIDEOVERLAY)); + enum sideoverlay_e field = Lua_optoption(L, 2, sideoverlay_valid, sideoverlay_fields_ref); + + if (!overlay) + { + if (field == sideoverlay_valid) { + lua_pushboolean(L, 0); + return 1; + } + return luaL_error(L, "accessed side_t.overlay doesn't exist anymore."); + } + + switch(field) + { + case side_valid: + return luaL_error(L, "side_t.overlay field " LUA_QS " cannot be set.", side_opt[field]); + default: + return luaL_error(L, "side_t.overlay has no field named " LUA_QS ".", lua_tostring(L, 2)); + case sideoverlay_texture: + overlay->texture = luaL_checkinteger(L, 3); + break; + case sideoverlay_offsetx: + overlay->offsetx = luaL_checkfixed(L, 3); + break; + case sideoverlay_offsety: + overlay->offsety = luaL_checkfixed(L, 3); + break; + case sideoverlay_scalex: + overlay->scalex = luaL_checkfixed(L, 3); + break; + case sideoverlay_scaley: + overlay->scaley = luaL_checkfixed(L, 3); + break; + case sideoverlay_noskew: + if (luaL_checkboolean(L, 3)) + overlay->flags |= SIDEOVERLAYFLAG_NOSKEW; + else + overlay->flags &= ~SIDEOVERLAYFLAG_NOSKEW; + break; + case sideoverlay_wrap: + if (luaL_checkboolean(L, 3)) + overlay->flags |= SIDEOVERLAYFLAG_WRAP; + else + overlay->flags &= ~SIDEOVERLAYFLAG_WRAP; + break; + } + return 0; +} + ////////////// // vertex_t // ////////////// @@ -2991,6 +3142,7 @@ int LUA_MapLib(lua_State *L) LUA_RegisterUserdataMetatable(L, META_LINESTRINGARGS, linestringargs_get, NULL, linestringargs_len); LUA_RegisterUserdataMetatable(L, META_SIDENUM, sidenum_get, NULL, NULL); LUA_RegisterUserdataMetatable(L, META_SIDE, side_get, side_set, side_num); + LUA_RegisterUserdataMetatable(L, META_SIDEOVERLAY, sideoverlay_get, sideoverlay_set, NULL); LUA_RegisterUserdataMetatable(L, META_VERTEX, vertex_get, NULL, vertex_num); LUA_RegisterUserdataMetatable(L, META_FFLOOR, ffloor_get, ffloor_set, NULL); LUA_RegisterUserdataMetatable(L, META_BBOX, bbox_get, NULL, NULL); @@ -3003,6 +3155,7 @@ int LUA_MapLib(lua_State *L) subsector_fields_ref = Lua_CreateFieldTable(L, subsector_opt); line_fields_ref = Lua_CreateFieldTable(L, line_opt); side_fields_ref = Lua_CreateFieldTable(L, side_opt); + sideoverlay_fields_ref = Lua_CreateFieldTable(L, sideoverlay_opt); vertex_fields_ref = Lua_CreateFieldTable(L, vertex_opt); ffloor_fields_ref = Lua_CreateFieldTable(L, ffloor_opt); slope_fields_ref = Lua_CreateFieldTable(L, slope_opt); diff --git a/src/lua_script.c b/src/lua_script.c index 11ced70f2..a4cf1feae 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -964,7 +964,11 @@ void LUA_InvalidateLevel(void) LUA_InvalidateUserdata(lines[i].sidenum); } for (i = 0; i < numsides; i++) + { + for (unsigned j = 0; j < NUM_WALL_OVERLAYS; j++) + LUA_InvalidateUserdata(&sides[i].overlays[j]); LUA_InvalidateUserdata(&sides[i]); + } for (i = 0; i < numvertexes; i++) LUA_InvalidateUserdata(&vertexes[i]); for (i = 0; i < (size_t)numPolyObjects; i++) diff --git a/src/p_setup.c b/src/p_setup.c index b662278e9..8b36f0383 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1366,13 +1366,12 @@ static void P_LoadSidedefs(UINT8 *data) sd->scalex_top = sd->scalex_mid = sd->scalex_bottom = FRACUNIT; sd->scaley_top = sd->scaley_mid = sd->scaley_bottom = FRACUNIT; - sd->flags = 0; - for (unsigned j = 0; j < NUM_WALL_OVERLAYS; j++) { sd->overlays[j].texture = R_TextureNumForName("-"); sd->overlays[j].offsetx = sd->overlays[j].offsety = 0; sd->overlays[j].scalex = sd->overlays[j].scaley = FRACUNIT; + sd->overlays[j].flags = 0; } P_SetSidedefSector(i, (UINT16)SHORT(msd->sector)); @@ -1907,20 +1906,21 @@ static void ParseTextmapSectorParameter(UINT32 i, const char *param, const char static void ParseTextmapSidedefOverlay(unsigned which, UINT32 i, const char *param, const char *val) { + side_overlay_t *overlay = &sides[i].overlays[which]; if (fastcmp(param, "texture")) - sides[i].overlays[which].texture = R_TextureNumForName(val); + overlay->texture = R_TextureNumForName(val); else if (fastcmp(param, "offsetx")) - sides[i].overlays[which].offsetx = FLOAT_TO_FIXED(atof(val)); + overlay->offsetx = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "offsety")) - sides[i].overlays[which].offsety = FLOAT_TO_FIXED(atof(val)); + overlay->offsety = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "scalex")) - sides[i].overlays[which].scalex = FLOAT_TO_FIXED(atof(val)); + overlay->scalex = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "scaley")) - sides[i].overlays[which].scaley = FLOAT_TO_FIXED(atof(val)); + overlay->scaley = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "noskew") && fastcmp("true", val)) - sides[i].flags |= GET_SIDEFLAG_EDGENOSKEW(which); + overlay->flags |= SIDEOVERLAYFLAG_NOSKEW; else if (fastcmp(param, "wrap") && fastcmp("true", val)) - sides[i].flags |= GET_SIDEFLAG_EDGEWRAP(which); + overlay->flags |= SIDEOVERLAYFLAG_WRAP; } static void ParseTextmapSidedefParameter(UINT32 i, const char *param, const char *val) @@ -2240,9 +2240,9 @@ static void WriteTextmapEdgeTexture(const char *prefix, unsigned i, side_t *side fprintf(f, "%s""scalex = %f;\n", prefix, FIXED_TO_FLOAT(side->overlays[i].scalex)); if (side->overlays[i].scaley != FRACUNIT) fprintf(f, "%s""scaley = %f;\n", prefix, FIXED_TO_FLOAT(side->overlays[i].scaley)); - if (side->flags & GET_SIDEFLAG_EDGENOSKEW(i)) + if (side->overlays[i].flags & SIDEOVERLAYFLAG_NOSKEW) fprintf(f, "%s""noskew = true;\n", prefix); - if (side->flags & GET_SIDEFLAG_EDGEWRAP(i)) + if (side->overlays[i].flags & SIDEOVERLAYFLAG_WRAP) fprintf(f, "%s""wrap = true;\n", prefix); } @@ -3101,7 +3101,6 @@ static void P_LoadTextmap(void) sd->offsety_top = sd->offsety_mid = sd->offsety_bottom = 0; sd->scalex_top = sd->scalex_mid = sd->scalex_bottom = FRACUNIT; sd->scaley_top = sd->scaley_mid = sd->scaley_bottom = FRACUNIT; - sd->flags = 0; sd->toptexture = R_TextureNumForName("-"); sd->midtexture = R_TextureNumForName("-"); sd->bottomtexture = R_TextureNumForName("-"); @@ -3110,6 +3109,7 @@ static void P_LoadTextmap(void) sd->overlays[j].texture = R_TextureNumForName("-"); sd->overlays[j].offsetx = sd->overlays[j].offsety = 0; sd->overlays[j].scalex = sd->overlays[j].scaley = FRACUNIT; + sd->overlays[j].flags = 0; } sd->sector = NULL; sd->repeatcnt = 0; diff --git a/src/r_defs.h b/src/r_defs.h index 3427d7143..f6f770de2 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -613,19 +613,17 @@ typedef struct line_s // Don't make available to Lua or I will find where you live enum { - SIDEFLAG_EDGENOSKEW1 = 1<<7, - SIDEFLAG_EDGENOSKEW2 = 1<<8, - SIDEFLAG_EDGENOSKEW3 = 1<<9, - SIDEFLAG_EDGENOSKEW4 = 1<<10, - - SIDEFLAG_EDGEWRAP1 = 1<<11, - SIDEFLAG_EDGEWRAP2 = 1<<12, - SIDEFLAG_EDGEWRAP3 = 1<<13, - SIDEFLAG_EDGEWRAP4 = 1<<14 + SIDEOVERLAYFLAG_NOSKEW = 1<<0, + SIDEOVERLAYFLAG_WRAP = 1<<1 }; -#define GET_SIDEFLAG_EDGENOSKEW(which) (SIDEFLAG_EDGENOSKEW1<<(which)) -#define GET_SIDEFLAG_EDGEWRAP(which) (SIDEFLAG_EDGEWRAP1<<(which)) +typedef struct +{ + INT32 texture; + fixed_t offsetx, offsety; + fixed_t scalex, scaley; + UINT8 flags; +} side_overlay_t; typedef struct { @@ -642,18 +640,12 @@ typedef struct fixed_t scalex_top, scalex_mid, scalex_bottom; fixed_t scaley_top, scaley_mid, scaley_bottom; - UINT16 flags; - // Texture indices. // We do not maintain names here. INT32 toptexture, bottomtexture, midtexture; // Upper and lower overlays for top and bottom textures - struct { - INT32 texture; - fixed_t offsetx, offsety; - fixed_t scalex, scaley; - } overlays[NUM_WALL_OVERLAYS]; + side_overlay_t overlays[NUM_WALL_OVERLAYS]; // Linedef the sidedef belongs to line_t *line; diff --git a/src/r_segs.c b/src/r_segs.c index 97b26c86f..e540fab49 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -647,7 +647,7 @@ static void R_RenderExtraTexture(drawseg_t *ds, unsigned which, INT32 x1, INT32 mfloorclip = overlayopening[1]; mceilingclip = overlayopening[0]; - if (sidedef->flags & GET_SIDEFLAG_EDGEWRAP(which)) + if (sidedef->overlays[which].flags & SIDEOVERLAYFLAG_WRAP) { fixed_t high, low; @@ -683,8 +683,8 @@ static void R_RenderExtraTexture(drawseg_t *ds, unsigned which, INT32 x1, INT32 P_GetSectorCeilingZAt(frontsector, ds_p->rightpos.x, ds_p->rightpos.y) ); low = min( - P_GetSectorFloorZAt(backsector, ds_p->leftpos.x, ds_p->leftpos.y), - P_GetSectorFloorZAt(backsector, ds_p->rightpos.x, ds_p->rightpos.y) + P_GetSectorFloorZAt(frontsector, ds_p->leftpos.x, ds_p->leftpos.y), + P_GetSectorFloorZAt(frontsector, ds_p->rightpos.x, ds_p->rightpos.y) ); } @@ -2029,8 +2029,8 @@ static void R_AddOverlayTextures(fixed_t ceilingfrontslide, fixed_t floorfrontsl if (!backsector) { // If one-sided, render just the upper top and the lower bottom overlays - overlaytexture[0] = texnums[0] ? texnums[0] : texnums[2]; - overlaytexture[3] = texnums[1] ? texnums[1] : texnums[3]; + overlaytexture[0] = texnums[0]; + overlaytexture[3] = texnums[3]; } else { @@ -2067,7 +2067,7 @@ static void R_AddOverlayTextures(fixed_t ceilingfrontslide, fixed_t floorfrontsl rw_overlay[i].invscalex = FixedDiv(FRACUNIT, rw_overlay[i].scalex); - if (sidedef->flags & GET_SIDEFLAG_EDGENOSKEW(i)) + if (sidedef->overlays[i].flags & SIDEOVERLAYFLAG_NOSKEW) { if (IS_BOTTOM_EDGE_TEXTURE(i)) {