a little code cleanup
authorkoda
Fri, 30 Sep 2011 12:55:04 +0200
changeset 6072 e3dc802965d6
parent 6071 212e5a5eadeb
child 6073 e6ce1a337e0f
a little code cleanup
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uSound.pas
hedgewars/uStore.pas
--- a/hedgewars/SDLh.pas	Fri Sep 30 13:17:34 2011 +0400
+++ b/hedgewars/SDLh.pas	Fri Sep 30 12:55:04 2011 +0200
@@ -228,6 +228,8 @@
     SDL_HWPALETTE   = $20000000;
     SDL_DOUBLEBUF   = $40000000;
     SDL_FULLSCREEN  = $80000000;
+
+    SDL_ALLEVENTS = $FFFFFFFF;
 {$ENDIF}
 
 {$IFDEF ENDIAN_LITTLE}
@@ -279,9 +281,6 @@
     IMG_INIT_TIF = $00000004;
 
     {* SDL_EventMask type definition *}
-{$IFNDEF SDL13}
-    SDL_ALLEVENTS = $FFFFFFFF;
-{$ENDIF}
 
 /////////////////////////////////////////////////////////////////
 ///////////////////////  TYPE DEFINITIONS ///////////////////////
@@ -872,8 +871,8 @@
 procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
 
 (*  SDL_mixer  *)
-function  Mix_Init(flags: LongInt): LongInt; cdecl; external SDL_MixerLibName;
-procedure Mix_Quit; cdecl; external SDL_MixerLibName;
+function  Mix_Init(flags: LongInt): LongInt; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF}
+procedure Mix_Quit; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF}
 
 function  Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName;
 procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName;
@@ -904,8 +903,8 @@
 function  Mix_FadeOutChannel(channel: LongInt; fadems: LongInt): LongInt; cdecl; external SDL_MixerLibName;
 
 (*  SDL_image  *)
-function  IMG_Init(flags: LongInt): LongInt; cdecl; external SDL_ImageLibName;
-procedure IMG_Quit; cdecl; external SDL_ImageLibName;
+function  IMG_Init(flags: LongInt): LongInt; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF}
+procedure IMG_Quit; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF}
 
 function  IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
 function  IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongInt): PSDL_Surface; cdecl; external SDL_ImageLibName;
@@ -964,13 +963,36 @@
 
 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
 begin
+    SDL_MustLock:=
 {$IFDEF SDL13}
-    SDL_MustLock:= ((surface^.flags and SDL_RLEACCEL) <> 0)
+        ((surface^.flags and SDL_RLEACCEL) <> 0)
 {$ELSE}
-    SDL_MustLock:= ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
+        ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
 {$ENDIF}
 end;
 
+{$IFNDEF SDL_MIXER_NEWER}
+function  Mix_Init(flags: LongInt): LongInt;
+begin
+    exit(flags);
+end;
+
+procedure Mix_Quit;
+begin
+end;
+{$ENDIF}
+
+{$IFNDEF SDL_IMAGE_NEWER}
+function  IMG_Init(flags: LongInt): LongInt;
+begin
+    exit(flags);
+end;
+
+procedure IMG_Quit;
+begin
+end;
+{$ENDIF}
+
 procedure SDLNet_Write16(value: Word; buf: pointer);
 begin
     PByteArray(buf)^[1]:= value;
--- a/hedgewars/hwengine.pas	Fri Sep 30 13:17:34 2011 +0400
+++ b/hedgewars/hwengine.pas	Fri Sep 30 12:55:04 2011 +0200
@@ -163,15 +163,11 @@
     while isTerminated = false do
     begin
         SDL_PumpEvents();
-{$IFDEF SDL13}
-        while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) > 0 do
-{$ELSE}
-        while SDL_PeepEvents(@event, 1, SDL_GETEVENT, SDL_ALLEVENTS) > 0 do
-{$ENDIF}
+        while SDL_PeepEvents(@event, 1, SDL_GETEVENT, {$IFDEF SDL13}SDL_FIRSTEVENT, SDL_LASTEVENT{$ELSE}SDL_ALLEVENTS{$ENDIF}) > 0 do
         begin
             case event.type_ of
+{$IFDEF SDL13}
                 SDL_KEYDOWN: if GameState = gsChat then
-{$IFDEF SDL13}
                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
                     KeyPressChat(event.key.keysym.sym);
                 SDL_WINDOWEVENT:
@@ -196,6 +192,7 @@
                         cScreenResizeDelay:= RealTicks+500;
                         end;
 {$ELSE}
+                SDL_KEYDOWN: if GameState = gsChat then
                     KeyPressChat(event.key.keysym.unicode);
                 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then wheelDown:= true;
                 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then wheelUp:= true;
@@ -224,6 +221,7 @@
                 SDL_QUITEV: isTerminated:= true
             end; //end case event.type_ of
         end; //end while SDL_PollEvent(@event) <> 0 do
+
         if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then
             begin
             cScreenResizeDelay:= 0;
@@ -237,25 +235,21 @@
             end;
 
         if isTerminated = false then
-        begin
+            begin
             CurrTime:= SDL_GetTicks;
             if PrevTime + longword(cTimerInterval) <= CurrTime then
-            begin
+                begin
                 DoTimer(CurrTime - PrevTime);
                 PrevTime:= CurrTime
-            end
+                end
             else SDL_Delay(1);
             IPCCheckSock();
-        end;
+            end;
     end;
 end;
 
 ///////////////
-{$IFDEF HWLIBRARY}
-procedure Game(gameArgs: PPChar); cdecl; export;
-{$ELSE}
-procedure Game;
-{$ENDIF}
+procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF};
 var p: TPathType;
     s: shortstring;
     i: LongInt;
--- a/hedgewars/uSound.pas	Fri Sep 30 13:17:34 2011 +0400
+++ b/hedgewars/uSound.pas	Fri Sep 30 12:55:04 2011 +0200
@@ -157,11 +157,9 @@
     if isSoundEnabled then
         isSoundEnabled:= Mix_OpenAudio(44100, $8010, channels, 1024) = 0;
 
-{$IFDEF SDL_MIXER_NEWER}
     WriteToConsole('Init SDL_mixer... ');
     SDLTry(Mix_Init(MIX_INIT_OGG) <> 0, true);
     WriteLnToConsole(msgOK);
-{$ENDIF}
 
     if isSoundEnabled then
         WriteLnToConsole(msgOK)
@@ -191,11 +189,9 @@
     if Mus <> nil then
         Mix_FreeMusic(Mus);
 
-{$IFDEF SDL_MIXER_NEWER}
     // make sure all instances of sdl_mixer are unloaded before continuing
     while Mix_Init(0) <> 0 do
         Mix_Quit();
-{$ENDIF}
 
     Mix_CloseAudio();
 end;
--- a/hedgewars/uStore.pas	Fri Sep 30 13:17:34 2011 +0400
+++ b/hedgewars/uStore.pas	Fri Sep 30 12:55:04 2011 +0200
@@ -399,10 +399,7 @@
 end;
 
 AddProgress;
-
-{$IFDEF SDL_IMAGE_NEWER}
 IMG_Quit();
-{$ENDIF}
 end;
 
 procedure StoreRelease(reload: boolean);
@@ -949,30 +946,24 @@
 
 procedure chFullScr(var s: shortstring);
 var flags: Longword = 0;
-    {$IFNDEF IPHONEOS}ico: PSDL_Surface;{$ENDIF}
-    reinit: boolean;
+    reinit: boolean = false;
+    {$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF}
     {$IFDEF SDL13}x, y: LongInt;{$ENDIF}
 begin
     if Length(s) = 0 then cFullScreen:= not cFullScreen
     else cFullScreen:= s = '1';
 
     AddFileLog('Preparing to change video parameters...');
-    reinit:= false;
 {$IFNDEF IPHONEOS}
     if SDLPrimSurface = nil then
         begin
         // set window title
         SDL_WM_SetCaption('Hedgewars', nil);
-{$IFDEF SDL_IMAGE_NEWER}
         WriteToConsole('Init SDL_image... ');
         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
         WriteLnToConsole(msgOK);
-{$ENDIF}
         // load engine icon
-{$IFDEF DARWIN}
-        ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
-        if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
-{$ELSE}
+{$IFNDEF DARWIN}
         ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
         if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
 {$ENDIF}