PGE API 0.4
PR00F's Game Engine full documentation
Loading...
Searching...
No Matches
PgeOldNewValue< T > Class Template Reference

PR00F's Game Engine old-new variable class. More...

Detailed Description

template<typename T>
class PgeOldNewValue< T >

PR00F's Game Engine old-new variable class.

This class can remember its old (previous) value. Its current value is always its new value. Useful if you want to implement a mechanism that depends on comparison of old and new value, such as:

  • configuration: old value is the applied, new value is to be applied, saving and applying is needed only if old is different than new;
  • sending updates over network: current values are saved at the beginning of a frame, and by end of frame sending any update over network is needed only if the old values are different to the current values.

Definition at line 30 of file PgeOldNewValue.h.

#include <PgeOldNewValue.h>

Public Member Functions

 PgeOldNewValue ()
 Constructs an object with both old and new values initialized to their default values based on their type.
 
 PgeOldNewValue (const T &value)
 Constructs an object with both old and new values as the given value.
 
const T & getOld () const
 
const T & getNew () const
 
bool set (const T &value)
 Sets the given value as new value.
 
const std::chrono::time_point< std::chrono::steady_clock > & getLastTimeNewValueChanged () const
 Returns the timestamp recorded when new (current) value was last updated, i.e.
 
bool isDirty () const
 Dirty flag.
 
void revert ()
 Resets new value to be same as old value and clears dirty flag.
 
void commit ()
 Saves new value to old value and clears dirty flag.
 
bool operator== (const T &other) const
 Equals to value-type.
 
bool operator== (const PgeOldNewValue< T > &other) const
 Equals to.
 
bool operator!= (const T &other) const
 Not equals to value-type.
 
bool operator!= (const PgeOldNewValue< T > &other) const
 Not equals to.
 
PgeOldNewValue< T > & PgeOldNewValue (const T &other)
 Assignment to value-type.
 
 operator T () const
 Conversion to value-type.
 
PgeOldNewValue< T > operator+ (const T &other) const
 Addition.
 
PgeOldNewValue< T > operator+ (const PgeOldNewValue< T > &other) const
 Addition.
 
PgeOldNewValue< T > & operator+= (const T &other)
 Addition assignment.
 
PgeOldNewValue< T > & operator+= (const PgeOldNewValue< T > &other)
 Addition assignment.
 
PgeOldNewValue< T > operator- (const T &other) const
 Subtraction.
 
PgeOldNewValue< T > operator- (const PgeOldNewValue< T > &other) const
 Subtraction.
 
PgeOldNewValue< T > & operator-= (const T &other)
 Subtraction assignment.
 
PgeOldNewValue< T > & operator-= (const PgeOldNewValue< T > &other)
 Subtraction assignment.
 
PgeOldNewValue< T > operator* (const T &other) const
 Multiplication by scalar.
 
PgeOldNewValue< T > operator* (const PgeOldNewValue< T > &other) const
 Multiplication by scalar.
 
PgeOldNewValue< T > & operator*= (const T &other)
 Multiplication assignment.
 
PgeOldNewValue< T > & operator*= (const PgeOldNewValue< T > &other)
 Multiplication assignment.
 
PgeOldNewValue< T > operator/ (const T &other) const
 Division by scalar.
 
PgeOldNewValue< T > operator/ (const PgeOldNewValue< T > &other) const
 Division by scalar.
 
PgeOldNewValue< T > & operator/= (const T &other)
 Division assignment.
 
PgeOldNewValue< T > & operator/= (const PgeOldNewValue< T > &other)
 Division assignment.
 
PgeOldNewValue< T > operator% (const T &other) const
 Modulo division by scalar.
 
PgeOldNewValue< T > operator% (const PgeOldNewValue< T > &other) const
 Modulo division by scalar.
 
PgeOldNewValue< T > & operator%= (const T &other)
 Modulo division assignment.
 
PgeOldNewValue< T > & operator%= (const PgeOldNewValue< T > &other)
 Modulo division assignment.
 
PgeOldNewValue< T > & operator++ ()
 Prefix increment.
 
PgeOldNewValue< T > operator++ (int)
 Postfix increment.
 
PgeOldNewValue< T > & operator-- ()
 Prefix decrement.
 
PgeOldNewValue< T > operator-- (int)
 Postfix decrement.
 
bool set (const float &value)
 
bool set (const PureVector &value)
 

Private Attributes

m_newValue
 
m_oldValue
 
std::chrono::time_point< std::chrono::steady_clock > m_timeLastChange
 

Constructor & Destructor Documentation

◆ PgeOldNewValue() [1/3]

template<typename T >
PgeOldNewValue< T >::PgeOldNewValue ( )

Constructs an object with both old and new values initialized to their default values based on their type.

By default dirty flag is cleared.

Definition at line 158 of file PgeOldNewValue.h.

◆ PgeOldNewValue() [2/3]

template<typename T >
PgeOldNewValue< T >::PgeOldNewValue ( const T & value)
explicit

Constructs an object with both old and new values as the given value.

By default dirty flag is cleared.

Definition at line 164 of file PgeOldNewValue.h.

◆ PgeOldNewValue() [3/3]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::PgeOldNewValue ( const T & other)

Assignment to value-type.

Member Function Documentation

◆ commit()

template<typename T >
void PgeOldNewValue< T >::commit ( )

Saves new value to old value and clears dirty flag.

Does not alter getLastTimeNewValueChanged().

Definition at line 238 of file PgeOldNewValue.h.

◆ getLastTimeNewValueChanged()

template<typename T >
const std::chrono::time_point< std::chrono::steady_clock > & PgeOldNewValue< T >::getLastTimeNewValueChanged ( ) const
inline

Returns the timestamp recorded when new (current) value was last updated, i.e.

when its value was actually changed. Timestamp is recorded only for changes done by set() functions, assignment-, increment- and decrement operators.

Neither revert() nor commit() counts as an actual change to new (current) value. Construction also does not count as an actual change to new (current) value.

Note that constructing a new PgeOldNewValue instance from an existing also copies this timestamp, so the newly constructed PgeOldNewValue instance will have the same timestamp as the original has.

Returns
Timestamp when new (current) value was last updated, i.e. when its value was actually changed.

Definition at line 220 of file PgeOldNewValue.h.

◆ getNew()

template<typename T >
const T & PgeOldNewValue< T >::getNew ( ) const
inline
Returns
New (current) value.

Definition at line 176 of file PgeOldNewValue.h.

◆ getOld()

template<typename T >
const T & PgeOldNewValue< T >::getOld ( ) const
inline
Returns
Old (previous) value.

Definition at line 170 of file PgeOldNewValue.h.

◆ isDirty()

template<typename T >
bool PgeOldNewValue< T >::isDirty ( ) const
inline

Dirty flag.

Returns
True (dirty flag set) if old value is different to new value, false (dirty flag cleared) otherwise.

Definition at line 226 of file PgeOldNewValue.h.

◆ operator T()

template<typename T >
PgeOldNewValue< T >::operator T ( ) const
inline

Conversion to value-type.

Returns
The current (new) value of this object.

Definition at line 299 of file PgeOldNewValue.h.

◆ operator!=() [1/2]

template<typename T >
bool PgeOldNewValue< T >::operator!= ( const PgeOldNewValue< T > & other) const
inline

Not equals to.

Returns
True if any of our old and current (new) values does not equal to the old and current (new) values of the other given object, false otherwise.

Definition at line 278 of file PgeOldNewValue.h.

◆ operator!=() [2/2]

template<typename T >
bool PgeOldNewValue< T >::operator!= ( const T & other) const
inline

Not equals to value-type.

Returns
True if our current (new) value does not equal to the given other value, false otherwise.

Definition at line 268 of file PgeOldNewValue.h.

◆ operator%() [1/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator% ( const PgeOldNewValue< T > & other) const
inline

Modulo division by scalar.

Modulo division.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new values of the 2 PgeOldNewValue operands.

Definition at line 487 of file PgeOldNewValue.h.

◆ operator%() [2/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator% ( const T & other) const
inline

Modulo division by scalar.

Modulo division.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new value of this and the other operands.

Definition at line 477 of file PgeOldNewValue.h.

◆ operator%=() [1/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator%= ( const PgeOldNewValue< T > & other)
inline

Modulo division assignment.

Returns
This object where only the new value is set to the result of the operation done on the new values of this and the other PgeOldNewValue operands.

Definition at line 508 of file PgeOldNewValue.h.

◆ operator%=() [2/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator%= ( const T & other)
inline

Modulo division assignment.

Returns
This object where only the new value is set to the result of the operation done on the new value of this and the other operands.

Definition at line 497 of file PgeOldNewValue.h.

◆ operator*() [1/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator* ( const PgeOldNewValue< T > & other) const
inline

Multiplication by scalar.

Multiplication.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new values of the 2 PgeOldNewValue operands.

Definition at line 403 of file PgeOldNewValue.h.

◆ operator*() [2/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator* ( const T & other) const
inline

Multiplication by scalar.

Multiplication.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new value of this and the other operands.

Definition at line 393 of file PgeOldNewValue.h.

◆ operator*=() [1/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator*= ( const PgeOldNewValue< T > & other)
inline

Multiplication assignment.

Returns
This object where only the new value is set to the result of the operation done on the new values of this and the other PgeOldNewValue operands.

Definition at line 424 of file PgeOldNewValue.h.

◆ operator*=() [2/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator*= ( const T & other)
inline

Multiplication assignment.

Returns
This object where only the new value is set to the result of the operation done on the new value of this and the other operands.

Definition at line 413 of file PgeOldNewValue.h.

◆ operator+() [1/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator+ ( const PgeOldNewValue< T > & other) const
inline

Addition.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new values of the 2 PgeOldNewValue operands.

Definition at line 319 of file PgeOldNewValue.h.

◆ operator+() [2/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator+ ( const T & other) const
inline

Addition.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new value of this and the other operands.

Definition at line 309 of file PgeOldNewValue.h.

◆ operator++() [1/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator++ ( )
inline

Prefix increment.

Returns
This object after the operation, only the new value is incremented.

Definition at line 519 of file PgeOldNewValue.h.

◆ operator++() [2/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator++ ( int )
inline

Postfix increment.

Returns
Copy of this object before the operation (new value is incremented only in the original object).

Definition at line 531 of file PgeOldNewValue.h.

◆ operator+=() [1/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator+= ( const PgeOldNewValue< T > & other)
inline

Addition assignment.

Returns
This object where only the new value is set to the result of the operation done on the new values of this and the other PgeOldNewValue operands.

Definition at line 340 of file PgeOldNewValue.h.

◆ operator+=() [2/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator+= ( const T & other)
inline

Addition assignment.

Returns
This object where only the new value is set to the result of the operation done on the new value of this and the other operands.

Definition at line 329 of file PgeOldNewValue.h.

◆ operator-() [1/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator- ( const PgeOldNewValue< T > & other) const
inline

Subtraction.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new values of the 2 PgeOldNewValue operands.

Definition at line 361 of file PgeOldNewValue.h.

◆ operator-() [2/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator- ( const T & other) const
inline

Subtraction.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new value of this and the other operands.

Definition at line 351 of file PgeOldNewValue.h.

◆ operator--() [1/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator-- ( )
inline

Prefix decrement.

Returns
This object after the operation, only the new value is decremented.

Definition at line 544 of file PgeOldNewValue.h.

◆ operator--() [2/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator-- ( int )
inline

Postfix decrement.

Returns
Copy of this object before the operation (new value is decremented only in the original object).

Definition at line 556 of file PgeOldNewValue.h.

◆ operator-=() [1/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator-= ( const PgeOldNewValue< T > & other)
inline

Subtraction assignment.

Returns
This object where only the new value is set to the result of the operation done on the new values of this and the other PgeOldNewValue operands.

Definition at line 382 of file PgeOldNewValue.h.

◆ operator-=() [2/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator-= ( const T & other)
inline

Subtraction assignment.

Returns
This object where only the new value is set to the result of the operation done on the new value of this and the other operands.

Definition at line 371 of file PgeOldNewValue.h.

◆ operator/() [1/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator/ ( const PgeOldNewValue< T > & other) const
inline

Division by scalar.

Division.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new values of the 2 PgeOldNewValue operands.

Definition at line 445 of file PgeOldNewValue.h.

◆ operator/() [2/2]

template<typename T >
PgeOldNewValue< T > PgeOldNewValue< T >::operator/ ( const T & other) const
inline

Division by scalar.

Division.

Returns
A PgeOldNewValue where both old and new value are set to the result of the operation done on the new value of this and the other operands.

Definition at line 435 of file PgeOldNewValue.h.

◆ operator/=() [1/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator/= ( const PgeOldNewValue< T > & other)
inline

Division assignment.

Returns
This object where only the new value is set to the result of the operation done on the new values of this and the other PgeOldNewValue operands.

Definition at line 466 of file PgeOldNewValue.h.

◆ operator/=() [2/2]

template<typename T >
PgeOldNewValue< T > & PgeOldNewValue< T >::operator/= ( const T & other)
inline

Division assignment.

Returns
This object where only the new value is set to the result of the operation done on the new value of this and the other operands.

Definition at line 455 of file PgeOldNewValue.h.

◆ operator==() [1/2]

template<typename T >
bool PgeOldNewValue< T >::operator== ( const PgeOldNewValue< T > & other) const
inline

Equals to.

Returns
True if both our old and current (new) values equal to the old and current (new) values of the other given object, false otherwise.

Definition at line 258 of file PgeOldNewValue.h.

◆ operator==() [2/2]

template<typename T >
bool PgeOldNewValue< T >::operator== ( const T & other) const
inline

Equals to value-type.

Returns
True if our current (new) value equals to the given other value, false otherwise.

Definition at line 248 of file PgeOldNewValue.h.

◆ revert()

template<typename T >
void PgeOldNewValue< T >::revert ( )

Resets new value to be same as old value and clears dirty flag.

Does not alter getLastTimeNewValueChanged().

Definition at line 232 of file PgeOldNewValue.h.

◆ set() [1/3]

bool PgeOldNewValue< float >::set ( const float & value)
inline

Definition at line 194 of file PgeOldNewValue.h.

◆ set() [2/3]

bool PgeOldNewValue< PureVector >::set ( const PureVector & value)
inline

Definition at line 206 of file PgeOldNewValue.h.

◆ set() [3/3]

template<typename T >
bool PgeOldNewValue< T >::set ( const T & value)

Sets the given value as new value.

Returns
Value of isDirty() after setting the new value.

Definition at line 182 of file PgeOldNewValue.h.

Member Data Documentation

◆ m_newValue

template<typename T >
T PgeOldNewValue< T >::m_newValue
private

Definition at line 131 of file PgeOldNewValue.h.

◆ m_oldValue

template<typename T >
T PgeOldNewValue< T >::m_oldValue
private

Definition at line 132 of file PgeOldNewValue.h.

◆ m_timeLastChange

template<typename T >
std::chrono::time_point<std::chrono::steady_clock> PgeOldNewValue< T >::m_timeLastChange
private

Definition at line 134 of file PgeOldNewValue.h.


The documentation for this class was generated from the following file: