--- a/hedgewars/GSHandlers.inc Sun Aug 06 17:11:33 2006 +0000
+++ b/hedgewars/GSHandlers.inc Sun Aug 06 20:08:15 2006 +0000
@@ -459,7 +459,7 @@
if not TestCollisionYwithGear(HHGear, 1) then HHGear.dY:= HHGear.dY + cGravity;
-HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX);
+HHGear.DirAngle:= arctan2(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX);
cs:= sin(HHGear.DirAngle);
cc:= cos(HHGear.DirAngle);
@@ -509,7 +509,7 @@
Gear.dX:= HHGear.X - Gear.X;
Gear.dY:= HHGear.Y - Gear.Y;
-HHGear.DirAngle:= arctan(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX);
+HHGear.DirAngle:= arctan2(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX);
cs:= sin(HHGear.DirAngle);
cc:= cos(HHGear.DirAngle);
--- a/hedgewars/uAIMisc.pas Sun Aug 06 17:11:33 2006 +0000
+++ b/hedgewars/uAIMisc.pas Sun Aug 06 20:08:15 2006 +0000
@@ -55,7 +55,6 @@
procedure FillBonuses(isAfterAttack: boolean);
procedure AwareOfExplosion(x, y, r: integer);
function RatePlace(Gear: PGear): integer;
-function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
function TestColl(x, y, r: integer): boolean;
function RateExplosion(Me: PGear; x, y, r: integer): integer;
function RateShove(Me: PGear; x, y, r, power: integer): integer;
@@ -168,19 +167,6 @@
end;
end;
-function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
-const piDIVMaxAngle: Extended = pi/cMaxAngle;
-asm
- fld _dY
- fld _dX
- fpatan
- fld piDIVMaxAngle
- fdiv
- sub esp, 4
- fistp dword ptr [esp]
- pop eax
-end;
-
function TestColl(x, y, r: integer): boolean;
begin
Result:=(((x-r) and $FFFFF800) = 0)and(((y-r) and $FFFFFC00) = 0) and (Land[y-r, x-r] <> 0);
--- a/hedgewars/uGears.pas Sun Aug 06 17:11:33 2006 +0000
+++ b/hedgewars/uGears.pas Sun Aug 06 20:08:15 2006 +0000
@@ -79,7 +79,7 @@
implementation
uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions,
- uLand, uIO, uLandGraphics, uAIMisc, uLocale;
+ uLand, uIO, uLandGraphics, uAIMisc, uLocale{$IFDEF FPC}, Math{$ENDIF};
var RopePoints: record
Count: Longword;
HookAngle: integer;
--- a/hedgewars/uMisc.pas Sun Aug 06 17:11:33 2006 +0000
+++ b/hedgewars/uMisc.pas Sun Aug 06 20:08:15 2006 +0000
@@ -105,19 +105,22 @@
procedure SDLTry(Assert: boolean; isFatal: boolean);
function IntToStr(n: integer): shortstring;
function FloatToStr(n: real): shortstring;
-function arctan(const Y, X: real): real;
function DxDy2Angle32(const _dY, _dX: Extended): integer;
+function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
procedure AdjustColor(var Color: Longword);
{$IFDEF DEBUGFILE}
procedure AddFileLog(s: shortstring);
function RectToStr(Rect: TSDL_Rect): shortstring;
{$ENDIF}
+{$IFNDEF FPC}
+function arctan2(const Y, X: real): real;
+{$ENDIF}
var CursorPoint: TPoint;
TargetPoint: TPoint = (X: NoPointX; Y: 0);
implementation
-uses uConsole, uStore, uIO;
+uses uConsole, uStore, uIO{$IFDEF FPC}, Math{$ENDIF};
{$IFDEF DEBUGFILE}
var f: textfile;
{$ENDIF}
@@ -175,29 +178,27 @@
str(n:5:5, Result)
end;
-function arctan(const Y, X: real): real;
+{$IFNDEF FPC}
+function arctan2(const Y, X: real): real;
asm
fld Y
fld X
fpatan
fwait
end;
+{$ENDIF}
function DxDy2Angle32(const _dY, _dX: Extended): integer;
-const piDIV32: Extended = pi/32;
-asm
- fld _dY
- fld _dX
- fpatan
- fld piDIV32
- fdiv
- sub esp, 4
- fistp dword ptr [esp]
- pop eax
- shr eax, 1
- and eax, $1F
+const _16divPI: Extended = 16/pi;
+begin
+Result:= trunc(arctan2(_dY, _dX) * _16divPI) and $1f
end;
+function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
+const MaxAngleDivPI: Extended = cMaxAngle/pi;
+begin
+Result:= trunc(arctan2(_dY, _dX) * MaxAngleDivPI) mod cMaxAngle
+end;
{$IFDEF DEBUGFILE}
procedure AddFileLog(s: shortstring);
--- a/hedgewars/uSHA.pas Sun Aug 06 17:11:33 2006 +0000
+++ b/hedgewars/uSHA.pas Sun Aug 06 20:08:15 2006 +0000
@@ -52,15 +52,14 @@
implementation
-function _bswap(X: LongWord): LongWord; assembler;
-asm
- bswap eax
+function _bswap(X: LongWord): LongWord;
+begin
+ Result:= (X shr 24) or ((X shr 8) and $FF00) or ((X shl 8) and $FF0000) or (X shl 24)
end;
-function rol(x: LongWord; y: Byte): LongWord; assembler;
-asm
- mov cl,dl
- rol eax,cl
+function rol(x: LongWord; y: Byte): LongWord;
+begin
+ Result:= (X shl y) or (X shr (32 - y))
end;
function Ft(t, b, c, d: LongWord): LongWord;