TDME2  1.9.200
NetworkLogic.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
9 
10 using std::string;
11 using std::vector;
12 
15 
16 /**
17  * Network Logic
18  * @author Andreas Drewke
19  */
21 public:
22  // forbid class copy
24 
25  /**
26  * Public constructor
27  * @param context context
28  * @param id id
29  * @param handlingHIDInput handling hid input
30  */
31  NetworkLogic(Context* context, const string& id, bool handlingHIDInput);
32 
33  /**
34  * @return is handling network input
35  */
36  virtual bool isHandlingNetworkInput();
37 
38  /**
39  * @return network packet type id
40  */
41  virtual uint32_t getNetworkPacketTypeId() = 0;
42 
43  /**
44  * Set that this entity has been synched from network
45  */
46  void setSynchedFromNetwork();
47 
48  /**
49  * @return if entity have been synched from network, will be reset in call
50  */
51  bool isSynchedFromNetwork();
52 
53  /**
54  * @return is server
55  */
56  bool isServer();
57 
58  /**
59  * Handle network packet
60  * @param packet message
61  */
62  virtual void handleNetworkPacket(LogicNetworkPacket& packet) = 0;
63 
64  /**
65  * Get outgoing network packets
66  * @return network packets
67  */
68  vector<LogicNetworkPacket>& getNetworkPackets();
69 
70  /**
71  * Send network packet
72  * @param packet packet
73  */
75 
76  /**
77  * Send network packet for initialization
78  * Note: This is server only for now
79  */
80  virtual void createInitialNetworkPackets() = 0;
81 
82 private:
83  bool synchedFromNetwork { false };
84  vector<LogicNetworkPacket> networkPackets;
85 };
vector< LogicNetworkPacket > & getNetworkPackets()
Get outgoing network packets.
virtual void createInitialNetworkPackets()=0
Send network packet for initialization Note: This is server only for now.
virtual uint32_t getNetworkPacketTypeId()=0
virtual void handleNetworkPacket(LogicNetworkPacket &packet)=0
Handle network packet.
NetworkLogic(Context *context, const string &id, bool handlingHIDInput)
Public constructor.
void setSynchedFromNetwork()
Set that this entity has been synched from network.
void sendNetworkPacket(LogicNetworkPacket &packet)
Send network packet.
vector< LogicNetworkPacket > networkPackets
Definition: NetworkLogic.h:84
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6