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