hedgewars/hwengine.pas
changeset 7180 53ffc8853008
parent 7151 ec15d9e1a7e3
child 7198 5debd5fe526e
equal deleted inserted replaced
7176:fb4b0c6dfdbd 7180:53ffc8853008
    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, uSound,
    32 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uInputHandler, uSound,
    33      uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions,
    33      uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions,
    34      SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted
    34      SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted, uVideoRec
    35      {$IFDEF SDL13}, uTouch{$ENDIF}{$IFDEF ANDROID}, GLUnit{$ENDIF};
    35      {$IFDEF SDL13}, uTouch{$ENDIF}{$IFDEF ANDROID}, GLUnit{$ENDIF};
    36 
    36 
    37 {$IFDEF HWLIBRARY}
    37 {$IFDEF HWLIBRARY}
    38 procedure initEverything(complete:boolean);
    38 procedure initEverything(complete:boolean);
    39 procedure freeEverything(complete:boolean);
    39 procedure freeEverything(complete:boolean);
    98         gsSuspend:
    98         gsSuspend:
    99             exit(false);
    99             exit(false);
   100             end;
   100             end;
   101 
   101 
   102     SwapBuffers;
   102     SwapBuffers;
       
   103 
       
   104     if flagPrerecording then
       
   105         SaveCameraPosition;
   103 
   106 
   104     if flagMakeCapture then
   107     if flagMakeCapture then
   105         begin
   108         begin
   106         flagMakeCapture:= false;
   109         flagMakeCapture:= false;
   107         {$IFDEF PAS2C}
   110         {$IFDEF PAS2C}
   259         else SDL_Delay(1);
   262         else SDL_Delay(1);
   260         IPCCheckSock();
   263         IPCCheckSock();
   261     end;
   264     end;
   262 end;
   265 end;
   263 
   266 
       
   267 ////////////////
       
   268 procedure RecorderMainLoop;
       
   269 var CurrTime, PrevTime: LongInt;
       
   270 begin
       
   271     if not BeginVideoRecording() then
       
   272         exit;
       
   273     DoTimer(0); // gsLandGen -> gsStart
       
   274     DoTimer(0); // gsStart -> gsGame
       
   275 
       
   276     CurrTime:= LoadNextCameraPosition();
       
   277     fastScrolling:= true;
       
   278     DoTimer(CurrTime);
       
   279     fastScrolling:= false;
       
   280     while true do
       
   281     begin
       
   282         EncodeFrame();
       
   283         PrevTime:= CurrTime;
       
   284         CurrTime:= LoadNextCameraPosition();
       
   285         if CurrTime = -1 then
       
   286             break;
       
   287         DoTimer(CurrTime - PrevTime);
       
   288         IPCCheckSock();
       
   289     end;
       
   290     StopVideoRecording();
       
   291 end;
       
   292 
   264 ///////////////
   293 ///////////////
   265 procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF};
   294 procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF};
   266 var p: TPathType;
   295 var p: TPathType;
   267     s: shortstring;
   296     s: shortstring;
   268     i: LongInt;
   297     i: LongInt;
   325 
   354 
   326     WriteToConsole('Init SDL_ttf... ');
   355     WriteToConsole('Init SDL_ttf... ');
   327     SDLTry(TTF_Init() <> -1, true);
   356     SDLTry(TTF_Init() <> -1, true);
   328     WriteLnToConsole(msgOK);
   357     WriteLnToConsole(msgOK);
   329 
   358 
   330     // show main window
   359     if GameType = gmtRecord then
   331     if cFullScreen then
   360         InitOffscreenOpenGL()
   332         ParseCommand('fullscr 1', true)
       
   333     else
   361     else
   334         ParseCommand('fullscr 0', true);
   362         begin            
       
   363         // show main window
       
   364         if cFullScreen then
       
   365             ParseCommand('fullscr 1', true)
       
   366         else
       
   367             ParseCommand('fullscr 0', true);
       
   368         end;
   335 
   369 
   336     ControllerInit(); // has to happen before InitKbdKeyTable to map keys
   370     ControllerInit(); // has to happen before InitKbdKeyTable to map keys
   337     InitKbdKeyTable();
   371     InitKbdKeyTable();
   338     AddProgress();
   372     AddProgress();
   339 
   373 
   366     s:= 'eproto ' + inttostr(cNetProtoVersion);
   400     s:= 'eproto ' + inttostr(cNetProtoVersion);
   367     SendIPCRaw(@s[0], Length(s) + 1); // send proto version
   401     SendIPCRaw(@s[0], Length(s) + 1); // send proto version
   368 
   402 
   369     InitTeams();
   403     InitTeams();
   370     AssignStores();
   404     AssignStores();
       
   405 
       
   406     if GameType = gmtRecord then
       
   407         SetSound(false);
       
   408 
   371     InitSound();
   409     InitSound();
   372 
   410 
   373     isDeveloperMode:= false;
   411     isDeveloperMode:= false;
   374     TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   412     TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
   375     ParseCommand('rotmask', true);
   413     ParseCommand('rotmask', true);
   376     MainLoop();
   414 
       
   415     if GameType = gmtRecord then
       
   416         RecorderMainLoop()
       
   417     else
       
   418         MainLoop();
   377 
   419 
   378     // clean up all the memory allocated
   420     // clean up all the memory allocated
   379     freeEverything(true);
   421     freeEverything(true);
   380 end;
   422 end;
   381 
   423 
   454         uChat.freeModule;
   496         uChat.freeModule;
   455         uAmmos.freeModule;
   497         uAmmos.freeModule;
   456         //uAIAmmoTests does not need to be freed
   498         //uAIAmmoTests does not need to be freed
   457         //uAIActions does not need to be freed
   499         //uAIActions does not need to be freed
   458         uStore.freeModule;
   500         uStore.freeModule;
       
   501         uVideoRec.freeModule;
   459     end;
   502     end;
   460 
   503 
   461     uIO.freeModule;
   504     uIO.freeModule;
   462     uLand.freeModule;
   505     uLand.freeModule;
   463     uLandPainted.freeModule;
   506     uLandPainted.freeModule;
   528         GameType:= gmtSyntax
   571         GameType:= gmtSyntax
   529     else
   572     else
   530         if (ParamCount = 3) and ((ParamStr(3) = '--stats-only') or (ParamStr(3) = 'landpreview')) then
   573         if (ParamCount = 3) and ((ParamStr(3) = '--stats-only') or (ParamStr(3) = 'landpreview')) then
   531             internalSetGameTypeLandPreviewFromParameters()
   574             internalSetGameTypeLandPreviewFromParameters()
   532         else
   575         else
   533             if (ParamCount = cDefaultParamNum) then
   576             if (ParamCount = cDefaultParamNum) or (ParamCount = cDefaultParamNum+1) then
   534                 internalStartGameWithParameters()
   577                 internalStartGameWithParameters()
   535             else
   578             else
   536                 playReplayFileWithParameters();
   579                 playReplayFileWithParameters();
   537 end;
   580 end;
   538 
   581