Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
"
3
#include "
networking/prediction.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!
12
elapsed_since_packet
= 0;
13
latest_timeout
= 0;
14
15
//NETFIXME: Cubic Splines appear to be broken...
16
17
//prediction = new MixedPrediction();
18
prediction
=
new
LinearPrediction
();
19
old_timeout
= 0;
20
ingame
=
false
;
21
loginstate
=
CONNECTED
;
22
webcam
= 0;
23
portaudio
= 0;
24
secured
= 0;
25
jumpok
= 0;
26
jumpfile
=
""
;
27
_disconnectReason
=
"none"
;
28
comm_freq
= 0;
29
last_packet
=
ClientState
();
30
}
31
32
//NetClient initialization
33
Client::Client
()
34
{
35
lossy_socket
= NULL;
36
this->Init();
37
}
38
39
//NetServer initialization
40
Client::Client
(
SOCKETALT
&s ) :
41
tcp_sock( s )
42
{
43
lossy_socket
= &
tcp_sock
;
44
cltadr
= s.
getRemoteAddress
();
45
this->Init();
46
}
47
48
Client::~Client
()
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
62
void
Client::setTCP
()
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
88
void
Client::clearLatestTimestamp
()
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
106
double
Client::getNextDeltatime
()
const
107
{
108
return
_next_deltatime;
109
}
110
src
networking
client.cpp
Generated on Fri May 29 2015 23:07:34 for Vegastrike 0.5.1 rc1 by
1.8.4