hedgewars/uMisc.pas
changeset 3939 e6fddcb04dc2
parent 3928 2560731c860d
parent 3932 2fc211f60015
child 3971 5c82ee165ed5
equal deleted inserted replaced
3935:5ca27a0e9a63 3939:e6fddcb04dc2
    15 * along with this program; if not, write to the Free Software
    15 * along with this program; if not, write to the Free Software
    16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17 *)
    17 *)
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 {$INLINE ON}
       
    21 
    20 
    22 unit uMisc;
    21 unit uMisc;
    23 interface
    22 interface
    24 
    23 
    25 uses    SDLh, uConsts, uFloat, GLunit, Math;
    24 uses    SDLh, uConsts, uFloat, GLunit, Math;
   163 function  EnumToStr(const en : TGearType) : shortstring; overload;
   162 function  EnumToStr(const en : TGearType) : shortstring; overload;
   164 function  EnumToStr(const en : TSound) : shortstring; overload;
   163 function  EnumToStr(const en : TSound) : shortstring; overload;
   165 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
   164 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
   166 function  EnumToStr(const en : THogEffect) : shortstring; overload;
   165 function  EnumToStr(const en : THogEffect) : shortstring; overload;
   167 procedure movecursor(dx, dy: LongInt);
   166 procedure movecursor(dx, dy: LongInt);
   168 function  hwSign(r: hwFloat): LongInt;
   167 function  hwSign(r: hwFloat): LongInt; inline;
   169 function  Min(a, b: LongInt): LongInt;
   168 function  Min(a, b: LongInt): LongInt; inline;
   170 function  Max(a, b: LongInt): LongInt;
   169 function  Max(a, b: LongInt): LongInt; inline;
   171 procedure OutError(Msg: shortstring; isFatalError: boolean);
   170 procedure OutError(Msg: shortstring; isFatalError: boolean);
   172 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
   171 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
   173 procedure SDLTry(Assert: boolean; isFatal: boolean);
   172 procedure SDLTry(Assert: boolean; isFatal: boolean);
   174 function  IntToStr(n: LongInt): shortstring;
   173 function  IntToStr(n: LongInt): shortstring;
   175 function  FloatToStr(n: hwFloat): shortstring;
   174 function  FloatToStr(n: hwFloat): shortstring;
   176 function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
   175 function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
   177 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
   176 function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
   178 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
   177 function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
       
   178 (*
   179 procedure AdjustColor(var Color: Longword);
   179 procedure AdjustColor(var Color: Longword);
   180 procedure SetKB(n: Longword);
   180 procedure SetKB(n: Longword);
       
   181 *)
   181 procedure SendKB;
   182 procedure SendKB;
   182 procedure SetLittle(var r: hwFloat);
   183 procedure SetLittle(var r: hwFloat);
   183 procedure SendStat(sit: TStatInfoType; s: shortstring);
   184 procedure SendStat(sit: TStatInfoType; s: shortstring);
   184 function  Str2PChar(const s: shortstring): PChar;
   185 function  Str2PChar(const s: shortstring): PChar;
   185 function  NewTexture(width, height: Longword; buf: Pointer): PTexture;
   186 function  NewTexture(width, height: Longword; buf: Pointer): PTexture;
   189 function  DecodeBase64(s: shortstring): shortstring;
   190 function  DecodeBase64(s: shortstring): shortstring;
   190 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   191 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   191 function  endian(independent: LongWord): LongWord;
   192 function  endian(independent: LongWord): LongWord;
   192 {$IFDEF DEBUGFILE}
   193 {$IFDEF DEBUGFILE}
   193 procedure AddFileLog(s: shortstring);
   194 procedure AddFileLog(s: shortstring);
   194 function  RectToStr(Rect: TSDL_Rect): shortstring;
   195 (* function  RectToStr(Rect: TSDL_Rect): shortstring; *)
   195 {$ENDIF}
   196 {$ENDIF}
   196 procedure MakeScreenshot(filename: shortstring);
   197 procedure MakeScreenshot(filename: shortstring);
   197 
   198 
   198 implementation
   199 implementation
   199 uses uConsole, uStore, uIO, uSound, typinfo, sysutils, uMobile;
   200 uses uConsole, uStore, uIO, uSound, typinfo, sysutils, uMobile;
   296 procedure SDLTry(Assert: boolean; isFatal: boolean);
   297 procedure SDLTry(Assert: boolean; isFatal: boolean);
   297 begin
   298 begin
   298 if not Assert then OutError(SDL_GetError, isFatal)
   299 if not Assert then OutError(SDL_GetError, isFatal)
   299 end;
   300 end;
   300 
   301 
       
   302 (*
   301 procedure AdjustColor(var Color: Longword);
   303 procedure AdjustColor(var Color: Longword);
   302 begin
   304 begin
   303 Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF)
   305 Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF)
   304 end;
   306 end;
       
   307 
       
   308 procedure SetKB(n: Longword);
       
   309 begin
       
   310 KBnum:= n
       
   311 end;
       
   312 *)
       
   313 
   305 
   314 
   306 function IntToStr(n: LongInt): shortstring;
   315 function IntToStr(n: LongInt): shortstring;
   307 begin
   316 begin
   308 str(n, IntToStr)
   317 str(n, IntToStr)
   309 end;
   318 end;
   352 dY:= _dY.QWordValue / $100000000;
   361 dY:= _dY.QWordValue / $100000000;
   353 if _dY.isNegative then dY:= - dY;
   362 if _dY.isNegative then dY:= - dY;
   354 dX:= _dX.QWordValue / $100000000;
   363 dX:= _dX.QWordValue / $100000000;
   355 if _dX.isNegative then dX:= - dX;
   364 if _dX.isNegative then dX:= - dX;
   356 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   365 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
   357 end;
       
   358 
       
   359 procedure SetKB(n: Longword);
       
   360 begin
       
   361 KBnum:= n
       
   362 end;
   366 end;
   363 
   367 
   364 procedure SendKB;
   368 procedure SendKB;
   365 var s: shortstring;
   369 var s: shortstring;
   366 begin
   370 begin
   655 procedure AddFileLog(s: shortstring);
   659 procedure AddFileLog(s: shortstring);
   656 begin
   660 begin
   657 writeln(f, GameTicks: 6, ': ', s);
   661 writeln(f, GameTicks: 6, ': ', s);
   658 flush(f)
   662 flush(f)
   659 end;
   663 end;
   660 
   664 (*
   661 function RectToStr(Rect: TSDL_Rect): shortstring;
   665 function RectToStr(Rect: TSDL_Rect): shortstring;
   662 begin
   666 begin
   663 RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
   667 RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
   664 end;
   668 end;
       
   669 *)
   665 {$ENDIF}
   670 {$ENDIF}
   666 
   671 
   667 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   672 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   668 {* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *}
   673 {* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *}
   669 var convertedSurf: PSDL_Surface = nil;
   674 var convertedSurf: PSDL_Surface = nil;
   814     if (ParamStr(1) <> '') and (ParamStr(2) <> '') then
   819     if (ParamStr(1) <> '') and (ParamStr(2) <> '') then
   815         if (ParamCount <> 3) and (ParamCount <> cDefaultParamNum) then
   820         if (ParamCount <> 3) and (ParamCount <> cDefaultParamNum) then
   816         begin
   821         begin
   817             for i:= 0 to 7 do
   822             for i:= 0 to 7 do
   818             begin
   823             begin
   819                 assign(f, ExtractFileDir(ParamStr(2)) + '/Logs/' + cLogfileBase + inttostr(i) + '.log');
   824                 assign(f, ExtractFileDir(ParamStr(2)) + '/' + cLogfileBase + inttostr(i) + '.log');
   820                 rewrite(f);
   825                 rewrite(f);
   821                 if IOResult = 0 then break;
   826                 if IOResult = 0 then break;
   822             end;
   827             end;
   823             if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
   828             if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
   824         end
   829         end