hedgewars/hwengine.pas
changeset 7180 53ffc8853008
parent 7151 ec15d9e1a7e3
child 7198 5debd5fe526e
--- a/hedgewars/hwengine.pas	Mon Jun 04 08:11:47 2012 -0400
+++ b/hedgewars/hwengine.pas	Mon Jun 04 21:32:30 2012 +0400
@@ -31,7 +31,7 @@
 
 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uInputHandler, uSound,
      uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions,
-     SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted
+     SysUtils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted, uVideoRec
      {$IFDEF SDL13}, uTouch{$ENDIF}{$IFDEF ANDROID}, GLUnit{$ENDIF};
 
 {$IFDEF HWLIBRARY}
@@ -101,6 +101,9 @@
 
     SwapBuffers;
 
+    if flagPrerecording then
+        SaveCameraPosition;
+
     if flagMakeCapture then
         begin
         flagMakeCapture:= false;
@@ -261,6 +264,32 @@
     end;
 end;
 
+////////////////
+procedure RecorderMainLoop;
+var CurrTime, PrevTime: LongInt;
+begin
+    if not BeginVideoRecording() then
+        exit;
+    DoTimer(0); // gsLandGen -> gsStart
+    DoTimer(0); // gsStart -> gsGame
+
+    CurrTime:= LoadNextCameraPosition();
+    fastScrolling:= true;
+    DoTimer(CurrTime);
+    fastScrolling:= false;
+    while true do
+    begin
+        EncodeFrame();
+        PrevTime:= CurrTime;
+        CurrTime:= LoadNextCameraPosition();
+        if CurrTime = -1 then
+            break;
+        DoTimer(CurrTime - PrevTime);
+        IPCCheckSock();
+    end;
+    StopVideoRecording();
+end;
+
 ///////////////
 procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF};
 var p: TPathType;
@@ -327,11 +356,16 @@
     SDLTry(TTF_Init() <> -1, true);
     WriteLnToConsole(msgOK);
 
-    // show main window
-    if cFullScreen then
-        ParseCommand('fullscr 1', true)
+    if GameType = gmtRecord then
+        InitOffscreenOpenGL()
     else
-        ParseCommand('fullscr 0', true);
+        begin            
+        // show main window
+        if cFullScreen then
+            ParseCommand('fullscr 1', true)
+        else
+            ParseCommand('fullscr 0', true);
+        end;
 
     ControllerInit(); // has to happen before InitKbdKeyTable to map keys
     InitKbdKeyTable();
@@ -368,12 +402,20 @@
 
     InitTeams();
     AssignStores();
+
+    if GameType = gmtRecord then
+        SetSound(false);
+
     InitSound();
 
     isDeveloperMode:= false;
     TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
     ParseCommand('rotmask', true);
-    MainLoop();
+
+    if GameType = gmtRecord then
+        RecorderMainLoop()
+    else
+        MainLoop();
 
     // clean up all the memory allocated
     freeEverything(true);
@@ -456,6 +498,7 @@
         //uAIAmmoTests does not need to be freed
         //uAIActions does not need to be freed
         uStore.freeModule;
+        uVideoRec.freeModule;
     end;
 
     uIO.freeModule;
@@ -530,7 +573,7 @@
         if (ParamCount = 3) and ((ParamStr(3) = '--stats-only') or (ParamStr(3) = 'landpreview')) then
             internalSetGameTypeLandPreviewFromParameters()
         else
-            if (ParamCount = cDefaultParamNum) then
+            if (ParamCount = cDefaultParamNum) or (ParamCount = cDefaultParamNum+1) then
                 internalStartGameWithParameters()
             else
                 playReplayFileWithParameters();