LibNRG  0.0.1
Networking for Real-time Games library
 All Classes Files Functions Variables Friends
nrg_input.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_INPUT_H
26 #define NRG_INPUT_H
27 #include "nrg_core.h"
28 #include "nrg_field.h"
29 #include "nrg_player.h"
30 #include <utility>
31 #include <functional>
32 #include <vector>
33 
34 namespace nrg {
35 
37 struct InputBase : protected FieldContainer {
38  void markUpdated(bool b);
39  bool readFromPacket(Packet& p);
40  void writeToPacket(Packet& p) const;
41 
43  virtual void onUpdate(Player& player) = 0;
44 
46  virtual void doPrediction() = 0;
47 };
48 
50 template<class CRTP>
51 struct Input : public InputBase {
53  void addPredictionFunc(std::function<void(CRTP&)>&& func){
54  predict_funcs.push_back(std::move(func));
55  }
56  void doPrediction(){
57  for(auto& f : predict_funcs){
58  f(*static_cast<CRTP* const>(this));
59  }
60  }
61 private:
62  std::vector<std::function<void(CRTP&)>> predict_funcs;
63 };
64 
65 }
66 
67 #endif
virtual void onUpdate(Player &player)=0
Virtual function called Server-side when the Player player has sent some new input.
Class for storing data to be sent / received across the network.
Definition: nrg_packet.h:58
Represents a connected client on the server.
Definition: nrg_player.h:34
void doPrediction()
NYI: Do prediction of inputs client-side.
Definition: nrg_input.h:56
Abstract base class for Input.
Definition: nrg_input.h:37
Contains the Player Interface used server-side.
Abstract class using the Curiously Recurring Template Pattern that users should inherit from and inse...
Definition: nrg_input.h:51
virtual void doPrediction()=0
NYI: Do prediction of inputs client-side.
Contains classes related to the Field template class that encapsulates data to be replicated across t...
Abstract class used by anything that contains Fields, like Entity or InputBase.
Definition: nrg_field.h:81
Common defines and includes used by all the other nrg header files.
void addPredictionFunc(std::function< void(CRTP &)> &&func)
NYI: Adds a function that is called client-side each frame to predict a Field's value before it is co...
Definition: nrg_input.h:53