Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vsnet_clientstate.cpp
Go to the documentation of this file.
1 #include <string>
2 #include <stdio.h>
3 #include "networking/client.h"
4 #include "vsnet_clientstate.h"
5 #include "vsnet_address.h"
6 #include "cmd/unit_generic.h"
7 
8 using std::string;
9 
11 {
12  //this->delay=50;
13  this->client_serial = 0;
14  this->SPECWarpMultiplier = 0.0;
15  this->SPECRampCounter = 0.0;
16  this->pos.position.Set( 0, 0, 0 );
17  this->veloc.Set( 0, 0, 0 );
18  //this->accel.Set( 0,0,0);
19  this->angveloc.Set( 0, 0, 0 );
20 }
21 
23 {
24  this->client_serial = un->GetSerial();
25  this->pos.position = un->curr_physical_state.position;
27  this->veloc = un->Velocity;
28  //this->accel = un->GetAcceleration();
29  this->angveloc = un->AngularVelocity;
30  if (un->graphicOptions.RampCounter != 0 || un->graphicOptions.InWarp) {
31  this->SPECRampCounter = (un->graphicOptions.InWarp ? 1 : -1)
33  this->SPECWarpMultiplier = un->graphicOptions.WarpFieldStrength;
34  } else {
35  this->SPECRampCounter = 0.0;
36  this->SPECWarpMultiplier = 1.0;
37  }
38 }
39 
41 {
42  un->curr_physical_state = this->pos;
43  un->Velocity = this->veloc;
44  un->AngularVelocity = this->angveloc;
45  if (SPECWarpMultiplier >= 1.0) {
46  //Otherwise, do not change.
47  un->graphicOptions.InWarp = (SPECWarpMultiplier != 1.0 || SPECRampCounter != 0.0);
48  if (un->graphicOptions.InWarp) {
49  if (SPECRampCounter < 0) {
50  un->graphicOptions.InWarp = 0;
51  un->graphicOptions.RampCounter = -SPECRampCounter;
52  } else {
53  un->graphicOptions.RampCounter = SPECRampCounter;
54  }
55  un->graphicOptions.WarpFieldStrength = SPECWarpMultiplier;
56  } else {
58  un->graphicOptions.RampCounter = 0.0;
59  }
61  }
62 }
63 
65 {
66  this->client_serial = serial;
67  this->pos.position.Set( 0, 0, 0 );
68  //pos.orientation.Set( 100,0,0);
69  this->veloc.Set( 0, 0, 0 );
70  //this->accel.Set( 0,0,0);
71  this->angveloc.Set( 0, 0, 0 );
72  this->SPECWarpMultiplier = 0.0;
73  this->SPECRampCounter = 0.0;
74  //this->delay = 50;
75 }
76 
77 ClientState::ClientState( ObjSerial serial, QVector posit, Quaternion orientat, Vector velocity, Vector acc, Vector angvel )
78 {
79  this->client_serial = serial;
80  this->pos.position = posit;
81  this->pos.orientation = orientat;
82  this->veloc = velocity;
83  //this->accel = acc;
84  this->angveloc = angvel;
85  this->SPECWarpMultiplier = 0.0;
86  this->SPECRampCounter = 0.0;
87 }
88 
90  QVector posit,
91  Quaternion orientat,
92  Vector velocity,
93  Vector acc,
94  Vector angvel,
95  unsigned int del )
96 {
97  //this->delay = del;
98  this->client_serial = serial;
99  this->pos.position = posit;
100  this->pos.orientation = orientat;
101  this->veloc = velocity;
102  //this->accel = acc;
103  this->angveloc = angvel;
104  this->SPECWarpMultiplier = 0.0;
105  this->SPECRampCounter = 0.0;
106 }
107 
108 ClientState::ClientState( ObjSerial serial, Transformation trans, Vector velocity, Vector acc, Vector angvel, unsigned int del )
109 {
110  //this->delay = del;
111  this->client_serial = serial;
112  this->pos = trans;
113  this->veloc = velocity;
114  //this->accel = acc;
115  this->angveloc = angvel;
116  this->SPECWarpMultiplier = 0.0;
117  this->SPECRampCounter = 0.0;
118 }
119 
121 {
122  display( cerr );
123  cerr<<endl;
124 }
125 bool operator==( const Quaternion &a, const Quaternion &b )
126 {
127  return a.v == b.v && a.s == b.s;
128 }
129 void ClientState::display( std::ostream &ostr ) const
130 {
131  ostr<<"SERIAL="<<this->client_serial
132  <<" - Position="<<pos.position.i<<","<<pos.position.j<<","<<pos.position.k
133  <<" - Orientation="<<pos.orientation.v.i<<","<<pos.orientation.v.j<<","<<pos.orientation.v.k
134  <<" - Velocity="<<veloc.i<<","<<veloc.j<<","<<veloc.k
135  //<< " - Acceleration="<<accel.i<<","<<accel.j<<","<<accel.k;
136  <<" - Ang Velocity="<<angveloc.i<<","<<angveloc.j<<","<<angveloc.k;
137  if (SPECWarpMultiplier != 0.0)
138  ostr<<" - SPEC="<<SPECWarpMultiplier<<", Ramp="<<SPECRampCounter;
139 }
140 
141 int ClientState::operator==( const ClientState &ctmp ) const
142 {
143  //Need == operator for Transformation class
144  return this->client_serial == ctmp.client_serial && this->pos.position == ctmp.pos.position && this->pos.orientation
145  == ctmp.pos.orientation;
146  //return 0;
147 }
148 
149 //Not used any more...
150 /*
151  * void ClientState::netswap()
152  * {
153  * // Switch everything to host or network byte order
154  * //this->delay = POSH_BigU32( this->delay);
155  * //this->client_serial = OBJSERIAL_TONET( this->client_serial);
156  *
157  * this->pos.netswap();
158  * this->veloc.netswap();
159  * // this->accel.netswap();
160  * this->angveloc.netswap();
161  * this->SPECWarpMultiplier = NetSwap(this->SPECWarpMultiplier);
162  * this->SPECRampCounter = NetSwap(this->SPECRampCounter);
163  * }
164  */
165 
166 std::ostream&operator<<( std::ostream &ostr, const Client &c )
167 {
168  ostr<<"(clnt addr "<<c.cltadr
169  <<" tcpsock="<<c.tcp_sock<<", lossysock=";
170  if (c.lossy_socket)
171  ostr<<*c.lossy_socket;
172  else
173  ostr<<"NULL";
174  return ostr;
175 }
176 
177 std::ostream&operator<<( std::ostream &ostr, const ClientState &cs )
178 {
179  cs.display( ostr );
180  return ostr;
181 }
182