This commit is contained in:
Christoph Oelckers 2016-02-22 12:06:34 +01:00
commit fe9a12173c
5 changed files with 49 additions and 28 deletions

View file

@ -673,3 +673,7 @@ xx(Max_Exp)
xx(Mant_Dig) xx(Mant_Dig)
xx(Min_10_Exp) xx(Min_10_Exp)
xx(Max_10_Exp) xx(Max_10_Exp)
xx(__decorate_internal_int__)
xx(__decorate_internal_bool__)
xx(__decorate_internal_state__)

View file

@ -192,6 +192,7 @@ void ParseFunctionParameters(FScanner &sc, PClassActor *cls, TArray<FxExpression
PFunction *afd, FString statestring, FStateDefinitions *statedef); PFunction *afd, FString statestring, FStateDefinitions *statedef);
FxExpression *ParseActions(FScanner &sc, FState state, FString statestring, Baggage &bag, PPrototype *&proto, bool &endswithret); FxExpression *ParseActions(FScanner &sc, FState state, FString statestring, Baggage &bag, PPrototype *&proto, bool &endswithret);
class FxVMFunctionCall *ParseAction(FScanner &sc, FState state, FString statestring, Baggage &bag); class FxVMFunctionCall *ParseAction(FScanner &sc, FState state, FString statestring, Baggage &bag);
FName CheckCastKludges(FName in);
void AddImplicitReturn(class FxSequence *code, const PPrototype *proto, FScanner &sc); void AddImplicitReturn(class FxSequence *code, const PPrototype *proto, FScanner &sc);
void SetImplicitArgs(TArray<PType *> *args, TArray<DWORD> *argflags, PClassActor *cls, DWORD funcflags); void SetImplicitArgs(TArray<PType *> *args, TArray<DWORD> *argflags, PClassActor *cls, DWORD funcflags);
@ -357,8 +358,8 @@ int MatchString (const char *in, const char **strings);
} }
#define ACTION_RETURN_STATE(state) if (numret > 0) { assert(ret != NULL); ret->SetPointer(state, ATAG_STATE); return 1; } return 0 #define ACTION_RETURN_STATE(v) do { FState *state = v; if (numret > 0) { assert(ret != NULL); ret->SetPointer(state, ATAG_STATE); return 1; } return 0; } while(0)
#define ACTION_RETURN_INT(v) if (numret > 0) { assert(ret != NULL); ret->SetInt(v); return 1; } return 0 #define ACTION_RETURN_INT(v) do { int u = v; if (numret > 0) { assert(ret != NULL); ret->SetInt(u); return 1; } return 0; } while(0)
#define ACTION_RETURN_BOOL(v) ACTION_RETURN_INT(v) #define ACTION_RETURN_BOOL(v) ACTION_RETURN_INT(v)
// Checks to see what called the current action function // Checks to see what called the current action function

View file

@ -325,13 +325,13 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, GetDistance)
//=========================================================================== //===========================================================================
// //
// A_State // __decorate_internal_state__
// //
// Returns the state passed in. // Returns the state passed in.
// //
//=========================================================================== //===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_State) DEFINE_ACTION_FUNCTION_PARAMS(AActor, __decorate_internal_state__)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_OBJECT(self, AActor); PARAM_OBJECT(self, AActor);
@ -341,13 +341,13 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_State)
//=========================================================================== //===========================================================================
// //
// A_Int // __decorate_internal_int__
// //
// Returns the int passed in. // Returns the int passed in.
// //
//=========================================================================== //===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Int) DEFINE_ACTION_FUNCTION_PARAMS(AActor, __decorate_internal_int__)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_OBJECT(self, AActor); PARAM_OBJECT(self, AActor);
@ -357,13 +357,13 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Int)
//=========================================================================== //===========================================================================
// //
// A_Bool // __decorate_internal_bool__
// //
// Returns the bool passed in. // Returns the bool passed in.
// //
//=========================================================================== //===========================================================================
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Bool) DEFINE_ACTION_FUNCTION_PARAMS(AActor, __decorate_internal_bool__)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_OBJECT(self, AActor); PARAM_OBJECT(self, AActor);
@ -1969,8 +1969,6 @@ static bool DoGiveInventory(AActor *receiver, bool orresult, VM_ARGS)
return false; return false;
} }
bool res = true;
if (amount <= 0) if (amount <= 0)
{ {
amount = 1; amount = 1;
@ -2008,15 +2006,13 @@ static bool DoGiveInventory(AActor *receiver, bool orresult, VM_ARGS)
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveInventory) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveInventory)
{ {
PARAM_ACTION_PROLOGUE; PARAM_ACTION_PROLOGUE;
bool result = DoGiveInventory(self, false, VM_ARGS_NAMES); ACTION_RETURN_BOOL(DoGiveInventory(self, false, VM_ARGS_NAMES));
ACTION_RETURN_BOOL(result);
} }
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveToTarget) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveToTarget)
{ {
PARAM_ACTION_PROLOGUE; PARAM_ACTION_PROLOGUE;
bool result = DoGiveInventory(self->target, false, VM_ARGS_NAMES); ACTION_RETURN_BOOL(DoGiveInventory(self->target, false, VM_ARGS_NAMES));
ACTION_RETURN_BOOL(result);
} }
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveToChildren) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GiveToChildren)
@ -2096,15 +2092,13 @@ bool DoTakeInventory(AActor *receiver, bool orresult, VM_ARGS)
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_TakeInventory) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_TakeInventory)
{ {
PARAM_ACTION_PROLOGUE; PARAM_ACTION_PROLOGUE;
bool result = DoTakeInventory(self, false, VM_ARGS_NAMES); ACTION_RETURN_BOOL(DoTakeInventory(self, false, VM_ARGS_NAMES));
ACTION_RETURN_BOOL(result);
} }
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_TakeFromTarget) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_TakeFromTarget)
{ {
PARAM_ACTION_PROLOGUE; PARAM_ACTION_PROLOGUE;
bool result = DoTakeInventory(self->target, false, VM_ARGS_NAMES); ACTION_RETURN_BOOL(DoTakeInventory(self->target, false, VM_ARGS_NAMES));
ACTION_RETURN_BOOL(result);
} }
DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_TakeFromChildren) DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_TakeFromChildren)
@ -2405,8 +2399,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SpawnItem)
AActor *mo = Spawn( missile, self->Vec3Angle(distance, self->angle, -self->floorclip + self->GetBobOffset() + zheight), ALLOW_REPLACE); AActor *mo = Spawn( missile, self->Vec3Angle(distance, self->angle, -self->floorclip + self->GetBobOffset() + zheight), ALLOW_REPLACE);
int flags = (transfer_translation ? SIXF_TRANSFERTRANSLATION : 0) + (useammo ? SIXF_SETMASTER : 0); int flags = (transfer_translation ? SIXF_TRANSFERTRANSLATION : 0) + (useammo ? SIXF_SETMASTER : 0);
bool result = InitSpawnedItem(self, mo, flags); ACTION_RETURN_BOOL(InitSpawnedItem(self, mo, flags)); // for an inventory item's use state
ACTION_RETURN_BOOL(result); // for an inventory item's use state
} }
//=========================================================================== //===========================================================================
@ -3255,8 +3248,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIf)
PARAM_BOOL (condition); PARAM_BOOL (condition);
PARAM_STATE (jump); PARAM_STATE (jump);
if (!condition) jump = NULL; ACTION_RETURN_STATE(condition ? jump : NULL);
ACTION_RETURN_STATE(jump);
} }
//=========================================================================== //===========================================================================

View file

@ -372,7 +372,7 @@ void AddImplicitReturn(FxSequence *code, const PPrototype *proto, FScanner &sc)
else else
{ // Something was returned earlier in the sequence. Make it an error { // Something was returned earlier in the sequence. Make it an error
// instead of adding an implicit one. // instead of adding an implicit one.
sc.ScriptError("Action list must return a value"); sc.ScriptError("Not all paths return a value");
} }
} }
@ -555,7 +555,9 @@ FxVMFunctionCall *ParseAction(FScanner &sc, FState state, FString statestring, B
return call; return call;
} }
PFunction *afd = dyn_cast<PFunction>(bag.Info->Symbols.FindSymbol(FName(sc.String, true), true)); FName symname = FName(sc.String, true);
symname = CheckCastKludges(symname);
PFunction *afd = dyn_cast<PFunction>(bag.Info->Symbols.FindSymbol(symname, true));
if (afd != NULL) if (afd != NULL)
{ {
FArgumentList *args = new FArgumentList; FArgumentList *args = new FArgumentList;
@ -678,3 +680,24 @@ void ParseFunctionParameters(FScanner &sc, PClassActor *cls, TArray<FxExpression
sc.MustGetStringName(")"); sc.MustGetStringName(")");
} }
} }
//==========================================================================
//
// CheckCastKludges
//
//==========================================================================
FName CheckCastKludges(FName in)
{
switch (in)
{
case NAME_Int:
return NAME___decorate_internal_int__;
case NAME_Bool:
return NAME___decorate_internal_bool__;
case NAME_State:
return NAME___decorate_internal_state__;
default:
return in;
}
}

View file

@ -43,10 +43,6 @@ ACTOR Actor native //: Thinker
native int CountInv(class<Inventory> itemtype, int ptr_select = AAPTR_DEFAULT); native int CountInv(class<Inventory> itemtype, int ptr_select = AAPTR_DEFAULT);
native float GetDistance(bool checkz, int ptr = AAPTR_DEFAULT); native float GetDistance(bool checkz, int ptr = AAPTR_DEFAULT);
native state A_State(state returnme);
native int A_Int(int returnme);
native bool A_Bool(bool returnme);
// Action functions // Action functions
// Meh, MBF redundant functions. Only for DeHackEd support. // Meh, MBF redundant functions. Only for DeHackEd support.
action native A_Turn(float angle = 0); action native A_Turn(float angle = 0);
@ -353,4 +349,9 @@ ACTOR Actor native //: Thinker
POL5 A -1 POL5 A -1
Stop Stop
} }
// Internal functions
native state __decorate_internal_state__(state);
native int __decorate_internal_int__(int);
native bool __decorate_internal_bool__(bool);
} }