20 #ifndef HEADER_TRACK_HPP
21 #define HEADER_TRACK_HPP
36 #include <irrString.h>
44 class IMesh;
class ISceneNode;
48 class IImage;
class ITexture;
54 #include "LinearMath/btTransform.h"
56 #include "utils/aligned_array.hpp"
57 #include "utils/log.hpp"
58 #include "utils/random_generator.hpp"
59 #include "utils/vec3.hpp"
60 #include "utils/stk_process.hpp"
63 class AnimationManager;
78 const int HEIGHT_MAP_RESOLUTION = 256;
84 core::vector3df m_position;
85 std::string m_challenge_id;
89 m_position = position;
90 m_challenge_id = challenge_id;
100 Subtitle(
int from,
int to, core::stringw text)
106 int getFrom()
const {
return m_from; }
107 int getTo()
const {
return m_to; }
108 const core::stringw& getText()
const {
return m_text; }
120 static std::atomic<Track*> m_current_track[PT_COUNT];
123 unsigned int m_magic_number;
133 std::string m_screenshot;
135 std::vector<MusicInformation*> m_music;
136 unsigned m_music_idx;
141 std::vector<Subtitle> m_subtitles;
147 std::string m_item_style;
148 std::string m_description;
149 core::stringw m_designer;
158 std::vector<std::string> m_groups;
200 std::vector<video::ITexture*> m_old_textures;
206 std::vector<std::string> m_old_mesh_buffers;
209 scene::ISceneNode *m_sun;
225 btTransform m_red_flag;
226 btTransform m_blue_flag;
267 enum {SKY_NONE, SKY_BOX,
268 SKY_COLOR} m_sky_type;
277 std::vector<void*> m_spherical_harmonics_textures;
307 std::string m_weather_sound;
319 unsigned int m_magic_number;
323 TrackMode() : m_name(
"default"), m_quad_name(
"quads.xml"),
324 m_graph_name(
"graph.xml"), m_scene(
"scene.xml")
327 m_magic_number = 0x46825179;
334 assert(m_magic_number == 0x46825179);
335 m_magic_number = 0xDEADBEEF;
364 float m_fog_height_start;
365 float m_fog_height_end;
366 core::vector3df m_sun_position;
369 video::SColor m_default_ambient_color;
370 video::SColor m_sun_specular_color;
371 video::SColor m_sun_diffuse_color;
372 video::SColor m_fog_color;
377 std::shared_ptr<ItemManager> m_item_manager;
378 float m_minimap_x_scale;
379 float m_minimap_y_scale;
382 float m_bloom_threshold;
385 core::vector3df m_godrays_position;
386 float m_godrays_opacity;
387 video::SColor m_godrays_color;
391 float m_displacement_speed;
392 int m_physical_object_uid;
394 bool m_minimap_invert_x_z;
400 core::vector2df m_color_outlevel;
405 std::vector<std::pair<TrackObject*, TrackObject*> > m_meta_library;
414 void loadTrackInfo();
415 void loadDriveGraph(
unsigned int mode_id,
const bool reverse);
416 void loadArenaGraph(
const XMLNode &node);
417 btQuaternion getArenaStartRotation(
const Vec3& xyz,
float heading);
418 bool loadMainTrack(
const XMLNode &node);
420 void createWater(
const XMLNode &node);
421 void getMusicInformation(std::vector<std::string>& filenames,
422 std::vector<MusicInformation*>& m_music );
423 void loadCurves(
const XMLNode &node);
424 void handleSky(
const XMLNode &root,
const std::string &filename);
425 void freeCachedMeshVertexBuffer();
426 void copyFromMainProcess();
427 video::IImage* getSkyTexture(std::string path)
const;
428 scene::IMesh* getClonedMesh(
const std::string& filename)
const;
435 ProcessType type = STKProcess::getType();
436 return m_current_track[type];
442 child_track->copyFromMainProcess();
446 void initChildTrack();
448 static void cleanChildTrack();
450 void handleAnimatedTextures(scene::ISceneNode *node,
const XMLNode &xml);
458 static void uploadNodeVertexBuffer(scene::ISceneNode *node);
460 static const float NOHIT;
462 Track (
const std::string &filename);
465 void removeCachedData ();
466 void startMusic ()
const;
468 void createPhysicsModel(
unsigned int main_track_count,
469 bool for_height_map);
470 void updateGraphics(
float dt);
471 void update(
int ticks);
473 void itemCommand(
const XMLNode *node);
476 core::stringw getName()
const;
478 core::stringw getSortName()
const;
479 bool isInGroup(
const std::string &group_name);
480 const core::vector3df& getSunRotation();
484 void handleExplosion(
const Vec3 &pos,
486 bool secondary_hits=
true)
const;
487 void loadTrackModel (
bool reverse_track =
false,
488 unsigned int mode_id=0);
491 std::vector< std::vector<float> > buildHeightMap();
492 void drawMiniMap(
const core::rect<s32>& dest_rect)
const;
493 void updateMiniMapScale();
498 bool isCTF()
const {
return m_is_ctf; }
504 return !m_internal && !m_is_arena && !m_is_soccer;
516 void loadObjects(
const XMLNode* root,
const std::string& path,
518 scene::ISceneNode* parent,
TrackObject* parent_library);
520 bool isSoccer ()
const {
return m_is_soccer; }
523 {m_music.push_back(mi); }
525 float getGravity ()
const {
return m_gravity; }
531 float getTrackLength ()
const;
534 const std::string&
getIdent ()
const {
return m_ident; }
537 const std::vector<std::string>&
559 if (index >= m_start_transforms.size())
560 Log::fatal(
"Track",
"No start position for kart %i.", index);
561 return m_start_transforms[index];
568 std::shuffle(m_start_transforms.begin(), m_start_transforms.end(),
574 { *min = &m_aabb_min; *max = &m_aabb_max; }
582 float getAngle(
int n)
const;
590 void mapPoint2MiniMap(
const Vec3 &xyz,
Vec3 *draw_at)
const;
594 {
return m_root+
"/"+s; }
600 unsigned int getNumOfCompletedChallenges();
604 {
return m_all_modes[i].m_name; }
608 {
return m_default_ambient_color; }
615 const TriangleMesh& getTriangleMesh()
const {
return *m_track_mesh; }
622 {
return m_max_arena_players; }
626 {
return (
unsigned int)m_start_transforms.size(); }
628 bool getWeatherLightning() {
return m_weather_lightning;}
630 const std::string& getWeatherSound() {
return m_weather_sound;}
632 ParticleKind* getSkyParticles () {
return m_sky_particles; }
641 return !m_force_disable_fog && m_use_fog;
645 float getFogStart()
const {
return m_fog_start; }
647 void setFogStart(
float start) { m_fog_start = start; }
649 float getFogEnd()
const {
return m_fog_end; }
651 void setFogEnd(
float end) { m_fog_end = end; }
653 float getFogStartHeight()
const {
return m_fog_height_start; }
655 float getFogEndHeight()
const {
return m_fog_height_end; }
657 float getFogMax()
const {
return m_fog_max; }
659 void setFogMax(
float max) { m_fog_max = max; }
661 video::SColor getFogColor()
const {
return m_fog_color; }
663 void setFogColor(video::SColor& color) { m_fog_color = color; }
665 video::SColor getSunColor()
const {
return m_sun_diffuse_color; }
683 return m_track_object_manager;
689 {
return m_challenges; }
692 const std::vector<Subtitle>& getSubtitles()
const {
return m_subtitles; }
695 bool hasBloom()
const {
return m_bloom; }
698 float getBloomThreshold()
const {
return m_bloom_threshold; }
704 core::vector2df getColorLevelOut()
const {
return m_color_outlevel; }
706 bool hasGodRays()
const {
return m_godrays; }
708 core::vector3df getGodRaysPosition()
const {
return m_godrays_position; }
710 float getGodRaysOpacity()
const {
return m_godrays_opacity; }
712 video::SColor getGodRaysColor()
const {
return m_godrays_color; }
714 bool hasShadows()
const {
return m_shadows; }
716 void addNode(scene::ISceneNode* node) { m_all_nodes.push_back(node); }
718 void addPhysicsOnlyNode(scene::ISceneNode* node)
720 m_object_physics_only_nodes.push_back(node);
723 float getDisplacementSpeed()
const {
return m_displacement_speed; }
725 int getPhysicalObjectUID() {
return m_physical_object_uid++; }
727 const int getDefaultNumberOfLaps()
const {
return m_default_number_of_laps;}
729 const int getActualNumberOfLap()
const {
return m_actual_number_of_laps; }
731 void setActualNumberOfLaps(
unsigned int laps)
732 { m_actual_number_of_laps = laps; }
734 bool operator<(
const Track &other)
const;
737 void addCachedMesh(scene::IMesh* mesh) { m_all_cached_meshes.push_back(mesh); }
741 { m_meta_library.emplace_back(parent, meta_library); }
743 const btTransform& getRedFlag()
const {
return m_red_flag; }
745 const btTransform& getBlueFlag()
const {
return m_blue_flag; }
747 bool isAddon()
const {
return m_is_addon; }
749 void convertTrackToBullet(scene::ISceneNode *node,
750 std::vector<std::array<btVector3, 3> >* occluder = NULL);
752 CheckManager* getCheckManager()
const {
return m_check_manager; }
754 ItemManager* getItemManager()
const {
return m_item_manager.get(); }
756 bool isOnGround(
const Vec3& xyz,
const Vec3& down,
Vec3* hit_point,
757 Vec3* normal,
bool print_warning =
true);
761 if (m_music_idx < m_music.size())
762 return m_music[m_music_idx];
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
A class to manage bezier curves and interpolation.
Definition: bezier_curve.hpp:34
Controls all checks structures of a track.
Definition: check_manager.hpp:40
Definition: item_manager.hpp:47
Utility class to load level-of-detail nodes and library nodes.
Definition: model_definition_loader.hpp:81
Handles animated textures (textures that move)
Definition: moving_texture.hpp:34
type of particles
Definition: particle_kind.hpp:42
Definition: physical_object.hpp:40
static std::mt19937 & getGenerator()
Return a reference to the thread-local generator.
Definition: random_generator.cpp:25
Definition: render_target.hpp:42
Definition: track_object_manager.hpp:39
This is a base object for any separate object on the track, which might also have a skeletal animatio...
Definition: track_object.hpp:56
A simple class to keep information about a track mode.
Definition: track.hpp:311
std::string m_quad_name
Name of the quad file to use.
Definition: track.hpp:314
std::string m_graph_name
Name of the graph file to use.
Definition: track.hpp:315
TrackMode()
Default constructor, sets default names for all fields.
Definition: track.hpp:323
std::string m_scene
Name of the scene file to use.
Definition: track.hpp:316
std::string m_name
Name / description of this mode.
Definition: track.hpp:313
Definition: track.hpp:115
int getVersion() const
Returns the version of the .track file.
Definition: track.hpp:528
std::vector< scene::IMesh * > m_all_cached_meshes
The list of all meshes that are loaded from disk, which means that those meshes are being cached by i...
Definition: track.hpp:174
std::vector< BezierCurve * > m_all_curves
List of all bezier curves in the track - for e.g.
Definition: track.hpp:403
irr::video::SColor m_sky_color
Used if m_sky_type is SKY_COLOR only.
Definition: track.hpp:280
const core::stringw & getDesigner() const
Returns the name of the designer.
Definition: track.hpp:544
void setAmbientColor(const video::SColor &color, unsigned int k)
Sets the current ambient color for a kart with index k.
RenderTarget * m_render_target
The render target for the mini map, which is displayed in the race gui.
Definition: track.hpp:375
TriangleMesh * m_gfx_effect_mesh
Used to collect the triangles which do not have a physical representation, but are needed for some ra...
Definition: track.hpp:220
void getAABB(const Vec3 **min, const Vec3 **max) const
Sets pointer to the aabb of this track.
Definition: track.hpp:573
void shuffleStartTransforms()
Shuffles the start transformations.
Definition: track.hpp:566
TrackObjectManager * m_track_object_manager
Manager for all track objects.
Definition: track.hpp:286
int m_actual_number_of_laps
The number of laps that is predefined in a track info dialog.
Definition: track.hpp:412
unsigned int m_max_arena_players
Max players supported by an arena.
Definition: track.hpp:231
static Track * getCurrentTrack()
Static function to get the current track.
Definition: track.hpp:433
const TriangleMesh * getPtrTriangleMesh() const
Returns the triangle mesh for this track.
Definition: track.hpp:614
float m_sky_sphere_percent
If a sky dome is used, percentage of the sphere to be used.
Definition: track.hpp:297
bool reverseAvailable() const
Returns true if this race can be driven in reverse.
Definition: track.hpp:511
static bool m_dont_load_navmesh
Flag to avoid loading navmeshes (useful to speedup debugging: e.g.
Definition: track.hpp:455
std::vector< scene::ISceneNode * > m_static_physics_only_nodes
The list of all nodes that are to be converted into physics, but not to be drawn (e....
Definition: track.hpp:165
std::string getTrackFile(const std::string &s) const
Returns the full path of a given file inside this track directory.
Definition: track.hpp:593
void addMetaLibrary(TrackObject *parent, TrackObject *meta_library)
Adds the parent of the meta library for correction later.
Definition: track.hpp:740
bool m_force_disable_fog
Can be set to force fog off (e.g.
Definition: track.hpp:354
unsigned int getNumberOfStartPositions() const
Get the number of start positions defined in the scene file.
Definition: track.hpp:625
unsigned int getNumberOfModes() const
Returns the number of modes available for this track.
Definition: track.hpp:597
bool m_smooth_normals
True if this track supports using smoothed normals.
Definition: track.hpp:357
bool isPushBackEnabled() const
True if push back of karts towards the track should be enabled.
Definition: track.hpp:675
core::vector3df m_color_inlevel
The levels for color correction m_color_inlevel(black, gamma, white) m_color_outlevel(black,...
Definition: track.hpp:399
void forceFogDisabled(bool v)
Override track fog value to force disabled.
Definition: track.hpp:635
std::vector< MovingTexture * > m_animated_textures
The list of all animated textures.
Definition: track.hpp:283
bool smoothNormals() const
Returns true if the normals of this track can be smoothed.
Definition: track.hpp:678
bool m_cache_track
True if this track (textures and track data) should be cached.
Definition: track.hpp:192
Vec3 m_aabb_min
Minimum coordinates of this track.
Definition: track.hpp:222
bool isInternal() const
Whether this is an "internal" track.
Definition: track.hpp:669
int m_sky_vert_segments
If a sky dome is used, the number of vertical segments the sphere should be divided in.
Definition: track.hpp:294
bool m_enable_push_back
If true any collision of a kart with the track will push the kart towards the nearest driveline.
Definition: track.hpp:264
const video::SColor & getDefaultAmbientColor() const
Returns the default ambient color.
Definition: track.hpp:607
std::vector< TrackMode > m_all_modes
List of all modes for a track.
Definition: track.hpp:342
const bool getIsDuringDay() const
Returns if the track is during day time.
Definition: track.hpp:550
std::vector< scene::ISceneNode * > m_object_physics_only_nodes
Same concept but for track objects.
Definition: track.hpp:170
AlignedArray< btTransform > m_start_transforms
Start transforms of karts (either the default, or the ones taken from the scene file).
Definition: track.hpp:145
const TriangleMesh & getGFXEffectMesh() const
Returns the graphical effect mesh for this track.
Definition: track.hpp:618
TriangleMesh * m_track_mesh
Used to collect the triangles for the bullet mesh.
Definition: track.hpp:211
std::vector< void * > m_sky_textures
A list of the textures for the sky to use.
Definition: track.hpp:275
bool m_reverse_available
Whether this track should be available in reverse version.
Definition: track.hpp:254
float m_sky_dx
sky rotation speed
Definition: track.hpp:271
bool m_enable_auto_rescue
If true a player kart will automatically be rescued if it is e.g.
Definition: track.hpp:258
bool m_has_easter_eggs
True if this track has easter eggs.
Definition: track.hpp:233
core::stringw m_sort_name
The name used in sorting the track.
Definition: track.hpp:348
const std::string & getModeName(unsigned int i) const
Returns the name of the i-th.
Definition: track.hpp:603
const std::string & getScreenshotFile() const
Returns an absolute path to the screenshot file of this track.
Definition: track.hpp:547
const btTransform & getStartTransform(unsigned int index) const
Returns the start coordinates for a kart with a given index.
Definition: track.hpp:557
bool isRaceTrack() const
Returns true if this track is a racing track.
Definition: track.hpp:502
bool m_materials_loaded
True if the materials.xml file is already loaded.
Definition: track.hpp:188
ParticleKind * m_sky_particles
Particles emitted from the sky (wheather)
Definition: track.hpp:303
bool m_use_fog
True if the track uses fog.
Definition: track.hpp:351
bool m_internal
Whether this is an "internal" track.
Definition: track.hpp:251
std::vector< video::ITexture * > m_all_cached_textures
A list of all textures loaded by the track, so that they can be removed from the cache at cleanup tim...
Definition: track.hpp:184
std::vector< scene::ISceneNode * > m_all_nodes
The list of all nodes.
Definition: track.hpp:161
const std::string & getIdent() const
Returns a unique identifier for this track (the directory name).
Definition: track.hpp:534
int m_default_number_of_laps
The number of laps the track will be raced in a random GP.
Definition: track.hpp:409
bool isArena() const
Returns true if this track has an arena mode.
Definition: track.hpp:496
bool isFogEnabled() const
Returns if fog is currently enabled.
Definition: track.hpp:639
const std::vector< std::string > & getGroups() const
Returns all groups this track belongs to.
Definition: track.hpp:538
bool m_weather_lightning
Use a special built-in wheather.
Definition: track.hpp:306
const bool getMinimapInvert() const
Returns if invert minimap.
Definition: track.hpp:553
bool m_is_soccer
True if this track is a soccer arena.
Definition: track.hpp:237
std::string m_name
Name of the track to display.
Definition: track.hpp:345
const std::vector< OverworldChallenge > & getChallengeList() const
Get list of challenges placed on that world.
Definition: track.hpp:688
float m_sky_texture_percent
If a sky dome is used, percentage of the texture to be used.
Definition: track.hpp:300
core::vector3df getColorLevelIn() const
Return the color levels for color correction shader.
Definition: track.hpp:702
unsigned int getMaxArenaPlayers() const
Get the max players supported for this track, for arena only.
Definition: track.hpp:621
bool isAutoRescueEnabled() const
Returns true if auto rescue is enabled.
Definition: track.hpp:672
float getCameraFar() const
Returns the far value for cameras.
Definition: track.hpp:611
float m_friction
Friction to be used for the track.
Definition: track.hpp:130
int m_sky_hori_segments
If a sky dome is used, the number of horizontal segments the sphere should be divided in.
Definition: track.hpp:290
std::vector< OverworldChallenge > m_challenges
Will only be used on overworld.
Definition: track.hpp:139
void addCachedMesh(scene::IMesh *mesh)
Adds mesh to cleanup list.
Definition: track.hpp:737
float m_camera_far
Far value for cameras for this track.
Definition: track.hpp:246
std::string m_root
The base dir of all files of this track.
Definition: track.hpp:157
TriangleMesh * m_height_map_mesh
Used to collect the triangles for the height map mesh used for particle rendering.
Definition: track.hpp:214
bool hasNavMesh() const
Returns true if this track navmesh.
Definition: track.hpp:514
bool m_is_arena
True if this track is an arena.
Definition: track.hpp:228
TrackObjectManager * getTrackObjectManager() const
Returns the track object manager.
Definition: track.hpp:681
int m_version
The version of this track.
Definition: track.hpp:243
bool m_has_navmesh
True if this track has navmesh.
Definition: track.hpp:235
const std::string & getFilename() const
Returns the filename of this track.
Definition: track.hpp:541
Vec3 m_aabb_max
Maximum coordinates of this track.
Definition: track.hpp:224
video::SColor m_ambient_color
The current ambient color for each kart.
Definition: track.hpp:368
std::vector< scene::IMesh * > m_detached_cached_meshes
m_all_cached_meshes assumes meshes are attached to a scene node.
Definition: track.hpp:180
bool hasEasterEggs() const
Returns true if this track has easter eggs.
Definition: track.hpp:508
std::string m_filename
The full filename of the config (xml) file.
Definition: track.hpp:154
A special class to store a triangle mesh with a separate material per triangle.
Definition: triangle_mesh.hpp:35
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48