[go: up one dir, main page]

Menu

[2d94f2]: / world / World.hpp  Maximize  Restore  History

Download this file

142 lines (117 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Handles interactions between a car and its environment.
//
// Copyright (C) 2001-2019 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vamos is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vamos. If not, see <http://www.gnu.org/licenses/>.
#ifndef _WORLD_H_
#define _WORLD_H_
#include "../geometry/Material.hpp"
#include "../geometry/Three_Matrix.hpp"
#include "../geometry/Three_Vector.hpp"
#include "Timing_Info.hpp"
#include <boost/circular_buffer.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Vamos_Body { class Car; }
namespace Vamos_Geometry { class Three_Vector; }
namespace Vamos_Track
{
class Road;
class Strip_Track;
}
namespace Vamos_World
{
class Driver;
struct Atmosphere
{
double density;
Vamos_Geometry::Three_Vector velocity;
};
struct Car_Information
{
Car_Information(Vamos_Body::Car* car_in, Driver* driver_in);
void reset();
void propagate(double time_step, double total_time,
const Vamos_Geometry::Three_Vector& track_position,
const Vamos_Geometry::Three_Vector& pointer_position);
const Vamos_Geometry::Three_Vector& track_position() const;
size_t road_index = 0;
size_t segment_index = 0;
Vamos_Body::Car* car;
Driver* driver;
Vamos_Geometry::Three_Vector m_pointer_position;
struct Record
{
Record(){};
Record(double time, Vamos_Body::Car* car,
const Vamos_Geometry::Three_Vector& track_position);
double m_time;
Vamos_Geometry::Three_Vector m_track_position;
Vamos_Geometry::Three_Vector m_position;
Vamos_Geometry::Three_Matrix m_orientation;
};
boost::circular_buffer<Record> m_record;
};
struct Interaction_Info
{
Vamos_Body::Car* car;
Vamos_Geometry::Material::Material_Type car_material;
Vamos_Geometry::Material::Material_Type track_material;
double parallel_speed;
double perpendicular_speed;
};
class Track;
class World
{
public:
World(Vamos_Track::Strip_Track& track, const Atmosphere& atmosphere);
virtual ~World() = default;
virtual void add_car(Vamos_Body::Car& car, Driver& driver);
virtual void set_focused_car(size_t car_index);
void interact(Vamos_Body::Car* car, size_t road_index, size_t segment_index);
void collide(Car_Information* car1_info, Car_Information* car2_info);
void gravity(double g);
double get_gravity() const { return m_gravity; }
void focus_other_car(int delta);
void cars_can_interact(bool can) { m_cars_can_interact = can; }
void propagate_cars(double time_step);
size_t number_of_cars() const { return m_cars.size(); }
void write_results(const std::string& file) const;
protected:
virtual void start(bool qualifying, size_t laps_or_minutes);
void reset();
void restart();
Car_Information* focused_car();
Car_Information* controlled_car();
Vamos_Track::Strip_Track& m_track;
Atmosphere m_atmosphere;
double m_gravity = 9.8;
std::vector<Car_Information> m_cars;
/// The times for all cars.
std::unique_ptr<Timing_Info> mp_timing;
std::vector<Interaction_Info> m_interaction_info;
size_t m_focused_car_index = 0;
private:
void place_car(Vamos_Body::Car* car, const Vamos_Geometry::Three_Vector& pos,
const Vamos_Track::Road& Road);
void set_controlled_car(size_t car_index);
double slipstream_air_density_factor(Car_Information& car1, Car_Information& car2);
bool m_cars_can_interact = true;
std::optional<size_t> m_controlled_car_index;
};
} // namespace Vamos_World
#endif // not _WORLD_H_