[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_bool.h" |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * standard constructor |
---|
[7446] | 22 | */ |
---|
[7508] | 23 | SynchronizeableBool::SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 1, permission, priority ) |
---|
[7444] | 24 | { |
---|
| 25 | this->vPtrIn = ptrIn; |
---|
| 26 | this->vPtrOut = ptrOut; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | * standard deconstructor |
---|
| 32 | */ |
---|
| 33 | SynchronizeableBool::~SynchronizeableBool () |
---|
| 34 | { |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | /** |
---|
| 38 | * write var data to byte buffer |
---|
| 39 | * @param buf pointer to write to |
---|
| 40 | * @param maxLength writeToBuf will not write more than maxLength bytes |
---|
| 41 | * @return number bytes written |
---|
| 42 | */ |
---|
| 43 | int SynchronizeableBool::writeToBuf( byte * buf, int maxLength ) |
---|
| 44 | { |
---|
[7459] | 45 | assert( maxLength >= 1 ); |
---|
| 46 | |
---|
| 47 | buf[0] = ( *vPtrIn ) ? 1 : 0; |
---|
| 48 | |
---|
| 49 | return 1; |
---|
[7444] | 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * read var data from byte buffer |
---|
| 54 | * @param buf pointer to read from |
---|
| 55 | * @param maxLength readFromBuf will not read more than maxLength bytes |
---|
| 56 | * @return number bytes read |
---|
| 57 | */ |
---|
| 58 | int SynchronizeableBool::readFromBuf( byte * buf, int maxLength ) |
---|
| 59 | { |
---|
[7459] | 60 | assert( maxLength >= 1 ); |
---|
| 61 | |
---|
[7631] | 62 | bool oldVal = *vPtrOut; |
---|
| 63 | |
---|
[7459] | 64 | *vPtrOut = buf[0] != 0; |
---|
| 65 | |
---|
[7631] | 66 | setHasChanged( oldVal != *vPtrOut ); |
---|
| 67 | |
---|
[7459] | 68 | return 1; |
---|
[7444] | 69 | } |
---|
[7578] | 70 | |
---|
| 71 | /** |
---|
| 72 | * print out variable value |
---|
| 73 | */ |
---|
| 74 | void SynchronizeableBool::debug( ) |
---|
| 75 | { |
---|
| 76 | printf( "SYNCHRONIZEABLE_VAR: %s IN: %d OUT: %d\n", name.c_str(), (int)*vPtrIn, (int)*vPtrOut ); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|