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