瀏覽代碼

enable video recording

Johxz 8 年之前
父節點
當前提交
5e47c018b2

+ 15 - 0
Templates/Empty/game/core/scripts/client/screenshot.cs

@@ -55,6 +55,9 @@ function formatSessionNumber(%number)
 // Records a movie file from the Canvas content using the specified fps.
 // Possible encoder values are "PNG" and "THEORA" (default).
 //---------------------------------------------------------------------------------------------
+
+$RecordingMovie = false;
+
 function recordMovie(%movieName, %fps, %encoder)
 {
    // If the canvas doesn't exist yet, setup a flag so it'll 
@@ -65,12 +68,24 @@ function recordMovie(%movieName, %fps, %encoder)
    if (%encoder $= "") 
       %encoder = "THEORA";   
    %resolution = Canvas.getVideoMode();
+   
+   // Start the movie recording
+   ChatHud.AddLine( "\c4Recording movie file to [\c2" @ %movieName @ "\cr].ogv.");
+   echo("Recording movie to: " @ %movieName);   
    startVideoCapture(Canvas, %movieName, %encoder, %fps); 
+   
+    $RecordingMovie = true;
 }
 
 function stopMovie()
 {
+   // Stop the current recording
+   ChatHud.AddLine( "\c4Recording movie file finished.");
+   echo("Stopped movie recording");
+   
    stopVideoCapture();
+
+   $RecordingMovie = false;
 }
 
 /// This is bound in initializeCommon() to take

+ 43 - 0
Templates/Empty/game/scripts/client/default.bind.cs

@@ -409,6 +409,49 @@ function stopRecordingDemo( %val )
 moveMap.bind( keyboard, F3, startRecordingDemo );
 moveMap.bind( keyboard, F4, stopRecordingDemo );
 
+//------------------------------------------------------------------------------
+// Theora Video Capture (Records a movie file)  
+//------------------------------------------------------------------------------
+
+function toggleMovieRecording(%val)
+{
+   if (!%val)
+      return;
+
+   %movieEncodingType = "THEORA";  // Valid encoder values are "PNG" and "THEORA" (default). 
+   %movieFPS = 30;  // video capture frame rate.
+   
+   if (!$RecordingMovie)
+   {
+       // locate a non-existent filename to use
+       for(%i = 0; %i < 1000; %i++)
+       {
+          %num = %i;
+          if(%num < 10)
+             %num = "0" @ %num;
+          if(%num < 100)
+             %num = "0" @ %num;
+       
+          %filePath = "movies/movie" @ %num;
+          if(!isfile(%filePath))
+             break;
+       }
+       if(%i == 1000)
+          return;
+
+      // Start the movie recording
+      recordMovie(%filePath, %movieFPS, %movieEncodingType);
+      
+   }
+   else
+   {
+      // Stop the current recording
+      stopMovie();
+   }
+}
+
+// Key binding works at any time and not just while in a game.
+GlobalActionMap.bind(keyboard, "alt m", toggleMovieRecording);
 
 //------------------------------------------------------------------------------
 // Helper Functions

+ 15 - 0
Templates/Full/game/core/scripts/client/screenshot.cs

@@ -55,6 +55,9 @@ function formatSessionNumber(%number)
 // Records a movie file from the Canvas content using the specified fps.
 // Possible encoder values are "PNG" and "THEORA" (default).
 //---------------------------------------------------------------------------------------------
+
+$RecordingMovie = false;
+
 function recordMovie(%movieName, %fps, %encoder)
 {
    // If the canvas doesn't exist yet, setup a flag so it'll 
@@ -65,12 +68,24 @@ function recordMovie(%movieName, %fps, %encoder)
    if (%encoder $= "") 
       %encoder = "THEORA";   
    %resolution = Canvas.getVideoMode();
+   
+   // Start the movie recording
+   ChatHud.AddLine( "\c4Recording movie file to [\c2" @ %movieName @ "\cr].ogv.");
+   echo("Recording movie to: " @ %movieName);   
    startVideoCapture(Canvas, %movieName, %encoder, %fps); 
+   
+    $RecordingMovie = true;
 }
 
 function stopMovie()
 {
+   // Stop the current recording
+   ChatHud.AddLine( "\c4Recording movie file finished.");
+   echo("Stopped movie recording");
+   
    stopVideoCapture();
+
+   $RecordingMovie = false;
 }
 
 /// This is bound in initializeCommon() to take

+ 43 - 0
Templates/Full/game/scripts/client/default.bind.cs

@@ -583,6 +583,49 @@ function stopRecordingDemo( %val )
 moveMap.bind( keyboard, F3, startRecordingDemo );
 moveMap.bind( keyboard, F4, stopRecordingDemo );
 
+//------------------------------------------------------------------------------
+// Theora Video Capture (Records a movie file)  
+//------------------------------------------------------------------------------
+
+function toggleMovieRecording(%val)
+{
+   if (!%val)
+      return;
+
+   %movieEncodingType = "THEORA";  // Valid encoder values are "PNG" and "THEORA" (default). 
+   %movieFPS = 30;  // video capture frame rate.
+   
+   if (!$RecordingMovie)
+   {
+       // locate a non-existent filename to use
+       for(%i = 0; %i < 1000; %i++)
+       {
+          %num = %i;
+          if(%num < 10)
+             %num = "0" @ %num;
+          if(%num < 100)
+             %num = "0" @ %num;
+       
+          %filePath = "movies/movie" @ %num;
+          if(!isfile(%filePath))
+             break;
+       }
+       if(%i == 1000)
+          return;
+
+      // Start the movie recording
+      recordMovie(%filePath, %movieFPS, %movieEncodingType);
+      
+   }
+   else
+   {
+      // Stop the current recording
+      stopMovie();
+   }
+}
+
+// Key binding works at any time and not just while in a game.
+GlobalActionMap.bind(keyboard, "alt m", toggleMovieRecording);
 
 //------------------------------------------------------------------------------
 // Helper Functions