From dd7cb8649f73e061c78d8b7c653d0d6b9e7338cb Mon Sep 17 00:00:00 2001 From: Boondorl <59555366+Boondorl@users.noreply.github.com> Date: Sun, 15 Jan 2023 15:29:23 -0500 Subject: [PATCH] Exported LinePortals Added helper functions for lines related to portals --- src/g_levellocals.h | 20 ++++++++++++++ src/gamedata/r_defs.h | 4 +++ src/playsim/portal.cpp | 11 ++++++++ src/scripting/thingdef_data.cpp | 4 +++ src/scripting/vmthunks.cpp | 25 +++++++++++++++++ wadsrc/static/zscript/doombase.zs | 1 + wadsrc/static/zscript/mapdata.zs | 45 +++++++++++++++++++++++++++++++ 7 files changed, 110 insertions(+) diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 8d9c92d7e..04ec8c6d9 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -845,11 +845,31 @@ inline line_t *line_t::getPortalDestination() const return portalindex >= GetLevel()->linePortals.Size() ? (line_t*)nullptr : GetLevel()->linePortals[portalindex].mDestination; } +inline int line_t::getPortalFlags() const +{ + return portalindex >= GetLevel()->linePortals.Size() ? 0 : GetLevel()->linePortals[portalindex].mFlags; +} + inline int line_t::getPortalAlignment() const { return portalindex >= GetLevel()->linePortals.Size() ? 0 : GetLevel()->linePortals[portalindex].mAlign; } +inline int line_t::getPortalType() const +{ + return portalindex >= GetLevel()->linePortals.Size() ? 0 : GetLevel()->linePortals[portalindex].mType; +} + +inline DVector2 line_t::getPortalDisplacement() const +{ + return portalindex >= GetLevel()->linePortals.Size() ? DVector2(0., 0.) : GetLevel()->linePortals[portalindex].mDisplacement; +} + +inline DAngle line_t::getPortalAngleDiff() const +{ + return portalindex >= GetLevel()->linePortals.Size() ? DAngle::fromDeg(0.) : GetLevel()->linePortals[portalindex].mAngleDiff; +} + inline bool line_t::hitSkyWall(AActor* mo) const { return backsector && diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index 273ffebfc..c6284b2f1 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -1504,7 +1504,11 @@ struct line_t : public linebase_t inline bool isLinePortal() const; inline bool isVisualPortal() const; inline line_t *getPortalDestination() const; + inline int getPortalFlags() const; inline int getPortalAlignment() const; + inline int getPortalType() const; + inline DVector2 getPortalDisplacement() const; + inline DAngle getPortalAngleDiff() const; inline bool hitSkyWall(AActor* mo) const; int Index() const { return linenum; } diff --git a/src/playsim/portal.cpp b/src/playsim/portal.cpp index 0caf13631..f94f7f914 100644 --- a/src/playsim/portal.cpp +++ b/src/playsim/portal.cpp @@ -51,6 +51,17 @@ DEFINE_FIELD(FSectorPortal, mDisplacement); DEFINE_FIELD(FSectorPortal, mPlaneZ); DEFINE_FIELD(FSectorPortal, mSkybox); +DEFINE_FIELD(FLinePortal, mOrigin); +DEFINE_FIELD(FLinePortal, mDestination); +DEFINE_FIELD(FLinePortal, mDisplacement); +DEFINE_FIELD(FLinePortal, mType); +DEFINE_FIELD(FLinePortal, mFlags); +DEFINE_FIELD(FLinePortal, mDefFlags); +DEFINE_FIELD(FLinePortal, mAlign); +DEFINE_FIELD(FLinePortal, mAngleDiff); +DEFINE_FIELD(FLinePortal, mSinRot); +DEFINE_FIELD(FLinePortal, mCosRot); + //============================================================================ // // BuildBlockmap diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 890637a37..ddd5925f3 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -708,6 +708,10 @@ void InitThingdef() sectorportalstruct->Size = sizeof(FSectorPortal); sectorportalstruct->Align = alignof(FSectorPortal); + auto lineportalstruct = NewStruct("LinePortal", nullptr, true); + lineportalstruct->Size = sizeof(FLinePortal); + lineportalstruct->Align = alignof(FLinePortal); + auto playerclassstruct = NewStruct("PlayerClass", nullptr, true); playerclassstruct->Size = sizeof(FPlayerClass); playerclassstruct->Align = alignof(FPlayerClass); diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 153a133f9..d672a5192 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -1199,12 +1199,36 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, SetXOffset, SetXOffset) return self->getPortalAlignment(); } + DEFINE_ACTION_FUNCTION(_Line, getPortalFlags) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_INT(self->getPortalFlags()); + } + DEFINE_ACTION_FUNCTION_NATIVE(_Line, getPortalAlignment, getPortalAlignment) { PARAM_SELF_STRUCT_PROLOGUE(line_t); ACTION_RETURN_INT(self->getPortalAlignment()); } + DEFINE_ACTION_FUNCTION(_Line, getPortalType) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_INT(self->getPortalType()); + } + + DEFINE_ACTION_FUNCTION(_Line, getPortalDisplacement) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_VEC2(self->getPortalDisplacement()); + } + + DEFINE_ACTION_FUNCTION(_Line, getPortalAngleDiff) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_FLOAT(self->getPortalAngleDiff().Degrees()); + } + static int LineIndex(line_t *self) { return self->Index(); @@ -2719,6 +2743,7 @@ DEFINE_FIELD(FLevelLocals, sectors) DEFINE_FIELD(FLevelLocals, lines) DEFINE_FIELD(FLevelLocals, sides) DEFINE_FIELD(FLevelLocals, vertexes) +DEFINE_FIELD(FLevelLocals, linePortals) DEFINE_FIELD(FLevelLocals, sectorPortals) DEFINE_FIELD(FLevelLocals, time) DEFINE_FIELD(FLevelLocals, maptime) diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index 9f4771bee..6ed46159a 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -409,6 +409,7 @@ struct LevelLocals native native Array<@Line> Lines; native Array<@Side> Sides; native readonly Array<@Vertex> Vertexes; + native readonly Array<@LinePortal> LinePortals; native internal Array<@SectorPortal> SectorPortals; native readonly int time; diff --git a/wadsrc/static/zscript/mapdata.zs b/wadsrc/static/zscript/mapdata.zs index 27c41dba6..e7f3044ff 100644 --- a/wadsrc/static/zscript/mapdata.zs +++ b/wadsrc/static/zscript/mapdata.zs @@ -28,6 +28,47 @@ struct SectorPortal native play native Actor mSkybox; }; +struct LinePortal native play +{ + enum EType + { + PORTT_VISUAL, + PORTT_TELEPORT, + PORTT_INTERACTIVE, + PORTT_LINKED, + PORTT_LINKEDEE // Eternity compatible definition which uses only one line ID and a different anchor type to link to. + }; + + enum EFlags + { + PORTF_VISIBLE = 1, + PORTF_PASSABLE = 2, + PORTF_SOUNDTRAVERSE = 4, + PORTF_INTERACTIVE = 8, + PORTF_POLYOBJ = 16, + + PORTF_TYPETELEPORT = PORTF_VISIBLE | PORTF_PASSABLE | PORTF_SOUNDTRAVERSE, + PORTF_TYPEINTERACTIVE = PORTF_VISIBLE | PORTF_PASSABLE | PORTF_SOUNDTRAVERSE | PORTF_INTERACTIVE, + }; + + enum EAlignment + { + PORG_ABSOLUTE, // does not align at all. z-ccoordinates must match. + PORG_FLOOR, + PORG_CEILING, + }; + + native Line mOrigin; + native Line mDestination; + native Vector2 mDisplacement; + native uint8 mType; + native uint8 mFlags; + native uint8 mDefFlags; + native uint8 mAlign; + native double mAngleDiff; + native double mSinRot; + native double mCosRot; +} struct Vertex native play { @@ -189,7 +230,11 @@ struct Line native play native clearscope bool isLinePortal() const; native clearscope bool isVisualPortal() const; native clearscope Line getPortalDestination() const; + native clearscope int getPortalFlags() const; native clearscope int getPortalAlignment() const; + native clearscope int getPortalType() const; + native clearscope Vector2 getPortalDisplacement() const; + native clearscope double getPortalAngleDiff() const; native clearscope int Index() const; native bool Activate(Actor activator, int side, int type); native bool RemoteActivate(Actor activator, int side, int type, Vector3 pos);