From 062528e0e22d1aa05be2eee12433fc0def0a73b9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 4 Dec 2018 18:16:01 +0100 Subject: [PATCH] - more direct native function calls. --- src/g_inventory/a_pickups.cpp | 9 +- src/g_shared/a_specialspot.cpp | 34 ---- src/p_actionfunctions.cpp | 15 -- src/scripting/backend/codegen.cpp | 7 +- src/scripting/thingdef_data.cpp | 147 -------------- src/scripting/vmthunks.cpp | 317 +++++++++++++++++++++++++++++- 6 files changed, 325 insertions(+), 204 deletions(-) diff --git a/src/g_inventory/a_pickups.cpp b/src/g_inventory/a_pickups.cpp index 0dfb30cd24..fdb0b22f4b 100644 --- a/src/g_inventory/a_pickups.cpp +++ b/src/g_inventory/a_pickups.cpp @@ -57,27 +57,24 @@ EXTERN_CVAR(Bool, sv_unlimited_pickup) //=========================================================================== // +// This is only native so it can have some static storage for comparison. // //=========================================================================== static int StaticLastMessageTic; static FString StaticLastMessage; -DEFINE_ACTION_FUNCTION(AInventory, PrintPickupMessage) +void PrintPickupMessage(bool localview, const FString &str) { - PARAM_PROLOGUE; - PARAM_BOOL(localview); - PARAM_STRING(str); if (str.IsNotEmpty() && localview && (StaticLastMessageTic != gametic || StaticLastMessage.Compare(str))) { StaticLastMessageTic = gametic; StaticLastMessage = str; const char *pstr = str.GetChars(); - + if (pstr[0] == '$') pstr = GStrings(pstr + 1); if (pstr[0] != 0) Printf(PRINT_LOW, "%s\n", pstr); StatusBar->FlashCrosshair(); } - return 0; } //=========================================================================== diff --git a/src/g_shared/a_specialspot.cpp b/src/g_shared/a_specialspot.cpp index 163f1a25c4..2797ab70ff 100644 --- a/src/g_shared/a_specialspot.cpp +++ b/src/g_shared/a_specialspot.cpp @@ -248,12 +248,6 @@ DSpotState *DSpotState::GetSpotState(bool create) return SpotState; } -DEFINE_ACTION_FUNCTION(DSpotState, GetSpotState) -{ - PARAM_PROLOGUE; - ACTION_RETURN_OBJECT(DSpotState::GetSpotState()); -} - //---------------------------------------------------------------------------- // // @@ -321,14 +315,6 @@ ASpecialSpot *DSpotState::GetNextInList(PClassActor *type, int skipcounter) return NULL; } -DEFINE_ACTION_FUNCTION(DSpotState, GetNextInList) -{ - PARAM_SELF_PROLOGUE(DSpotState); - PARAM_CLASS(type, AActor); - PARAM_INT(skipcounter); - ACTION_RETURN_OBJECT(self->GetNextInList(type, skipcounter)); -} - //---------------------------------------------------------------------------- // // @@ -342,18 +328,6 @@ ASpecialSpot *DSpotState::GetSpotWithMinMaxDistance(PClassActor *type, double x, return NULL; } -DEFINE_ACTION_FUNCTION(DSpotState, GetSpotWithMinMaxDistance) -{ - PARAM_SELF_PROLOGUE(DSpotState); - PARAM_CLASS(type, AActor); - PARAM_FLOAT(x); - PARAM_FLOAT(y); - PARAM_FLOAT(mindist); - PARAM_FLOAT(maxdist); - ACTION_RETURN_OBJECT(self->GetSpotWithMinMaxDistance(type, x, y, mindist, maxdist)); -} - - //---------------------------------------------------------------------------- // // @@ -367,14 +341,6 @@ ASpecialSpot *DSpotState::GetRandomSpot(PClassActor *type, bool onlyonce) return NULL; } -DEFINE_ACTION_FUNCTION(DSpotState, GetRandomSpot) -{ - PARAM_SELF_PROLOGUE(DSpotState); - PARAM_CLASS(type, AActor); - PARAM_BOOL(onlyonce); - ACTION_RETURN_POINTER(self->GetRandomSpot(type, onlyonce)); -} - //---------------------------------------------------------------------------- // // diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index e3d46fd6a4..88a95e3b7f 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -243,21 +243,6 @@ DEFINE_ACTION_FUNCTION(ACustomInventory, CallStateChain) ACTION_RETURN_BOOL(CallStateChain(self, affectee, state)); } -//========================================================================== -// -// GetPointer -// -// resolve AAPTR_* -// -//========================================================================== - -DEFINE_ACTION_FUNCTION(AActor, GetPointer) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_INT(ptr); - ACTION_RETURN_OBJECT(COPY_AAPTR(self, ptr)); -} - //========================================================================== // // CheckClass diff --git a/src/scripting/backend/codegen.cpp b/src/scripting/backend/codegen.cpp index b0f1d9776d..0eecab9a9b 100644 --- a/src/scripting/backend/codegen.cpp +++ b/src/scripting/backend/codegen.cpp @@ -8530,7 +8530,12 @@ FxExpression *FxActionSpecialCall::Resolve(FCompileContext& ctx) // //========================================================================== -DEFINE_ACTION_FUNCTION(DObject, BuiltinCallLineSpecial) +void BuiltinCallLineSpecial(int special, AActor *activator, int arg1, int arg2, int arg3, int arg4, int arg5) +{ + P_ExecuteSpecial(special, nullptr, activator, 0, arg1, arg2, arg3, arg4, arg5); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DObject, BuiltinCallLineSpecial, BuiltinCallLineSpecial) { PARAM_PROLOGUE; PARAM_INT(special); diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index f1abb5febf..1ddfac1fe2 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -409,13 +409,6 @@ static FFlagDef MoreFlagDefs[] = DEFINE_DUMMY_FLAG(SERVERSIDEONLY, false), }; -static FFlagDef InventoryFlagDefs[] = -{ - // Inventory flags - DEFINE_DEPRECATED_FLAG(PICKUPFLASH), - DEFINE_DEPRECATED_FLAG(INTERHUBSTRIP), -}; - static FFlagDef PlayerPawnFlagDefs[] = { // PlayerPawn flags @@ -969,25 +962,6 @@ DEFINE_ACTION_FUNCTION(DObject, BAM) ACTION_RETURN_INT(DAngle(ang).BAMs()); } -DEFINE_ACTION_FUNCTION(FStringTable, Localize) -{ - PARAM_PROLOGUE; - PARAM_STRING(label); - PARAM_BOOL(prefixed); - if (!prefixed) ACTION_RETURN_STRING(GStrings(label)); - if (label[0] != '$') ACTION_RETURN_STRING(label); - ACTION_RETURN_STRING(GStrings(&label[1])); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, Replace) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_STRING(s1); - PARAM_STRING(s2); - self->Substitute(s1, s2); - return 0; -} - FString FStringFormat(VM_ARGS, int offset) { PARAM_VA_POINTER(va_reginfo) // Get the hidden type information array @@ -1203,124 +1177,3 @@ DEFINE_ACTION_FUNCTION(FStringStruct, AppendFormat) return 0; } -DEFINE_ACTION_FUNCTION(FStringStruct, Mid) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_UINT(pos); - PARAM_UINT(len); - FString s = self->Mid(pos, len); - ACTION_RETURN_STRING(s); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, Left) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_UINT(len); - FString s = self->Left(len); - ACTION_RETURN_STRING(s); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, Truncate) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_UINT(len); - self->Truncate(len); - return 0; -} - -DEFINE_ACTION_FUNCTION(FStringStruct, Remove) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_UINT(index); - PARAM_UINT(remlen); - self->Remove(index, remlen); - return 0; -} - -// CharAt and CharCodeAt is how JS does it, and JS is similar here in that it doesn't have char type as int. -DEFINE_ACTION_FUNCTION(FStringStruct, CharAt) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_INT(pos); - int slen = (int)self->Len(); - if (pos < 0 || pos >= slen) - ACTION_RETURN_STRING(""); - ACTION_RETURN_STRING(FString((*self)[pos])); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, CharCodeAt) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_INT(pos); - int slen = (int)self->Len(); - if (pos < 0 || pos >= slen) - ACTION_RETURN_INT(0); - ACTION_RETURN_INT((*self)[pos]); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, Filter) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - ACTION_RETURN_STRING(strbin1(*self)); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, IndexOf) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_STRING(substr); - PARAM_INT(startIndex); - ACTION_RETURN_INT(self->IndexOf(substr, startIndex)); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, LastIndexOf) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_STRING(substr); - PARAM_INT(endIndex); - ACTION_RETURN_INT(self->LastIndexOfBroken(substr, endIndex)); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, RightIndexOf) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_STRING(substr); - PARAM_INT(endIndex); - ACTION_RETURN_INT(self->LastIndexOf(substr, endIndex)); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, ToUpper) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - self->ToUpper(); - return 0; -} - -DEFINE_ACTION_FUNCTION(FStringStruct, ToLower) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - self->ToLower(); - return 0; -} - -DEFINE_ACTION_FUNCTION(FStringStruct, ToInt) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_INT(base); - ACTION_RETURN_INT(self->ToLong(base)); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, ToDouble) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - ACTION_RETURN_FLOAT(self->ToDouble()); -} - -DEFINE_ACTION_FUNCTION(FStringStruct, Split) -{ - PARAM_SELF_STRUCT_PROLOGUE(FString); - PARAM_POINTER(tokens, TArray); - PARAM_STRING(delimiter); - PARAM_INT(keepEmpty); - self->Split(*tokens, delimiter, static_cast(keepEmpty)); - return 0; -} diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 2312de8c80..685dc12891 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -40,9 +40,243 @@ #include "doomstat.h" #include "p_acs.h" #include "a_pickups.h" +#include "a_specialspot.h" +#include "actorptrselect.h" DVector2 AM_GetPosition(); int Net_GetLatency(int *ld, int *ad); +void PrintPickupMessage(bool localview, const FString &str); + +//===================================================================================== +// +// FString exports +// +//===================================================================================== + +static void LocalizeString(const FString &label, bool prefixed, FString *result) +{ + if (!prefixed) *result = GStrings(label); + else if (label[0] != '$') *result = label; + else *result = GStrings(&label[1]); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringTable, Localize, LocalizeString) +{ + PARAM_PROLOGUE; + PARAM_STRING(label); + PARAM_BOOL(prefixed); + FString result; + LocalizeString(label, prefixed, &result); + ACTION_RETURN_STRING(result); +} + +static void StringReplace(FString *self, const FString &s1, const FString &s2) +{ + self->Substitute(s1, s2); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, Replace, StringReplace) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(s1); + PARAM_STRING(s2); + self->Substitute(s1, s2); + return 0; +} + +static void StringMid(FString *self, unsigned pos, unsigned len, FString *result) +{ + *result = self->Mid(pos, len); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, Mid, StringMid) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_UINT(pos); + PARAM_UINT(len); + FString s = self->Mid(pos, len); + ACTION_RETURN_STRING(s); +} + +static void StringLeft(FString *self, unsigned len, FString *result) +{ + *result = self->Left(len); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, Left, StringLeft) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_UINT(len); + FString s = self->Left(len); + ACTION_RETURN_STRING(s); +} + +static void StringTruncate(FString *self, unsigned len) +{ + self->Truncate(len); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, Truncate, StringTruncate) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_UINT(len); + self->Truncate(len); + return 0; +} + +static void StringRemove(FString *self, unsigned index, unsigned remlen) +{ + self->Remove(index, remlen); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, Remove, StringRemove) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_UINT(index); + PARAM_UINT(remlen); + self->Remove(index, remlen); + return 0; +} + +static void StringCharAt(FString *self, int pos, FString *result) +{ + if ((unsigned)pos >= self->Len()) *result = ""; + else *result = FString((*self)[pos]); +} +// CharAt and CharCodeAt is how JS does it, and JS is similar here in that it doesn't have char type as int. +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, CharAt, StringCharAt) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_INT(pos); + FString result; + StringCharAt(self, pos, &result); + ACTION_RETURN_STRING(result); +} + +static int StringCharCodeAt(FString *self, int pos) +{ + if ((unsigned)pos >= self->Len()) return 0; + else return (*self)[pos]; +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, CharCodeAt, StringCharCodeAt) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_INT(pos); + ACTION_RETURN_INT(StringCharCodeAt(self, pos)); +} + +static void StringFilter(FString *self, FString *result) +{ + *result = strbin1(*self); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, Filter, StringFilter) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + ACTION_RETURN_STRING(strbin1(*self)); +} + +static int StringIndexOf(FString *self, const FString &substr, int startIndex) +{ + return self->IndexOf(substr, startIndex); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, IndexOf, StringIndexOf) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(substr); + PARAM_INT(startIndex); + ACTION_RETURN_INT(self->IndexOf(substr, startIndex)); +} + +static int StringLastIndexOf(FString *self, const FString &substr, int endIndex) +{ + return self->LastIndexOfBroken(substr, endIndex); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, LastIndexOf, StringLastIndexOf) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(substr); + PARAM_INT(endIndex); + ACTION_RETURN_INT(self->LastIndexOfBroken(substr, endIndex)); +} + +static int StringRightIndexOf(FString *self, const FString &substr, int endIndex) +{ + return self->LastIndexOf(substr, endIndex); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, RightIndexOf, StringRightIndexOf) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(substr); + PARAM_INT(endIndex); + ACTION_RETURN_INT(self->LastIndexOf(substr, endIndex)); +} + +static void StringToUpper(FString *self) +{ + self->ToUpper(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, ToUpper, StringToUpper) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + self->ToUpper(); + return 0; +} + +static void StringToLower(FString *self) +{ + self->ToLower(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, ToLower, StringToLower) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + self->ToLower(); + return 0; +} + +static int StringToInt(FString *self, int base) +{ + return (int)self->ToLong(base); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, ToInt, StringToInt) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_INT(base); + ACTION_RETURN_INT(self->ToLong(base)); +} + +static int StringToDbl(FString *self) +{ + return self->ToDouble(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, ToDouble, StringToDbl) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + ACTION_RETURN_FLOAT(self->ToDouble()); +} + +static void StringSplit(FString *self, TArray *tokens, const FString &delimiter, int keepEmpty) +{ + self->Split(*tokens, delimiter, static_cast(keepEmpty)); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, Split, StringSplit) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_POINTER(tokens, TArray); + PARAM_STRING(delimiter); + PARAM_INT(keepEmpty); + StringSplit(self, tokens, delimiter, keepEmpty); + return 0; +} //===================================================================================== // @@ -1578,6 +1812,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetCursor, GetCursor) // //===================================================================================== +DEFINE_ACTION_FUNCTION_NATIVE(AActor, GetPointer, COPY_AAPTR) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_INT(ptr); + ACTION_RETURN_OBJECT(COPY_AAPTR(self, ptr)); +} + + DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_PlaySound, A_PlaySound) { PARAM_SELF_PROLOGUE(AActor); @@ -1601,6 +1843,21 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, CheckKeys, P_CheckKeys) } +//===================================================================================== +// +// Inventory exports +// +//===================================================================================== + +DEFINE_ACTION_FUNCTION_NATIVE(AInventory, PrintPickupMessage, PrintPickupMessage) +{ + PARAM_PROLOGUE; + PARAM_BOOL(localview); + PARAM_STRING(str); + PrintPickupMessage(localview, str); + return 0; +} + //===================================================================================== // // Key exports @@ -1620,6 +1877,64 @@ DEFINE_ACTION_FUNCTION_NATIVE(AKey, GetKeyType, P_GetKeyType) ACTION_RETURN_POINTER(P_GetKeyType(num)); } +//===================================================================================== +// +// SpotState exports +// +//===================================================================================== + +static DSpotState *GetSpotState() +{ + return DSpotState::GetSpotState(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DSpotState, GetSpotState, GetSpotState) +{ + PARAM_PROLOGUE; + ACTION_RETURN_OBJECT(DSpotState::GetSpotState()); +} + +static AActor *GetNextInList(DSpotState *self, PClassActor *type, int skipcounter) +{ + return self->GetNextInList(type, skipcounter); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DSpotState, GetNextInList, GetNextInList) +{ + PARAM_SELF_PROLOGUE(DSpotState); + PARAM_CLASS(type, AActor); + PARAM_INT(skipcounter); + ACTION_RETURN_OBJECT(self->GetNextInList(type, skipcounter)); +} + +static AActor *GetSpotWithMinMaxDistance(DSpotState *self, PClassActor *type, double x, double y, double mindist, double maxdist) +{ + return self->GetSpotWithMinMaxDistance(type, x, y, mindist, maxdist); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DSpotState, GetSpotWithMinMaxDistance, GetSpotWithMinMaxDistance) +{ + PARAM_SELF_PROLOGUE(DSpotState); + PARAM_CLASS(type, AActor); + PARAM_FLOAT(x); + PARAM_FLOAT(y); + PARAM_FLOAT(mindist); + PARAM_FLOAT(maxdist); + ACTION_RETURN_OBJECT(self->GetSpotWithMinMaxDistance(type, x, y, mindist, maxdist)); +} + +static AActor *GetRandomSpot(DSpotState *self, PClassActor *type, bool onlyonce) +{ + return self->GetRandomSpot(type, onlyonce); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DSpotState, GetRandomSpot, GetRandomSpot) +{ + PARAM_SELF_PROLOGUE(DSpotState); + PARAM_CLASS(type, AActor); + PARAM_BOOL(onlyonce); + ACTION_RETURN_POINTER(self->GetRandomSpot(type, onlyonce)); +} //===================================================================================== // @@ -1867,7 +2182,7 @@ void SBar_DrawImage(DBaseStatusBar *self, const FString &texid, double x, double self->DrawGraphic(TexMan.CheckForTexture(texid, ETextureType::Any), x, y, flags, alpha, w, h, scaleX, scaleY); } -DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawImage) +DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, DrawImage, SBar_DrawImage) { PARAM_SELF_PROLOGUE(DBaseStatusBar); PARAM_STRING(texid);