move all mobile-related functions in their own module, provides a structure for future mobile ports
--- a/hedgewars/CCHandlers.inc Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/CCHandlers.inc Thu Oct 07 02:03:01 2010 +0200
@@ -458,9 +458,6 @@
{$IFDEF DEBUGFILE}
AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));
{$ENDIF}
-{$IFDEF IPHONEOS}
- clearView();
-{$ENDIF}
end;
procedure chSay(var s: shortstring);
--- a/hedgewars/CMakeLists.txt Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/CMakeLists.txt Thu Oct 07 02:03:01 2010 +0200
@@ -59,6 +59,7 @@
uLandTexture.pas
uLocale.pas
uMisc.pas
+ uMobile.pas
uRandom.pas
uScript.pas
adler32.pas
--- a/hedgewars/PascalExports.pas Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/PascalExports.pas Thu Oct 07 02:03:01 2010 +0200
@@ -276,11 +276,31 @@
SetWeapon(TAmmoType(whichone+1));
end;
-function HW_getDelays: pByte; cdecl; export;
+function HW_getAmmoCounts: PByte; cdecl; export;
+var counts : PByte;
+ a : PHHAmmo;
+ slot, index: LongInt;
+begin
+ if (CurrentTeam^.ExtDriven) or (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then
+ exit(nil);
+ a:= CurrentHedgehog^.Ammo;
+ GetMem(counts,ord(High(TAmmoType)));
+ FillChar(counts^,ord(High(TAmmoType)),0);
+ for slot:= 0 to cMaxSlotIndex do
+ for index:= 0 to cMaxSlotAmmoIndex do
+ counts[ord(a^[slot,index].AmmoType)-1]:= byte(a^[slot,index].Count);
+ exit(counts);
+ // leak?
+end;
+
+function HW_getAmmoDelays: PByte; cdecl; export;
var skipTurns : PByte;
a : TAmmoType;
begin
+ if (CurrentTeam^.ExtDriven) or (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then
+ exit(nil);
GetMem(skipTurns,ord(High(TAmmoType)));
+ FillChar(skipTurns^,ord(High(TAmmoType)),0);
for a:= Low(TAmmoType) to High(TAmmoType) do
skipTurns[ord(a)-1]:= byte(Ammoz[a].SkipTurns);
exit(skipTurns);
--- a/hedgewars/SDLh.pas Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/SDLh.pas Thu Oct 07 02:03:01 2010 +0200
@@ -842,15 +842,6 @@
function SDLNet_Read16(buf: pointer): Word;
function SDLNet_Read32(buf: pointer): LongWord;
-{$IFDEF IPHONEOS}
-(* iPhone related calls *)
-procedure clearView; cdecl; external;
-procedure startSpinning; cdecl; external;
-procedure stopSpinning; cdecl; external;
-function isPhone: Boolean; cdecl; external;
-procedure replayBegan; cdecl; external;
-procedure replayFinished; cdecl; external;
-{$ENDIF}
implementation
function SDL_MustLock(Surface: PSDL_Surface): Boolean;
--- a/hedgewars/hwengine.pas Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/hwengine.pas Thu Oct 07 02:03:01 2010 +0200
@@ -30,7 +30,7 @@
{$ENDIF}
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;
+ uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, uMobile, sysutils;
var isTerminated: boolean = false;
alsoShutdownFrontend: boolean = false;
@@ -285,9 +285,7 @@
else
begin
LoadRecordFromFile(recordFileName);
-{$IFDEF IPHONEOS}
- replayBegan();
-{$ENDIF}
+ doSomethingWhen_SaveBeganSynching();
end;
ScriptOnGameInit;
--- a/hedgewars/uAIAmmoTests.pas Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/uAIAmmoTests.pas Thu Oct 07 02:03:01 2010 +0200
@@ -106,7 +106,7 @@
const BadTurn = Low(LongInt) div 4;
implementation
-uses uMisc, uAIMisc, uLand, uTeams;
+uses uMisc, uAIMisc, uLand;
function Metric(x1, y1, x2, y2: LongInt): LongInt;
begin
--- a/hedgewars/uGame.pas Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/uGame.pas Thu Oct 07 02:03:01 2010 +0200
@@ -26,7 +26,7 @@
////////////////////
implementation
////////////////////
-uses uMisc, uConsts, uKeys, uTeams, uIO, uAI, uGears, uScript, uSound, SDLh;
+uses uMisc, uConsts, uKeys, uTeams, uIO, uAI, uGears, uScript, uSound, uMobile;
procedure DoGameTick(Lag: LongInt);
var i: LongInt;
@@ -68,9 +68,7 @@
if isSoundEnabled then playMusic;
GameType:= gmtLocal;
InitIPC;
-{$IFDEF IPHONEOS}
- replayFinished();
-{$ENDIF}
+ doSomethingWhen_SaveFinishedSynching();
end;
end
else ProcessGears
--- a/hedgewars/uMisc.pas Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/uMisc.pas Thu Oct 07 02:03:01 2010 +0200
@@ -196,7 +196,7 @@
procedure MakeScreenshot(filename: shortstring);
implementation
-uses uConsole, uStore, uIO, uSound, typinfo, sysutils;
+uses uConsole, uStore, uIO, uSound, typinfo, sysutils, uMobile;
var KBnum: Longword;
{$IFDEF DEBUGFILE}
@@ -791,21 +791,20 @@
ScreenFade := sfNone;
+{$IFDEF SDL13}
+ SDLwindow := nil;
+{$ENDIF}
+
// those values still aren't perfect
cLeftScreenBorder:= round(-cMinZoomLevel * cScreenWidth);
cRightScreenBorder:= round(cMinZoomLevel * cScreenWidth + LAND_WIDTH);
cScreenSpace:= cRightScreenBorder - cLeftScreenBorder;
-{$IFDEF IPHONEOS}
if isPhone() then
cMaxCaptions:= 3
else
-{$ENDIF}
cMaxCaptions:= 4;
-{$IFDEF SDL13}
- SDLwindow := nil;
-{$ENDIF}
{$IFDEF DEBUGFILE}
{$I-}
{$IFDEF IPHONEOS}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/uMobile.pas Thu Oct 07 02:03:01 2010 +0200
@@ -0,0 +1,94 @@
+(*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *)
+
+{$INCLUDE "options.inc"}
+
+unit uMobile;
+interface
+
+{$IFDEF IPHONEOS}
+(* iOS calls written in C/Objc *)
+procedure clearView; cdecl; external;
+procedure startSpinning; cdecl; external;
+procedure stopSpinning; cdecl; external;
+procedure replayBegan; cdecl; external;
+procedure replayFinished; cdecl; external;
+procedure updateVisualsNewTurn; cdecl; external;
+function isApplePhone: Boolean; cdecl; external;
+{$ENDIF}
+function isPhone: Boolean;
+procedure doRumble;
+procedure doSomethingWhen_AddProgress;
+procedure doSomethingWhen_FinishProgress;
+procedure doSomethingWhen_NewTurnBeginning;
+procedure doSomethingWhen_SaveBeganSynching;
+procedure doSomethingWhen_SaveFinishedSynching;
+
+implementation
+
+function isPhone: Boolean;
+begin
+{$IFDEF IPHONEOS}
+ exit(isApplePhone());
+{$ENDIF}
+ exit(false);
+end;
+
+procedure doRumble;
+begin
+ // fill me!
+end;
+
+procedure doSomethingWhen_AddProgress;
+begin
+{$IFDEF IPHONEOS}
+ startSpinning();
+{$ENDIF}
+end;
+
+procedure doSomethingWhen_FinishProgress;
+begin
+{$IFDEF IPHONEOS}
+ stopSpinning();
+{$ENDIF}
+end;
+
+procedure doSomethingWhen_NewTurnBeginning;
+begin
+{$IFDEF IPHONEOS}
+ clearView();
+ updateVisualsNewTurn();
+{$ENDIF}
+end;
+
+procedure doSomethingWhen_SaveBeganSynching;
+begin
+{$IFDEF IPHONEOS}
+ replayBegan();
+{$ENDIF}
+end;
+
+procedure doSomethingWhen_SaveFinishedSynching;
+begin
+{$IFDEF IPHONEOS}
+ replayFinished();
+{$ENDIF}
+end;
+
+
+end.
--- a/hedgewars/uStore.pas Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/uStore.pas Thu Oct 07 02:03:01 2010 +0200
@@ -80,7 +80,7 @@
procedure Tint(c: Longword); inline;
implementation
-uses uMisc, uConsole, uLocale;
+uses uMisc, uConsole, uLocale, uMobile;
type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
@@ -1138,10 +1138,12 @@
end;
procedure SetupOpenGL;
+{$IFNDEF IPHONEOS}
var vendor: shortstring;
{$IFDEF DARWIN}
one: LongInt;
{$ENDIF}
+{$ENDIF}
begin
{$IFDEF IPHONEOS}
@@ -1149,6 +1151,7 @@
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
{$ELSE}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
{$IFNDEF SDL13}
// this attribute is default in 1.3 and must be enabled in MacOSX
if (cReducedQuality and rqDesyncVBlank) <> 0 then
@@ -1172,7 +1175,6 @@
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
- vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
{$IFDEF DEBUGFILE}
AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER))));
AddFileLog(' |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR))));
@@ -1268,9 +1270,8 @@
squaresize:= texsurf^.w shr 1;
numsquares:= texsurf^.h div squaresize;
SDL_FreeSurface(texsurf);
-{$IFDEF IPHONEOS}
- startSpinning();
-{$ENDIF}
+
+ doSomethingWhen_AddProgress();
end;
TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
@@ -1297,9 +1298,7 @@
begin
WriteLnToConsole('Freeing progress surface... ');
FreeTexture(ProgrTex);
-{$IFDEF IPHONEOS}
- stopSpinning();
-{$ENDIF}
+ doSomethingWhen_FinishProgress();
end;
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
--- a/hedgewars/uTeams.pas Wed Oct 06 02:31:04 2010 +0200
+++ b/hedgewars/uTeams.pas Thu Oct 07 02:03:01 2010 +0200
@@ -114,10 +114,10 @@
function CheckForWin: boolean;
procedure TeamGone(s: shortstring);
procedure TeamGoneEffect(var Team: TTeam);
-function GetTeamStatString(p: PTeam): shortstring;
+function GetTeamStatString(p: PTeam): shortstring;
implementation
-uses uMisc, uWorld, uLocale, uAmmos, uChat;
+uses uMisc, uWorld, uLocale, uAmmos, uChat, uMobile;
const MaxTeamHealth: LongInt = 0;
function CheckForWin: boolean;
@@ -224,7 +224,8 @@
end
until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil);
-CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog])
+CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]);
+doSomethingWhen_NewTurnBeginning();
end;
procedure AfterSwitchHedgehog;
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Wed Oct 06 02:31:04 2010 +0200
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Thu Oct 07 02:03:01 2010 +0200
@@ -49,6 +49,7 @@
61272339117DF778005B90CF /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61272338117DF778005B90CF /* MobileCoreServices.framework */; };
6129B9F711EFB04D0017E305 /* denied.png in Resources */ = {isa = PBXBuildFile; fileRef = 6129B9F611EFB04D0017E305 /* denied.png */; };
61370653117B1D50004EE44A /* Entitlements-Distribution.plist in Resources */ = {isa = PBXBuildFile; fileRef = 61370652117B1D50004EE44A /* Entitlements-Distribution.plist */; };
+ 61399013125D19C0003C2DC0 /* uMobile.pas in Sources */ = {isa = PBXBuildFile; fileRef = 61399012125D19C0003C2DC0 /* uMobile.pas */; };
6147DAD31253DCDE0010357E /* savesButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 6147DAD21253DCDE0010357E /* savesButton.png */; };
61536DF411CEAE7100D87A7E /* GameConfigViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924A11CA9CB400D6E256 /* GameConfigViewController.xib */; };
615AD96212073B4D00F2FF04 /* startGameButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 615AD96112073B4D00F2FF04 /* startGameButton.png */; };
@@ -83,9 +84,7 @@
6165923111CA9BD500D6E256 /* SquareButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165922B11CA9BD500D6E256 /* SquareButtonView.m */; };
6165923211CA9BD500D6E256 /* UIImageExtra.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165922D11CA9BD500D6E256 /* UIImageExtra.m */; };
6165925311CA9CB400D6E256 /* MainMenuViewController-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924B11CA9CB400D6E256 /* MainMenuViewController-iPad.xib */; };
- 6165925411CA9CB400D6E256 /* MainMenuViewController-iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924C11CA9CB400D6E256 /* MainMenuViewController-iPhone.xib */; };
6165925511CA9CB400D6E256 /* MapConfigViewController-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924D11CA9CB400D6E256 /* MapConfigViewController-iPad.xib */; };
- 6165925611CA9CB400D6E256 /* MapConfigViewController-iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924E11CA9CB400D6E256 /* MapConfigViewController-iPhone.xib */; };
6165925811CA9CB400D6E256 /* OverlayViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165925011CA9CB400D6E256 /* OverlayViewController.xib */; };
6165929E11CA9E2F00D6E256 /* SDL_uikitappdelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165929D11CA9E2F00D6E256 /* SDL_uikitappdelegate.m */; };
61798816114AA34C00BA94A9 /* hwengine.pas in Sources */ = {isa = PBXBuildFile; fileRef = 617987E7114AA34C00BA94A9 /* hwengine.pas */; };
@@ -745,6 +744,7 @@
61272338117DF778005B90CF /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
6129B9F611EFB04D0017E305 /* denied.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = denied.png; path = Resources/denied.png; sourceTree = "<group>"; };
61370652117B1D50004EE44A /* Entitlements-Distribution.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Entitlements-Distribution.plist"; sourceTree = "<group>"; };
+ 61399012125D19C0003C2DC0 /* uMobile.pas */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = uMobile.pas; path = ../../hedgewars/uMobile.pas; sourceTree = SOURCE_ROOT; };
6147DAD21253DCDE0010357E /* savesButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = savesButton.png; path = Resources/savesButton.png; sourceTree = "<group>"; };
614E333D11DE9A93009DBA4E /* VGSHandlers.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = VGSHandlers.inc; path = ../../hedgewars/VGSHandlers.inc; sourceTree = SOURCE_ROOT; };
615AD96112073B4D00F2FF04 /* startGameButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = startGameButton.png; path = "Resources/Frontend-iPad/startGameButton.png"; sourceTree = "<group>"; };
@@ -1414,6 +1414,7 @@
9283015C0F10E48900CC5A3C /* Pascal Sources */ = {
isa = PBXGroup;
children = (
+ 61399012125D19C0003C2DC0 /* uMobile.pas */,
619C5AF3124F7E3100D041AE /* LuaPas.pas */,
61798892114AA56300BA94A9 /* inc */,
61E1F4F711D004240016A5AA /* adler32.pas */,
@@ -2080,9 +2081,7 @@
61370653117B1D50004EE44A /* Entitlements-Distribution.plist in Resources */,
611E12FF117BBBDA0044B62F /* Entitlements-Development.plist in Resources */,
6165925311CA9CB400D6E256 /* MainMenuViewController-iPad.xib in Resources */,
- 6165925411CA9CB400D6E256 /* MainMenuViewController-iPhone.xib in Resources */,
6165925511CA9CB400D6E256 /* MapConfigViewController-iPad.xib in Resources */,
- 6165925611CA9CB400D6E256 /* MapConfigViewController-iPhone.xib in Resources */,
6165925811CA9CB400D6E256 /* OverlayViewController.xib in Resources */,
61EF920E11DF57AC003441C4 /* arrowDown.png in Resources */,
61EF920F11DF57AC003441C4 /* arrowLeft.png in Resources */,
@@ -2261,6 +2260,7 @@
619C5AF4124F7E3100D041AE /* LuaPas.pas in Sources */,
619C5BA2124FA59000D041AE /* MapPreviewButtonView.m in Sources */,
61DE8F221257EB1100B80214 /* AmmoMenuViewController.m in Sources */,
+ 61399013125D19C0003C2DC0 /* uMobile.pas in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};