Game Development Community

Demo Bookmarks

by Matt T · in Torque 3D Beginner · 05/01/2013 (8:52 am) · 1 replies

I added something I thought was nifty and works well enough. Legions is on TGEA 1.8.1 but I think this will still work for T3D ?

I have only been scripting for a few months , sure parts of this are quite messy. Sorry : (

The basic idea is:
-When the game/demorecording starts, start a function increasing $demoTime by 1 every 1ms.
-Generate a .txt file named the same as the demo.

-During gametime , pressing the bookmark keybind will append the file with a line of $demoTime

--

-When the demo is loaded and playback starts , same $demoTime function is started.

-Pressing the seek bind will set the timeScale to 30 until 5 seconds before the next bookmark found.
-Pressing the bookmark button during playback will insert a $demoTime bookmark into the file where it belongs.

--------

These two are for the keybindings:

function seekDemoBookmark(%val)
{
   if(%val)
   {
   }
   else
   {
   if($resuming == 1)
      {
      cancelResume();
      return;
      }
      if (ServerConnection.isDemoPlaying())
         {
         for(%i=-1;%i < 20;%i++)
            {
               if(%i == $currBookmark)
                  {

                  $currBookmark = %i++;
                  $timeScale = 30;

                  if(ReadBookmarkLine(%i))
                  {
                  }

                  resumeAtBookmark(%i);

                  $resuming = 1;
                  resuming();
                  return;
                  
                  }
            }
         }
         
         
      clientCmdBottomPrint("You are not playing back a demo.", 2500, 1);

   }
      
   //demoRecordingLogStart(qq);
}

function createDemoBookmark(%val)
{
   if(%val)
   {
   }
   else
   {
   //echo("herrro?");
   if($resuming == 1)
      {
      cancelResume();
      return;
      }
      if (ServerConnection.isDemoPlaying())
         {
            insertBookmark();
            //echo("inserting bookmark to file");
            return;
         }
      if(!ServerConnection.isDemoPlaying() && !ServerConnection.isDemoRecording())
         {
            clientCmdBottomPrint("You are not recording a demo.", 2500, 1);
            return;
         }
         
      for(%i=1;%i < 20;%i++)
         {
	        if($demoBookmarks::bookmark[%i] $= "")
		       {
                  $demoBookmarks::bookmark[%i] = getSimTime();
                  //demoRecordingLogStart($demoName);
                  appendFile($demoName);
                  clientCmdBottomPrint("Demo Bookmark Saved.", 2500, 1);
                  return;
               }
        }
   }


}

And this is the rest:

function startDemoTime()
{
   $demoTime = ($demoTime + 1);
   schedule(1,ServerConnection,"startDemoTime");
}



function resumeAtBookMark(%i)
{
   if($demoTime < ($bookMarkStopTime - 7000))
   {
      schedule(1,0,"resumeAtBookMark",%i);
      //$resuming = 1;
      return;
   }
         
   cancel($resumeSchedule);
   clientCmdDescriptionPrint("", 5000, "");
   $timescale = 1;
   $resuming = 0;
   //echo("I think the next bookmark is" SPC $bookMarkStopTime);
   //echo("the current demotime is" SPC $demoTime);
   //echo("the current simtime is" SPC getSimTime());

}



function resuming()
{
   clientCmdDescriptionPrint("Seeking to Bookmark. Press again to cancel.", 5000, "-");
   if($resuming == 1)
   {  
      $resumeSchedule = schedule(3000,0,"resuming");
   }
   
}



function cancelResume()
{
 
   echo("cancel resume");
   cancel($resumeSchedule);
   clientCmdDescriptionPrint("", 5000, "");
   $timeScale = 1;
   $resuming = 0;
   $currBookmark = $currBookmark--;
}



function ReadBookmarkLine(%i)
{
   $bookmarkFound = 0;
   %file = new FileObject();  
   if(%file.openForRead("legions/data/recordings/" @ $demoName @ ".txt"))  
   {  
      while(!%file.isEOF())  
      {
         %input = %file.readLine();
         %n++;  
         //echo(%input); 
         if($demoTime < (%input - 5000) && $bookmarkFound == 0)
            {
               $bookMarkStopTime = %input; 
               $bookmarkFound = 1;
               echo(%input);
            }
      }  
   }  
   
   %file.close();  
   %file.delete();
   return true;
}



function insertBookmark()
{

%line = 1;
%numberOfBookmarks = saveBookmarksToGroup();

//echo("next bookmark after scan is" SPC %next);
//echo("number of bookmarks I saved was" SPC %numberOfBookmarks);

%fw = new FileObject("FW");                    
FW.OpenForWrite("legions/data/recordings/" @ $demoName @ ".txt");

for(%i = 0; %i < %numberOfBookmarks; %i++)
   {
      if($bookmarkSaveLine[%i] > $demoTime && %bookmarkInserted == 0)
         {
            FW.writeline($demoTime);
            %bookmarkInserted = 1;
         }
         
      FW.writeline($bookmarkSaveLine[%i]);
   
   }  
     
FW.Close();                                  

}



function saveBookmarksToGroup()
{
%n = 0;

   %file = new FileObject();  
   if(%file.openForRead("legions/data/recordings/" @ $demoName @ ".txt"))  
   {  
      while(!%file.isEOF())  
      {
         %input = %file.readLine();
         $bookmarkSaveLine[%n] = %input;
         %n++;           
      }
   }
   %file.close();  
   %file.delete();
   return %n;
      
}



function demoBookmarksCreateFile(%file)  
{  
       
        %fw = new FileObject("FW");
        FW.OpenForWrite("legions/data/recordings/" @ %file @ ".txt"); 
        FW.Close();
}  
  


function appendfile(%file)  
{  
   
        %fa = new FileObject("FA");
        FA.OpenForAppend("legions/data/recordings/" @ %file @ ".txt");  
        FA.writeline($demoTime);    
        FA.Close();        
}

Some parts of this are print functions and names specific to Legions , just wanted to share the general idea. I'm sorry for how redundant certain parts probably are : D

It works very well as far as landing on the exact bookmark time you want. We cant has rewind but this helps!

A cool thing to try might be having certain events create the bookmarks automatically.



#1
05/01/2013 (10:29 am)
That's pretty cool, and that would definitely be a handy thing to have with a demo running on a show floor. That should work in T3D, the demo recording system is still in there. It was just kind of hidden away by not explicitly displaying it or binding any keys for it.