mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-18 22:51:39 +00:00
- added DavidPH's sqrt for DECORATE submission.
SVN r3586 (trunk)
This commit is contained in:
parent
44519f3972
commit
4df1ea63b5
6 changed files with 609 additions and 449 deletions
|
@ -873,6 +873,7 @@ add_executable( zdoom WIN32
|
||||||
thingdef/thingdef_data.cpp
|
thingdef/thingdef_data.cpp
|
||||||
thingdef/thingdef_exp.cpp
|
thingdef/thingdef_exp.cpp
|
||||||
thingdef/thingdef_expression.cpp
|
thingdef/thingdef_expression.cpp
|
||||||
|
thingdef/thingdef_function.cpp
|
||||||
thingdef/thingdef_parse.cpp
|
thingdef/thingdef_parse.cpp
|
||||||
thingdef/thingdef_properties.cpp
|
thingdef/thingdef_properties.cpp
|
||||||
thingdef/thingdef_states.cpp
|
thingdef/thingdef_states.cpp
|
||||||
|
|
|
@ -274,6 +274,7 @@ xx(MomZ)
|
||||||
xx(Abs)
|
xx(Abs)
|
||||||
xx(ACS_NamedExecuteWithResult)
|
xx(ACS_NamedExecuteWithResult)
|
||||||
xx(CallACS)
|
xx(CallACS)
|
||||||
|
xx(Sqrt)
|
||||||
|
|
||||||
// Various actor names which are used internally
|
// Various actor names which are used internally
|
||||||
xx(MapSpot)
|
xx(MapSpot)
|
||||||
|
|
|
@ -710,17 +710,41 @@ public:
|
||||||
|
|
||||||
class FxGlobalFunctionCall : public FxExpression
|
class FxGlobalFunctionCall : public FxExpression
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
typedef FxExpression *(*Creator)(FName, FArgumentList *, const FScriptPosition &);
|
||||||
|
struct CreatorAdder
|
||||||
|
{
|
||||||
|
CreatorAdder(FName methodname, Creator creator)
|
||||||
|
{
|
||||||
|
FxGlobalFunctionCall::AddCreator(methodname, creator);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static void AddCreator(FName methodname, Creator creator);
|
||||||
|
static FxExpression *StaticCreate(FName methodname, FArgumentList *args, const FScriptPosition &pos);
|
||||||
|
|
||||||
|
protected:
|
||||||
FName Name;
|
FName Name;
|
||||||
FArgumentList *ArgList;
|
FArgumentList *ArgList;
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
FxGlobalFunctionCall(FName fname, FArgumentList *args, const FScriptPosition &pos);
|
FxGlobalFunctionCall(FName fname, FArgumentList *args, const FScriptPosition &pos);
|
||||||
~FxGlobalFunctionCall();
|
~FxGlobalFunctionCall();
|
||||||
FxExpression *Resolve(FCompileContext&);
|
|
||||||
ExpVal EvalExpression (AActor *self);
|
FxExpression *ResolveArgs(FCompileContext &, unsigned min, unsigned max, bool numeric);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define GLOBALFUNCTION_DEFINE(CLASS) \
|
||||||
|
FxGlobalFunctionCall_##CLASS(FName methodname, FArgumentList *args, const FScriptPosition &pos) \
|
||||||
|
: FxGlobalFunctionCall(methodname, args, pos) {} \
|
||||||
|
static FxExpression *StaticCreate(FName methodname, FArgumentList *args, const FScriptPosition &pos) \
|
||||||
|
{return new FxGlobalFunctionCall_##CLASS(methodname, args, pos);}
|
||||||
|
|
||||||
|
#define GLOBALFUNCTION_ADDER(CLASS) GLOBALFUNCTION_ADDER_NAMED(CLASS, CLASS)
|
||||||
|
|
||||||
|
#define GLOBALFUNCTION_ADDER_NAMED(CLASS,NAME) \
|
||||||
|
static FxGlobalFunctionCall::CreatorAdder FxGlobalFunctionCall_##NAME##Adder \
|
||||||
|
(NAME_##NAME, FxGlobalFunctionCall_##CLASS::StaticCreate)
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
|
|
@ -2279,22 +2279,6 @@ FxFunctionCall::~FxFunctionCall()
|
||||||
|
|
||||||
FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
|
FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
|
||||||
{
|
{
|
||||||
// There's currently only 2 global functions.
|
|
||||||
// This will have to change later!
|
|
||||||
if (MethodName == NAME_Sin || MethodName == NAME_Cos)
|
|
||||||
{
|
|
||||||
if (Self != NULL)
|
|
||||||
{
|
|
||||||
ScriptPosition.Message(MSG_ERROR, "Global variables cannot have a self pointer");
|
|
||||||
delete this;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
FxExpression *x = new FxGlobalFunctionCall(MethodName, ArgList, ScriptPosition);
|
|
||||||
ArgList = NULL;
|
|
||||||
delete this;
|
|
||||||
return x->Resolve(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
int min, max, special;
|
int min, max, special;
|
||||||
if (MethodName == NAME_ACS_NamedExecuteWithResult || MethodName == NAME_CallACS)
|
if (MethodName == NAME_ACS_NamedExecuteWithResult || MethodName == NAME_CallACS)
|
||||||
{
|
{
|
||||||
|
@ -2328,6 +2312,19 @@ FxExpression *FxFunctionCall::Resolve(FCompileContext& ctx)
|
||||||
delete this;
|
delete this;
|
||||||
return x->Resolve(ctx);
|
return x->Resolve(ctx);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Self != NULL)
|
||||||
|
{
|
||||||
|
ScriptPosition.Message(MSG_ERROR, "Global variables cannot have a self pointer");
|
||||||
|
delete this;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
FxExpression *x = FxGlobalFunctionCall::StaticCreate(MethodName, ArgList, ScriptPosition);
|
||||||
|
ArgList = NULL;
|
||||||
|
delete this;
|
||||||
|
return x->Resolve(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
ScriptPosition.Message(MSG_ERROR, "Call to unknown function '%s'", MethodName.GetChars());
|
ScriptPosition.Message(MSG_ERROR, "Call to unknown function '%s'", MethodName.GetChars());
|
||||||
delete this;
|
delete this;
|
||||||
|
@ -2474,60 +2471,6 @@ FxGlobalFunctionCall::~FxGlobalFunctionCall()
|
||||||
SAFE_DELETE(ArgList);
|
SAFE_DELETE(ArgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
// // so far just a quick hack to handle sin and cos
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
FxExpression *FxGlobalFunctionCall::Resolve(FCompileContext& ctx)
|
|
||||||
{
|
|
||||||
CHECKRESOLVED();
|
|
||||||
|
|
||||||
if (ArgList == NULL || ArgList->Size() != 1)
|
|
||||||
{
|
|
||||||
ScriptPosition.Message(MSG_ERROR, "%s only has one parameter", Name.GetChars());
|
|
||||||
delete this;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*ArgList)[0] = (*ArgList)[0]->Resolve(ctx);
|
|
||||||
if ((*ArgList)[0] == NULL)
|
|
||||||
{
|
|
||||||
delete this;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(*ArgList)[0]->ValueType.isNumeric())
|
|
||||||
{
|
|
||||||
ScriptPosition.Message(MSG_ERROR, "numeric value expected for parameter");
|
|
||||||
delete this;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
ValueType = VAL_Float;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//==========================================================================
|
|
||||||
|
|
||||||
ExpVal FxGlobalFunctionCall::EvalExpression (AActor *self)
|
|
||||||
{
|
|
||||||
double v = (*ArgList)[0]->EvalExpression(self).GetFloat();
|
|
||||||
ExpVal ret;
|
|
||||||
ret.Type = VAL_Float;
|
|
||||||
|
|
||||||
// shall we use the CRT's sin and cos functions?
|
|
||||||
angle_t angle = angle_t(v * ANGLE_90/90.);
|
|
||||||
if (Name == NAME_Sin) ret.Float = FIXED2FLOAT (finesine[angle>>ANGLETOFINESHIFT]);
|
|
||||||
else ret.Float = FIXED2FLOAT (finecosine[angle>>ANGLETOFINESHIFT]);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
|
187
src/thingdef/thingdef_function.cpp
Normal file
187
src/thingdef/thingdef_function.cpp
Normal file
|
@ -0,0 +1,187 @@
|
||||||
|
/*
|
||||||
|
** thingdef_function.cpp
|
||||||
|
**
|
||||||
|
** Expression function evaluation.
|
||||||
|
**
|
||||||
|
**---------------------------------------------------------------------------
|
||||||
|
** Copyright 2012 David Hill
|
||||||
|
** All rights reserved.
|
||||||
|
**
|
||||||
|
** Redistribution and use in source and binary forms, with or without
|
||||||
|
** modification, are permitted provided that the following conditions
|
||||||
|
** are met:
|
||||||
|
**
|
||||||
|
** 1. Redistributions of source code must retain the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer.
|
||||||
|
** 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer in the
|
||||||
|
** documentation and/or other materials provided with the distribution.
|
||||||
|
** 3. The name of the author may not be used to endorse or promote products
|
||||||
|
** derived from this software without specific prior written permission.
|
||||||
|
** 4. When not used as part of ZDoom or a ZDoom derivative, this code will be
|
||||||
|
** covered by the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
** your option) any later version.
|
||||||
|
**
|
||||||
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
**---------------------------------------------------------------------------
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "tables.h"
|
||||||
|
#include "tarray.h"
|
||||||
|
#include "thingdef.h"
|
||||||
|
#include "thingdef_exp.h"
|
||||||
|
|
||||||
|
static TMap<FName, FxGlobalFunctionCall::Creator> CreatorMap;
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// FxGlobalFunctionCall::AddCreator
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
void FxGlobalFunctionCall::AddCreator(FName methodname, Creator creator)
|
||||||
|
{
|
||||||
|
CreatorMap.Insert(methodname, creator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// FxGlobalFunctionCall::ResolveArgs
|
||||||
|
//
|
||||||
|
// Handles common Resolve processing of args.
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
FxExpression *FxGlobalFunctionCall::ResolveArgs(FCompileContext &ctx, unsigned min, unsigned max, bool numeric)
|
||||||
|
{
|
||||||
|
unsigned i = ArgList ? ArgList->Size() : 0;
|
||||||
|
|
||||||
|
if (i < min || i > max)
|
||||||
|
{
|
||||||
|
ScriptPosition.Message(MSG_ERROR, "%s expects %u to %u parameters", Name.GetChars(), min, max);
|
||||||
|
delete this;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (i--)
|
||||||
|
{
|
||||||
|
if (!((*ArgList)[i] = (*ArgList)[i]->Resolve(ctx)))
|
||||||
|
{
|
||||||
|
delete this;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numeric && !(*ArgList)[i]->ValueType.isNumeric())
|
||||||
|
{
|
||||||
|
ScriptPosition.Message(MSG_ERROR, "numeric value expected for parameter");
|
||||||
|
delete this;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// FxGlobalFunctionCall::StaticCreate
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
FxExpression *FxGlobalFunctionCall::StaticCreate
|
||||||
|
(FName methodname, FArgumentList *args, const FScriptPosition &pos)
|
||||||
|
{
|
||||||
|
Creator *creator = CreatorMap.CheckKey(methodname);
|
||||||
|
|
||||||
|
if (!creator)
|
||||||
|
{
|
||||||
|
pos.Message(MSG_ERROR, "Call to unknown function '%s'", methodname.GetChars());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (*creator)(methodname, args, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// Function: cos/sin
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
class FxGlobalFunctionCall_Cos : public FxGlobalFunctionCall
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GLOBALFUNCTION_DEFINE(Cos);
|
||||||
|
|
||||||
|
FxExpression *Resolve(FCompileContext& ctx)
|
||||||
|
{
|
||||||
|
CHECKRESOLVED();
|
||||||
|
|
||||||
|
ValueType = VAL_Float;
|
||||||
|
return ResolveArgs(ctx, 1, 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpVal EvalExpression(AActor *self)
|
||||||
|
{
|
||||||
|
double v = (*ArgList)[0]->EvalExpression(self).GetFloat();
|
||||||
|
ExpVal ret;
|
||||||
|
ret.Type = VAL_Float;
|
||||||
|
|
||||||
|
// shall we use the CRT's sin and cos functions?
|
||||||
|
angle_t angle = angle_t(v * ANGLE_90/90.);
|
||||||
|
if (Name == NAME_Sin) ret.Float = FIXED2DBL (finesine[angle>>ANGLETOFINESHIFT]);
|
||||||
|
else ret.Float = FIXED2DBL (finecosine[angle>>ANGLETOFINESHIFT]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GLOBALFUNCTION_ADDER(Cos);
|
||||||
|
GLOBALFUNCTION_ADDER_NAMED(Cos, Sin);
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// Function: sqrt
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
class FxGlobalFunctionCall_Sqrt : public FxGlobalFunctionCall
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GLOBALFUNCTION_DEFINE(Sqrt);
|
||||||
|
|
||||||
|
FxExpression *Resolve(FCompileContext& ctx)
|
||||||
|
{
|
||||||
|
CHECKRESOLVED();
|
||||||
|
|
||||||
|
if (!ResolveArgs(ctx, 1, 1, true))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ValueType = VAL_Float;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpVal EvalExpression(AActor *self)
|
||||||
|
{
|
||||||
|
ExpVal ret;
|
||||||
|
ret.Type = VAL_Float;
|
||||||
|
ret.Float = sqrt((*ArgList)[0]->EvalExpression(self).GetFloat());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GLOBALFUNCTION_ADDER(Sqrt);
|
||||||
|
|
754
zdoom.vcproj
754
zdoom.vcproj
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue