hedgewars/uUtils.pas
branchtransitional_engine
changeset 15900 128ace913837
parent 15875 d7b53d08ad9c
child 15975 2146cb7be36f
equal deleted inserted replaced
15899:73cdc306888f 15900:128ace913837
    46 function  EnumToStr(const en : TCapGroup) : shortstring; overload;
    46 function  EnumToStr(const en : TCapGroup) : shortstring; overload;
    47 function  EnumToStr(const en : TSprite) : shortstring; overload;
    47 function  EnumToStr(const en : TSprite) : shortstring; overload;
    48 function  EnumToStr(const en : TMapGen) : shortstring; overload;
    48 function  EnumToStr(const en : TMapGen) : shortstring; overload;
    49 function  EnumToStr(const en : TWorldEdge) : shortstring; overload;
    49 function  EnumToStr(const en : TWorldEdge) : shortstring; overload;
    50 
    50 
    51 function  Min(a, b: LongInt): LongInt; inline;
    51 function  Min(a, b: LongInt): LongInt; 
    52 function  MinD(a, b: double) : double; inline;
    52 function  MinD(a, b: double) : double; 
    53 function  Max(a, b: LongInt): LongInt; inline;
    53 function  Max(a, b: LongInt): LongInt; 
    54 
    54 
    55 function  IntToStr(n: LongInt): shortstring;
    55 function  IntToStr(n: LongInt): shortstring;
    56 function  StrToInt(s: shortstring): LongInt;
    56 function  StrToInt(s: shortstring): LongInt;
    57 //function  StrToInt(s: shortstring; var success: boolean): LongInt;
    57 //function  StrToInt(s: shortstring; var success: boolean): LongInt;
    58 function  FloatToStr(n: hwFloat): shortstring;
    58 function  FloatToStr(n: hwFloat): shortstring;
    59 
    59 
    60 function  DxDy2Angle(const _dY, _dX: hwFloat): real; inline;
    60 function  DxDy2Angle(const _dY, _dX: hwFloat): real; 
    61 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
    61 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
    62 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
    62 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
    63 function  DxDy2AttackAnglef(const _dY, _dX: extended): LongInt;
    63 function  DxDy2AttackAnglef(const _dY, _dX: extended): LongInt;
    64 
    64 
    65 procedure SetLittle(var r: hwFloat);
    65 procedure SetLittle(var r: hwFloat);
    66 
    66 
    67 function  Str2PChar(const s: shortstring): PChar;
    67 function  Str2PChar(const s: shortstring): PChar;
    68 function  DecodeBase64(s: shortstring): shortstring;
    68 function  DecodeBase64(s: shortstring): shortstring;
    69 
    69 
    70 function  isPowerOf2(i: Longword): boolean;
    70 function  isPowerOf2(i: Longword): boolean;
    71 function  toPowerOf2(i: Longword): Longword; inline;
    71 function  toPowerOf2(i: Longword): Longword; 
    72 
    72 
    73 function  endian(independent: LongWord): LongWord; inline;
    73 function  endian(independent: LongWord): LongWord; 
    74 
    74 
    75 function  CheckCJKFont(s: ansistring; font: THWFont): THWFont;
    75 function  CheckCJKFont(s: ansistring; font: THWFont): THWFont;
    76 
    76 
    77 procedure AddFileLog(s: shortstring);
    77 procedure AddFileLog(s: shortstring);
    78 procedure AddFileLogRaw(s: pchar); cdecl;
    78 procedure AddFileLogRaw(s: pchar); cdecl;
    79 
    79 
    80 function  CheckNoTeamOrHH: boolean; inline;
    80 function  CheckNoTeamOrHH: boolean; 
    81 
    81 
    82 function  GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt;
    82 function  GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt;
    83 function  GetLaunchY(at: TAmmoType; angle: LongInt): LongInt;
    83 function  GetLaunchY(at: TAmmoType; angle: LongInt): LongInt;
    84 
    84 
    85 function CalcWorldWrap(X, radius: LongInt): LongInt;
    85 function CalcWorldWrap(X, radius: LongInt): LongInt;
    95 procedure WriteLn(var f: textfile; s: shortstring);
    95 procedure WriteLn(var f: textfile; s: shortstring);
    96 function StrLength(s: PChar): Longword;
    96 function StrLength(s: PChar): Longword;
    97 procedure SetLengthA(var s: ansistring; len: Longword);
    97 procedure SetLengthA(var s: ansistring; len: Longword);
    98 {$ENDIF}
    98 {$ENDIF}
    99 
    99 
   100 function  isPhone: Boolean; inline;
   100 function  isPhone: Boolean; 
   101 
   101 
   102 {$IFDEF IPHONEOS}
   102 {$IFDEF IPHONEOS}
   103 procedure startLoadingIndicator; cdecl; external;
   103 procedure startLoadingIndicator; cdecl; external;
   104 procedure stopLoadingIndicator; cdecl; external;
   104 procedure stopLoadingIndicator; cdecl; external;
   105 procedure saveFinishedSynching; cdecl; external;
   105 procedure saveFinishedSynching; cdecl; external;
   405 begin
   405 begin
   406 FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue))
   406 FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue))
   407 end;
   407 end;
   408 
   408 
   409 
   409 
   410 function DxDy2Angle(const _dY, _dX: hwFloat): real; inline;
   410 function DxDy2Angle(const _dY, _dX: hwFloat): real; 
   411 var dY, dX: Extended;
   411 var dY, dX: Extended;
   412 begin
   412 begin
   413 dY:= hwFloat2Float(_dY);
   413 dY:= hwFloat2Float(_dY);
   414 dX:= hwFloat2Float(_dX);
   414 dX:= hwFloat2Float(_dX);
   415 DxDy2Angle:= arctan2(dY, dX) * 180 / pi
   415 DxDy2Angle:= arctan2(dY, dX) * 180 / pi
   431 dY:= hwFloat2Float(_dY);
   431 dY:= hwFloat2Float(_dY);
   432 dX:= hwFloat2Float(_dX);
   432 dX:= hwFloat2Float(_dX);
   433 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   433 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   434 end;
   434 end;
   435 
   435 
   436 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; inline;
   436 function DxDy2AttackAnglef(const _dY, _dX: extended): LongInt; 
   437 begin
   437 begin
   438 DxDy2AttackAnglef:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
   438 DxDy2AttackAnglef:= trunc(arctan2(_dY, _dX) * (cMaxAngle/pi))
   439 end;
   439 end;
   440 
   440 
   441 
   441 
   501    CharArray[Length(s)]:= #0;
   501    CharArray[Length(s)]:= #0;
   502    Str2PChar:= @(CharArray[0]);
   502    Str2PChar:= @(CharArray[0]);
   503 end;
   503 end;
   504 
   504 
   505 
   505 
   506 function endian(independent: LongWord): LongWord; inline;
   506 function endian(independent: LongWord): LongWord; 
   507 begin
   507 begin
   508 {$IFDEF ENDIAN_LITTLE}
   508 {$IFDEF ENDIAN_LITTLE}
   509 endian:= independent;
   509 endian:= independent;
   510 {$ELSE}
   510 {$ELSE}
   511 endian:= (((independent and $FF000000) shr 24) or
   511 endian:= (((independent and $FF000000) shr 24) or
   678     StrLength:= length(s)
   678     StrLength:= length(s)
   679 end;
   679 end;
   680 {$ENDIF}
   680 {$ENDIF}
   681 
   681 
   682 // this function is just to determine whether we are running on a limited screen device
   682 // this function is just to determine whether we are running on a limited screen device
   683 function isPhone: Boolean; inline;
   683 function isPhone: Boolean; 
   684 begin
   684 begin
   685     isPhone:= false;
   685     isPhone:= false;
   686 {$IFDEF IPHONEOS}
   686 {$IFDEF IPHONEOS}
   687     isPhone:= isApplePhone();
   687     isPhone:= isApplePhone();
   688 {$ENDIF}
   688 {$ENDIF}