hedgewars/uUtils.pas
branchwebgl
changeset 8026 4a4f21070479
parent 7896 67217e6108fd
child 8330 aaefa587e277
equal deleted inserted replaced
8023:7de85783b823 8026:4a4f21070479
    23 interface
    23 interface
    24 uses uTypes, uFloat, GLunit;
    24 uses uTypes, uFloat, GLunit;
    25 
    25 
    26 procedure SplitBySpace(var a, b: shortstring);
    26 procedure SplitBySpace(var a, b: shortstring);
    27 procedure SplitByChar(var a, b: shortstring; c: char);
    27 procedure SplitByChar(var a, b: shortstring; c: char);
       
    28 
       
    29 {$IFNDEF PAS2C}
    28 procedure SplitByChar(var a, b: ansistring; c: char);
    30 procedure SplitByChar(var a, b: ansistring; c: char);
    29 
    31 {$ENDIF}
    30 {$IFNDEF PAS2C}
    32 
       
    33 //{$IFNDEF PAS2C}
    31 function  EnumToStr(const en : TGearType) : shortstring; overload;
    34 function  EnumToStr(const en : TGearType) : shortstring; overload;
    32 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
    35 function  EnumToStr(const en : TVisualGearType) : shortstring; overload;
    33 function  EnumToStr(const en : TSound) : shortstring; overload;
    36 function  EnumToStr(const en : TSound) : shortstring; overload;
    34 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
    37 function  EnumToStr(const en : TAmmoType) : shortstring; overload;
    35 function  EnumToStr(const en : THogEffect) : shortstring; overload;
    38 function  EnumToStr(const en : THogEffect) : shortstring; overload;
    36 function  EnumToStr(const en : TCapGroup) : shortstring; overload;
    39 function  EnumToStr(const en : TCapGroup) : shortstring; overload;
    37 {$ENDIF}
    40 //{$ENDIF}
    38 
    41 
    39 function  Min(a, b: LongInt): LongInt; inline;
    42 function  Min(a, b: LongInt): LongInt; inline;
    40 function  Max(a, b: LongInt): LongInt; inline;
    43 function  Max(a, b: LongInt): LongInt; inline;
    41 
    44 
    42 function  IntToStr(n: LongInt): shortstring;
    45 function  IntToStr(n: LongInt): shortstring;
    84 var f: textfile;
    87 var f: textfile;
    85 {$IFDEF USE_VIDEO_RECORDING}
    88 {$IFDEF USE_VIDEO_RECORDING}
    86     logMutex: TRTLCriticalSection; // mutex for debug file
    89     logMutex: TRTLCriticalSection; // mutex for debug file
    87 {$ENDIF}
    90 {$ENDIF}
    88 {$ENDIF}
    91 {$ENDIF}
    89 var CharArray: array[byte] of Char;
    92 var CharArray: array[0..255] of Char;
    90 
    93 
    91 procedure SplitBySpace(var a,b: shortstring);
    94 procedure SplitBySpace(var a,b: shortstring);
    92 begin
    95 begin
    93 SplitByChar(a,b,' ');
    96 SplitByChar(a,b,' ');
    94 end;
    97 end;
   103     for t:= 1 to Pred(i) do
   106     for t:= 1 to Pred(i) do
   104         if (a[t] >= 'A')and(a[t] <= 'Z') then
   107         if (a[t] >= 'A')and(a[t] <= 'Z') then
   105             Inc(a[t], 32);
   108             Inc(a[t], 32);
   106     b:= copy(a, i + 1, Length(a) - i);
   109     b:= copy(a, i + 1, Length(a) - i);
   107     a[0]:= char(Pred(i))
   110     a[0]:= char(Pred(i))
       
   111     {$IFDEF PAS2C}
       
   112        a[i] := 0;
       
   113     {$ENDIF}
   108     end
   114     end
   109 else
   115 else
   110     b:= '';
   116     b:= '';
   111 end;
   117 end;
   112 
   118 
       
   119 {$IFNDEF PAS2C}
   113 procedure SplitByChar(var a, b: ansistring; c: char);
   120 procedure SplitByChar(var a, b: ansistring; c: char);
   114 var i: LongInt;
   121 var i: LongInt;
   115 begin
   122 begin
   116 i:= Pos(c, a);
   123 i:= Pos(c, a);
   117 if i > 0 then
   124 if i > 0 then
   118     begin
   125     begin
   119     b:= copy(a, i + 1, Length(a) - i);
   126     b:= copy(a, i + 1, Length(a) - i);
   120     setlength(a, Pred(i));
   127     setlength(a, Pred(i));
   121     end else b:= '';
   128     end else b:= '';
   122 end;
   129 end; { SplitByChar }
   123 
   130 {$ENDIF}
   124 {$IFNDEF PAS2C}
   131 
       
   132 //{$IFNDEF PAS2C}
   125 function EnumToStr(const en : TGearType) : shortstring; overload;
   133 function EnumToStr(const en : TGearType) : shortstring; overload;
   126 begin
   134 begin
   127 EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
   135 EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
   128 end;
   136 end;
   129 function EnumToStr(const en : TVisualGearType) : shortstring; overload;
   137 function EnumToStr(const en : TVisualGearType) : shortstring; overload;
   148 
   156 
   149 function EnumToStr(const en: TCapGroup) : shortstring; overload;
   157 function EnumToStr(const en: TCapGroup) : shortstring; overload;
   150 begin
   158 begin
   151 EnumToStr := GetEnumName(TypeInfo(TCapGroup), ord(en))
   159 EnumToStr := GetEnumName(TypeInfo(TCapGroup), ord(en))
   152 end;
   160 end;
   153 {$ENDIF}
   161 //{$ENDIF}
   154 
   162 
   155 function Min(a, b: LongInt): LongInt;
   163 function Min(a, b: LongInt): LongInt;
   156 begin
   164 begin
   157 if a < b then
   165 if a < b then
   158     Min:= a
   166     Min:= a
   269 DecodeBase64[0]:= char(t - 1)
   277 DecodeBase64[0]:= char(t - 1)
   270 end;
   278 end;
   271 
   279 
   272 
   280 
   273 function Str2PChar(const s: shortstring): PChar;
   281 function Str2PChar(const s: shortstring): PChar;
   274 begin
   282 var i :Integer ;
   275 CharArray:= s;
   283 begin
       
   284    for i:= 1 to Length(s) do
       
   285       begin
       
   286       CharArray[i - 1] := s[i];
       
   287       end;
   276 CharArray[Length(s)]:= #0;
   288 CharArray[Length(s)]:= #0;
   277 Str2PChar:= @CharArray
   289    Str2PChar:= @(CharArray[0]);
   278 end;
   290 end;
   279 
   291 
   280 
   292 
   281 function endian(independent: LongWord): LongWord; inline;
   293 function endian(independent: LongWord): LongWord; inline;
   282 begin
   294 begin
   291 end;
   303 end;
   292 
   304 
   293 
   305 
   294 procedure AddFileLog(s: shortstring);
   306 procedure AddFileLog(s: shortstring);
   295 begin
   307 begin
   296 s:= s;
   308 // s:= s;
   297 {$IFDEF DEBUGFILE}
   309 {$IFNDEF WEBGL}
       
   310 {$IFDEF DEBUGFILE}
       
   311 
   298 {$IFDEF USE_VIDEO_RECORDING}
   312 {$IFDEF USE_VIDEO_RECORDING}
   299 EnterCriticalSection(logMutex);
   313 EnterCriticalSection(logMutex);
   300 {$ENDIF}
   314 {$ENDIF}
   301 writeln(f, inttostr(GameTicks)  + ': ' + s);
   315 writeln(f, inttostr(GameTicks)  + ': ' + s);
   302 flush(f);
   316 flush(f);
       
   317 
   303 {$IFDEF USE_VIDEO_RECORDING}
   318 {$IFDEF USE_VIDEO_RECORDING}
   304 LeaveCriticalSection(logMutex);
   319 LeaveCriticalSection(logMutex);
       
   320 {$ENDIF}
       
   321 
   305 {$ENDIF}
   322 {$ENDIF}
   306 {$ENDIF}
   323 {$ENDIF}
   307 end;
   324 end;
   308 
   325 
   309 procedure AddFileLogRaw(s: pchar); cdecl;
   326 procedure AddFileLogRaw(s: pchar); cdecl;