hedgewars/hwengine.pas
branchwebgl
changeset 8096 453917e94e55
parent 8026 4a4f21070479
parent 8057 93e16240f178
child 8330 aaefa587e277
equal deleted inserted replaced
8053:2e836bebb518 8096:453917e94e55
    28 {$ELSE}
    28 {$ELSE}
    29 program hwengine;
    29 program hwengine;
    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, uLandTexture, uCollisions, uAILandMarks,
    33      uSound, uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uLandTexture, uCollisions,
    34      SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted, uFloat
    34      uAILandMarks, SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers,
       
    35      uLandPainted, uFloat, uPhysFSLayer
    35      {$IFDEF USE_VIDEO_RECORDING}, uVideoRec {$ENDIF}
    36      {$IFDEF USE_VIDEO_RECORDING}, uVideoRec {$ENDIF}
    36      {$IFDEF WEBGL}, uWeb{$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      ;
    40      ;
    40 
    41 
    41 {$IFDEF HWLIBRARY}
    42 {$IFDEF HWLIBRARY}
    42 procedure preInitEverything();
    43 procedure preInitEverything();
    43 procedure initEverything(complete:boolean);
    44 procedure initEverything(complete:boolean);
    66     isRunning : boolean;
    67     isRunning : boolean;
    67 {$ENDIF}
    68 {$ENDIF}
    68 
    69 
    69 ///////////////////////////////////////////////////////////////////////////////
    70 ///////////////////////////////////////////////////////////////////////////////
    70 function DoTimer(Lag: LongInt): boolean;
    71 function DoTimer(Lag: LongInt): boolean;
    71 var s : shortstring;
    72 var s: shortstring;
    72 begin
    73 begin
    73     DoTimer:= false;
    74     DoTimer:= false;
    74     inc(RealTicks, Lag);
    75     inc(RealTicks, Lag);
    75 
    76 
    76     case GameState of
    77     case GameState of
   102             ScriptCall('onGameStart');
   103             ScriptCall('onGameStart');
   103             GameState:= gsGame;
   104             GameState:= gsGame;
   104             end;
   105             end;
   105         gsConfirm, gsGame:
   106         gsConfirm, gsGame:
   106             begin
   107             begin
       
   108             if not cOnlyStats then
   107 {$IFDEF WEBGL}
   109 {$IFDEF WEBGL}
   108             drawworld_hook();
   110                 drawworld_hook();
   109 {$ELSE}
   111 {$ELSE}
   110             DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
   112                 // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
       
   113                 DrawWorld(Lag);
   111 {$ENDIF}
   114 {$ENDIF}
   112             DoGameTick(Lag);
   115             DoGameTick(Lag);
   113             ProcessVisualGears(Lag);
   116             if not cOnlyStats then ProcessVisualGears(Lag);
   114             end;
   117             end;
   115         gsChat:
   118         gsChat:
   116             begin
   119             begin
   117             DrawWorld(Lag);
   120             if not cOnlyStats then DrawWorld(Lag);
   118             DoGameTick(Lag);
   121             DoGameTick(Lag);
   119             ProcessVisualGears(Lag);
   122             if not cOnlyStats then ProcessVisualGears(Lag);
   120             end;
   123             end;
   121         gsExit:
   124         gsExit:
   122             begin
   125             begin
   123             DoTimer:= true;
   126             DoTimer:= true;
   124             end;
   127             end;
   125         gsSuspend:
   128         gsSuspend:
   126             exit(false);
   129             exit(false);
   127             end;
   130             end;
   128 
   131 
   129     SwapBuffers;
   132     if not cOnlyStats then SwapBuffers;
   130 
   133 
   131 {$IFDEF USE_VIDEO_RECORDING}
   134 {$IFDEF USE_VIDEO_RECORDING}
   132     if flagPrerecording then
   135     if flagPrerecording then
   133         SaveCameraPosition;
   136         SaveCameraPosition;
   134 {$ENDIF}
   137 {$ENDIF}
   377     recordFileName:= gameArgs[10];
   380     recordFileName:= gameArgs[10];
   378 {$ENDIF}
   381 {$ENDIF}
   379     initEverything(true);
   382     initEverything(true);
   380 
   383 
   381     WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
   384     WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
   382     AddFileLog('Prefix: "' + PathPrefix +'"');
       
   383     AddFileLog('UserPrefix: "' + UserPathPrefix +'"');
       
   384     
   385     
   385     for i:= 0 to ParamCount do
   386     for i:= 0 to ParamCount do
   386         AddFileLog(inttostr(i) + ': ' + ParamStr(i));
   387         AddFileLog(inttostr(i) + ': ' + ParamStr(i));
   387 
   388 
   388     for p:= Succ(Low(TPathType)) to High(TPathType) do
       
   389         if (p <> ptMapCurrent) and (p <> ptData) then
       
   390             UserPathz[p]:= UserPathPrefix + '/Data/' + Pathz[p];
       
   391 
       
   392     UserPathz[ptData]:= UserPathPrefix + '/Data';
       
   393 
       
   394     for p:= Succ(Low(TPathType)) to High(TPathType) do
       
   395         if p <> ptMapCurrent then
       
   396             Pathz[p]:= PathPrefix + '/' + Pathz[p];
       
   397 
       
   398     WriteToConsole('Init SDL... ');
   389     WriteToConsole('Init SDL... ');
   399     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);
   400     WriteLnToConsole(msgOK);
   391     WriteLnToConsole(msgOK);
   401 
   392 
   402     SDL_EnableUNICODE(1);
   393     SDL_EnableUNICODE(1);
   403     SDL_ShowCursor(0);
   394     SDL_ShowCursor(0);
   404 
   395 
   421 
   412 
   422     ControllerInit(); // has to happen before InitKbdKeyTable to map keys
   413     ControllerInit(); // has to happen before InitKbdKeyTable to map keys
   423     InitKbdKeyTable();
   414     InitKbdKeyTable();
   424     AddProgress();
   415     AddProgress();
   425 
   416 
   426     LoadLocale(UserPathz[ptLocale] + '/en.txt');  // Do an initial load with english
   417     LoadLocale(cPathz[ptLocale] + '/en.txt');  // Do an initial load with english
   427     LoadLocale(Pathz[ptLocale] + '/en.txt');  // Do an initial load with english
       
   428     if cLocaleFName <> 'en.txt' then
   418     if cLocaleFName <> 'en.txt' then
   429         begin
   419         begin
   430         // Try two letter locale first before trying specific locale overrides
   420         // Try two letter locale first before trying specific locale overrides
   431         if (Length(cLocale) > 3) and (Copy(cLocale,1,2) <> 'en') then
   421         if (Length(cLocale) > 3) and (Copy(cLocale, 1, 2) <> 'en') then
   432             begin
   422             begin
   433             LoadLocale(UserPathz[ptLocale] + '/' + Copy(cLocale,1,2)+'.txt');
   423             LoadLocale(cPathz[ptLocale] + '/' + Copy(cLocale, 1, 2) + '.txt')
   434             LoadLocale(Pathz[ptLocale] + '/' + Copy(cLocale,1,2)+'.txt')
       
   435             end;
   424             end;
   436         LoadLocale(UserPathz[ptLocale] + '/' + cLocaleFName);
   425         LoadLocale(cPathz[ptLocale] + '/' + cLocaleFName)
   437         LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName)
       
   438         end
   426         end
   439     else cLocale := 'en';
   427     else cLocale := 'en';
   440 
   428 
   441     WriteLnToConsole(msgGettingConfig);
   429     WriteLnToConsole(msgGettingConfig);
   442 
   430 
   449         LoadRecordFromFile(recordFileName);
   437         LoadRecordFromFile(recordFileName);
   450 
   438 
   451     ScriptOnGameInit;
   439     ScriptOnGameInit;
   452     s:= 'eproto ' + inttostr(cNetProtoVersion);
   440     s:= 'eproto ' + inttostr(cNetProtoVersion);
   453     SendIPCRaw(@s[0], Length(s) + 1); // send proto version
   441     SendIPCRaw(@s[0], Length(s) + 1); // send proto version
   454 	
   442 
   455     InitTeams();
   443     InitTeams();
   456     AssignStores();
   444     AssignStores();
   457 
   445 
   458     if GameType = gmtRecord then
   446     if GameType = gmtRecord then
   459         SetSound(false);
   447         SetSound(false);
   513     uLandPainted.initModule;        // computes drawn land
   501     uLandPainted.initModule;        // computes drawn land
   514     uIO.initModule;                 // sets up sockets
   502     uIO.initModule;                 // sets up sockets
   515 
   503 
   516     if complete then
   504     if complete then
   517     begin
   505     begin
       
   506         uPhysFSLayer.initModule;
   518 {$IFDEF ANDROID}GLUnit.initModule;{$ENDIF}
   507 {$IFDEF ANDROID}GLUnit.initModule;{$ENDIF}
   519 {$IFDEF USE_TOUCH_INTERFACE}uTouch.initModule;{$ENDIF}
   508 {$IFDEF USE_TOUCH_INTERFACE}uTouch.initModule;{$ENDIF}
   520 {$IFDEF USE_VIDEO_RECORDING}uVideoRec.initModule;{$ENDIF}   //stub
   509 {$IFDEF USE_VIDEO_RECORDING}uVideoRec.initModule;{$ENDIF}   //stub
   521         uAI.initModule;
   510         uAI.initModule;
   522         uAIMisc.initModule;
   511         uAIMisc.initModule;
   564         uAmmos.freeModule;
   553         uAmmos.freeModule;
   565         uStore.freeModule;          // closes SDL
   554         uStore.freeModule;          // closes SDL
   566 {$IFDEF USE_VIDEO_RECORDING}uVideoRec.freeModule;{$ENDIF}
   555 {$IFDEF USE_VIDEO_RECORDING}uVideoRec.freeModule;{$ENDIF}
   567 {$IFDEF USE_TOUCH_INTERFACE}uTouch.freeModule;{$ENDIF}  //stub
   556 {$IFDEF USE_TOUCH_INTERFACE}uTouch.freeModule;{$ENDIF}  //stub
   568 {$IFDEF ANDROID}GLUnit.freeModule;{$ENDIF}
   557 {$IFDEF ANDROID}GLUnit.freeModule;{$ENDIF}
       
   558         uPhysFSLayer.freeModule;
   569     end;
   559     end;
   570 
   560 
   571     uIO.freeModule;
   561     uIO.freeModule;
   572     uLand.freeModule;
   562     uLand.freeModule;
   573     uLandPainted.freeModule;
   563     uLandPainted.freeModule;