Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/synchronizeable_var/synchronizeable_float.cc @ 8192

Last change on this file since 8192 was 7954, checked in by patrick, 19 years ago

trunk: merged the network branche back to trunk.

File size: 1.9 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_float.h"
18#include "converter.h"
19
20
21/**
22 * standard constructor
23 * @todo this constructor is not jet implemented - do it
24*/
25SynchronizeableFloat::SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission, int priority) : SynchronizeableVar( ptrIn, ptrOut, name, FLOATSIZE, permission, priority )
26{
27  this->vPtrIn = ptrIn;
28  this->vPtrOut = ptrOut;
29}
30
31
32/**
33 * standard deconstructor
34*/
35SynchronizeableFloat::~SynchronizeableFloat ()
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 SynchronizeableFloat::writeToBuf( byte * buf, int maxLength )
46{
47  int res = Converter::floatToByteArray( *vPtrIn, buf, maxLength );
48 
49  assert( res == FLOATSIZE );
50 
51  return res;
52}
53
54/**
55 * read var data from byte buffer
56 * @param buf pointer to read from
57 * @param maxLength readFromBuf will not read more than maxLength bytes
58 * @return number bytes read
59 */
60int SynchronizeableFloat::readFromBuf( byte * buf, int maxLength )
61{
62  assert( maxLength >= FLOATSIZE );
63 
64  float oldVal = *vPtrOut;
65 
66  int res = Converter::byteArrayToFloat( buf, vPtrOut );
67 
68  setHasChanged( oldVal != *vPtrOut );
69 
70  assert( res == FLOATSIZE );
71 
72  return res;
73}
74
75
76/**
77 * print out variable value
78 */
79void SynchronizeableFloat::debug( )
80{
81  printf( "SYNCHRONIZEABLE_VAR: %s IN: %f OUT: %f\n", name.c_str(), *vPtrIn, *vPtrOut );
82}
83
Note: See TracBrowser for help on using the repository browser.