hedgewars/uMisc.pas
changeset 100 f324a18698fe
parent 95 1ef5e2c41115
child 107 b08ce0293a51
equal deleted inserted replaced
99:fd9613278d1b 100:f324a18698fe
   103 procedure OutError(Msg: String; const isFatalError: boolean=false);
   103 procedure OutError(Msg: String; const isFatalError: boolean=false);
   104 procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean);
   104 procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean);
   105 procedure SDLTry(Assert: boolean; isFatal: boolean);
   105 procedure SDLTry(Assert: boolean; isFatal: boolean);
   106 function IntToStr(n: integer): shortstring;
   106 function IntToStr(n: integer): shortstring;
   107 function FloatToStr(n: real): shortstring;
   107 function FloatToStr(n: real): shortstring;
   108 function arctan(const Y, X: real): real;
       
   109 function DxDy2Angle32(const _dY, _dX: Extended): integer;
   108 function DxDy2Angle32(const _dY, _dX: Extended): integer;
       
   109 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
   110 procedure AdjustColor(var Color: Longword);
   110 procedure AdjustColor(var Color: Longword);
   111 {$IFDEF DEBUGFILE}
   111 {$IFDEF DEBUGFILE}
   112 procedure AddFileLog(s: shortstring);
   112 procedure AddFileLog(s: shortstring);
   113 function RectToStr(Rect: TSDL_Rect): shortstring;
   113 function RectToStr(Rect: TSDL_Rect): shortstring;
   114 {$ENDIF}
   114 {$ENDIF}
       
   115 {$IFNDEF FPC}
       
   116 function arctan2(const Y, X: real): real;
       
   117 {$ENDIF}
   115 
   118 
   116 var CursorPoint: TPoint;
   119 var CursorPoint: TPoint;
   117     TargetPoint: TPoint = (X: NoPointX; Y: 0);
   120     TargetPoint: TPoint = (X: NoPointX; Y: 0);
   118 
   121 
   119 implementation
   122 implementation
   120 uses uConsole, uStore, uIO;
   123 uses uConsole, uStore, uIO{$IFDEF FPC}, Math{$ENDIF};
   121 {$IFDEF DEBUGFILE}
   124 {$IFDEF DEBUGFILE}
   122 var f: textfile;
   125 var f: textfile;
   123 {$ENDIF}
   126 {$ENDIF}
   124 
   127 
   125 
   128 
   173 function FloatToStr(n: real): shortstring;
   176 function FloatToStr(n: real): shortstring;
   174 begin
   177 begin
   175 str(n:5:5, Result)
   178 str(n:5:5, Result)
   176 end;
   179 end;
   177 
   180 
   178 function arctan(const Y, X: real): real;
   181 {$IFNDEF FPC}
       
   182 function arctan2(const Y, X: real): real;
   179 asm
   183 asm
   180         fld     Y
   184         fld     Y
   181         fld     X
   185         fld     X
   182         fpatan
   186         fpatan
   183         fwait
   187         fwait
   184 end;
   188 end;
       
   189 {$ENDIF}
   185 
   190 
   186 function DxDy2Angle32(const _dY, _dX: Extended): integer;
   191 function DxDy2Angle32(const _dY, _dX: Extended): integer;
   187 const piDIV32: Extended = pi/32;
   192 const _16divPI: Extended = 16/pi;
   188 asm
   193 begin
   189         fld     _dY
   194 Result:= trunc(arctan2(_dY, _dX) * _16divPI) and $1f
   190         fld     _dX
   195 end;
   191         fpatan
   196 
   192         fld     piDIV32
   197 function DxDy2AttackAngle(const _dY, _dX: Extended): integer;
   193         fdiv
   198 const MaxAngleDivPI: Extended = cMaxAngle/pi;
   194         sub     esp, 4
   199 begin
   195         fistp   dword ptr [esp]
   200 Result:= trunc(arctan2(_dY, _dX) * MaxAngleDivPI) mod cMaxAngle
   196         pop     eax
   201 end;
   197         shr     eax, 1
       
   198         and     eax, $1F
       
   199 end;
       
   200 
       
   201 
   202 
   202 {$IFDEF DEBUGFILE}
   203 {$IFDEF DEBUGFILE}
   203 procedure AddFileLog(s: shortstring);
   204 procedure AddFileLog(s: shortstring);
   204 begin
   205 begin
   205 writeln(f, GameTicks: 6, ': ', s);
   206 writeln(f, GameTicks: 6, ': ', s);