From d62a26a177c3f13e4146dfca13f3269e8aca1146 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 29 Nov 2018 00:01:16 +0100 Subject: [PATCH 01/10] - use psprite renderstyle on HUD models --- src/polyrenderer/scene/poly_model.cpp | 85 ++++++++++++++++++--------- src/polyrenderer/scene/poly_model.h | 10 +++- src/swrenderer/things/r_model.cpp | 85 ++++++++++++++++++--------- src/swrenderer/things/r_model.h | 10 +++- 4 files changed, 134 insertions(+), 56 deletions(-) diff --git a/src/polyrenderer/scene/poly_model.cpp b/src/polyrenderer/scene/poly_model.cpp index 91c975d1eb..30bad72dea 100644 --- a/src/polyrenderer/scene/poly_model.cpp +++ b/src/polyrenderer/scene/poly_model.cpp @@ -36,15 +36,69 @@ void PolyRenderModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_t stencilValue, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor) { PolyModelRenderer renderer(thread, worldToClip, stencilValue); + + renderer.sector = actor->Sector; + renderer.RenderStyle = actor->RenderStyle; + renderer.RenderAlpha = (float)actor->Alpha; + if (!renderer.RenderStyle.IsVisible(renderer.RenderAlpha)) + return; + + bool foggy = false; + int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4; + bool fullbrightSprite = ((actor->renderflags & RF_FULLBRIGHT) || (actor->flags5 & MF5_BRIGHT)); + int lightlevel = fullbrightSprite ? 255 : actor->Sector->lightlevel + actualextralight; + renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy); + + renderer.fillcolor = actor->fillcolor; + renderer.Translation = actor->Translation; + renderer.AddLights(actor); renderer.RenderModel(x, y, z, smf, actor, r_viewpoint.TicFrac); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f); PolyTriangleDrawer::SetTransform(thread->DrawQueue, thread->FrameMemory->NewObject(worldToClip), nullptr); } +static bool isBright(DPSprite *psp) +{ + if (psp != nullptr && psp->GetState() != nullptr) + { + bool disablefullbright = false; + FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., nullptr); + if (lump.isValid()) + { + FTexture * tex = TexMan(lump); + if (tex) disablefullbright = tex->bDisableFullbright; + } + return psp->GetState()->GetFullbright() && !disablefullbright; + } + return false; +} + void PolyRenderHUDModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_t stencilValue, DPSprite *psp, float ofsx, float ofsy) { PolyModelRenderer renderer(thread, worldToClip, stencilValue); + + AActor *playermo = players[consoleplayer].camera; + auto rs = psp->GetRenderStyle(playermo->RenderStyle, playermo->Alpha); + renderer.sector = playermo->Sector; + renderer.RenderStyle = rs.first; + renderer.RenderAlpha = rs.second; + if (psp->Flags & PSPF_FORCEALPHA) renderer.RenderAlpha = 0.0f; + if (!renderer.RenderStyle.IsVisible(renderer.RenderAlpha)) + return; + + bool foggy = false; + int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4; + bool fullbrightSprite = isBright(psp); + int lightlevel = fullbrightSprite ? 255 : playermo->Sector->lightlevel + actualextralight; + renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy); + + PalEntry ThingColor = (playermo->RenderStyle.Flags & STYLEF_ColorIsFixed) ? playermo->fillcolor : 0xffffff; + ThingColor.a = 255; + + renderer.fillcolor = fullbrightSprite ? ThingColor : ThingColor.Modulate(playermo->Sector->SpecialColors[sector_t::sprites]); + renderer.Translation = 0xffffffff;// playermo->Translation; + renderer.RenderHUDModel(psp, ofsx, ofsy); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f); } @@ -121,7 +175,6 @@ void PolyModelRenderer::AddLights(AActor *actor) void PolyModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) { - ModelActor = actor; const_cast(objectToWorldMatrix).copy(ObjectToWorld.Matrix); SetTransform(); @@ -135,8 +188,6 @@ void PolyModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf) if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES)) PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, false); PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, true); - - ModelActor = nullptr; } IModelVertexBuffer *PolyModelRenderer::CreateVertexBuffer(bool needindex, bool singleframe) @@ -162,7 +213,6 @@ VSMatrix PolyModelRenderer::GetViewToWorldMatrix() void PolyModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) { - ModelActor = actor; const_cast(objectToWorldMatrix).copy(ObjectToWorld.Matrix); SetTransform(); PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, true); @@ -174,7 +224,6 @@ void PolyModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectT void PolyModelRenderer::EndDrawHUDModel(AActor *actor) { - ModelActor = nullptr; PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, false); if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal]) @@ -206,21 +255,12 @@ void PolyModelRenderer::SetTransform() void PolyModelRenderer::DrawArrays(int start, int count) { - const auto &viewpoint = PolyRenderer::Instance()->Viewpoint; - - bool foggy = false; - int actualextralight = foggy ? 0 : viewpoint.extralight << 4; - sector_t *sector = ModelActor->Sector; - - bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT)); - int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight; - PolyDrawArgs args; - args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.SpriteGlobVis(foggy), fullbrightSprite); + args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, visibility, fullbrightSprite); args.SetLights(Lights, NumLights); args.SetStencilTestValue(StencilValue); args.SetClipPlane(0, PolyClipPlane()); - args.SetStyle(ModelActor->RenderStyle, ModelActor->Alpha, ModelActor->fillcolor, ModelActor->Translation, SkinTexture, fullbrightSprite); + args.SetStyle(RenderStyle, RenderAlpha, fillcolor, Translation, SkinTexture, fullbrightSprite); args.SetDepthTest(true); args.SetWriteDepth(true); args.SetWriteStencil(false); @@ -229,21 +269,12 @@ void PolyModelRenderer::DrawArrays(int start, int count) void PolyModelRenderer::DrawElements(int numIndices, size_t offset) { - const auto &viewpoint = PolyRenderer::Instance()->Viewpoint; - - bool foggy = false; - int actualextralight = foggy ? 0 : viewpoint.extralight << 4; - sector_t *sector = ModelActor->Sector; - - bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT)); - int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight; - PolyDrawArgs args; - args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.SpriteGlobVis(foggy), fullbrightSprite); + args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, visibility, fullbrightSprite); args.SetLights(Lights, NumLights); args.SetStencilTestValue(StencilValue); args.SetClipPlane(0, PolyClipPlane()); - args.SetStyle(ModelActor->RenderStyle, ModelActor->Alpha, ModelActor->fillcolor, ModelActor->Translation, SkinTexture, fullbrightSprite); + args.SetStyle(RenderStyle, RenderAlpha, fillcolor, Translation, SkinTexture, fullbrightSprite); args.SetDepthTest(true); args.SetWriteDepth(true); args.SetWriteStencil(false); diff --git a/src/polyrenderer/scene/poly_model.h b/src/polyrenderer/scene/poly_model.h index 4521951e55..ff7269e182 100644 --- a/src/polyrenderer/scene/poly_model.h +++ b/src/polyrenderer/scene/poly_model.h @@ -55,7 +55,15 @@ public: const Mat4f &WorldToClip; uint32_t StencilValue = 0; - AActor *ModelActor = nullptr; + FRenderStyle RenderStyle; + float RenderAlpha; + sector_t *sector; + bool fullbrightSprite; + int lightlevel; + double visibility; + uint32_t fillcolor; + uint32_t Translation; + Mat4f ObjectToWorld; FTexture *SkinTexture = nullptr; unsigned int *IndexBuffer = nullptr; diff --git a/src/swrenderer/things/r_model.cpp b/src/swrenderer/things/r_model.cpp index 2ee4169732..fc6159fe1f 100644 --- a/src/swrenderer/things/r_model.cpp +++ b/src/swrenderer/things/r_model.cpp @@ -75,6 +75,22 @@ namespace swrenderer void RenderModel::Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) { SWModelRenderer renderer(thread, clip3DFloor, &WorldToClip, MirrorWorldToClip); + + renderer.sector = actor->Sector; + renderer.RenderStyle = actor->RenderStyle; + renderer.RenderAlpha = (float)actor->Alpha; + if (!renderer.RenderStyle.IsVisible(renderer.RenderAlpha)) + return; + + bool foggy = false; + int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4; + bool fullbrightSprite = ((actor->renderflags & RF_FULLBRIGHT) || (actor->flags5 & MF5_BRIGHT)); + int lightlevel = fullbrightSprite ? 255 : actor->Sector->lightlevel + actualextralight; + renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy); + + renderer.fillcolor = actor->fillcolor; + renderer.Translation = actor->Translation; + renderer.AddLights(actor); renderer.RenderModel(x, y, z, smf, actor, r_viewpoint.TicFrac); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f); @@ -82,9 +98,47 @@ namespace swrenderer ///////////////////////////////////////////////////////////////////////////// + static bool isBright(DPSprite *psp) + { + if (psp != nullptr && psp->GetState() != nullptr) + { + bool disablefullbright = false; + FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., nullptr); + if (lump.isValid()) + { + FTexture * tex = TexMan(lump); + if (tex) disablefullbright = tex->bDisableFullbright; + } + return psp->GetState()->GetFullbright() && !disablefullbright; + } + return false; + } + void RenderHUDModel(RenderThread *thread, DPSprite *psp, float ofsx, float ofsy) { SWModelRenderer renderer(thread, Fake3DTranslucent(), &thread->Viewport->WorldToClip, false); + + AActor *playermo = players[consoleplayer].camera; + auto rs = psp->GetRenderStyle(playermo->RenderStyle, playermo->Alpha); + renderer.sector = playermo->Sector; + renderer.RenderStyle = rs.first; + renderer.RenderAlpha = rs.second; + if (psp->Flags & PSPF_FORCEALPHA) renderer.RenderAlpha = 0.0f; + if (!renderer.RenderStyle.IsVisible(renderer.RenderAlpha)) + return; + + bool foggy = false; + int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4; + bool fullbrightSprite = isBright(psp); + int lightlevel = fullbrightSprite ? 255 : playermo->Sector->lightlevel + actualextralight; + renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy); + + PalEntry ThingColor = (playermo->RenderStyle.Flags & STYLEF_ColorIsFixed) ? playermo->fillcolor : 0xffffff; + ThingColor.a = 255; + + renderer.fillcolor = fullbrightSprite ? ThingColor : ThingColor.Modulate(playermo->Sector->SpecialColors[sector_t::sprites]); + renderer.Translation = 0xffffffff;// playermo->Translation; + renderer.RenderHUDModel(psp, ofsx, ofsy); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f); } @@ -162,7 +216,6 @@ namespace swrenderer void SWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) { - ModelActor = actor; const_cast(objectToWorldMatrix).copy(ObjectToWorld.Matrix); ClipTop = {}; @@ -209,8 +262,6 @@ namespace swrenderer if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES)) PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, false); PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, true); - - ModelActor = nullptr; } IModelVertexBuffer *SWModelRenderer::CreateVertexBuffer(bool needindex, bool singleframe) @@ -255,7 +306,6 @@ namespace swrenderer void SWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) { - ModelActor = actor; const_cast(objectToWorldMatrix).copy(ObjectToWorld.Matrix); ClipTop = {}; ClipBottom = {}; @@ -269,7 +319,6 @@ namespace swrenderer void SWModelRenderer::EndDrawHUDModel(AActor *actor) { - ModelActor = nullptr; PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, false); if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal]) @@ -301,20 +350,11 @@ namespace swrenderer void SWModelRenderer::DrawArrays(int start, int count) { - const auto &viewpoint = Thread->Viewport->viewpoint; - - bool foggy = false; - int actualextralight = foggy ? 0 : viewpoint.extralight << 4; - sector_t *sector = ModelActor->Sector; - - bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT)); - int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight; - PolyDrawArgs args; - args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, Thread->Light->SpriteGlobVis(foggy), fullbrightSprite); + args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, visibility, fullbrightSprite); args.SetLights(Lights, NumLights); args.SetNormal(FVector3(0.0f, 0.0f, 0.0f)); - args.SetStyle(ModelActor->RenderStyle, ModelActor->Alpha, ModelActor->fillcolor, ModelActor->Translation, SkinTexture, fullbrightSprite); + args.SetStyle(RenderStyle, RenderAlpha, fillcolor, Translation, SkinTexture, fullbrightSprite); args.SetDepthTest(true); args.SetWriteDepth(true); args.SetWriteStencil(false); @@ -327,20 +367,11 @@ namespace swrenderer void SWModelRenderer::DrawElements(int numIndices, size_t offset) { - const auto &viewpoint = Thread->Viewport->viewpoint; - - bool foggy = false; - int actualextralight = foggy ? 0 : viewpoint.extralight << 4; - sector_t *sector = ModelActor->Sector; - - bool fullbrightSprite = ((ModelActor->renderflags & RF_FULLBRIGHT) || (ModelActor->flags5 & MF5_BRIGHT)); - int lightlevel = fullbrightSprite ? 255 : ModelActor->Sector->lightlevel + actualextralight; - PolyDrawArgs args; - args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, Thread->Light->SpriteGlobVis(foggy), fullbrightSprite); + args.SetLight(GetColorTable(sector->Colormap, sector->SpecialColors[sector_t::sprites], true), lightlevel, visibility, fullbrightSprite); args.SetLights(Lights, NumLights); args.SetNormal(FVector3(0.0f, 0.0f, 0.0f)); - args.SetStyle(ModelActor->RenderStyle, ModelActor->Alpha, ModelActor->fillcolor, ModelActor->Translation, SkinTexture, fullbrightSprite); + args.SetStyle(RenderStyle, RenderAlpha, fillcolor, Translation, SkinTexture, fullbrightSprite); args.SetDepthTest(true); args.SetWriteDepth(true); args.SetWriteStencil(false); diff --git a/src/swrenderer/things/r_model.h b/src/swrenderer/things/r_model.h index dc746e8c53..76509123f8 100644 --- a/src/swrenderer/things/r_model.h +++ b/src/swrenderer/things/r_model.h @@ -78,7 +78,15 @@ namespace swrenderer RenderThread *Thread = nullptr; Fake3DTranslucent Clip3DFloor; - AActor *ModelActor = nullptr; + FRenderStyle RenderStyle; + float RenderAlpha; + sector_t *sector; + bool fullbrightSprite; + int lightlevel; + double visibility; + uint32_t fillcolor; + uint32_t Translation; + Mat4f ObjectToWorld; PolyClipPlane ClipTop, ClipBottom; FTexture *SkinTexture = nullptr; From 4ee7cf2de159a388ecc1761a71fb77626031fac5 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 29 Nov 2018 00:03:50 +0100 Subject: [PATCH 02/10] - forgot to set the light level --- src/polyrenderer/scene/poly_model.cpp | 4 ++-- src/swrenderer/things/r_model.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/polyrenderer/scene/poly_model.cpp b/src/polyrenderer/scene/poly_model.cpp index 30bad72dea..cba1c991ba 100644 --- a/src/polyrenderer/scene/poly_model.cpp +++ b/src/polyrenderer/scene/poly_model.cpp @@ -46,7 +46,7 @@ void PolyRenderModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint32_ bool foggy = false; int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4; bool fullbrightSprite = ((actor->renderflags & RF_FULLBRIGHT) || (actor->flags5 & MF5_BRIGHT)); - int lightlevel = fullbrightSprite ? 255 : actor->Sector->lightlevel + actualextralight; + renderer.lightlevel = fullbrightSprite ? 255 : actor->Sector->lightlevel + actualextralight; renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy); renderer.fillcolor = actor->fillcolor; @@ -90,7 +90,7 @@ void PolyRenderHUDModel(PolyRenderThread *thread, const Mat4f &worldToClip, uint bool foggy = false; int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4; bool fullbrightSprite = isBright(psp); - int lightlevel = fullbrightSprite ? 255 : playermo->Sector->lightlevel + actualextralight; + renderer.lightlevel = fullbrightSprite ? 255 : playermo->Sector->lightlevel + actualextralight; renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy); PalEntry ThingColor = (playermo->RenderStyle.Flags & STYLEF_ColorIsFixed) ? playermo->fillcolor : 0xffffff; diff --git a/src/swrenderer/things/r_model.cpp b/src/swrenderer/things/r_model.cpp index fc6159fe1f..611d756699 100644 --- a/src/swrenderer/things/r_model.cpp +++ b/src/swrenderer/things/r_model.cpp @@ -85,7 +85,7 @@ namespace swrenderer bool foggy = false; int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4; bool fullbrightSprite = ((actor->renderflags & RF_FULLBRIGHT) || (actor->flags5 & MF5_BRIGHT)); - int lightlevel = fullbrightSprite ? 255 : actor->Sector->lightlevel + actualextralight; + renderer.lightlevel = fullbrightSprite ? 255 : actor->Sector->lightlevel + actualextralight; renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy); renderer.fillcolor = actor->fillcolor; @@ -130,7 +130,7 @@ namespace swrenderer bool foggy = false; int actualextralight = foggy ? 0 : PolyRenderer::Instance()->Viewpoint.extralight << 4; bool fullbrightSprite = isBright(psp); - int lightlevel = fullbrightSprite ? 255 : playermo->Sector->lightlevel + actualextralight; + renderer.lightlevel = fullbrightSprite ? 255 : playermo->Sector->lightlevel + actualextralight; renderer.visibility = PolyRenderer::Instance()->Light.SpriteGlobVis(foggy); PalEntry ThingColor = (playermo->RenderStyle.Flags & STYLEF_ColorIsFixed) ? playermo->fillcolor : 0xffffff; From fa185693d23d538d250104f276d26385e0e105cb Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 29 Nov 2018 00:17:40 +0100 Subject: [PATCH 03/10] - _mm_rcp_ps may be faster but its precision is too poor --- src/polyrenderer/drawers/screen_triangle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/polyrenderer/drawers/screen_triangle.cpp b/src/polyrenderer/drawers/screen_triangle.cpp index 1323da2709..52b9cc1a2a 100644 --- a/src/polyrenderer/drawers/screen_triangle.cpp +++ b/src/polyrenderer/drawers/screen_triangle.cpp @@ -528,7 +528,7 @@ void StepSpan(int y, int x0, int x1, const TriDrawTriangleArgs *args, PolyTriang for (int x = x0; x < x1; x += 4) { - __m128 rcp_posW = _mm_rcp_ps(mposW); + __m128 rcp_posW = _mm_div_ps(_mm_set1_ps(1.0f), mposW); // precision of _mm_rcp_ps(mposW) is terrible! if (OptT::Flags & SWOPT_DynLights) { From 110b9820314785e64b6b92a71cb24a078bc16271 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 29 Nov 2018 13:08:46 +0100 Subject: [PATCH 04/10] - fix compile error on systems with no SSE support --- src/polyrenderer/drawers/screen_triangle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/polyrenderer/drawers/screen_triangle.cpp b/src/polyrenderer/drawers/screen_triangle.cpp index 52b9cc1a2a..e914551c57 100644 --- a/src/polyrenderer/drawers/screen_triangle.cpp +++ b/src/polyrenderer/drawers/screen_triangle.cpp @@ -331,7 +331,7 @@ void ScreenTriangle::Draw(const TriDrawTriangleArgs *args, PolyTriangleThreadDat if (x > xstart) { if (writeColor) - drawfunc(y, xstart, x, args); + drawfunc(y, xstart, x, args, thread); if (writeStencil) { From df6fe563c3df382efebe36958ae78d2c365133a6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 29 Nov 2018 19:42:11 +0100 Subject: [PATCH 05/10] - cleaned up the sound options menu. There were still some leftover definitions from FMod and far too many things were at the top level. Anything non-essential has been moved to the "Advanced Sound Options" submenu and the pointless sound backend switch has been removed entirely. --- wadsrc/static/language.enu | 15 ------------- wadsrc/static/menudef.txt | 46 +++++++++++++------------------------- 2 files changed, 15 insertions(+), 46 deletions(-) diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index ab2f74fb46..2b49fe55f9 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -2530,22 +2530,7 @@ OPTSTR_SIMPLEARROW = "Simple arrow"; OPTSTR_HERETIC = "Heretic"; OPTSTR_CHEX = "Chex"; OPTSTR_SYSTEMCURSOR = "System cursor"; -OPTSTR_DIRECTSOUND = "DirectSound"; -OPTSTR_WASAPI = "Vista WASAPI"; -OPTSTR_ASIO = "ASIO"; -OPTSTR_WAVEOUT = "WaveOut"; OPTSTR_NOSOUND = "No Sound"; -OPTSTR_OSS = "OSS"; -OPTSTR_ALSA = "ALSA"; -OPTSTR_SDL = "SDL"; -OPTSTR_ESD = "ESD"; -OPTSTR_PULSEAUDIO = "PulseAudio"; -OPTSTR_COREAUDIO = "Core Audio"; -OPTSTR_PCM8BIT = "8-bit"; -OPTSTR_PCM16BIT = "16-bit"; -OPTSTR_PCM24BIT = "24-bit"; -OPTSTR_PCM32BIT = "32-bit"; -OPTSTR_PCMFLOAT = "32-bit float"; OPTSTR_AUTO = "Auto"; OPTSTR_MONO = "Mono"; OPTSTR_STEREO = "Stereo"; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 4bb577ac6d..965f23d0c9 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -1553,16 +1553,6 @@ OptionString ALResamplers // filled in by the sound code } -OptionString OutputFormats -{ - "PCM-8", "$OPTSTR_PCM8BIT" - "PCM-16", "$OPTSTR_PCM16BIT" - "PCM-24", "$OPTSTR_PCM24BIT" - "PCM-32", "$OPTSTR_PCM32BIT" - "PCM-Float", "$OPTSTR_PCMFLOAT" -} - - OptionString SpeakerModes { "Auto", "$OPTSTR_AUTO" @@ -1585,12 +1575,6 @@ OptionString Resamplers } -OptionString SoundBackendsOpenALOnly -{ - "openal", "$OPTSTR_OPENAL" - "null", "$OPTSTR_NOSOUND" -} - OptionMenu OpenALSoundItems protected { Title "$OPENALMNU_TITLE" @@ -1616,23 +1600,8 @@ OptionMenu SoundOptions protected Option "$SNDMNU_UNDERWATERREVERB", "snd_waterreverb", "OnOff" Option "$SNDMNU_RANDOMIZEPITCHES", "snd_pitched", "OnOff" Slider "$SNDMNU_CHANNELS", "snd_channels", 64, 256, 8, 0 - StaticText " " - Option "$SNDMNU_BACKGROUND", "i_soundinbackground", "OnOff" - StaticText " " - - ifoption(openal) - { - Option "$SNDMNU_BACKEND", "snd_backend", "SoundBackendsOpenALOnly" - Submenu "$SNDMNU_OPENAL", "OpenALSoundItems" - } - StaticText " " - Command "$SNDMNU_RESTART", "snd_reset" - StaticText " " Submenu "$SNDMNU_ADVANCED", "AdvSoundOptions" - Submenu "$SNDMNU_MIDIPLAYER", "MidiPlayerOptions" - Submenu "$SNDMNU_MODREPLAYER", "ModReplayerOptions" - StaticText " " Submenu "$OPTMNU_REVERB", "ReverbEdit" } @@ -1665,6 +1634,21 @@ OptionMenu AdvSoundOptions protected Title "$ADVSNDMNU_TITLE" Option "$ADVSNDMNU_SAMPLERATE", "snd_samplerate", "SampleRates" Option "$ADVSNDMNU_HRTF", "snd_hrtf", "AutoOffOn" + StaticText " " + Option "$SNDMNU_BACKGROUND", "i_soundinbackground", "OnOff" + StaticText " " + + ifoption(openal) + { + StaticText " " + Submenu "$SNDMNU_OPENAL", "OpenALSoundItems" + } + + StaticText " " + Submenu "$SNDMNU_MIDIPLAYER", "MidiPlayerOptions" + Submenu "$SNDMNU_MODREPLAYER", "ModReplayerOptions" + StaticText " " + Command "$SNDMNU_RESTART", "snd_reset" } OptionMenu GusConfigMenu protected From 927d333063efd0c6dfaf40bf56ae251a7138638c Mon Sep 17 00:00:00 2001 From: Player701 Date: Thu, 29 Nov 2018 23:49:13 +0300 Subject: [PATCH 06/10] - Exported AActor::Grind to ZScript. --- src/actor.h | 3 +- src/g_inventory/a_pickups.cpp | 27 ------------------ src/g_inventory/a_pickups.h | 1 - src/p_map.cpp | 2 +- src/p_mobj.cpp | 20 +++++++++++++ src/po_man.cpp | 2 +- wadsrc/static/zscript/actor.txt | 1 + wadsrc/static/zscript/inventory/inventory.txt | 28 ++++++++++++++++++- 8 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/actor.h b/src/actor.h index bd6b51a4da..8f0a8e9f38 100644 --- a/src/actor.h +++ b/src/actor.h @@ -814,7 +814,8 @@ public: virtual bool Massacre (); // Transforms the actor into a finely-ground paste - virtual bool Grind(bool items); + bool Grind(bool items); + bool CallGrind(bool items); // Get this actor's team int GetTeam(); diff --git a/src/g_inventory/a_pickups.cpp b/src/g_inventory/a_pickups.cpp index 7b7721b486..6ec1a4e846 100644 --- a/src/g_inventory/a_pickups.cpp +++ b/src/g_inventory/a_pickups.cpp @@ -173,33 +173,6 @@ void AInventory::MarkPrecacheSounds() const PickupSound.MarkUsed(); } -//=========================================================================== -// -// AInventory :: Grind -// -//=========================================================================== - -bool AInventory::Grind(bool items) -{ - // Does this grind request even care about items? - if (!items) - { - return false; - } - // Dropped items are normally destroyed by crushers. Set the DONTGIB flag, - // and they'll act like corpses with it set and be immune to crushers. - if (flags & MF_DROPPED) - { - if (!(flags3 & MF3_DONTGIB)) - { - Destroy(); - } - return false; - } - // Non-dropped items call the super method for compatibility. - return Super::Grind(items); -} - //=========================================================================== // // AInventory :: BecomeItem diff --git a/src/g_inventory/a_pickups.h b/src/g_inventory/a_pickups.h index 4cb202f7d2..33b7a40a23 100644 --- a/src/g_inventory/a_pickups.h +++ b/src/g_inventory/a_pickups.h @@ -76,7 +76,6 @@ public: virtual void OnDestroy() override; virtual void Tick() override; virtual bool Massacre() override; - virtual bool Grind(bool items) override; bool CallTryPickup(AActor *toucher, AActor **toucher_return = NULL); // Wrapper for script function. diff --git a/src/p_map.cpp b/src/p_map.cpp index e0b16ca2e5..5d248d2dbf 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -6485,7 +6485,7 @@ void P_FindBelowIntersectors(AActor *actor) void P_DoCrunch(AActor *thing, FChangePosition *cpos) { - if (!(thing && thing->Grind(true) && cpos)) return; + if (!(thing && thing->CallGrind(true) && cpos)) return; cpos->nofit = true; if ((cpos->crushchange > 0) && !(level.maptime & 3)) diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 0999e71eb2..67290a08ee 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -1903,6 +1903,26 @@ bool AActor::Grind(bool items) return true; } +DEFINE_ACTION_FUNCTION(AActor, Grind) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_BOOL(items); + ACTION_RETURN_BOOL(self->Grind(items)); +} + +bool AActor::CallGrind(bool items) +{ + IFVIRTUAL(AActor, Grind) + { + VMValue params[] = { (DObject*)this, items }; + int retv; + VMReturn ret(&retv); + VMCall(func, params, 2, &ret, 1); + return !!retv; + } + return Grind(items); +} + //============================================================================ // // AActor :: Massacre diff --git a/src/po_man.cpp b/src/po_man.cpp index ca12120de8..cb934c4764 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -869,7 +869,7 @@ void FPolyObj::ThrustMobj (AActor *actor, side_t *side) P_TraceBleed (newdam > 0 ? newdam : crush, actor); } } - if (level.flags2 & LEVEL2_POLYGRIND) actor->Grind(false); // crush corpses that get caught in a polyobject's way + if (level.flags2 & LEVEL2_POLYGRIND) actor->CallGrind(false); // crush corpses that get caught in a polyobject's way } //========================================================================== diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 1099464a1a..a77b5d559e 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -577,6 +577,7 @@ class Actor : Thinker native native void ClearCounters(); native bool GiveBody (int num, int max=0); native bool HitFloor(); + native virtual bool Grind(bool items); native clearscope bool isTeammate(Actor other) const; native clearscope int PlayerNumber() const; native void SetFriendPlayer(PlayerInfo player); diff --git a/wadsrc/static/zscript/inventory/inventory.txt b/wadsrc/static/zscript/inventory/inventory.txt index 1e47428921..8645cf74f9 100644 --- a/wadsrc/static/zscript/inventory/inventory.txt +++ b/wadsrc/static/zscript/inventory/inventory.txt @@ -144,7 +144,33 @@ class Inventory : Actor native Spawn ("ItemFog", Pos, ALLOW_REPLACE); } } - + + //=========================================================================== + // + // AInventory :: Grind + // + //=========================================================================== + + override bool Grind(bool items) + { + // Does this grind request even care about items? + if (!items) + { + return false; + } + // Dropped items are normally destroyed by crushers. Set the DONTGIB flag, + // and they'll act like corpses with it set and be immune to crushers. + if (bDropped) + { + if (!bDontGib) + { + Destroy(); + } + return false; + } + // Non-dropped items call the super method for compatibility. + return Super.Grind(items); + } //=========================================================================== // From 024870ba1168564c256f1854b24ed888b1285ba7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 30 Nov 2018 17:02:39 +0100 Subject: [PATCH 07/10] - merged DCanvas and DSimpleCanvas and use a TArray to hold its memory. --- src/swrenderer/r_swrenderer.cpp | 4 +- src/swrenderer/r_swscene.cpp | 2 +- src/swrenderer/r_swscene.h | 2 +- src/textures/formats/canvastexture.cpp | 4 +- src/textures/textures.h | 10 ++-- src/v_framebuffer.cpp | 81 -------------------------- src/v_video.cpp | 53 +++++++++++++++++ src/v_video.h | 33 ++--------- 8 files changed, 68 insertions(+), 121 deletions(-) diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index 9dbba63cb8..a20b474cd2 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -181,7 +181,7 @@ void FSoftwareRenderer::RenderView(player_t *player, DCanvas *target, void *vide void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height) { - DSimpleCanvas pic(width, height, false); + DCanvas pic(width, height, false); PalEntry palette[256]; // Take a snapshot of the player's view @@ -241,7 +241,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin cameraViewwindow = r_viewwindow; uint8_t *Pixels = renderTarget->IsBgra() ? (uint8_t*)tex->GetPixelsBgra() : (uint8_t*)tex->GetPixels(DefaultRenderStyle()); - DSimpleCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas(); + DCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas(); // curse Doom's overuse of global variables in the renderer. // These get clobbered by rendering to a camera texture but they need to be preserved so the final rendering can be done with the correct palette. diff --git a/src/swrenderer/r_swscene.cpp b/src/swrenderer/r_swscene.cpp index f68336e853..c29e4fb673 100644 --- a/src/swrenderer/r_swscene.cpp +++ b/src/swrenderer/r_swscene.cpp @@ -96,7 +96,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) mat->AddTextureLayer(PaletteTexture.get()); Canvas.reset(); - Canvas.reset(new DSimpleCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); + Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); } auto buf = fbtex->SystemTexture[0]->MapBuffer(); diff --git a/src/swrenderer/r_swscene.h b/src/swrenderer/r_swscene.h index 9ed0bec03b..47757a3348 100644 --- a/src/swrenderer/r_swscene.h +++ b/src/swrenderer/r_swscene.h @@ -16,7 +16,7 @@ class SWSceneDrawer std::unique_ptr FBTexture[2]; int FBTextureIndex = 0; bool FBIsTruecolor = false; - std::unique_ptr Canvas; + std::unique_ptr Canvas; public: SWSceneDrawer(); diff --git a/src/textures/formats/canvastexture.cpp b/src/textures/formats/canvastexture.cpp index ae4a4697ed..49729818b7 100644 --- a/src/textures/formats/canvastexture.cpp +++ b/src/textures/formats/canvastexture.cpp @@ -108,7 +108,7 @@ const uint32_t *FCanvasTexture::GetPixelsBgra() void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style because making it work as alpha texture is impractical. { - Canvas = new DSimpleCanvas (Width, Height, false); + Canvas = new DCanvas (Width, Height, false); if (Width != Height || Width != Canvas->GetPitch()) { @@ -128,7 +128,7 @@ void FCanvasTexture::MakeTexture (FRenderStyle) // This ignores the render style void FCanvasTexture::MakeTextureBgra() { - CanvasBgra = new DSimpleCanvas(Width, Height, true); + CanvasBgra = new DCanvas(Width, Height, true); if (Width != Height || Width != CanvasBgra->GetPitch()) { diff --git a/src/textures/textures.h b/src/textures/textures.h index fc70ef1229..4c4cd57c6e 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -754,7 +754,7 @@ protected: }; // A texture that can be drawn to. -class DSimpleCanvas; +class DCanvas; class AActor; class FCanvasTexture : public FTexture @@ -770,16 +770,16 @@ public: bool CheckModified (FRenderStyle) override; void NeedUpdate() { bNeedsUpdate=true; } void SetUpdated() { bNeedsUpdate = false; bDidUpdate = true; bFirstUpdate = false; } - DSimpleCanvas *GetCanvas() { return Canvas; } - DSimpleCanvas *GetCanvasBgra() { return CanvasBgra; } + DCanvas *GetCanvas() { return Canvas; } + DCanvas *GetCanvasBgra() { return CanvasBgra; } bool Mipmapped() override { return false; } void MakeTexture (FRenderStyle style); void MakeTextureBgra (); protected: - DSimpleCanvas *Canvas = nullptr; - DSimpleCanvas *CanvasBgra = nullptr; + DCanvas *Canvas = nullptr; + DCanvas *CanvasBgra = nullptr; uint8_t *Pixels = nullptr; uint32_t *PixelsBgra = nullptr; Span DummySpans[2]; diff --git a/src/v_framebuffer.cpp b/src/v_framebuffer.cpp index c89d3cf8a8..dd697d9433 100644 --- a/src/v_framebuffer.cpp +++ b/src/v_framebuffer.cpp @@ -82,87 +82,6 @@ void DFrameBuffer::CalcGamma (float gamma, uint8_t gammalookup[256]) } } -//========================================================================== -// -// DSimpleCanvas Constructor -// -// A simple canvas just holds a buffer in main memory. -// -//========================================================================== - -DSimpleCanvas::DSimpleCanvas (int width, int height, bool bgra) - : DCanvas (width, height, bgra) -{ - PixelBuffer = nullptr; - Resize(width, height); -} - -void DSimpleCanvas::Resize(int width, int height) -{ - Width = width; - Height = height; - - if (PixelBuffer != NULL) - { - delete[] PixelBuffer; - PixelBuffer = NULL; - } - - // Making the pitch a power of 2 is very bad for performance - // Try to maximize the number of cache lines that can be filled - // for each column drawing operation by making the pitch slightly - // longer than the width. The values used here are all based on - // empirical evidence. - - if (width <= 640) - { - // For low resolutions, just keep the pitch the same as the width. - // Some speedup can be seen using the technique below, but the speedup - // is so marginal that I don't consider it worthwhile. - Pitch = width; - } - else - { - // If we couldn't figure out the CPU's L1 cache line size, assume - // it's 32 bytes wide. - if (CPU.DataL1LineSize == 0) - { - CPU.DataL1LineSize = 32; - } - // The Athlon and P3 have very different caches, apparently. - // I am going to generalize the Athlon's performance to all AMD - // processors and the P3's to all non-AMD processors. I don't know - // how smart that is, but I don't have a vast plethora of - // processors to test with. - if (CPU.bIsAMD) - { - Pitch = width + CPU.DataL1LineSize; - } - else - { - Pitch = width + MAX(0, CPU.DataL1LineSize - 8); - } - } - int bytes_per_pixel = Bgra ? 4 : 1; - PixelBuffer = new uint8_t[Pitch * height * bytes_per_pixel]; - memset (PixelBuffer, 0, Pitch * height * bytes_per_pixel); -} - -//========================================================================== -// -// DSimpleCanvas Destructor -// -//========================================================================== - -DSimpleCanvas::~DSimpleCanvas () -{ - if (PixelBuffer != NULL) - { - delete[] PixelBuffer; - PixelBuffer = NULL; - } -} - //========================================================================== // // DFrameBuffer Constructor diff --git a/src/v_video.cpp b/src/v_video.cpp index c94f141d24..b9efcf6a1c 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -177,6 +177,7 @@ DCanvas::DCanvas (int _width, int _height, bool _bgra) Width = _width; Height = _height; Bgra = _bgra; + Resize(_width, _height); } //========================================================================== @@ -189,6 +190,58 @@ DCanvas::~DCanvas () { } +//========================================================================== +// +// +// +//========================================================================== + +void DCanvas::Resize(int width, int height) +{ + Width = width; + Height = height; + + // Making the pitch a power of 2 is very bad for performance + // Try to maximize the number of cache lines that can be filled + // for each column drawing operation by making the pitch slightly + // longer than the width. The values used here are all based on + // empirical evidence. + + if (width <= 640) + { + // For low resolutions, just keep the pitch the same as the width. + // Some speedup can be seen using the technique below, but the speedup + // is so marginal that I don't consider it worthwhile. + Pitch = width; + } + else + { + // If we couldn't figure out the CPU's L1 cache line size, assume + // it's 32 bytes wide. + if (CPU.DataL1LineSize == 0) + { + CPU.DataL1LineSize = 32; + } + // The Athlon and P3 have very different caches, apparently. + // I am going to generalize the Athlon's performance to all AMD + // processors and the P3's to all non-AMD processors. I don't know + // how smart that is, but I don't have a vast plethora of + // processors to test with. + if (CPU.bIsAMD) + { + Pitch = width + CPU.DataL1LineSize; + } + else + { + Pitch = width + MAX(0, CPU.DataL1LineSize - 8); + } + } + int bytes_per_pixel = Bgra ? 4 : 1; + Pixels.Resize(Pitch * height * bytes_per_pixel); + memset (Pixels.Data(), 0, Pixels.Size()); +} + + //========================================================================== // // V_GetColorFromString diff --git a/src/v_video.h b/src/v_video.h index 61185e1b32..fbecf1f420 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -291,53 +291,29 @@ struct VMVa_List // // VIDEO // -// [RH] Made screens more implementation-independant: // class DCanvas { public: DCanvas (int width, int height, bool bgra); - virtual ~DCanvas (); + ~DCanvas (); + void Resize(int width, int height); // Member variable access - inline uint8_t *GetPixels () const { return PixelBuffer; } + inline uint8_t *GetPixels () const { return Pixels.Data(); } inline int GetWidth () const { return Width; } inline int GetHeight () const { return Height; } inline int GetPitch () const { return Pitch; } inline bool IsBgra() const { return Bgra; } - // Note: pitch here is in pixels, not bytes. - bool SetBuffer(int width, int height, int pitch, uint8_t *buffer) - { - assert(buffer); - Width = width; - Height = height; - Pitch = pitch; - PixelBuffer = buffer; - return true; - } - - protected: - uint8_t *PixelBuffer; + TArray Pixels; int Width; int Height; int Pitch; bool Bgra; }; -// A canvas in system memory. - -class DSimpleCanvas : public DCanvas -{ - typedef DCanvas Super; -public: - DSimpleCanvas (int width, int height, bool bgra); - ~DSimpleCanvas (); - void Resize(int width, int height); -}; - - class FUniquePalette; class IHardwareTexture; class FTexture; @@ -348,7 +324,6 @@ class FTexture; class DFrameBuffer { - typedef DSimpleCanvas Super; protected: void DrawTextureV(FTexture *img, double x, double y, uint32_t tag, va_list tags) = delete; From 25ad71a113360179217e5848683d18a729e73aa9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 30 Nov 2018 17:07:42 +0100 Subject: [PATCH 08/10] - Changed a few allocations into usin TArrays S_SoundCurve in particular looked like a candidate for leaking memory. --- src/s_sound.cpp | 68 +++++++++++++++++------------------------- src/s_sound.h | 4 +-- src/sc_man.cpp | 12 +++----- src/sound/oalsound.cpp | 4 +-- src/v_font.cpp | 18 +++++------ 5 files changed, 43 insertions(+), 63 deletions(-) diff --git a/src/s_sound.cpp b/src/s_sound.cpp index be12d36939..8a10d71b79 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -150,8 +150,7 @@ FSoundChan *Channels; FSoundChan *FreeChannels; FRolloffInfo S_Rolloff; -uint8_t *S_SoundCurve; -int S_SoundCurveSize; +TArray S_SoundCurve; FBoolCVar noisedebug ("noise", false, 0); // [RH] Print sound debugging info? CUSTOM_CVAR (Int, snd_channels, 128, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // number of channels available @@ -311,20 +310,16 @@ void S_Init () atterm (S_Shutdown); - // remove old data (S_Init can be called multiple times!) - if (S_SoundCurve != NULL) - { - delete[] S_SoundCurve; - S_SoundCurve = NULL; - } - // Heretic and Hexen have sound curve lookup tables. Doom does not. curvelump = Wads.CheckNumForName ("SNDCURVE"); if (curvelump >= 0) { - S_SoundCurveSize = Wads.LumpLength (curvelump); - S_SoundCurve = new uint8_t[S_SoundCurveSize]; - Wads.ReadLump(curvelump, S_SoundCurve); + S_SoundCurve.Resize(Wads.LumpLength (curvelump)); + Wads.ReadLump(curvelump, S_SoundCurve.Data()); + } + else + { + S_SoundCurve.Clear(); } // Free all channels for use. @@ -376,11 +371,6 @@ void S_Shutdown () } FreeChannels = NULL; - if (S_SoundCurve != NULL) - { - delete[] S_SoundCurve; - S_SoundCurve = NULL; - } if (PlayList != NULL) { delete PlayList; @@ -1486,34 +1476,32 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer) if (size > 0) { auto wlump = Wads.OpenLumpReader(sfx->lumpnum); - uint8_t *sfxdata = new uint8_t[size]; - wlump.Read(sfxdata, size); - int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]); + auto sfxdata = wlump.Read(size); + int32_t dmxlen = LittleLong(((int32_t *)sfxdata.Data())[1]); std::pair snd; // If the sound is voc, use the custom loader. - if (strncmp ((const char *)sfxdata, "Creative Voice File", 19) == 0) + if (strncmp ((const char *)sfxdata.Data(), "Creative Voice File", 19) == 0) { - snd = GSnd->LoadSoundVoc(sfxdata, size); + snd = GSnd->LoadSoundVoc(sfxdata.Data(), size); } // If the sound is raw, just load it as such. else if (sfx->bLoadRAW) { - snd = GSnd->LoadSoundRaw(sfxdata, size, sfx->RawRate, 1, 8, sfx->LoopStart); + snd = GSnd->LoadSoundRaw(sfxdata.Data(), size, sfx->RawRate, 1, 8, sfx->LoopStart); } // Otherwise, try the sound as DMX format. - else if (((uint8_t *)sfxdata)[0] == 3 && ((uint8_t *)sfxdata)[1] == 0 && dmxlen <= size - 8) + else if (((uint8_t *)sfxdata.Data())[0] == 3 && ((uint8_t *)sfxdata.Data())[1] == 0 && dmxlen <= size - 8) { - int frequency = LittleShort(((uint16_t *)sfxdata)[1]); + int frequency = LittleShort(((uint16_t *)sfxdata.Data())[1]); if (frequency == 0) frequency = 11025; - snd = GSnd->LoadSoundRaw(sfxdata+8, dmxlen, frequency, 1, 8, sfx->LoopStart); + snd = GSnd->LoadSoundRaw(sfxdata.Data()+8, dmxlen, frequency, 1, 8, sfx->LoopStart); } // If that fails, let the sound system try and figure it out. else { - snd = GSnd->LoadSound(sfxdata, size, false, pBuffer); + snd = GSnd->LoadSound(sfxdata.Data(), size, false, pBuffer); } - delete[] sfxdata; sfx->data = snd.first; if(snd.second) @@ -1554,33 +1542,31 @@ static void S_LoadSound3D(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer) if (size <= 0) return; auto wlump = Wads.OpenLumpReader(sfx->lumpnum); - uint8_t *sfxdata = new uint8_t[size]; - wlump.Read(sfxdata, size); - int32_t dmxlen = LittleLong(((int32_t *)sfxdata)[1]); + auto sfxdata = wlump.Read(size); + int32_t dmxlen = LittleLong(((int32_t *)sfxdata.Data())[1]); // If the sound is voc, use the custom loader. - if (strncmp((const char *)sfxdata, "Creative Voice File", 19) == 0) + if (strncmp((const char *)sfxdata.Data(), "Creative Voice File", 19) == 0) { - snd = GSnd->LoadSoundVoc(sfxdata, size, true); + snd = GSnd->LoadSoundVoc(sfxdata.Data(), size, true); } // If the sound is raw, just load it as such. else if (sfx->bLoadRAW) { - snd = GSnd->LoadSoundRaw(sfxdata, size, sfx->RawRate, 1, 8, sfx->LoopStart, true); + snd = GSnd->LoadSoundRaw(sfxdata.Data(), size, sfx->RawRate, 1, 8, sfx->LoopStart, true); } // Otherwise, try the sound as DMX format. - else if (((uint8_t *)sfxdata)[0] == 3 && ((uint8_t *)sfxdata)[1] == 0 && dmxlen <= size - 8) + else if (((uint8_t *)sfxdata.Data())[0] == 3 && ((uint8_t *)sfxdata.Data())[1] == 0 && dmxlen <= size - 8) { - int frequency = LittleShort(((uint16_t *)sfxdata)[1]); + int frequency = LittleShort(((uint16_t *)sfxdata.Data())[1]); if (frequency == 0) frequency = 11025; - snd = GSnd->LoadSoundRaw(sfxdata + 8, dmxlen, frequency, 1, 8, sfx->LoopStart, -1, true); + snd = GSnd->LoadSoundRaw(sfxdata.Data() + 8, dmxlen, frequency, 1, 8, sfx->LoopStart, -1, true); } // If that fails, let the sound system try and figure it out. else { - snd = GSnd->LoadSound(sfxdata, size, true, pBuffer); + snd = GSnd->LoadSound(sfxdata.Data(), size, true, pBuffer); } - delete[] sfxdata; } sfx->data3d = snd.first; @@ -2256,9 +2242,9 @@ float S_GetRolloff(FRolloffInfo *rolloff, float distance, bool logarithmic) } float volume = (rolloff->MaxDistance - distance) / (rolloff->MaxDistance - rolloff->MinDistance); - if (rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve != NULL) + if (rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve.Size() > 0) { - volume = S_SoundCurve[int(S_SoundCurveSize * (1 - volume))] / 127.f; + volume = S_SoundCurve[int(S_SoundCurve.Size() * (1 - volume))] / 127.f; } if (logarithmic) { diff --git a/src/s_sound.h b/src/s_sound.h index 1d42cb2aed..5ff5110e7a 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -165,8 +165,8 @@ public: }; extern FRolloffInfo S_Rolloff; -extern uint8_t *S_SoundCurve; -extern int S_SoundCurveSize; +extern TArray S_SoundCurve; + // Information about one playing sound. struct sector_t; diff --git a/src/sc_man.cpp b/src/sc_man.cpp index 44fbdb42ca..7eb6b3c3aa 100644 --- a/src/sc_man.cpp +++ b/src/sc_man.cpp @@ -249,14 +249,10 @@ bool FScanner::OpenFile (const char *name) FileReader fr; if (!fr.OpenFile(name)) return false; auto filesize = fr.GetLength(); - auto filebuf = new uint8_t[filesize]; - if (fr.Read(filebuf, filesize) != filesize) - { - delete[] filebuf; - return false; - } - ScriptBuffer = FString((const char *)filebuf, filesize); - delete[] filebuf; + auto filebuff = fr.Read(); + if (filebuff.Size() == 0 && filesize > 0) return false; + + ScriptBuffer = FString((const char *)filebuff.Data(), filesize); ScriptName = name; // This is used for error messages so the full file name is preferable LumpNum = -1; PrepareScript (); diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index 4b494ed110..ed3098d9f9 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -688,8 +688,8 @@ static float GetRolloff(const FRolloffInfo *rolloff, float distance) if(rolloff->RolloffType == ROLLOFF_Linear) return volume; - if(rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve != NULL) - return S_SoundCurve[int(S_SoundCurveSize * (1.f - volume))] / 127.f; + if(rolloff->RolloffType == ROLLOFF_Custom && S_SoundCurve.Size() > 0) + return S_SoundCurve[int(S_SoundCurve.Size() * (1.f - volume))] / 127.f; return (powf(10.f, volume) - 1.f) / 9.f; } diff --git a/src/v_font.cpp b/src/v_font.cpp index 4678c56b95..3a589e7413 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -357,7 +357,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count, int i; FTextureID lump; char buffer[12]; - FTexture **charlumps; + TArray charLumps; int maxyoffs; bool doomtemplate = gameinfo.gametype & GAME_DoomChex ? strncmp (nametemplate, "STCFN", 5) == 0 : false; bool stcfn121 = false; @@ -365,7 +365,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count, noTranslate = notranslate; Lump = fdlump; Chars = new CharData[count]; - charlumps = new FTexture *[count]; + charLumps.Resize(count); PatchRemap = new uint8_t[256]; FirstChar = first; LastChar = first + count - 1; @@ -381,7 +381,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count, for (i = 0; i < count; i++) { - charlumps[i] = NULL; + charLumps[i] = NULL; mysnprintf (buffer, countof(buffer), nametemplate, i + start); lump = TexMan.CheckForTexture(buffer, ETextureType::MiscPatch); @@ -395,7 +395,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count, !TexMan.CheckForTexture("STCFN122", ETextureType::MiscPatch).isValid()) { // insert the incorrectly named '|' graphic in its correct position. - if (count > 124-start) charlumps[124-start] = TexMan[lump]; + if (count > 124-start) charLumps[124-start] = TexMan[lump]; lump.SetInvalid(); stcfn121 = true; } @@ -408,7 +408,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count, { // set the lump here only if it represents a valid texture if (i != 124-start || !stcfn121) - charlumps[i] = pic; + charLumps[i] = pic; int height = pic->GetScaledHeight(); int yoffs = pic->GetScaledTopOffset(0); @@ -425,10 +425,10 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count, } } - if (charlumps[i] != NULL) + if (charLumps[i] != nullptr) { - if (!noTranslate) Chars[i].Pic = new FFontChar1 (charlumps[i]); - else Chars[i].Pic = charlumps[i]; + if (!noTranslate) Chars[i].Pic = new FFontChar1 (charLumps[i]); + else Chars[i].Pic = charLumps[i]; Chars[i].XMove = Chars[i].Pic->GetScaledWidth(); } else @@ -454,8 +454,6 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count, FixXMoves(); if (!noTranslate) LoadTranslations(); - - delete[] charlumps; } //========================================================================== From a3df67bdd4c14a45baea3d67ca283643d33f3aa0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 30 Nov 2018 17:12:36 +0100 Subject: [PATCH 09/10] - let FOBJModel::ParseVector actually use its templated size parameter In this setup the array can be statically updated because the size is always constant per instantiation --- src/r_data/models/models_obj.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/r_data/models/models_obj.cpp b/src/r_data/models/models_obj.cpp index 035efd4d4d..b6adb29cf9 100644 --- a/src/r_data/models/models_obj.cpp +++ b/src/r_data/models/models_obj.cpp @@ -236,7 +236,7 @@ bool FOBJModel::Load(const char* fn, int lumpnum, const char* buffer, int length */ template void FOBJModel::ParseVector(TArray &array) { - float *coord = new float[L]; + float coord[L]; for (size_t axis = 0; axis < L; axis++) { sc.MustGetFloat(); @@ -244,7 +244,6 @@ template void FOBJModel::ParseVector(TArray &array) } T vec(coord); array.Push(vec); - delete[] coord; } /** From 00d97197db7874a67b3c92c5d3158f131b327c84 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 30 Nov 2018 17:16:21 +0100 Subject: [PATCH 10/10] - removed deprecated method to retrieve OpenGL extensions Since we force a core profile and this was explicitly disabled for core profiles, this code has no use anymore --- src/gl_load/gl_interface.cpp | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/src/gl_load/gl_interface.cpp b/src/gl_load/gl_interface.cpp index d690a1a15f..d2dc502db3 100644 --- a/src/gl_load/gl_interface.cpp +++ b/src/gl_load/gl_interface.cpp @@ -52,35 +52,11 @@ static void CollectExtensions() int max = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &max); - if (max == 0) + // Use modern method to collect extensions + for (int i = 0; i < max; i++) { - // Try old method to collect extensions - const char *supported = (char *)glGetString(GL_EXTENSIONS); - - if (nullptr != supported) - { - char *extensions = new char[strlen(supported) + 1]; - strcpy(extensions, supported); - - char *extension = strtok(extensions, " "); - - while (extension) - { - m_Extensions.Push(FString(extension)); - extension = strtok(nullptr, " "); - } - - delete [] extensions; - } - } - else - { - // Use modern method to collect extensions - for (int i = 0; i < max; i++) - { - extension = (const char*)glGetStringi(GL_EXTENSIONS, i); - m_Extensions.Push(FString(extension)); - } + extension = (const char*)glGetStringi(GL_EXTENSIONS, i); + m_Extensions.Push(FString(extension)); } } @@ -269,4 +245,4 @@ std::pair gl_getInfo() // gl_ARB_bindless_texture is the closest we can get to determine Vulkan support from OpenGL. // This isn't foolproof because Intel doesn't support it but for NVidia and AMD support of this extension means Vulkan support. return std::make_pair(realglversion, CheckExtension("GL_ARB_bindless_texture")); -} \ No newline at end of file +}