Tinman  1.0
track.h
Go to the documentation of this file.
1 // -*- coding:utf-8; tab-width:4; mode:cpp -*-
2 // Copyright (C) 2014 ISAAC LACOBA MOLINA
3 // Tinman author: Isaac Lacoba Molina
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef TRACK_H
19 #define TRACK_H
20 #include <iostream>
21 #include <fstream>
22 #include <string>
23 #include <stack>
24 #include <map>
25 #include <functional>
26 #include <uchar.h>
27 
28 #include "physics.h"
29 #include "scene.h"
30 #include "animation.h"
31 #include "meshstrider.h"
32 
33 struct Section {
37  Ogre::SceneNode* node;
38  Ogre::Entity* physics_entity;
39  btRigidBody* body;
40  btVector3 position;
41  int id;
42  std::pair<char, char> direction;
43 };
44 
45 
46 class Track {
47  std::string file_name_;
48  std::wifstream file_;
49  std::map<wchar_t, std::function<Section()>> builder_;
50  std::map<wchar_t, std::pair<char, char>> directions_;
51  std::map<char, char> ends_;
52 
53  int x_, z_, index_;
56  wchar_t current_char_;
57 
58 public:
59  typedef std::shared_ptr<Track> shared;
60  std::vector<Section> segments_;
61  int columns_;
62 
63  Track(std::string file);
64 
65  void next(std::string file);
66  void next(Scene::shared scene, Physics::shared physics);
67  Section create_section(std::string name);
68 
69  void reset();
70  private:
71  void open_file(std::string file);
72 
73  Ogre::SceneNode* create_graphic_element(std::string name);
74  Section create_physic_element(std::string name, Ogre::SceneNode* graphic_element);
75  Section::Type get_section_type(std::string name);
76 
77  void order_track();
78  int get_next_section(int index, char direction);
79  char get_direction(Section::Type type, Section::Type previous, char last_direction);
80 };
81 #endif
Scene::shared scene_
Definition: track.h:54
Physics::shared physics_
Definition: track.h:55
int id
Definition: track.h:41
std::vector< Section > segments_
Definition: track.h:60
int x_
Definition: track.h:53
char get_direction(Section::Type type, Section::Type previous, char last_direction)
Definition: track.cpp:204
btRigidBody * body
Definition: track.h:39
std::shared_ptr< Physics > shared
Definition: physics.h:33
Definition: track.h:34
void reset()
Definition: track.cpp:146
void next(std::string file)
Definition: track.cpp:51
Ogre::SceneNode * node
Definition: track.h:37
std::shared_ptr< Scene > shared
Definition: scene.h:43
Definition: track.h:33
void open_file(std::string file)
Definition: track.cpp:38
std::string file_name_
Definition: track.h:47
Section create_section(std::string name)
Definition: track.cpp:85
Type type
Definition: track.h:36
Section create_physic_element(std::string name, Ogre::SceneNode *graphic_element)
Definition: track.cpp:101
int z_
Definition: track.h:53
Definition: track.h:34
int columns_
Definition: track.h:61
std::map< wchar_t, std::pair< char, char > > directions_
Definition: track.h:50
Ogre::Entity * physics_entity
Definition: track.h:38
Definition: track.h:35
btVector3 position
Definition: track.h:40
Definition: track.h:34
Definition: track.h:34
Ogre::SceneNode * create_graphic_element(std::string name)
Definition: track.cpp:91
std::map< char, char > ends_
Definition: track.h:51
void order_track()
Definition: track.cpp:159
std::shared_ptr< Track > shared
Definition: track.h:59
int get_next_section(int index, char direction)
Definition: track.cpp:185
Definition: track.h:35
std::wifstream file_
Definition: track.h:48
Type
Definition: track.h:34
Section::Type get_section_type(std::string name)
Definition: track.cpp:123
Definition: track.h:35
int index_
Definition: track.h:53
Definition: track.h:46
Track(std::string file)
Definition: track.cpp:21
std::map< wchar_t, std::function< Section()> > builder_
Definition: track.h:49
wchar_t current_char_
Definition: track.h:56
std::pair< char, char > direction
Definition: track.h:42