LibNRG  0.0.1
Networking for Real-time Games library
 All Classes Files Functions Variables Friends
nrg_entity.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_ENTITY_H
26 #define NRG_ENTITY_H
27 #include "nrg_core.h"
28 #include "nrg_field.h"
29 #include <vector>
30 
31 namespace nrg {
32 
33 class EntityManager;
34 class Client;
35 
37 class Entity : public FieldContainer {
38 public:
39 
41  Entity();
42 
44  virtual Entity* clone() = 0;
45 
47  virtual uint16_t getType() const = 0;
48 
50  uint16_t getID() const { return nrg_id; }
51 
54  virtual void onCreate(Client& c){}
56  virtual void onDestroy(Client& c){}
58  virtual void onUpdate(Client& c){}
62  virtual ~Entity();
63 
65  void markUpdated(bool updated);
66  double getInterpTimer() const;
68  void setID(int id){ nrg_id = id; }
70  EntityManager* getManager() const { return manager; }
72  void setManager(EntityManager* m){ manager = m; }
75 private:
76  int nrg_id;
77  bool nrg_updated;
78  EntityManager* manager;
79 };
80 
81 class InputBase;
82 
84 struct EntityManager {
85  virtual void markEntityUpdated(Entity& e){}
86  virtual void unregisterEntity(Entity& e){}
87  virtual double getInterpTimer() const { return 1.0; }
88  virtual bool supportsPrediction() const { return false; }
89  virtual InputBase* getInput() const { return nullptr; }
90 };
91 
93 template<class T, uint16_t type>
95  virtual nrg::Entity* clone(){ return new T(*static_cast<T* const>(this)); }
96  virtual uint16_t getType() const { return type; }
97 };
98 
99 }
100 
101 #endif
virtual nrg::Entity * clone()
Returns an identical copy of the derived class of this Entity.
Definition: nrg_entity.h:95
Abstract class to be inherited by users of the library which acts as a container of one or more Field...
Definition: nrg_entity.h:37
Abstract base class for Input.
Definition: nrg_input.h:37
Abstract class that contains functionality required by Entity objects.
Definition: nrg_entity.h:84
virtual uint16_t getType() const
Returns this entity's user-defined type identifier.
Definition: nrg_entity.h:96
uint16_t getID() const
Returns this Entity's ID assigned by the library.
Definition: nrg_entity.h:50
Entity()
Default Constructor.
virtual Entity * clone()=0
Returns an identical copy of the derived class of this Entity.
virtual void onCreate(Client &c)
Virtual function called on the client-side when the Entity is created.
Definition: nrg_entity.h:54
virtual void onUpdate(Client &c)
Virtual function called on the client-side when the Entity is updated.
Definition: nrg_entity.h:58
Helper template class that automatically implements the Entity::clone and Entity::getType methods...
Definition: nrg_entity.h:94
Contains classes related to the Field template class that encapsulates data to be replicated across t...
virtual void onDestroy(Client &c)
Virtual function called on the client-side just before the Entity is destroyed.
Definition: nrg_entity.h:56
The main client-side nrg class.
Definition: nrg_client.h:42
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.
virtual uint16_t getType() const =0
Returns this entity's user-defined type identifier.
virtual ~Entity()
Standard Destructor.