home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / ReplicaNetFreewareV5_4.exe / data1.cab / Program_Executable_Files / Example6 / DataBlock_WatchedFloat.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  2.1 KB  |  83 lines

  1. /* START_LICENSE_HEADER
  2.  
  3. Copyright (C) 2000 Martin Piper, original design and program code
  4. Copyright (C) 2001-2005 Replica Software
  5.  
  6. This program file is copyright (C) Replica Software and can only be used under license.
  7. For more information visit: http://www.replicanet.com/
  8. Or email: info@replicanet.com
  9.  
  10. END_LICENSE_HEADER */
  11. #ifndef __DATABLOCK_WATHCEDFLOAT_H__
  12. #define __DATABLOCK_WATHCEDFLOAT_H__
  13.  
  14. #include "RNReplicaNet/Inc/DataBlock_Predict_Float.h"
  15.  
  16. /**
  17.  * This class is an example of how to expand the standard DataBlock derived classes to provide a custom interface.
  18.  */
  19. class WatchedFloat : public RNReplicaNet::DataBlock_Predict_Float
  20. {
  21. public:
  22.     WatchedFloat()
  23.     {
  24.         // This class is not designed to be newed in the normal way. It is designed to be included as part of an object as a member variable
  25.         SetIsAllocated(false);        // When the ReplicaObject is deleted the dtor will not use 'delete' to free this DataBlock
  26.         RegisterInClassPointer(&mValue);
  27.         mUpdated = false;
  28.     }
  29.  
  30.     ~WatchedFloat()
  31.     {
  32.     }
  33.  
  34.     // Because we get a message from ReplicaNet the value of this DataBlock is about to change
  35.     virtual void ParseMessage(RNReplicaNet::MessageHelper *message)
  36.     {
  37.         mUpdated = true;
  38.         // Now call the real DataBlock below us to parse the message
  39.         DataBlock_Predict_Float::ParseMessage(message);
  40.     }
  41.  
  42.     /**
  43.      * This reads the updated flag and resets the flag back to false
  44.      * \return returns the changed flag
  45.      */
  46.     bool GetUpdated(void)
  47.     {
  48.         bool retVal = mUpdated;
  49.         mUpdated = false;
  50.         return retVal;
  51.     }
  52.  
  53.     /**
  54.      * Gets the value
  55.      * \return the value
  56.      */
  57.     float GetValue(void) const
  58.     {
  59.         return mValue;
  60.     }
  61.  
  62.     /**
  63.      * Sets the value
  64.      * \param value the value to set
  65.      */
  66.     void SetValue(const float value)
  67.     {
  68.         mValue = value;
  69.     }
  70.  
  71. private:
  72.     bool mUpdated;
  73.     float mValue;
  74. };
  75.  
  76. // These two macros are used by the ROL compiled object to reference the DataBlock class and to register it with ReplicaNet.
  77. #define EXTENSION_WATCHEDFLOATCTOR(x)    \
  78.     RegisterDataBlock(&(basepoint->x));
  79.  
  80. #define EXTENSION_WATCHEDFLOATDTOR()
  81.  
  82. #endif
  83.