diff --git a/src/actor.h b/src/actor.h index c1d5696b3..631d854d0 100644 --- a/src/actor.h +++ b/src/actor.h @@ -1324,6 +1324,20 @@ public: result.Roll = PrevAngles.Roll + deltaangle(PrevAngles.Roll, Angles.Roll) * ticFrac; return result; } + DAngle GetSpriteAngle(DAngle viewangle, double ticFrac) + { + if (flags7 & MF7_SPRITEANGLE) + { + return SpriteAngle; + } + else + { + DAngle thisang; + if (renderflags & RF_INTERPOLATEANGLES) thisang = PrevAngles.Yaw + deltaangle(PrevAngles.Yaw, Angles.Yaw) * ticFrac; + else thisang = Angles.Yaw; + return viewangle - (thisang + SpriteRotation); + } + } DVector3 PosPlusZ(double zadd) const { return { X(), Y(), Z() + zadd }; diff --git a/src/g_shared/a_dynlight.cpp b/src/g_shared/a_dynlight.cpp index 9400826f6..1c29f4f9f 100644 --- a/src/g_shared/a_dynlight.cpp +++ b/src/g_shared/a_dynlight.cpp @@ -72,16 +72,13 @@ #include "doomstat.h" #include "serializer.h" #include "g_levellocals.h" +#include "a_dynlight.h" #include "actorinlines.h" - - -#include "gl/renderer/gl_renderer.h" -#include "gl/data/gl_data.h" -#include "gl/dynlights/gl_dynlight.h" -#include "gl/utility/gl_convert.h" -#include "gl/utility/gl_templates.h" +#include "c_cvars.h" #include "gl/system//gl_interface.h" +EXTERN_CVAR(Int, vid_renderer) + CUSTOM_CVAR (Bool, gl_lights, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { @@ -168,7 +165,7 @@ void ADynamicLight::BeginPlay() specialf1 = DAngle(double(SpawnAngle)).Normalized360().Degrees; visibletoplayer = true; - if (gl.legacyMode && (flags4 & MF4_ATTENUATE)) + if (vid_renderer == 1 && gl.legacyMode && (flags4 & MF4_ATTENUATE)) { args[LIGHT_INTENSITY] = args[LIGHT_INTENSITY] * 2 / 3; args[LIGHT_SECONDARY_INTENSITY] = args[LIGHT_SECONDARY_INTENSITY] * 2 / 3; @@ -793,7 +790,7 @@ CCMD(listlights) if (dl->target) { - FTextureID spr = gl_GetSpriteFrame(dl->target->sprite, dl->target->frame, 0, 0, NULL); + FTextureID spr = sprites[dl->target->sprite].GetSpriteFrame(dl->target->frame, 0, 0., nullptr); Printf(", frame = %s ", TexMan[spr]->Name.GetChars()); } diff --git a/src/gl/data/gl_data.cpp b/src/gl/data/gl_data.cpp index f4b2ff391..e041e5a05 100644 --- a/src/gl/data/gl_data.cpp +++ b/src/gl/data/gl_data.cpp @@ -333,42 +333,6 @@ CCMD(gl_resetmap) } -//=========================================================================== -// -// Gets the texture index for a sprite frame -// -//=========================================================================== - -FTextureID gl_GetSpriteFrame(unsigned sprite, int frame, int rot, angle_t ang, bool *mirror) -{ - spritedef_t *sprdef = &sprites[sprite]; - if (frame >= sprdef->numframes) - { - // If there are no frames at all for this sprite, don't draw it. - return FNullTextureID(); - } - else - { - //picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0]; - // choose a different rotation based on player view - spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + frame]; - if (rot==-1) - { - if (sprframe->Texture[0] == sprframe->Texture[1]) - { - rot = (ang + (angle_t)(ANGLE_90/4)*9) >> 28; - } - else - { - rot = (ang + (angle_t)(ANGLE_90/4)*9-(angle_t)(ANGLE_180/16)) >> 28; - } - } - if (mirror) *mirror = !!(sprframe->Flip&(1<Texture[rot]; - } -} - - //========================================================================== // // Recalculate all heights affecting this vertex. diff --git a/src/gl/data/gl_data.h b/src/gl/data/gl_data.h index 509afb17d..5075d9c5f 100644 --- a/src/gl/data/gl_data.h +++ b/src/gl/data/gl_data.h @@ -36,7 +36,6 @@ inline int getExtraLight() } void gl_RecalcVertexHeights(vertex_t * v); -FTextureID gl_GetSpriteFrame(unsigned sprite, int frame, int rot, angle_t ang, bool *mirror); struct GLSectorStackPortal; diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index af3ed691f..0725156b3 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -785,18 +785,22 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) patch = thing->picnum; mirror = false; } - else if (thing->flags7 & MF7_SPRITEANGLE) - { - patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, (thing->SpriteAngle).BAMs(), &mirror); - } - else if (!(thing->renderflags & RF_FLATSPRITE)) - { - patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, (ang - (Angles.Yaw + thing->SpriteRotation)).BAMs(), &mirror); - } else { - // Flat sprites cannot rotate in a predictable manner. - patch = gl_GetSpriteFrame(spritenum, thing->frame, 0, 0, &mirror); + DAngle sprangle; + int rot; + if (!(thing->renderflags & RF_FLATSPRITE)) + { + sprangle = thing->GetSpriteAngle(ang, r_viewpoint.TicFrac); + rot = -1; + } + else + { + // Flat sprites cannot rotate in a predictable manner. + sprangle = 0.; + rot = 0; + } + patch = sprites[spritenum].GetSpriteFrame(thing->frame, rot, sprangle, &mirror); } if (!patch.isValid()) return; diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 7e13b17e4..5f261d9d4 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -82,7 +82,7 @@ void GLSceneDrawer::DrawPSprite (player_t * player,DPSprite *psp, float sx, floa // decide which patch to use bool mirror; - FTextureID lump = gl_GetSpriteFrame(psp->GetSprite(), psp->GetFrame(), 0, 0, &mirror); + FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., &mirror); if (!lump.isValid()) return; FMaterial * tex = FMaterial::ValidateTexture(lump, true, false); @@ -172,7 +172,7 @@ static bool isBright(DPSprite *psp) if (psp != nullptr && psp->GetState() != nullptr) { bool disablefullbright = false; - FTextureID lump = gl_GetSpriteFrame(psp->GetSprite(), psp->GetFrame(), 0, 0, NULL); + FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., nullptr); if (lump.isValid()) { FMaterial * tex = FMaterial::ValidateTexture(lump, false, false); diff --git a/src/polyrenderer/scene/poly_sprite.cpp b/src/polyrenderer/scene/poly_sprite.cpp index 3940bf05d..e53d1cc2e 100644 --- a/src/polyrenderer/scene/poly_sprite.cpp +++ b/src/polyrenderer/scene/poly_sprite.cpp @@ -376,6 +376,10 @@ FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX) { const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint; flipX = false; + + if (thing->renderflags & RF_FLATSPRITE) + return nullptr; // do not draw flat sprites. + if (thing->picnum.isValid()) { FTexture *tex = TexMan(thing->picnum); @@ -422,21 +426,15 @@ FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX) { //picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0]; // choose a different rotation based on player view - spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame]; + DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac); pos.Z += thing->GetBobOffset(viewpoint.TicFrac); DAngle ang = (pos - viewpoint.Pos).Angle(); - angle_t rot; - if (sprframe->Texture[0] == sprframe->Texture[1]) - { - rot = (ang - thing->Angles.Yaw + 45.0 / 2 * 9).BAMs() >> 28; - } - else - { - rot = (ang - thing->Angles.Yaw + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28; - } - flipX = (sprframe->Flip & (1 << rot)) != 0; - return TexMan[sprframe->Texture[rot]]; // Do not animate the rotation + + DAngle sprangle = thing->GetSpriteAngle((pos - viewpoint.Pos).Angle(), viewpoint.TicFrac); + FTextureID tex = sprdef->GetSpriteFrame(thing->frame, -1, sprangle, &flipX); + if (!tex.isValid()) return nullptr; + return TexMan[tex]; } } } diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp index d932e6377..7a5927be6 100644 --- a/src/r_data/sprites.cpp +++ b/src/r_data/sprites.cpp @@ -35,6 +35,39 @@ uint8_t OtherGameSkinRemap[256]; PalEntry OtherGameSkinPalette[256]; +//=========================================================================== +// +// Gets the texture index for a sprite frame +// +//=========================================================================== + +FTextureID spritedef_t::GetSpriteFrame(int frame, int rot, DAngle ang, bool *mirror) +{ + if ((unsigned)frame >= numframes) + { + // If there are no frames at all for this sprite, don't draw it. + return FNullTextureID(); + } + else + { + // choose a different rotation based on player view + spriteframe_t *sprframe = &SpriteFrames[spriteframes + frame]; + if (rot == -1) + { + if (sprframe->Texture[0] == sprframe->Texture[1]) + { + rot = (ang + 45.0 / 2 * 9).BAMs() >> 28; + } + else + { + rot = (ang + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28; + } + } + if (mirror) *mirror = !!(sprframe->Flip&(1 << rot)); + return sprframe->Texture[rot]; + } +} + // // R_InstallSpriteLump diff --git a/src/r_data/sprites.h b/src/r_data/sprites.h index d40be370f..aec0a246d 100644 --- a/src/r_data/sprites.h +++ b/src/r_data/sprites.h @@ -36,6 +36,8 @@ struct spritedef_t }; uint8_t numframes; uint16_t spriteframes; + + FTextureID GetSpriteFrame(int frame, int rot, DAngle ang, bool *mirror); }; extern TArray SpriteFrames; diff --git a/src/swrenderer/drawers/r_draw_rgba.cpp b/src/swrenderer/drawers/r_draw_rgba.cpp index 8778414e6..57ea136f1 100644 --- a/src/swrenderer/drawers/r_draw_rgba.cpp +++ b/src/swrenderer/drawers/r_draw_rgba.cpp @@ -36,7 +36,7 @@ #include "v_palette.h" #include "r_data/colormaps.h" #include "r_draw_rgba.h" -#include "gl/data/gl_matrix.h" +//#include "gl/data/gl_matrix.h" #include "swrenderer/viewport/r_viewport.h" #include "swrenderer/scene/r_light.h" #ifdef NO_SSE diff --git a/src/swrenderer/line/r_fogboundary.cpp b/src/swrenderer/line/r_fogboundary.cpp index 8bd907c70..7f3ef3529 100644 --- a/src/swrenderer/line/r_fogboundary.cpp +++ b/src/swrenderer/line/r_fogboundary.cpp @@ -28,7 +28,7 @@ #include "g_level.h" #include "v_palette.h" #include "r_data/colormaps.h" -#include "gl/dynlights/gl_dynlight.h" +#include "a_dynlight.h" #include "swrenderer/drawers/r_draw_rgba.h" #include "swrenderer/scene/r_opaque_pass.h" #include "swrenderer/scene/r_3dfloors.h" diff --git a/src/swrenderer/line/r_walldraw.cpp b/src/swrenderer/line/r_walldraw.cpp index 8e3c73a17..00d5d4860 100644 --- a/src/swrenderer/line/r_walldraw.cpp +++ b/src/swrenderer/line/r_walldraw.cpp @@ -28,7 +28,7 @@ #include "r_walldraw.h" #include "v_palette.h" #include "r_data/colormaps.h" -#include "gl/dynlights/gl_dynlight.h" +#include "a_dynlight.h" #include "swrenderer/drawers/r_draw.h" #include "swrenderer/segments/r_drawsegment.h" #include "swrenderer/scene/r_opaque_pass.h" diff --git a/src/swrenderer/plane/r_flatplane.cpp b/src/swrenderer/plane/r_flatplane.cpp index 159d4c45a..17b9a2630 100644 --- a/src/swrenderer/plane/r_flatplane.cpp +++ b/src/swrenderer/plane/r_flatplane.cpp @@ -33,7 +33,7 @@ #include "v_palette.h" #include "r_data/colormaps.h" #include "swrenderer/drawers/r_draw_rgba.h" -#include "gl/dynlights/gl_dynlight.h" +#include "a_dynlight.h" #include "swrenderer/segments/r_clipsegment.h" #include "swrenderer/segments/r_drawsegment.h" #include "swrenderer/scene/r_portal.h" diff --git a/src/swrenderer/plane/r_planerenderer.cpp b/src/swrenderer/plane/r_planerenderer.cpp index 6bc023738..772c13df4 100644 --- a/src/swrenderer/plane/r_planerenderer.cpp +++ b/src/swrenderer/plane/r_planerenderer.cpp @@ -27,7 +27,7 @@ #include "cmdlib.h" #include "d_net.h" #include "g_level.h" -#include "gl/dynlights/gl_dynlight.h" +#include "a_dynlight.h" #include "swrenderer/plane/r_visibleplane.h" #include "swrenderer/plane/r_planerenderer.h" diff --git a/src/swrenderer/plane/r_skyplane.cpp b/src/swrenderer/plane/r_skyplane.cpp index 613c1fbea..c75411e7f 100644 --- a/src/swrenderer/plane/r_skyplane.cpp +++ b/src/swrenderer/plane/r_skyplane.cpp @@ -32,7 +32,7 @@ #include "v_palette.h" #include "r_data/colormaps.h" #include "swrenderer/drawers/r_draw_rgba.h" -#include "gl/dynlights/gl_dynlight.h" +#include "a_dynlight.h" #include "swrenderer/segments/r_clipsegment.h" #include "swrenderer/segments/r_drawsegment.h" #include "swrenderer/line/r_wallsetup.h" diff --git a/src/swrenderer/plane/r_slopeplane.cpp b/src/swrenderer/plane/r_slopeplane.cpp index 90aaf9cea..d8897aa6c 100644 --- a/src/swrenderer/plane/r_slopeplane.cpp +++ b/src/swrenderer/plane/r_slopeplane.cpp @@ -33,7 +33,7 @@ #include "v_palette.h" #include "r_data/colormaps.h" #include "swrenderer/drawers/r_draw_rgba.h" -#include "gl/dynlights/gl_dynlight.h" +#include "a_dynlight.h" #include "swrenderer/segments/r_clipsegment.h" #include "swrenderer/segments/r_drawsegment.h" #include "swrenderer/scene/r_portal.h" diff --git a/src/swrenderer/plane/r_visibleplane.cpp b/src/swrenderer/plane/r_visibleplane.cpp index b32e092b4..88c2e6d34 100644 --- a/src/swrenderer/plane/r_visibleplane.cpp +++ b/src/swrenderer/plane/r_visibleplane.cpp @@ -27,7 +27,7 @@ #include "cmdlib.h" #include "d_net.h" #include "g_level.h" -#include "gl/dynlights/gl_dynlight.h" +#include "a_dynlight.h" #include "swrenderer/r_memory.h" #include "swrenderer/r_renderthread.h" #include "swrenderer/scene/r_opaque_pass.h" diff --git a/src/swrenderer/plane/r_visibleplanelist.cpp b/src/swrenderer/plane/r_visibleplanelist.cpp index 8cb29d938..16f992562 100644 --- a/src/swrenderer/plane/r_visibleplanelist.cpp +++ b/src/swrenderer/plane/r_visibleplanelist.cpp @@ -27,7 +27,7 @@ #include "cmdlib.h" #include "d_net.h" #include "g_level.h" -#include "gl/dynlights/gl_dynlight.h" +#include "a_dynlight.h" #include "swrenderer/r_memory.h" #include "swrenderer/scene/r_opaque_pass.h" #include "swrenderer/scene/r_3dfloors.h" diff --git a/src/swrenderer/scene/r_opaque_pass.cpp b/src/swrenderer/scene/r_opaque_pass.cpp index 35d7c3054..471731df6 100644 --- a/src/swrenderer/scene/r_opaque_pass.cpp +++ b/src/swrenderer/scene/r_opaque_pass.cpp @@ -997,34 +997,20 @@ namespace swrenderer } else { - //picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0]; - // choose a different rotation based on player view - spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame]; - DAngle ang = (sprite.pos - Thread->Viewport->viewpoint.Pos).Angle(); - angle_t rot; - if (sprframe->Texture[0] == sprframe->Texture[1]) - { - if (thing->flags7 & MF7_SPRITEANGLE) - rot = (thing->SpriteAngle + 45.0 / 2 * 9).BAMs() >> 28; - else - rot = (ang - (thing->Angles.Yaw + thing->SpriteRotation) + 45.0 / 2 * 9).BAMs() >> 28; - } - else - { - if (thing->flags7 & MF7_SPRITEANGLE) - rot = (thing->SpriteAngle + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28; - else - rot = (ang - (thing->Angles.Yaw + thing->SpriteRotation) + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28; - } - sprite.picnum = sprframe->Texture[rot]; - if (sprframe->Flip & (1 << rot)) + auto &viewpoint = Thread->Viewport->viewpoint; + DAngle sprangle = thing->GetSpriteAngle((sprite.pos - viewpoint.Pos).Angle(), viewpoint.TicFrac); + bool flipX; + FTextureID tex = sprdef->GetSpriteFrame(thing->frame, -1, sprangle, &flipX); + if (!tex.isValid()) return false; + + if (flipX) { sprite.renderflags ^= RF_XFLIP; } - sprite.tex = TexMan[sprite.picnum]; // Do not animate the rotation + sprite.tex = TexMan[tex]; // Do not animate the rotation if (r_drawvoxels) { - sprite.voxel = sprframe->Voxel; + sprite.voxel = SpriteFrames[sprdef->spriteframes + thing->frame].Voxel; } } diff --git a/src/swrenderer/things/r_sprite.cpp b/src/swrenderer/things/r_sprite.cpp index b18df3b69..2e8a0f3aa 100644 --- a/src/swrenderer/things/r_sprite.cpp +++ b/src/swrenderer/things/r_sprite.cpp @@ -56,7 +56,7 @@ #include "swrenderer/viewport/r_viewport.h" #include "swrenderer/r_memory.h" #include "swrenderer/r_renderthread.h" -#include "gl/dynlights/gl_dynlight.h" +#include "a_dynlight.h" EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor) EXTERN_CVAR(Bool, gl_light_sprites)