LibNRG  0.0.1
Networking for Real-time Games library
 All Classes Files Functions Variables Friends
nrg_state_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
26 #define NRG_STATE_MANAGER
27 #include "nrg_core.h"
28 #include "nrg_state.h"
29 #include <type_traits>
30 #include <vector>
31 
32 namespace nrg {
33 
36 struct TransitionState : public State {
37  void pre_init(State* old_s, State* new_s);
38  bool init(Client*, Server*, Player*);
39  bool onRecvPacket(Packet& p, PacketFlags f);
40  bool needsUpdate() const;
41  StateResult update(StateConnectionOut& out, StateFlags f);
42  size_t getTimeoutSeconds() const;
43 private:
44  int timeouts;
45  bool client_mode, starting, resend, done;
46  State *old_state, *new_state;
47  Packet buffer;
48 };
49 
51 class StateManager {
52 public:
54  StateManager(Client* c, Server* s, Player* p);
55 
57  StateManager(Server* s, Player* p);
58 
60  StateManager(Client* c);
61 
63  void addState(State& s);
64 
66  bool onRecvPacket(Packet& packet, PacketFlags f);
67 
69  Status update(StateConnectionOut& out);
70 private:
71  std::vector<State*> states;
72  State* state_ptr;
73  TransitionState transition;
74  uint32_t last_update;
75  Client* c;
76  Server* s;
77  Player* p;
78 };
79 
80 }
81 
82 #endif
Common defines and includes used by all the other nrg header files.
Functionality related to the State abstract class.