//eval( "dbgSetParameters( 6060, \"password\"" @ ( $dbgVersion > 0 ? ", true );" : " );" ) );

//-----------------------------------------------------------------------------
// GarageGames Billiards 
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
$collisionsButtonFlag = false;
$statsButtonFlag = false;
$Game::tryingFullscreen = false;

function BIT(%bitIndex)
{
   // -- bit-shifter helper
   // ----

   return 1<<%bitIndex;
}

function timerTest()
{
   %stime = getSimTime();
   %rtime = getRealTime();
   
   schedule(5000, 0, timerPrint, %stime, %rtime);
}

function timerPrint(%simTime, %realTime)
{
   %stime = getSimTime();
   %rtime = getRealTime();
   
   error("sim: " SPC %stime - %simTime);
   error("real:" SPC %rtime - %realTime);
}

function toggleCollisions()
{
   // -- displays all collision polies
   // ----
   
   if(!$collisionsButtonFlag)
   {
      $collisionsButtonFlag = true;	
      $poolSceneGraph2D.setDebugOn(BIT(5));
   }
   else
   {   
      $collisionsButtonFlag = false;
      $poolSceneGraph2D.setDebugOff(BIT(5));
   }
}

function toggleStats()
{
   // -- displays object boxes for all objects
   // ----
   
   if(!$statsButtonFlag)
   {
      $statsButtonFlag = true;
      //$poolSceneGraph2D.setDebugOn(BIT(0) | BIT(1));
      $poolSceneGraph2D.setDebugOn(BIT(1));
   }
   else
   {
      $statsButtonFlag = false;
      //$poolSceneGraph2D.setDebugOff(BIT(0) | BIT(1));
      $poolSceneGraph2D.setDebugOff(BIT(1));
   }
}


//-----------------------------------------------------------------------------


function savePrefs()
{
   // -- save preferences
   //----
   
   export("$pref::*", "pool/saves/prefs.cs");
}

function loadPrefs()
{
   // -- load preferences
   // ----
   
   // first load defaults
   exec("pool/saves/defaults.cs");
   
   // find and load any client preferences
   if(isFile("pool/saves/prefs.cs"))
      exec("pool/saves/prefs.cs");
}


//-----------------------------------------------------------------------------


function onStart()
{
   // -- default startup function
   // ----
   
   // make sure we are random
   setRandomSeed();
   
   // load preferences
   loadPrefs();
   
   // load the openal audio system
   // Need to load this early so that sound profiles can preload
   exec("pool/audio.cs");
   OpenALInit();
   
   // load the canvas
   exec("pool/locale/localization.cs");
   exec("pool/sound/soundProfiles.cs");
   exec("pool/gui/common/ui_canvas.cs");
   
   // initCanvas starts up the graphics system, the canvas needs to be
   // constructed before the gui scripts are executed because many
   // of the controls assume the canvas exists at load time
   if( initCanvas($Text::GameTitle) )
   {      
      // load and init the client
      exec("pool/main.cs");
      createClient();
      
      //populateFonts(); 
      //fontbitmapIO(1);
      
      // start up the splash screen
      ui_screenSplash.loadSplash();
   }
   else
      quit();
      
   // rdb: now apply audio prefs 
   applyAudioPrefs();
}

function onExit()
{
   // -- onExit is called directly from C++
   // ----
      
   // kill the client
   destroyClient();
   
   // kill audio
   OpenALShutdown();
   
   // save prefs
   savePrefs();
}

function screenModeForceFullscreen()
{
   if( $Game::tryingFullscreen )
      MessageBoxOK( "Display Change Failure", "\nDevice or Desktop color depth does not allow windowed mode!", "" );
   
   $Game::tryingFullscreen = false;
}


//-----------------------------------------------------------------------------


// default to a new logfile each session.
setLogMode(6);

// set the mod path which dictates which directories will be visible
// to the scripts and the resource engine
setModPaths("pool");
//setModPaths("pool;particleeditor");
//exec("particleeditor/main.cs");

//new ConsoleLogger( warnLog, "logwarnings.txt", false )
//{
//   level = "warning";
//};

//new ConsoleLogger( errorLog, "logerrors.txt", false )
//{
//   level = "error";
//};


// startup the pool game
echo("T2D Engine (" @ getT2DVersion() @ ") initialized...");
onStart();
