Tinman  1.0
session.h
Go to the documentation of this file.
1 // Copyright (C) 2014 ISAAC LACOBA MOLINA
2 // Tinman author: Isaac Lacoba Molina
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef SESSION_H
18 #define SESSION_H
19 #include <OgreTextAreaOverlayElement.h>
20 
21 #include <algorithm>
22 
23 #include "physics.h"
24 #include "car.h"
25 #include "race.h"
26 #include "player.h"
27 
28 class Game;
29 
30 class Session: public std::enable_shared_from_this<Session> {
31  Tinman::LoginInfo login_info_;
32 
33  Ogre::OverlayElement *timer_, *lap_overlay_, *nitro_overlay_, *position_overlay_;
35  /* std::pair<std::string, int> socket_; */
36  std::vector<Tinman::Snapshot> snapshots_;
37 
38  int track_;
39  std::vector<std::pair<std::string, int>> players_positions_;
40 
41  public:
42  std::shared_ptr<Game> game_;
44  std::vector<std::string> players_nicks_;
46  std::vector<Player::shared> players_;
47 
48  typedef std::shared_ptr<Session> shared;
49 
50  Session(Race::shared race);
51  Session(Race::shared new_race, Player::shared player);
52 
53  void add_bot(std::string nick);
54  void add_network_player(std::string nick);
55  void add_instrumentated_player(std::string nick);
56 
57  void update(float delta);
58  void realize();
59  bool race_ended();
60 
61  void next_race();
62 
63  void store(Tinman::Snapshot snapshot);
64 
65  Ice::AsyncResultPtr login();
66  Tinman::LoginInfo complete_login(Ice::AsyncResultPtr login);
67 
68  void reset();
69  void disconnect(void);
70 
71  private:
72  Player::shared get_player(std::string nick);
73  Player::shared get_player(Ice::Byte id);
74 
75  void add_remote_players(Tinman::LoginInfo login_info);
76 
77  void create_overlays(void);
78  void config_cars_in_login_order(void);
79 
80  void update_players(float delta);
81  void update_overlays(void);
82  void update_ranking();
83 
84  std::string to_string_with_precision(const float number, const int n);
85 
86  void configure_race();
87 
88  void reset_race();
89  void active_animation(std::string node, std::string animation_name);
90 
92 };
93 #endif
Ogre::OverlayElement * nitro_overlay_
Definition: session.h:33
std::shared_ptr< Race > shared
Definition: race.h:39
void disconnect(void)
Definition: session.cpp:124
std::shared_ptr< Game > game_
Definition: session.h:42
void add_bot(std::string nick)
Definition: session.cpp:33
void next_race()
std::vector< Player::shared > players_
Definition: session.h:46
bool race_ended()
std::vector< std::pair< std::string, int > > players_positions_
Definition: session.h:39
Race::shared race_
Definition: session.h:43
Ogre::OverlayElement * lap_overlay_
Definition: session.h:33
void add_network_player(std::string nick)
Definition: session.cpp:39
std::shared_ptr< Player > shared
Definition: player.h:14
std::shared_ptr< PowerUp > shared
Definition: powerup.h:45
Ogre::OverlayElement * timer_
Definition: session.h:33
void config_cars_in_login_order(void)
void configure_race()
Definition: session.cpp:157
Player::shared human_player_
Definition: session.h:45
void store(Tinman::Snapshot snapshot)
Definition: session.cpp:136
Tinman::LoginInfo complete_login(Ice::AsyncResultPtr login)
Definition: session.cpp:115
void update_players(float delta)
void add_instrumentated_player(std::string nick)
Definition: session.cpp:45
std::string to_string_with_precision(const float number, const int n)
Definition: session.cpp:129
Ice::AsyncResultPtr login()
Definition: session.cpp:107
Definition: game.h:36
void update_overlays(void)
Definition: session.cpp:88
std::vector< Tinman::Snapshot > snapshots_
Definition: session.h:36
Tinman::LoginInfo login_info_
Definition: session.h:31
PowerUp::shared money_
Definition: session.h:34
PowerUp::shared nitro_
Definition: session.h:34
void active_animation(std::string node, std::string animation_name)
Definition: session.h:30
Session(Race::shared race)
Definition: session.cpp:20
void create_overlays(void)
Definition: session.cpp:69
std::vector< std::string > players_nicks_
Definition: session.h:44
void update_ranking()
Definition: session.cpp:99
Ogre::OverlayElement * position_overlay_
Definition: session.h:33
void add_remote_players(Tinman::LoginInfo login_info)
Definition: session.cpp:52
int track_
Definition: session.h:38
int get_human_player_position()
Definition: session.cpp:162
Player::shared get_player(std::string nick)
void reset_race()
Definition: session.cpp:149
void realize()
Definition: session.cpp:62
void reset()
Definition: session.cpp:142
std::shared_ptr< Session > shared
Definition: session.h:48
void update(float delta)
Definition: session.cpp:77