include/vamos/world/World.h

Go to the documentation of this file.
00001 //  World.h - handles interactions between a car and its environment.
00002 //
00003 //      Vamos Automotive Simulator
00004 //  Copyright (C) 2001--2004 Sam Varner
00005 //
00006 //  This program is free software; you can redistribute it and/or modify
00007 //  it under the terms of the GNU General Public License as published by
00008 //  the Free Software Foundation; either version 2 of the License, or
00009 //  (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 #ifndef _WORLD_H_
00021 #define _WORLD_H_
00022 
00023 #include <vamos/body/Car.h>
00024 #include <vamos/geometry/Material.h>
00025 #include <vamos/geometry/Three_Vector.h>
00026 //#include <vamos/track/Track.h>
00027 //#include <vamos/track/Strip_Track.h>
00028 //#include <vamos/track/Road_Segment.h>
00029 
00030 #include "track.h"
00031 
00032 #include <vector>
00033 
00034 namespace Vamos_World
00035 {
00036   typedef Vamos_Geometry::Material::Material_Type Mat_Type;
00037 
00038   class Times
00039   {
00040         friend class Timing_Info;
00041 
00042         double m_current;
00043         double m_previous;
00044         double m_best;
00045         double m_difference;
00046 
00047   public:
00048         Times ();
00049         void update (double time_step);
00050         void finalize ();
00051         void reset ();
00052   };
00053 
00054   class Timing_Info
00055   {
00056         Times m_lap_times;
00057         std::vector <Times> ma_sector_times;
00058 
00059         int m_sector;
00060         int m_previous_sector;
00061         double m_distance;
00062 
00063         void update_sector_info (int sector);
00064         void update_times (int sector, double time_step);
00065 
00066   public:
00067         Timing_Info ();
00068 
00069         void reset ();
00070         void update (double time_step, double distance, int sector);
00071 
00072         int get_sector () const { return m_sector; }
00073         int get_previous_sector () const { return m_previous_sector; }
00074         double get_distance () const { return m_distance; }
00075 
00076         double get_lap_time () const { return m_lap_times.m_current; }
00077         double get_previous_lap_time () const { return m_lap_times.m_previous; }
00078         double get_best_lap_time () const { return m_lap_times.m_best; }
00079         double get_lap_time_difference () const { return m_lap_times.m_difference; }
00080 
00081         double get_sector_time () const
00082         { return ma_sector_times [m_sector].m_current; }
00083         double get_previous_sector_time () const
00084         { return ma_sector_times [m_previous_sector].m_previous; }
00085         double get_previous_sector_time_difference () const 
00086         { return ma_sector_times [m_previous_sector].m_difference; }
00087         double get_best_sector_time (int sector) const
00088         { return (size_t (sector) < ma_sector_times.size ()) 
00089                 ? ma_sector_times [sector].m_best : 0.0; }
00090   };
00091 
00092   struct Car_Information
00093   {
00094         Car_Information (Vamos_Body::Car* new_car) 
00095           : segment_index (0), car (new_car) {};
00096 
00097         Timing_Info timing;
00098         size_t segment_index;
00099         Vamos_Body::Car* car;
00100 
00101         void reset ();
00102   };
00103 
00104   struct Contact_Info
00105   {
00106         Contact_Info (Vamos_Body::Car* car_in, 
00107                                   Mat_Type car_material_type, 
00108                                   Mat_Type track_material_type,
00109                                   double par_speed, double perp_speed)
00110           : car (car_in),
00111                 car_material (car_material_type),
00112                 track_material (track_material_type),
00113                 parallel_speed (par_speed),
00114                 perpendicular_speed (perp_speed)
00115         {};
00116 
00117         Vamos_Body::Car* car;
00118         Mat_Type car_material;
00119         Mat_Type track_material;
00120         double parallel_speed;
00121         double perpendicular_speed;
00122   };
00123 
00124   class World
00125   {
00126         size_t m_focused_car_index;
00127 
00128 //  protected:
00129 public:
00130         std::vector <Car_Information> m_cars;
00131         //Vamos_Track::Strip_Track* mp_track;
00132         TRACK * p_track;
00133 //      Atmosphere* mp_atmosphere;
00134 
00135         double m_gravity;
00136 
00137         std::vector <Contact_Info> m_contact_info;
00138 
00139         void reset ();
00140         void reset (bool all);
00141         void reset (Car_Information * cartoreset);
00142         void restart ();
00143 
00144         Car_Information* focused_car ();
00145 
00146 //  public:
00147         World (TRACK * track);
00148         ~World ();
00149 
00150         void interact (Vamos_Body::Car* car, size_t segment_index);
00151         void collide (Vamos_Body::Car* car1, Vamos_Body::Car* car2);
00152         void gravity (double g);
00153         void add_car (Vamos_Body::Car* car);
00154         void set_focused_car (size_t car_index);
00155         void focus_other_car (int delta);
00156   };
00157 }
00158 
00159 #endif // not _WORLD_H_

Generated on Thu Oct 19 04:05:48 2006 by  doxygen 1.4.6