* fix initialisation, preload values and then read args
authorkoda
Sun, 28 Oct 2012 03:48:37 +0100
changeset 7848 775a72905708
parent 7847 a595d4f4837d
child 7849 a12155461b34
* fix initialisation, preload values and then read args * respect audio and music settings * a few variables cleanup
hedgewars/ArgParsers.inc
hedgewars/hwengine.pas
hedgewars/uInputHandler.pas
hedgewars/uMisc.pas
hedgewars/uSound.pas
hedgewars/uVariables.pas
--- a/hedgewars/ArgParsers.inc	Sun Oct 28 03:12:49 2012 +0100
+++ b/hedgewars/ArgParsers.inc	Sun Oct 28 03:48:37 2012 +0100
@@ -16,20 +16,6 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  *)
 
-procedure playReplayFileWithParameters(); forward;
-
-procedure internalSetGameTypeLandPreviewFromParameters();
-begin
-    if ParamStr(3) = '--stats-only' then
-        playReplayFileWithParameters()
-    else
-        begin
-        ipcPort:= StrToInt(ParamStr(2));
-        GameType:= gmtLandPreview;
-        if ParamStr(3) <> 'landpreview' then
-            GameType:= gmtSyntax
-        end
-end;
 
 procedure internalStartGameWithParameters();
 var tmp: LongInt;
--- a/hedgewars/hwengine.pas	Sun Oct 28 03:12:49 2012 +0100
+++ b/hedgewars/hwengine.pas	Sun Oct 28 03:48:37 2012 +0100
@@ -317,8 +317,7 @@
     i: LongInt;
 begin
 {$IFDEF HWLIBRARY}
-    cBits:= 32;
-    cTimerInterval:= 8;
+    initEverything(true);
     cShowFPS:= {$IFDEF DEBUGFILE}true{$ELSE}false{$ENDIF};
     ipcPort:= StrToInt(gameArgs[0]);
     cScreenWidth:= StrToInt(gameArgs[1]);
@@ -347,7 +346,6 @@
     cOrigScreenWidth:= cScreenWidth;
     cOrigScreenHeight:= cScreenHeight;
 
-    initEverything(true);
     WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
     AddFileLog('Prefix: "' + PathPrefix +'"');
     AddFileLog('UserPrefix: "' + UserPathPrefix +'"');
@@ -540,8 +538,8 @@
 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF};
 var Preview: TPreview;
 begin
+{$IFDEF HWLIBRARY}
     initEverything(false);
-{$IFDEF HWLIBRARY}
     WriteLnToConsole('Preview connecting on port ' + inttostr(port));
     ipcPort:= port;
     InitStepsFlags:= cifRandomize;
@@ -593,16 +591,28 @@
     if (ParamCount < 3) then
         GameType:= gmtSyntax
     else
-        if (ParamCount = 3) and ((ParamStr(3) = '--stats-only') or (ParamStr(3) = 'landpreview')) then
-            internalSetGameTypeLandPreviewFromParameters()
-        else if ParamCount = cDefaultParamNum then
-            internalStartGameWithParameters()
+        if (ParamCount = 3) and (ParamStr(3) = 'landpreview') then
+            begin
+            initEverything(false);
+            ipcPort:= StrToInt(ParamStr(2));
+            GameType:= gmtLandPreview;
+            exit;
+            end
+        else
+            begin
+            initEverything(true);
+            if (ParamCount = 3) and (ParamStr(3) = '--stats-only') then
+                playReplayFileWithParameters()
+            else
+                if ParamCount = cDefaultParamNum then
+                    internalStartGameWithParameters()
 {$IFDEF USE_VIDEO_RECORDING}
-        else if ParamCount = cVideorecParamNum then
-            internalStartVideoRecordingWithParameters()
+                else if ParamCount = cVideorecParamNum then
+                    internalStartVideoRecordingWithParameters()
 {$ENDIF}
-        else
-            playReplayFileWithParameters();
+                else
+                    playReplayFileWithParameters();
+            end
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/hedgewars/uInputHandler.pas	Sun Oct 28 03:12:49 2012 +0100
+++ b/hedgewars/uInputHandler.pas	Sun Oct 28 03:48:37 2012 +0100
@@ -426,8 +426,6 @@
 
 procedure initModule;
 begin
-    wheelUp:= false;
-    wheelDown:= false;
 end;
 
 procedure freeModule;
--- a/hedgewars/uMisc.pas	Sun Oct 28 03:12:49 2012 +0100
+++ b/hedgewars/uMisc.pas	Sun Oct 28 03:48:37 2012 +0100
@@ -311,7 +311,6 @@
 
 procedure freeModule;
 begin
-    recordFileName:= '';
     SDL_FreeFormat(conversionFormat);
 end;
 
--- a/hedgewars/uSound.pas	Sun Oct 28 03:12:49 2012 +0100
+++ b/hedgewars/uSound.pas	Sun Oct 28 03:48:37 2012 +0100
@@ -47,7 +47,7 @@
 
 // Obvious music commands for music track
 procedure SetMusic(enabled: boolean);           // Enable/disable music.
-procedure SetMusicName(musicname: shortstring); // Enable/disable music and set name of the file to play.
+procedure SetMusicName(musicname: shortstring); // Set name of the file to play.
 procedure PlayMusic;                            // Play music from the start.
 procedure PauseMusic;                           // Pause music.
 procedure ResumeMusic;                          // Resume music from pause point.
@@ -95,7 +95,7 @@
 // MISC
 
 // Set the initial volume
-procedure SetVolume(volume: LongInt);
+procedure SetVolume(vol: LongInt);
 
 // Modifies the sound volume of the game by voldelta and returns the new volume level.
 function  ChangeVolume(voldelta: LongInt): LongInt;
@@ -114,7 +114,7 @@
     lastChan: array [TSound] of LongInt;
     voicepacks: array[0..cMaxTeams] of TVoicepack;
     defVoicepack: PVoicepack;
-    Mus: PMixMusic = nil; // music pointer
+    Mus: PMixMusic; // music pointer
     MusicFN: shortstring; // music file name
     isMusicEnabled: boolean;
     isSoundEnabled: boolean;
@@ -445,15 +445,15 @@
     SDLTry(Mix_FadeInMusic(Mus, -1, 3000) <> -1, false)
 end;
 
-procedure SetVolume(volume: LongInt);
+procedure SetVolume(vol: LongInt);
 begin
-    cInitVolume:= volume;
+    cInitVolume:= vol;
 end;
 
 function ChangeVolume(voldelta: LongInt): LongInt;
 begin
     ChangeVolume:= 0;
-    if (not isSoundEnabled) or (voldelta = 0) then
+    if (not isSoundEnabled) or ((voldelta = 0) and not (cInitVolume = 0)) then
         exit;
 
     inc(Volume, voldelta);
@@ -494,7 +494,7 @@
 procedure MuteAudio;
 begin
     if (not isSoundEnabled) then
-    exit;
+        exit;
 
     if (isAudioMuted) then
     begin
@@ -514,12 +514,10 @@
 procedure SetMusic(enabled: boolean);
 begin
     isMusicEnabled:= enabled;
-    MusicFN:= '';
 end;
 
 procedure SetMusicName(musicname: shortstring);
 begin
-    isMusicEnabled:= not (musicname = '');    
     MusicFN:= musicname;
 end;
 
@@ -587,9 +585,13 @@
     RegisterVariable('mute'     , @chMute     , true );
 
     MusicFN:='';
+    Mus:= nil;
+    isMusicEnabled:= true;
+    isSoundEnabled:= true;
     isAudioMuted:= false;
     isSEBackup:= isSoundEnabled;
     Volume:= 0;
+    cInitVolume:= 100;
     defVoicepack:= AskForVoicepack('Default');
 
     for i:= Low(TSound) to High(TSound) do
@@ -602,7 +604,7 @@
                 voicepacks[t].chunks[i]:= nil;
 
     (* on MOBILE SDL_mixer has to be compiled against Tremor (USE_OGG_TREMOR)
-       or sound files bigger than 32k will lockup the game*)
+       or sound files bigger than 32k will lockup the game *)
     for i:= Low(TSound) to High(TSound) do
         defVoicepack^.chunks[i]:= nil;
 
@@ -612,11 +614,6 @@
 begin
     if isSoundEnabled then
         ReleaseSound(true);
-    // koda still needs to fix this properly.  when he rearranged things, he made these variables get
-    // reset after argparsers picks them up
-    isMusicEnabled:= true;
-    isSoundEnabled:= true;
-    cInitVolume:= 100;
 end;
 
 end.
--- a/hedgewars/uVariables.pas	Sun Oct 28 03:12:49 2012 +0100
+++ b/hedgewars/uVariables.pas	Sun Oct 28 03:48:37 2012 +0100
@@ -25,45 +25,44 @@
 
 var
 /////// init flags ///////
-    cMinScreenWidth    : LongInt     = 640;
-    cMinScreenHeight   : LongInt     = 480;
-    cScreenWidth       : LongInt     = 1024;
-    cScreenHeight      : LongInt     = 768;
-    cOrigScreenWidth   : LongInt     = 1024;
-    cOrigScreenHeight  : LongInt     = 768;
-    cNewScreenWidth    : LongInt     = 1024;
-    cNewScreenHeight   : LongInt     = 768;
-    cScreenResizeDelay : LongWord    = 0;
-    cBits           : LongInt     = 32;
-    ipcPort         : Word        = 0;
-    cFullScreen     : boolean     = false;
-    cLocaleFName    : shortstring = 'en.txt';
-    cLocale         : shortstring = 'en';
-    cTimerInterval  : LongInt     = 8;
-    PathPrefix      : shortstring = './';
-    UserPathPrefix  : shortstring = './';
-    cShowFPS        : boolean     = false;
-    cFlattenFlakes  : boolean     = false;
-    cFlattenClouds  : boolean     = false;
-    cAltDamage      : boolean     = true;
-    cReducedQuality : LongWord    = rqNone;
-    UserNick        : shortstring = '';
-    recordFileName  : shortstring = '';
-    cReadyDelay     : Longword    = 5000;
-    cStereoMode     : TStereoMode = smNone;
-    cOnlyStats      : boolean = False;
+    cMinScreenWidth    : LongInt;
+    cMinScreenHeight   : LongInt;
+    cScreenWidth       : LongInt;
+    cScreenHeight      : LongInt;
+    cOrigScreenWidth   : LongInt;
+    cOrigScreenHeight  : LongInt;
+    cNewScreenWidth    : LongInt;
+    cNewScreenHeight   : LongInt;
+    cScreenResizeDelay : LongWord;
+    cBits              : LongInt;
+    ipcPort            : Word;
+    cFullScreen        : boolean;
+    cLocaleFName       : shortstring;
+    cLocale            : shortstring;
+    cTimerInterval     : LongInt;
+    PathPrefix         : shortstring;
+    UserPathPrefix     : shortstring;
+    cShowFPS           : boolean;
+    cFlattenFlakes     : boolean;
+    cFlattenClouds     : boolean;
+    cAltDamage         : boolean;
+    cReducedQuality    : LongWord;
+    UserNick           : shortstring;
+    recordFileName     : shortstring;
+    cReadyDelay        : Longword;
+    cStereoMode        : TStereoMode;
+    cOnlyStats         : boolean;
 {$IFDEF USE_VIDEO_RECORDING}
-    RecPrefix      : shortstring;
-    cAVFormat       : shortstring;
-    cVideoCodec     : shortstring;
+    RecPrefix          : shortstring;
+    cAVFormat          : shortstring;
+    cVideoCodec        : shortstring;
     cVideoFramerateNum : LongInt;
     cVideoFramerateDen : LongInt;
     cVideoQuality      : LongInt;
-    cAudioCodec     : shortstring;
+    cAudioCodec        : shortstring;
 {$ENDIF}
 //////////////////////////
-    cMapName        : shortstring = '';
-
+    cMapName        : shortstring;
     isCursorVisible : boolean;
     isInLag         : boolean;
     isPaused        : boolean;
@@ -111,7 +110,7 @@
 
     cWaterLine       : Word;
     cGearScrEdgesDist: LongInt;
-	isAudioMuted     : boolean;
+    isAudioMuted     : boolean;
 
     // originally typed consts
     ExplosionBorderColor: LongWord;
@@ -2511,8 +2510,6 @@
     vobSDVelocity, vobSDFallSpeed: LongInt;
 
     hideAmmoMenu: boolean;
-    wheelUp: boolean;
-    wheelDown: boolean;
 
     ControllerNumControllers: Integer;
     ControllerEnabled: Integer;
@@ -2543,6 +2540,32 @@
 
 procedure initModule;
 begin
+    // initialisation flags - they are going to be overwritten by args or by msgs
+    cScreenWidth    := 1024;
+    cScreenHeight   := 768;
+    cBits           := 32;
+    ipcPort         := 0;
+    cFullScreen     := false;
+    cLocaleFName    := 'en.txt';
+    cLocale         := 'en';
+    cTimerInterval  := 8;
+    PathPrefix      := './';
+    UserPathPrefix  := './';
+    cShowFPS        := false;
+    cFlattenFlakes  := false;
+    cFlattenClouds  := false;
+    cAltDamage      := true;
+    cReducedQuality := rqNone;
+    UserNick        := '';
+    recordFileName  := '';
+    cScriptName     := '';
+    cReadyDelay     := 5000;
+    cStereoMode     := smNone;
+    GrayScale       := false;
+
+    cFlattenFlakes  := false;
+    cFlattenClouds  := false;
+    cOnlyStats      := False;
     lastVisualGearByUID:= nil;
     lastGearByUID:= nil;
     
@@ -2577,8 +2600,10 @@
     SDWaterColorArray[2].a := 255;
     SDWaterColorArray[1]:= SDWaterColorArray[0];
     SDWaterColorArray[3]:= SDWaterColorArray[2];
-
+    SDWaterOpacity:= $80;
     SDTint:= $80;
+    ExplosionBorderColor:= $FF808080;
+    WaterOpacity:= $80;
 
     cDrownSpeed.QWordValue  := 257698038;       // 0.06
     cDrownSpeedf            := 0.06;
@@ -2628,7 +2653,6 @@
     cExplosives     := 2;
 
     GameState       := Low(TGameState);
-//    GameType        := gmtLocal;
     zoom            := cDefaultZoomLevel;
     ZoomValue       := cDefaultZoomLevel;
     WeaponTooltipTex:= nil;
@@ -2675,11 +2699,18 @@
     vobSDVelocity:= 15;
     vobSDFallSpeed:= 250;
 
-    ExplosionBorderColor:= $FF808080;
-    WaterOpacity:= $80;
-    SDWaterOpacity:= $80;
+    cMinScreenWidth    := 640;
+    cMinScreenHeight   := 480;
+    cScreenWidth       := 1024;
+    cScreenHeight      := 768;
+    cOrigScreenWidth   := 1024;
+    cOrigScreenHeight  := 768;
+    cNewScreenWidth    := 1024;
+    cNewScreenHeight   := 768;
+    cScreenResizeDelay := 0;
 
     LuaGoals:= '';
+    cMapName:= '';
 
     LuaTemplateNumber:= 0;
     hiddenHedgehogsNumber:=0;
@@ -2687,27 +2718,6 @@
 
 procedure freeModule;
 begin
-    // re-init flags so they will always contain safe values
-    cScreenWidth    := 1024;
-    cScreenHeight   := 768;
-    cBits           := 32;
-    ipcPort         := 0;
-    cFullScreen     := false;
-    cLocaleFName    := 'en.txt';
-    cTimerInterval  := 8;
-    PathPrefix      := './';
-    UserPathPrefix  := './';
-    cShowFPS        := false;
-    cFlattenFlakes  := false;
-    cFlattenClouds  := false;
-    cAltDamage      := true;
-    cReducedQuality := rqNone;
-    UserNick        := '';
-    recordFileName  := '';
-    cScriptName     := '';
-    cReadyDelay     := 5000;
-    cStereoMode     := smNone;
-    GrayScale       := false;
 end;
 
 end.