From eace79ccad325b9c6181b4e941eeb5a48604be42 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 18 Feb 2016 22:11:05 -0600 Subject: [PATCH] Add some functions for use with DECORATE return - Since DECORATE's return statement can only return the results of function calls (I do not want to spend the time necessary to make it return arbitrary expressions), here are three functions to get around this limitation: * A_State - Returns the state passed to it. You can simulate A_Jump functions with this. * A_Int - Returns the int passed to it. * A_Bool - Returns the bool passed to it. - e.g. If you want to return the number 3, you use this: return A_Int(3); If you want to jump to a different state, you use this: return A_State("SomeState"); --- src/thingdef/thingdef_codeptr.cpp | 45 +++++++++++++++++++++++++++++++ src/thingdef/thingdef_parse.cpp | 4 +++ wadsrc/static/actors/actor.txt | 4 +++ 3 files changed, 53 insertions(+) diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 40cd68b6f..19e9d4a96 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -6757,3 +6757,48 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_FaceMovementDirection) } ACTION_RETURN_BOOL(true); } + +//=========================================================================== +// +// A_State +// +// Returns the state passed in. +// +//=========================================================================== + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_State) +{ + PARAM_ACTION_PROLOGUE; + PARAM_STATE(returnme); + ACTION_RETURN_STATE(returnme); +} + +//=========================================================================== +// +// A_Int +// +// Returns the int passed in. +// +//=========================================================================== + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Int) +{ + PARAM_ACTION_PROLOGUE; + PARAM_INT(returnme); + ACTION_RETURN_INT(returnme); +} + +//=========================================================================== +// +// A_Bool +// +// Returns the bool passed in. +// +//=========================================================================== + +DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Bool) +{ + PARAM_ACTION_PROLOGUE; + PARAM_BOOL(returnme); + ACTION_RETURN_BOOL(returnme); +} diff --git a/src/thingdef/thingdef_parse.cpp b/src/thingdef/thingdef_parse.cpp index 4774ac9d1..daff4a99b 100644 --- a/src/thingdef/thingdef_parse.cpp +++ b/src/thingdef/thingdef_parse.cpp @@ -494,6 +494,10 @@ static void ParseNativeFunction(FScanner &sc, PClassActor *cls) rets.Push(TypeFixed); break; + case TK_State: + rets.Push(TypeState); + break; + case TK_Identifier: rets.Push(NewPointer(RUNTIME_CLASS(DObject))); // Todo: Object type diff --git a/wadsrc/static/actors/actor.txt b/wadsrc/static/actors/actor.txt index 5b0f3a2de..54bc6c07c 100644 --- a/wadsrc/static/actors/actor.txt +++ b/wadsrc/static/actors/actor.txt @@ -332,6 +332,10 @@ ACTOR Actor native //: Thinker action native int ACS_NamedExecuteWithResult(name script, int arg1=0, int arg2=0, int arg3=0, int arg4=0); action native ACS_NamedExecuteAlways(name script, int mapnum=0, int arg1=0, int arg2=0, int arg3=0); + native state A_State(state returnme); + native int A_Int(int returnme); + native bool A_Bool(bool returnme); + States { Spawn: