--- a/hedgewars/hwengine.pas Thu Aug 26 23:59:18 2010 +0200
+++ b/hedgewars/hwengine.pas Wed Oct 27 14:02:20 2010 +0200
@@ -29,10 +29,9 @@
program hwengine;
{$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;
-
-type arrayofpchar = array[0..9] of PChar;
+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, uMobile, sysutils;
+
var isTerminated: boolean = false;
alsoShutdownFrontend: boolean = false;
@@ -136,7 +135,7 @@
end;
///////////////////
-procedure MainLoop;
+procedure MainLoop;
var PrevTime, CurrTime: Longword;
event: TSDL_Event;
begin
@@ -176,11 +175,11 @@
if isTerminated = false then
begin
CurrTime:= SDL_GetTicks;
- if PrevTime + cTimerInterval <= CurrTime then
+ if PrevTime + longword(cTimerInterval) <= CurrTime then
begin
DoTimer(CurrTime - PrevTime);
PrevTime:= CurrTime
- end
+ end
else SDL_Delay(1);
IPCCheckSock();
end;
@@ -197,7 +196,7 @@
///////////////
{$IFDEF HWLIBRARY}
-procedure Game(gameArgs: arrayofpchar); cdecl; export;
+procedure Game(gameArgs: PPChar); cdecl; export;
{$ELSE}
procedure Game;
{$ENDIF}
@@ -215,24 +214,23 @@
{$IFDEF DEBUGFILE}
cShowFPS:= true;
{$ELSE}
- cShowFPS:= true; // update me at release time
+ cShowFPS:= false;
{$ENDIF}
- cInitVolume:= 100;
-
- UserNick:= gameArgs[0];
- val(gameArgs[1], ipcPort);
- isSoundEnabled:= gameArgs[2] = '1';
- isMusicEnabled:= gameArgs[3] = '1';
+ val(gameArgs[0], ipcPort);
+ val(gameArgs[1], cScreenWidth);
+ val(gameArgs[2], cScreenHeight);
+ val(gameArgs[3], cReducedQuality);
cLocaleFName:= gameArgs[4];
- cAltDamage:= gameArgs[5] = '1';
- val(gameArgs[6], cScreenHeight);
- val(gameArgs[7], cScreenWidth);
- recordFileName:= gameArgs[8];
-
- val(gameArgs[9], cReducedQuality);
+ UserNick:= gameArgs[5];
+ isSoundEnabled:= gameArgs[6] = '1';
+ isMusicEnabled:= gameArgs[7] = '1';
+ cAltDamage:= gameArgs[8] = '1';
+ val(gameArgs[9], rotationQt);
+ recordFileName:= gameArgs[10];
cStereoMode:= smNone; // TODO: Enable anaglyph rendering on iPhone?
{$ENDIF}
+ cLogfileBase:= 'game';
initEverything(true);
WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
@@ -244,7 +242,7 @@
for p:= Succ(Low(TPathType)) to High(TPathType) do
if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p];
-
+
WriteToConsole('Init SDL... ');
SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true);
WriteLnToConsole(msgOK);
@@ -269,23 +267,26 @@
ControllerInit(); // has to happen before InitKbdKeyTable to map keys
InitKbdKeyTable();
- if recordFileName = '' then
- InitIPC;
- WriteLnToConsole(msgGettingConfig);
-
LoadLocale(Pathz[ptLocale] + '/en.txt'); // Do an initial load with english
if cLocaleFName <> 'en.txt' then
begin
// Try two letter locale first before trying specific locale overrides
- if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then
+ if (Length(cLocaleFName) > 6) and (Copy(cLocaleFName,1,2)+'.txt' <> 'en.txt') then
LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocaleFName,1,2)+'.txt');
LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName);
end;
+ WriteLnToConsole(msgGettingConfig);
if recordFileName = '' then
- SendIPCAndWaitReply('C') // ask for game config
+ begin
+ InitIPC;
+ SendIPCAndWaitReply('C'); // ask for game config
+ end
else
+ begin
LoadRecordFromFile(recordFileName);
+ perfExt_SaveBeganSynching();
+ end;
ScriptOnGameInit;
@@ -316,13 +317,13 @@
begin
Randomize();
- uConsts.initModule;
+ // uConsts does not need initialization as they are all consts
uMisc.initModule;
uConsole.initModule; // MUST happen after uMisc
uLand.initModule;
uIO.initModule;
-
+
if complete then
begin
uAI.initModule;
@@ -341,7 +342,7 @@
//uLandTemplates does not need initialization
uLandTexture.initModule;
//uLocale does not need initialization
- uRandom.initModule;
+ uRandom.initModule;
uScript.initModule;
uSound.initModule;
uStats.initModule;
@@ -381,19 +382,19 @@
//uAIActions does not need to be freed
uAI.freeModule; //stub
end;
-
+
uIO.freeModule; //stub
uLand.freeModule;
uConsole.freeModule;
uMisc.freeModule; // uMisc closes the debug log.
- uConsts.freeModule; //stub
end;
/////////////////////////
procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF};
var Preview: TPreview;
begin
+ cLogfileBase:= 'preview';
initEverything(false);
{$IFDEF HWLIBRARY}
WriteLnToConsole('Preview connecting on port ' + inttostr(port));
@@ -419,134 +420,38 @@
begin
WriteLn('Wrong argument format: correct configurations is');
WriteLn();
- WriteLn(' hwengine <path to data folder> <path to replay file> [option]');
+ WriteLn(' hwengine <path to data folder> <path to replay file> [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;
-var i : LongInt;
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';
- val(ParamStr(18), cReducedQuality);
- val(ParamStr(19), i);
- cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), i)));
- 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 = cDefaultParamNum) 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;
////////////////////////////////////////////////////////////////////////////////
@@ -558,7 +463,7 @@
if GameType = gmtLandPreview then GenLandPreview()
else if GameType = gmtSyntax then DisplayUsage()
else Game();
-
+
if GameType = gmtSyntax then
ExitCode:= 1
else