28 #include "nrg_packet.h"
99 virtual void markUpdated(
bool b) = 0;
101 virtual double getInterpTimer()
const {
return 1.0; }
111 template<
typename T,
class Cdc = nrg::Codec<T> >
121 return Cdc().decode(p, data_next);
125 return Cdc().encode(p, data);
140 data = data_next = other;
154 return func(data, data_next, this->container->getInterpTimer());
159 return lerp<T>()(data, data_next, this->container->getInterpTimer());
166 template<
typename T,
size_t N>
170 updated_indices.set();
173 updated_indices.set();
178 p.
read<index_t>(count);
179 size_t uic = count + 1;
181 if(uic * (
sizeof(index_t) +
sizeof(T)) > N *
sizeof(T)){
182 for(
size_t i = 0; i < N; ++i){
183 p.
read<T>(data_next[i]);
185 return sizeof(index_t) + N *
sizeof(T);
187 for(
size_t i = 0; i < uic; ++i){
191 p.
read<T>(data_next[k]);
193 p.
seek(SEEK_CUR,
sizeof(T));
196 return sizeof(index_t) + (uic * (
sizeof(index_t) +
sizeof(T)));
201 size_t uic = updated_indices.count();
202 p.
write<index_t>(uic-1);
204 if(uic * (
sizeof(index_t) +
sizeof(T)) > N *
sizeof(T)){
205 for(
size_t i = 0; i < N; ++i){
208 return sizeof(index_t) + (N *
sizeof(T));
210 for(
size_t i = 0; i < N; ++i){
211 if(updated_indices[i]){
216 return sizeof(index_t) + (uic * (
sizeof(index_t) +
sizeof(T)));
221 memcpy(data, data_next, N *
sizeof(T));
226 if(!updated) updated_indices.reset();
229 void set(
size_t index,
const T& other){
230 if(data[index] != other){
232 updated_indices.set(index);
243 T
get(
size_t index)
const {
244 return data_next[index];
248 T
getInterp(
size_t index,
const F& func)
const {
249 return func(data[index], data_next[index], this->container->getInterpTimer());
253 return lerp<T>()(data[index], data_next[index], this->container->getInterpTimer());
256 T data[N], data_next[N];
257 std::bitset<N> updated_indices;
258 typedef typename detail::size2type<detail::min_sizeof<N-1>::val>::type index_t;
Packet & seek(off_t offset, int whence)
Seeks the packet to some offset using SEEK_SET, SEEK_CUR or SEEK_END.
virtual void setUpdated(bool updated)
Force this Field's updated flag to be true or false.
Definition: nrg_field.h:224
FieldContainer()
Standard Constructor.
Field & operator=(const T &other)
Assignment operator, which also marks this field as having been updated.
Definition: nrg_field.h:138
Template class encapsulating a type that will be replicated from Server to Clients, and is stored inside a FieldContainer.
Definition: nrg_field.h:112
FieldBase * getNextField() const
Returns the next Field in the FielcContainer's linked list, or nullptr at the end of the list...
FieldBase & operator=(const FieldBase ©)
Assignment operator.
Contains the Codec class, which encodes and decodes types to and from Packets.
Class for storing data to be sent / received across the network.
Definition: nrg_packet.h:58
void read(T &v)
Generic read function with endian conversion, be careful with types like size_t that differ across pl...
Definition: nrg_packet.h:115
virtual void shiftData()
Indicates a new Snapshot has begun and the Field should move data_next to data.
Definition: nrg_field.h:220
virtual size_t readFromPacket(Packet &p)
Reads data from Packet p into this Field.
Definition: nrg_field.h:120
virtual size_t writeToPacket(Packet &p) const
Writes this Field into the Packet p.
Definition: nrg_field.h:200
virtual size_t readFromPacket(Packet &p)=0
Reads data from Packet p into this Field.
virtual void setUpdated(bool updated)
Force this Field's updated flag to be true or false.
Various utility classes and functions.
virtual size_t readFromPacket(Packet &p)
Reads data from Packet p into this Field.
Definition: nrg_field.h:176
virtual size_t writeToPacket(Packet &p) const =0
Writes this Field into the Packet p.
FieldContainer & operator=(const FieldContainer ©)
Assignment Operator.
FieldBase(FieldContainer *container)
Standard Constructor.
virtual size_t writeToPacket(Packet &p) const
Writes this Field into the Packet p.
Definition: nrg_field.h:124
T getInterp(const F &func) const
Returns data interpolated between the two latest Snapshots using func.
Definition: nrg_field.h:153
virtual void shiftData()=0
Indicates a new Snapshot has begun and the Field should move data_next to data.
Abstract base class that Field inherits from.
Definition: nrg_field.h:39
virtual void shiftData()
Indicates a new Snapshot has begun and the Field should move data_next to data.
Definition: nrg_field.h:128
Simple linear-interpolation functor.
Definition: nrg_interp.h:33
virtual bool wasUpdated() const
Returns true if the Field was updated since the last update.
void set(const T &other)
Alternative to Field::operator=.
Definition: nrg_field.h:133
size_t getNumFields() const
Returns the number of fields in this FieldContainer's linked-list.
Abstract class used by anything that contains Fields, like Entity or InputBase.
Definition: nrg_field.h:81
T getInterp() const
Returns data linearly interpolated between the two latest Snapshots using nrg::lerp.
Definition: nrg_field.h:158
Common defines and includes used by all the other nrg header files.
FieldBase * getFirstField() const
Return the first field in this FieldContainer's internal linked-list.
virtual ~FieldBase()
Standard Destructor.
Definition: nrg_field.h:60
void write(const T &v)
Generic write function with endian conversion, be careful with types like size_t that differ across p...
Definition: nrg_packet.h:94
Interpolation functionality.