Skip to content

Commit 96768e0

Browse files
author
phillemann
committed
Added speed display, added max_speed, added create_path
1 parent 7eb222b commit 96768e0

15 files changed

+119
-48
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ FILE(GLOB_RECURSE skydome_files skydome/*)
7070
FILE(GLOB_RECURSE water_files water/*)
7171
FILE(GLOB_RECURSE physics_files physics/*)
7272
FILE(GLOB_RECURSE model_files model/*)
73-
FILE(GLOB base_files media_path.cpp input_delegator.cpp)
73+
FILE(GLOB base_files media_path.cpp input_delegator.cpp create_path.cpp)
7474

7575
SET_SOURCE_FILES_PROPERTIES(
7676
media_path.cpp

create_path.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "create_path.hpp"
2+
#include "media_path.hpp"
3+
#include <fcppt/assert.hpp>
4+
5+
fcppt::filesystem::path const
6+
insula::create_path(
7+
fcppt::string const &g,
8+
fcppt::string const &dir_below_media)
9+
{
10+
FCPPT_ASSERT(!g.empty());
11+
12+
if (g[0] == FCPPT_TEXT('/'))
13+
return g;
14+
15+
return media_path()/dir_below_media/g;
16+
}

create_path.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef INSULA_CREATE_PATH_HPP_INCLUDED
2+
#define INSULA_CREATE_PATH_HPP_INCLUDED
3+
4+
#include <fcppt/filesystem/path.hpp>
5+
#include <fcppt/string.hpp>
6+
7+
namespace insula
8+
{
9+
fcppt::filesystem::path const
10+
create_path(
11+
fcppt::string const &,
12+
fcppt::string const &dir_below_media);
13+
}
14+
15+
#endif

graphics/frame_counter.cpp graphics/stats.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "frame_counter.hpp"
1+
#include "stats.hpp"
22
#include <sge/renderer/device.hpp>
33
#include <sge/font/system.hpp>
44
#include <sge/config/media_path.hpp>
@@ -18,7 +18,7 @@
1818
#include <fcppt/math/dim/structure_cast.hpp>
1919
#include <fcppt/make_shared_ptr.hpp>
2020

21-
insula::graphics::frame_counter::frame_counter(
21+
insula::graphics::stats::stats(
2222
sge::renderer::device_ptr const _renderer,
2323
sge::font::system_ptr const fs)
2424
:
@@ -36,14 +36,15 @@ insula::graphics::frame_counter::frame_counter(
3636
}
3737

3838
void
39-
insula::graphics::frame_counter::update_and_render()
39+
insula::graphics::stats::update_and_render(
40+
fcppt::string const &additional_stats)
4041
{
4142
counter_.update();
4243

4344
sge::font::draw_text(
4445
metrics_,
4546
drawer_,
46-
FCPPT_TEXT("FPS: ")+counter_.frames_str(),
47+
FCPPT_TEXT("FPS: ")+counter_.frames_str()+FCPPT_TEXT("\n")+additional_stats,
4748
sge::font::pos::null(),
4849
fcppt::math::dim::structure_cast<sge::font::dim>(
4950
renderer_->screen_size()),

graphics/frame_counter.hpp graphics/stats.hpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
#ifndef INSULA_GRAPHICS_FRAME_COUNTER_HPP_INCLUDED
2-
#define INSULA_GRAPHICS_FRAME_COUNTER_HPP_INCLUDED
1+
#ifndef INSULA_GRAPHICS_STATS_HPP_INCLUDED
2+
#define INSULA_GRAPHICS_STATS_HPP_INCLUDED
33

44
#include <sge/time/frames_counter.hpp>
55
#include <sge/renderer/device_ptr.hpp>
66
#include <sge/font/metrics_ptr.hpp>
77
#include <sge/font/drawer_ptr.hpp>
88
#include <sge/font/system_ptr.hpp>
9+
#include <fcppt/text.hpp>
910

1011
namespace insula
1112
{
1213
namespace graphics
1314
{
14-
class frame_counter
15+
class stats
1516
{
1617
public:
17-
frame_counter(frame_counter const &) = delete;
18-
frame_counter &operator=(frame_counter const &) = delete;
18+
stats(stats const &) = delete;
19+
stats &operator=(stats const &) = delete;
1920

2021
explicit
21-
frame_counter(
22+
stats(
2223
sge::renderer::device_ptr,
2324
sge::font::system_ptr);
2425

2526
void
26-
update_and_render();
27+
update_and_render(
28+
fcppt::string const &additional_stats = FCPPT_TEXT(""));
2729
private:
2830
sge::time::frames_counter counter_;
2931
sge::renderer::device_ptr const renderer_;

height_map/cli_factory.cpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "cli_factory.hpp"
22
#include "image_to_array.hpp"
33
#include "object.hpp"
4-
#include "../media_path.hpp"
4+
#include "../create_path.hpp"
55
#include "../get_option.hpp"
66
#include "../graphics/scalar.hpp"
77
#include "../graphics/vec3.hpp"
@@ -32,25 +32,24 @@ insula::height_map::cli_factory(
3232
renderer,
3333
image_to_array(
3434
image_loader.load(
35-
media_path()/
36-
FCPPT_TEXT("heightfields")/
37-
get_option<fcppt::string>(vm,"height-map"))),
35+
create_path(
36+
get_option<fcppt::string>(vm,"height-map"),
37+
FCPPT_TEXT("heightfields")))),
3838
get_option<graphics::scalar>(vm,"cell-size"),
39-
// get_option<graphics::scalar>(vm,"cell-size"),
4039
get_option<graphics::scalar>(vm,"height-scaling"),
4140
get_option<graphics::vec3>(vm,"sun-direction"),
4241
get_option<graphics::scalar>(vm,"ambient-light"),
4342
get_option<graphics::scalar>(vm,"texture-scaling"),
4443
image_loader.load(
45-
media_path()/
46-
FCPPT_TEXT("textures")/
47-
get_option<fcppt::string>(vm,"gradient-texture")),
44+
create_path(
45+
get_option<fcppt::string>(vm,"gradient-texture"),
46+
FCPPT_TEXT("textures"))),
4847
image_loader.load(
49-
media_path()/
50-
FCPPT_TEXT("textures")/
51-
height_textures[0]),
48+
create_path(
49+
height_textures[0],
50+
FCPPT_TEXT("textures"))),
5251
image_loader.load(
53-
media_path()/
54-
FCPPT_TEXT("textures")/
55-
height_textures[1]));
52+
create_path(
53+
height_textures[1],
54+
FCPPT_TEXT("textures"))));
5655
}

media/vehicles/buggy.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"max_engine_force" : 1200.0,
1717
"max_breaking_force" : 100.0,
1818
"steering_clamp" : 0.3,
19+
"max_speed" : 800.0,
1920

2021
"default_wheel" :
2122
{

media/vehicles/insula_car.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"chassis_center_of_mass_shift" : -0.0,
1515
"scaling" : 1.0,
1616
"max_engine_force" : 800.0,
17+
"max_speed" : 800.0,
1718
"max_breaking_force" : 300.0,
1819
"steering_clamp" : 0.4,
1920

notizen.org

+12-7
Original file line numberDiff line numberDiff line change
@@ -331,25 +331,28 @@ gl_FragColor = mix(gl_Fog.color, finalColor, fogFactor );
331331
wie beim Wasser)
332332
- Vergleiche den z-Wert von vp mit dem z-Wert in der Shadowmap, setze
333333
entsprechend die Pixel
334-
** TODO Physik, Fahrzeuge [1/6]
334+
** TODO Physik, Fahrzeuge [3/6]
335335
*** TODO insula::physics::model
336336
Sollte eine Klasse sein, die ein Model reinbekommt, sowie einen Parameter, der angibt, wie dieses Model in der Physikengine dargestellt werden soll:
337337

338338
-Boundingbox
339339
-Boundingcylinder
340340
-Boundingsphere
341341
-Exact
342-
*** TODO Setter für gravity
342+
*** DONE Setter für gravity
343+
CLOSED: [2010-08-15 Sun 13:53]
343344
*** DONE json-Part muss in mehrere Dateien aufgeteilt werden
344345
CLOSED: [2010-08-10 Tue 01:34]
345-
*** TODO Nach weiteren Eigenschaften von Fahrzeugen gucken, die noch nicht in wheel_info sind
346+
*** DONE Nach weiteren Eigenschaften von Fahrzeugen gucken, die noch nicht in wheel_info sind
347+
CLOSED: [2010-08-15 Sun 13:53]
346348
*** TODO wheel_info muss in cpp ausgelagert werden.
347349
*** TODO world muss mehr RAII kriegen
348350
** TODO Sounds
349-
** TODO Diverses [17/23]
351+
** TODO Diverses [20/26]
350352
*** DONE Framecounter einbauen
351353
CLOSED: [2010-07-30 Fri 18:24]
352-
*** TODO gizmo_init fixen
354+
*** DONE gizmo_init fixen
355+
CLOSED: [2010-08-15 Sun 13:23]
353356
*** DONE Average-Filter übers Terrain laufen lassen
354357
CLOSED: [2010-08-03 Tue 20:44]
355358
*** DONE Skydome-Unterfarbe weiterreichen
@@ -417,7 +420,8 @@ Far-Plane, die näher dran ist.
417420
CLOSED: [2010-08-09 Mon 20:58]
418421
CLOSED: [2010-08-03 Tue 20:44
419422

420-
*** TODO Absolute Pfade bei Dateien auf Kommandozeile
423+
*** DONE Absolute Pfade bei Dateien auf Kommandozeile
424+
CLOSED: [2010-08-15 Sun 13:30]
421425
Vielleicht so machen, dass man einen Pfad mit '/' prependen kann und
422426
der dann den absoluten Pfad nimmt. Dürfte ja einfach in eine Funktion
423427
packbar sein.
@@ -439,7 +443,8 @@ wurde.
439443
-mirror_camera aus water rausziehen?
440444

441445
*** TODO Anzeigebug fuer Skydome fixen
442-
*** TODO Der Inputdelegator funzt nicht, die Konsole blockiert nicht den Auto-Input
446+
*** DONE Der Inputdelegator funzt nicht, die Konsole blockiert nicht den Auto-Input
447+
CLOSED: [2010-08-15 Sun 13:30]
443448
*** DONE Library bauen statt einzelne Executables mit denselben Dateien
444449
CLOSED: [2010-08-14 Sat 18:32]
445450
Wieso ist die Farbe ganz unten nicht korrekt, wenn man einen weniger

physics/json/parse_vehicle.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ insula::physics::json::parse_vehicle(
7575
sge::parse::json::find_member_exn<sge::parse::json::float_type>(
7676
json_file.members,
7777
FCPPT_TEXT("max_breaking_force"))),
78+
static_cast<scalar>(
79+
sge::parse::json::find_member_exn<sge::parse::json::float_type>(
80+
json_file.members,
81+
FCPPT_TEXT("max_speed"))),
7882
parse_model(
7983
sge::parse::json::find_member_exn<sge::parse::json::object>(
8084
json_file.members,

physics/vehicle.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ insula::physics::vehicle::vehicle(
5959
vec3 const &_position,
6060
scalar const _max_engine_force,
6161
scalar const _max_breaking_force,
62+
scalar const _max_speed,
6263
model::object_ptr _wheel_model,
6364
wheel_info_sequence const &_wheels)
6465
:
@@ -72,6 +73,8 @@ insula::physics::vehicle::vehicle(
7273
_max_engine_force),
7374
max_breaking_force_(
7475
_max_breaking_force),
76+
max_speed_(
77+
_max_speed),
7578
current_engine_force_(
7679
0),
7780
current_breaking_force_(
@@ -232,6 +235,16 @@ insula::physics::vehicle::vehicle(
232235
void
233236
insula::physics::vehicle::update()
234237
{
238+
btVector3 const velocity =
239+
car_body_->getLinearVelocity();
240+
241+
btScalar const speed =
242+
velocity.length();
243+
244+
if (speed > max_speed_)
245+
car_body_->setLinearVelocity(
246+
velocity * max_speed_/speed);
247+
235248
for (wheel_info_sequence::size_type i = 0; i < wheels_.size(); ++i)
236249
{
237250
if (wheels_[i].gets_engine_force())
@@ -297,6 +310,12 @@ insula::physics::vehicle::steering(
297310
current_steering_ = s * steering_clamp_;
298311
}
299312

313+
insula::physics::scalar
314+
insula::physics::vehicle::speed_kmh() const
315+
{
316+
return vehicle_->getCurrentSpeedKmHour();
317+
}
318+
300319
insula::physics::gizmo const
301320
insula::physics::vehicle::gizmo() const
302321
{

physics/vehicle.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class vehicle
4848
vec3 const &position,
4949
scalar max_engine_force,
5050
scalar max_breaking_force,
51+
scalar max_speed,
5152
model::object_ptr wheel,
5253
wheel_info_sequence const &);
5354

@@ -69,6 +70,9 @@ class vehicle
6970
steering(
7071
scalar);
7172

73+
scalar
74+
speed_kmh() const;
75+
7276
// The camera needs this
7377
insula::physics::gizmo const
7478
gizmo() const;
@@ -86,6 +90,7 @@ class vehicle
8690
wheel_info_sequence const wheels_;
8791
scalar max_engine_force_;
8892
scalar max_breaking_force_;
93+
scalar max_speed_;
8994
scalar current_engine_force_;
9095
scalar current_breaking_force_;
9196
scalar current_steering_;

physics/vehicle_controller.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#include "vehicle_controller.hpp"
2+
#include "../input_delegator.hpp"
23
#include "vehicle.hpp"
34
#include "scalar.hpp"
4-
#include <sge/input/system.hpp>
55
#include <sge/input/key_pair.hpp>
66
#include <functional>
77

88
insula::physics::vehicle_controller::vehicle_controller(
9-
sge::input::system_ptr is,
9+
input_delegator &is,
1010
vehicle &_vehicle)
1111
:
1212
vehicle_(
1313
_vehicle),
1414
is_active_(
1515
true),
1616
input_connection_(
17-
is->register_callback(
17+
is.register_callback(
1818
std::bind(
1919
&vehicle_controller::callback,
2020
this,

physics/vehicle_controller.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define INSULA_PHYSICS_VEHICLE_CONTROLLER_HPP_INCLUDED
33

44
#include "vehicle_fwd.hpp"
5-
#include <sge/input/system_ptr.hpp>
5+
#include "../input_delegator_fwd.hpp"
66
#include <sge/input/key_pair_fwd.hpp>
77
#include <fcppt/signal/scoped_connection.hpp>
88

@@ -18,7 +18,7 @@ class vehicle_controller
1818

1919
explicit
2020
vehicle_controller(
21-
sge::input::system_ptr,
21+
input_delegator &,
2222
vehicle &);
2323

2424
void

0 commit comments

Comments
 (0)