hedgewars/hwengine.pas
changeset 4454 42bfc1a70968
parent 4437 05192cdbce9b
child 4490 f6840f7e2f60
equal deleted inserted replaced
4453:15a483b2558a 4454:42bfc1a70968
    46 
    46 
    47 ////////////////////////////////
    47 ////////////////////////////////
    48 procedure DoTimer(Lag: LongInt);
    48 procedure DoTimer(Lag: LongInt);
    49 var s: shortstring;
    49 var s: shortstring;
    50 begin
    50 begin
    51     if not isPaused then inc(RealTicks, Lag);
    51     if isPaused = false then
       
    52         inc(RealTicks, Lag);
    52 
    53 
    53     case GameState of
    54     case GameState of
    54         gsLandGen: begin
    55         gsLandGen: begin
    55                 GenMap;
    56                 GenMap;
    56                 ParseCommand('sendlanddigest', true);
    57                 ParseCommand('sendlanddigest', true);
    95                     end;
    96                     end;
    96                 end;
    97                 end;
    97         gsExit: begin
    98         gsExit: begin
    98                 isTerminated:= true;
    99                 isTerminated:= true;
    99                 end;
   100                 end;
       
   101         gsSuspend: exit;
   100         end;
   102         end;
   101 
   103 
   102 {$IFDEF SDL13}
   104 {$IFDEF SDL13}
   103     SDL_RenderPresent();
   105     SDL_RenderPresent();
   104 {$ELSE}
   106 {$ELSE}
   105     SDL_GL_SwapBuffers();
   107     SDL_GL_SwapBuffers();
   106 {$ENDIF}
   108 {$ENDIF}
   107     // not going to make captures on the iPhone
   109 
   108     if flagMakeCapture then
   110     if flagMakeCapture then
   109     begin
   111     begin
   110         flagMakeCapture:= false;
   112         flagMakeCapture:= false;
   111         s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks);
   113         s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks);
   112         WriteLnToConsole('Saving ' + s + '...');
   114         WriteLnToConsole('Saving ' + s + '...');
   144 
   146 
   145         while SDL_PollEvent(@event) <> 0 do
   147         while SDL_PollEvent(@event) <> 0 do
   146         begin
   148         begin
   147             case event.type_ of
   149             case event.type_ of
   148                 SDL_KEYDOWN: if GameState = gsChat then
   150                 SDL_KEYDOWN: if GameState = gsChat then
   149 {$IFDEF IPHONEOS}
   151 {$IFDEF SDL13}
   150                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
   152                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
   151                     KeyPressChat(event.key.keysym.sym);
   153                     KeyPressChat(event.key.keysym.sym);
       
   154                 SDL_WINDOWEVENT:
       
   155                     if event.wevent.event = SDL_WINDOWEVENT_SHOWN then
       
   156                         cHasFocus:= true;
   152 {$ELSE}
   157 {$ELSE}
   153                     KeyPressChat(event.key.keysym.unicode);
   158                     KeyPressChat(event.key.keysym.unicode);
   154                 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
   159                 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then uKeys.wheelDown:= true;
   155                 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true;
   160                 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then uKeys.wheelUp:= true;
   156 {$ENDIF}
       
   157 {$IFDEF SDL13}
       
   158                 SDL_WINDOWEVENT:
       
   159                     if event.wevent.event = SDL_WINDOWEVENT_SHOWN then
       
   160                         cHasFocus:= true;
       
   161 {$ELSE}
       
   162                 SDL_ACTIVEEVENT:
   161                 SDL_ACTIVEEVENT:
   163                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   162                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   164                         cHasFocus:= event.active.gain = 1;
   163                         cHasFocus:= event.active.gain = 1;
   165 {$ENDIF}
   164 {$ENDIF}
   166                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   165                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
   167                 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
   166                 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
   168                 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
   167                 SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
   169                 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
   168                 SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
   170                 SDL_QUITEV: isTerminated:= true
   169                 SDL_QUITEV: isTerminated:= true
   171             end; // end case event.type_
   170             end; //end case event.type_ of
   172         end; // end while SDL_PollEvent(@event) <> 0
   171         end; //end while SDL_PollEvent(@event) <> 0 do
   173 
   172 
   174         if isTerminated = false then
   173         if isTerminated = false then
   175         begin
   174         begin
   176             CurrTime:= SDL_GetTicks;
   175             CurrTime:= SDL_GetTicks;
   177             if PrevTime + longword(cTimerInterval) <= CurrTime then
   176             if PrevTime + longword(cTimerInterval) <= CurrTime then