# HG changeset patch # User koda # Date 1280565760 -7200 # Node ID 09892cdb8f95caacee25eb246941fa3386a16fbc # Parent aaf832c6fbd7dd88f5399efa5916d2ee77e1e34f# Parent 34fe2149f75dd275a5c4247c8e6aaea32cf7c589 merge diff -r 34fe2149f75d -r 09892cdb8f95 hedgewars/ArgParsers.inc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hedgewars/ArgParsers.inc Sat Jul 31 10:42:40 2010 +0200 @@ -0,0 +1,212 @@ + +procedure internalSetGameTypeLandPreviewFromParameters(); +begin + val(ParamStr(2), ipcPort); + GameType:= gmtLandPreview; + if ParamStr(3) <> 'landpreview' then + GameType:= gmtSyntax; +end; + +procedure internalStartGameWithParameters(); +begin + val(ParamStr(2), cScreenWidth); + val(ParamStr(3), cScreenHeight); + cBitsStr:= ParamStr(4); + val(cBitsStr, cBits); + val(ParamStr(5), ipcPort); + cFullScreen:= ParamStr(6) = '1'; + isSoundEnabled:= ParamStr(7) = '1'; + //cVSyncInUse:= ParamStr(8) = '1'; //merged with rqFlags + //cWeaponTooltips:= ParamStr(9) = '1'; //merged with rqFlags + cLocaleFName:= ParamStr(10); + val(ParamStr(11), cInitVolume); + val(ParamStr(12), cTimerInterval); + PathPrefix:= ParamStr(13); + cShowFPS:= ParamStr(14) = '1'; + cAltDamage:= ParamStr(15) = '1'; + UserNick:= DecodeBase64(ParamStr(16)); + isMusicEnabled:= ParamStr(17) = '1'; + + if (ParamStr(18) = '1') then //HACK - always disable rqLowRes as it is a game breaker + cReducedQuality:= $FFFFFFFF xor rqLowRes + else + val(ParamStr(18), cReducedQuality); + + if (ParamStr(8) = '0') then //HACK - ifcVSyncInUse not true, disable it + cReducedQuality:= cReducedQuality xor rqDesyncVBlank; + if (ParamStr(9) = '0') then //HACK - if cWeaponTooltips not true, disable it + cReducedQuality:= cReducedQuality xor rqTooltipsOff; +end; + +procedure setVideo(screenWidth: LongInt; screenHeight: LongInt; bitsStr: LongInt); +begin + cScreenWidth:= screenWidth; + cScreenHeight:= screenHeight; + cBits:= bitsStr; +end; + +procedure setVideoWithParameters(screenWidthParam: string; screenHeightParam: string; bitsParam: string); +var screenWidthAsInt, screenHeightAsInt, bitsStrAsInt: LongInt; +begin + val(screenWidthParam, screenWidthAsInt); + val(screenHeightParam, screenHeightAsInt); + cBitsStr:= bitsParam; + val(cBitsStr, bitsStrAsInt); + setVideo(screenWidthAsInt,screenHeightAsInt,bitsStrAsInt); +end; + +procedure setOtherOptions(languageFile: string; fullScreen: boolean); +begin + cLocaleFName:= languageFile; + cFullScreen:= fullScreen; +end; + +procedure setShowFPS(showFPS: boolean); +begin + cShowFPS:= showFPS; +end; + +procedure setOtherOptionsWithParameters(languageFileParam: string; fullScreenParam: string; showFPSParam: string); +var fullScreen, showFPS: boolean; +begin + fullScreen:= fullScreenParam = '1'; + showFPS:= showFPSParam = '1'; + setOtherOptions(languageFileParam,fullScreen); + setShowFPS(showFPS); +end; + +procedure setAudio(initialVolume: LongInt; musicEnabled: boolean; soundEnabled: boolean); +begin + cInitVolume:= initialVolume; + isMusicEnabled:= musicEnabled; + isSoundEnabled:= soundEnabled; +end; + +procedure setAudioWithParameters(initialVolumeParam: string; musicEnabledParam: string; soundEnabledParam: string); +var initialVolumeAsInt: LongInt; + musicEnabled, soundEnabled: boolean; +begin + val(initialVolumeParam, initialVolumeAsInt); + musicEnabled:= musicEnabledParam = '1'; + soundEnabled:= soundEnabledParam = '1'; + setAudio(initialVolumeAsInt,musicEnabled, soundEnabled); +end; + +procedure setMultimediaOptionsWithParameters(screenWidthParam, screenHeightParam, bitsParam: string; + initialVolumeParam, musicEnabledParam, soundEnabledParam: string; + languageFileParam, fullScreenParam: string); +begin + setVideoWithParameters(screenWidthParam,screenHeightParam, bitsParam); + setAudioWithParameters(initialVolumeParam,musicEnabledParam,soundEnabledParam); + setOtherOptions(languageFileParam,fullScreenParam = '1'); +end; + +procedure setAltDamageTimerValueAndQuality(altDamage: boolean; timeIterval: LongInt; reducedQuality: boolean); +begin + cAltDamage:= altDamage; + cTimerInterval:= timeIterval; + if (reducedQuality) then //HACK + cReducedQuality:= $FFFFFFFF xor rqLowRes +end; + +procedure setAllOptionsWithParameters(screenWidthParam:string; screenHeightParam:string; bitsParam:string; + initialVolumeParam:string; musicEnabledParam:string; soundEnabledParam:string; + languageFileParam:string; fullScreenParam:string; showFPSParam:string; + altDamageParam:string; timeItervalParam:string; reducedQualityParam: string); +var showFPS, altDamage, reducedQuality: boolean; + timeIterval: LongInt; +begin + setMultimediaOptionsWithParameters(screenWidthParam,screenHeightParam, bitsParam, + initialVolumeParam,musicEnabledParam,soundEnabledParam, + languageFileParam,fullScreenParam); + showFPS := showFPSParam = '1'; + setShowFPS(showFPS); + + altDamage:= altDamageParam = '1'; + val(timeItervalParam, timeIterval); + reducedQuality:= reducedQualityParam = '1'; + setAltDamageTimerValueAndQuality(altDamage,timeIterval,reducedQuality); +end; + +procedure playReplayFileWithParameters(); +var paramIndex: LongInt; + wrongParameter: boolean; +begin + PathPrefix:= ParamStr(1); + recordFileName:= ParamStr(2); + paramIndex:= 3; + wrongParameter:= false; + while (paramIndex <= ParamCount) and not wrongParameter do + begin + //--set-video [screen width] [screen height] [color dept] + if(ParamStr(paramIndex) = '--set-video') then + begin + if(ParamCount-paramIndex < 3) then + begin + wrongParameter:= true; + GameType:= gmtSyntax; + end; + setVideoWithParameters(ParamStr(paramIndex+1), ParamStr(paramIndex+2), ParamStr(paramIndex+3)); + paramIndex:= paramIndex + 4; + end + else + //--set-audio [volume] [enable music] [enable sounds] + if(ParamStr(paramIndex) = '--set-audio') then + begin + if(ParamCount-paramIndex < 3) then + begin + wrongParameter := true; + GameType:= gmtSyntax; + end; + setAudioWithParameters(ParamStr(paramIndex+1),ParamStr(paramIndex+2), ParamStr(paramIndex+3)); + paramIndex:= paramIndex + 4; + end + else + // --set-other [language file] [full screen] [show FPS] + if(ParamStr(paramIndex) = '--set-other') then + begin + if(ParamCount-paramIndex < 3) then + begin + wrongParameter:= true; + GameType:= gmtSyntax; + end; + setOtherOptionsWithParameters(ParamStr(paramIndex+1),ParamStr(paramIndex+2), ParamStr(paramIndex+3)); + paramIndex:= paramIndex + 4; + end + else + //--set-multimedia [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] + if(ParamStr(paramIndex) = '--set-multimedia') then + begin + if(ParamCount-paramIndex < 8) then + begin + wrongParameter:= true; + GameType:= gmtSyntax; + end; + setMultimediaOptionsWithParameters(ParamStr(paramIndex+1),ParamStr(paramIndex+2),ParamStr(paramIndex+3), + ParamStr(paramIndex+4),ParamStr(paramIndex+5),ParamStr(paramIndex+6), + ParamStr(paramIndex+7),ParamStr(paramIndex+8)); + paramIndex:= paramIndex + 9; + end + else + //--set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality] + if(ParamStr(paramIndex) = '--set-everything') then + begin + if(ParamCount-paramIndex < 12) then + begin + wrongParameter:= true; + GameType:= gmtSyntax; + end; + setAllOptionsWithParameters(ParamStr(paramIndex+1),ParamStr(paramIndex+2),ParamStr(paramIndex+3), + ParamStr(paramIndex+4),ParamStr(paramIndex+5),ParamStr(paramIndex+6), + ParamStr(paramIndex+7),ParamStr(paramIndex+8),ParamStr(paramIndex+9), + ParamStr(paramIndex+10),ParamStr(paramIndex+11),ParamStr(paramIndex+12)); + paramIndex:= paramIndex + 13; + end + else + begin + wrongParameter:= true; + GameType:= gmtSyntax; + end; + end; +end; + diff -r 34fe2149f75d -r 09892cdb8f95 hedgewars/CCHandlers.inc --- a/hedgewars/CCHandlers.inc Fri Jul 30 19:56:28 2010 +0200 +++ b/hedgewars/CCHandlers.inc Sat Jul 31 10:42:40 2010 +0200 @@ -824,13 +824,13 @@ procedure chChat(var s: shortstring); begin -s:= s; // avoid compiler hint -GameState:= gsChat; -KeyPressChat(27) + s:= s; // avoid compiler hint + GameState:= gsChat; + KeyPressChat(27) end; procedure chHistory(var s: shortstring); begin -s:= s; // avoid compiler hint -uChat.showAll:= not uChat.showAll + s:= s; // avoid compiler hint + uChat.showAll:= not uChat.showAll end; diff -r 34fe2149f75d -r 09892cdb8f95 hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Fri Jul 30 19:56:28 2010 +0200 +++ b/hedgewars/CMakeLists.txt Sat Jul 31 10:42:40 2010 +0200 @@ -74,6 +74,7 @@ GearDrawing.inc HHHandlers.inc SinTable.inc + ArgParsers.inc options.inc ${CMAKE_CURRENT_BINARY_DIR}/config.inc ) diff -r 34fe2149f75d -r 09892cdb8f95 hedgewars/PascalExports.pas --- a/hedgewars/PascalExports.pas Fri Jul 30 19:56:28 2010 +0200 +++ b/hedgewars/PascalExports.pas Sat Jul 31 10:42:40 2010 +0200 @@ -54,6 +54,17 @@ followGear:= CurrentHedgehog^.Gear; end; +function HW_zoomFactor: GLfloat; cdecl; export; +begin + exit( ZoomValue / cDefaultZoomLevel ); +end; + +function HW_zoomLevel: LongInt; cdecl; export; +begin + writelntoconsole(inttostr(trunc((ZoomValue - cDefaultZoomLevel) / cZoomDelta) )); + exit( trunc((ZoomValue - cDefaultZoomLevel) / cZoomDelta) ); +end; + procedure HW_ammoMenu; cdecl; export; begin rightClick:= true; diff -r 34fe2149f75d -r 09892cdb8f95 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Fri Jul 30 19:56:28 2010 +0200 +++ b/hedgewars/hwengine.pas Sat Jul 31 10:42:40 2010 +0200 @@ -32,11 +32,12 @@ uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, sysutils; -type arrayofpchar = array[0..9] of PChar; var isTerminated: boolean = false; alsoShutdownFrontend: boolean = false; {$IFDEF HWLIBRARY} +type arrayofpchar = array[0..9] of PChar; + procedure initEverything(complete:boolean); procedure freeEverything(complete:boolean); @@ -230,11 +231,9 @@ recordFileName:= gameArgs[8]; val(gameArgs[9], cReducedQuality); - isStereoEnabled:= false; // TODO: Enable anaglyph rendering on iPhone? {$ENDIF} initEverything(true); - WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')'); {$IFDEF DEBUGFILE} AddFileLog('Prefix: "' + PathPrefix +'"'); @@ -419,141 +418,38 @@ begin WriteLn('Wrong argument format: correct configurations is'); WriteLn(); - WriteLn(' hwengine [option]'); + WriteLn(' hwengine [options]'); WriteLn(); - WriteLn('where [option] must be specified either as'); + WriteLn('where [options] must be specified either as:'); WriteLn(' --set-video [screen width] [screen height] [color dept]'); WriteLn(' --set-audio [volume] [enable music] [enable sounds]'); WriteLn(' --set-other [language file] [full screen] [show FPS]'); - WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); - WriteLn(' --set-everything [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]'); + WriteLn(' --set-multimedia [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]'); + WriteLn(' --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]'); WriteLn(); - WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information'); - Write('parsed command: '); + WriteLn('Read documentation online at http://code.google.com/p/hedgewars/wiki/CommandLineOptions for more information'); + WriteLn(); + Write('PARSED COMMAND: '); for i:=0 to ParamCount do Write(ParamStr(i) + ' '); WriteLn(); end; //////////////////// +{$INCLUDE "ArgParsers.inc"} + procedure GetParams; begin - case ParamCount of - 19: begin - val(ParamStr(2), cScreenWidth); - val(ParamStr(3), cScreenHeight); - cBitsStr:= ParamStr(4); - val(cBitsStr, cBits); - val(ParamStr(5), ipcPort); - cFullScreen:= ParamStr(6) = '1'; - isSoundEnabled:= ParamStr(7) = '1'; - //cVSyncInUse:= ParamStr(8) = '1'; //merged with rqFlags - //cWeaponTooltips:= ParamStr(9) = '1'; //merged with rqFlags - cLocaleFName:= ParamStr(10); - val(ParamStr(11), cInitVolume); - val(ParamStr(12), cTimerInterval); - PathPrefix:= ParamStr(13); - cShowFPS:= ParamStr(14) = '1'; - cAltDamage:= ParamStr(15) = '1'; - UserNick:= DecodeBase64(ParamStr(16)); - isMusicEnabled:= ParamStr(17) = '1'; - isStereoEnabled:= ParamStr(19) = '1'; - - if (ParamStr(18) = '1') then //HACK - always disable rqLowRes as it's a game breaker - cReducedQuality:= $FFFFFFFF xor rqLowRes - else - val(ParamStr(18), cReducedQuality); - - if (ParamStr(8) = '0') then //HACK - ifcVSyncInUse not true, disable it - cReducedQuality:= cReducedQuality xor rqDesyncVBlank; - if (ParamStr(9) = '0') then //HACK - if cWeaponTooltips not true, disable it - cReducedQuality:= cReducedQuality xor rqTooltipsOff; - end; - 3: begin - val(ParamStr(2), ipcPort); - GameType:= gmtLandPreview; - if ParamStr(3) <> 'landpreview' then - OutError(errmsgShouldntRun, true); - end; - 2: begin - PathPrefix:= ParamStr(1); - recordFileName:= ParamStr(2); - end; - 6: begin - PathPrefix:= ParamStr(1); - recordFileName:= ParamStr(2); - - if ParamStr(3) = '--set-video' then - begin - val(ParamStr(4), cScreenWidth); - val(ParamStr(5), cScreenHeight); - cBitsStr:= ParamStr(6); - val(cBitsStr, cBits); - end + if (ParamCount < 2) then + GameType:= gmtSyntax + else + if (ParamCount = 3) then + internalSetGameTypeLandPreviewFromParameters() + else + if (ParamCount = 18) then + internalStartGameWithParameters() else - begin - if ParamStr(3) = '--set-audio' then - begin - val(ParamStr(4), cInitVolume); - isMusicEnabled:= ParamStr(5) = '1'; - isSoundEnabled:= ParamStr(6) = '1'; - end - else - begin - if ParamStr(3) = '--set-other' then - begin - cLocaleFName:= ParamStr(4); - cFullScreen:= ParamStr(5) = '1'; - cShowFPS:= ParamStr(6) = '1'; - end - else GameType:= gmtSyntax; - end - end; - end; - 11: begin - PathPrefix:= ParamStr(1); - recordFileName:= ParamStr(2); - - if ParamStr(3) = '--set-multimedia' then - begin - val(ParamStr(4), cScreenWidth); - val(ParamStr(5), cScreenHeight); - cBitsStr:= ParamStr(6); - val(cBitsStr, cBits); - val(ParamStr(7), cInitVolume); - isMusicEnabled:= ParamStr(8) = '1'; - isSoundEnabled:= ParamStr(9) = '1'; - cLocaleFName:= ParamStr(10); - cFullScreen:= ParamStr(11) = '1'; - end - else GameType:= gmtSyntax; - end; - 15: begin - PathPrefix:= ParamStr(1); - recordFileName:= ParamStr(2); - if ParamStr(3) = '--set-everything' then - begin - val(ParamStr(4), cScreenWidth); - val(ParamStr(5), cScreenHeight); - cBitsStr:= ParamStr(6); - val(cBitsStr, cBits); - val(ParamStr(7), cInitVolume); - isMusicEnabled:= ParamStr(8) = '1'; - isSoundEnabled:= ParamStr(9) = '1'; - cLocaleFName:= ParamStr(10); - cFullScreen:= ParamStr(11) = '1'; - cAltDamage:= ParamStr(12) = '1'; - cShowFPS:= ParamStr(13) = '1'; - val(ParamStr(14), cTimerInterval); - if (ParamStr(15) = '1') then //HACK - cReducedQuality:= $FFFFFFFF xor rqLowRes - else - val(ParamStr(15), cReducedQuality); - end - else GameType:= gmtSyntax; - end; - else GameType:= gmtSyntax; - end; + playReplayFileWithParameters(); end; //////////////////////////////////////////////////////////////////////////////// diff -r 34fe2149f75d -r 09892cdb8f95 hedgewars/uChat.pas --- a/hedgewars/uChat.pas Fri Jul 30 19:56:28 2010 +0200 +++ b/hedgewars/uChat.pas Sat Jul 31 10:42:40 2010 +0200 @@ -29,7 +29,7 @@ procedure DrawChat; procedure KeyPressChat(Key: Longword); -var UserNick: shortstring; +var UserNick: shortstring = ''; ChatReady: boolean; showAll: boolean; @@ -316,7 +316,6 @@ begin lastStr:= 0; visibleCount:= 0; - UserNick:= ''; showAll:= false; ChatReady:= false; missedCount:= 0; @@ -324,7 +323,7 @@ procedure freeModule; begin - + UserNick:= ''; end; end. diff -r 34fe2149f75d -r 09892cdb8f95 hedgewars/uIO.pas --- a/hedgewars/uIO.pas Fri Jul 30 19:56:28 2010 +0200 +++ b/hedgewars/uIO.pas Sat Jul 31 10:42:40 2010 +0200 @@ -366,7 +366,6 @@ procedure freeModule; begin ipcPort:= 0; - end; end. diff -r 34fe2149f75d -r 09892cdb8f95 hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Fri Jul 30 19:56:28 2010 +0200 +++ b/hedgewars/uMisc.pas Sat Jul 31 10:42:40 2010 +0200 @@ -89,7 +89,7 @@ cShowFPS : boolean = false; cAltDamage : boolean = true; cReducedQuality : LongInt = rqNone; - + //userNick is in uChat recordFileName : shortstring = ''; cCaseFactor : Longword; @@ -259,12 +259,12 @@ begin // obsolete? written in WriteLnToConsole() anyway // {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} -WriteLnToConsole(Msg); -if isFatalError then + WriteLnToConsole(Msg); + if isFatalError then begin - SendIPC('E' + GetLastConsoleLine); - SDL_Quit; - halt(1) + SendIPC('E' + GetLastConsoleLine); + SDL_Quit; + halt(1) end end; @@ -796,6 +796,25 @@ flush(f); close(f); {$ENDIF} + + // re-init flags so they'll always contain safe values + cScreenWidth := 1024; + cScreenHeight := 768; + cBits := 32; + cBitsStr := '32'; + //ipcPort is in uIO + cFullScreen := false; + isSoundEnabled := true; + isMusicEnabled := false; + cLocaleFName := 'en.txt'; + cInitVolume := 50; + cTimerInterval := 8; + //pathPrefix is in uConsts + cShowFPS := false; + cAltDamage := true; + cReducedQuality := rqNone; + //userNick is in uChat + recordFileName := ''; end; end. diff -r 34fe2149f75d -r 09892cdb8f95 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Fri Jul 30 19:56:28 2010 +0200 +++ b/hedgewars/uWorld.pas Sat Jul 31 10:42:40 2010 +0200 @@ -1140,15 +1140,16 @@ if (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not fastUntilLag) then if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then - begin + begin FollowGear:= nil; prevPoint:= CursorPoint; exit - end - else begin + end + else + begin CursorPoint.X:= (prevPoint.X * 7 + hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100 + WorldDx) div 8; CursorPoint.Y:= (prevPoint.Y * 7 + cScreenHeight - (hwRound(FollowGear^.Y) + WorldDy)) div 8; - end; + end; wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater; if WorldDy < wdy then WorldDy:= wdy; @@ -1156,7 +1157,7 @@ if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit; if AMxShift < AMWidth then - begin +begin {$IFDEF IPHONEOS} if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth; if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset; @@ -1171,50 +1172,56 @@ prevPoint:= CursorPoint; if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y); exit - end; +end; if isCursorVisible then - begin +begin if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then - begin + begin SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy); PrevSentPointTime:= GameTicks + end; + EdgesDist:= cCursorEdgesDist +end +else + EdgesDist:= cGearScrEdgesDist; + +// this generates the border around the screen that moves the camera when cursor is near it +if isCursorVisible or (FollowGear <> nil) then +begin + if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then + begin + WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist; + CursorPoint.X:= - cScreenWidth div 2 + EdgesDist + end + else + if CursorPoint.X > cScreenWidth div 2 - EdgesDist then + begin + WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist; + CursorPoint.X:= cScreenWidth div 2 - EdgesDist end; + if CursorPoint.Y < EdgesDist then + begin + WorldDy:= WorldDy + CursorPoint.Y - EdgesDist; + CursorPoint.Y:= EdgesDist + end + else + if CursorPoint.Y > cScreenHeight - EdgesDist then + begin + WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist; + CursorPoint.Y:= cScreenHeight - EdgesDist + end; +end +else + if cHasFocus then + begin + WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; + WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y; + CursorPoint.X:= 0; + CursorPoint.Y:= cScreenHeight div 2; end; -if isCursorVisible or (FollowGear <> nil) then - begin - if isCursorVisible then EdgesDist:= cCursorEdgesDist - else EdgesDist:= cGearScrEdgesDist; - if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then - begin - WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist; - CursorPoint.X:= - cScreenWidth div 2 + EdgesDist - end else - if CursorPoint.X > cScreenWidth div 2 - EdgesDist then - begin - WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist; - CursorPoint.X:= cScreenWidth div 2 - EdgesDist - end; - if CursorPoint.Y < EdgesDist then - begin - WorldDy:= WorldDy + CursorPoint.Y - EdgesDist; - CursorPoint.Y:= EdgesDist - end else - if CursorPoint.Y > cScreenHeight - EdgesDist then - begin - WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist; - CursorPoint.Y:= cScreenHeight - EdgesDist - end; - end else - if cHasFocus then - begin - WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; - WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y; - CursorPoint.X:= 0; - CursorPoint.Y:= cScreenHeight div 2; - end; - +// this moves the camera according to CursorPoint X and Y prevPoint:= CursorPoint; if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y); if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024; diff -r 34fe2149f75d -r 09892cdb8f95 project_files/HedgewarsMobile/Classes/CGPointUtils.h --- a/project_files/HedgewarsMobile/Classes/CGPointUtils.h Fri Jul 30 19:56:28 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/CGPointUtils.h Sat Jul 31 10:42:40 2010 +0200 @@ -9,12 +9,16 @@ #import -#define degreesToRadian(x) (M_PI * x / 180.0) -#define radiansToDegrees(x) (180.0 * x / M_PI) +#define degreesToRadians(x) ( M_PI * x / 180.0) +#define radiansToDegrees(x) (180.0 * x / M_PI ) -#define HWX(x) (int)(x-screen.size.height/2) -#define HWY(x) (int)(screen.size.width-x) +// 40 is not a good value for iphone but works for ipad +#define HWX(x) (int)(x-screen.size.height/2)/HW_zoomFactor() +#define HWY(x) (int)(screen.size.width-x)/HW_zoomFactor() + 40*HW_zoomLevel()/HW_zoomFactor() + +#define HWXZ(x) (int)(x-screen.size.height/2) +#define HWYZ(x) (int)(screen.size.width-x) CGFloat distanceBetweenPoints (CGPoint first, CGPoint second); CGFloat angleBetweenPoints(CGPoint first, CGPoint second); -CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint lin2End); +CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End); diff -r 34fe2149f75d -r 09892cdb8f95 project_files/HedgewarsMobile/Classes/OverlayViewController.m --- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m Fri Jul 30 19:56:28 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m Sat Jul 31 10:42:40 2010 +0200 @@ -43,13 +43,13 @@ [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; switch (orientation) { case UIDeviceOrientationLandscapeLeft: - sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); - self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); + sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); + self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); HW_setLandscape(YES); break; case UIDeviceOrientationLandscapeRight: - sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); - self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); + sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); + self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); HW_setLandscape(YES); break; /* @@ -90,12 +90,12 @@ UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; switch (orientation) { case UIDeviceOrientationLandscapeLeft: - sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); - self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); + sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); + self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); break; case UIDeviceOrientationLandscapeRight: - sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); - self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); + sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); + self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); break; default: break; @@ -360,7 +360,7 @@ case 1: // if we're in the menu we just click in the point if (HW_isAmmoOpen()) { - HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); + HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y)); // this click doesn't need any wrapping because the ammoMenu already limits the cursor HW_click(); } else @@ -462,20 +462,26 @@ touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint currentPosition = [touch locationInView:self.view]; - if (HW_isAmmoOpen() || HW_isWeaponRequiringClick()) { - // moves the cursor around - HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); - } else { - // panning \o/ - dx = startingPoint.x - currentPosition.x; - dy = currentPosition.y - startingPoint.y; - HW_getCursor(&x, &y); - // momentum (or something like that) - if (abs(dx) > 40) dx *= log(abs(dx)/4); - if (abs(dy) > 40) dy *= log(abs(dy)/4); - HW_setCursor(x + dx, y + dy); - startingPoint = currentPosition; - } + if (HW_isAmmoOpen()) { + // no zoom consideration for this + HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y)); + } else + if (HW_isWeaponRequiringClick()) { + // moves the cursor around wrt zoom + HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); + } else { + // panning \o/ + dx = startingPoint.x - currentPosition.x; + dy = currentPosition.y - startingPoint.y; + HW_getCursor(&x, &y); + // momentum (or something like that) + /*if (abs(dx) > 40) + dx *= log(abs(dx)/4); + if (abs(dy) > 40) + dy *= log(abs(dy)/4);*/ + HW_setCursor(x + dx/HW_zoomFactor(), y + dy/HW_zoomFactor()); + startingPoint = currentPosition; + } break; case 2: first = [[allTouches allObjects] objectAtIndex:0]; diff -r 34fe2149f75d -r 09892cdb8f95 project_files/HedgewarsMobile/Classes/PascalImports.h --- a/project_files/HedgewarsMobile/Classes/PascalImports.h Fri Jul 30 19:56:28 2010 +0200 +++ b/project_files/HedgewarsMobile/Classes/PascalImports.h Sat Jul 31 10:42:40 2010 +0200 @@ -58,6 +58,9 @@ void HW_setPianoSound(int snd); + float HW_zoomFactor(void); + int HW_zoomLevel(void); + BOOL HW_isAmmoOpen(void); BOOL HW_isPaused(void); BOOL HW_isWeaponRequiringClick(void);