Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7559 was 7559, checked in by patrick, 18 years ago

network: added some comments and found some small bugs

File size: 2.2 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
20
21/**
22 * standard constructor
23 * @todo this constructor is not jet implemented - do it
24*/
25SynchronizeableVector::SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, 3*FLOATSIZE, permission, priority )
26{
27  this->vPtrIn = ptrIn;
28  this->vPtrOut = ptrOut;
29}
30
31
32/**
33 * standard deconstructor
34*/
35SynchronizeableVector::~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 */
45int SynchronizeableVector::writeToBuf( byte * buf, int maxLength )
46{
47  int n = 0;
48  int res;
49
50  res = Converter::floatToByteArray( vPtrIn->x, buf + n, maxLength - n );
51  assert( res > 0 );
52  n += res;
53
54  res = Converter::floatToByteArray( vPtrIn->y, buf + n, maxLength - n );
55  assert( res > 0 );
56  n += res;
57
58  res = Converter::floatToByteArray( vPtrIn->z, buf + n, maxLength - n );
59  assert( res > 0 );
60  n += res;
61
62  assert( 3*FLOATSIZE == n );
63
64  return n;
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 */
73int SynchronizeableVector::readFromBuf( byte * buf, int maxLength )
74{
75  assert( maxLength >= 3*FLOATSIZE );
76
77  float x,y,z;
78
79  int res;
80  int n = 0;
81
82  res += Converter::byteArrayToFloat( buf + n, &x );
83  assert( res > 0 );
84  n += res;
85
86  res += Converter::byteArrayToFloat( buf + n, &x );
87  assert( res > 0 );
88  n += res;
89
90  res += Converter::byteArrayToFloat( buf + n, &x );
91  assert( res > 0 );
92  n += res;
93
94  *vPtrOut = Vector( x, y, z );
95
96  assert( res == 3*FLOATSIZE );
97  return res;
98}
Note: See TracBrowser for help on using the repository browser.