From ba114f6f238d70d10333d4b1d1b396fac088f219 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 25 Jan 2019 01:26:16 +0100 Subject: [PATCH] - give the hardware renderer's drawinfo its own level pointer --- src/actor.h | 2 +- src/dthinker.cpp | 2 +- src/gl/renderer/gl_scene.cpp | 5 ++-- src/hwrenderer/data/flatvertices.cpp | 16 +++++----- src/hwrenderer/data/flatvertices.h | 6 ++-- src/hwrenderer/data/hw_vertexbuilder.cpp | 8 ++--- src/hwrenderer/data/hw_vertexbuilder.h | 2 +- src/hwrenderer/scene/hw_bsp.cpp | 6 ++-- src/hwrenderer/scene/hw_decal.cpp | 6 ++-- src/hwrenderer/scene/hw_drawinfo.cpp | 37 ++++++++++++++---------- src/hwrenderer/scene/hw_drawinfo.h | 8 ++--- src/hwrenderer/scene/hw_drawlist.cpp | 4 +-- src/hwrenderer/scene/hw_fakeflat.cpp | 5 ++-- src/hwrenderer/scene/hw_flats.cpp | 10 +++---- src/hwrenderer/scene/hw_portal.cpp | 8 ++--- src/hwrenderer/scene/hw_portal.h | 2 +- src/hwrenderer/scene/hw_renderhacks.cpp | 22 +++++++------- src/hwrenderer/scene/hw_renderstate.cpp | 4 +-- src/hwrenderer/scene/hw_sky.cpp | 16 +++++----- src/hwrenderer/scene/hw_skydome.cpp | 5 ++-- src/hwrenderer/scene/hw_skydome.h | 5 ++-- src/hwrenderer/scene/hw_skyportal.cpp | 10 +++---- src/hwrenderer/scene/hw_spritelight.cpp | 4 +-- src/hwrenderer/scene/hw_sprites.cpp | 24 +++++++-------- src/hwrenderer/scene/hw_walls.cpp | 18 ++++++------ src/hwrenderer/scene/hw_weapon.cpp | 8 ++--- src/hwrenderer/utility/hw_clock.cpp | 3 +- src/hwrenderer/utility/hw_lighting.cpp | 22 +++++++------- src/maploader/maploader.cpp | 2 +- src/p_setup.cpp | 29 +++++++++++++++++++ src/p_spec.cpp | 26 +---------------- src/r_utility.cpp | 1 + src/r_utility.h | 3 ++ 33 files changed, 172 insertions(+), 157 deletions(-) diff --git a/src/actor.h b/src/actor.h index 778ed611ee..afed3a51f2 100644 --- a/src/actor.h +++ b/src/actor.h @@ -902,7 +902,7 @@ public: DVector2 Vec2Offset(double dx, double dy, bool absolute = false); DVector3 Vec2OffsetZ(double dx, double dy, double atz, bool absolute = false); - DVector2 AActor::Vec2Angle(double length, DAngle angle, bool absolute = false); + DVector2 Vec2Angle(double length, DAngle angle, bool absolute = false); DVector3 Vec3Offset(double dx, double dy, double dz, bool absolute = false); DVector3 Vec3Offset(const DVector3 &ofs, bool absolute = false); DVector3 Vec3Angle(double length, DAngle angle, double dz, bool absolute = false); diff --git a/src/dthinker.cpp b/src/dthinker.cpp index 0c41054799..439685438d 100644 --- a/src/dthinker.cpp +++ b/src/dthinker.cpp @@ -625,7 +625,7 @@ void DThinker::RunThinkers () auto next = light->next; light->Tick(); light = next; - } + } } else { diff --git a/src/gl/renderer/gl_scene.cpp b/src/gl/renderer/gl_scene.cpp index f19bf10189..52c4612889 100644 --- a/src/gl/renderer/gl_scene.cpp +++ b/src/gl/renderer/gl_scene.cpp @@ -39,6 +39,7 @@ #include "p_local.h" #include "serializer.h" #include "g_levellocals.h" +#include "actorinlines.h" #include "r_data/models/models.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/utility/hw_clock.h" @@ -175,7 +176,7 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came } - auto di = HWDrawInfo::StartDrawInfo(nullptr, mainvp, nullptr); + auto di = HWDrawInfo::StartDrawInfo(mainvp.ViewLevel, nullptr, mainvp, nullptr); auto &vp = di->Viewpoint; di->Set3DViewport(gl_RenderState); @@ -221,4 +222,4 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came return mainvp.sector; } -} \ No newline at end of file +} diff --git a/src/hwrenderer/data/flatvertices.cpp b/src/hwrenderer/data/flatvertices.cpp index 6ba517bdf9..d185240fb4 100644 --- a/src/hwrenderer/data/flatvertices.cpp +++ b/src/hwrenderer/data/flatvertices.cpp @@ -232,9 +232,9 @@ int FFlatVertexBuffer::CreateIndexedVertices(int h, sector_t *sec, const secplan // //========================================================================== -void FFlatVertexBuffer::CreateIndexedFlatVertices() +void FFlatVertexBuffer::CreateIndexedFlatVertices(TArray §ors) { - auto verts = BuildVertices(); + auto verts = BuildVertices(sectors); int i = 0; /* @@ -259,7 +259,7 @@ void FFlatVertexBuffer::CreateIndexedFlatVertices() for (int h = sector_t::floor; h <= sector_t::ceiling; h++) { - for (auto &sec : level.sectors) + for (auto &sec : sectors) { CreateIndexedVertices(h, &sec, sec.GetSecPlane(h), h == sector_t::floor, verts); } @@ -267,7 +267,7 @@ void FFlatVertexBuffer::CreateIndexedFlatVertices() // We need to do a final check for Vavoom water and FF_FIX sectors. // No new vertices are needed here. The planes come from the actual sector - for (auto &sec : level.sectors) + for (auto &sec : sectors) { for (auto ff : sec.e->XFloor.ffloors) { @@ -310,10 +310,10 @@ void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane) // //========================================================================== -void FFlatVertexBuffer::CreateVertices() +void FFlatVertexBuffer::CreateVertices(TArray §ors) { vbo_shadowdata.Resize(NUM_RESERVED); - CreateIndexedFlatVertices(); + CreateIndexedFlatVertices(sectors); } //========================================================================== @@ -390,10 +390,10 @@ void FFlatVertexBuffer::Copy(int start, int count) // //========================================================================== -void FFlatVertexBuffer::CreateVBO() +void FFlatVertexBuffer::CreateVBO(TArray §ors) { vbo_shadowdata.Resize(mNumReserved); - FFlatVertexBuffer::CreateVertices(); + FFlatVertexBuffer::CreateVertices(sectors); mCurIndex = mIndex = vbo_shadowdata.Size(); Copy(0, mIndex); mIndexBuffer->SetData(ibo_data.Size() * sizeof(uint32_t), &ibo_data[0]); diff --git a/src/hwrenderer/data/flatvertices.h b/src/hwrenderer/data/flatvertices.h index 890e5580c2..1a1588c710 100644 --- a/src/hwrenderer/data/flatvertices.h +++ b/src/hwrenderer/data/flatvertices.h @@ -84,7 +84,7 @@ public: return std::make_pair(mVertexBuffer, mIndexBuffer); } - void CreateVBO(); + void CreateVBO(TArray §ors); void Copy(int start, int count); FFlatVertex *GetBuffer(int index) const @@ -119,11 +119,11 @@ private: int CreateIndexedSectionVertices(subsector_t *sub, const secplane_t &plane, int floor, VertexContainer &cont); int CreateIndexedSectorVertices(sector_t *sec, const secplane_t &plane, int floor, VertexContainer &cont); int CreateIndexedVertices(int h, sector_t *sec, const secplane_t &plane, int floor, VertexContainers &cont); - void CreateIndexedFlatVertices(); + void CreateIndexedFlatVertices(TArray §ors); void UpdatePlaneVertices(sector_t *sec, int plane); protected: - void CreateVertices(); + void CreateVertices(TArray §ors); void CheckPlanes(sector_t *sector); public: void CheckUpdate(sector_t *sector); diff --git a/src/hwrenderer/data/hw_vertexbuilder.cpp b/src/hwrenderer/data/hw_vertexbuilder.cpp index 6a0542cdf9..f4e4c6c368 100644 --- a/src/hwrenderer/data/hw_vertexbuilder.cpp +++ b/src/hwrenderer/data/hw_vertexbuilder.cpp @@ -137,12 +137,12 @@ static void CreateVerticesForSector(sector_t *sec, VertexContainer &gen) } -TArray BuildVertices() +TArray BuildVertices(TArray §ors) { - TArray verticesPerSector(level.sectors.Size(), true); - for (unsigned i=0; i verticesPerSector(sectors.Size(), true); + for (unsigned i=0; i< sectors.Size(); i++) { - CreateVerticesForSector(&level.sectors[i], verticesPerSector[i]); + CreateVerticesForSector(§ors[i], verticesPerSector[i]); } return verticesPerSector; } diff --git a/src/hwrenderer/data/hw_vertexbuilder.h b/src/hwrenderer/data/hw_vertexbuilder.h index 60ed770b86..8ab7d21d86 100644 --- a/src/hwrenderer/data/hw_vertexbuilder.h +++ b/src/hwrenderer/data/hw_vertexbuilder.h @@ -64,6 +64,6 @@ struct VertexContainer using VertexContainers = TArray; -VertexContainers BuildVertices(); +VertexContainers BuildVertices(TArray §ors); diff --git a/src/hwrenderer/scene/hw_bsp.cpp b/src/hwrenderer/scene/hw_bsp.cpp index d7f47f78e4..7ecbccaf21 100644 --- a/src/hwrenderer/scene/hw_bsp.cpp +++ b/src/hwrenderer/scene/hw_bsp.cpp @@ -686,7 +686,7 @@ void HWDrawInfo::DoSubsector(subsector_t * sub) fakesector = hw_FakeFlat(sector, in_area, false); } - uint8_t &srf = section_renderflags[level.sections.SectionIndex(sub->section)]; + uint8_t &srf = section_renderflags[Level->sections.SectionIndex(sub->section)]; if (!(srf & SSRF_PROCESSED)) { srf |= SSRF_PROCESSED; @@ -761,9 +761,9 @@ void HWDrawInfo::DoSubsector(subsector_t * sub) void HWDrawInfo::RenderBSPNode (void *node) { - if (level.nodes.Size() == 0) + if (Level->nodes.Size() == 0) { - DoSubsector (&level.subsectors[0]); + DoSubsector (&Level->subsectors[0]); return; } while (!((size_t)node & 1)) // Keep going until found a subsector diff --git a/src/hwrenderer/scene/hw_decal.cpp b/src/hwrenderer/scene/hw_decal.cpp index d3c28735c0..01c69de3f7 100644 --- a/src/hwrenderer/scene/hw_decal.cpp +++ b/src/hwrenderer/scene/hw_decal.cpp @@ -49,7 +49,7 @@ void GLDecal::DrawDecal(HWDrawInfo *di, FRenderState &state) auto tex = gltexture; // calculate dynamic light effect. - if (level.HasDynamicLights && !di->isFullbrightScene() && gl_light_sprites) + if (di->Level->HasDynamicLights && !di->isFullbrightScene() && gl_light_sprites) { // Note: This should be replaced with proper shader based lighting. double x, y; @@ -107,7 +107,7 @@ void GLDecal::DrawDecal(HWDrawInfo *di, FRenderState &state) thiscm.FadeColor = Colormap.FadeColor; thiscm.CopyFrom3DLight(&lightlist[k]); di->SetColor(state, thisll, rellight, di->isFullbrightScene(), thiscm, alpha); - if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) thiscm.Decolorize(); + if (di->Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) thiscm.Decolorize(); di->SetFog(state, thisll, rellight, di->isFullbrightScene(), &thiscm, false); state.SetSplitPlanes(lightlist[k].plane, lowplane); @@ -397,7 +397,7 @@ void GLWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor gldecal->Colormap = Colormap; - if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) + if (di->Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) { gldecal->Colormap.Decolorize(); } diff --git a/src/hwrenderer/scene/hw_drawinfo.cpp b/src/hwrenderer/scene/hw_drawinfo.cpp index 524cf660ff..8856fc9e2d 100644 --- a/src/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/hwrenderer/scene/hw_drawinfo.cpp @@ -85,13 +85,14 @@ HWDrawInfo *FDrawInfoList::GetNew() mList.Pop(di); return di; } - return new HWDrawInfo; + return new HWDrawInfo(); } void FDrawInfoList::Release(HWDrawInfo * di) { di->DrawScene = nullptr; di->ClearBuffers(); + di->Level = nullptr; mList.Push(di); } @@ -101,10 +102,11 @@ void FDrawInfoList::Release(HWDrawInfo * di) // //========================================================================== -HWDrawInfo *HWDrawInfo::StartDrawInfo(HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) +HWDrawInfo *HWDrawInfo::StartDrawInfo(FLevelLocals *lev, HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) { HWDrawInfo *di = di_list.GetNew(); if (parent) di->DrawScene = parent->DrawScene; + di->Level = lev; di->StartScene(parentvp, uniforms); return di; } @@ -125,7 +127,7 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni mClipper = &staticClipper; Viewpoint = parentvp; - lightmode = level.lightMode; + lightmode = Level->lightMode; if (uniforms) { VPUniforms = *uniforms; @@ -193,16 +195,19 @@ void HWDrawInfo::ClearBuffers() HandledSubsectors.Clear(); spriteindex = 0; - CurrentMapSections.Resize(level.NumMapSections); - CurrentMapSections.Zero(); + if (Level) + { + CurrentMapSections.Resize(Level->NumMapSections); + CurrentMapSections.Zero(); - section_renderflags.Resize(level.sections.allSections.Size()); - ss_renderflags.Resize(level.subsectors.Size()); - no_renderflags.Resize(level.subsectors.Size()); + section_renderflags.Resize(Level->sections.allSections.Size()); + ss_renderflags.Resize(Level->subsectors.Size()); + no_renderflags.Resize(Level->subsectors.Size()); - memset(§ion_renderflags[0], 0, level.sections.allSections.Size() * sizeof(section_renderflags[0])); - memset(&ss_renderflags[0], 0, level.subsectors.Size() * sizeof(ss_renderflags[0])); - memset(&no_renderflags[0], 0, level.nodes.Size() * sizeof(no_renderflags[0])); + memset(§ion_renderflags[0], 0, Level->sections.allSections.Size() * sizeof(section_renderflags[0])); + memset(&ss_renderflags[0], 0, Level->subsectors.Size() * sizeof(ss_renderflags[0])); + memset(&no_renderflags[0], 0, Level->nodes.Size() * sizeof(no_renderflags[0])); + } Decals[0].Clear(); Decals[1].Clear(); @@ -245,7 +250,7 @@ void HWDrawInfo::SetViewArea() } else { - in_area = level.HasHeightSecs ? area_default : area_normal; // depends on exposed lower sectors, if map contains heightsecs. + in_area = Level->HasHeightSecs ? area_default : area_normal; // depends on exposed lower sectors, if map contains heightsecs. } } @@ -335,7 +340,7 @@ angle_t HWDrawInfo::FrustumAngle() void HWDrawInfo::SetViewMatrix(const FRotator &angles, float vx, float vy, float vz, bool mirror, bool planemirror) { float mult = mirror ? -1.f : 1.f; - float planemult = planemirror ? -level.info->pixelstretch : level.info->pixelstretch; + float planemult = planemirror ? -Level->info->pixelstretch : Level->info->pixelstretch; VPUniforms.mViewMatrix.loadIdentity(); VPUniforms.mViewMatrix.rotate(angles.Roll.Degrees, 0.0f, 0.0f, 1.0f); @@ -424,7 +429,7 @@ void HWDrawInfo::CreateScene() // reset the portal manager screen->mPortalState->StartFrame(); - PO_LinkToSubsectors(&level); + PO_LinkToSubsectors(Level); ProcessAll.Clock(); @@ -432,7 +437,7 @@ void HWDrawInfo::CreateScene() screen->mVertexData->Map(); screen->mLights->Map(); - RenderBSP(level.HeadNode()); + RenderBSP(Level->HeadNode()); // And now the crappy hacks that have to be done to avoid rendering anomalies. // These cannot be multithreaded when the time comes because all these depend @@ -551,7 +556,7 @@ void HWDrawInfo::RenderPortal(HWPortal *p, FRenderState &state, bool usestencil) { auto gp = static_cast(p); gp->SetupStencil(this, state, usestencil); - auto new_di = StartDrawInfo(this, Viewpoint, &VPUniforms); + auto new_di = StartDrawInfo(this->Level, this, Viewpoint, &VPUniforms); new_di->mCurrentPortal = gp; state.SetLightIndex(-1); gp->DrawContents(new_di, state); diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index bf625d5d1b..9738cbe443 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -97,11 +97,6 @@ enum DrawListType struct HWDrawInfo { - virtual ~HWDrawInfo() - { - ClearBuffers(); - } - struct wallseg { float x1, y1, z1, x2, y2, z2; @@ -142,6 +137,7 @@ struct HWDrawInfo int vpIndex; ELightMode lightmode; + FLevelLocals *Level; HWDrawInfo * outer = nullptr; int FullbrightFlags; std::atomic spriteindex; @@ -243,7 +239,7 @@ public: void RenderBSPNode(void *node); void RenderBSP(void *node); - static HWDrawInfo *StartDrawInfo(HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms); + static HWDrawInfo *StartDrawInfo(FLevelLocals *lev, HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms); void StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms); void ClearBuffers(); HWDrawInfo *EndDrawInfo(); diff --git a/src/hwrenderer/scene/hw_drawlist.cpp b/src/hwrenderer/scene/hw_drawlist.cpp index 5b19288c15..f50c49b8bc 100644 --- a/src/hwrenderer/scene/hw_drawlist.cpp +++ b/src/hwrenderer/scene/hw_drawlist.cpp @@ -289,7 +289,7 @@ void HWDrawList::SortWallIntoPlane(SortNode * head, SortNode * sort) float newtexv = ws->tcs[GLWall::UPLFT].v + ((ws->tcs[GLWall::LOLFT].v - ws->tcs[GLWall::UPLFT].v) / (ws->zbottom[0] - ws->ztop[0])) * (fh->z - ws->ztop[0]); // I make the very big assumption here that translucent walls in sloped sectors - // and 3D-floors never coexist in the same level. If that were the case this + // and 3D-floors never coexist in the same level - If that were the case this // code would become extremely more complicated. if (!ceiling) { @@ -709,7 +709,7 @@ void HWDrawList::Sort(HWDrawInfo *di) //========================================================================== // -// Sorting the drawitems first by texture and then by light level. +// Sorting the drawitems first by texture and then by light level // //========================================================================== diff --git a/src/hwrenderer/scene/hw_fakeflat.cpp b/src/hwrenderer/scene/hw_fakeflat.cpp index 510e7d48a3..030c09f8e4 100644 --- a/src/hwrenderer/scene/hw_fakeflat.cpp +++ b/src/hwrenderer/scene/hw_fakeflat.cpp @@ -196,8 +196,9 @@ static sector_t *allocateSector(sector_t *sec) { if (fakesectorbuffer == nullptr) { - fakesectorbuffer = (sector_t**)FakeSectorAllocator.Alloc(level.sectors.Size() * sizeof(sector_t*)); - memset(fakesectorbuffer, 0, level.sectors.Size() * sizeof(sector_t*)); + unsigned numsectors = level.sectors.Size(); + fakesectorbuffer = (sector_t**)FakeSectorAllocator.Alloc(numsectors * sizeof(sector_t*)); + memset(fakesectorbuffer, 0, numsectors * sizeof(sector_t*)); } auto sectornum = sec->sectornum; fakesectorbuffer[sectornum] = (sector_t*)FakeSectorAllocator.Alloc(sizeof(sector_t)); diff --git a/src/hwrenderer/scene/hw_flats.cpp b/src/hwrenderer/scene/hw_flats.cpp index a72122a488..d4bc79ee2c 100644 --- a/src/hwrenderer/scene/hw_flats.cpp +++ b/src/hwrenderer/scene/hw_flats.cpp @@ -141,7 +141,7 @@ void GLFlat::SetupLights(HWDrawInfo *di, FLightNode * node, FDynLightData &light Plane p; lightdata.Clear(); - if (renderstyle == STYLE_Add && !level.lightadditivesurfaces) + if (renderstyle == STYLE_Add && !di->Level->lightadditivesurfaces) { dynlightindex = -1; return; // no lights on additively blended surfaces. @@ -182,7 +182,7 @@ void GLFlat::SetupLights(HWDrawInfo *di, FLightNode * node, FDynLightData &light void GLFlat::DrawSubsectors(HWDrawInfo *di, FRenderState &state) { - if (level.HasDynamicLights && screen->BuffersArePersistent() && !di->isFullbrightScene()) + if (di->Level->HasDynamicLights && screen->BuffersArePersistent() && !di->isFullbrightScene()) { SetupLights(di, section->lighthead, lightdata, sector->PortalGroup); } @@ -377,7 +377,7 @@ inline void GLFlat::PutFlat(HWDrawInfo *di, bool fog) } else if (!screen->BuffersArePersistent()) { - if (level.HasDynamicLights && gltexture != nullptr && !di->isFullbrightScene() && !(hacktype & (SSRF_PLANEHACK|SSRF_FLOODHACK)) ) + if (di->Level->HasDynamicLights && gltexture != nullptr && !di->isFullbrightScene() && !(hacktype & (SSRF_PLANEHACK|SSRF_FLOODHACK)) ) { SetupLights(di, section->lighthead, lightdata, sector->PortalGroup); } @@ -484,13 +484,13 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector, int which) #endif // Get the real sector for this one. - sector = &level.sectors[frontsector->sectornum]; + sector = &di->Level->sectors[frontsector->sectornum]; extsector_t::xfloor &x = sector->e->XFloor; dynlightindex = -1; hacktype = (which & (SSRF_PLANEHACK|SSRF_FLOODHACK)); uint8_t sink; - uint8_t &srf = hacktype? sink : di->section_renderflags[level.sections.SectionIndex(section)]; + uint8_t &srf = hacktype? sink : di->section_renderflags[di->Level->sections.SectionIndex(section)]; const auto &vp = di->Viewpoint; // diff --git a/src/hwrenderer/scene/hw_portal.cpp b/src/hwrenderer/scene/hw_portal.cpp index c31cda01b3..457f0fb4d0 100644 --- a/src/hwrenderer/scene/hw_portal.cpp +++ b/src/hwrenderer/scene/hw_portal.cpp @@ -733,7 +733,7 @@ const char *HWSkyboxPortal::GetName() { return "Skybox"; } static uint8_t SetCoverage(HWDrawInfo *di, void *node) { - if (level.nodes.Size() == 0) + if (di->Level->nodes.Size() == 0) { return 0; } @@ -759,12 +759,12 @@ void HWSectorStackPortal::SetupCoverage(HWDrawInfo *di) int plane = origin->plane; for (int j = 0; jportalcoverage[plane].sscount; j++) { - subsector_t *dsub = &::level.subsectors[sub->portalcoverage[plane].subsectors[j]]; + subsector_t *dsub = &di->Level->subsectors[sub->portalcoverage[plane].subsectors[j]]; di->CurrentMapSections.Set(dsub->mapsection); di->ss_renderflags[dsub->Index()] |= SSRF_SEEN; } } - SetCoverage(di, ::level.HeadNode()); + SetCoverage(di, di->Level->HeadNode()); } //----------------------------------------------------------------------------- @@ -1020,7 +1020,7 @@ void HWEEHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state) sector->GetTexture(sector_t::ceiling) == skyflatnum) { GLSkyInfo skyinfo; - skyinfo.init(sector->sky, 0); + skyinfo.init(di, sector->sky, 0); HWSkyPortal sky(screen->mSkyData, mState, &skyinfo, true); sky.DrawContents(di, state); } diff --git a/src/hwrenderer/scene/hw_portal.h b/src/hwrenderer/scene/hw_portal.h index 879420c106..f5efdca28e 100644 --- a/src/hwrenderer/scene/hw_portal.h +++ b/src/hwrenderer/scene/hw_portal.h @@ -28,7 +28,7 @@ struct GLSkyInfo { return !!memcmp(this, &inf, sizeof(*this)); } - void init(int sky1, PalEntry fadecolor); + void init(HWDrawInfo *di, int sky1, PalEntry fadecolor); }; struct GLHorizonInfo diff --git a/src/hwrenderer/scene/hw_renderhacks.cpp b/src/hwrenderer/scene/hw_renderhacks.cpp index b2467a5eb3..65a3da6073 100644 --- a/src/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/hwrenderer/scene/hw_renderhacks.cpp @@ -55,28 +55,28 @@ void HWDrawInfo::DispatchRenderHacks() glflat.section = nullptr; while (ofi.NextPair(pair)) { - auto sec = hw_FakeFlat(&level.sectors[pair->Key], in_area, false); + auto sec = hw_FakeFlat(&Level->sectors[pair->Key], in_area, false); glflat.ProcessSector(this, sec, SSRF_RENDERFLOOR | SSRF_PLANEHACK); } TMap::Iterator oci(otherCeilingPlanes); while (oci.NextPair(pair)) { - auto sec = hw_FakeFlat(&level.sectors[pair->Key], in_area, false); + auto sec = hw_FakeFlat(&Level->sectors[pair->Key], in_area, false); glflat.ProcessSector(this, sec, SSRF_RENDERCEILING | SSRF_PLANEHACK); } TMap::Iterator ffi(floodFloorSegs); while (ffi.NextPair(fpair)) { - auto sec = hw_FakeFlat(&level.sectors[fpair->Key], in_area, false); + auto sec = hw_FakeFlat(&Level->sectors[fpair->Key], in_area, false); glflat.ProcessSector(this, sec, SSRF_RENDERFLOOR | SSRF_FLOODHACK); } TMap::Iterator fci(floodCeilingSegs); while (fci.NextPair(fpair)) { - auto sec = hw_FakeFlat(&level.sectors[fpair->Key], in_area, false); + auto sec = hw_FakeFlat(&Level->sectors[fpair->Key], in_area, false); glflat.ProcessSector(this, sec, SSRF_RENDERCEILING | SSRF_FLOODHACK); } } @@ -108,7 +108,7 @@ static gl_floodrendernode *NewFloodRenderNode() int HWDrawInfo::SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &lightdata, const secplane_t *plane) { - if (level.HasDynamicLights && !isFullbrightScene()) + if (Level->HasDynamicLights && !isFullbrightScene()) { Plane p; @@ -170,8 +170,8 @@ void HWDrawInfo::AddOtherFloorPlane(int sector, gl_subsectorrendernode * node) auto pNode = otherFloorPlanes.CheckKey(sector); node->next = pNode? *pNode : nullptr; - node->lightindex = SetupLightsForOtherPlane(node->sub, lightdata, &level.sectors[sector].floorplane); - node->vertexindex = CreateOtherPlaneVertices(node->sub, &level.sectors[sector].floorplane); + node->lightindex = SetupLightsForOtherPlane(node->sub, lightdata, &Level->sectors[sector].floorplane); + node->vertexindex = CreateOtherPlaneVertices(node->sub, &Level->sectors[sector].floorplane); otherFloorPlanes[sector] = node; } @@ -180,8 +180,8 @@ void HWDrawInfo::AddOtherCeilingPlane(int sector, gl_subsectorrendernode * node) auto pNode = otherCeilingPlanes.CheckKey(sector); node->next = pNode? *pNode : nullptr; - node->lightindex = SetupLightsForOtherPlane(node->sub, lightdata, &level.sectors[sector].ceilingplane); - node->vertexindex = CreateOtherPlaneVertices(node->sub, &level.sectors[sector].ceilingplane); + node->lightindex = SetupLightsForOtherPlane(node->sub, lightdata, &Level->sectors[sector].ceilingplane); + node->vertexindex = CreateOtherPlaneVertices(node->sub, &Level->sectors[sector].ceilingplane); otherCeilingPlanes[sector] = node; } @@ -837,7 +837,7 @@ void HWDrawInfo::PrepareLowerGap(seg_t * seg) void HWDrawInfo::PrepareUnhandledMissingTextures() { - if (!level.notexturefill) + if (!Level->notexturefill) { validcount++; for (int i = MissingUpperSegs.Size() - 1; i >= 0; i--) @@ -894,7 +894,7 @@ void HWDrawInfo::PrepareUnhandledMissingTextures() void HWDrawInfo::AddHackedSubsector(subsector_t * sub) { - if (!(level.maptype == MAPTYPE_HEXEN)) + if (!(Level->maptype == MAPTYPE_HEXEN)) { SubsectorHackInfo sh={sub, 0}; SubsectorHacks.Push (sh); diff --git a/src/hwrenderer/scene/hw_renderstate.cpp b/src/hwrenderer/scene/hw_renderstate.cpp index 6f4bc036d9..ec183e3fb5 100644 --- a/src/hwrenderer/scene/hw_renderstate.cpp +++ b/src/hwrenderer/scene/hw_renderstate.cpp @@ -100,7 +100,7 @@ void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, int rellight, bool PalEntry fogcolor; float fogdensity; - if (level.flags&LEVEL_HASFADETABLE) + if (Level->flags&LEVEL_HASFADETABLE) { fogdensity = 70; fogcolor = 0x808080; @@ -150,7 +150,7 @@ void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, int rellight, bool state.SetFog(fogcolor, fogdensity); // Korshun: fullbright fog like in software renderer. - if (isSoftwareLighting() && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0) + if (isSoftwareLighting() && cmap->BlendFactor == 0 && Level->brightfog && fogdensity != 0 && fogcolor != 0) { state.SetSoftLightLevel(255); } diff --git a/src/hwrenderer/scene/hw_sky.cpp b/src/hwrenderer/scene/hw_sky.cpp index d2a8c41c52..a446facc2a 100644 --- a/src/hwrenderer/scene/hw_sky.cpp +++ b/src/hwrenderer/scene/hw_sky.cpp @@ -41,16 +41,16 @@ CVAR(Bool,gl_noskyboxes, false, 0) // //========================================================================== -void GLSkyInfo::init(int sky1, PalEntry FadeColor) +void GLSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) { memset(this, 0, sizeof(*this)); if ((sky1 & PL_SKYFLAT) && (sky1 & (PL_SKYFLAT - 1))) { - const line_t *l = &level.lines[(sky1&(PL_SKYFLAT - 1)) - 1]; + const line_t *l = &di->Level->lines[(sky1&(PL_SKYFLAT - 1)) - 1]; const side_t *s = l->sidedef[0]; int pos; - if (level.flags & LEVEL_SWAPSKIES && s->GetTexture(side_t::bottom).isValid()) + if (di->Level->flags & LEVEL_SWAPSKIES && s->GetTexture(side_t::bottom).isValid()) { pos = side_t::bottom; } @@ -70,14 +70,14 @@ void GLSkyInfo::init(int sky1, PalEntry FadeColor) else { normalsky: - if (level.flags&LEVEL_DOUBLESKY) + if (di->Level->flags&LEVEL_DOUBLESKY) { texture[1] = FMaterial::ValidateTexture(sky1texture, false, true); x_offset[1] = hw_sky1pos; doublesky = true; } - if ((level.flags&LEVEL_SWAPSKIES || (sky1 == PL_SKYFLAT) || (level.flags&LEVEL_DOUBLESKY)) && + if ((di->Level->flags&LEVEL_SWAPSKIES || (sky1 == PL_SKYFLAT) || (di->Level->flags&LEVEL_DOUBLESKY)) && sky2texture != sky1texture) // If both skies are equal use the scroll offset of the first! { texture[0] = FMaterial::ValidateTexture(sky2texture, false, true); @@ -92,7 +92,7 @@ void GLSkyInfo::init(int sky1, PalEntry FadeColor) x_offset[0] = hw_sky1pos; } } - if (level.skyfog > 0) + if (di->Level->skyfog > 0) { fadecolor = FadeColor; fadecolor.a = 0; @@ -119,7 +119,7 @@ void GLWall::SkyPlane(HWDrawInfo *di, sector_t *sector, int plane, bool allowref if ((sportal == nullptr && sector->GetTexture(plane) == skyflatnum) || (gl_noskyboxes && sportal != nullptr && sportal->mType == PORTS_SKYVIEWPOINT)) { GLSkyInfo skyinfo; - skyinfo.init(sector->sky, Colormap.FadeColor); + skyinfo.init(di, sector->sky, Colormap.FadeColor); ptype = PORTALTYPE_SKY; sky = &skyinfo; PutPortal(di, ptype, plane); @@ -189,7 +189,7 @@ void GLWall::SkyLine(HWDrawInfo *di, sector_t *fs, line_t *line) } else { - skyinfo.init(fs->sky, Colormap.FadeColor); + skyinfo.init(di, fs->sky, Colormap.FadeColor); ptype = PORTALTYPE_SKY; sky = &skyinfo; } diff --git a/src/hwrenderer/scene/hw_skydome.cpp b/src/hwrenderer/scene/hw_skydome.cpp index f0436ca530..262ded1ed1 100644 --- a/src/hwrenderer/scene/hw_skydome.cpp +++ b/src/hwrenderer/scene/hw_skydome.cpp @@ -66,6 +66,7 @@ #include "hwrenderer/textures/hw_material.h" #include "hw_skydome.h" #include "hw_renderstate.h" +#include "hw_drawinfo.h" #include "hwrenderer/data/buffers.h" //----------------------------------------------------------------------------- @@ -281,7 +282,7 @@ void FSkyVertexBuffer::CreateDome() // //----------------------------------------------------------------------------- -void FSkyVertexBuffer::SetupMatrices(FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix) +void FSkyVertexBuffer::SetupMatrices(HWDrawInfo *di, FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix) { int texw = tex->TextureWidth(); int texh = tex->TextureHeight(); @@ -291,7 +292,7 @@ void FSkyVertexBuffer::SetupMatrices(FMaterial *tex, float x_offset, float y_off float xscale = texw < 1024.f ? floor(1024.f / float(texw)) : 1.f; float yscale = 1.f; - if (texh <= 128 && (level.flags & LEVEL_FORCETILEDSKY)) + if (texh <= 128 && (di->Level->flags & LEVEL_FORCETILEDSKY)) { modelMatrix.translate(0.f, (-40 + tex->tex->GetSkyOffset() + skyoffset)*skyoffsetfactor, 0.f); modelMatrix.scale(1.f, 1.2f * 1.17f, 1.f); diff --git a/src/hwrenderer/scene/hw_skydome.h b/src/hwrenderer/scene/hw_skydome.h index ed130084cb..8f2c9ca8df 100644 --- a/src/hwrenderer/scene/hw_skydome.h +++ b/src/hwrenderer/scene/hw_skydome.h @@ -6,6 +6,8 @@ class FMaterial; class FRenderState; class IVertexBuffer; +struct HWSkyPortal; +struct HWDrawInfo; struct FSkyVertex { @@ -34,7 +36,6 @@ struct FSkyVertex }; -struct HWSkyPortal; class FSkyVertexBuffer { friend struct HWSkyPortal; @@ -68,7 +69,7 @@ public: FSkyVertexBuffer(); ~FSkyVertexBuffer(); - void SetupMatrices(FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix); + void SetupMatrices(HWDrawInfo *di, FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix); std::pair GetBufferObjects() const { return std::make_pair(mVertexBuffer, nullptr); diff --git a/src/hwrenderer/scene/hw_skyportal.cpp b/src/hwrenderer/scene/hw_skyportal.cpp index 88e9c6a833..bba4b60eea 100644 --- a/src/hwrenderer/scene/hw_skyportal.cpp +++ b/src/hwrenderer/scene/hw_skyportal.cpp @@ -58,7 +58,7 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FMaterial * te state.EnableModelMatrix(true); state.EnableTextureMatrix(true); - vertexBuffer->SetupMatrices(tex, x_offset, y_offset, mirror, mode, state.mModelMatrix, state.mTextureMatrix); + vertexBuffer->SetupMatrices(di, tex, x_offset, y_offset, mirror, mode, state.mModelMatrix, state.mTextureMatrix); } int rc = vertexBuffer->mRows + 1; @@ -104,9 +104,9 @@ void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texn state.mModelMatrix.loadIdentity(); if (!sky2) - state.mModelMatrix.rotate(-180.0f+x_offset, ::level.info->skyrotatevector.X, ::level.info->skyrotatevector.Z, ::level.info->skyrotatevector.Y); + state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector.X, di->Level->info->skyrotatevector.Z, di->Level->info->skyrotatevector.Y); else - state.mModelMatrix.rotate(-180.0f+x_offset, ::level.info->skyrotatevector2.X, ::level.info->skyrotatevector2.Z, ::level.info->skyrotatevector2.Y); + state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector2.X, di->Level->info->skyrotatevector2.Z, di->Level->info->skyrotatevector2.Y); if (sb->faces[5]) { @@ -203,10 +203,10 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) RenderDome(di, state, origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER); } - if (::level.skyfog>0 && !di->isFullbrightScene() && (origin->fadecolor & 0xffffff) != 0) + if (di->Level->skyfog>0 && !di->isFullbrightScene() && (origin->fadecolor & 0xffffff) != 0) { PalEntry FadeColor = origin->fadecolor; - FadeColor.a = clamp(::level.skyfog, 0, 255); + FadeColor.a = clamp(di->Level->skyfog, 0, 255); state.EnableTexture(false); state.SetObjectColor(FadeColor); diff --git a/src/hwrenderer/scene/hw_spritelight.cpp b/src/hwrenderer/scene/hw_spritelight.cpp index f3058cf53f..8023f62725 100644 --- a/src/hwrenderer/scene/hw_spritelight.cpp +++ b/src/hwrenderer/scene/hw_spritelight.cpp @@ -67,13 +67,13 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FLig // This is a performance critical section of code where we cannot afford to let the compiler decide whether to inline the function or not. // This will do the calculations explicitly rather than calling one of AActor's utility functions. - if (level.Displacements.size > 0) + if (Level->Displacements.size > 0) { int fromgroup = light->Sector->PortalGroup; int togroup = portalgroup; if (fromgroup == togroup || fromgroup == 0 || togroup == 0) goto direct; - DVector2 offset = level.Displacements.getOffset(fromgroup, togroup); + DVector2 offset = Level->Displacements.getOffset(fromgroup, togroup); L = FVector3(x - (float)(light->X() + offset.X), y - (float)(light->Y() + offset.Y), z - (float)light->Z()); } else diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index b7d8fb581c..49ced7dfe7 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -127,7 +127,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) state.AlphaFunc(Alpha_GEqual, gl_mask_sprite_threshold); state.SetColor(0.2f, 0.2f, 0.2f, fuzzalpha, Colormap.Desaturation); additivefog = true; - lightlist = nullptr; // the fuzz effect does not use the sector's light level so splitting is not needed. + lightlist = nullptr; // the fuzz effect does not use the sector's light di->Level-> so splitting is not needed. } else if (RenderStyle.BlendOp == STYLEOP_Add && RenderStyle.DestAlpha == STYLEALPHA_One) { @@ -142,7 +142,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) } if (RenderStyle.BlendOp != STYLEOP_Shadow) { - if (level.HasDynamicLights && !di->isFullbrightScene() && !fullbright) + if (di->Level->HasDynamicLights && !di->isFullbrightScene() && !fullbright) { if (dynlightindex == -1) // only set if we got no light buffer index. This covers all cases where sprite lighting is used. { @@ -224,7 +224,7 @@ void GLSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) FColormap thiscm; thiscm.CopyFog(Colormap); thiscm.CopyFrom3DLight(&(*lightlist)[i]); - if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) + if (di->Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) { thiscm.Decolorize(); } @@ -459,7 +459,7 @@ bool GLSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v, DVector3 *vp) inline void GLSprite::PutSprite(HWDrawInfo *di, bool translucent) { // That's a lot of checks... - if (modelframe && !modelframe->isVoxel && RenderStyle.BlendOp != STYLEOP_Shadow && gl_light_sprites && level.HasDynamicLights && !di->isFullbrightScene() && !fullbright) + if (modelframe && !modelframe->isVoxel && RenderStyle.BlendOp != STYLEOP_Shadow && gl_light_sprites && di->Level->HasDynamicLights && !di->isFullbrightScene() && !fullbright) { hw_GetDynModelLight(actor, lightdata); dynlightindex = screen->mLights->UploadLights(lightdata); @@ -528,7 +528,7 @@ void GLSprite::SplitSprite(HWDrawInfo *di, sector_t * frontsector, bool transluc copySprite.lightlevel = hw_ClampLight(*lightlist[i].p_lightlevel); copySprite.Colormap.CopyLight(lightlist[i].extra_colormap); - if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) + if (di->Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) { copySprite.Colormap.Decolorize(); } @@ -696,13 +696,13 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t // [RH] Interpolate the sprite's position to make it look smooth DVector3 thingpos = thing->InterpolatedPosition(vp.TicFrac); - if (thruportal == 1) thingpos += level.Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup); + if (thruportal == 1) thingpos += di->Level->Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup); // Some added checks if the camera actor is not supposed to be seen. It can happen that some portal setup has this actor in view in which case it may not be skipped here if (thing == camera && !vp.showviewer) { DVector3 thingorigin = thing->Pos(); - if (thruportal == 1) thingorigin += level.Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup); + if (thruportal == 1) thingorigin += di->Level->Displacements.getOffset(thing->Sector->PortalGroup, sector->PortalGroup); if (fabs(thingorigin.X - vp.ActorPos.X) < 2 && fabs(thingorigin.Y - vp.ActorPos.Y) < 2) return; } // Thing is invisible if close to the camera. @@ -773,7 +773,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t x = thingpos.X; z = thingpos.Z; y = thingpos.Y; - if (spritetype == RF_FACESPRITE) z -= thing->Floorclip; // wall and flat sprites are to be considered level geometry so this may not apply. + if (spritetype == RF_FACESPRITE) z -= thing->Floorclip; // wall and flat sprites are to be considered di->Level-> geometry so this may not apply. // [RH] Make floatbobbing a renderer-only effect. if (thing->flags2 & MF2_FLOATBOB) @@ -946,7 +946,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t Colormap = rendersector->Colormap; if (fullbright) { - if (rendersector == &level.sectors[rendersector->sectornum] || in_area != area_below) + if (rendersector == &di->Level->sectors[rendersector->sectornum] || in_area != area_below) // under water areas keep their color for fullbright objects { // Only make the light white but keep everything else (fog, desaturation and Boom colormap.) @@ -960,7 +960,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t Colormap.LightColor.b = (3 * Colormap.LightColor.b + 0xff) / 4; } } - else if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) + else if (di->Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) { Colormap.Decolorize(); } @@ -1143,7 +1143,7 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * break; } } - if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) + if (di->Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) { Colormap.Decolorize(); // ZDoom never applies colored light to particles. } @@ -1198,7 +1198,7 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * const auto &vp = di->Viewpoint; double timefrac = vp.TicFrac; - if (paused || bglobal.freeze || (level.flags2 & LEVEL2_FROZEN)) + if (paused || bglobal.freeze || (di->Level->flags2 & LEVEL2_FROZEN)) timefrac = 0.; float xvf = (particle->Vel.X) * timefrac; float yvf = (particle->Vel.Y) * timefrac; diff --git a/src/hwrenderer/scene/hw_walls.cpp b/src/hwrenderer/scene/hw_walls.cpp index c110378948..905e70b11b 100644 --- a/src/hwrenderer/scene/hw_walls.cpp +++ b/src/hwrenderer/scene/hw_walls.cpp @@ -281,7 +281,7 @@ void GLWall::DrawWall(HWDrawInfo *di, FRenderState &state, bool translucent) { if (screen->BuffersArePersistent()) { - if (level.HasDynamicLights && !di->isFullbrightScene() && gltexture != nullptr) + if (di->Level->HasDynamicLights && !di->isFullbrightScene() && gltexture != nullptr) { SetupLights(di, lightdata); } @@ -322,7 +322,7 @@ void GLWall::SetupLights(HWDrawInfo *di, FDynLightData &lightdata) { lightdata.Clear(); - if (RenderStyle == STYLE_Add && !level.lightadditivesurfaces) return; // no lights on additively blended surfaces. + if (RenderStyle == STYLE_Add && !di->Level->lightadditivesurfaces) return; // no lights on additively blended surfaces. // check for wall types which cannot have dynamic lights on them (portal types never get here so they don't need to be checked.) switch (type) @@ -456,7 +456,7 @@ void GLWall::PutWall(HWDrawInfo *di, bool translucent) if (!screen->BuffersArePersistent()) { - if (level.HasDynamicLights && !di->isFullbrightScene() && gltexture != nullptr) + if (di->Level->HasDynamicLights && !di->isFullbrightScene() && gltexture != nullptr) { SetupLights(di, lightdata); } @@ -567,7 +567,7 @@ void GLWall::PutPortal(HWDrawInfo *di, int ptype, int plane) if (!portal) { line_t *otherside = lineportal->lines[0]->mDestination; - if (otherside != nullptr && otherside->portalindex < level.linePortals.Size()) + if (otherside != nullptr && otherside->portalindex < di->Level->linePortals.Size()) { di->ProcessActorsInPortal(otherside->getPortal()->mGroup, di->in_area); } @@ -604,7 +604,7 @@ void GLWall::PutPortal(HWDrawInfo *di, int ptype, int plane) void GLWall::Put3DWall(HWDrawInfo *di, lightlist_t * lightlist, bool translucent) { - // only modify the light level if it doesn't originate from the seg's frontsector. This is to account for light transferring effects + // only modify the light di->Level-> if it doesn't originate from the seg's frontsector. This is to account for light transferring effects if (lightlist->p_lightlevel != &seg->sidedef->sector->lightlevel) { lightlevel = hw_ClampLight(*lightlist->p_lightlevel); @@ -1516,7 +1516,7 @@ void GLWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, light = P_GetPlaneLight(rover->target, rover->top.plane, true); Colormap.Clear(); Colormap.LightColor = light->extra_colormap.FadeColor; - // the fog plane defines the light level, not the front sector + // the fog plane defines the light di->Level->, not the front sector lightlevel = hw_ClampLight(*light->p_lightlevel); gltexture = NULL; type = RENDERWALL_FFBLOCK; @@ -1867,8 +1867,8 @@ void GLWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ else { // Need these for aligning the textures - realfront = &level.sectors[frontsector->sectornum]; - realback = backsector ? &level.sectors[backsector->sectornum] : NULL; + realfront = &di->Level->sectors[frontsector->sectornum]; + realback = backsector ? &di->Level->sectors[backsector->sectornum] : NULL; segfront = frontsector; segback = backsector; } @@ -1928,7 +1928,7 @@ void GLWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ int rel = 0; int orglightlevel = hw_ClampLight(frontsector->lightlevel); - bool foggy = (!Colormap.FadeColor.isBlack() || level.flags&LEVEL_HASFADETABLE); // fog disables fake contrast + bool foggy = (!Colormap.FadeColor.isBlack() || di->Level->flags&LEVEL_HASFADETABLE); // fog disables fake contrast lightlevel = hw_ClampLight(seg->sidedef->GetLightLevel(foggy, orglightlevel, false, &rel)); if (orglightlevel >= 253) // with the software renderer fake contrast won't be visible above this. { diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index 787bf539ec..96bd52b630 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -237,7 +237,7 @@ WeaponLighting HWDrawInfo::GetWeaponLighting(sector_t *viewsector, const DVector l.lightlevel = hw_ClampLight(fakesec->lightlevel); // calculate colormap for weapon sprites - if (viewsector->e->XFloor.ffloors.Size() && !(level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING)) + if (viewsector->e->XFloor.ffloors.Size() && !(Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING)) { TArray & lightlist = viewsector->e->XFloor.lightlist; for (unsigned i = 0; iColormap; - if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) l.cm.ClearColor(); + if (Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) l.cm.ClearColor(); } l.lightlevel = CalcLightLevel(l.lightlevel, getExtraLight(), true, 0); @@ -289,7 +289,7 @@ WeaponLighting HWDrawInfo::GetWeaponLighting(sector_t *viewsector, const DVector } // Korshun: fullbright fog in opengl, render weapon sprites fullbright (but don't cancel out the light color!) - if (level.brightfog && ((level.flags&LEVEL_HASFADETABLE) || l.cm.FadeColor != 0)) + if (Level->brightfog && ((Level->flags&LEVEL_HASFADETABLE) || l.cm.FadeColor != 0)) { l.lightlevel = 255; } @@ -530,7 +530,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) hudsprite.dynrgb[0] = hudsprite.dynrgb[1] = hudsprite.dynrgb[2] = 0; hudsprite.lightindex = -1; // set the lighting parameters - if (hudsprite.RenderStyle.BlendOp != STYLEOP_Shadow && level.HasDynamicLights && !isFullbrightScene() && gl_light_sprites) + if (hudsprite.RenderStyle.BlendOp != STYLEOP_Shadow && Level->HasDynamicLights && !isFullbrightScene() && gl_light_sprites) { if (!hudModelStep) { diff --git a/src/hwrenderer/utility/hw_clock.cpp b/src/hwrenderer/utility/hw_clock.cpp index 179776a656..2ac4c48f07 100644 --- a/src/hwrenderer/utility/hw_clock.cpp +++ b/src/hwrenderer/utility/hw_clock.cpp @@ -167,8 +167,9 @@ void CheckBench() FString compose; auto &vp = r_viewpoint; + auto Level = vp.ViewLevel; compose.Format("Map %s: \"%s\",\nx = %1.4f, y = %1.4f, z = %1.4f, angle = %1.4f, pitch = %1.4f\n", - level.MapName.GetChars(), level.LevelName.GetChars(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw.Degrees, vp.Angles.Pitch.Degrees); + Level->MapName.GetChars(), Level->LevelName.GetChars(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw.Degrees, vp.Angles.Pitch.Degrees); AppendRenderStats(compose); AppendRenderTimes(compose); diff --git a/src/hwrenderer/utility/hw_lighting.cpp b/src/hwrenderer/utility/hw_lighting.cpp index 499d947abd..e1845b51a9 100644 --- a/src/hwrenderer/utility/hw_lighting.cpp +++ b/src/hwrenderer/utility/hw_lighting.cpp @@ -164,7 +164,7 @@ PalEntry HWDrawInfo::CalcLightColor(int light, PalEntry pe, int blendfactor) // This is what Legacy's GL render does. // 2. black fog means no fog and always uses the distfogtable based on the level's fog density setting // 3. If outside fog is defined and the current fog color is the same as the outside fog -// the engine always uses the outside fog density to make the fog uniform across the level. +// the engine always uses the outside fog density to make the fog uniform across the Level-> // If the outside fog's density is undefined it uses the level's fog density and if that is // not defined it uses a default of 70. // 4. If a global fog density is specified it is being used for all fog on the level @@ -182,7 +182,7 @@ float HWDrawInfo::GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfog if (lightmode == ELightMode::DoomLegacy) { // uses approximations of Legacy's default settings. - density = level.fogdensity ? (float)level.fogdensity : 18; + density = Level->fogdensity ? (float)Level->fogdensity : 18; } else if (sectorfogdensity != 0) { @@ -192,7 +192,7 @@ float HWDrawInfo::GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfog else if ((fogcolor.d & 0xffffff) == 0) { // case 2: black fog - if ((!isSoftwareLighting() || blendfactor > 0) && !(level.flags3 & LEVEL3_NOLIGHTFADE)) + if ((!isSoftwareLighting() || blendfactor > 0) && !(Level->flags3 & LEVEL3_NOLIGHTFADE)) { density = distfogtable[lightmode != ELightMode::LinearStandard][hw_ClampLight(lightlevel)]; } @@ -201,15 +201,15 @@ float HWDrawInfo::GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfog density = 0; } } - else if (level.outsidefogdensity != 0 && APART(level.info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (level.info->outsidefog & 0xffffff)) + else if (Level->outsidefogdensity != 0 && APART(Level->info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (Level->info->outsidefog & 0xffffff)) { // case 3. outsidefogdensity has already been set as needed - density = (float)level.outsidefogdensity; + density = (float)Level->outsidefogdensity; } - else if (level.fogdensity != 0) + else if (Level->fogdensity != 0) { // case 4: level has fog density set - density = (float)level.fogdensity; + density = (float)Level->fogdensity; } else if (lightlevel < 248) { @@ -249,10 +249,10 @@ bool HWDrawInfo::CheckFog(sector_t *frontsector, sector_t *backsector) else if (fogcolor.a != 0) { } - else if (level.outsidefogdensity != 0 && APART(level.info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (level.info->outsidefog & 0xffffff)) + else if (Level->outsidefogdensity != 0 && APART(Level->info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (Level->info->outsidefog & 0xffffff)) { } - else if (level.fogdensity!=0 || lightmode == ELightMode::DoomLegacy) + else if (Level->fogdensity!=0 || lightmode == ELightMode::DoomLegacy) { // case 3: level has fog density set } @@ -267,11 +267,11 @@ bool HWDrawInfo::CheckFog(sector_t *frontsector, sector_t *backsector) if ((fogcolor.d & 0xffffff) == 0) { } - else if (level.outsidefogdensity != 0 && APART(level.info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (level.info->outsidefog & 0xffffff)) + else if (Level->outsidefogdensity != 0 && APART(Level->info->outsidefog) != 0xff && (fogcolor.d & 0xffffff) == (Level->info->outsidefog & 0xffffff)) { return false; } - else if (level.fogdensity!=0 || lightmode == ELightMode::DoomLegacy) + else if (Level->fogdensity!=0 || lightmode == ELightMode::DoomLegacy) { // case 3: level has fog density set return false; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index c3f207927a..aa234a33b4 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -3276,7 +3276,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position) InitRenderInfo(); // create hardware independent renderer resources for the level. This must be done BEFORE the PolyObj Spawn!!! P_ClearDynamic3DFloorData(); // CreateVBO must be run on the plain 3D floor data. - screen->mVertexData->CreateVBO(); + screen->mVertexData->CreateVBO(Level->sectors); for (auto &sec : Level->sectors) { diff --git a/src/p_setup.cpp b/src/p_setup.cpp index eebefbfdc9..0fff24c55a 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -643,3 +643,32 @@ CCMD(listmapsections) } } +//========================================================================== +// +// +// +//========================================================================== + +CUSTOM_CVAR(Bool, forcewater, false, CVAR_ARCHIVE | CVAR_SERVERINFO) +{ + if (gamestate == GS_LEVEL) + { + auto Level = &level; + for (auto &sec : Level->sectors) + { + sector_t *hsec = sec.GetHeightSec(); + if (hsec && !(hsec->MoreFlags & SECMF_UNDERWATER)) + { + if (self) + { + hsec->MoreFlags |= SECMF_FORCEDUNDERWATER; + } + else + { + hsec->MoreFlags &= ~SECMF_FORCEDUNDERWATER; + } + } + } + } +} + diff --git a/src/p_spec.cpp b/src/p_spec.cpp index d84f36074f..3d07180c13 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -103,6 +103,7 @@ static FRandom pr_playerinspecialsector ("PlayerInSpecialSector"); EXTERN_CVAR(Bool, cl_predict_specials) +EXTERN_CVAR(Bool, forcewater) // [RH] Check dmflags for noexit and respond accordingly bool FLevelLocals::CheckIfExitIsGood (AActor *self, level_info_t *info) @@ -680,35 +681,10 @@ void P_UpdateSpecials (FLevelLocals *Level) } } - - // // SPECIAL SPAWNING // -CUSTOM_CVAR (Bool, forcewater, false, CVAR_ARCHIVE|CVAR_SERVERINFO) -{ - if (gamestate == GS_LEVEL) - { - auto Level = &level; - for (auto &sec : Level->sectors) - { - sector_t *hsec = sec.GetHeightSec(); - if (hsec && !(hsec->MoreFlags & SECMF_UNDERWATER)) - { - if (self) - { - hsec->MoreFlags |= SECMF_FORCEDUNDERWATER; - } - else - { - hsec->MoreFlags &= ~SECMF_FORCEDUNDERWATER; - } - } - } - } -} - IMPLEMENT_CLASS(DLightTransfer, false, false) void DLightTransfer::Serialize(FSerializer &arc) diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 9117fc01f4..26d8d4f6db 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -1034,6 +1034,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor viewpoint.HWAngles.Pitch = RAD2DEG((float)asin(angy / alen)); viewpoint.HWAngles.Roll.Degrees = (float)viewpoint.Angles.Roll.Degrees; // copied for convenience. + viewpoint.ViewLevel = &level; // ViewActor only gets set, if the camera actor should not be rendered if (actor->player && actor->player - players == consoleplayer && diff --git a/src/r_utility.h b/src/r_utility.h index 1eb93096a4..53218615f0 100644 --- a/src/r_utility.h +++ b/src/r_utility.h @@ -13,6 +13,8 @@ struct FViewWindow; // There a 0-31, i.e. 32 LUT in the COLORMAP lump. #define NUMCOLORMAPS 32 +struct FLevelLocals; + struct FRenderViewpoint { FRenderViewpoint(); @@ -24,6 +26,7 @@ struct FRenderViewpoint FRotator HWAngles; // Actual rotation angles for the hardware renderer DVector2 ViewVector; // HWR only: direction the camera is facing. AActor *ViewActor; // either the same as camera or nullptr + FLevelLocals *ViewLevel; // The level this viewpoint is on. DVector3 Path[2]; // View path for portal calculations double Cos; // cos(Angles.Yaw)