Module: rmanager.cpp

class RManager
.h

constructorRManager()
destructor~RManager()
Destroyvoid Destroy()
EnableAudiovoid EnableAudio(){ flags&=~NO_AUDIO; }

void RManager::DisableAudio(){ flags|=NO_AUDIO; }
void RManager::EnableControls(){ flags&=~NO_CONTROLS; }
void RManager::DisableControls(){ flags|=NO_CONTROLS; }

Createbool Create()

Create the managed items, so you can start using the Racer universe

LoadTrackbool LoadTrack(cstring trackName)

Loads a track and sets it into the scene



/*
 * RManager
 * 05-10-00: Created!
 * (c) Dolphinity/Ruud van Gaal
 */

#include <racer/racer.h>
#include <qlib/debug.h>
#pragma hdrstop
#include <qlib/app.h>
DEBUG_ENABLE

#define DEBUG_FILE "debug.ini"		// Debug settings
#define MAIN_FILE  "racer.ini"          // Global flags
#define GFX_FILE   "gfx.ini"            // Graphics settings

// Racer's one and only global variable, accessable through RMGR
RManager *__rmgr;

RManager::RManager()
{
  if(__rmgr)
  { qerr("RManager created more than once");
    return;
  }
  __rmgr=this;

  flags=0;
  devFlags=0;
  scene=0;
  trackFlat=0;
  trackVRML=0;
  controls=0;
  profile=0;
  audio=0;
  time=0;
  fontDefault=0;
  infoDebug=0;
  infoMain=new QInfo(RFindFile(MAIN_FILE));
  infoGfx=new QInfo(RFindFile(GFX_FILE));
  
  // Load preferences
  lowSpeed=infoMain->GetFloat("car.low_speed");
  resWidth=infoGfx->GetInt("resolution.width");
  resHeight=infoGfx->GetInt("resolution.height");
//qdbg("RMGR: main file='%s'\n",RFindFile(MAIN_FILE));
}
RManager::~RManager()
{
  Destroy();
}

void RManager::Destroy()
{
  if(scene){ delete scene; scene=0; }
  if(controls){ delete controls; controls=0; }
  if(audio){ delete audio; audio=0; }
  if(time){ delete time; time=0; }
  if(trackFlat){ delete trackFlat; trackFlat=0; }
  if(trackVRML){ delete trackVRML; trackVRML=0; }
  if(profile){ delete profile; profile=0; }
  if(fontDefault){ delete fontDefault; fontDefault=0; }
  if(infoDebug){ delete infoDebug; infoDebug=0; }
  if(infoMain){ delete infoMain; infoMain=0; }
  if(infoGfx){ delete infoGfx; infoGfx=0; }
}

/***********
* Creation *
***********/
void RManager::EnableAudio(){ flags&=~NO_AUDIO; }
void RManager::DisableAudio(){ flags|=NO_AUDIO; }
void RManager::EnableControls(){ flags&=~NO_CONTROLS; }
void RManager::DisableControls(){ flags|=NO_CONTROLS; }

bool RManager::Create()
// Create the managed items, so you can start using the Racer universe
{
  // Info files
  infoDebug=new QInfo(RFindFile(DEBUG_FILE));

  // Get some more prefs now that the debug file is known
  if(infoDebug->GetInt("stats.show_tire_forces"))
    flags|=SHOW_TIRE_FORCES;
  
  time=new RTime();
  scene=new RScene();
  if(!(flags&NO_CONTROLS))
    controls=new RControls();
  if(!(flags&NO_AUDIO))
    audio=new RAudio();

  profile=new RProfile();

  // Create default fonts
  fontDefault=new DTexFont("data/fonts/euro16");
  
  return TRUE;
}

/*********
* TRACKS *
*********/
bool RManager::LoadTrack(cstring trackName)
// Loads a track and sets it into the scene
{
  RTrack *trackNew;
  bool r=TRUE;                // Return value
  
  // Make sure textures go into the right OpenGL context
  QCV->Select();
  
  // Attempt to find track to get its type
  trackNew=new RTrack();
  trackNew->SetName(trackName);
  trackNew->Load();
qdbg("RMGR:Track(%s); type=%s\n",trackName,trackNew->GetType());
  
  // Delete old track
  //...
  
  // Load new track
  if(!strcmp(trackNew->GetType(),"vrml"))
  {
qdbg("Loading VRML track\n");
    trackVRML=new RTrackVRML();
    trackVRML->SetName(trackName);
    trackVRML->Load();
    track=trackVRML;
    scene->SetTrack(RMGR->trackVRML);
  } else if(!strcmp(trackNew->GetType(),"flat"))
  {
qdbg("Loading FLAT track\n");
    trackFlat=new RTrackFlat();
    trackFlat->SetName(trackName);
    trackFlat->Load();
    track=trackFlat;
    scene->SetTrack(RMGR->trackFlat);
  } else
  {
    qwarn("RManager:LoadTrack(%s); unknown track type (%s)",
      trackName,trackNew->GetType());
    r=FALSE;
  }
  delete trackNew;
  return r;
}