# HG changeset patch # User sheepluva # Date 1417281289 -3600 # Node ID c23f13a65638bafbd865e0680bb336978d728ec4 # Parent 13b1e9008f4bec905ac09eed3611f7ddf506cfda# Parent c90a1814a91ba882fcdc6471d287a22608b22d54 some moar mergin' diff -r c90a1814a91b -r c23f13a65638 hedgewars/pas2cRedo.pas --- a/hedgewars/pas2cRedo.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/pas2cRedo.pas Sat Nov 29 18:14:49 2014 +0100 @@ -84,6 +84,7 @@ min, max:function:integer; assign, rewrite, rewrite_2, reset, reset_2, flush, BlockWrite, BlockRead, close : procedure; FileExists, DirectoryExists, eof : function : boolean; + ExtractFileDir : function : string; ExtractFileName : function : string; ParamCount : function : integer; diff -r c90a1814a91b -r c23f13a65638 hedgewars/uAmmos.pas --- a/hedgewars/uAmmos.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uAmmos.pas Sat Nov 29 18:14:49 2014 +0100 @@ -43,11 +43,11 @@ procedure SetWeapon(weap: TAmmoType); procedure DisableSomeWeapons; procedure ResetWeapons; -function GetAmmoByNum(num: Longword): PHHAmmo; +function GetAmmoByNum(num: LongInt): PHHAmmo; function GetCurAmmoEntry(var Hedgehog: THedgehog): PAmmo; function GetAmmoEntry(var Hedgehog: THedgehog; am: TAmmoType): PAmmo; -var StoreCnt: Longword; +var StoreCnt: LongInt; implementation uses uVariables, uCommands, uUtils, uCaptions, uDebug; @@ -151,7 +151,7 @@ FillAmmoStore(StoresList[Pred(StoreCnt)], newAmmos) end; -function GetAmmoByNum(num: Longword): PHHAmmo; +function GetAmmoByNum(num: LongInt): PHHAmmo; begin TryDo(num < StoreCnt, 'Invalid store number', true); GetAmmoByNum:= StoresList[num] diff -r c90a1814a91b -r c23f13a65638 hedgewars/uFloat.pas --- a/hedgewars/uFloat.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uFloat.pas Sat Nov 29 18:14:49 2014 +0100 @@ -370,8 +370,8 @@ function hwSqrt1(const t: hwFloat): hwFloat; const pwr = 8; // even value, feel free to adjust - rThreshold = 1 shl (pwr + 32); - lThreshold = 1 shl (pwr div 2 + 32); + rThreshold: QWord = 1 shl (pwr + 32); + lThreshold: QWord = 1 shl (pwr div 2 + 32); var l, r: QWord; c: hwFloat; begin diff -r c90a1814a91b -r c23f13a65638 hedgewars/uGearsRender.pas --- a/hedgewars/uGearsRender.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uGearsRender.pas Sat Nov 29 18:14:49 2014 +0100 @@ -166,8 +166,7 @@ end; procedure DrawRope(Gear: PGear); -var roplen: LongInt; - i: Longword; +var roplen, i: LongInt; begin if (cReducedQuality and rqSimpleRope) <> 0 then DrawRopeLinesRQ(Gear) @@ -624,7 +623,7 @@ if ((Gear^.State and gstAnimation) <> 0) then begin - if (TWave(Gear^.Tag) < Low(TWave)) or (TWave(Gear^.Tag) > High(TWave)) then + if (Gear^.Tag < LongInt(ord(Low(TWave)))) or (Gear^.Tag > LongInt(ord(High(TWave)))) then begin Gear^.State:= Gear^.State and (not gstAnimation); end @@ -711,7 +710,7 @@ LongInt(rightX)+WorldDx, cWaterLine+WorldDy, LongInt(leftX)+WorldDx); - if hwRound(Gear^.X) > rightX-256 then + if hwRound(Gear^.X) > LongInt(rightX) - 256 then DrawSpriteClipped(sprGirder, leftX-(rightX-ox)-256, oy-256, @@ -1167,7 +1166,7 @@ end; if Gear^.Timer < 1833 then begin - DrawTextureRotatedF(SpritesData[sprPortal].texture, min(abs(1.25 - (Gear^.Timer mod 1333) / 400), 1.25), 0, 0, + DrawTextureRotatedF(SpritesData[sprPortal].texture, MinD(abs(1.25 - (Gear^.Timer mod 1333) / 400), 1.25), 0, 0, x, LongInt(Gear^.Angle) + WorldDy - 16, 4 + Gear^.Tag, 1, 32, 32, 270); end end; diff -r c90a1814a91b -r c23f13a65638 hedgewars/uIO.pas --- a/hedgewars/uIO.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uIO.pas Sat Nov 29 18:14:49 2014 +0100 @@ -350,7 +350,7 @@ while (headcmd <> nil) and (tmpflag or (headcmd^.cmd = '#')) // '#' is the only cmd which can be sent within same tick after 'N' - and ((GameTicks = hiTicks shl 16 + headcmd^.loTime) + and ((GameTicks = LongWord(hiTicks shl 16 + headcmd^.loTime)) or (headcmd^.cmd = 's') // for these commands time is not specified or (headcmd^.cmd = 'h') // seems the hedgewars protocol does not allow remote synced commands or (headcmd^.cmd = '#') // must be synced for saves to work @@ -426,7 +426,7 @@ end; if (headcmd <> nil) and tmpflag and (not CurrentTeam^.hasGone) then - TryDo(GameTicks < hiTicks shl 16 + headcmd^.loTime, + TryDo(GameTicks < LongWord(hiTicks shl 16) + headcmd^.loTime, 'oops, queue error. in buffer: ' + headcmd^.cmd + ' (' + IntToStr(GameTicks) + ' > ' + IntToStr(hiTicks shl 16 + headcmd^.loTime) + ')', diff -r c90a1814a91b -r c23f13a65638 hedgewars/uLandGenTemplateBased.pas --- a/hedgewars/uLandGenTemplateBased.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uLandGenTemplateBased.pas Sat Nov 29 18:14:49 2014 +0100 @@ -18,7 +18,7 @@ with Template do begin pa.Count:= BasePointsCount; - for i:= 0 to pred(pa.Count) do + for i:= 0 to pred(LongInt(pa.Count)) do begin pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w)); if pa.ar[i].x <> NTPX then @@ -174,7 +174,7 @@ // now go through all other segments fp:= pa.ar[0]; - for i:= 0 to pa.Count - 2 do + for i:= 0 to LongInt(pa.Count) - 2 do if pa.ar[i].x = NTPX then fp:= pa.ar[i + 1] else if (i <> si) then @@ -210,7 +210,7 @@ end; // go through all points, including fill points - for i:= 0 to Pred(pa.Count + fillPointsCount) do + for i:= 0 to Pred(LongInt(pa.Count + fillPointsCount)) do // if this point isn't on current segment if (si <> i) and (i <> si + 1) and (pa.ar[i].x <> NTPX) then begin @@ -294,7 +294,7 @@ newPoint.y:= 0; i:= 0; - while i < pa.Count - 1 do + while i < LongInt(pa.Count) - 1 do begin FindPoint(i, fillPointsCount, newPoint, pa); diff -r c90a1814a91b -r c23f13a65638 hedgewars/uLandObjects.pas --- a/hedgewars/uLandObjects.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uLandObjects.pas Sat Nov 29 18:14:49 2014 +0100 @@ -253,15 +253,15 @@ inc(x1, 2); if k = 16 then begin - while (x2 < (rightX-150)) and (CountNonZeroz(x2, y) = 0) do + while (x2 < (LongInt(rightX)-150)) and (CountNonZeroz(x2, y) = 0) do inc(x2, 2); i:= x2 + 12; repeat inc(x2, 2); k:= CountNonZeroz(x2, y) - until (x2 >= (rightX-150)) or (k = 0) or (k = 16) or (x2 > i) or (x2 - x1 >= 768); + until (x2 >= (LongInt(rightX)-150)) or (k = 0) or (k = 16) or (x2 > i) or (x2 - x1 >= 768); - if (x2 < (rightX - 150)) and (k = 16) and (x2 - x1 > 250) and (x2 - x1 < 768) + if (x2 < (LongInt(rightX) - 150)) and (k = 16) and (x2 - x1 > 250) and (x2 - x1 < 768) and (not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144)) then break; end; diff -r c90a1814a91b -r c23f13a65638 hedgewars/uLandOutline.pas --- a/hedgewars/uLandOutline.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uLandOutline.pas Sat Nov 29 18:14:49 2014 +0100 @@ -253,7 +253,7 @@ var i: Longword; begin CheckSelfIntersect:= false; - if (ind <= 0) or (ind >= Pred(pa.Count)) then + if (ind <= 0) or (LongInt(ind) >= Pred(pa.Count)) then exit; CheckSelfIntersect:= true; diff -r c90a1814a91b -r c23f13a65638 hedgewars/uPhysFSLayer.pas --- a/hedgewars/uPhysFSLayer.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uPhysFSLayer.pas Sat Nov 29 18:14:49 2014 +0100 @@ -179,13 +179,11 @@ // need access to teams and frontend configs (for bindings) pfsMountAtRoot(UserPathPrefix); - {$IFNDEF PAS2C} if cTestLua then begin - pfsMountAtRoot(ExtractFileDir(cScriptName)); + pfsMountAtRoot(ansistring(ExtractFileDir(cScriptName))); cScriptName := ExtractFileName(cScriptName); end; - {$ENDIF} end; procedure freeModule; diff -r c90a1814a91b -r c23f13a65638 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uScript.pas Sat Nov 29 18:14:49 2014 +0100 @@ -2534,7 +2534,7 @@ function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt; begin if (not ScriptLoaded) or (not ScriptExists(fname)) then - exit; + exit(0); SetGlobals; lua_getglobal(luaState, Str2PChar(fname)); lua_pushinteger(luaState, par1); diff -r c90a1814a91b -r c23f13a65638 hedgewars/uUtils.pas --- a/hedgewars/uUtils.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uUtils.pas Sat Nov 29 18:14:49 2014 +0100 @@ -37,6 +37,7 @@ function EnumToStr(const en : TSprite) : shortstring; overload; function Min(a, b: LongInt): LongInt; inline; +function MinD(a, b: double) : double; inline; function Max(a, b: LongInt): LongInt; inline; function IntToStr(n: LongInt): shortstring; @@ -95,7 +96,7 @@ uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, SysUtils; {$IFDEF DEBUGFILE} -var f: textfile; +var logFile: textfile; {$IFDEF USE_VIDEO_RECORDING} logMutex: TRTLCriticalSection; // mutex for debug file {$ENDIF} @@ -194,6 +195,14 @@ Min:= b end; +function MinD(a, b: double): double; +begin +if a < b then + MinD:= a +else + MinD:= b +end; + function Max(a, b: LongInt): LongInt; begin if a > b then @@ -217,7 +226,7 @@ val(s, StrToInt, c); {$IFDEF DEBUGFILE} if c <> 0 then - writeln(f, 'Error at position ' + IntToStr(c) + ' : ' + s[c]) + writeln(logFile, 'Error at position ' + IntToStr(c) + ' : ' + s[c]) {$ENDIF} {$ENDIF} end; @@ -280,7 +289,7 @@ function DecodeBase64(s: shortstring): shortstring; const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; -var i, t, c: Longword; +var i, t, c: LongInt; begin c:= 0; for i:= 1 to Length(s) do @@ -345,8 +354,8 @@ {$IFDEF USE_VIDEO_RECORDING} EnterCriticalSection(logMutex); {$ENDIF} -writeln(f, inttostr(GameTicks) + ': ' + s); -flush(f); +writeln(logFile, inttostr(GameTicks) + ': ' + s); +flush(logFile); {$IFDEF USE_VIDEO_RECORDING} LeaveCriticalSection(logMutex); @@ -363,8 +372,8 @@ {$IFDEF USE_VIDEO_RECORDING} EnterCriticalSection(logMutex); {$ENDIF} -write(f, s); -flush(f); +write(logFile, s); +flush(logFile); {$IFDEF USE_VIDEO_RECORDING} LeaveCriticalSection(logMutex); {$ENDIF} @@ -529,9 +538,6 @@ InitCriticalSection(logMutex); {$ENDIF} {$I-} -{$IFNDEF PAS2C} - f:= stderr; // if everything fails, write to stderr -{$ENDIF} if (length(UserPathPrefix) > 0) then begin {$IFNDEF PAS2C} @@ -543,13 +549,19 @@ i:= 0; while(i < 7) do begin - assign(f, shortstring(UserPathPrefix) + '/Logs/' + logfileBase + inttostr(i) + '.log'); + assign(logFile, shortstring(UserPathPrefix) + '/Logs/' + logfileBase + inttostr(i) + '.log'); + Rewrite(logFile); if IOResult = 0 then break; inc(i) end; end; - Rewrite(f); + +{$IFNDEF PAS2C} + // if everything fails, write to stderr + if (length(UserPathPrefix) = 0) or (IOResult = 0) then + logFile:= stderr; +{$ENDIF} {$I+} {$ENDIF} @@ -571,9 +583,9 @@ procedure freeModule; begin {$IFDEF DEBUGFILE} - writeln(f, 'halt at ' + inttostr(GameTicks) + ' ticks. TurnTimeLeft = ' + inttostr(TurnTimeLeft)); - flush(f); - close(f); + writeln(logFile, 'halt at ' + inttostr(GameTicks) + ' ticks. TurnTimeLeft = ' + inttostr(TurnTimeLeft)); + flush(logFile); + close(logFile); {$IFDEF USE_VIDEO_RECORDING} DoneCriticalSection(logMutex); {$ENDIF} diff -r c90a1814a91b -r c23f13a65638 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Sat Nov 29 09:45:02 2014 -0500 +++ b/hedgewars/uWorld.pas Sat Nov 29 18:14:49 2014 +0100 @@ -1872,12 +1872,12 @@ end else begin - if abs(prevPoint.X - WorldDx - hwRound(FollowGear^.X)) > rightX - leftX - 100 then + if abs(prevPoint.X - WorldDx - hwRound(FollowGear^.X)) > LongInt(rightX) - leftX - 100 then begin - if (prevPoint.X - WorldDx) * 2 < LongInt(rightX + leftX) then - cameraJump:= rightX - leftX + if (prevPoint.X - WorldDx) * 2 < LongInt((rightX + leftX)) then + cameraJump:= LongInt(rightX) - leftX else - cameraJump:= leftX - rightX; + cameraJump:= LongInt(leftX) - rightX; WorldDx:= WorldDx - cameraJump; end; diff -r c90a1814a91b -r c23f13a65638 project_files/hwc/rtl/SysUtils.h --- a/project_files/hwc/rtl/SysUtils.h Sat Nov 29 09:45:02 2014 -0500 +++ b/project_files/hwc/rtl/SysUtils.h Sat Nov 29 18:14:49 2014 +0100 @@ -31,6 +31,9 @@ #define StrToInt fpcrtl_strToInt #define strToInt fpcrtl_strToInt +string255 fpcrtl_extractFileDir(string255 f); +#define fpcrtl_ExtractFileDir fpcrtl_extractFileDir + string255 fpcrtl_extractFileName(string255 f); #define fpcrtl_ExtractFileName fpcrtl_extractFileName diff -r c90a1814a91b -r c23f13a65638 project_files/hwc/rtl/fileio.c --- a/project_files/hwc/rtl/fileio.c Sat Nov 29 09:45:02 2014 -0500 +++ b/project_files/hwc/rtl/fileio.c Sat Nov 29 18:14:49 2014 +0100 @@ -162,7 +162,11 @@ void __attribute__((overloadable)) fpcrtl_writeLn(File f, string255 s) { FIX_STRING(s); - fprintf(f->fp, "%s\n", s.str); + // filthy hack to write to stderr + if (!f->fp) + fprintf(stderr, "%s\n", s.str); + else + fprintf(f->fp, "%s\n", s.str); } void __attribute__((overloadable)) fpcrtl_writeLn(FILE *f, string255 s) { diff -r c90a1814a91b -r c23f13a65638 project_files/hwc/rtl/system.h --- a/project_files/hwc/rtl/system.h Sat Nov 29 09:45:02 2014 -0500 +++ b/project_files/hwc/rtl/system.h Sat Nov 29 18:14:49 2014 +0100 @@ -1,6 +1,7 @@ #ifndef SYSTEM_H_ #define SYSTEM_H_ +#include #include #include "Types.h" #include "misc.h" @@ -134,7 +135,8 @@ int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen); -#define fpcrtl_halt(t) assert(0) +// #define fpcrtl_halt(t) assert(0) +#define fpcrtl_halt(t) exit(t) #define fpcrtl_Load_GL_VERSION_2_0() 1 diff -r c90a1814a91b -r c23f13a65638 project_files/hwc/rtl/sysutils.c --- a/project_files/hwc/rtl/sysutils.c Sat Nov 29 09:45:02 2014 -0500 +++ b/project_files/hwc/rtl/sysutils.c Sat Nov 29 18:14:49 2014 +0100 @@ -131,6 +131,24 @@ return atoi(s.str); } +string255 fpcrtl_extractFileDir(string255 f) +{ + const char sep[] = {'\\', '/', ':'}; + LongInt i,j; + + i = f.len - 1; + while(i >= 0){ + for(j = 0; j < sizeof(sep); j++){ + if(f.str[i] == sep[j]){ + goto FPCRTL_EXTRACTFILEDIR_END; + } + } + i--; + } +FPCRTL_EXTRACTFILEDIR_END: + return fpcrtl_copy(f, 1, i); +} + //function ExtractFileName(const FileName: string): string; //var // i : longint;