| [7444] | 1 | /* | 
|---|
 | 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
 | 3 |  | 
|---|
 | 4 |    Copyright (C) 2004 orx | 
|---|
 | 5 |  | 
|---|
 | 6 |    This program is free software; you can redistribute it and/or modify | 
|---|
 | 7 |    it under the terms of the GNU General Public License as published by | 
|---|
 | 8 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
 | 9 |    any later version. | 
|---|
 | 10 |  | 
|---|
 | 11 |    ### File Specific: | 
|---|
 | 12 |    main-programmer: Christoph Renner | 
|---|
 | 13 |    co-programmer: ... | 
|---|
 | 14 | */ | 
|---|
 | 15 |  | 
|---|
 | 16 |  | 
|---|
 | 17 | #include "synchronizeable_float.h" | 
|---|
| [7459] | 18 | #include "converter.h" | 
|---|
| [9406] | 19 | #include <cassert> | 
|---|
| [7444] | 20 |  | 
|---|
 | 21 |  | 
|---|
 | 22 | /** | 
|---|
 | 23 |  * standard constructor | 
|---|
 | 24 |  * @todo this constructor is not jet implemented - do it | 
|---|
 | 25 | */ | 
|---|
| [7459] | 26 | SynchronizeableFloat::SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, FLOATSIZE, permission, priority ) | 
|---|
| [7444] | 27 | { | 
|---|
 | 28 |   this->vPtrIn = ptrIn; | 
|---|
 | 29 |   this->vPtrOut = ptrOut; | 
|---|
 | 30 | } | 
|---|
 | 31 |  | 
|---|
 | 32 |  | 
|---|
 | 33 | /** | 
|---|
 | 34 |  * standard deconstructor | 
|---|
 | 35 | */ | 
|---|
 | 36 | SynchronizeableFloat::~SynchronizeableFloat () | 
|---|
 | 37 | { | 
|---|
 | 38 | } | 
|---|
 | 39 |  | 
|---|
 | 40 | /** | 
|---|
 | 41 |  * write var data to byte buffer | 
|---|
 | 42 |  * @param buf pointer to write to | 
|---|
 | 43 |  * @param maxLength writeToBuf will not write more than maxLength bytes | 
|---|
 | 44 |  * @return number bytes written | 
|---|
 | 45 |  */ | 
|---|
 | 46 | int SynchronizeableFloat::writeToBuf( byte * buf, int maxLength ) | 
|---|
 | 47 | { | 
|---|
| [7459] | 48 |   int res = Converter::floatToByteArray( *vPtrIn, buf, maxLength ); | 
|---|
| [9406] | 49 |  | 
|---|
| [7459] | 50 |   assert( res == FLOATSIZE ); | 
|---|
| [9406] | 51 |  | 
|---|
| [7459] | 52 |   return res; | 
|---|
| [7444] | 53 | } | 
|---|
 | 54 |  | 
|---|
 | 55 | /** | 
|---|
 | 56 |  * read var data from byte buffer | 
|---|
 | 57 |  * @param buf pointer to read from | 
|---|
 | 58 |  * @param maxLength readFromBuf will not read more than maxLength bytes | 
|---|
 | 59 |  * @return number bytes read | 
|---|
 | 60 |  */ | 
|---|
 | 61 | int SynchronizeableFloat::readFromBuf( byte * buf, int maxLength ) | 
|---|
 | 62 | { | 
|---|
| [7459] | 63 |   assert( maxLength >= FLOATSIZE ); | 
|---|
| [9406] | 64 |  | 
|---|
| [7631] | 65 |   float oldVal = *vPtrOut; | 
|---|
| [9406] | 66 |  | 
|---|
| [7459] | 67 |   int res = Converter::byteArrayToFloat( buf, vPtrOut ); | 
|---|
| [9406] | 68 |  | 
|---|
| [7631] | 69 |   setHasChanged( oldVal != *vPtrOut ); | 
|---|
| [9406] | 70 |  | 
|---|
| [7459] | 71 |   assert( res == FLOATSIZE ); | 
|---|
| [9406] | 72 |  | 
|---|
| [7459] | 73 |   return res; | 
|---|
| [7444] | 74 | } | 
|---|
| [7578] | 75 |  | 
|---|
 | 76 |  | 
|---|
 | 77 | /** | 
|---|
 | 78 |  * print out variable value | 
|---|
 | 79 |  */ | 
|---|
 | 80 | void SynchronizeableFloat::debug( ) | 
|---|
 | 81 | { | 
|---|
 | 82 |   printf( "SYNCHRONIZEABLE_VAR: %s IN: %f OUT: %f\n", name.c_str(), *vPtrIn, *vPtrOut ); | 
|---|
 | 83 | } | 
|---|
 | 84 |  | 
|---|