From 1c74faea73369dc4af7b8f5ecb7b5e89f1867967 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 8 Jan 2017 15:45:37 +0100 Subject: [PATCH] - exported line_t's functions to the VM. --- src/p_sectors.cpp | 45 ++++++++++++++++++++++++++++++++-- src/scripting/vm/vm.h | 3 +++ src/scripting/vm/vmexec.cpp | 4 +-- wadsrc/static/zscript/base.txt | 6 +++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 3d77b44c9..8be0862b6 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -1779,12 +1779,53 @@ DEFINE_ACTION_FUNCTION(_Sector, NextLowestFloorAt) if (ndx >= level.sectors.Size()) { // This qualifies as an array out of bounds exception. Normally it can only happen when a sector copy is concerned which scripts should not be able to create. - va_list ap; - throw CVMAbortException(X_ARRAY_OUT_OF_BOUNDS, "Accessed invalid sector", ap); + ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Accessed invalid sector"); } ACTION_RETURN_INT(ndx); } + //=========================================================================== + // + // line_t exports + // + //=========================================================================== + + DEFINE_ACTION_FUNCTION(_Line, isLinePortal) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_BOOL(self->isLinePortal()); + } + + DEFINE_ACTION_FUNCTION(_Line, isVisualPortal) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_BOOL(self->isVisualPortal()); + } + + DEFINE_ACTION_FUNCTION(_Line, getPortalDestination) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_POINTER(self->getPortalDestination()); + } + + DEFINE_ACTION_FUNCTION(_Line, getPortalAlignment) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_INT(self->getPortalAlignment()); + } + + DEFINE_ACTION_FUNCTION(_Line, Index) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + unsigned ndx = self->Index(); + if (ndx >= level.lines.Size()) + { + ThrowAbortException(X_ARRAY_OUT_OF_BOUNDS, "Accessed invalid line"); + } + ACTION_RETURN_INT(ndx); + } + + //=========================================================================== // // diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index fdf5f3c9f..2e98e865e 100644 --- a/src/scripting/vm/vm.h +++ b/src/scripting/vm/vm.h @@ -209,6 +209,9 @@ public: void MaybePrintMessage(); }; +// This must be a separate function because the VC compiler would otherwise allocate memory on the stack for every separate instance of the exception object that may get thrown. +void ThrowAbortException(EVMAbortException reason, const char *moreinfo, ...); + enum EVMOpMode { MODE_ASHIFT = 0, diff --git a/src/scripting/vm/vmexec.cpp b/src/scripting/vm/vmexec.cpp index 3183edcfb..1ad4e3256 100644 --- a/src/scripting/vm/vmexec.cpp +++ b/src/scripting/vm/vmexec.cpp @@ -44,9 +44,7 @@ extern cycle_t VMCycles[10]; extern int VMCalls[10]; -// This must be a separate function because the VC compiler would otherwise allocate memory on the stack for every separate instance of the exception object that may get thrown. -void ThrowAbortException(EVMAbortException reason, const char *moreinfo, ...); -// intentionally implemented in a different source file tp prevent inlining. +// intentionally implemented in a different source file to prevent inlining. void ThrowVMException(VMException *x); #define IMPLEMENT_VMEXEC diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index b48f0ee58..3dc846f0b 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -240,6 +240,12 @@ struct Line native native int locknumber; // [Dusk] lock number for special native readonly uint portalindex; native readonly uint portaltransferred; + + native bool isLinePortal(); + native bool isVisualPortal(); + native Line getPortalDestination(); + native int getPortalAlignment(); + native int Index(); } struct SecPlane native