mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-03-02 15:42:17 +00:00
added Zandronum's BYTESTREAM_s
This commit is contained in:
parent
8d8d03d139
commit
b3361bb833
2 changed files with 105 additions and 0 deletions
|
@ -24,8 +24,58 @@
|
|||
|
||||
extern bool netserver, netclient;
|
||||
|
||||
//*****************************************************************************
|
||||
// VARIABLES
|
||||
|
||||
// [BB] Are we measuring outbound traffic?
|
||||
static bool g_MeasuringOutboundTraffic = false;
|
||||
// [BB] Number of bytes sent by NETWORK_Write* since NETWORK_StartTrafficMeasurement() was called.
|
||||
static int g_OutboundBytesMeasured = 0;
|
||||
|
||||
IDList<AActor> g_NetIDList;
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
void NETWORK_AdvanceByteStreamPointer( BYTESTREAM_s *pByteStream, const int NumBytes, const bool OutboundTraffic )
|
||||
{
|
||||
pByteStream->pbStream += NumBytes;
|
||||
|
||||
// [BB]
|
||||
if ( g_MeasuringOutboundTraffic && OutboundTraffic )
|
||||
g_OutboundBytesMeasured += NumBytes;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
int NETWORK_ReadByte( BYTESTREAM_s *pByteStream )
|
||||
{
|
||||
int Byte = -1;
|
||||
|
||||
if (( pByteStream->pbStream + 1 ) <= pByteStream->pbStreamEnd )
|
||||
Byte = *pByteStream->pbStream;
|
||||
|
||||
// Advance the pointer.
|
||||
pByteStream->pbStream += 1;
|
||||
|
||||
return ( Byte );
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
void NETWORK_WriteByte( BYTESTREAM_s *pByteStream, int Byte )
|
||||
{
|
||||
if (( pByteStream->pbStream + 1 ) > pByteStream->pbStreamEnd )
|
||||
{
|
||||
Printf( "NETWORK_WriteByte: Overflow!\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
*pByteStream->pbStream = Byte;
|
||||
|
||||
// Advance the pointer.
|
||||
NETWORK_AdvanceByteStreamPointer ( pByteStream, 1, true );
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
void NetSyncData::AssignNetID ( AActor *pActor )
|
||||
|
@ -46,6 +96,44 @@ void NetSyncData::FreeNetID ( )
|
|||
g_NetIDList.freeID ( NetID );
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
BYTESTREAM_s::BYTESTREAM_s() :
|
||||
bitBuffer( NULL ),
|
||||
bitShift( -1 ) {}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
void BYTESTREAM_s::EnsureBitSpace( int bits, bool writing )
|
||||
{
|
||||
if ( ( bitBuffer == NULL ) || ( bitShift < 0 ) || ( bitShift + bits > 8 ) )
|
||||
{
|
||||
if ( writing )
|
||||
{
|
||||
// Not enough bits left in our current byte, we need a new one.
|
||||
NETWORK_WriteByte( this, 0 );
|
||||
bitBuffer = pbStream - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No room for the value in this byte, so we need a new one.
|
||||
if ( NETWORK_ReadByte( this ) != -1 )
|
||||
{
|
||||
bitBuffer = pbStream - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Argh! No bytes left!
|
||||
Printf("BYTESTREAM_s::EnsureBitSpace: out of bytes to use\n");
|
||||
static uint8_t fallback = 0;
|
||||
bitBuffer = &fallback;
|
||||
}
|
||||
}
|
||||
|
||||
bitShift = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
template <typename T>
|
||||
|
|
|
@ -36,6 +36,23 @@ struct NetSyncData {
|
|||
void FreeNetID ();
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
struct BYTESTREAM_s
|
||||
{
|
||||
BYTESTREAM_s();
|
||||
void EnsureBitSpace( int bits, bool writing );
|
||||
|
||||
// Pointer to our stream of data.
|
||||
uint8_t *pbStream;
|
||||
|
||||
// Pointer to the end of the stream. When pbStream > pbStreamEnd, the
|
||||
// entire stream has been read.
|
||||
uint8_t *pbStreamEnd;
|
||||
|
||||
uint8_t *bitBuffer;
|
||||
int bitShift;
|
||||
};
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// IDList
|
||||
|
|
Loading…
Reference in a new issue