- removed fixed_t and associated utility macros from FraggleScript code.

This commit is contained in:
Christoph Oelckers 2016-03-24 09:16:35 +01:00
parent 4a79602325
commit eac0bfeaeb
6 changed files with 34 additions and 48 deletions

View File

@ -165,7 +165,7 @@ void FS_EmulateCmd(char * string)
else if (sc.Compare("viewheight"))
{
sc.MustGetFloat();
double playerviewheight = sc.Float*FRACUNIT;
double playerviewheight = sc.Float;
for(int i=0;i<MAXPLAYERS;i++)
{
// No, this is not correct. But this is the way Legacy WADs expect it to be handled!

View File

@ -74,10 +74,6 @@
static FRandom pr_script("FScript");
#define AngleToFixed(x) ((((double) x) / ((double) ANG45/45)) * FRACUNIT)
#define FixedToAngle(x) ((((double) x) / FRACUNIT) * ANG45/45)
// functions. FParser::SF_ means Script Function not, well.. heh, me
/////////// actually running a function /////////////
@ -1420,9 +1416,7 @@ void FParser::SF_PointToDist(void)
// Doing this in floating point is actually faster with modern computers!
double x = floatvalue(t_argv[2]) - floatvalue(t_argv[0]);
double y = floatvalue(t_argv[3]) - floatvalue(t_argv[1]);
t_return.type = svt_fixed;
t_return.value.f = FLOAT2FIXED(g_sqrt(x*x+y*y));
t_return.setDouble(g_sqrt(x*x+y*y));
}
}
@ -2177,7 +2171,7 @@ void FParser::SF_OpenDoor(void)
if(t_argc > 2) speed = intvalue(t_argv[2]);
else speed = 1; // 1= normal speed
EV_DoDoor(wait_time? DDoor::doorRaise:DDoor::doorOpen,NULL,NULL,sectag,2*FRACUNIT*clamp(speed,1,127),wait_time,0,0);
EV_DoDoor(wait_time ? DDoor::doorRaise : DDoor::doorOpen, NULL, NULL, sectag, 2. * clamp(speed, 1, 127), wait_time, 0, 0);
}
}
@ -2202,7 +2196,7 @@ void FParser::SF_CloseDoor(void)
if(t_argc > 1) speed = intvalue(t_argv[1]);
else speed = 1; // 1= normal speed
EV_DoDoor(DDoor::doorClose,NULL,NULL,sectag,2*FRACUNIT*clamp(speed,1,127),0,0,0);
EV_DoDoor(DDoor::doorClose, NULL, NULL, sectag, 2.*clamp(speed, 1, 127), 0, 0, 0);
}
}
@ -2416,12 +2410,10 @@ void FParser::SF_SetLineTexture(void)
void FParser::SF_Max(void)
{
fixed_t n1, n2;
if (CheckArgs(2))
{
n1 = fixedvalue(t_argv[0]);
n2 = fixedvalue(t_argv[1]);
auto n1 = fixedvalue(t_argv[0]);
auto n2 = fixedvalue(t_argv[1]);
t_return.type = svt_fixed;
t_return.value.f = (n1 > n2) ? n1 : n2;
@ -2437,12 +2429,10 @@ void FParser::SF_Max(void)
void FParser::SF_Min(void)
{
fixed_t n1, n2;
if (CheckArgs(1))
{
n1 = fixedvalue(t_argv[0]);
n2 = fixedvalue(t_argv[1]);
auto n1 = fixedvalue(t_argv[0]);
auto n2 = fixedvalue(t_argv[1]);
t_return.type = svt_fixed;
t_return.value.f = (n1 < n2) ? n1 : n2;
@ -2458,11 +2448,10 @@ void FParser::SF_Min(void)
void FParser::SF_Abs(void)
{
fixed_t n1;
if (CheckArgs(1))
{
n1 = fixedvalue(t_argv[0]);
auto n1 = fixedvalue(t_argv[0]);
t_return.type = svt_fixed;
t_return.value.f = (n1 < 0) ? -n1 : n1;
@ -3877,10 +3866,9 @@ void FParser::SF_SetCorona(void)
return;
}
int num = t_argv[0].value.i; // which corona we want to modify
int what = t_argv[1].value.i; // what we want to modify (type, color, offset,...)
int ival = t_argv[2].value.i; // the value of what we modify
double fval = ((double) t_argv[2].value.f / FRACUNIT);
int num = intvalue(t_argv[0]); // which corona we want to modify
int what = intvalue(t_argv[1]); // what we want to modify (type, color, offset,...)
double val = floatvalue(t_argv[2]); // the value of what we modify
/*
switch (what)

View File

@ -384,9 +384,9 @@ void FParser::OPdivide(svalue_t &result, int start, int n, int stop)
// haleyjd: 8-17
if(left.type == svt_fixed || right.type == svt_fixed)
{
fixed_t fr;
auto fr = fixedvalue(right);
if((fr = fixedvalue(right)) == 0)
if(fr == 0)
script_error("divide by zero\n");
else
{
@ -396,9 +396,9 @@ void FParser::OPdivide(svalue_t &result, int start, int n, int stop)
}
else
{
int ir;
auto ir = intvalue(right);
if(!(ir = intvalue(right)))
if(!ir)
script_error("divide by zero\n");
else
{
@ -508,8 +508,7 @@ void FParser::OPincrement(svalue_t &result, int start, int n, int stop)
}
else
{
result.value.f = fixedvalue(result) + FRACUNIT;
result.type = svt_fixed;
result.setDouble(floatvalue(result)+1);
var->SetValue (result);
}
}
@ -534,8 +533,7 @@ void FParser::OPincrement(svalue_t &result, int start, int n, int stop)
}
else
{
newvalue.type = svt_fixed;
newvalue.value.f = fixedvalue(result) + FRACUNIT;
newvalue.setDouble(floatvalue(result)+1);
var->SetValue (newvalue);
}
}
@ -573,7 +571,7 @@ void FParser::OPdecrement(svalue_t &result, int start, int n, int stop)
}
else
{
result.value.f = fixedvalue(result) - FRACUNIT;
result.setDouble(floatvalue(result)-1);
result.type = svt_fixed;
var->SetValue (result);
}
@ -599,8 +597,7 @@ void FParser::OPdecrement(svalue_t &result, int start, int n, int stop)
}
else
{
newvalue.type = svt_fixed;
newvalue.value.f = fixedvalue(result) - FRACUNIT;
newvalue.setDouble(floatvalue(result)-1);
var->SetValue (newvalue);
}
}

View File

@ -567,8 +567,7 @@ void FParser::SimpleEvaluate(svalue_t &returnvar, int n)
case number:
if(strchr(Tokens[n], '.'))
{
returnvar.type = svt_fixed;
returnvar.value.f = (fixed_t)(atof(Tokens[n]) * FRACUNIT);
returnvar.setDouble(atof(Tokens[n]));
}
else
{

View File

@ -82,15 +82,17 @@ enum
//
//
//==========================================================================
typedef int fsfix;
struct svalue_t
{
int type;
FString string;
union
{
int i;
fixed_t f; // haleyjd: 8-17
fsfix f; // haleyjd: 8-17
AActor *mobj;
} value;
@ -113,7 +115,7 @@ struct svalue_t
type = svt_int;
}
void setFixed(fixed_t fp)
void setFixed(fsfix fp)
{
value.f = fp;
type = svt_fixed;
@ -121,13 +123,13 @@ struct svalue_t
void setDouble(double dp)
{
value.f = FLOAT2FIXED(dp);
value.f = fsfix(dp/65536);
type = svt_fixed;
}
};
int intvalue(const svalue_t & v);
fixed_t fixedvalue(const svalue_t & v);
fsfix fixedvalue(const svalue_t & v);
double floatvalue(const svalue_t & v);
const char *stringvalue(const svalue_t & v);
AActor *actorvalue(const svalue_t &svalue);
@ -171,7 +173,7 @@ public:
union value_t
{
SDWORD i;
fixed_t fixed; // haleyjd: fixed-point
fsfix fixed; // haleyjd: fixed-point
// the following are only used in the global script so we don't need to bother with them
// when serializing variables.

View File

@ -66,7 +66,7 @@
int intvalue(const svalue_t &v)
{
return (v.type == svt_string ? atoi(v.string) :
v.type == svt_fixed ? (int)(v.value.f / FRACUNIT) :
v.type == svt_fixed ? (int)(v.value.f / 65536.) :
v.type == svt_mobj ? -1 : v.value.i );
}
@ -76,11 +76,11 @@ int intvalue(const svalue_t &v)
//
//==========================================================================
fixed_t fixedvalue(const svalue_t &v)
fsfix fixedvalue(const svalue_t &v)
{
return (v.type == svt_fixed ? v.value.f :
v.type == svt_string ? (fixed_t)(atof(v.string) * FRACUNIT) :
v.type == svt_mobj ? -1*FRACUNIT : v.value.i * FRACUNIT );
v.type == svt_string ? (fsfix)(atof(v.string) * 65536.) :
v.type == svt_mobj ? -65536 : v.value.i * 65536 );
}
//==========================================================================
@ -93,7 +93,7 @@ double floatvalue(const svalue_t &v)
{
return
v.type == svt_string ? atof(v.string) :
v.type == svt_fixed ? FIXED2DBL(v.value.f) :
v.type == svt_fixed ? v.value.f * 65536. :
v.type == svt_mobj ? -1. : (double)v.value.i;
}
@ -118,7 +118,7 @@ const char *stringvalue(const svalue_t & v)
case svt_fixed:
{
double val = ((double)v.value.f) / FRACUNIT;
double val = v.value.f / 65536.;
mysnprintf(buffer, countof(buffer), "%g", val);
return buffer;
}