[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_vector.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 | SynchronizeableVector::SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 3*FLOATSIZE, permission, priority ) |
---|
[7444] | 27 | { |
---|
| 28 | this->vPtrIn = ptrIn; |
---|
| 29 | this->vPtrOut = ptrOut; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * standard deconstructor |
---|
| 35 | */ |
---|
| 36 | SynchronizeableVector::~SynchronizeableVector () |
---|
| 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 SynchronizeableVector::writeToBuf( byte * buf, int maxLength ) |
---|
| 47 | { |
---|
[7459] | 48 | int n = 0; |
---|
| 49 | int res; |
---|
[7559] | 50 | |
---|
| 51 | res = Converter::floatToByteArray( vPtrIn->x, buf + n, maxLength - n ); |
---|
[7459] | 52 | assert( res > 0 ); |
---|
| 53 | n += res; |
---|
[7559] | 54 | |
---|
| 55 | res = Converter::floatToByteArray( vPtrIn->y, buf + n, maxLength - n ); |
---|
[7459] | 56 | assert( res > 0 ); |
---|
| 57 | n += res; |
---|
[7559] | 58 | |
---|
| 59 | res = Converter::floatToByteArray( vPtrIn->z, buf + n, maxLength - n ); |
---|
[7459] | 60 | assert( res > 0 ); |
---|
| 61 | n += res; |
---|
[7559] | 62 | |
---|
[7459] | 63 | assert( 3*FLOATSIZE == n ); |
---|
[7559] | 64 | |
---|
[7459] | 65 | return n; |
---|
[7444] | 66 | } |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * read var data from byte buffer |
---|
| 70 | * @param buf pointer to read from |
---|
| 71 | * @param maxLength readFromBuf will not read more than maxLength bytes |
---|
| 72 | * @return number bytes read |
---|
| 73 | */ |
---|
| 74 | int SynchronizeableVector::readFromBuf( byte * buf, int maxLength ) |
---|
| 75 | { |
---|
[7459] | 76 | assert( maxLength >= 3*FLOATSIZE ); |
---|
[7559] | 77 | |
---|
[7459] | 78 | float x,y,z; |
---|
[7559] | 79 | |
---|
[7459] | 80 | int res; |
---|
| 81 | int n = 0; |
---|
[9406] | 82 | |
---|
[7793] | 83 | Vector oldVec = *vPtrOut; |
---|
[7559] | 84 | |
---|
[7614] | 85 | res = Converter::byteArrayToFloat( buf + n, &x ); |
---|
[7459] | 86 | assert( res > 0 ); |
---|
| 87 | n += res; |
---|
[7559] | 88 | |
---|
[7614] | 89 | res = Converter::byteArrayToFloat( buf + n, &y ); |
---|
[7459] | 90 | assert( res > 0 ); |
---|
| 91 | n += res; |
---|
[7559] | 92 | |
---|
[7614] | 93 | res = Converter::byteArrayToFloat( buf + n, &z ); |
---|
[7459] | 94 | assert( res > 0 ); |
---|
| 95 | n += res; |
---|
[7559] | 96 | |
---|
[7459] | 97 | *vPtrOut = Vector( x, y, z ); |
---|
[9406] | 98 | |
---|
[7793] | 99 | setHasChanged( !(*vPtrOut == oldVec) ); |
---|
[7559] | 100 | |
---|
[7614] | 101 | assert( n == 3*FLOATSIZE ); |
---|
| 102 | return n; |
---|
[7444] | 103 | } |
---|
[7578] | 104 | |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * print out variable value |
---|
| 108 | */ |
---|
| 109 | void SynchronizeableVector::SynchronizeableVector::debug( ) |
---|
| 110 | { |
---|
| 111 | printf( "SYNCHRONIZEABLE_VAR: %s IN: (%f, %f, %f) OUT: (%f %f %f)\n", name.c_str(), vPtrIn->x, vPtrIn->y, vPtrIn->z, vPtrOut->x, vPtrOut->y, vPtrOut->z ); |
---|
| 112 | } |
---|
| 113 | |
---|