HoverRace  2.0
ClientSession.h
Go to the documentation of this file.
1 // ClientSession.h
2 //
3 // Copyright (c) 1995-1998 - Richard Langlois and Grokksoft Inc.
4 // Copyright (c) 2013-2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 //
22 
23 #pragma once
24 
25 #include "../../engine/Model/GameSession.h"
26 #include "../../engine/VideoServices/Sprite.h"
27 #include "../../engine/Util/OS.h"
28 
29 namespace HoverRace {
30  namespace Client {
31  namespace HoverScript {
32  class MetaSession;
33  class TrackPeer;
34  }
35  class Rules;
36  }
37  namespace MainCharacter {
38  class MainCharacter;
39  }
40  namespace Player {
41  class Player;
42  }
43  namespace Model {
44  class Track;
45  }
46  namespace Script {
47  class Core;
48  }
49  namespace Util {
50  class Clock;
51  class Duration;
52  }
53 }
54 
55 namespace HoverRace {
56 namespace Client {
57 
59 {
60 private:
61  ClientSession() = delete;
62 public:
63  ClientSession(std::shared_ptr<Rules> rules);
64  virtual ~ClientSession();
65 
66 public:
67  enum class Phase
68  {
69  INIT,
70  PREGAME,
71  PLAYING,
72  POSTGAME,
73  DONE
74  };
75 
76 protected:
77  struct ChatMessage
78  {
79  ChatMessage() : mCreationTime(0) { }
80 
81  time_t mCreationTime;
82  std::string mBuffer;
83  };
84 
85 public:
86  Phase GetPhase() const { return phase; }
87  bool AdvancePhase();
88  bool AdvancePhase(Phase nextPhase);
89 
90  std::shared_ptr<HoverScript::MetaSession> GetMeta() const { return meta; };
91  void SetMeta(std::shared_ptr<HoverScript::MetaSession> meta);
92 
93  // Simulation control
94  virtual void Process();
95 
96  virtual bool LoadNew(const char *pTitle, Script::Core &scripting,
97  std::shared_ptr<Model::Track> track,
99 
100  void AttachPlayer(int i, std::shared_ptr<Player::Player> player);
101 
102  std::shared_ptr<Util::Clock> GetClock() { return clock; }
103  std::shared_ptr<Util::Clock> GetCountdown() { return countdown; }
104  void CountdownToNextPhase(const Util::Duration &duration);
105  virtual void SetSimulationTime(MR_SimulationTime pTime);
106  MR_SimulationTime GetSimulationTime() const;
107  void UpdateCharacterSimulationTimes();
108 
109  const MR_UInt8 *GetBackImage() const;
110 
111  virtual int ResultAvaillable() const; // Return the number of players desc avail
112  virtual void GetResult(int pPosition, const char *&pPlayerName, int &pId, BOOL & pConnected, int &pNbLap, MR_SimulationTime &pFinishTime, MR_SimulationTime &pBestLap) const;
113  virtual void GetHitResult(int pPosition, const char *&pPlayerName, int &pId, BOOL & pConnected, int &pNbHitOther, int &pNbHitHimself) const;
114 
115  virtual int GetNbPlayers() const;
116  virtual int GetRank(const MainCharacter::MainCharacter * pPlayer) const;
117 
118  virtual Player::Player *GetPlayer(int i) const
119  {
120  return players[static_cast<size_t>(i)].get();
121  }
122 
123  virtual std::shared_ptr<Player::Player> SharePlayer(int i) const
124  {
125  return players[static_cast<size_t>(i)];
126  }
127 
128  // Chat related functions (all messages are already converted in internal ASCII
129  virtual void AddMessageKey(char pKey);
130  virtual void GetCurrentMessage(char *pDest) const;
131  BOOL GetMessageStack(int pLevel, char *pDest, int pExpiration) const;
132  void AddMessage(const char *pMessage);
133 
134  const Model::Level *GetCurrentLevel() const;
135  std::shared_ptr<HoverScript::TrackPeer> GetTrackPeer() const { return trackPeer; }
136 
137  std::shared_ptr<Rules> GetRules() { return rules; }
138 
139 private:
141 
142  mutable boost::mutex chatMutex;
143  static const int CHAT_MESSAGE_STACK = 8;
144  ChatMessage mMessageStack[CHAT_MESSAGE_STACK];
145 
147  static const int MAX_PLAYERS = 4;
148  std::array<std::shared_ptr<Player::Player>, MAX_PLAYERS> players;
149 
150  std::shared_ptr<HoverScript::MetaSession> meta;
151  std::shared_ptr<HoverScript::TrackPeer> trackPeer;
152 
154 
155  std::shared_ptr<Util::Clock> clock;
156  std::shared_ptr<Util::Clock> countdown;
157  boost::signals2::scoped_connection countdownConn;
158  std::shared_ptr<Rules> rules;
159 
160  void ReadLevelAttrib(Parcel::RecordFile *pFile,
162 };
163 
164 } // namespace Client
165 } // namespace HoverRace
std::shared_ptr< HoverScript::MetaSession > meta
Definition: ClientSession.h:150
std::shared_ptr< HoverScript::TrackPeer > trackPeer
Definition: ClientSession.h:151
Phase
Definition: ClientSession.h:67
ChatMessage()
Definition: ClientSession.h:79
virtual std::shared_ptr< Player::Player > SharePlayer(int i) const
Definition: ClientSession.h:123
time_t mCreationTime
Definition: ClientSession.h:81
std::shared_ptr< Util::Clock > clock
Definition: ClientSession.h:155
std::shared_ptr< Util::Clock > countdown
Definition: ClientSession.h:156
std::shared_ptr< Rules > rules
Definition: ClientSession.h:158
std::shared_ptr< Util::Clock > GetClock()
Definition: ClientSession.h:102
std::shared_ptr< Util::Clock > GetCountdown()
Definition: ClientSession.h:103
Base class for parcel implementations.
Definition: RecordFile.h:46
std::string countdown
Definition: Observer.cpp:56
Phase phase
Definition: ClientSession.h:140
Phase GetPhase() const
Definition: ClientSession.h:86
std::array< std::shared_ptr< Player::Player >, MAX_PLAYERS > players
Definition: ClientSession.h:148
MR_Int32 MR_SimulationTime
Definition: WorldCoordinates.h:106
virtual Player::Player * GetPlayer(int i) const
Definition: ClientSession.h:118
boost::signals2::scoped_connection countdownConn
Definition: ClientSession.h:157
Video framebuffer for legacy (8-bit, palettized) rendering.
Definition: VideoBuffer.h:54
std::shared_ptr< HoverScript::MetaSession > GetMeta() const
Definition: ClientSession.h:90
A track level.
Definition: Track.h:57
MR_UInt8 * mBackImage
Definition: ClientSession.h:153
Model::GameSession mSession
Definition: ClientSession.h:146
Definition: Level.h:74
Definition: ClientSession.h:58
Definition: Announcement.h:24
Definition: GameSession.h:54
boost::mutex chatMutex
Definition: ClientSession.h:142
Base class for connected players.
Definition: Player.h:49
std::string mBuffer
Definition: ClientSession.h:82
The relative time between two timestamps.
Definition: Duration.h:49
std::shared_ptr< Rules > GetRules()
Definition: ClientSession.h:137
uint8_t MR_UInt8
Definition: MR_Types.h:40
std::shared_ptr< HoverScript::TrackPeer > GetTrackPeer() const
Definition: ClientSession.h:135
Definition: MainCharacter.h:62
Definition: ClientSession.h:77
A script environment.
Definition: Core.h:66