hedgewars/hwengine.pas
branchwebgl
changeset 9127 e350500c4edb
parent 8847 ff7fbab7cd56
parent 9080 9b42757d7e71
child 9521 8054d9d775fd
equal deleted inserted replaced
8860:bde641cf53c8 9127:e350500c4edb
     1 (*
     1 (*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    30 {$ENDIF}
    30 {$ENDIF}
    31 
    31 
    32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uInputHandler
    32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uInputHandler
    33      , uSound, uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uAILandMarks, uLandTexture, uCollisions
    33      , uSound, uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uAILandMarks, uLandTexture, uCollisions
    34      , SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted
    34      , SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted
    35      , uPhysFSLayer, uCursor
    35      , uPhysFSLayer, uCursor, uRandom
    36      {$IFDEF USE_VIDEO_RECORDING}, uVideoRec {$ENDIF}
    36      {$IFDEF USE_VIDEO_RECORDING}, uVideoRec {$ENDIF}
    37      {$IFDEF USE_TOUCH_INTERFACE}, uTouch {$ENDIF}
    37      {$IFDEF USE_TOUCH_INTERFACE}, uTouch {$ENDIF}
    38      {$IFDEF ANDROID}, GLUnit{$ENDIF}
    38      {$IFDEF ANDROID}, GLUnit{$ENDIF}
    39      {$IFDEF WEBGL}, uWeb{$ENDIF}
    39      {$IFDEF WEBGL}, uWeb{$ENDIF}
    40      ;
    40      ;
    92             begin
    92             begin
    93             if HasBorder then
    93             if HasBorder then
    94                 DisableSomeWeapons;
    94                 DisableSomeWeapons;
    95             AddClouds;
    95             AddClouds;
    96             AddFlakes;
    96             AddFlakes;
       
    97             SetRandomSeed(cSeed, false);
    97             AssignHHCoords;
    98             AssignHHCoords;
    98             AddMiscGears;
    99             AddMiscGears;
    99             StoreLoad(false);
   100             StoreLoad(false);
   100             InitWorld;
   101             InitWorld;
   101             ResetKbd;
   102             ResetKbd;
   105             PlayMusic;
   106             PlayMusic;
   106             SetScale(zoom);
   107             SetScale(zoom);
   107             ScriptCall('onGameStart');
   108             ScriptCall('onGameStart');
   108             GameState:= gsGame;
   109             GameState:= gsGame;
   109             end;
   110             end;
   110         gsConfirm, gsGame:
   111         gsConfirm, gsGame, gsChat:
   111             begin
   112             begin
   112             if not cOnlyStats then
   113             if not cOnlyStats then
   113 {$IFDEF WEBGL}
   114 {$IFDEF WEBGL}
   114                 drawworld_hook();
   115                 drawworld_hook();
   115 {$ELSE}
   116 {$ELSE}
   116                 // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
   117                 // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
   117                 DrawWorld(Lag);
   118                 DrawWorld(Lag);
   118 {$ENDIF}
   119 {$ENDIF}
   119             DoGameTick(Lag);
       
   120             if not cOnlyStats then ProcessVisualGears(Lag);
       
   121             end;
       
   122         gsChat:
       
   123             begin
       
   124             if not cOnlyStats then DrawWorld(Lag);
       
   125             DoGameTick(Lag);
   120             DoGameTick(Lag);
   126             if not cOnlyStats then ProcessVisualGears(Lag);
   121             if not cOnlyStats then ProcessVisualGears(Lag);
   127             end;
   122             end;
   128         gsExit:
   123         gsExit:
   129             begin
   124             begin
   198                     if GameState = gsChat then
   193                     if GameState = gsChat then
   199                         begin
   194                         begin
   200                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
   195                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
   201                         KeyPressChat(SDL_GetKeyFromScancode(event.key.keysym.sym), event.key.keysym.sym); //TODO correct for keymodifiers
   196                         KeyPressChat(SDL_GetKeyFromScancode(event.key.keysym.sym), event.key.keysym.sym); //TODO correct for keymodifiers
   202                         end
   197                         end
   203                     else
   198                     else 
   204                         ProcessKey(event.key);
   199                         if GameState >= gsGame then ProcessKey(event.key);
   205                 SDL_KEYUP:
   200                 SDL_KEYUP:
   206                     if GameState <> gsChat then
   201                     if (GameState <> gsChat) and (GameState >= gsGame) then
   207                         ProcessKey(event.key);
   202                         ProcessKey(event.key);
   208 
   203 
   209                 SDL_WINDOWEVENT:
   204                 SDL_WINDOWEVENT:
   210                     if event.window.event = SDL_WINDOWEVENT_SHOWN then
   205                     if event.window.event = SDL_WINDOWEVENT_SHOWN then
   211                     begin
   206                     begin
   243 {$ELSE}
   238 {$ELSE}
   244                 SDL_KEYDOWN:
   239                 SDL_KEYDOWN:
   245                     if GameState = gsChat then
   240                     if GameState = gsChat then
   246                         KeyPressChat(event.key.keysym.unicode, event.key.keysym.sym)
   241                         KeyPressChat(event.key.keysym.unicode, event.key.keysym.sym)
   247                     else
   242                     else
   248                         ProcessKey(event.key);
   243                         if GameState >= gsGame then ProcessKey(event.key);
   249                 SDL_KEYUP:
   244                 SDL_KEYUP:
   250                     if GameState <> gsChat then
   245                     if (GameState <> gsChat) and (GameState >= gsGame) then
   251                         ProcessKey(event.key);
   246                         ProcessKey(event.key);
   252 
   247 
   253                 SDL_MOUSEBUTTONDOWN:
   248                 SDL_MOUSEBUTTONDOWN:
   254                     if GameState = gsConfirm then
   249                     if GameState = gsConfirm then
   255                     begin
   250                         ParseCommand('quit', true)
   256                         resetPosition();
       
   257                         ParseCommand('quit', true);
       
   258                     end
       
   259                     else
   251                     else
   260                         ProcessMouse(event.button, true);
   252                         if (GameState >= gsGame) then ProcessMouse(event.button, true);
   261 
   253 
   262                 SDL_MOUSEBUTTONUP:
   254                 SDL_MOUSEBUTTONUP:
   263                     ProcessMouse(event.button, false);
   255                     if (GameState >= gsGame) then ProcessMouse(event.button, false);
   264 
   256 
   265                 SDL_ACTIVEEVENT:
   257                 SDL_ACTIVEEVENT:
   266                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   258                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
   267                     begin
   259                     begin
   268                         prevFocusState:= cHasFocus;
   260                         prevFocusState:= cHasFocus;
   388     initEverything(true);
   380     initEverything(true);
   389     WriteLnToConsole('Hedgewars engine ' + cVersionString + '-r' + cRevisionString +
   381     WriteLnToConsole('Hedgewars engine ' + cVersionString + '-r' + cRevisionString +
   390                      ' (' + cHashString + ') with protocol #' + inttostr(cNetProtoVersion));
   382                      ' (' + cHashString + ') with protocol #' + inttostr(cNetProtoVersion));
   391     AddFileLog('Prefix: "' + PathPrefix +'"');
   383     AddFileLog('Prefix: "' + PathPrefix +'"');
   392     AddFileLog('UserPrefix: "' + UserPathPrefix +'"');
   384     AddFileLog('UserPrefix: "' + UserPathPrefix +'"');
   393     
   385 
   394     for i:= 0 to ParamCount do
   386     for i:= 0 to ParamCount do
   395         AddFileLog(inttostr(i) + ': ' + ParamStr(i));
   387         AddFileLog(inttostr(i) + ': ' + ParamStr(i));
   396 
   388 
   397     WriteToConsole('Init SDL... ');
   389     WriteToConsole('Init SDL... ');
   398     if not cOnlyStats then SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true);
   390     if not cOnlyStats then SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true);