- moved most of gl_setup.cpp to r_data as this is only some data setup in the main map data structures.

- made currentmapsections array something nicer to look at and made it a member of the scene drawer class.
This commit is contained in:
Christoph Oelckers 2018-04-02 09:27:40 +02:00
parent 202d209eb8
commit 8080e039e0
12 changed files with 101 additions and 40 deletions

View file

@ -1043,7 +1043,6 @@ set (PCH_SOURCES
g_statusbar/sbar_mugshot.cpp
g_statusbar/shared_sbar.cpp
gl/compatibility/gl_20.cpp
gl/data/gl_setup.cpp
gl/data/gl_vertexbuffer.cpp
gl/dynlights/gl_glow.cpp
gl/dynlights/gl_lightbuffer.cpp
@ -1150,6 +1149,7 @@ set (PCH_SOURCES
r_data/sprites.cpp
r_data/portalgroups.cpp
r_data/voxels.cpp
r_data/renderinfo.cpp
r_data/renderstyle.cpp
r_data/r_interpolate.cpp
r_data/r_vanillatrans.cpp

View file

@ -91,6 +91,7 @@ struct FLevelLocals
TArray<FLinePortal*> linkedPortals; // only the linked portals, this is used to speed up looking for them in P_CollectConnectedGroups.
TArray<FSectorPortalGroup *> portalGroups;
TArray<FLinePortalSpan> linePortalSpans;
int NumMapSections;
TArray<zone_t> Zones;

View file

@ -17,9 +17,4 @@ inline int getExtraLight()
return r_viewpoint.extralight * gl_weaponlight;
}
struct GLSectorStackPortal;
extern TArray<uint8_t> currentmapsection;
#endif

View file

@ -423,7 +423,7 @@ void GLSceneDrawer::DoSubsector(subsector_t * sub)
if (!sector) return;
// If the mapsections differ this subsector can't possibly be visible from the current view point
if (!(currentmapsection[sub->mapsection>>3] & (1 << (sub->mapsection & 7)))) return;
if (!CurrentMapSections[sub->mapsection]) return;
if (sub->flags & SSECF_POLYORG) return; // never render polyobject origin subsectors because their vertices no longer are where one may expect.
if (gl_drawinfo->ss_renderflags[sub->Index()] & SSRF_SEEN)

View file

@ -579,20 +579,22 @@ GLPortal * GLPortal::FindPortal(const void * src)
//-----------------------------------------------------------------------------
//
//
// Save/RestoreMapSection
//
// saves CurrentMapSection for a recursive call of SceneDrawer::DrawScene
//
//-----------------------------------------------------------------------------
void GLPortal::SaveMapSection()
{
savedmapsection.Resize(currentmapsection.Size());
memcpy(&savedmapsection[0], &currentmapsection[0], currentmapsection.Size());
memset(&currentmapsection[0], 0, currentmapsection.Size());
SavedMapSection = std::move(drawer->CurrentMapSections);
drawer->CurrentMapSections.Resize(SavedMapSection.Size());
drawer->CurrentMapSections.Zero();
}
void GLPortal::RestoreMapSection()
{
memcpy(&currentmapsection[0], &savedmapsection[0], currentmapsection.Size());
drawer->CurrentMapSections = std::move(SavedMapSection);
}
//-----------------------------------------------------------------------------
@ -650,7 +652,7 @@ void GLSkyboxPortal::DrawContents()
int mapsection = R_PointInSubsector(r_viewpoint.Pos)->mapsection;
SaveMapSection();
currentmapsection[mapsection >> 3] |= 1 << (mapsection & 7);
drawer->CurrentMapSections.Set(mapsection);
drawer->DrawScene(DM_SKYPORTAL);
portal->mFlags &= ~PORTSF_INSKYBOX;
@ -732,7 +734,7 @@ void GLSectorStackPortal::SetupCoverage()
for(int j=0;j<sub->portalcoverage[plane].sscount; j++)
{
subsector_t *dsub = &::level.subsectors[sub->portalcoverage[plane].subsectors[j]];
currentmapsection[dsub->mapsection>>3] |= 1 << (dsub->mapsection&7);
drawer->CurrentMapSections.Set(dsub->mapsection);
gl_drawinfo->ss_renderflags[dsub->Index()] |= SSRF_SEEN;
}
}
@ -1055,8 +1057,7 @@ void GLLineToLinePortal::DrawContents()
if (line->sidedef[0]->Flags & WALLF_POLYOBJ)
sub = R_PointInSubsector(line->v1->fixX(), line->v1->fixY());
else sub = line->frontsector->subsectors[0];
int mapsection = sub->mapsection;
currentmapsection[mapsection >> 3] |= 1 << (mapsection & 7);
drawer->CurrentMapSections.Set(sub->mapsection);
}
GLRenderer->mViewActor = nullptr;

View file

@ -109,7 +109,7 @@ private:
ActorRenderFlags savedvisibility;
GLPortal *PrevPortal;
GLPortal *PrevClipPortal;
TArray<uint8_t> savedmapsection;
BitArray SavedMapSection;
TArray<unsigned int> mPrimIndices;
protected:

View file

@ -88,7 +88,6 @@ EXTERN_CVAR (Bool, r_drawvoxels)
extern bool NoInterpolateView;
area_t in_area;
TArray<uint8_t> currentmapsection;
int camtexcount;
//-----------------------------------------------------------------------------
@ -737,8 +736,9 @@ void GLSceneDrawer::ProcessScene(bool toscreen)
GLPortal::BeginScene();
int mapsection = R_PointInSubsector(r_viewpoint.Pos)->mapsection;
memset(&currentmapsection[0], 0, currentmapsection.Size());
currentmapsection[mapsection>>3] |= 1 << (mapsection & 7);
CurrentMapSections.Resize(level.NumMapSections);
CurrentMapSections.Zero();
CurrentMapSections.Set(mapsection);
DrawScene(toscreen ? DM_MAINVIEW : DM_OFFSCREEN);
FDrawInfo::EndDrawInfo();
@ -1129,10 +1129,12 @@ void FGLInterface::RenderTextureView (FCanvasTexture *tex, AActor *Viewpoint, do
//
//
//===========================================================================
void gl_PreprocessLevel();
void FGLInterface::PreprocessLevel()
{
gl_PreprocessLevel();
if (GLRenderer != NULL)
{
GLRenderer->SetupLevel();
}
}
uint32_t FGLInterface::GetCaps()

View file

@ -45,6 +45,7 @@ public:
Clipper clipper;
int FixedColormap;
area_t in_area;
BitArray CurrentMapSections; // this cannot be a single number, because a group of portals with the same displacement may link different sections.
angle_t FrustumAngle();
void SetViewMatrix(float vx, float vy, float vz, bool mirror, bool planemirror);
@ -71,7 +72,7 @@ public:
void DrawPSprite(player_t * player, DPSprite *psp, float sx, float sy, bool hudModelStep, int OverrideShader, bool alphatexture);
void DrawPlayerSprites(sector_t * viewsector, bool hudModelStep);
void DrawTargeterSprites();
void InitClipper(angle_t a1, angle_t a2)
{
clipper.Clear();

View file

@ -721,7 +721,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
}
// If this thing is in a map section that's not in view it can't possibly be visible
if (!thruportal && !(currentmapsection[thing->subsector->mapsection >> 3] & (1 << (thing->subsector->mapsection & 7)))) return;
if (!thruportal && !mDrawer->CurrentMapSections[thing->subsector->mapsection]) return;
// [RH] Interpolate the sprite's position to make it look smooth
DVector3 thingpos = thing->InterpolatedPosition(r_viewpoint.TicFrac);

View file

@ -129,6 +129,7 @@ void P_SetSlopes ();
void P_CopySlopes();
void BloodCrypt (void *data, int key, int len);
void P_ClearUDMFKeys();
void InitRenderInfo();
extern AActor *P_SpawnMapThing (FMapThing *mthing, int position);
@ -4120,6 +4121,7 @@ void P_SetupLevel (const char *lumpname, int position)
}
// This must be done BEFORE the PolyObj Spawn!!!
InitRenderInfo();
Renderer->PreprocessLevel();
InitPortalGroups();

View file

@ -21,8 +21,8 @@
//
/*
** gl_setup.cpp
** Initializes the data structures required by the GL renderer to handle
** a level
** Initializes the data structures required by the hardware renderer to handle
** render hacks and optimization.
**
**/
@ -42,13 +42,6 @@
#include "g_level.h"
#include "g_levellocals.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/data/gl_data.h"
#include "gl/data/gl_vertexbuffer.h"
#include "gl/dynlights/gl_dynlight.h"
#include "gl/dynlights/gl_glow.h"
#include "gl/utility/gl_clock.h"
//==========================================================================
//
// Map section generation
@ -208,7 +201,7 @@ struct MapSectionGenerator
}
while (set);
num = MergeMapSections(num);
currentmapsection.Resize(1 + num/8);
level.NumMapSections = num;
#ifdef DEBUG
Printf("%d map sections found\n", num);
#endif
@ -544,7 +537,7 @@ static void PrepareSegs()
//
//==========================================================================
void gl_PreprocessLevel()
void InitRenderInfo()
{
PrepareSegs();
PrepareSectorData();
@ -581,11 +574,6 @@ void gl_PreprocessLevel()
}
delete[] checkmap;
if (GLRenderer != NULL)
{
GLRenderer->SetupLevel();
}
#if 0
gl_CreateSections();
#endif

View file

@ -1259,3 +1259,74 @@ public:
Clear();
}
};
class BitArray
{
TArray<uint8_t> bytes;
unsigned size;
public:
void Resize(unsigned elem)
{
bytes.Resize((elem + 7) / 8);
size = elem;
}
BitArray() : size(0)
{
}
BitArray(const BitArray & arr)
{
bytes = arr.bytes;
size = arr.size;
}
BitArray &operator=(const BitArray & arr)
{
bytes = arr.bytes;
size = arr.size;
return *this;
}
BitArray(BitArray && arr)
{
bytes = std::move(arr.bytes);
size = arr.size;
arr.size = 0;
}
BitArray &operator=(BitArray && arr)
{
bytes = std::move(arr.bytes);
size = arr.size;
arr.size = 0;
return *this;
}
bool operator[](size_t index) const
{
return !!(bytes[index >> 3] & (1 << (index & 7)));
}
void Set(size_t index)
{
bytes[index >> 3] |= (1 << (index & 7));
}
void Clear(size_t index)
{
bytes[index >> 3] &= ~(1 << (index & 7));
}
unsigned Size() const
{
return size;
}
void Zero()
{
memset(&bytes[0], 0, bytes.Size());
}
};