R-Type
R-Type project
NetworkIdentity.hpp
1 #pragma once
2 
3 #include "Component.hpp"
4 
5 namespace KapMirror {
7  private:
8  static int nextNetworkId;
9 
10  private:
11  unsigned int _networkId;
12  bool _hasAuthority;
13 
14  bool _isServer;
15  bool _isClient;
16 
17  public:
18  explicit NetworkIdentity(std::shared_ptr<KapEngine::GameObject> go);
19  ~NetworkIdentity() = default;
20 
24  unsigned int getNetworkId() const { return _networkId; }
25 
30  void setNetworkId(unsigned int networkId) { _networkId = networkId; }
31 
35  bool hasAuthority() const { return _hasAuthority; }
36 
40  void setAuthority(bool authority) { _hasAuthority = authority; }
41 
45  bool isServer() const { return _isServer; }
46 
50  bool isClient() const { return _isClient; }
51 
55  bool isLocal() const { return !_isServer && !_isClient; }
56 
57  void onStartServer();
58  void onStopServer();
59 
60  void onStartClient();
61  void onStopClient();
62  };
63 } // namespace KapMirror
KapMirror::NetworkIdentity
Definition: NetworkIdentity.hpp:6
KapMirror::NetworkIdentity::isServer
bool isServer() const
Returns true if NetworkServer.isActive and server is not stopped.
Definition: NetworkIdentity.hpp:45
KapMirror::NetworkIdentity::isClient
bool isClient() const
Returns true if running as a client and this object was spawned by a server.
Definition: NetworkIdentity.hpp:50
KapMirror::NetworkIdentity::setAuthority
void setAuthority(bool authority)
Set the authority of this object.
Definition: NetworkIdentity.hpp:40
KapMirror::NetworkIdentity::setNetworkId
void setNetworkId(unsigned int networkId)
Set the network Id of this object. (warning: set manually only if you know what you are doing)
Definition: NetworkIdentity.hpp:30
KapEngine::Component
Definition: Component.hpp:38
KapMirror::NetworkIdentity::hasAuthority
bool hasAuthority() const
True on client if that component has been assigned to the client.
Definition: NetworkIdentity.hpp:35
KapMirror::NetworkIdentity::getNetworkId
unsigned int getNetworkId() const
The unique network Id of this object (unique at runtime).
Definition: NetworkIdentity.hpp:24
KapMirror::NetworkIdentity::isLocal
bool isLocal() const
Returns true if running on local. (not spawned by server or client)
Definition: NetworkIdentity.hpp:55