HoverRace  2.0
Player.h
Go to the documentation of this file.
1 
2 // Player.h
3 //
4 // Copyright (c) 2014, 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 #pragma once
23 
24 #include "Profile.h"
25 
26 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
27 # ifdef MR_ENGINE
28 # define MR_DllDeclare __declspec( dllexport )
29 # else
30 # define MR_DllDeclare __declspec( dllimport )
31 # endif
32 #else
33 # define MR_DllDeclare
34 #endif
35 
36 namespace HoverRace {
37  namespace MainCharacter {
38  class MainCharacter;
39  }
40 }
41 
42 namespace HoverRace {
43 namespace Player {
44 
50 {
51 public:
52  enum class ConnectionState
53  {
54  DISCONNECTED,
55  CONNECTING,
56  CONNECTED,
57  DISCONNECTING,
58  };
59 
60 public:
61  Player() = delete;
62  Player(std::shared_ptr<Profile> profile,
63  bool local, bool human, bool competing);
64  virtual ~Player() { }
65 
66 public:
67  virtual std::ostream &StreamOut(std::ostream &os) const;
68 
69 public:
80  const std::string &GetName() const { return name; }
81 
82  void SetNameSuffix(const std::string &suffix);
83 
84  Profile *GetProfile() const { return profile.get(); }
85 
86  std::shared_ptr<Profile> ShareProfile() const { return profile; }
87 
88  bool IsLocal() const { return local; }
89 
90  bool IsHuman() const { return human; }
91 
92  bool IsCompeting() const { return competing; }
93 
94  ConnectionState GetConnectionState() const { return connectionState; }
95 
100  MainCharacter::MainCharacter *GetMainCharacter() const { return mainCharacter; }
101 
107  {
108  this->mainCharacter = mainCharacter;
109  }
110 
115  {
116  this->mainCharacter = nullptr;
117  }
118 
119 public:
120  using nameChangedSignal_t = boost::signals2::signal<void()>;
121  nameChangedSignal_t &GetNameChangedSignal() { return nameChangedSignal; }
122 
123  using connectionStateChanged_t = boost::signals2::signal<void()>;
124  connectionStateChanged_t &GetConnectionStateChangedSignal() { return connectionStateChangedSignal; }
125 
126 protected:
127  void SetConnectionState(ConnectionState state);
128  virtual void Disconnect() = 0;
129 
130 private:
131  std::string name;
132  std::shared_ptr<Profile> profile;
133  bool local;
134  bool human;
135  bool competing;
140 };
141 
142 inline std::ostream &operator<<(std::ostream &os, const Player &p)
143 {
144  return p.StreamOut(os);
145 }
146 
147 } // namespace Player
148 } // namespace HoverRace
149 
150 #undef MR_DllDeclare
bool IsLocal() const
Definition: Player.h:88
ConnectionState
Definition: Player.h:52
bool IsCompeting() const
Definition: Player.h:92
connectionStateChanged_t & GetConnectionStateChangedSignal()
Definition: Player.h:124
ConnectionState connectionState
Definition: Player.h:136
bool IsHuman() const
Definition: Player.h:90
bool competing
Definition: Player.h:135
boost::signals2::signal< void()> connectionStateChanged_t
Definition: Player.h:123
Profile * GetProfile() const
Definition: Player.h:84
std::string name
Definition: Player.h:131
std::shared_ptr< Profile > ShareProfile() const
Definition: Player.h:86
Player::Profile & profile
Definition: ProfileEditScene.cpp:83
void AttachMainCharacter(MainCharacter::MainCharacter *mainCharacter)
Attach the main character (when joining a game session).
Definition: Player.h:106
bool local
Definition: Player.h:133
std::shared_ptr< Profile > profile
Definition: Player.h:132
connectionStateChanged_t connectionStateChangedSignal
Definition: Player.h:139
ConnectionState GetConnectionState() const
Definition: Player.h:94
void DetachMainCharacter()
Detach the main character (when leaving a game session).
Definition: Player.h:114
nameChangedSignal_t nameChangedSignal
Definition: Player.h:138
std::ostream & operator<<(std::ostream &os, const Vec2 &v)
Definition: Vec.h:48
bool human
Definition: Player.h:134
Base class for player profiles.
Definition: Profile.h:56
MainCharacter::MainCharacter * GetMainCharacter() const
Retrieve the main character, if attached.
Definition: Player.h:100
Definition: Announcement.h:24
virtual ~Player()
Definition: Player.h:64
Base class for connected players.
Definition: Player.h:49
#define MR_DllDeclare
Definition: Player.h:33
nameChangedSignal_t & GetNameChangedSignal()
Definition: Player.h:121
boost::signals2::signal< void()> nameChangedSignal_t
Definition: Player.h:120
const std::string & GetName() const
Retrieve the display name of the player.
Definition: Player.h:80
Definition: MainCharacter.h:62
MainCharacter::MainCharacter * mainCharacter
Definition: Player.h:137