coastline 0.0.4
Loading...
Searching...
No Matches
netstream.h
Go to the documentation of this file.
1#pragma once
2
4
9
11#define NET_STREAM_BUFFER_SIZE 0x200
13#define NET_PLAYER_STREAM_COUNT 16
14
16class NetStream {
17private:
18 int nReadBit;
19 int nReadPos;
20 int nWriteBit;
21 int nWritePos;
22 unsigned char *pBuffer;
23 unsigned char abBuffer[NET_STREAM_BUFFER_SIZE];
24
31 void StreamAlignReadByte();
32
39 void StreamFlushWriteByte();
40
41public:
49
58 void StreamAttachBuffer(unsigned char *pData, int nSize);
59
67
75
83 void StreamSkip(int nCount);
84
92 unsigned char StreamReadByte();
93
101 unsigned StreamReadInt16();
102
110 unsigned StreamReadInt24();
111
120
129 unsigned BitStreamReadBits(int nBits);
130
139
147 void StreamWriteByte(unsigned char bValue);
148
156 void StreamWriteInt16(unsigned nValue);
157
165 void StreamWriteInt24(unsigned nValue);
166
174 void StreamWriteInt32(unsigned nValue);
175
184 void BitStreamWriteBits(unsigned nValue, int nBits);
185
194
202 unsigned char *StreamGetBufferPtr();
203};
204
212
213#ifdef __cplusplus
214extern "C" {
215#endif
216
220 float fProgress;
221};
222
230
240int CompareNetworkPlayerProgressDescending(const void *pA, const void *pB);
241
243#define NET_PACKET_MAX_SIZE 256
244
258 unsigned char bPlayer,
259 unsigned nTime,
260 unsigned nValue);
261
269
281bool WritePlayerRankingPacket(NetStream *pStream, unsigned char bPlayer);
282
292 unsigned char bPlayer,
293 int nState,
294 int nStatusValue,
295 unsigned char bOptionA,
296 unsigned char bOptionB,
297 unsigned char bOptionC,
298 const char *szPlayerName,
299 unsigned dwOwner);
300
308bool WriteGameSettingsPacket(NetStream *pStream, unsigned char bPlayer);
309
315extern int g_bNetGameSettingUnk_10221280;
317
318struct KeyframeState;
319
327
336
350extern float g_afKeyframeAccumMax[7];
351
359
368
377
385
393unsigned GetInterpolatedRemoteVehicleState(KeyframeState *state, int slotIndex);
394
402
410 const KeyframeState *pBase,
411 NetStream *pStream);
412#ifdef __cplusplus
413}
414#endif
415
422extern unsigned g_dwNetRaceStartCountdownTime;
A stream of the bytes and bits of a packet, read and written from the most significant bit.
Definition netstream.h:16
void StreamWriteInt32(unsigned nValue)
Write the four bytes of a number, from the next whole byte.
bool StreamIsAtEnd()
Whether the reading arrived at the end of the data written.
unsigned char * StreamGetBufferPtr()
The bytes of the stream.
NetStream()
An empty stream of its own bytes.
void StreamWriteInt16(unsigned nValue)
Write the low two bytes of a number, from the next whole byte.
void StreamAttachBuffer(unsigned char *pData, int nSize)
Read the bytes of a buffer from their start.
int StreamReadInt32()
Read four bytes as a number, from the next whole byte.
int StreamGetWriteSize()
The number of bytes written, counting a byte partly written.
void BitStreamWriteBits(unsigned nValue, int nBits)
Write the low bits of a number.
unsigned StreamReadInt24()
Read three bytes as an unsigned number, from the next whole byte.
void StreamResetReadWrite()
Empty the stream.
void StreamWriteByte(unsigned char bValue)
Write a byte, from the next whole byte.
void StreamResetRead()
Read the stream again from its start.
unsigned char StreamReadByte()
Read a byte, from the next whole byte.
unsigned StreamReadInt16()
Read two bytes as an unsigned number, from the next whole byte.
void StreamSkip(int nCount)
Skip bytes, from the next whole byte.
unsigned BitStreamReadBits(int nBits)
Read bits as an unsigned number.
void StreamWriteInt24(unsigned nValue)
Write the low three bytes of a number, from the next whole byte.
#define NET_STREAM_BUFFER_SIZE
The size of the buffer of a NetStream.
Definition netstream.h:11
bool WritePlayerRankingPacket(NetStream *pStream, unsigned char bPlayer)
Write a packet of the positions of the players: the player with the tag 0x20 and the positions of g_a...
void EncodeKeyframeBitstreamDelta(NetStream *stream, KeyframeState *state, KeyframeState *base)
Encode a keyframe against base, shortening position and progress fields.
bool WriteGameSettingsPacket(NetStream *pStream, unsigned char bPlayer)
Write the maximum player count, track, weather, allowed cars, and tyre and suspension settings.
int g_adwNetPlayerRankPosition[NET_PLAYER_STREAM_COUNT]
The position of each network player in the race, from 0 to 15.
NetStream g_aNetPlayerStreams[NET_PLAYER_STREAM_COUNT]
The streams of the players of network play.
void DeserializeVehicleState(KeyframeState *pState, NetStream *pStream)
Decode a full network vehicle keyframe from the bit stream into pState.
int g_dwVehicleStateSendCounter
The number of local vehicle state updates since the network race started.
void EncodeKeyframeBitstreamFull(NetStream *stream, KeyframeState *state)
Encode orientation, position, motion, progress, lights, and effects as a full keyframe.
bool WriteTimeSyncPacket(NetStream *pStream, unsigned char bPlayer, unsigned nTime, unsigned nValue)
Write a packet of the time of a player: the player with the tag 0xc0, the time in 24 bits,...
unsigned g_dwNetRaceStartCountdownTime
The clock time at which the network race countdown ends, in milliseconds.
int CompareNetworkPlayerProgressDescending(const void *pA, const void *pB)
Order two NetPlayerProgress entries for qsort() by their progress, the greatest first.
float g_afKeyframeAccumMax[7]
The largest values accumulated for the seven keyframe fields before the next send.
unsigned SendKeyframePacket(KeyframeState *state)
Send a complete vehicle keyframe as an unreliable network packet.
unsigned GetInterpolatedRemoteVehicleState(KeyframeState *state, int slotIndex)
Interpolate or predict the vehicle state of a remote player from buffered snapshots.
#define NET_PLAYER_STREAM_COUNT
The number of entries of g_aNetPlayerStreams.
Definition netstream.h:13
unsigned SendLocalVehicleStateUpdate(KeyframeState *state)
Accumulate vehicle state over three frames and send full or delta snapshots on schedule.
KeyframeState g_LastSentKeyframe
The last complete local vehicle state sent to the other players.
NetPlayerProgress g_aNetPlayerProgressSort[NET_PLAYER_STREAM_COUNT]
The players of network play, sorted by their progress.
unsigned SendDeltaKeyframePacket(KeyframeState *state, KeyframeState *base)
Send a vehicle keyframe compressed against base as an unreliable network packet.
bool WritePlayerStatusPacket(NetStream *pStream, unsigned char bPlayer, int nState, int nStatusValue, unsigned char bOptionA, unsigned char bOptionB, unsigned char bOptionC, const char *szPlayerName, unsigned dwOwner)
Write a player's state, options, and owner, followed by a name or countdown for states that include t...
void DeserializeKeyframeDelta(KeyframeState *pState, const KeyframeState *pBase, NetStream *pStream)
Reconstruct position and progress relative to pBase from a delta keyframe.
Vehicle pose and interpolated controls before compact frame encoding.
Definition ghost.h:29
A player of network play and the progress that ranks it.
Definition netstream.h:218
int nPlayer
Definition netstream.h:219
float fProgress
Definition netstream.h:220