Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cleanup/src/lib/network/synchronizeable_var/synchronizeable_vector.cc

Last change on this file was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 2.5 KB
Line 
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"
18#include "converter.h"
19#include <cassert>
20
21
22/**
23 * standard constructor
24 * @todo this constructor is not jet implemented - do it
25*/
26SynchronizeableVector::SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 3*FLOATSIZE, permission, priority )
27{
28  this->vPtrIn = ptrIn;
29  this->vPtrOut = ptrOut;
30}
31
32
33/**
34 * standard deconstructor
35*/
36SynchronizeableVector::~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 */
46int SynchronizeableVector::writeToBuf( byte * buf, int maxLength )
47{
48  int n = 0;
49  int res;
50
51  res = Converter::floatToByteArray( vPtrIn->x, buf + n, maxLength - n );
52  assert( res > 0 );
53  n += res;
54
55  res = Converter::floatToByteArray( vPtrIn->y, buf + n, maxLength - n );
56  assert( res > 0 );
57  n += res;
58
59  res = Converter::floatToByteArray( vPtrIn->z, buf + n, maxLength - n );
60  assert( res > 0 );
61  n += res;
62
63  assert( 3*FLOATSIZE == n );
64
65  return n;
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 */
74int SynchronizeableVector::readFromBuf( byte * buf, int maxLength )
75{
76  assert( maxLength >= 3*FLOATSIZE );
77
78  float x,y,z;
79
80  int res;
81  int n = 0;
82
83  Vector oldVec = *vPtrOut;
84
85  res = Converter::byteArrayToFloat( buf + n, &x );
86  assert( res > 0 );
87  n += res;
88
89  res = Converter::byteArrayToFloat( buf + n, &y );
90  assert( res > 0 );
91  n += res;
92
93  res = Converter::byteArrayToFloat( buf + n, &z );
94  assert( res > 0 );
95  n += res;
96
97  *vPtrOut = Vector( x, y, z );
98
99  setHasChanged( !(*vPtrOut == oldVec) );
100
101  assert( n == 3*FLOATSIZE );
102  return n;
103}
104
105
106/**
107 * print out variable value
108 */
109void 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
Note: See TracBrowser for help on using the repository browser.