- some floating point changes in t_func.cpp

This commit is contained in:
Christoph Oelckers 2016-03-22 01:12:38 +01:00
parent cf79e1cb6d
commit f3d6ca04fc
2 changed files with 42 additions and 47 deletions

View File

@ -1049,6 +1049,10 @@ public:
SetOrigin(npos.x, npos.y, npos.z, moving); SetOrigin(npos.x, npos.y, npos.z, moving);
} }
void SetOrigin(double x, double y, double z, bool moving)
{
SetOrigin(FLOAT2FIXED(x), FLOAT2FIXED(y), FLOAT2FIXED(z), moving);
}
void SetOrigin(const DVector3 & npos, bool moving) void SetOrigin(const DVector3 & npos, bool moving)
{ {
SetOrigin(FLOAT2FIXED(npos.X), FLOAT2FIXED(npos.Y), FLOAT2FIXED(npos.Z), moving); SetOrigin(FLOAT2FIXED(npos.X), FLOAT2FIXED(npos.Y), FLOAT2FIXED(npos.Z), moving);

View File

@ -1396,15 +1396,12 @@ void FParser::SF_PointToAngle(void)
{ {
if (CheckArgs(4)) if (CheckArgs(4))
{ {
fixed_t x1 = fixedvalue(t_argv[0]); double x1 = floatvalue(t_argv[0]);
fixed_t y1 = fixedvalue(t_argv[1]); double y1 = floatvalue(t_argv[1]);
fixed_t x2 = fixedvalue(t_argv[2]); double x2 = floatvalue(t_argv[2]);
fixed_t y2 = fixedvalue(t_argv[3]); double y2 = floatvalue(t_argv[3]);
angle_t angle = R_PointToAngle2(x1, y1, x2, y2); t_return.setDouble(DVector2(x2 - x1, y2 - y1).Angle().BAMs);
t_return.type = svt_fixed;
t_return.value.f = (fixed_t)AngleToFixed(angle);
} }
} }
@ -3062,8 +3059,7 @@ void FParser::SF_MoveCamera(void)
fixed_t x, y, z; fixed_t x, y, z;
fixed_t zdist, xydist, movespeed; fixed_t zdist, xydist, movespeed;
fixed_t xstep, ystep, zstep, targetheight; fixed_t xstep, ystep, zstep, targetheight;
angle_t anglespeed, anglestep, angledist, targetangle, angle_t anglespeed, anglestep, angledist, targetangle, bigangle, smallangle;
bigangle, smallangle;
DAngle mobjangle; DAngle mobjangle;
// I have to use floats for the math where angles are divided // I have to use floats for the math where angles are divided
@ -3080,21 +3076,27 @@ void FParser::SF_MoveCamera(void)
if (CheckArgs(6)) if (CheckArgs(6))
{ {
cam = actorvalue(t_argv[0]); cam = actorvalue(t_argv[0]);
target = actorvalue(t_argv[1]); target = actorvalue(t_argv[1]);
if(!cam || !target) if(!cam || !target)
{ {
script_error("invalid target for camera\n"); return; script_error("invalid target for camera\n"); return;
} }
DVector2 fdist = cam->Vec2To(target);
fixed_t distx = FLOAT2FIXED(fdist.X);
fixed_t disty = FLOAT2FIXED(fdist.Y);
fixed_t camx = FLOAT2FIXED(cam->X());
fixed_t camy = FLOAT2FIXED(cam->Y());
fixed_t camz = FLOAT2FIXED(cam->Z());
targetheight = fixedvalue(t_argv[2]); targetheight = fixedvalue(t_argv[2]);
movespeed = fixedvalue(t_argv[3]); movespeed = fixedvalue(t_argv[3]);
targetangle = (angle_t)FixedToAngle(fixedvalue(t_argv[4])); targetangle = (angle_t)FixedToAngle(fixedvalue(t_argv[4]));
anglespeed = (angle_t)FixedToAngle(fixedvalue(t_argv[5])); anglespeed = (angle_t)FixedToAngle(fixedvalue(t_argv[5]));
// figure out how big one step will be // figure out how big one step will be
fixedvec2 dist = cam->_f_Vec2To(target); zdist = targetheight - camz;
zdist = targetheight - cam->_f_Z();
// Angle checking... // Angle checking...
// 90 // 90
@ -3166,19 +3168,19 @@ void FParser::SF_MoveCamera(void)
else else
anglestep = anglespeed; anglestep = anglespeed;
if(abs(xstep) >= (abs(dist.x) - 1)) if(abs(xstep) >= (abs(distx) - 1))
x = cam->_f_X() + dist.x; x = camx + distx;
else else
{ {
x = cam->_f_X() + xstep; x = camx + xstep;
moved = 1; moved = 1;
} }
if(abs(ystep) >= (abs(dist.y) - 1)) if(abs(ystep) >= (abs(disty) - 1))
y = cam->_f_Y() + dist.y; y = camy + disty;
else else
{ {
y = cam->_f_Y() + ystep; y = camy + ystep;
moved = 1; moved = 1;
} }
@ -3186,7 +3188,7 @@ void FParser::SF_MoveCamera(void)
z = targetheight; z = targetheight;
else else
{ {
z = cam->_f_Z() + zstep; z = camz + zstep;
moved = 1; moved = 1;
} }
@ -3208,12 +3210,12 @@ void FParser::SF_MoveCamera(void)
cam->radius = 1 / 8192.; cam->radius = 1 / 8192.;
cam->Height = 1 / 8192.; cam->Height = 1 / 8192.;
if ((x != cam->_f_X() || y != cam->_f_Y()) && !P_TryMove(cam, x, y, true)) if ((x != camx || y != camy) && !P_TryMove(cam, FIXED2FLOAT(x), FIXED2FLOAT(y), true))
{ {
Printf("Illegal camera move to (%f, %f)\n", x/65536.f, y/65536.f); Printf("Illegal camera move to (%f, %f)\n", x/65536.f, y/65536.f);
return; return;
} }
cam->_f_SetZ(z); cam->SetZ(FIXED2FLOAT(z));
t_return.type = svt_int; t_return.type = svt_int;
t_return.value.i = moved; t_return.value.i = moved;
@ -3407,9 +3409,9 @@ void FParser::SF_SetObjPosition()
if (!mobj) return; if (!mobj) return;
mobj->SetOrigin( mobj->SetOrigin(
fixedvalue(t_argv[1]), floatvalue(t_argv[1]),
(t_argc >= 3)? fixedvalue(t_argv[2]) : mobj->_f_Y(), (t_argc >= 3)? floatvalue(t_argv[2]) : mobj->Y(),
(t_argc >= 4)? fixedvalue(t_argv[3]) : mobj->_f_Z(), false); (t_argc >= 4)? floatvalue(t_argv[3]) : mobj->Z(), false);
} }
} }
@ -3819,8 +3821,7 @@ void FParser::SF_Sin()
{ {
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.setDouble(g_sin(floatvalue(t_argv[0])));
t_return.value.f = FLOAT2FIXED(g_sin(floatvalue(t_argv[0])));
} }
} }
@ -3829,8 +3830,7 @@ void FParser::SF_ASin()
{ {
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.setDouble(g_asin(floatvalue(t_argv[0])));
t_return.value.f = FLOAT2FIXED(g_asin(floatvalue(t_argv[0])));
} }
} }
@ -3839,8 +3839,7 @@ void FParser::SF_Cos()
{ {
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.setDouble(g_cos(floatvalue(t_argv[0])));
t_return.value.f = FLOAT2FIXED(g_cos(floatvalue(t_argv[0])));
} }
} }
@ -3849,8 +3848,7 @@ void FParser::SF_ACos()
{ {
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.setDouble(g_acos(floatvalue(t_argv[0])));
t_return.value.f = FLOAT2FIXED(g_acos(floatvalue(t_argv[0])));
} }
} }
@ -3859,9 +3857,7 @@ void FParser::SF_Tan()
{ {
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.setDouble(g_tan(floatvalue(t_argv[0])));
t_return.value.f = FLOAT2FIXED(
g_tan(floatvalue(t_argv[0])));
} }
} }
@ -3870,8 +3866,7 @@ void FParser::SF_ATan()
{ {
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.setDouble(g_atan(floatvalue(t_argv[0])));
t_return.value.f = FLOAT2FIXED(g_atan(floatvalue(t_argv[0])));
} }
} }
@ -3880,8 +3875,7 @@ void FParser::SF_Exp()
{ {
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.setDouble(g_exp(floatvalue(t_argv[0])));
t_return.value.f = FLOAT2FIXED(g_exp(floatvalue(t_argv[0])));
} }
} }
@ -3889,8 +3883,7 @@ void FParser::SF_Log()
{ {
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.setDouble(g_log(floatvalue(t_argv[0])));
t_return.value.f = FLOAT2FIXED(g_log(floatvalue(t_argv[0])));
} }
} }
@ -3899,8 +3892,7 @@ void FParser::SF_Sqrt()
{ {
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.setDouble(g_sqrt(floatvalue(t_argv[0])));
t_return.value.f = FLOAT2FIXED(g_sqrt(floatvalue(t_argv[0])));
} }
} }
@ -3910,7 +3902,7 @@ void FParser::SF_Floor()
if (CheckArgs(1)) if (CheckArgs(1))
{ {
t_return.type = svt_fixed; t_return.type = svt_fixed;
t_return.value.f = fixedvalue(t_argv[0]) & 0xffFF0000; t_return.value.f = fixedvalue(t_argv[0]) & 0xffff0000;
} }
} }
@ -3919,8 +3911,7 @@ void FParser::SF_Pow()
{ {
if (CheckArgs(2)) if (CheckArgs(2))
{ {
t_return.type = svt_fixed; t_return.setDouble(pow(floatvalue(t_argv[0]), floatvalue(t_argv[1])));
t_return.value.f = FLOAT2FIXED(pow(floatvalue(t_argv[0]), floatvalue(t_argv[1])));
} }
} }