From eac0bfeaebe7f06d5c75f4d907a9bfc69be4c046 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 24 Mar 2016 09:16:35 +0100 Subject: [PATCH] - removed fixed_t and associated utility macros from FraggleScript code. --- src/fragglescript/t_cmd.cpp | 2 +- src/fragglescript/t_func.cpp | 34 +++++++++++--------------------- src/fragglescript/t_oper.cpp | 19 ++++++++---------- src/fragglescript/t_parse.cpp | 3 +-- src/fragglescript/t_script.h | 12 ++++++----- src/fragglescript/t_variable.cpp | 12 +++++------ 6 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/fragglescript/t_cmd.cpp b/src/fragglescript/t_cmd.cpp index c5f77776f..1434870d1 100644 --- a/src/fragglescript/t_cmd.cpp +++ b/src/fragglescript/t_cmd.cpp @@ -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 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) diff --git a/src/fragglescript/t_oper.cpp b/src/fragglescript/t_oper.cpp index 31673eb54..5a2092369 100644 --- a/src/fragglescript/t_oper.cpp +++ b/src/fragglescript/t_oper.cpp @@ -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); } } diff --git a/src/fragglescript/t_parse.cpp b/src/fragglescript/t_parse.cpp index 64dc3fb52..0b2f27680 100644 --- a/src/fragglescript/t_parse.cpp +++ b/src/fragglescript/t_parse.cpp @@ -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 { diff --git a/src/fragglescript/t_script.h b/src/fragglescript/t_script.h index 0cbeb446f..39b0b93ee 100644 --- a/src/fragglescript/t_script.h +++ b/src/fragglescript/t_script.h @@ -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. diff --git a/src/fragglescript/t_variable.cpp b/src/fragglescript/t_variable.cpp index 09cdf950f..7fd39aa14 100644 --- a/src/fragglescript/t_variable.cpp +++ b/src/fragglescript/t_variable.cpp @@ -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; }