LibNRG  0.0.1
Networking for Real-time Games library
 All Classes Files Functions Variables Friends
nrg_message_manager.h
Go to the documentation of this file.
1 /*
2  LibNRG - Networking for Real-time Games
3 
4  Copyright (C) 2012-2014 Alex Baines <alex@abaines.me.uk>
5 
6  This software is provided 'as-is', without any express or implied
7  warranty. In no event will the authors be held liable for any damages
8  arising from the use of this software.
9 
10  Permission is granted to anyone to use this software for any purpose,
11  including commercial applications, and to alter it and redistribute it
12  freely, subject to the following restrictions:
13 
14  1. The origin of this software must not be misrepresented; you must not
15  claim that you wrote the original software. If you use this software
16  in a product, an acknowledgment in the product documentation would be
17  appreciated but is not required.
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20  3. This notice may not be removed or altered from any source distribution.
21 */
25 #ifndef NRG_STATE_MANAGER_H
26 #define NRG_STATE_MANAGER_H
27 #include "nrg_core.h"
28 #include "nrg_packet.h"
29 #include "nrg_message.h"
30 #include <memory>
31 #include <vector>
32 #include <map>
33 
34 namespace nrg {
35 
38 public:
41 
43  void writeToPacket(Packet& p, uint16_t server_ms);
44 
46  bool readFromPacket(Packet& p, uint16_t server_ms);
47 
49  void addHandler(MessageBase&& m);
50 
52  void addHandler(const MessageBase& m);
53 
55  void addMessage(const MessageBase& m, uint16_t server_ms);
56 private:
57  struct MessageInfo {
58  off_t data_offset;
59  uint16_t type_id;
60  size_t data_len;
61  uint8_t creation_seq;
62  uint16_t server_creation_time_ms;
63  uint32_t local_creation_time_ms;
64  };
65  std::map<uint16_t, std::unique_ptr<MessageBase>> handlers;
66  std::vector<MessageInfo> msg_metadata;
67  Packet *msg_data, buffer, buffer2;
68  uint8_t local_seq, remote_seq;
69  bool up_to_date, waiting_for_response;
70 };
71 
72 }
73 
74 #endif
Abstract base class for Message.
Definition: nrg_message.h:36
Contains Message classes and functionality for two-way RPC between Server and Client.
Class for storing data to be sent / received across the network.
Definition: nrg_packet.h:58
void addHandler(MessageBase &&m)
Add a Message containing a callback function to be run, passed in m as an R-value reference...
Class that stores Messages to be sent, and parses received messages from packets, running their callb...
Definition: nrg_message_manager.h:37
bool readFromPacket(Packet &p, uint16_t server_ms)
Reads all Messages from Packet p, running associated callback functions with them - The current Serve...
MessageManager()
Default Constructor.
void writeToPacket(Packet &p, uint16_t server_ms)
Writes any queued Messages into the Packet p - The current Server time must be provided in server_ms...
Common defines and includes used by all the other nrg header files.
void addMessage(const MessageBase &m, uint16_t server_ms)
Add a Message m to be sent over the network - The current Server time must be provided in server_ms...