Game Development Community

RestartInstance works?

by Paul /*ilys*/ Symeou · in Torque Game Engine · 07/17/2008 (6:17 am) · 4 replies

I've noticed this console function exists, along with the code to do the do which is never called. Is there something fundamentally wrong with the code or is the functionality just not hooked in?

Getting it to restart the instance seems simple enough, just add the following to the bottom of DemoGame::main() in main.cc before the very last "return 0;" and use the console function "restartInstance();"

if(Game->requiresRestart())
      Platform::restartInstance();

It seems to work on Windows, but I have no idea if it works on Mac or Linux.

#1
07/17/2008 (6:26 am)
It does work fine on Windows, the only thing I had an issue with is that the restart doesn't inherit anything you may have launched with in terms of command line arguments in the first place. So as long as that's not a problem for ya, it's a handy little thing.
#2
07/17/2008 (7:42 am)
Actually, it is possible to pass the command line arguments to the child process.
In winWindow, use the following code:
void Platform::restartInstance()
{
   if( Game->isRunning() )
   {
      //Con::errorf( "Error restarting instance, Game is still running!");
      return;
   }
  
   STARTUPINFO si;
   PROCESS_INFORMATION pi;


   ZeroMemory( &si, sizeof(si) );
   si.cb = sizeof(si);
   ZeroMemory( &pi, sizeof(pi) );


   char cen_buf[2048];
   GetModuleFileNameA( NULL, cen_buf, 2047);
#ifdef UNICODE
   UTF16 b[512];
   convertUTF8toUTF16((UTF8 *)cen_buf, b, sizeof(b));
#else
   const char* b = cen_buf;
#endif
   [b]LPWSTR lpszCmdLine = GetCommandLine();[/b]
   // Start the child process. 
   if( CreateProcess( b,
      [b]lpszCmdLine,    // Command line[/b]
      NULL,           // Process handle not inheritable
      NULL,           // Thread handle not inheritable
      FALSE,          // Set handle inheritance to FALSE
      0,              // No creation flags
      NULL,           // Use parent's environment block
      NULL,           // Use parent's starting directory 
      &si,            // Pointer to STARTUPINFO structure
      &pi )           // Pointer to PROCESS_INFORMATION structure
      != false )
   {
      WaitForInputIdle( pi.hProcess, 5000 );
      CloseHandle( pi.hProcess );
      CloseHandle( pi.hThread );
   }
}
#3
07/17/2008 (7:56 am)
Well done Paul.
#4
07/17/2008 (8:05 am)
My only problem is Mac and Linux. I have absolutely no programming knowledge on either platforms, and it would be nice to get all three working :)