Skip to content

Commit 53b4d5f

Browse files
rm5248madebr
andauthored
Build wwbitpack linux (w3dhub#72)
* Build wwbitpack on Linux * add unsigned long back in until we can remove the custom types * Update .github/workflows/openw3d.yml Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com> * update with latest version from review --------- Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
1 parent da27179 commit 53b4d5f

7 files changed

Lines changed: 96 additions & 89 deletions

File tree

.github/workflows/openw3d.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ jobs:
4444
shell: msys2 {0}
4545
- name: Linux x64
4646
os: ubuntu-latest
47-
build-args: --parallel --target scripts --target bandtest
47+
build-args: >
48+
--parallel
49+
--target
50+
scripts
51+
bandtest
52+
wwmath
53+
wwutil
54+
wwbitpack
4855
shell: bash
4956

5057
steps:

Code/wwbitpack/BitPacker.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
#include "wwdebug.h"
3232

3333
//-----------------------------------------------------------------------------
34-
//cBitPacker::cBitPacker(UINT buffer_size) :
34+
//cBitPacker::cBitPacker(uint32_t buffer_size) :
3535
cBitPacker::cBitPacker() :
3636
//BufferSize(buffer_size),
3737
BitWritePosition(0),
3838
BitReadPosition(0)
3939
{
4040
//WWASSERT(BufferSize > 0);
4141

42-
//Buffer = new BYTE[BufferSize];
42+
//Buffer = new uint8_t[BufferSize];
4343
//WWASSERT(Buffer != NULL);
4444
//memset(Buffer, 0, BufferSize);
4545
memset(Buffer, 0, MAX_BUFFER_SIZE);
@@ -73,7 +73,7 @@ cBitPacker& cBitPacker::operator=(const cBitPacker& rhs)
7373
// If you use optimized Add_Bits() you need to also use optimize Get_Bits().
7474
//
7575

76-
void cBitPacker::Add_Bits(ULONG value, UINT num_bits)
76+
void cBitPacker::Add_Bits(uint32_t value, uint32_t num_bits)
7777
{
7878
//
7979
// N.B. Presently you cannot use this class with an atomic type of more
@@ -83,14 +83,14 @@ void cBitPacker::Add_Bits(ULONG value, UINT num_bits)
8383
#if 0 // Old version
8484
WWASSERT(num_bits > 0 && num_bits <= MAX_BITS);
8585

86-
ULONG mask = 1 << (num_bits - 1);
86+
uint32_t mask = 1 << (num_bits - 1);
8787
while (mask > 0) {
8888

8989
//WWASSERT(BitWritePosition < BufferSize * 8);
9090
WWASSERT(BitWritePosition < MAX_BUFFER_SIZE * 8);
9191

92-
UINT byte_num = BitWritePosition / 8;
93-
UINT bit_offset = BitWritePosition % 8;
92+
uint32_t byte_num = BitWritePosition / 8;
93+
uint32_t bit_offset = BitWritePosition % 8;
9494
bool bit_value = (value & mask) != 0;
9595
Buffer[byte_num] |= bit_value << bit_offset;
9696

@@ -106,17 +106,17 @@ void cBitPacker::Add_Bits(ULONG value, UINT num_bits)
106106
WWASSERT(BitWritePosition+num_bits <= MAX_BUFFER_SIZE * 8);
107107

108108
// Fill the remaining bits of the write byte first
109-
UINT byte_num = BitWritePosition >> 3;
110-
UINT bit_offset = BitWritePosition & 0x7;
109+
uint32_t byte_num = BitWritePosition >> 3;
110+
uint32_t bit_offset = BitWritePosition & 0x7;
111111
BitWritePosition+=num_bits; // Advance the write position
112112

113113
// If write buffer is not byte aligned, write the remaining bits first
114114
value <<= 32-num_bits;
115115
if (bit_offset) {
116-
UINT bit_count = 8 - bit_offset;
116+
uint32_t bit_count = 8 - bit_offset;
117117
if (bit_count>num_bits) bit_count=num_bits;
118118

119-
ULONG bit_value = value;
119+
uint32_t bit_value = value;
120120
value <<= bit_count; // Remove the copied bits
121121
num_bits -= bit_count;
122122
bit_value >>= (24+bit_offset);
@@ -141,7 +141,7 @@ void cBitPacker::Add_Bits(ULONG value, UINT num_bits)
141141
// This method needs optimization
142142
// 02-14-2002 Jani: Optimized. See Add_Bits() for notes.
143143
//
144-
void cBitPacker::Get_Bits(ULONG & value, UINT num_bits)
144+
void cBitPacker::Get_Bits(uint32_t & value, uint32_t num_bits)
145145
{
146146
#if 0 // Old version
147147
WWASSERT(num_bits > 0 && num_bits <= MAX_BITS);
@@ -152,8 +152,8 @@ void cBitPacker::Get_Bits(ULONG & value, UINT num_bits)
152152
//WWASSERT(BitReadPosition < BufferSize * 8);
153153
WWASSERT(BitReadPosition < MAX_BUFFER_SIZE * 8);
154154
WWASSERT(BitReadPosition < BitWritePosition);
155-
UINT byte_num = BitReadPosition / 8;
156-
UINT bit_offset = BitReadPosition % 8;
155+
uint32_t byte_num = BitReadPosition / 8;
156+
uint32_t bit_offset = BitReadPosition % 8;
157157
bool b = (Buffer[byte_num] & (1 << bit_offset)) != 0;
158158

159159
value += (b << bit);
@@ -167,14 +167,14 @@ void cBitPacker::Get_Bits(ULONG & value, UINT num_bits)
167167
WWASSERT(BitReadPosition+num_bits <= MAX_BUFFER_SIZE * 8);
168168
WWASSERT(BitReadPosition+num_bits <= BitWritePosition);
169169

170-
UINT read_len=num_bits;
171-
UINT byte_num = BitReadPosition / 8;
172-
UINT bit_offset = BitReadPosition % 8;
170+
uint32_t read_len=num_bits;
171+
uint32_t byte_num = BitReadPosition / 8;
172+
uint32_t bit_offset = BitReadPosition % 8;
173173
BitReadPosition += num_bits;
174174

175-
UINT bit_count = 8 - bit_offset;
175+
uint32_t bit_count = 8 - bit_offset;
176176
if (bit_count>num_bits) bit_count=num_bits;
177-
value = (ULONG(Buffer[byte_num++]) << (bit_offset+24));
177+
value = (uint32_t(Buffer[byte_num++]) << (bit_offset+24));
178178
num_bits-=bit_count;
179179

180180
int shift;
@@ -190,7 +190,7 @@ void cBitPacker::Get_Bits(ULONG & value, UINT num_bits)
190190
// This method is only for use by a packet class when data is received.
191191
//
192192

193-
void cBitPacker::Set_Bit_Write_Position(UINT position)
193+
void cBitPacker::Set_Bit_Write_Position(uint32_t position)
194194
{
195195
//WWASSERT(position <= BufferSize * 8);
196196
WWASSERT(position <= MAX_BUFFER_SIZE * 8);
@@ -219,7 +219,7 @@ void cBitPacker::Increment_Bit_Position(int num_bits)
219219
}
220220
221221
//-----------------------------------------------------------------------------
222-
UINT cBitPacker::Get_Compressed_Size_Bytes() const
222+
uint32_t cBitPacker::Get_Compressed_Size_Bytes() const
223223
{
224224
return (int) ceil(BitWritePosition / 8.0f);
225225
}

Code/wwbitpack/BitPacker.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929

3030

3131
#include "always.h"
32-
#include "bittype.h"
32+
#include <cstdint>
3333

34-
static const int MAX_BITS = 32;
34+
static constexpr int MAX_BITS = 8 * sizeof(uint32_t);
3535

3636
// 1400 is too big. Minimum MTU allowable on the internet is 576. IP Header is 20 bytes. UDP header is 8 bytes
3737
// So our max packet size is 576 - 28 = 548
@@ -41,21 +41,21 @@ static const int MAX_BUFFER_SIZE = 548;
4141
class cBitPacker
4242
{
4343
public:
44-
//cBitPacker(UINT buffer_size);
44+
//cBitPacker(uint32_t buffer_size);
4545
cBitPacker();
4646
virtual ~cBitPacker();
4747

4848
char * Get_Data() const {return (char *) Buffer;}
49-
//UINT Get_Buffer_Size() const {return BufferSize;}
50-
UINT Get_Buffer_Size() const {return MAX_BUFFER_SIZE;}
49+
//uint32_t Get_Buffer_Size() const {return BufferSize;}
50+
uint32_t Get_Buffer_Size() const {return MAX_BUFFER_SIZE;}
5151
void Flush() {BitReadPosition = BitWritePosition;}
5252
bool Is_Flushed() const {return (BitReadPosition == BitWritePosition);}
5353

54-
void Add_Bits(ULONG value, UINT num_bits);
55-
void Get_Bits(ULONG & value, UINT num_bits);
54+
void Add_Bits(uint32_t value, uint32_t num_bits);
55+
void Get_Bits(uint32_t & value, uint32_t num_bits);
5656

57-
void Set_Bit_Write_Position(UINT position);
58-
UINT Get_Bit_Write_Position() const {return BitWritePosition;}
57+
void Set_Bit_Write_Position(uint32_t position);
58+
uint32_t Get_Bit_Write_Position() const {return BitWritePosition;}
5959

6060
protected:
6161
cBitPacker& operator=(const cBitPacker& rhs);
@@ -64,11 +64,11 @@ class cBitPacker
6464

6565
cBitPacker(const cBitPacker& source); // Disallow copy constructor
6666

67-
//BYTE * Buffer;
68-
//const UINT BufferSize;
69-
BYTE Buffer[MAX_BUFFER_SIZE];
70-
UINT BitWritePosition;
71-
UINT BitReadPosition;
67+
//uint8_t * Buffer;
68+
//const uint32_t BufferSize;
69+
uint8_t Buffer[MAX_BUFFER_SIZE];
70+
uint32_t BitWritePosition;
71+
uint32_t BitReadPosition;
7272
};
7373

7474
#endif // BITPACKER_H
@@ -78,7 +78,7 @@ class cBitPacker
7878

7979
/*
8080
void Reset() {BitWritePosition = 0;}
81-
UINT Get_Compressed_Size_Bytes() const;
81+
uint32_t Get_Compressed_Size_Bytes() const;
8282
8383
void Flush() {NumBits = 0;}
8484
bool Is_Flushed() const {return (NumBits < 8);}
@@ -92,4 +92,4 @@ class cBitPacker
9292
//inline void Advance_Bit_Position();
9393
9494
//int NumBits;
95-
*/
95+
*/

Code/wwbitpack/bitstream.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ void BitStreamClass::Add(bool value)
7676
Add_Bits(value, BIT_DEPTH(bool));
7777
}
7878

79-
UncompressedSizeBytes += BYTE_DEPTH(bool);
79+
UncompressedSizeBytes += BYTE_DEPTH(bool);
8080
}
8181

8282
//-----------------------------------------------------------------------------
8383
bool BitStreamClass::Get(bool & value)
8484
{
85-
ULONG u_value;
85+
uint32_t u_value;
8686
if (cEncoderList::Is_Compression_Enabled()) {
8787
Get_Bits(u_value, 1);
8888
} else {
@@ -94,7 +94,7 @@ bool BitStreamClass::Get(bool & value)
9494
}
9595

9696
//-----------------------------------------------------------------------------
97-
void BitStreamClass::Add_Raw_Data(LPCSTR data, USHORT data_size)
97+
void BitStreamClass::Add_Raw_Data(const char * data, uint16_t data_size)
9898
{
9999
WWASSERT(data != NULL);
100100
WWASSERT(data_size >= 0);
@@ -105,7 +105,7 @@ void BitStreamClass::Add_Raw_Data(LPCSTR data, USHORT data_size)
105105
}
106106

107107
//-----------------------------------------------------------------------------
108-
void BitStreamClass::Get_Raw_Data(char * buffer, USHORT buffer_size, USHORT data_size)
108+
void BitStreamClass::Get_Raw_Data(char * buffer, uint16_t buffer_size, uint16_t data_size)
109109
{
110110
WWASSERT(buffer != NULL);
111111
WWASSERT(data_size >= 0);
@@ -117,14 +117,14 @@ void BitStreamClass::Get_Raw_Data(char * buffer, USHORT buffer_size, USHORT data
117117
}
118118

119119
//-----------------------------------------------------------------------------
120-
void BitStreamClass::Add_Terminated_String(LPCSTR string, bool permit_empty)
120+
void BitStreamClass::Add_Terminated_String(const char * string, bool permit_empty)
121121
{
122122
WWASSERT(string != NULL);
123123

124124
//
125125
// The terminating null is not transmitted.
126126
//
127-
USHORT len = (USHORT) strlen(string);
127+
uint16_t len = (uint16_t) strlen(string);
128128
if (!permit_empty) {
129129
WWASSERT(len > 0);
130130
}
@@ -136,12 +136,12 @@ void BitStreamClass::Add_Terminated_String(LPCSTR string, bool permit_empty)
136136
}
137137

138138
//-----------------------------------------------------------------------------
139-
void BitStreamClass::Get_Terminated_String(char * buffer, USHORT buffer_size, bool permit_empty)
139+
void BitStreamClass::Get_Terminated_String(char * buffer, uint16_t buffer_size, bool permit_empty)
140140
{
141141
WWASSERT(buffer != NULL);
142142
WWASSERT(buffer_size > 0);
143143

144-
USHORT len;
144+
uint16_t len;
145145
Get(len);
146146
WWASSERT(len < buffer_size);
147147
if (!permit_empty) {
@@ -174,7 +174,7 @@ void BitStreamClass::Add_Wide_Terminated_String(const wchar_t *string, bool perm
174174
//
175175
// The terminating null is not transmitted.
176176
//
177-
USHORT len = (USHORT)wcslen (string);
177+
uint16_t len = (uint16_t)wcslen (string);
178178
if (!permit_empty) {
179179
WWASSERT(len > 0 && "Empty string not permitted");
180180
}
@@ -186,12 +186,12 @@ void BitStreamClass::Add_Wide_Terminated_String(const wchar_t *string, bool perm
186186
}
187187

188188
//-----------------------------------------------------------------------------
189-
void BitStreamClass::Get_Wide_Terminated_String(wchar_t *buffer, USHORT buffer_len, bool permit_empty)
189+
void BitStreamClass::Get_Wide_Terminated_String(wchar_t *buffer, uint16_t buffer_len, bool permit_empty)
190190
{
191191
WWASSERT(buffer != NULL);
192192
WWASSERT(buffer_len > 0);
193193

194-
USHORT len;
194+
uint16_t len;
195195
Get(len);
196196
WWASSERT(len < buffer_len && "String length exceeds provided buffer");
197197
if (!permit_empty) {
@@ -216,16 +216,16 @@ void BitStreamClass::Get_Wide_Terminated_String(wchar_t *buffer, USHORT buffer_l
216216

217217

218218
//-----------------------------------------------------------------------------
219-
UINT BitStreamClass::Get_Compressed_Size_Bytes() const
219+
uint32_t BitStreamClass::Get_Compressed_Size_Bytes() const
220220
{
221-
return (UINT) ceil(Get_Bit_Write_Position() / 8.0f);
221+
return (uint32_t) ceil(Get_Bit_Write_Position() / 8.0f);
222222
}
223223

224224
//-----------------------------------------------------------------------------
225-
UINT BitStreamClass::Get_Compression_Pc() const
225+
uint32_t BitStreamClass::Get_Compression_Pc() const
226226
{
227-
UINT c_size = Get_Compressed_Size_Bytes();
228-
UINT u_size = Get_Uncompressed_Size_Bytes();
227+
uint32_t c_size = Get_Compressed_Size_Bytes();
228+
uint32_t u_size = Get_Uncompressed_Size_Bytes();
229229

230230
if (cEncoderList::Is_Compression_Enabled()) {
231231
WWASSERT(c_size <= u_size);
@@ -235,7 +235,7 @@ UINT BitStreamClass::Get_Compression_Pc() const
235235

236236
WWASSERT(u_size > 0);
237237

238-
UINT compression_pc = (UINT) cMathUtil::Round(100 * c_size / (float) u_size);
238+
uint32_t compression_pc = (uint32_t) cMathUtil::Round(100 * c_size / (float) u_size);
239239
WWASSERT(compression_pc >= 0 && compression_pc <= 100);
240240

241241
return compression_pc;

0 commit comments

Comments
 (0)