From a9ef73528d073ce6140169633f711fd4680d0802 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 14 Jan 2017 16:05:40 +0100 Subject: [PATCH] - removed all skybox class types from code in preparation for exporting these classes. - moved SectorPortal struct to FLevelLocals and exported it. --- src/dobject.cpp | 4 +- src/dobjgc.cpp | 2 +- src/g_levellocals.h | 33 +++++++++++++ src/g_shared/a_skies.cpp | 9 ++-- src/gl/data/gl_data.h | 1 - src/gl/scene/gl_portal.h | 3 -- src/p_saveg.cpp | 2 +- src/p_spec.cpp | 36 +++++++-------- src/portal.cpp | 77 +++++++++++++++++-------------- src/portal.h | 5 +- src/r_defs.h | 38 +++------------ src/r_plane.cpp | 6 +-- src/r_plane.h | 2 - src/scripting/thingdef_data.cpp | 6 ++- wadsrc/static/zscript/mapdata.txt | 18 +++++++- 15 files changed, 135 insertions(+), 107 deletions(-) diff --git a/src/dobject.cpp b/src/dobject.cpp index 30c3c1710d..a0f046b758 100644 --- a/src/dobject.cpp +++ b/src/dobject.cpp @@ -480,11 +480,11 @@ size_t DObject::StaticPointerSubstitution (DObject *old, DObject *notOld, bool s changed += players[i].FixPointers (old, notOld); } - for (auto &s : sectorPortals) + for (auto &s : level.sectorPortals) { if (s.mSkybox == old) { - s.mSkybox = static_cast(notOld); + s.mSkybox = static_cast(notOld); changed++; } } diff --git a/src/dobjgc.cpp b/src/dobjgc.cpp index 625f806785..230dbeac7e 100644 --- a/src/dobjgc.cpp +++ b/src/dobjgc.cpp @@ -329,7 +329,7 @@ static void MarkRoot() DThinker::MarkRoots(); FCanvasTextureInfo::Mark(); Mark(DACSThinker::ActiveThinker); - for (auto &s : sectorPortals) + for (auto &s : level.sectorPortals) { Mark(s.mSkybox); } diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 08b18145d9..357e2e1545 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -32,6 +32,9 @@ struct FLevelLocals TStaticArray lines; TStaticArray sides; + TArray sectorPortals; + + DWORD flags; DWORD flags2; DWORD flags3; @@ -95,7 +98,37 @@ inline int line_t::Index() const return int(this - &level.lines[0]); } +inline FSectorPortal *line_t::GetTransferredPortal() +{ + return portaltransferred >= level.sectorPortals.Size() ? (FSectorPortal*)nullptr : &level.sectorPortals[portaltransferred]; +} + inline int sector_t::Index() const { return int(this - &level.sectors[0]); } + +inline FSectorPortal *sector_t::GetPortal(int plane) +{ + return &level.sectorPortals[Portals[plane]]; +} + +inline double sector_t::GetPortalPlaneZ(int plane) +{ + return level.sectorPortals[Portals[plane]].mPlaneZ; +} + +inline DVector2 sector_t::GetPortalDisplacement(int plane) +{ + return level.sectorPortals[Portals[plane]].mDisplacement; +} + +inline int sector_t::GetPortalType(int plane) +{ + return level.sectorPortals[Portals[plane]].mType; +} + +inline int sector_t::GetOppositePortalGroup(int plane) +{ + return level.sectorPortals[Portals[plane]].mDestination->PortalGroup; +} diff --git a/src/g_shared/a_skies.cpp b/src/g_shared/a_skies.cpp index 497e4014ac..234597554a 100644 --- a/src/g_shared/a_skies.cpp +++ b/src/g_shared/a_skies.cpp @@ -39,6 +39,7 @@ #include "r_sky.h" #include "r_state.h" #include "portal.h" +#include "g_levellocals.h" // arg0 = Visibility*4 for this skybox @@ -49,17 +50,17 @@ void ASkyViewpoint::BeginPlay () { Super::BeginPlay (); - if (tid == 0 && sectorPortals[0].mSkybox == nullptr) + if (tid == 0 && level.sectorPortals[0].mSkybox == nullptr) { - sectorPortals[0].mSkybox = this; - sectorPortals[0].mDestination = Sector; + level.sectorPortals[0].mSkybox = this; + level.sectorPortals[0].mDestination = Sector; } } void ASkyViewpoint::OnDestroy () { // remove all sector references to ourselves. - for (auto &s : sectorPortals) + for (auto &s : level.sectorPortals) { if (s.mSkybox == this) { diff --git a/src/gl/data/gl_data.h b/src/gl/data/gl_data.h index bb57c9139a..d5bdeb46a6 100644 --- a/src/gl/data/gl_data.h +++ b/src/gl/data/gl_data.h @@ -46,7 +46,6 @@ inline int getExtraLight() void gl_RecalcVertexHeights(vertex_t * v); FTextureID gl_GetSpriteFrame(unsigned sprite, int frame, int rot, angle_t ang, bool *mirror); -class AStackPoint; struct GLSectorStackPortal; struct FPortal diff --git a/src/gl/scene/gl_portal.h b/src/gl/scene/gl_portal.h index 8a40ec2e22..3adaa4aa48 100644 --- a/src/gl/scene/gl_portal.h +++ b/src/gl/scene/gl_portal.h @@ -43,9 +43,6 @@ #include "gl/utility/gl_templates.h" #include "gl/data/gl_data.h" -class ASkyViewpoint; - - struct GLHorizonInfo { GLSectorPlane plane; diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 6a944452e9..04c35d1570 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -964,7 +964,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload) arc.Array("sectors", &level.sectors[0], &loadsectors[0], level.sectors.Size()); arc("zones", Zones); arc("lineportals", linePortals); - arc("sectorportals", sectorPortals); + arc("sectorportals", level.sectorPortals); if (arc.isReading()) P_CollectLinkedPortals(); DThinker::SerializeThinkers(arc, !hubload); diff --git a/src/p_spec.cpp b/src/p_spec.cpp index b3953b1bd2..0909da70fc 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -845,12 +845,12 @@ void DWallLightTransfer::DoTransfer (short lightlevel, int target, BYTE flags) //--------------------------------------------------------------------------- // Upper stacks go in the top sector. Lower stacks go in the bottom sector. -static void SetupFloorPortal (AStackPoint *point) +static void SetupFloorPortal (AActor *point) { NActorIterator it (NAME_LowerStackLookOnly, point->tid); sector_t *Sector = point->Sector; - ASkyViewpoint *skyv = static_cast(it.Next()); - if (skyv != NULL) + auto skyv = it.Next(); + if (skyv != nullptr) { skyv->target = point; if (Sector->GetAlpha(sector_t::floor) == 1.) @@ -860,12 +860,12 @@ static void SetupFloorPortal (AStackPoint *point) } } -static void SetupCeilingPortal (AStackPoint *point) +static void SetupCeilingPortal (AActor *point) { NActorIterator it (NAME_UpperStackLookOnly, point->tid); sector_t *Sector = point->Sector; - ASkyViewpoint *skyv = static_cast(it.Next()); - if (skyv != NULL) + auto skyv = it.Next(); + if (skyv != nullptr) { skyv->target = point; if (Sector->GetAlpha(sector_t::ceiling) == 1.) @@ -877,9 +877,9 @@ static void SetupCeilingPortal (AStackPoint *point) void P_SetupPortals() { - TThinkerIterator it; - AStackPoint *pt; - TArray points; + TThinkerIterator it("StackPoint"); + AActor *pt; + TArray points; while ((pt = it.Next())) { @@ -897,21 +897,21 @@ void P_SetupPortals() } // the semantics here are incredibly lax so the final setup can only be done once all portals have been created, // because later stackpoints will happily overwrite info in older ones, if there are multiple links. - for (auto &s : sectorPortals) + for (auto &s : level.sectorPortals) { if (s.mType == PORTS_STACKEDSECTORTHING && s.mSkybox) { - for (auto &ss : sectorPortals) + for (auto &ss : level.sectorPortals) { if (ss.mType == PORTS_STACKEDSECTORTHING && ss.mSkybox == s.mSkybox->target) { - s.mPartner = unsigned((&ss) - §orPortals[0]); + s.mPartner = unsigned((&ss) - &level.sectorPortals[0]); } } } } // Now we can finally set the displacement and delete the stackpoint reference. - for (auto &s : sectorPortals) + for (auto &s : level.sectorPortals) { if (s.mType == PORTS_STACKEDSECTORTHING && s.mSkybox) { @@ -932,7 +932,7 @@ static void SetPortal(sector_t *sector, int plane, unsigned pnum, double alpha) if (sector->GetAlpha(sector_t::ceiling) == 1.) sector->SetAlpha(sector_t::ceiling, alpha); - if (sectorPortals[pnum].mFlags & PORTSF_SKYFLATONLY) + if (level.sectorPortals[pnum].mFlags & PORTSF_SKYFLATONLY) sector->SetTexture(sector_t::ceiling, skyflatnum); } } @@ -945,7 +945,7 @@ static void SetPortal(sector_t *sector, int plane, unsigned pnum, double alpha) if (sector->GetAlpha(sector_t::floor) == 1.) sector->SetAlpha(sector_t::floor, alpha); - if (sectorPortals[pnum].mFlags & PORTSF_SKYFLATONLY) + if (level.sectorPortals[pnum].mFlags & PORTSF_SKYFLATONLY) sector->SetTexture(sector_t::floor, skyflatnum); } } @@ -1027,7 +1027,7 @@ void P_SpawnPortal(line_t *line, int sectortag, int plane, int bytealpha, int li // This searches the viewpoint's sector // for a skybox line special, gets its tag and transfers the skybox to all tagged sectors. -void P_SpawnSkybox(ASkyViewpoint *origin) +void P_SpawnSkybox(AActor *origin) { sector_t *Sector = origin->Sector; if (Sector == NULL) @@ -1260,8 +1260,8 @@ void P_SpawnSpecials (void) P_SpawnFriction(); // phares 3/12/98: New friction model using linedefs P_SpawnPushers(); // phares 3/20/98: New pusher model using linedefs - TThinkerIterator it2; - ASkyCamCompat *pt2; + TThinkerIterator it2("SkyCamCompat"); + AActor *pt2; while ((pt2 = it2.Next())) { P_SpawnSkybox(pt2); diff --git a/src/portal.cpp b/src/portal.cpp index abe4425548..fc5b555c43 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -62,7 +62,16 @@ FPortalBlockmap PortalBlockmap; TArray linePortals; TArray linkedPortals; // only the linked portals, this is used to speed up looking for them in P_CollectConnectedGroups. -TArray sectorPortals; + +DEFINE_FIELD(FSectorPortal, mType); +DEFINE_FIELD(FSectorPortal, mFlags); +DEFINE_FIELD(FSectorPortal, mPartner); +DEFINE_FIELD(FSectorPortal, mPlane); +DEFINE_FIELD(FSectorPortal, mOrigin); +DEFINE_FIELD(FSectorPortal, mDestination); +DEFINE_FIELD(FSectorPortal, mDisplacement); +DEFINE_FIELD(FSectorPortal, mPlaneZ); +DEFINE_FIELD(FSectorPortal, mSkybox); //============================================================================ // @@ -490,15 +499,15 @@ void P_ClearPortals() Displacements.Create(1); linePortals.Clear(); linkedPortals.Clear(); - sectorPortals.Resize(2); + level.sectorPortals.Resize(2); // The first entry must always be the default skybox. This is what every sector gets by default. - memset(§orPortals[0], 0, sizeof(sectorPortals[0])); - sectorPortals[0].mType = PORTS_SKYVIEWPOINT; - sectorPortals[0].mFlags = PORTSF_SKYFLATONLY; + memset(&level.sectorPortals[0], 0, sizeof(level.sectorPortals[0])); + level.sectorPortals[0].mType = PORTS_SKYVIEWPOINT; + level.sectorPortals[0].mFlags = PORTSF_SKYFLATONLY; // The second entry will be the default sky. This is for forcing a regular sky through the skybox picker - memset(§orPortals[1], 0, sizeof(sectorPortals[0])); - sectorPortals[1].mType = PORTS_SKYVIEWPOINT; - sectorPortals[1].mFlags = PORTSF_SKYFLATONLY; + memset(&level.sectorPortals[1], 0, sizeof(level.sectorPortals[0])); + level.sectorPortals[1].mType = PORTS_SKYVIEWPOINT; + level.sectorPortals[1].mFlags = PORTSF_SKYFLATONLY; } //============================================================================ @@ -651,19 +660,19 @@ void P_TranslatePortalZ(line_t* src, double& z) // //============================================================================ -unsigned P_GetSkyboxPortal(ASkyViewpoint *actor) +unsigned P_GetSkyboxPortal(AActor *actor) { if (actor == NULL) return 1; // this means a regular sky. - for (unsigned i = 0;iGetClass()->IsDescendantOf(RUNTIME_CLASS(ASkyCamCompat)) ? 0 : PORTSF_SKYFLATONLY; - sectorPortals[i].mSkybox = actor; - sectorPortals[i].mDestination = actor->Sector; + unsigned i = level.sectorPortals.Reserve(1); + memset(&level.sectorPortals[i], 0, sizeof(level.sectorPortals[i])); + level.sectorPortals[i].mType = PORTS_SKYVIEWPOINT; + level.sectorPortals[i].mFlags = actor->GetClass()->IsDescendantOf(PClass::FindActor("SkyCamCompat")) ? 0 : PORTSF_SKYFLATONLY; + level.sectorPortals[i].mSkybox = actor; + level.sectorPortals[i].mDestination = actor->Sector; return i; } @@ -677,14 +686,14 @@ unsigned P_GetSkyboxPortal(ASkyViewpoint *actor) unsigned P_GetPortal(int type, int plane, sector_t *from, sector_t *to, const DVector2 &displacement) { - unsigned i = sectorPortals.Reserve(1); - memset(§orPortals[i], 0, sizeof(sectorPortals[i])); - sectorPortals[i].mType = type; - sectorPortals[i].mPlane = plane; - sectorPortals[i].mOrigin = from; - sectorPortals[i].mDestination = to; - sectorPortals[i].mDisplacement = displacement; - sectorPortals[i].mPlaneZ = type == PORTS_LINKEDPORTAL? from->GetPlaneTexZ(plane) : FLT_MAX; + unsigned i = level.sectorPortals.Reserve(1); + memset(&level.sectorPortals[i], 0, sizeof(level.sectorPortals[i])); + level.sectorPortals[i].mType = type; + level.sectorPortals[i].mPlane = plane; + level.sectorPortals[i].mOrigin = from; + level.sectorPortals[i].mDestination = to; + level.sectorPortals[i].mDisplacement = displacement; + level.sectorPortals[i].mPlaneZ = type == PORTS_LINKEDPORTAL? from->GetPlaneTexZ(plane) : FLT_MAX; return i; } @@ -698,14 +707,14 @@ unsigned P_GetPortal(int type, int plane, sector_t *from, sector_t *to, const DV unsigned P_GetStackPortal(AActor *point, int plane) { - unsigned i = sectorPortals.Reserve(1); - memset(§orPortals[i], 0, sizeof(sectorPortals[i])); - sectorPortals[i].mType = PORTS_STACKEDSECTORTHING; - sectorPortals[i].mPlane = plane; - sectorPortals[i].mOrigin = point->target->Sector; - sectorPortals[i].mDestination = point->Sector; - sectorPortals[i].mPlaneZ = FLT_MAX; - sectorPortals[i].mSkybox = point; + unsigned i = level.sectorPortals.Reserve(1); + memset(&level.sectorPortals[i], 0, sizeof(level.sectorPortals[i])); + level.sectorPortals[i].mType = PORTS_STACKEDSECTORTHING; + level.sectorPortals[i].mPlane = plane; + level.sectorPortals[i].mOrigin = point->target->Sector; + level.sectorPortals[i].mDestination = point->Sector; + level.sectorPortals[i].mPlaneZ = FLT_MAX; + level.sectorPortals[i].mSkybox = point; return i; } @@ -971,7 +980,7 @@ void P_CreateLinkedPortals() int id = 1; bool bogus = false; - for(auto &s : sectorPortals) + for(auto &s : level.sectorPortals) { if (s.mType == PORTS_LINKEDPORTAL) { diff --git a/src/portal.h b/src/portal.h index f5c8f8c885..0f2e470689 100644 --- a/src/portal.h +++ b/src/portal.h @@ -6,7 +6,6 @@ #include "m_bbox.h" struct FPortalGroupArray; -class ASkyViewpoint; struct portnode_t; //============================================================================ // @@ -237,8 +236,6 @@ struct FSectorPortal } }; -extern TArray sectorPortals; - //============================================================================ // // Functions @@ -256,7 +253,7 @@ inline int P_NumPortalGroups() { return Displacements.size; } -unsigned P_GetSkyboxPortal(ASkyViewpoint *actor); +unsigned P_GetSkyboxPortal(AActor *actor); unsigned P_GetPortal(int type, int plane, sector_t *orgsec, sector_t *destsec, const DVector2 &displacement); unsigned P_GetStackPortal(AActor *point, int plane); diff --git a/src/r_defs.h b/src/r_defs.h index 916ff569d0..9551778b06 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -292,8 +292,6 @@ protected: bool CheckTrigger(AActor *triggerer) const; }; -class ASkyViewpoint; - struct secplane_t { // the plane is defined as a*x + b*y + c*z + d = 0 @@ -925,32 +923,13 @@ public: portals[plane] = nullptr; } - FSectorPortal *GetPortal(int plane) - { - return §orPortals[Portals[plane]]; - } + FSectorPortal *GetPortal(int plane); + double GetPortalPlaneZ(int plane); + DVector2 GetPortalDisplacement(int plane); + int GetPortalType(int plane); + int GetOppositePortalGroup(int plane); - double GetPortalPlaneZ(int plane) - { - return sectorPortals[Portals[plane]].mPlaneZ; - } - - DVector2 GetPortalDisplacement(int plane) - { - return sectorPortals[Portals[plane]].mDisplacement; - } - - int GetPortalType(int plane) - { - return sectorPortals[Portals[plane]].mType; - } - - int GetOppositePortalGroup(int plane) - { - return sectorPortals[Portals[plane]].mDestination->PortalGroup; - } - - void SetVerticesDirty() + void SetVerticesDirty() { for (unsigned i = 0; i < e->vertices.Size(); i++) e->vertices[i]->dirty = true; } @@ -1312,10 +1291,7 @@ struct line_t alpha = a; } - FSectorPortal *GetTransferredPortal() - { - return portaltransferred >= sectorPortals.Size() ? (FSectorPortal*)NULL : §orPortals[portaltransferred]; - } + FSectorPortal *GetTransferredPortal(); FLinePortal *getPortal() const { diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 1018f27f6e..29f852ece3 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1136,7 +1136,7 @@ void R_DrawPortals () case PORTS_SKYVIEWPOINT: { // Don't let gun flashes brighten the sky box - ASkyViewpoint *sky = barrier_cast(port->mSkybox); + AActor *sky = port->mSkybox; extralight = 0; R_SetVisibility(sky->args[0] * 0.25f); @@ -1171,7 +1171,7 @@ void R_DrawPortals () } port->mFlags |= PORTSF_INSKYBOX; - if (port->mPartner > 0) sectorPortals[port->mPartner].mFlags |= PORTSF_INSKYBOX; + if (port->mPartner > 0) level.sectorPortals[port->mPartner].mFlags |= PORTSF_INSKYBOX; camera = NULL; viewsector = port->mDestination; assert(viewsector != NULL); @@ -1234,7 +1234,7 @@ void R_DrawPortals () R_DrawPlanes (); port->mFlags &= ~PORTSF_INSKYBOX; - if (port->mPartner > 0) sectorPortals[port->mPartner].mFlags &= ~PORTSF_INSKYBOX; + if (port->mPartner > 0) level.sectorPortals[port->mPartner].mFlags &= ~PORTSF_INSKYBOX; } // Draw all the masked textures in a second pass, in the reverse order they diff --git a/src/r_plane.h b/src/r_plane.h index 0e133a7cd2..cd1405a7c2 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -25,8 +25,6 @@ #include -class ASkyViewpoint; - namespace swrenderer { diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 9c96593566..fde56fb406 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -738,6 +738,9 @@ void InitThingdef() vertstruct->Size = sizeof(vertex_t); vertstruct->Align = alignof(vertex_t); + auto sectorportalstruct = NewNativeStruct("SectorPortal", nullptr); + sectorportalstruct->Size = sizeof(FSectorPortal); + sectorportalstruct->Align = alignof(FSectorPortal); // set up the lines array in the sector struct. This is a bit messy because the type system is not prepared to handle a pointer to an array of pointers to a native struct even remotely well... // As a result, the size has to be set to something large and arbritrary because it can change between maps. This will need some serious improvement when things get cleaned up. @@ -762,11 +765,12 @@ void InitThingdef() PField *levelf = new PField("level", lstruct, VARF_Native | VARF_Static, (intptr_t)&level); GlobalSymbols.AddSymbol(levelf); - // Add the sector array to LevelLocals. + // Add the game data arrays to LevelLocals. lstruct->AddNativeField("sectors", NewPointer(NewResizableArray(sectorstruct), false), myoffsetof(FLevelLocals, sectors), VARF_Native); lstruct->AddNativeField("lines", NewPointer(NewResizableArray(linestruct), false), myoffsetof(FLevelLocals, lines), VARF_Native); lstruct->AddNativeField("sides", NewPointer(NewResizableArray(sidestruct), false), myoffsetof(FLevelLocals, sides), VARF_Native); lstruct->AddNativeField("vertexes", NewPointer(NewResizableArray(vertstruct), false), myoffsetof(FLevelLocals, vertexes), VARF_Native|VARF_ReadOnly); + lstruct->AddNativeField("sectorportals", NewPointer(NewResizableArray(sectorportalstruct), false), myoffsetof(FLevelLocals, sectorPortals), VARF_Native); // set up a variable for the DEH data PStruct *dstruct = NewNativeStruct("DehInfo", nullptr); diff --git a/wadsrc/static/zscript/mapdata.txt b/wadsrc/static/zscript/mapdata.txt index 9d352e5fbc..148e2c1d5a 100644 --- a/wadsrc/static/zscript/mapdata.txt +++ b/wadsrc/static/zscript/mapdata.txt @@ -1,10 +1,24 @@ +struct SectorPortal native +{ + native int mType; + native int mFlags; + native uint mPartner; + native int mPlane; + native Sector mOrigin; + native Sector mDestination; + native Vector2 mDisplacement; + native double mPlaneZ; + native Actor mSkybox; +}; + + struct Vertex native { native readonly Vector2 p; } -struct Side +struct Side native { enum ETexpart { @@ -97,7 +111,7 @@ struct Line native native int special; native int args[5]; // <--- hexen-style arguments (expanded to ZDoom's full width) native double alpha; // <--- translucency (0=invisibile, FRACUNIT=opaque) - //native Side sidedef[2]; + native Side sidedef[2]; native readonly double bbox[4]; // bounding box, for the extent of the LineDef. native readonly Sector frontsector, backsector; native int validcount; // if == validcount, already checked