src/main.cpp File Reference

#include <fenv.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <SDL/SDL.h>
#include <math.h>
#include <string>
#include <vector>
#include "font.h"
#include "utility.h"
#include "textures.h"
#include "backdrop.h"
#include "camera.h"
#include "weather.h"
#include "keyman.h"
#include "mouse.h"
#include "messageq.h"
#include "particles.h"
#include "settings.h"
#include "sound.h"
#include "timer.h"
#include "controls.h"
#include "vamosworld.h"
#include "replay.h"
#include "logo.h"
#include "gamestate.h"
#include "objects.h"
#include "multiplay.h"
#include "net.h"
#include "configfile.h"
#include "bezier.h"
#include "track.h"
#include "exception.h"
#include "cardinfo.h"
#include <vamos/body/Gl_Car.h>
#include <vamos/geometry/Texture_Image.h>
#include <vamos/geometry/Three_Vector.h>
#include <vamos/body/Car.h>
#include <vamos/body/Fuel_Tank.h>
#include <vamos/body/Wheel.h>
#include <vamos/geometry/Conversions.h>
#include <vamos/world/World.h>
#include "gui/gui.h"

Include dependency graph for main.cpp:

Go to the source code of this file.

Namespaces

namespace  std

Defines

#define GL_GLEXT_PROTOTYPES
#define TRUE   1
#define FALSE   0
#define CAR_Y_OFFSET   1.0
#define AVERAGEFRAMES   5
#define FRAME_TIME   0.004

Functions

float FrameTime ()
int Screenshot (char *filename)
void ResetWorld (bool fullreset)
void Quit (int returnCode)
int resizeWindow (int width, int height)
void LoadingScreen (string loadtext)
void ChangeDisplay (int w, int h, int bpp, bool fullscreen, bool reloadtextures)
void ReloadDisplay ()
void Update ()
void snap_screenshot ()
void MainPause ()
void MainUnpause ()
void handleKeyPress (SDL_keysym *keysym)
void handleKeyRelease (SDL_keysym *keysym)
void glSetup ()
void SelectCar (string cfile, bool trim)
bool UnloadWorld ()
bool LoadWorld ()
void InitGameData ()
void InitGL (GLvoid)
int drawGLScene (GLvoid)
bool isExtensionSupported (string extstring)
int main (int argc, char **argv)

Variables

int SCREEN_WIDTH = 1024
int SCREEN_HEIGHT = 768
int SCREEN_BPP = 32
bool verbose_output = false
SDL_Surface * surface
GLfloat LightAmbient [] = { 0.15f, 0.15f, 0.15f, 1.0f }
GLfloat LightDiffuse [] = { 1.0f, 1.0f, 1.0f, 1.0f }
GLfloat LightSpecular [] = { 0.0f, 0.0f, 0.0f, 0.0f }
GLfloat LightPosition [4]
KEYMAN keyman
GAMECONTROLS gamecontrols
SETTINGS settings
TEXTURES textures
CAMERA cam
FONT font
UTILITY utility
BACKDROP backdrop
WEATHER weathersystem
MOUSE mouse
MESSAGEQ mq1
PARTICLE particle
SOUNDMANAGER sound
TIMER timer
REPLAY replay
LOGO logo
GAMESTATE state
OBJECTS objects
NET net
MULTIPLAY multiplay
VGUI::Gui gui
TRACK track
CARDINFO gfxcard
VAMOSWORLD world
ofstream error_log
double day_time
double abs_time
static GLint T0
static GLint Frames
static GLfloat fps
bool showfps
static int frameno
float timefactor = 1.0f
float pfps
float lfps [AVERAGEFRAMES]
int lfpspos = 0
bool lfpsfull = false
double execution_time = 0.0
bool pauserequest = false
bool unpauserequest = false
bool esc_pressed = false
float view_dist = 10000.0
string cur_tex_size = ""
int cur_screen_w = 0
int cur_screen_h = 0
int cur_screen_bpp = 0
bool cur_fullscreen = false
string tree_detail = ""
string data_dir


Define Documentation

#define AVERAGEFRAMES   5
 

Definition at line 194 of file main.cpp.

#define CAR_Y_OFFSET   1.0
 

Definition at line 177 of file main.cpp.

Referenced by SelectCar().

#define FALSE   0
 

Definition at line 102 of file main.cpp.

Referenced by main().

#define FRAME_TIME   0.004
 

Definition at line 202 of file main.cpp.

Referenced by FrameTime(), and Update().

#define GL_GLEXT_PROTOTYPES
 

Definition at line 2 of file main.cpp.

#define TRUE   1
 

Definition at line 101 of file main.cpp.

Referenced by main(), and resizeWindow().


Function Documentation

void ChangeDisplay int  w,
int  h,
int  bpp,
bool  fullscreen,
bool  reloadtextures
 

Definition at line 331 of file main.cpp.

References backdrop, font, gamecontrols, VGUI::Gui::GetEnabled(), gui, BACKDROP::Init(), TIMER::Load(), PARTICLE::Load(), FONT::Load(), GAMECONTROLS::LoadControls(), VAMOSWORLD::LoadHUD(), LoadingScreen(), NULL, particle, VGUI::Gui::ReInit(), TEXTURES::ReloadAll(), resizeWindow(), SCREEN_BPP, SCREEN_HEIGHT, SCREEN_WIDTH, VGUI::Gui::SetEnabled(), surface, textures, timer, VAMOSWORLD::UnloadHUD(), VGUI::Gui::UpdateScreenSize(), and world.

Referenced by ReloadDisplay().

int drawGLScene GLvoid   ) 
 

Definition at line 1700 of file main.cpp.

References backdrop, WEATHER::GetFogDensity(), GAMESTATE::GetGameState(), BACKDROP::RefreshFog(), BACKDROP::SetFogStrength(), state, STATE_INITIALMENU, and weathersystem.

float FrameTime  ) 
 

Definition at line 219 of file main.cpp.

References FRAME_TIME.

Referenced by MULTIPLAY::GetPacketArrayTime(), REPLAY::Jump(), REPLAY::PlayIncrement(), REPLAY::PlayProcessFrame(), MULTIPLAY::ReceivePacketArray(), MULTIPLAY::ReceiveState(), MULTIPLAY::SendPacketArray(), MULTIPLAY::SendState(), MULTIPLAY::UpdateFuncmem(), and MULTIPLAY::UpdateStats().

void glSetup  ) 
 

Definition at line 740 of file main.cpp.

Referenced by LoadingScreen().

void handleKeyPress SDL_keysym *  keysym  ) 
 

Definition at line 639 of file main.cpp.

References esc_pressed, VGUI::Gui::GetEnabled(), and gui.

void handleKeyRelease SDL_keysym *  keysym  ) 
 

Definition at line 714 of file main.cpp.

References esc_pressed, VGUI::Gui::GetEnabled(), gui, keyman, MainPause(), and KEYMAN::OneTime().

void InitGameData  ) 
 

Definition at line 1184 of file main.cpp.

References abs_time, cam, day_time, gamecontrols, SETTINGS::Get(), GAMESTATE::GetCarName(), GAMESTATE::GetTrackName(), NET::Init(), WEATHER::Init(), UTILITY::Init(), keyman, LightPosition, TIMER::Load(), PARTICLE::Load(), KEYMAN::Load(), GAMECONTROLS::LoadControls(), LoadingScreen(), CAMERA::LoadVelocityIdentity(), logo, CAMERA::Move(), mq1, net, particle, LOGO::run(), MESSAGEQ::SetBuildUp(), GAMESTATE::SetCarName(), GAMESTATE::SetCarPaint(), MESSAGEQ::SetDepth(), GAMESTATE::SetGameState(), MESSAGEQ::SetPersist(), MESSAGEQ::SetPos(), settings, GAMESTATE::SetTrackName(), PARTICLE::SetWind(), state, STATE_INITIALMENU, STATE_LOGO, timer, track, CAMERA::Update(), WEATHER::Update(), utility, weathersystem, VERTEX::x, and VERTEX::z.

void InitGL GLvoid   ) 
 

Definition at line 1323 of file main.cpp.

References font, LightAmbient, LightDiffuse, LightPosition, LightSpecular, FONT::Load(), SCREEN_HEIGHT, and SCREEN_WIDTH.

bool isExtensionSupported string  extstring  ) 
 

Definition at line 2088 of file main.cpp.

void LoadingScreen string  loadtext  ) 
 

Definition at line 1378 of file main.cpp.

References font, fps, Frames, glSetup(), FONT::Print(), T0, UTILITY::Tex2D(), utility, and verbose_output.

Referenced by ChangeDisplay(), InitGameData(), and LoadWorld().

bool LoadWorld  ) 
 

Definition at line 876 of file main.cpp.

References MESSAGEQ::AddMessage(), backdrop, PARTICLE::Clear(), OBJECTS::Collide(), TRACK::CollideRoads(), BEZIER::CollideSubDivQuadSimpleNorm(), data_dir, VERTEX::DebugPrint(), SETTINGS::Get(), GAMESTATE::GetCarName(), SETTINGS::GetDataDir(), TRACK::GetPatch(), GAMESTATE::GetTrackName(), BACKDROP::Init(), VAMOSWORLD::Init(), TRACK::Load(), LoadingScreen(), OBJECTS::LoadObjectsFromFolder(), mq1, VERTEX::normalize(), NULL, objects, particle, SOUNDMANAGER::Reload(), TIMER::Reset(), TIMER::ResetBest(), TIMER::ResetLast(), VERTEX::Scale(), VERTEX::ScaleR(), SelectCar(), VERTEX::Set(), GAMESTATE::SetCarName(), GAMESTATE::SetCarPaint(), settings, GAMESTATE::SetTrackName(), sound, state, timefactor, timer, track, UnloadWorld(), world, and VERTEX::y.

int main int  argc,
char **  argv
 

Definition at line 2124 of file main.cpp.

References error_log, FALSE, SETTINGS::GetSettingsDir(), NULL, settings, surface, TRUE, and verbose_output.

void MainPause  ) 
 

Definition at line 618 of file main.cpp.

References VGUI::Gui::GetEnabled(), gui, multiplay, MULTIPLAY::NumConnected(), pauserequest, and VGUI::Gui::ProcessAction().

void MainUnpause  ) 
 

Definition at line 633 of file main.cpp.

References unpauserequest.

void Quit int  returnCode  ) 
 

Cleaup and exit.

Parameters:
returnCode the exit code
This function cleans up the game state and restores the desktop environment to it's previous state.

Definition at line 275 of file main.cpp.

References error_log, gamecontrols, REPLAY::Recording(), replay, GAMESTATE::SetGameState(), state, STATE_EXIT, REPLAY::Stop(), verbose_output, and GAMECONTROLS::WriteControlFile().

Referenced by VGUI::Gui::ProcessAction().

void ReloadDisplay  ) 
 

Definition at line 402 of file main.cpp.

References ChangeDisplay(), cur_fullscreen, cur_screen_bpp, cur_screen_h, cur_screen_w, cur_tex_size, SETTINGS::Get(), objects, settings, showfps, tree_detail, OBJECTS::UpdateSettings(), VAMOSWORLD::UpdateSettings(), view_dist, and world.

Referenced by VGUI::Gui::ProcessAction().

void ResetWorld bool  fullreset  ) 
 

int resizeWindow int  width,
int  height
 

Definition at line 299 of file main.cpp.

References TRUE.

Referenced by ChangeDisplay().

int Screenshot char *  filename  ) 
 

Definition at line 224 of file main.cpp.

References NULL, and surface.

Referenced by snap_screenshot().

void SelectCar string  cfile,
bool  trim
 

Definition at line 777 of file main.cpp.

References VAMOSWORLD::add_car(), CAR_Y_OFFSET, Vamos_Body::Car::chassis(), VAMOSWORLD::clear_cars(), GAMESTATE::GetCarName(), GAMESTATE::GetCarPaint(), TRACK::GetStart(), multiplay, MULTIPLAY::MyNum(), MULTIPLAY::NumConnected(), Vamos_Body::Car::read(), Vamos_Body::Car::set_controller(), GAMESTATE::SetCarName(), Vamos_Body::Gl_Car::SetPaint(), Vamos_Body::Car::start_engine(), state, track, world, VERTEX::x, VERTEX::y, and VERTEX::z.

Referenced by LoadWorld(), and ResetWorld().

void snap_screenshot  ) 
 

Definition at line 608 of file main.cpp.

References SETTINGS::Get(), SETTINGS::GetSettingsDir(), Screenshot(), SETTINGS::Set(), and settings.

bool UnloadWorld  ) 
 

Definition at line 859 of file main.cpp.

References backdrop, VAMOSWORLD::DeInit(), BACKDROP::DeInit(), sound, SOUNDMANAGER::Unload(), and world.

Referenced by LoadWorld().

void Update  ) 
 

Definition at line 437 of file main.cpp.

References abs_time, backdrop, cam, day_time, KEYMAN::DoHeldKeys(), KEYMAN::DoOneTimeKeys(), execution_time, fps, FRAME_TIME, gamecontrols, GAMECONTROLS::Get_js(), GAMESTATE::GetGameState(), keyman, LightDiffuse, LightPosition, mouse, MP_DBGDEEP, multiplay, particle, VERTEX::Scale(), SCREEN_HEIGHT, SCREEN_WIDTH, MULTIPLAY::Send(), VERTEX::Set(), state, STATE_INITIALMENU, BACKDROP::sunpos_lat, TIMER::TickTimer(), timefactor, timer, PARTICLE::Update(), VAMOSWORLD::Update(), WEATHER::Update(), MOUSE::Update(), VERTEX::v3(), weathersystem, and world.


Variable Documentation

double abs_time
 

Definition at line 180 of file main.cpp.

Referenced by InitGameData(), and Update().

BACKDROP backdrop
 

Definition at line 152 of file main.cpp.

Referenced by ChangeDisplay(), drawGLScene(), LoadWorld(), UnloadWorld(), and Update().

CAMERA cam
 

Definition at line 149 of file main.cpp.

Referenced by KEYMAN::DoHeldKeys(), BACKDROP::DrawClouds(), OBJECTS::DrawObject(), BACKDROP::DrawRain(), BACKDROP::DrawSky(), VAMOSWORLD::Init(), InitGameData(), VAMOSWORLD::SetCameraMode(), Update(), MOUSE::UpdateCamera(), and ROADSTRIP::Visualize().

bool cur_fullscreen = false
 

Definition at line 216 of file main.cpp.

Referenced by ReloadDisplay().

int cur_screen_bpp = 0
 

Definition at line 215 of file main.cpp.

Referenced by ReloadDisplay().

int cur_screen_h = 0
 

Definition at line 214 of file main.cpp.

Referenced by ReloadDisplay().

int cur_screen_w = 0
 

Definition at line 213 of file main.cpp.

Referenced by ReloadDisplay().

string cur_tex_size = ""
 

Definition at line 212 of file main.cpp.

Referenced by ReloadDisplay().

string data_dir
 

Definition at line 771 of file main.cpp.

Referenced by br_find_locale_dir(), and LoadWorld().

double day_time
 

Definition at line 179 of file main.cpp.

Referenced by InitGameData(), and Update().

ofstream error_log
 

Definition at line 175 of file main.cpp.

Referenced by main(), and Quit().

bool esc_pressed = false
 

Definition at line 207 of file main.cpp.

Referenced by handleKeyPress(), and handleKeyRelease().

double execution_time = 0.0
 

Definition at line 203 of file main.cpp.

Referenced by Update().

FONT font
 

Definition at line 150 of file main.cpp.

Referenced by VGUI::Button::Button(), ChangeDisplay(), TIMER::Draw(), VGUI::Toggle::Draw(), VGUI::TextBox::Draw(), VGUI::Slider::Draw(), VGUI::Page::Draw(), VGUI::Label::Draw(), VGUI::Calibrate::Draw(), VGUI::Button::Draw(), VGUI::Wheel2< wheel_t1, wheel_t2 >::Draw(), VGUI::Wheel< wheel_t >::Draw(), Vamos_Body::Gl_Car::draw_string(), VAMOSWORLD::DrawHUD(), InitGL(), LoadingScreen(), VGUI::TextBox::MousePress(), VGUI::TextBox::MouseRelease(), VGUI::TextBox::SetSpacing(), and VGUI::TextBox::TextBox().

GLfloat fps [static]
 

Definition at line 185 of file main.cpp.

Referenced by LoadingScreen(), LOGO::run(), and Update().

int frameno [static]
 

Definition at line 189 of file main.cpp.

GLint Frames [static]
 

Definition at line 184 of file main.cpp.

Referenced by LoadingScreen().

GAMECONTROLS gamecontrols
 

Definition at line 146 of file main.cpp.

Referenced by VGUI::ControlGrab::BuildControlVectors(), ChangeDisplay(), InitGameData(), VGUI::Gui::ProcessAction(), Quit(), VGUI::ControlGrab::Save(), VGUI::Calibrate::Save(), VAMOSWORLD::steer_to(), and Update().

CARDINFO gfxcard
 

Definition at line 170 of file main.cpp.

Referenced by UTILITY::TexLoad().

VGUI::Gui gui
 

Definition at line 168 of file main.cpp.

Referenced by ChangeDisplay(), handleKeyPress(), handleKeyRelease(), and MainPause().

KEYMAN keyman
 

Definition at line 145 of file main.cpp.

Referenced by VGUI::ControlGrab::GrabKey(), handleKeyRelease(), InitGameData(), VAMOSWORLD::SetCameraMode(), and Update().

float lfps[AVERAGEFRAMES]
 

Definition at line 197 of file main.cpp.

bool lfpsfull = false
 

Definition at line 199 of file main.cpp.

int lfpspos = 0
 

Definition at line 198 of file main.cpp.

GLfloat LightAmbient[] = { 0.15f, 0.15f, 0.15f, 1.0f }
 

Definition at line 129 of file main.cpp.

Referenced by VGUI::SpinningCar::Draw(), and InitGL().

GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }
 

Definition at line 132 of file main.cpp.

Referenced by VGUI::SpinningCar::Draw(), InitGL(), and Update().

GLfloat LightPosition[4]
 

Definition at line 135 of file main.cpp.

Referenced by VAMOSWORLD::Draw(), VGUI::SpinningCar::Draw(), VAMOSWORLD::DrawCars(), InitGameData(), InitGL(), Vamos_Body::Gl_Car::transform_body(), and Update().

GLfloat LightSpecular[] = { 0.0f, 0.0f, 0.0f, 0.0f }
 

Definition at line 133 of file main.cpp.

Referenced by VGUI::SpinningCar::Draw(), and InitGL().

LOGO logo
 

Definition at line 163 of file main.cpp.

Referenced by InitGameData().

MOUSE mouse
 

Definition at line 154 of file main.cpp.

Referenced by VGUI::Gui::MousePress(), VGUI::Gui::MouseRelease(), VGUI::Gui::MouseUpdate(), VGUI::Gui::ProcessAction(), and Update().

MESSAGEQ mq1
 

Definition at line 155 of file main.cpp.

Referenced by MULTIPLAY::Connect(), InitGameData(), and LoadWorld().

MULTIPLAY multiplay
 

Definition at line 167 of file main.cpp.

Referenced by VAMOSWORLD::DrawHUD(), MainPause(), VAMOSWORLD::PhysUpdate(), SelectCar(), and Update().

NET net
 

Definition at line 166 of file main.cpp.

Referenced by MULTIPLAY::Connect(), MULTIPLAY::Connected(), MULTIPLAY::Disconnect(), MULTIPLAY::Host(), InitGameData(), MULTIPLAY::ReceivePacketArray(), MULTIPLAY::ReceiveState(), MULTIPLAY::SendPacketArray(), MULTIPLAY::SendState(), MULTIPLAY::Server(), and MULTIPLAY::UpdateStats().

OBJECTS objects
 

Definition at line 165 of file main.cpp.

Referenced by TRACK::Collide(), TRACK::CollideD(), TRACK::CollideModel(), LoadWorld(), and ReloadDisplay().

PARTICLE particle
 

Definition at line 157 of file main.cpp.

Referenced by ChangeDisplay(), VAMOSWORLD::DrawTopLevel(), InitGameData(), LoadWorld(), Update(), and Vamos_Body::Rigid_Body::velocity().

bool pauserequest = false
 

Definition at line 205 of file main.cpp.

Referenced by MainPause().

float pfps
 

Definition at line 196 of file main.cpp.

REPLAY replay
 

Definition at line 161 of file main.cpp.

Referenced by MULTIPLAY::Connect(), MULTIPLAY::Disconnect(), VAMOSWORLD::DrawHUD(), MULTIPLAY::ExchangeWorldInfo(), MULTIPLAY::Host(), NET::IsEqualToPacket(), VAMOSWORLD::PhysUpdate(), VGUI::Gui::ProcessAction(), VAMOSWORLD::ProcessControls(), MULTIPLAY::ProcessPacket(), Quit(), MULTIPLAY::ReadState(), MULTIPLAY::ReceivePacketArray(), MULTIPLAY::ReceiveState(), MULTIPLAY::SendPacketArray(), VAMOSWORLD::steer_commit(), and NET::WriteToPacket().

int SCREEN_BPP = 32
 

Definition at line 111 of file main.cpp.

Referenced by ChangeDisplay().

int SCREEN_HEIGHT = 768
 

Definition at line 110 of file main.cpp.

Referenced by ChangeDisplay(), InitGL(), and Update().

int SCREEN_WIDTH = 1024
 

Definition at line 109 of file main.cpp.

Referenced by ChangeDisplay(), InitGL(), and Update().

SETTINGS settings
 

Definition at line 147 of file main.cpp.

Referenced by REPLAY::BuildFuncMem(), VGUI::Button::Button(), VGUI::Calibrate::Calibrate(), VGUI::ControlGrab::ControlGrab(), Vamos_Body::Gl_Car::engine_sound(), Vamos_Body::Gl_Car::exterior_model(), FONT::FONT(), SETTINGS::GetCarPartName(), VGUI::Gui::Gui(), VAMOSWORLD::Init(), UTILITY::Init(), VGUI::Gui::Init(), BACKDROP::Init(), InitGameData(), Vamos_Body::Gl_Car::interior_model(), TIMER::Lap(), VERTEXD::len(), VERTEX::len(), TRACK::Load(), SOUNDMANAGER::Load(), KEYMAN::Load(), VGUI::MultiImage::Load(), FONT::Load(), GAMECONTROLS::LoadCalibration(), VGUI::SpinningCar::LoadCar(), Vamos_Body::Car::LoadCarDefinition(), SETTINGS::LoadCarPartsSettings(), GAMECONTROLS::LoadControls(), Vamos_Body::Car::LoadPart(), LoadWorld(), main(), OBJECTS::OBJECTS(), REPLAY::PlayStart(), VGUI::Gui::ProcessAction(), ReloadDisplay(), TIMER::ResetBest(), VGUI::Toggle::ResetValue(), VGUI::TextBox::ResetValue(), VGUI::SpinningCar::ResetValue(), VGUI::Slider::ResetValue(), VGUI::MultiImage::ResetValue(), VGUI::Wheel2< wheel_t1, wheel_t2 >::ResetValue(), VGUI::Wheel< wheel_t >::ResetValue(), LOGO::run(), VGUI::Toggle::Save(), VGUI::TextBox::Save(), VGUI::Slider::Save(), VGUI::Wheel2< wheel_t1, wheel_t2 >::Save(), VGUI::Wheel< wheel_t >::Save(), VAMOSWORLD::SetCameraMode(), GAMESTATE::SetCarName(), GAMESTATE::SetCarPaint(), GAMESTATE::SetGameMode(), Vamos_Body::Gl_Car::SetPaint(), GAMESTATE::SetTrackName(), VGUI::Slider::Slider(), snap_screenshot(), VGUI::SpinningCar::SpinningCar(), REPLAY::Stop(), UTILITY::TexLoad(), VGUI::TextBox::TextBox(), TIMER::TIMER(),