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
client.cpp
Go to the documentation of this file.
1 #include "client.h"
2 #include "lowlevel/vsnet_debug.h"
4 #include "lowlevel/netbuffer.h"
5 
6 void Client::Init()
7 {
8  _latest_timestamp = 0;
9  _old_timestamp = 0;
10  _deltatime = 0;
11  _next_deltatime = 0.5; //Some (sane) default here!
13  latest_timeout = 0;
14 
15 //NETFIXME: Cubic Splines appear to be broken...
16 
17 //prediction = new MixedPrediction();
19  old_timeout = 0;
20  ingame = false;
22  webcam = 0;
23  portaudio = 0;
24  secured = 0;
25  jumpok = 0;
26  jumpfile = "";
27  _disconnectReason = "none";
28  comm_freq = 0;
30 }
31 
32 //NetClient initialization
34 {
35  lossy_socket = NULL;
36  this->Init();
37 }
38 
39 //NetServer initialization
41  tcp_sock( s )
42 {
45  this->Init();
46 }
47 
49 {
50  if (prediction) {
51  delete prediction;
52  prediction = NULL;
53  }
54 }
55 
56 void Client::setUDP( SOCKETALT *udpSock, AddressIP &udpadr )
57 {
58  this->lossy_socket = udpSock;
59  this->cltudpadr = udpadr;
60 }
61 
63 {
64  this->lossy_socket = &this->tcp_sock;
65  this->cltudpadr = this->cltadr;
66 }
67 
68 void Client::versionBuf( NetBuffer &buf ) const
69 {
70  buf.setVersion( netversion );
71 }
72 
73 void Client::setLatestTimestamp( unsigned int ts )
74 {
75 //COUT << "set latest client timestamp " << ts << " (old=" << _old_timestamp << ")" << endl;
76  _old_timestamp = _latest_timestamp;
77  _latest_timestamp = ts;
78  //Compute the deltatime in seconds that is time between packet_timestamp
79  //in ms and the old_timestamp in ms
80  //If the timestamp values are precicely 0 then that means we don't have any good data yet.
81  if (_old_timestamp != 0 && ts != 0) {
82  _deltatime = ( (double) (ts-_old_timestamp) )/1000;
83  _next_deltatime = .33*_deltatime+.67*_next_deltatime;
84  //cerr<<"Unit "<<(game_unit.GetUnit()?game_unit.GetUnit()->GetSerial():-1)<<" has DELTATIME = "<<(_deltatime)<<", NEXT = "<<(_next_deltatime)<<" s ------"<<endl;
85  }
86 }
87 
89 {
90  _latest_timestamp = 0;
91  _old_timestamp = 0;
92  _deltatime = 0;
93  //cerr << "Clearing deltatime for "<<(game_unit.GetUnit()?game_unit.GetUnit()->GetSerial():1)<<", next="<<_next_deltatime<<endl;
94 }
95 
96 unsigned int Client::getLatestTimestamp() const
97 {
98  return _latest_timestamp;
99 }
100 
101 double Client::getDeltatime() const
102 {
103  return _deltatime;
104 }
105 
107 {
108  return _next_deltatime;
109 }
110