Tinman  1.0
game.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 GAME_H
18 #define GAME_H
19 #include <memory>
20 #include <Ice/Ice.h>
21 #include <IceUtil/IceUtil.h>
22 
23 #include "physicsdebugdrawer.h"
24 #include "playerfactory.h"
25 #include "carfactory.h"
26 
27 #include "initial.h"
28 #include "menu.h"
29 #include "pause.h"
30 #include "play.h"
31 #include "results.h"
32 
33 class StateMachine;
34 
35 enum class StateName { Initial, Menu, Play, Pause, Results};
36 class Game: public std::enable_shared_from_this<Game> {
37  const float FPS = 60;
39  std::shared_ptr<StateMachine> state_machine_;
42 
43  public:
44  typedef std::shared_ptr<Game> shared;
45  enum class Mode {Bots, Network};
46 
48  float delta_;
49  float finish_time_;
50  std::vector<std::pair<std::string, int>> race_results_;
51 
52  std::string ip_, nick_;
53  int port_;
54 
63 
64  Ice::CommunicatorPtr communicator_;
65  ObjectAdapterPtr debug_adapter_;
66 
67  Game();
68  Game(Session::shared session);
69  virtual ~Game();
70 
71  void start();
72  void start(int seconds);
73  void shutdown();
74  bool gui_shutdown(const CEGUI::EventArgs &event);
75 
76  Ice::AsyncResultPtr login();
77  void complete_login(Ice::AsyncResultPtr async_result);
78  void disconnect();
79 
80  void create_remote_players(Tinman::LoginInfo login_info);
81  void update_remote_players(Tinman::Snapshot snapshot);
82 
83  void new_session();
84 
85  void add_race(Race::shared race);
86  void add_debug_drawer();
87  void add_debug_adapter();
88 
89  void set_current_state(StateName state);
90  void change_state();
91 
93  private:
94  void init();
95  void realize();
96 
97  void step();
98  void game_loop();
99  void game_loop(int seconds);
100 };
101 #endif
std::shared_ptr< StateMachine > state_machine_
Definition: game.h:39
std::shared_ptr< Animation > shared
Definition: animation.h:27
std::shared_ptr< PhysicsDebugDrawer > shared
Definition: physicsdebugdrawer.h:141
std::shared_ptr< Race > shared
Definition: race.h:39
Definition: results.h:5
void add_race(Race::shared race)
Timer timer_
Definition: game.h:38
std::shared_ptr< CarFactory > shared
Definition: carfactory.h:10
Definition: statemachine.h:6
Animation::shared animation_
Definition: game.h:60
std::shared_ptr< Game > shared
Definition: game.h:44
StateName
Definition: game.h:35
std::shared_ptr< Physics > shared
Definition: physics.h:33
Player::shared get_human_player()
Definition: game.cpp:147
void game_loop()
Definition: game.cpp:103
GUI::shared gui_
Definition: game.h:57
void start()
Definition: game.cpp:80
CarFactory::shared car_factory_
Definition: game.h:61
float delta_
Definition: game.h:48
std::shared_ptr< Scene > shared
Definition: scene.h:43
const float FPS
Definition: game.h:37
Scene::shared scene_
Definition: game.h:55
void realize()
Definition: game.cpp:65
bool gui_shutdown(const CEGUI::EventArgs &event)
Definition: game.cpp:141
EventListener::shared input_
Definition: game.h:56
Mode
Definition: game.h:45
void shutdown()
Definition: game.cpp:136
std::shared_ptr< Player > shared
Definition: player.h:14
Session::shared session_
Definition: game.h:62
std::string ip_
Definition: game.h:52
void create_remote_players(Tinman::LoginInfo login_info)
void init()
Definition: game.cpp:34
std::shared_ptr< Sound > shared
Definition: sound.h:13
void add_debug_adapter()
Definition: game.cpp:152
virtual ~Game()
Definition: game.cpp:50
PhysicsDebugDrawer::shared physics_drawer_
Definition: game.h:41
Definition: game.h:36
void disconnect()
Definition: game.cpp:98
void change_state()
Definition: game.cpp:54
void add_debug_drawer()
Definition: game.cpp:159
void step()
Definition: game.cpp:120
Game()
Definition: game.cpp:20
Ice::CommunicatorPtr communicator_
Definition: game.h:64
int port_
Definition: game.h:53
std::vector< std::pair< std::string, int > > race_results_
Definition: game.h:50
Physics::shared physics_
Definition: game.h:59
int frame_counter_
Definition: game.h:40
void set_current_state(StateName state)
Definition: game.cpp:59
Ice::AsyncResultPtr login()
Definition: game.cpp:88
Mode mode_
Definition: game.h:47
void update_remote_players(Tinman::Snapshot snapshot)
std::shared_ptr< EventListener > shared
Definition: input.h:56
std::shared_ptr< GUI > shared
Definition: gui.h:36
Definition: timer.h:22
ObjectAdapterPtr debug_adapter_
Definition: game.h:65
float finish_time_
Definition: game.h:49
void new_session()
Sound::shared sound_
Definition: game.h:58
void complete_login(Ice::AsyncResultPtr async_result)
Definition: game.cpp:93
std::shared_ptr< Session > shared
Definition: session.h:48
std::string nick_
Definition: game.h:52