mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
uint16 -> uint16_t
This commit is contained in:
parent
66385a2ff6
commit
ad8f49c289
@ -135,11 +135,11 @@ static void WaterAnimation_Tick(UInt32* ptr, int size) {
|
|||||||
*-------------------------------------------------------Animations--------------------------------------------------------*
|
*-------------------------------------------------------Animations--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
struct AnimationData {
|
struct AnimationData {
|
||||||
TextureLoc TexLoc; /* Tile (not pixel) coordinates in terrain.png */
|
TextureLoc TexLoc; /* Tile (not pixel) coordinates in terrain.png */
|
||||||
UInt16 FrameX, FrameY; /* Top left pixel coordinates of start frame in animatons.png */
|
uint16_t FrameX, FrameY; /* Top left pixel coordinates of start frame in animatons.png */
|
||||||
UInt16 FrameSize; /* Size of each frame in pixel coordinates */
|
uint16_t FrameSize; /* Size of each frame in pixel coordinates */
|
||||||
UInt16 State; /* Current animation frame index */
|
uint16_t State; /* Current animation frame index */
|
||||||
UInt16 StatesCount; /* Total number of animation frames */
|
uint16_t StatesCount; /* Total number of animation frames */
|
||||||
Int16 Tick, TickDelay;
|
Int16 Tick, TickDelay;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ cleanup:
|
|||||||
#define MUSIC_MAX_FILES 512
|
#define MUSIC_MAX_FILES 512
|
||||||
static void Music_RunLoop(void) {
|
static void Music_RunLoop(void) {
|
||||||
int i, count = 0;
|
int i, count = 0;
|
||||||
UInt16 musicFiles[MUSIC_MAX_FILES];
|
uint16_t musicFiles[MUSIC_MAX_FILES];
|
||||||
String ogg = String_FromConst(".ogg");
|
String ogg = String_FromConst(".ogg");
|
||||||
|
|
||||||
for (i = 0; i < files.Count && count < MUSIC_MAX_FILES; i++) {
|
for (i = 0; i < files.Count && count < MUSIC_MAX_FILES; i++) {
|
||||||
|
@ -12,28 +12,28 @@ struct ChunkPartInfo {
|
|||||||
#ifdef CC_BUILD_GL11
|
#ifdef CC_BUILD_GL11
|
||||||
GfxResourceID Vb;
|
GfxResourceID Vb;
|
||||||
#endif
|
#endif
|
||||||
Int32 Offset; /* -1 if no vertices at all */
|
int Offset; /* -1 if no vertices at all */
|
||||||
Int32 SpriteCount; /* Sprite vertices count */
|
int SpriteCount; /* Sprite vertices count */
|
||||||
UInt16 Counts[FACE_COUNT]; /* Counts per face */
|
uint16_t Counts[FACE_COUNT]; /* Counts per face */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Describes data necessary for rendering a chunk. */
|
/* Describes data necessary for rendering a chunk. */
|
||||||
struct ChunkInfo {
|
struct ChunkInfo {
|
||||||
UInt16 CentreX, CentreY, CentreZ; /* Centre coordinates of the chunk */
|
uint16_t CentreX, CentreY, CentreZ; /* Centre coordinates of the chunk */
|
||||||
|
|
||||||
UInt8 Visible : 1; /* Whether chunk is visibile to the player */
|
uint8_t Visible : 1; /* Whether chunk is visibile to the player */
|
||||||
UInt8 Empty : 1; /* Whether the chunk is empty of data */
|
uint8_t Empty : 1; /* Whether the chunk is empty of data */
|
||||||
UInt8 PendingDelete : 1; /* Whether chunk is pending deletion*/
|
uint8_t PendingDelete : 1; /* Whether chunk is pending deletion*/
|
||||||
UInt8 AllAir : 1; /* Whether chunk is completely air */
|
uint8_t AllAir : 1; /* Whether chunk is completely air */
|
||||||
UInt8 : 0; /* pad to next byte*/
|
uint8_t : 0; /* pad to next byte*/
|
||||||
|
|
||||||
UInt8 DrawXMin : 1;
|
uint8_t DrawXMin : 1;
|
||||||
UInt8 DrawXMax : 1;
|
uint8_t DrawXMax : 1;
|
||||||
UInt8 DrawZMin : 1;
|
uint8_t DrawZMin : 1;
|
||||||
UInt8 DrawZMax : 1;
|
uint8_t DrawZMax : 1;
|
||||||
UInt8 DrawYMin : 1;
|
uint8_t DrawYMin : 1;
|
||||||
UInt8 DrawYMax : 1;
|
uint8_t DrawYMax : 1;
|
||||||
UInt8 : 0; /* pad to next byte */
|
uint8_t : 0; /* pad to next byte */
|
||||||
#ifdef OCCLUSION
|
#ifdef OCCLUSION
|
||||||
public bool Visited = false, Occluded = false;
|
public bool Visited = false, Occluded = false;
|
||||||
public byte OcclusionFlags, OccludedFlags, DistanceFlags;
|
public byte OcclusionFlags, OccludedFlags, DistanceFlags;
|
||||||
|
@ -49,7 +49,7 @@ enum FONT_STYLE { FONT_STYLE_NORMAL, FONT_STYLE_BOLD, FONT_STYLE_UNDERLINE };
|
|||||||
#define UInt8_MaxValue ((UInt8)255)
|
#define UInt8_MaxValue ((UInt8)255)
|
||||||
#define Int16_MinValue ((Int16)-32768)
|
#define Int16_MinValue ((Int16)-32768)
|
||||||
#define Int16_MaxValue ((Int16)32767)
|
#define Int16_MaxValue ((Int16)32767)
|
||||||
#define UInt16_MaxValue ((UInt16)65535)
|
#define UInt16_MaxValue ((uint16_t)65535)
|
||||||
#define Int32_MinValue ((Int32)-2147483647L - (Int32)1L)
|
#define Int32_MinValue ((Int32)-2147483647L - (Int32)1L)
|
||||||
#define Int32_MaxValue ((Int32)2147483647L)
|
#define Int32_MaxValue ((Int32)2147483647L)
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#if _MSC_VER
|
#if _MSC_VER
|
||||||
typedef unsigned __int8 UInt8;
|
typedef unsigned __int8 UInt8;
|
||||||
typedef unsigned __int16 UInt16;
|
|
||||||
typedef unsigned __int32 UInt32;
|
typedef unsigned __int32 UInt32;
|
||||||
typedef unsigned __int64 UInt64;
|
typedef unsigned __int64 UInt64;
|
||||||
typedef unsigned __int8 uint8_t;
|
typedef unsigned __int8 uint8_t;
|
||||||
@ -30,7 +29,6 @@ typedef signed __int64 int64_t;
|
|||||||
#elif __GNUC__
|
#elif __GNUC__
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
typedef uint8_t UInt8;
|
typedef uint8_t UInt8;
|
||||||
typedef uint16_t UInt16;
|
|
||||||
typedef uint32_t UInt32;
|
typedef uint32_t UInt32;
|
||||||
typedef uint64_t UInt64;
|
typedef uint64_t UInt64;
|
||||||
|
|
||||||
@ -42,6 +40,7 @@ typedef int64_t Int64;
|
|||||||
#error "I don't recognise this compiler. You'll need to add required definitions in Core.h!"
|
#error "I don't recognise this compiler. You'll need to add required definitions in Core.h!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef uint16_t Codepoint;
|
||||||
typedef UInt8 bool;
|
typedef UInt8 bool;
|
||||||
#define true 1
|
#define true 1
|
||||||
#define false 0
|
#define false 0
|
||||||
@ -70,7 +69,7 @@ typedef UInt64 TimeMS;
|
|||||||
typedef struct Rect2D_ { int X, Y, Width, Height; } Rect2D;
|
typedef struct Rect2D_ { int X, Y, Width, Height; } Rect2D;
|
||||||
typedef struct Point2D_ { int X, Y; } Point2D;
|
typedef struct Point2D_ { int X, Y; } Point2D;
|
||||||
typedef struct Size2D_ { int Width, Height; } Size2D;
|
typedef struct Size2D_ { int Width, Height; } Size2D;
|
||||||
typedef struct FontDesc_ { void* Handle; UInt16 Size, Style; } FontDesc;
|
typedef struct FontDesc_ { void* Handle; uint16_t Size, Style; } FontDesc;
|
||||||
typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec;
|
typedef struct TextureRec_ { float U1, V1, U2, V2; } TextureRec;
|
||||||
typedef struct Bitmap_ { UInt8* Scan0; int Width, Height; } Bitmap;
|
typedef struct Bitmap_ { UInt8* Scan0; int Width, Height; } Bitmap;
|
||||||
|
|
||||||
|
@ -472,7 +472,7 @@ static void D3D9_SetIbData(IDirect3DIndexBuffer9* buffer, void* data, Int32 size
|
|||||||
}
|
}
|
||||||
|
|
||||||
GfxResourceID Gfx_CreateIb(void* indices, int indicesCount) {
|
GfxResourceID Gfx_CreateIb(void* indices, int indicesCount) {
|
||||||
int size = indicesCount * sizeof(UInt16);
|
int size = indicesCount * 2;
|
||||||
IDirect3DIndexBuffer9* ibuffer;
|
IDirect3DIndexBuffer9* ibuffer;
|
||||||
ReturnCode res = IDirect3DDevice9_CreateIndexBuffer(device, size, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ibuffer, NULL);
|
ReturnCode res = IDirect3DDevice9_CreateIndexBuffer(device, size, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &ibuffer, NULL);
|
||||||
if (res) ErrorHandler_Fail2(res, "D3D9_CreateIb");
|
if (res) ErrorHandler_Fail2(res, "D3D9_CreateIb");
|
||||||
|
@ -169,7 +169,7 @@ static UInt32 Huffman_ReverseBits(UInt32 n, UInt8 bits) {
|
|||||||
return n >> (16 - bits);
|
return n >> (16 - bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Huffman_Build(struct HuffmanTable* table, UInt8* bitLens, Int32 count) {
|
static void Huffman_Build(struct HuffmanTable* table, UInt8* bitLens, int count) {
|
||||||
int i;
|
int i;
|
||||||
table->FirstCodewords[0] = 0;
|
table->FirstCodewords[0] = 0;
|
||||||
table->FirstOffsets[0] = 0;
|
table->FirstOffsets[0] = 0;
|
||||||
@ -329,13 +329,13 @@ UInt8 fixed_dists[INFLATE_MAX_DISTS] = {
|
|||||||
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
|
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
|
||||||
};
|
};
|
||||||
|
|
||||||
UInt16 len_base[31] = { 3,4,5,6,7,8,9,10,11,13,
|
uint16_t len_base[31] = { 3,4,5,6,7,8,9,10,11,13,
|
||||||
15,17,19,23,27,31,35,43,51,59,
|
15,17,19,23,27,31,35,43,51,59,
|
||||||
67,83,99,115,131,163,195,227,258,0,0 };
|
67,83,99,115,131,163,195,227,258,0,0 };
|
||||||
UInt8 len_bits[31] = { 0,0,0,0,0,0,0,0,1,1,
|
UInt8 len_bits[31] = { 0,0,0,0,0,0,0,0,1,1,
|
||||||
1,1,2,2,2,2,3,3,3,3,
|
1,1,2,2,2,2,3,3,3,3,
|
||||||
4,4,4,4,5,5,5,5,0,0,0 };
|
4,4,4,4,5,5,5,5,0,0,0 };
|
||||||
UInt16 dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,
|
uint16_t dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,
|
||||||
33,49,65,97,129,193,257,385,513,769,
|
33,49,65,97,129,193,257,385,513,769,
|
||||||
1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0 };
|
1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0 };
|
||||||
UInt8 dist_bits[32] = { 0,0,0,0,1,1,2,2,3,3,
|
UInt8 dist_bits[32] = { 0,0,0,0,1,1,2,2,3,3,
|
||||||
@ -699,8 +699,8 @@ void Inflate_MakeStream(struct Stream* stream, struct InflateState* state, struc
|
|||||||
#define Deflate_FlushBits(state) while (state->NumBits >= 8) { Deflate_WriteByte(state); }
|
#define Deflate_FlushBits(state) while (state->NumBits >= 8) { Deflate_WriteByte(state); }
|
||||||
|
|
||||||
#define DEFLATE_MAX_MATCH_LEN 258
|
#define DEFLATE_MAX_MATCH_LEN 258
|
||||||
static Int32 Deflate_MatchLen(UInt8* a, UInt8* b, Int32 maxLen) {
|
static int Deflate_MatchLen(UInt8* a, UInt8* b, int maxLen) {
|
||||||
Int32 i = 0;
|
int i = 0;
|
||||||
while (i < maxLen && *a == *b) { i++; a++; b++; }
|
while (i < maxLen && *a == *b) { i++; a++; b++; }
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -709,14 +709,14 @@ static UInt32 Deflate_Hash(UInt8* src) {
|
|||||||
return (UInt32)((src[0] << 8) ^ (src[1] << 4) ^ (src[2])) & DEFLATE_HASH_MASK;
|
return (UInt32)((src[0] << 8) ^ (src[1] << 4) ^ (src[2])) & DEFLATE_HASH_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Deflate_Lit(struct DeflateState* state, Int32 lit) {
|
static void Deflate_Lit(struct DeflateState* state, int lit) {
|
||||||
if (lit <= 143) { Deflate_PushHuff(state, lit + 48, 8); }
|
if (lit <= 143) { Deflate_PushHuff(state, lit + 48, 8); }
|
||||||
else { Deflate_PushHuff(state, lit + 256, 9); }
|
else { Deflate_PushHuff(state, lit + 256, 9); }
|
||||||
Deflate_FlushBits(state);
|
Deflate_FlushBits(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Deflate_LenDist(struct DeflateState* state, Int32 len, Int32 dist) {
|
static void Deflate_LenDist(struct DeflateState* state, int len, int dist) {
|
||||||
Int32 j;
|
int j;
|
||||||
len_base[29] = UInt16_MaxValue;
|
len_base[29] = UInt16_MaxValue;
|
||||||
dist_base[30] = UInt16_MaxValue;
|
dist_base[30] = UInt16_MaxValue;
|
||||||
/* TODO: Remove this hack out into Deflate_FlushBlock */
|
/* TODO: Remove this hack out into Deflate_FlushBlock */
|
||||||
@ -755,21 +755,21 @@ static ReturnCode Deflate_FlushBlock(struct DeflateState* state, Int32 len) {
|
|||||||
|
|
||||||
while (len > 3) {
|
while (len > 3) {
|
||||||
UInt32 hash = Deflate_Hash(cur);
|
UInt32 hash = Deflate_Hash(cur);
|
||||||
Int32 maxLen = min(len, DEFLATE_MAX_MATCH_LEN);
|
int maxLen = min(len, DEFLATE_MAX_MATCH_LEN);
|
||||||
|
|
||||||
Int32 bestLen = 3 - 1; /* Match must be at least 3 bytes */
|
int bestLen = 3 - 1; /* Match must be at least 3 bytes */
|
||||||
Int32 bestPos = 0;
|
int bestPos = 0;
|
||||||
|
|
||||||
Int32 pos = state->Head[hash];
|
int pos = state->Head[hash];
|
||||||
while (pos != 0) { /* TODO: Need to limit chain length here */
|
while (pos != 0) { /* TODO: Need to limit chain length here */
|
||||||
Int32 matchLen = Deflate_MatchLen(&src[pos], cur, maxLen);
|
int matchLen = Deflate_MatchLen(&src[pos], cur, maxLen);
|
||||||
if (matchLen > bestLen) { bestLen = matchLen; bestPos = pos; }
|
if (matchLen > bestLen) { bestLen = matchLen; bestPos = pos; }
|
||||||
pos = state->Prev[pos];
|
pos = state->Prev[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert this entry into the hash chain */
|
/* Insert this entry into the hash chain */
|
||||||
pos = (Int32)(cur - src);
|
pos = (int)(cur - src);
|
||||||
UInt16 oldHead = state->Head[hash];
|
uint16_t oldHead = state->Head[hash];
|
||||||
state->Head[hash] = pos;
|
state->Head[hash] = pos;
|
||||||
state->Prev[pos] = oldHead;
|
state->Prev[pos] = oldHead;
|
||||||
|
|
||||||
@ -777,11 +777,11 @@ static ReturnCode Deflate_FlushBlock(struct DeflateState* state, Int32 len) {
|
|||||||
/* If that's longer than the longest match at current byte, throwaway this match */
|
/* If that's longer than the longest match at current byte, throwaway this match */
|
||||||
if (bestPos && len > 2) {
|
if (bestPos && len > 2) {
|
||||||
UInt32 nextHash = Deflate_Hash(cur + 1);
|
UInt32 nextHash = Deflate_Hash(cur + 1);
|
||||||
Int32 nextPos = state->Head[nextHash];
|
int nextPos = state->Head[nextHash];
|
||||||
maxLen = min(len - 1, DEFLATE_MAX_MATCH_LEN);
|
maxLen = min(len - 1, DEFLATE_MAX_MATCH_LEN);
|
||||||
|
|
||||||
while (nextPos != 0) { /* TODO: Need to limit chain length here */
|
while (nextPos != 0) { /* TODO: Need to limit chain length here */
|
||||||
Int32 matchLen = Deflate_MatchLen(&src[nextPos], cur + 1, maxLen);
|
int matchLen = Deflate_MatchLen(&src[nextPos], cur + 1, maxLen);
|
||||||
if (matchLen > bestLen) { bestPos = 0; break; }
|
if (matchLen > bestLen) { bestPos = 0; break; }
|
||||||
nextPos = state->Prev[nextPos];
|
nextPos = state->Prev[nextPos];
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,11 @@ ReturnCode ZLibHeader_Read(struct Stream* s, struct ZLibHeader* header);
|
|||||||
#define INFLATE_WINDOW_MASK 0x7FFFUL
|
#define INFLATE_WINDOW_MASK 0x7FFFUL
|
||||||
|
|
||||||
struct HuffmanTable {
|
struct HuffmanTable {
|
||||||
Int16 Fast[1 << INFLATE_FAST_BITS]; /* Fast lookup table for huffman codes */
|
int16_t Fast[1 << INFLATE_FAST_BITS]; /* Fast lookup table for huffman codes */
|
||||||
UInt16 FirstCodewords[INFLATE_MAX_BITS]; /* Starting codeword for each bit length */
|
uint16_t FirstCodewords[INFLATE_MAX_BITS]; /* Starting codeword for each bit length */
|
||||||
UInt16 EndCodewords[INFLATE_MAX_BITS]; /* (Last codeword + 1) for each bit length. 0 is ignored. */
|
uint16_t EndCodewords[INFLATE_MAX_BITS]; /* (Last codeword + 1) for each bit length. 0 is ignored. */
|
||||||
UInt16 FirstOffsets[INFLATE_MAX_BITS]; /* Base offset into Values for codewords of each bit length. */
|
uint16_t FirstOffsets[INFLATE_MAX_BITS]; /* Base offset into Values for codewords of each bit length. */
|
||||||
UInt16 Values[INFLATE_MAX_LITS]; /* Values/Symbols list */
|
uint16_t Values[INFLATE_MAX_LITS]; /* Values/Symbols list */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InflateState {
|
struct InflateState {
|
||||||
@ -85,8 +85,8 @@ struct DeflateState {
|
|||||||
|
|
||||||
UInt8 Input[DEFLATE_BUFFER_SIZE];
|
UInt8 Input[DEFLATE_BUFFER_SIZE];
|
||||||
UInt8 Output[DEFLATE_OUT_SIZE];
|
UInt8 Output[DEFLATE_OUT_SIZE];
|
||||||
UInt16 Head[DEFLATE_HASH_SIZE];
|
uint16_t Head[DEFLATE_HASH_SIZE];
|
||||||
UInt16 Prev[DEFLATE_BUFFER_SIZE];
|
uint16_t Prev[DEFLATE_BUFFER_SIZE];
|
||||||
bool WroteHeader;
|
bool WroteHeader;
|
||||||
};
|
};
|
||||||
NOINLINE_ void Deflate_MakeStream(struct Stream* stream, struct DeflateState* state, struct Stream* underlying);
|
NOINLINE_ void Deflate_MakeStream(struct Stream* stream, struct DeflateState* state, struct Stream* underlying);
|
||||||
|
@ -20,7 +20,7 @@ void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, FontDesc* font, bool useS
|
|||||||
args->UseShadow = useShadow;
|
args->UseShadow = useShadow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drawer2D_MakeFont(FontDesc* desc, UInt16 size, UInt16 style) {
|
void Drawer2D_MakeFont(FontDesc* desc, uint16_t size, uint16_t style) {
|
||||||
if (Drawer2D_BitmappedText) {
|
if (Drawer2D_BitmappedText) {
|
||||||
desc->Handle = NULL;
|
desc->Handle = NULL;
|
||||||
desc->Size = size;
|
desc->Size = size;
|
||||||
@ -196,7 +196,7 @@ void Drawer2D_ReducePadding_Tex(struct Texture* tex, int point, int scale) {
|
|||||||
int padding = (tex->Height - point) / scale;
|
int padding = (tex->Height - point) / scale;
|
||||||
float vAdj = (float)padding / Math_NextPowOf2(tex->Height);
|
float vAdj = (float)padding / Math_NextPowOf2(tex->Height);
|
||||||
tex->V1 += vAdj; tex->V2 -= vAdj;
|
tex->V1 += vAdj; tex->V2 -= vAdj;
|
||||||
tex->Height -= (UInt16)(padding * 2);
|
tex->Height -= (uint16_t)(padding * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drawer2D_ReducePadding_Height(int* height, int point, int scale) {
|
void Drawer2D_ReducePadding_Height(int* height, int point, int scale) {
|
||||||
@ -245,9 +245,9 @@ static void Drawer2D_DrawCore(Bitmap* bmp, struct DrawTextArgs* args, int x, int
|
|||||||
String text = args->Text;
|
String text = args->Text;
|
||||||
int point = args->Font.Size, count = 0, i;
|
int point = args->Font.Size, count = 0, i;
|
||||||
|
|
||||||
UInt8 coords[256];
|
uint8_t coords[256];
|
||||||
PackedCol cols[256];
|
PackedCol cols[256];
|
||||||
UInt16 dstWidths[256];
|
uint16_t dstWidths[256];
|
||||||
|
|
||||||
for (i = 0; i < text.length; i++) {
|
for (i = 0; i < text.length; i++) {
|
||||||
char c = text.buffer[i];
|
char c = text.buffer[i];
|
||||||
|
@ -11,7 +11,7 @@ struct Texture;
|
|||||||
|
|
||||||
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const String* text, FontDesc* font, bool useShadow);
|
void DrawTextArgs_Make(struct DrawTextArgs* args, STRING_REF const String* text, FontDesc* font, bool useShadow);
|
||||||
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, FontDesc* font, bool useShadow);
|
void DrawTextArgs_MakeEmpty(struct DrawTextArgs* args, FontDesc* font, bool useShadow);
|
||||||
NOINLINE_ void Drawer2D_MakeFont(FontDesc* desc, UInt16 size, UInt16 style);
|
NOINLINE_ void Drawer2D_MakeFont(FontDesc* desc, uint16_t size, uint16_t style);
|
||||||
|
|
||||||
/* Whether chat text should be drawn and measuring using the currently bitmapped font,
|
/* Whether chat text should be drawn and measuring using the currently bitmapped font,
|
||||||
false uses the font supplied as the DrawTextArgs argument supplied to the function. */
|
false uses the font supplied as the DrawTextArgs argument supplied to the function. */
|
||||||
|
@ -115,9 +115,9 @@ void Entities_DrawShadows(void);
|
|||||||
|
|
||||||
#define TABLIST_MAX_NAMES 256
|
#define TABLIST_MAX_NAMES 256
|
||||||
StringsBuffer TabList_Buffer;
|
StringsBuffer TabList_Buffer;
|
||||||
UInt16 TabList_PlayerNames[TABLIST_MAX_NAMES];
|
uint16_t TabList_PlayerNames[TABLIST_MAX_NAMES];
|
||||||
UInt16 TabList_ListNames[TABLIST_MAX_NAMES];
|
uint16_t TabList_ListNames[TABLIST_MAX_NAMES];
|
||||||
UInt16 TabList_GroupNames[TABLIST_MAX_NAMES];
|
uint16_t TabList_GroupNames[TABLIST_MAX_NAMES];
|
||||||
UInt8 TabList_GroupRanks[TABLIST_MAX_NAMES];
|
UInt8 TabList_GroupRanks[TABLIST_MAX_NAMES];
|
||||||
bool TabList_Valid(EntityID id);
|
bool TabList_Valid(EntityID id);
|
||||||
bool TabList_Remove(EntityID id);
|
bool TabList_Remove(EntityID id);
|
||||||
|
@ -155,7 +155,7 @@ static ReturnCode Fcm_ReadString(struct Stream* stream) {
|
|||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
if ((res = Stream_Read(stream, data, sizeof(data)))) return res;
|
if ((res = Stream_Read(stream, data, sizeof(data)))) return res;
|
||||||
|
|
||||||
UInt16 len = Stream_GetU16_LE(data);
|
int len = Stream_GetU16_LE(data);
|
||||||
return Stream_Skip(stream, len);
|
return Stream_Skip(stream, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ static ReturnCode Nbt_ReadString(struct Stream* stream, char* strBuffer, UInt32*
|
|||||||
char nameBuffer[NBT_SMALL_SIZE * 4];
|
char nameBuffer[NBT_SMALL_SIZE * 4];
|
||||||
if ((res = Stream_Read(stream, nameBuffer, 2))) return res;
|
if ((res = Stream_Read(stream, nameBuffer, 2))) return res;
|
||||||
|
|
||||||
UInt16 nameLen = Stream_GetU16_BE(nameBuffer);
|
int nameLen = Stream_GetU16_BE(nameBuffer);
|
||||||
if (nameLen > NBT_SMALL_SIZE * 4) return CW_ERR_STRING_LEN;
|
if (nameLen > NBT_SMALL_SIZE * 4) return CW_ERR_STRING_LEN;
|
||||||
if ((res = Stream_Read(stream, nameBuffer, nameLen))) return res;
|
if ((res = Stream_Read(stream, nameBuffer, nameLen))) return res;
|
||||||
|
|
||||||
@ -359,9 +359,9 @@ static bool IsTag(struct NbtTag* tag, const char* tagName) {
|
|||||||
*--------------------------------------------------ClassicWorld format----------------------------------------------------*
|
*--------------------------------------------------ClassicWorld format----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static bool Cw_Callback_1(struct NbtTag* tag) {
|
static bool Cw_Callback_1(struct NbtTag* tag) {
|
||||||
if (IsTag(tag, "X")) { World_Width = (UInt16)NbtTag_I16(tag); return true; }
|
if (IsTag(tag, "X")) { World_Width = (uint16_t)NbtTag_I16(tag); return true; }
|
||||||
if (IsTag(tag, "Y")) { World_Height = (UInt16)NbtTag_I16(tag); return true; }
|
if (IsTag(tag, "Y")) { World_Height = (uint16_t)NbtTag_I16(tag); return true; }
|
||||||
if (IsTag(tag, "Z")) { World_Length = (UInt16)NbtTag_I16(tag); return true; }
|
if (IsTag(tag, "Z")) { World_Length = (uint16_t)NbtTag_I16(tag); return true; }
|
||||||
|
|
||||||
if (IsTag(tag, "UUID")) {
|
if (IsTag(tag, "UUID")) {
|
||||||
if (tag->DataSize != sizeof(World_Uuid)) ErrorHandler_Fail("Map UUID must be 16 bytes");
|
if (tag->DataSize != sizeof(World_Uuid)) ErrorHandler_Fail("Map UUID must be 16 bytes");
|
||||||
@ -608,14 +608,14 @@ struct JFieldDesc {
|
|||||||
|
|
||||||
struct JClassDesc {
|
struct JClassDesc {
|
||||||
char ClassName[JNAME_SIZE];
|
char ClassName[JNAME_SIZE];
|
||||||
UInt16 FieldsCount;
|
uint16_t FieldsCount;
|
||||||
struct JFieldDesc Fields[22];
|
struct JFieldDesc Fields[22];
|
||||||
};
|
};
|
||||||
|
|
||||||
static ReturnCode Dat_ReadString(struct Stream* stream, char* buffer) {
|
static ReturnCode Dat_ReadString(struct Stream* stream, char* buffer) {
|
||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
if ((res = Stream_Read(stream, buffer, 2))) return res;
|
if ((res = Stream_Read(stream, buffer, 2))) return res;
|
||||||
UInt16 len = Stream_GetU16_BE(buffer);
|
int len = Stream_GetU16_BE(buffer);
|
||||||
|
|
||||||
Mem_Set(buffer, 0, JNAME_SIZE);
|
Mem_Set(buffer, 0, JNAME_SIZE);
|
||||||
if (len > JNAME_SIZE) return DAT_ERR_JSTRING_LEN;
|
if (len > JNAME_SIZE) return DAT_ERR_JSTRING_LEN;
|
||||||
@ -793,13 +793,13 @@ ReturnCode Dat_Load(struct Stream* stream) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
#define CW_META_VERSION 'E','x','t','e','n','s','i','o','n','V','e','r','s','i','o','n'
|
#define CW_META_VERSION 'E','x','t','e','n','s','i','o','n','V','e','r','s','i','o','n'
|
||||||
#define CW_META_RGB NBT_I16,0,1,'R',0,0, NBT_I16,0,1,'G',0,0, NBT_I16,0,1,'B',0,0,
|
#define CW_META_RGB NBT_I16,0,1,'R',0,0, NBT_I16,0,1,'G',0,0, NBT_I16,0,1,'B',0,0,
|
||||||
static Int32 Cw_WriteEndString(UInt8* data, const String* text) {
|
static int Cw_WriteEndString(UInt8* data, const String* text) {
|
||||||
Int32 i, len = 0;
|
int i, len = 0;
|
||||||
UInt8* cur = data + 2;
|
UInt8* cur = data + 2;
|
||||||
|
|
||||||
for (i = 0; i < text->length; i++) {
|
for (i = 0; i < text->length; i++) {
|
||||||
UInt16 codepoint = Convert_CP437ToUnicode(text->buffer[i]);
|
Codepoint cp = Convert_CP437ToUnicode(text->buffer[i]);
|
||||||
Int32 bytes = Stream_WriteUtf8(cur, codepoint);
|
int bytes = Stream_WriteUtf8(cur, cp);
|
||||||
len += bytes; cur += bytes;
|
len += bytes; cur += bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -939,9 +939,9 @@ ReturnCode Cw_Save(struct Stream* stream) {
|
|||||||
|
|
||||||
struct LocalPlayer* p = &LocalPlayer_Instance;
|
struct LocalPlayer* p = &LocalPlayer_Instance;
|
||||||
Vector3 spawn = p->Spawn; /* TODO: Maybe keep real spawn too? */
|
Vector3 spawn = p->Spawn; /* TODO: Maybe keep real spawn too? */
|
||||||
Stream_SetU16_BE(&tmp[89], (UInt16)spawn.X);
|
Stream_SetU16_BE(&tmp[89], (uint16_t)spawn.X);
|
||||||
Stream_SetU16_BE(&tmp[95], (UInt16)spawn.Y);
|
Stream_SetU16_BE(&tmp[95], (uint16_t)spawn.Y);
|
||||||
Stream_SetU16_BE(&tmp[101], (UInt16)spawn.Z);
|
Stream_SetU16_BE(&tmp[101], (uint16_t)spawn.Z);
|
||||||
tmp[107] = Math_Deg2Packed(p->SpawnRotY);
|
tmp[107] = Math_Deg2Packed(p->SpawnRotY);
|
||||||
tmp[112] = Math_Deg2Packed(p->SpawnHeadX);
|
tmp[112] = Math_Deg2Packed(p->SpawnHeadX);
|
||||||
}
|
}
|
||||||
@ -950,7 +950,7 @@ ReturnCode Cw_Save(struct Stream* stream) {
|
|||||||
|
|
||||||
Mem_Copy(tmp, cw_meta_cpe, sizeof(cw_meta_cpe));
|
Mem_Copy(tmp, cw_meta_cpe, sizeof(cw_meta_cpe));
|
||||||
{
|
{
|
||||||
Stream_SetU16_BE(&tmp[67], (UInt16)(LocalPlayer_Instance.ReachDistance * 32));
|
Stream_SetU16_BE(&tmp[67], (uint16_t)(LocalPlayer_Instance.ReachDistance * 32));
|
||||||
tmp[124] = Env_Weather;
|
tmp[124] = Env_Weather;
|
||||||
|
|
||||||
col = Env_SkyCol; tmp[172] = col.R; tmp[178] = col.G; tmp[184] = col.B;
|
col = Env_SkyCol; tmp[172] = col.R; tmp[178] = col.G; tmp[184] = col.B;
|
||||||
|
@ -18,7 +18,7 @@ void GfxCommon_Init(void) {
|
|||||||
GfxCommon_quadVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, 4);
|
GfxCommon_quadVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, 4);
|
||||||
GfxCommon_texVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, 4);
|
GfxCommon_texVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FT2FC4B, 4);
|
||||||
|
|
||||||
UInt16 indices[GFX_MAX_INDICES];
|
uint16_t indices[GFX_MAX_INDICES];
|
||||||
GfxCommon_MakeIndices(indices, GFX_MAX_INDICES);
|
GfxCommon_MakeIndices(indices, GFX_MAX_INDICES);
|
||||||
GfxCommon_defaultIb = Gfx_CreateIb(indices, GFX_MAX_INDICES);
|
GfxCommon_defaultIb = Gfx_CreateIb(indices, GFX_MAX_INDICES);
|
||||||
}
|
}
|
||||||
@ -135,17 +135,17 @@ void GfxCommon_Mode3D(void) {
|
|||||||
if (gfx_hadFog) Gfx_SetFog(true);
|
if (gfx_hadFog) Gfx_SetFog(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GfxCommon_MakeIndices(UInt16* indices, int iCount) {
|
void GfxCommon_MakeIndices(uint16_t* indices, int iCount) {
|
||||||
int element = 0, i;
|
int element = 0, i;
|
||||||
|
|
||||||
for (i = 0; i < iCount; i += 6) {
|
for (i = 0; i < iCount; i += 6) {
|
||||||
indices[0] = (UInt16)(element + 0);
|
indices[0] = (uint16_t)(element + 0);
|
||||||
indices[1] = (UInt16)(element + 1);
|
indices[1] = (uint16_t)(element + 1);
|
||||||
indices[2] = (UInt16)(element + 2);
|
indices[2] = (uint16_t)(element + 2);
|
||||||
|
|
||||||
indices[3] = (UInt16)(element + 2);
|
indices[3] = (uint16_t)(element + 2);
|
||||||
indices[4] = (UInt16)(element + 3);
|
indices[4] = (uint16_t)(element + 3);
|
||||||
indices[5] = (UInt16)(element + 0);
|
indices[5] = (uint16_t)(element + 0);
|
||||||
|
|
||||||
indices += 6; element += 4;
|
indices += 6; element += 4;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ GfxResourceID GfxCommon_defaultIb;
|
|||||||
/* Contains the information necessary to describe a 2D textured quad. */
|
/* Contains the information necessary to describe a 2D textured quad. */
|
||||||
struct Texture {
|
struct Texture {
|
||||||
GfxResourceID ID;
|
GfxResourceID ID;
|
||||||
Int16 X, Y; UInt16 Width, Height;
|
Int16 X, Y; uint16_t Width, Height;
|
||||||
float U1, V1, U2, V2;
|
float U1, V1, U2, V2;
|
||||||
};
|
};
|
||||||
#define TEX_RECT(x,y, width,height) x,y,width,height
|
#define TEX_RECT(x,y, width,height) x,y,width,height
|
||||||
@ -38,7 +38,7 @@ void GfxCommon_Make2DQuad(struct Texture* tex, PackedCol col, VertexP3fT2fC4b**
|
|||||||
void GfxCommon_Mode2D(int width, int height);
|
void GfxCommon_Mode2D(int width, int height);
|
||||||
void GfxCommon_Mode3D(void);
|
void GfxCommon_Mode3D(void);
|
||||||
|
|
||||||
void GfxCommon_MakeIndices(UInt16* indices, int iCount);
|
void GfxCommon_MakeIndices(uint16_t* indices, int iCount);
|
||||||
void GfxCommon_SetupAlphaState(UInt8 draw);
|
void GfxCommon_SetupAlphaState(UInt8 draw);
|
||||||
void GfxCommon_RestoreAlphaState(UInt8 draw);
|
void GfxCommon_RestoreAlphaState(UInt8 draw);
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ void Lighting_OnBlockChanged(int x, int y, int z, BlockID oldBlock, BlockID newB
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------Lighting heightmap----------------------------------------------------*
|
*---------------------------------------------------Lighting heightmap----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static int Lighting_InitialHeightmapCoverage(int x1, int z1, int xCount, int zCount, Int32* skip) {
|
static int Lighting_InitialHeightmapCoverage(int x1, int z1, int xCount, int zCount, int32_t* skip) {
|
||||||
int elemsLeft = 0, index = 0, curRunCount = 0;
|
int elemsLeft = 0, index = 0, curRunCount = 0;
|
||||||
int x, z;
|
int x, z;
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ for (y = World_Height - 1; y >= 0; y--) {\
|
|||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool Lighting_CalculateHeightmapCoverage(int x1, int z1, int xCount, int zCount, int elemsLeft, Int32* skip) {
|
static bool Lighting_CalculateHeightmapCoverage(int x1, int z1, int xCount, int zCount, int elemsLeft, int32_t* skip) {
|
||||||
int prevRunCount = 0;
|
int prevRunCount = 0;
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ void Lighting_LightHint(int startX, int startZ) {
|
|||||||
int x1 = max(startX, 0), x2 = min(World_Width, startX + EXTCHUNK_SIZE);
|
int x1 = max(startX, 0), x2 = min(World_Width, startX + EXTCHUNK_SIZE);
|
||||||
int z1 = max(startZ, 0), z2 = min(World_Length, startZ + EXTCHUNK_SIZE);
|
int z1 = max(startZ, 0), z2 = min(World_Length, startZ + EXTCHUNK_SIZE);
|
||||||
int xCount = x2 - x1, zCount = z2 - z1;
|
int xCount = x2 - x1, zCount = z2 - z1;
|
||||||
Int32 skip[EXTCHUNK_SIZE * EXTCHUNK_SIZE];
|
int32_t skip[EXTCHUNK_SIZE * EXTCHUNK_SIZE];
|
||||||
|
|
||||||
int elemsLeft = Lighting_InitialHeightmapCoverage(x1, z1, xCount, zCount, skip);
|
int elemsLeft = Lighting_InitialHeightmapCoverage(x1, z1, xCount, zCount, skip);
|
||||||
if (!Lighting_CalculateHeightmapCoverage(x1, z1, xCount, zCount, elemsLeft, skip)) {
|
if (!Lighting_CalculateHeightmapCoverage(x1, z1, xCount, zCount, elemsLeft, skip)) {
|
||||||
|
@ -95,7 +95,7 @@ if (stack_size == 32768) {\
|
|||||||
static void NotchyGen_FloodFill(int startIndex, BlockRaw block) {
|
static void NotchyGen_FloodFill(int startIndex, BlockRaw block) {
|
||||||
if (startIndex < 0) return; /* y below map, immediately ignore */
|
if (startIndex < 0) return; /* y below map, immediately ignore */
|
||||||
/* This is way larger size than I actually have seen used, but we play it safe here.*/
|
/* This is way larger size than I actually have seen used, but we play it safe here.*/
|
||||||
int stack[32768];
|
int32_t stack[32768];
|
||||||
int stack_size = 0;
|
int stack_size = 0;
|
||||||
Stack_Push(startIndex);
|
Stack_Push(startIndex);
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@ int MapRenderer_ChunksX, MapRenderer_ChunksY, MapRenderer_ChunksZ;
|
|||||||
int MapRenderer_1DUsedCount;
|
int MapRenderer_1DUsedCount;
|
||||||
/* The number of non-empty Normal ChunkPartInfos (across entire world) for each 1D atlas batch.
|
/* The number of non-empty Normal ChunkPartInfos (across entire world) for each 1D atlas batch.
|
||||||
1D atlas batches that do not have any ChunkPartInfos can be entirely skipped. */
|
1D atlas batches that do not have any ChunkPartInfos can be entirely skipped. */
|
||||||
Int32 MapRenderer_NormalPartsCount[ATLAS1D_MAX_ATLASES];
|
int32_t MapRenderer_NormalPartsCount[ATLAS1D_MAX_ATLASES];
|
||||||
/* The number of non-empty Translucent ChunkPartInfos (across entire world) for each 1D atlas batch.
|
/* The number of non-empty Translucent ChunkPartInfos (across entire world) for each 1D atlas batch.
|
||||||
1D atlas batches that do not have any ChunkPartInfos can be entirely skipped. */
|
1D atlas batches that do not have any ChunkPartInfos can be entirely skipped. */
|
||||||
Int32 MapRenderer_TranslucentPartsCount[ATLAS1D_MAX_ATLASES];
|
int32_t MapRenderer_TranslucentPartsCount[ATLAS1D_MAX_ATLASES];
|
||||||
/* Whether there are any visible Translucent ChunkPartInfos for each 1D atlas batch.
|
/* Whether there are any visible Translucent ChunkPartInfos for each 1D atlas batch.
|
||||||
1D atlas batches that do not have any visible translucent ChunkPartInfos can be skipped. */
|
1D atlas batches that do not have any visible translucent ChunkPartInfos can be skipped. */
|
||||||
bool MapRenderer_HasTranslucentParts[ATLAS1D_MAX_ATLASES];
|
bool MapRenderer_HasTranslucentParts[ATLAS1D_MAX_ATLASES];
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
#include "GraphicsAPI.h"
|
#include "GraphicsAPI.h"
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
|
||||||
#define UV_POS_MASK ((UInt16)0x7FFF)
|
#define UV_POS_MASK ((uint16_t)0x7FFF)
|
||||||
#define UV_MAX ((UInt16)0x8000)
|
#define UV_MAX ((uint16_t)0x8000)
|
||||||
#define UV_MAX_SHIFT 15
|
#define UV_MAX_SHIFT 15
|
||||||
#define AABB_Width(bb) (bb->Max.X - bb->Min.X)
|
#define AABB_Width(bb) (bb->Max.X - bb->Min.X)
|
||||||
#define AABB_Height(bb) (bb->Max.Y - bb->Min.Y)
|
#define AABB_Height(bb) (bb->Max.Y - bb->Min.Y)
|
||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
void ModelVertex_Init(struct ModelVertex* vertex, float x, float y, float z, int u, int v) {
|
void ModelVertex_Init(struct ModelVertex* vertex, float x, float y, float z, int u, int v) {
|
||||||
vertex->X = x; vertex->Y = y; vertex->Z = z;
|
vertex->X = x; vertex->Y = y; vertex->Z = z;
|
||||||
vertex->U = (UInt16)u; vertex->V = (UInt16)v;
|
vertex->U = (uint16_t)u; vertex->V = (uint16_t)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelPart_Init(struct ModelPart* part, int offset, int count, float rotX, float rotY, float rotZ) {
|
void ModelPart_Init(struct ModelPart* part, int offset, int count, float rotX, float rotY, float rotZ) {
|
||||||
|
12
src/Model.h
12
src/Model.h
@ -14,12 +14,12 @@ struct AABB;
|
|||||||
enum ROTATE_ORDER { ROTATE_ORDER_ZYX, ROTATE_ORDER_XZY, ROTATE_ORDER_YZX };
|
enum ROTATE_ORDER { ROTATE_ORDER_ZYX, ROTATE_ORDER_XZY, ROTATE_ORDER_YZX };
|
||||||
|
|
||||||
/* Describes a vertex within a model. */
|
/* Describes a vertex within a model. */
|
||||||
struct ModelVertex { float X, Y, Z; UInt16 U, V; };
|
struct ModelVertex { float X, Y, Z; uint16_t U, V; };
|
||||||
void ModelVertex_Init(struct ModelVertex* vertex, float x, float y, float z, int u, int v);
|
void ModelVertex_Init(struct ModelVertex* vertex, float x, float y, float z, int u, int v);
|
||||||
|
|
||||||
/* Describes the starting index of this part within a model's array of vertices,
|
/* Describes the starting index of this part within a model's array of vertices,
|
||||||
and the number of vertices following the starting index that this part uses. */
|
and the number of vertices following the starting index that this part uses. */
|
||||||
struct ModelPart { UInt16 Offset, Count; float RotX, RotY, RotZ; };
|
struct ModelPart { uint16_t Offset, Count; float RotX, RotY, RotZ; };
|
||||||
void ModelPart_Init(struct ModelPart* part, int offset, int count, float rotX, float rotY, float rotZ);
|
void ModelPart_Init(struct ModelPart* part, int offset, int count, float rotX, float rotY, float rotZ);
|
||||||
|
|
||||||
/* Contains a set of quads and/or boxes that describe a 3D object as well as
|
/* Contains a set of quads and/or boxes that describe a 3D object as well as
|
||||||
@ -83,10 +83,10 @@ void Model_DrawArmPart(struct ModelPart* part);
|
|||||||
|
|
||||||
/* Describes data for a box being built. */
|
/* Describes data for a box being built. */
|
||||||
struct BoxDesc {
|
struct BoxDesc {
|
||||||
UInt16 TexX, TexY; /* Texture origin */
|
uint16_t TexX, TexY; /* Texture origin */
|
||||||
UInt8 SizeX, SizeY, SizeZ; /* Texture dimensions */
|
UInt8 SizeX, SizeY, SizeZ; /* Texture dimensions */
|
||||||
float X1,Y1,Z1, X2,Y2,Z2; /* Box corners coordinates */
|
float X1,Y1,Z1, X2,Y2,Z2; /* Box corners coordinates */
|
||||||
float RotX,RotY,RotZ; /* Rotation origin point */
|
float RotX,RotY,RotZ; /* Rotation origin point */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Sets the texture origin for this part within the texture atlas. */
|
/* Sets the texture origin for this part within the texture atlas. */
|
||||||
|
@ -596,9 +596,9 @@ void Window_ProcessEvents(void) {
|
|||||||
int i, len = 0;
|
int i, len = 0;
|
||||||
|
|
||||||
for (i = 0; i < clipboard_copy_text.length; i++) {
|
for (i = 0; i < clipboard_copy_text.length; i++) {
|
||||||
UInt16 codepoint = Convert_CP437ToUnicode(clipboard_copy_text.buffer[i]);
|
Codepoint cp = Convert_CP437ToUnicode(clipboard_copy_text.buffer[i]);
|
||||||
UInt8* cur = data + len;
|
UInt8* cur = data + len;
|
||||||
len += Stream_WriteUtf8(cur, codepoint);
|
len += Stream_WriteUtf8(cur, cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
XChangeProperty(win_display, reply.xselection.requestor, reply.xselection.property, xa_utf8_string, 8,
|
XChangeProperty(win_display, reply.xselection.requestor, reply.xselection.property, xa_utf8_string, 8,
|
||||||
|
@ -297,7 +297,7 @@ GfxResourceID Gfx_CreateVb(void* vertices, int vertexFormat, int count) {
|
|||||||
glNewList(list, GL_COMPILE);
|
glNewList(list, GL_COMPILE);
|
||||||
count &= ~0x01; /* Need to get rid of the 1 extra element, see comment in chunk mesh builder for why */
|
count &= ~0x01; /* Need to get rid of the 1 extra element, see comment in chunk mesh builder for why */
|
||||||
|
|
||||||
UInt16 indices[GFX_MAX_INDICES];
|
uint16_t indices[GFX_MAX_INDICES];
|
||||||
GfxCommon_MakeIndices(indices, ICOUNT(count));
|
GfxCommon_MakeIndices(indices, ICOUNT(count));
|
||||||
|
|
||||||
int stride = vertexFormat == VERTEX_FORMAT_P3FT2FC4B ? sizeof(VertexP3fT2fC4b) : sizeof(VertexP3fC4b);
|
int stride = vertexFormat == VERTEX_FORMAT_P3FT2FC4B ? sizeof(VertexP3fT2fC4b) : sizeof(VertexP3fC4b);
|
||||||
@ -317,7 +317,7 @@ GfxResourceID Gfx_CreateVb(void* vertices, int vertexFormat, int count) {
|
|||||||
GfxResourceID Gfx_CreateIb(void* indices, int indicesCount) {
|
GfxResourceID Gfx_CreateIb(void* indices, int indicesCount) {
|
||||||
#ifndef CC_BUILD_GL11
|
#ifndef CC_BUILD_GL11
|
||||||
GfxResourceID id = GL_GenAndBind(GL_ELEMENT_ARRAY_BUFFER);
|
GfxResourceID id = GL_GenAndBind(GL_ELEMENT_ARRAY_BUFFER);
|
||||||
UInt32 sizeInBytes = indicesCount * sizeof(UInt16);
|
UInt32 sizeInBytes = indicesCount * 2;
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (void*)sizeInBytes, indices, GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (void*)sizeInBytes, indices, GL_STATIC_DRAW);
|
||||||
return id;
|
return id;
|
||||||
#else
|
#else
|
||||||
|
@ -775,7 +775,7 @@ static void CPE_WriteCustomBlockLevel(UInt8 version) {
|
|||||||
ServerConnection_WriteBuffer = data;
|
ServerConnection_WriteBuffer = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CPE_WriteTwoWayPing(bool serverToClient, UInt16 payload) {
|
static void CPE_WriteTwoWayPing(bool serverToClient, uint16_t payload) {
|
||||||
UInt8* data = ServerConnection_WriteBuffer;
|
UInt8* data = ServerConnection_WriteBuffer;
|
||||||
*data++ = OPCODE_TWO_WAY_PING;
|
*data++ = OPCODE_TWO_WAY_PING;
|
||||||
{
|
{
|
||||||
@ -1032,9 +1032,9 @@ static void CPE_RemoveSelection(UInt8* data) {
|
|||||||
|
|
||||||
static void CPE_SetEnvCol(UInt8* data) {
|
static void CPE_SetEnvCol(UInt8* data) {
|
||||||
UInt8 variable = *data++;
|
UInt8 variable = *data++;
|
||||||
UInt16 r = Stream_GetU16_BE(&data[0]);
|
uint16_t r = Stream_GetU16_BE(&data[0]);
|
||||||
UInt16 g = Stream_GetU16_BE(&data[2]);
|
uint16_t g = Stream_GetU16_BE(&data[2]);
|
||||||
UInt16 b = Stream_GetU16_BE(&data[4]);
|
uint16_t b = Stream_GetU16_BE(&data[4]);
|
||||||
bool invalid = r > 255 || g > 255 || b > 255;
|
bool invalid = r > 255 || g > 255 || b > 255;
|
||||||
PackedCol col = PACKEDCOL_CONST((UInt8)r, (UInt8)g, (UInt8)b, 255);
|
PackedCol col = PACKEDCOL_CONST((UInt8)r, (UInt8)g, (UInt8)b, 255);
|
||||||
|
|
||||||
@ -1095,7 +1095,7 @@ static void CPE_HackControl(UInt8* data) {
|
|||||||
p->Hacks.CanUseThirdPersonCamera = *data++ != 0;
|
p->Hacks.CanUseThirdPersonCamera = *data++ != 0;
|
||||||
LocalPlayer_CheckHacksConsistency();
|
LocalPlayer_CheckHacksConsistency();
|
||||||
|
|
||||||
UInt16 jumpHeight = Stream_GetU16_BE(data);
|
int jumpHeight = Stream_GetU16_BE(data);
|
||||||
struct PhysicsComp* physics = &p->Physics;
|
struct PhysicsComp* physics = &p->Physics;
|
||||||
if (jumpHeight == UInt16_MaxValue) { /* special value of -1 to reset default */
|
if (jumpHeight == UInt16_MaxValue) { /* special value of -1 to reset default */
|
||||||
physics->JumpVel = HacksComp_CanJumpHigher(&p->Hacks) ? physics->UserJumpVel : 0.42f;
|
physics->JumpVel = HacksComp_CanJumpHigher(&p->Hacks) ? physics->UserJumpVel : 0.42f;
|
||||||
@ -1267,7 +1267,7 @@ static void CPE_SetEntityProperty(UInt8* data) {
|
|||||||
|
|
||||||
static void CPE_TwoWayPing(UInt8* data) {
|
static void CPE_TwoWayPing(UInt8* data) {
|
||||||
UInt8 serverToClient = *data++;
|
UInt8 serverToClient = *data++;
|
||||||
UInt16 payload = Stream_GetU16_BE(data);
|
uint16_t payload = Stream_GetU16_BE(data);
|
||||||
|
|
||||||
if (serverToClient) {
|
if (serverToClient) {
|
||||||
CPE_WriteTwoWayPing(true, payload); /* server to client reply */
|
CPE_WriteTwoWayPing(true, payload); /* server to client reply */
|
||||||
|
@ -198,8 +198,8 @@ struct TerrainParticle {
|
|||||||
|
|
||||||
struct TerrainParticle Terrain_Particles[PARTICLES_MAX];
|
struct TerrainParticle Terrain_Particles[PARTICLES_MAX];
|
||||||
int Terrain_Count;
|
int Terrain_Count;
|
||||||
UInt16 Terrain_1DCount[ATLAS1D_MAX_ATLASES];
|
uint16_t Terrain_1DCount[ATLAS1D_MAX_ATLASES];
|
||||||
UInt16 Terrain_1DIndices[ATLAS1D_MAX_ATLASES];
|
uint16_t Terrain_1DIndices[ATLAS1D_MAX_ATLASES];
|
||||||
|
|
||||||
static bool TerrainParticle_Tick(struct TerrainParticle* p, double delta) {
|
static bool TerrainParticle_Tick(struct TerrainParticle* p, double delta) {
|
||||||
return Particle_PhysicsTick(&p->Base, 5.4f, true, delta);
|
return Particle_PhysicsTick(&p->Base, 5.4f, true, delta);
|
||||||
|
@ -202,13 +202,13 @@ TimeMS DateTime_CurrentUTC_MS(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Platform_FromSysTime(DateTime* time, SYSTEMTIME* sysTime) {
|
static void Platform_FromSysTime(DateTime* time, SYSTEMTIME* sysTime) {
|
||||||
time->Year = (UInt16)sysTime->wYear;
|
time->Year = (uint16_t)sysTime->wYear;
|
||||||
time->Month = (UInt8)sysTime->wMonth;
|
time->Month = (UInt8)sysTime->wMonth;
|
||||||
time->Day = (UInt8)sysTime->wDay;
|
time->Day = (UInt8)sysTime->wDay;
|
||||||
time->Hour = (UInt8)sysTime->wHour;
|
time->Hour = (UInt8)sysTime->wHour;
|
||||||
time->Minute = (UInt8)sysTime->wMinute;
|
time->Minute = (UInt8)sysTime->wMinute;
|
||||||
time->Second = (UInt8)sysTime->wSecond;
|
time->Second = (UInt8)sysTime->wSecond;
|
||||||
time->Milli = (UInt16)sysTime->wMilliseconds;
|
time->Milli = (uint16_t)sysTime->wMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DateTime_CurrentUTC(DateTime* time) {
|
void DateTime_CurrentUTC(DateTime* time) {
|
||||||
@ -454,7 +454,7 @@ ReturnCode Directory_Enum(const String* dirPath, void* obj, Directory_EnumCallba
|
|||||||
if (src[0] == '.' && src[1] == '\0') continue;
|
if (src[0] == '.' && src[1] == '\0') continue;
|
||||||
if (src[0] == '.' && src[1] == '.' && src[2] == '\0') continue;
|
if (src[0] == '.' && src[1] == '.' && src[2] == '\0') continue;
|
||||||
|
|
||||||
UInt16 len = String_CalcLen(src, UInt16_MaxValue);
|
int len = String_CalcLen(src, UInt16_MaxValue);
|
||||||
String_DecodeUtf8(&path, src, len);
|
String_DecodeUtf8(&path, src, len);
|
||||||
|
|
||||||
/* TODO: fallback to stat when this fails */
|
/* TODO: fallback to stat when this fails */
|
||||||
@ -726,7 +726,7 @@ void Font_GetNames(StringsBuffer* buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font_Make(FontDesc* desc, const String* fontName, UInt16 size, UInt16 style) {
|
void Font_Make(FontDesc* desc, const String* fontName, uint16_t size, uint16_t style) {
|
||||||
desc->Size = size;
|
desc->Size = size;
|
||||||
desc->Style = style;
|
desc->Style = style;
|
||||||
if (!norm_fonts.Count) Font_Init();
|
if (!norm_fonts.Count) Font_Init();
|
||||||
@ -806,13 +806,13 @@ static void Font_DirCallback(const String* srcPath, void* obj) {
|
|||||||
#define TEXT_CEIL(x) (((x) + 63) >> 6)
|
#define TEXT_CEIL(x) (((x) + 63) >> 6)
|
||||||
Size2D Platform_TextMeasure(struct DrawTextArgs* args) {
|
Size2D Platform_TextMeasure(struct DrawTextArgs* args) {
|
||||||
FT_Face face = args->Font.Handle;
|
FT_Face face = args->Font.Handle;
|
||||||
String text = args->Text;
|
String text = args->Text;
|
||||||
Size2D s = { 0, face->size->metrics.height };
|
Size2D s = { 0, face->size->metrics.height };
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < text.length; i++) {
|
for (i = 0; i < text.length; i++) {
|
||||||
UInt16 c = Convert_CP437ToUnicode(text.buffer[i]);
|
Codepoint cp = Convert_CP437ToUnicode(text.buffer[i]);
|
||||||
FT_Load_Char(face, c, 0); /* TODO: Check error */
|
FT_Load_Char(face, cp, 0); /* TODO: Check error */
|
||||||
s.Width += face->glyph->advance.x;
|
s.Width += face->glyph->advance.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -828,8 +828,8 @@ Size2D Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, P
|
|||||||
int i, descender = TEXT_CEIL(face->size->metrics.descender);
|
int i, descender = TEXT_CEIL(face->size->metrics.descender);
|
||||||
|
|
||||||
for (i = 0; i < text.length; i++) {
|
for (i = 0; i < text.length; i++) {
|
||||||
UInt16 c = Convert_CP437ToUnicode(text.buffer[i]);
|
Codepoint cp = Convert_CP437ToUnicode(text.buffer[i]);
|
||||||
FT_Load_Char(face, c, FT_LOAD_RENDER); /* TODO: Check error */
|
FT_Load_Char(face, cp, FT_LOAD_RENDER); /* TODO: Check error */
|
||||||
|
|
||||||
FT_Bitmap* img = &face->glyph->bitmap;
|
FT_Bitmap* img = &face->glyph->bitmap;
|
||||||
int xx, yy, offset = s.Height + descender - face->glyph->bitmap_top;
|
int xx, yy, offset = s.Height + descender - face->glyph->bitmap_top;
|
||||||
@ -1694,8 +1694,8 @@ void Platform_ConvertString(void* dstPtr, const String* src) {
|
|||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < src->length; i++) {
|
for (i = 0; i < src->length; i++) {
|
||||||
UInt16 codepoint = Convert_CP437ToUnicode(src->buffer[i]);
|
Codepoint cp = Convert_CP437ToUnicode(src->buffer[i]);
|
||||||
int len = Stream_WriteUtf8(dst, codepoint); dst += len;
|
int len = Stream_WriteUtf8(dst, cp); dst += len;
|
||||||
}
|
}
|
||||||
*dst = '\0';
|
*dst = '\0';
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ void Waitable_Wait(void* handle);
|
|||||||
void Waitable_WaitFor(void* handle, UInt32 milliseconds);
|
void Waitable_WaitFor(void* handle, UInt32 milliseconds);
|
||||||
|
|
||||||
NOINLINE_ void Font_GetNames(StringsBuffer* buffer);
|
NOINLINE_ void Font_GetNames(StringsBuffer* buffer);
|
||||||
NOINLINE_ void Font_Make(FontDesc* desc, const String* fontName, UInt16 size, UInt16 style);
|
NOINLINE_ void Font_Make(FontDesc* desc, const String* fontName, uint16_t size, uint16_t style);
|
||||||
NOINLINE_ void Font_Free(FontDesc* desc);
|
NOINLINE_ void Font_Free(FontDesc* desc);
|
||||||
NOINLINE_ Size2D Platform_TextMeasure(struct DrawTextArgs* args);
|
NOINLINE_ Size2D Platform_TextMeasure(struct DrawTextArgs* args);
|
||||||
NOINLINE_ Size2D Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, PackedCol col);
|
NOINLINE_ Size2D Platform_TextDraw(struct DrawTextArgs* args, Bitmap* bmp, int x, int y, PackedCol col);
|
||||||
@ -108,7 +108,7 @@ ReturnCode Http_Do(struct AsyncRequest* req, volatile int* progress);
|
|||||||
ReturnCode Http_Free(void);
|
ReturnCode Http_Free(void);
|
||||||
|
|
||||||
#define AUDIO_MAX_CHUNKS 4
|
#define AUDIO_MAX_CHUNKS 4
|
||||||
struct AudioFormat { UInt16 Channels, BitsPerSample; int SampleRate; };
|
struct AudioFormat { uint16_t Channels, BitsPerSample; int SampleRate; };
|
||||||
#define AudioFormat_Eq(a, b) ((a)->Channels == (b)->Channels && (a)->BitsPerSample == (b)->BitsPerSample && (a)->SampleRate == (b)->SampleRate)
|
#define AudioFormat_Eq(a, b) ((a)->Channels == (b)->Channels && (a)->BitsPerSample == (b)->BitsPerSample && (a)->SampleRate == (b)->SampleRate)
|
||||||
typedef int AudioHandle;
|
typedef int AudioHandle;
|
||||||
|
|
||||||
|
@ -83,13 +83,13 @@ int main(int argc, char** argv) {
|
|||||||
String_Copy(&Game_Mppass, &args[1]);
|
String_Copy(&Game_Mppass, &args[1]);
|
||||||
String_Copy(&Game_IPAddress, &args[2]);
|
String_Copy(&Game_IPAddress, &args[2]);
|
||||||
|
|
||||||
UInt8 ip[4];
|
uint8_t ip[4];
|
||||||
if (!Utils_ParseIP(&args[2], ip)) {
|
if (!Utils_ParseIP(&args[2], ip)) {
|
||||||
ErrorHandler_ShowDialog("Failed to start", "Invalid IP");
|
ErrorHandler_ShowDialog("Failed to start", "Invalid IP");
|
||||||
Platform_Exit(1); return 1;
|
Platform_Exit(1); return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 port;
|
uint16_t port;
|
||||||
if (!Convert_TryParseUInt16(&args[3], &port)) {
|
if (!Convert_TryParseUInt16(&args[3], &port)) {
|
||||||
ErrorHandler_ShowDialog("Failed to start", "Invalid port");
|
ErrorHandler_ShowDialog("Failed to start", "Invalid port");
|
||||||
Platform_Exit(1); return 1;
|
Platform_Exit(1); return 1;
|
||||||
|
@ -1268,7 +1268,7 @@ static bool HUDScreen_MouseDown(void* screen, int x, int y, MouseButton btn) {
|
|||||||
|
|
||||||
static void HUDScreen_Init(void* screen) {
|
static void HUDScreen_Init(void* screen) {
|
||||||
struct HUDScreen* s = screen;
|
struct HUDScreen* s = screen;
|
||||||
UInt16 size = Drawer2D_BitmappedText ? 16 : 11;
|
uint16_t size = Drawer2D_BitmappedText ? 16 : 11;
|
||||||
Drawer2D_MakeFont(&s->PlayerFont, size, FONT_STYLE_NORMAL);
|
Drawer2D_MakeFont(&s->PlayerFont, size, FONT_STYLE_NORMAL);
|
||||||
|
|
||||||
ChatScreen_MakeInstance();
|
ChatScreen_MakeInstance();
|
||||||
|
@ -86,24 +86,24 @@ void ServerConnection_CheckAsyncResources(void) {
|
|||||||
*--------------------------------------------------------PingList---------------------------------------------------------*
|
*--------------------------------------------------------PingList---------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
struct PingEntry {
|
struct PingEntry {
|
||||||
int64_t TimeSent, TimeReceived; UInt16 Data;
|
int64_t TimeSent, TimeReceived; uint16_t Data;
|
||||||
};
|
};
|
||||||
struct PingEntry PingList_Entries[10];
|
struct PingEntry PingList_Entries[10];
|
||||||
|
|
||||||
UInt16 PingList_Set(int i, UInt16 prev) {
|
uint16_t PingList_Set(int i, uint16_t prev) {
|
||||||
PingList_Entries[i].Data = (UInt16)(prev + 1);
|
PingList_Entries[i].Data = (uint16_t)(prev + 1);
|
||||||
PingList_Entries[i].TimeSent = DateTime_CurrentUTC_MS();
|
PingList_Entries[i].TimeSent = DateTime_CurrentUTC_MS();
|
||||||
PingList_Entries[i].TimeReceived = 0;
|
PingList_Entries[i].TimeReceived = 0;
|
||||||
return (UInt16)(prev + 1);
|
return (uint16_t)(prev + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 PingList_NextPingData(void) {
|
uint16_t PingList_NextPingData(void) {
|
||||||
/* Find free ping slot */
|
/* Find free ping slot */
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < Array_Elems(PingList_Entries); i++) {
|
for (i = 0; i < Array_Elems(PingList_Entries); i++) {
|
||||||
if (PingList_Entries[i].TimeSent) continue;
|
if (PingList_Entries[i].TimeSent) continue;
|
||||||
|
|
||||||
UInt16 prev = i > 0 ? PingList_Entries[i - 1].Data : 0;
|
uint16_t prev = i > 0 ? PingList_Entries[i - 1].Data : 0;
|
||||||
return PingList_Set(i, prev);
|
return PingList_Set(i, prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ UInt16 PingList_NextPingData(void) {
|
|||||||
return PingList_Set(j, PingList_Entries[j].Data);
|
return PingList_Set(j, PingList_Entries[j].Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PingList_Update(UInt16 data) {
|
void PingList_Update(uint16_t data) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < Array_Elems(PingList_Entries); i++) {
|
for (i = 0; i < Array_Elems(PingList_Entries); i++) {
|
||||||
if (PingList_Entries[i].Data != data) continue;
|
if (PingList_Entries[i].Data != data) continue;
|
||||||
@ -127,8 +127,7 @@ void PingList_Update(UInt16 data) {
|
|||||||
|
|
||||||
int PingList_AveragePingMs(void) {
|
int PingList_AveragePingMs(void) {
|
||||||
double totalMs = 0.0;
|
double totalMs = 0.0;
|
||||||
int measures = 0;
|
int i, measures = 0;
|
||||||
int i;
|
|
||||||
for (i = 0; i < Array_Elems(PingList_Entries); i++) {
|
for (i = 0; i < Array_Elems(PingList_Entries); i++) {
|
||||||
struct PingEntry entry = PingList_Entries[i];
|
struct PingEntry entry = PingList_Entries[i];
|
||||||
if (!entry.TimeSent || !entry.TimeReceived) continue;
|
if (!entry.TimeSent || !entry.TimeReceived) continue;
|
||||||
@ -460,8 +459,8 @@ static void MPConnection_Tick(struct ScheduledTask* task) {
|
|||||||
net_ticks++;
|
net_ticks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Net_Set(UInt8 opcode, Net_Handler handler, UInt16 packetSize) {
|
void Net_Set(UInt8 opcode, Net_Handler handler, uint16_t packetSize) {
|
||||||
Net_Handlers[opcode] = handler;
|
Net_Handlers[opcode] = handler;
|
||||||
Net_PacketSizes[opcode] = packetSize;
|
Net_PacketSizes[opcode] = packetSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ struct Stream;
|
|||||||
struct IGameComponent;
|
struct IGameComponent;
|
||||||
struct ScheduledTask;
|
struct ScheduledTask;
|
||||||
|
|
||||||
UInt16 PingList_NextPingData(void);
|
uint16_t PingList_NextPingData(void);
|
||||||
void PingList_Update(UInt16 data);
|
void PingList_Update(uint16_t data);
|
||||||
int PingList_AveragePingMs(void);
|
int PingList_AveragePingMs(void);
|
||||||
|
|
||||||
bool ServerConnection_IsSinglePlayer;
|
bool ServerConnection_IsSinglePlayer;
|
||||||
@ -70,8 +70,8 @@ void ServerConnection_InitMultiplayer(void);
|
|||||||
void ServerConnection_MakeComponent(struct IGameComponent* comp);
|
void ServerConnection_MakeComponent(struct IGameComponent* comp);
|
||||||
|
|
||||||
typedef void (*Net_Handler)(UInt8* data);
|
typedef void (*Net_Handler)(UInt8* data);
|
||||||
UInt16 Net_PacketSizes[OPCODE_COUNT];
|
uint16_t Net_PacketSizes[OPCODE_COUNT];
|
||||||
Net_Handler Net_Handlers[OPCODE_COUNT];
|
Net_Handler Net_Handlers[OPCODE_COUNT];
|
||||||
void Net_Set(UInt8 opcode, Net_Handler handler, UInt16 size);
|
void Net_Set(UInt8 opcode, Net_Handler handler, uint16_t size);
|
||||||
void Net_SendPacket(void);
|
void Net_SendPacket(void);
|
||||||
#endif
|
#endif
|
||||||
|
114
src/Stream.c
114
src/Stream.c
@ -7,7 +7,7 @@
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*---------------------------------------------------------Stream----------------------------------------------------------*
|
*---------------------------------------------------------Stream----------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
ReturnCode Stream_Read(struct Stream* stream, UInt8* buffer, UInt32 count) {
|
ReturnCode Stream_Read(struct Stream* stream, uint8_t* buffer, UInt32 count) {
|
||||||
UInt32 read;
|
UInt32 read;
|
||||||
while (count) {
|
while (count) {
|
||||||
ReturnCode res = stream->Read(stream, buffer, count, &read);
|
ReturnCode res = stream->Read(stream, buffer, count, &read);
|
||||||
@ -20,7 +20,7 @@ ReturnCode Stream_Read(struct Stream* stream, UInt8* buffer, UInt32 count) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnCode Stream_Write(struct Stream* stream, UInt8* buffer, UInt32 count) {
|
ReturnCode Stream_Write(struct Stream* stream, uint8_t* buffer, UInt32 count) {
|
||||||
UInt32 write;
|
UInt32 write;
|
||||||
while (count) {
|
while (count) {
|
||||||
ReturnCode res = stream->Write(stream, buffer, count, &write);
|
ReturnCode res = stream->Write(stream, buffer, count, &write);
|
||||||
@ -36,7 +36,7 @@ ReturnCode Stream_Write(struct Stream* stream, UInt8* buffer, UInt32 count) {
|
|||||||
ReturnCode Stream_Skip(struct Stream* stream, UInt32 count) {
|
ReturnCode Stream_Skip(struct Stream* stream, UInt32 count) {
|
||||||
ReturnCode res = stream->Seek(stream, count, STREAM_SEEKFROM_CURRENT);
|
ReturnCode res = stream->Seek(stream, count, STREAM_SEEKFROM_CURRENT);
|
||||||
if (!res) return 0;
|
if (!res) return 0;
|
||||||
UInt8 tmp[3584]; /* not quite 4 KB to avoid chkstk call */
|
uint8_t tmp[3584]; /* not quite 4 KB to avoid chkstk call */
|
||||||
|
|
||||||
while (count) {
|
while (count) {
|
||||||
UInt32 toRead = min(count, sizeof(tmp)), read;
|
UInt32 toRead = min(count, sizeof(tmp)), read;
|
||||||
@ -49,10 +49,10 @@ ReturnCode Stream_Skip(struct Stream* stream, UInt32 count) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ReturnCode Stream_DefaultIO(struct Stream* stream, UInt8* data, UInt32 count, UInt32* modified) {
|
static ReturnCode Stream_DefaultIO(struct Stream* stream, uint8_t* data, UInt32 count, UInt32* modified) {
|
||||||
*modified = 0; return ReturnCode_NotSupported;
|
*modified = 0; return ReturnCode_NotSupported;
|
||||||
}
|
}
|
||||||
ReturnCode Stream_DefaultReadU8(struct Stream* stream, UInt8* data) {
|
ReturnCode Stream_DefaultReadU8(struct Stream* stream, uint8_t* data) {
|
||||||
UInt32 modified = 0;
|
UInt32 modified = 0;
|
||||||
ReturnCode res = stream->Read(stream, data, 1, &modified);
|
ReturnCode res = stream->Read(stream, data, 1, &modified);
|
||||||
return res ? res : (modified ? 0 : ERR_END_OF_STREAM);
|
return res ? res : (modified ? 0 : ERR_END_OF_STREAM);
|
||||||
@ -80,10 +80,10 @@ void Stream_Init(struct Stream* stream) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------------FileStream--------------------------------------------------------*
|
*-------------------------------------------------------FileStream--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static ReturnCode Stream_FileRead(struct Stream* stream, UInt8* data, UInt32 count, UInt32* modified) {
|
static ReturnCode Stream_FileRead(struct Stream* stream, uint8_t* data, UInt32 count, UInt32* modified) {
|
||||||
return File_Read(stream->Meta.File, data, count, modified);
|
return File_Read(stream->Meta.File, data, count, modified);
|
||||||
}
|
}
|
||||||
static ReturnCode Stream_FileWrite(struct Stream* stream, UInt8* data, UInt32 count, UInt32* modified) {
|
static ReturnCode Stream_FileWrite(struct Stream* stream, uint8_t* data, UInt32 count, UInt32* modified) {
|
||||||
return File_Write(stream->Meta.File, data, count, modified);
|
return File_Write(stream->Meta.File, data, count, modified);
|
||||||
}
|
}
|
||||||
static ReturnCode Stream_FileClose(struct Stream* stream) {
|
static ReturnCode Stream_FileClose(struct Stream* stream) {
|
||||||
@ -117,7 +117,7 @@ void Stream_FromFile(struct Stream* stream, void* file) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------PortionStream-------------------------------------------------------*
|
*-----------------------------------------------------PortionStream-------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static ReturnCode Stream_PortionRead(struct Stream* stream, UInt8* data, UInt32 count, UInt32* modified) {
|
static ReturnCode Stream_PortionRead(struct Stream* stream, uint8_t* data, UInt32 count, UInt32* modified) {
|
||||||
count = min(count, stream->Meta.Mem.Left);
|
count = min(count, stream->Meta.Mem.Left);
|
||||||
struct Stream* source = stream->Meta.Portion.Source;
|
struct Stream* source = stream->Meta.Portion.Source;
|
||||||
ReturnCode code = source->Read(source, data, count, modified);
|
ReturnCode code = source->Read(source, data, count, modified);
|
||||||
@ -125,7 +125,7 @@ static ReturnCode Stream_PortionRead(struct Stream* stream, UInt8* data, UInt32
|
|||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ReturnCode Stream_PortionReadU8(struct Stream* stream, UInt8* data) {
|
static ReturnCode Stream_PortionReadU8(struct Stream* stream, uint8_t* data) {
|
||||||
if (!stream->Meta.Mem.Left) return ERR_END_OF_STREAM;
|
if (!stream->Meta.Mem.Left) return ERR_END_OF_STREAM;
|
||||||
stream->Meta.Mem.Left--;
|
stream->Meta.Mem.Left--;
|
||||||
struct Stream* source = stream->Meta.Portion.Source;
|
struct Stream* source = stream->Meta.Portion.Source;
|
||||||
@ -155,7 +155,7 @@ void Stream_ReadonlyPortion(struct Stream* stream, struct Stream* source, UInt32
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------MemoryStream--------------------------------------------------------*
|
*-----------------------------------------------------MemoryStream--------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static ReturnCode Stream_MemoryRead(struct Stream* stream, UInt8* data, UInt32 count, UInt32* modified) {
|
static ReturnCode Stream_MemoryRead(struct Stream* stream, uint8_t* data, UInt32 count, UInt32* modified) {
|
||||||
count = min(count, stream->Meta.Mem.Left);
|
count = min(count, stream->Meta.Mem.Left);
|
||||||
if (count) { Mem_Copy(data, stream->Meta.Mem.Cur, count); }
|
if (count) { Mem_Copy(data, stream->Meta.Mem.Cur, count); }
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ static ReturnCode Stream_MemoryRead(struct Stream* stream, UInt8* data, UInt32 c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ReturnCode Stream_MemoryReadU8(struct Stream* stream, UInt8* data) {
|
static ReturnCode Stream_MemoryReadU8(struct Stream* stream, uint8_t* data) {
|
||||||
if (!stream->Meta.Mem.Left) return ERR_END_OF_STREAM;
|
if (!stream->Meta.Mem.Left) return ERR_END_OF_STREAM;
|
||||||
|
|
||||||
*data = *stream->Meta.Mem.Cur;
|
*data = *stream->Meta.Mem.Cur;
|
||||||
@ -172,7 +172,7 @@ static ReturnCode Stream_MemoryReadU8(struct Stream* stream, UInt8* data) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ReturnCode Stream_MemoryWrite(struct Stream* stream, UInt8* data, UInt32 count, UInt32* modified) {
|
static ReturnCode Stream_MemoryWrite(struct Stream* stream, uint8_t* data, UInt32 count, UInt32* modified) {
|
||||||
count = min(count, stream->Meta.Mem.Left);
|
count = min(count, stream->Meta.Mem.Left);
|
||||||
if (count) { Mem_Copy(stream->Meta.Mem.Cur, data, count); }
|
if (count) { Mem_Copy(stream->Meta.Mem.Cur, data, count); }
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ void Stream_WriteonlyMemory(struct Stream* stream, void* data, UInt32 len) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*----------------------------------------------------BufferedStream-------------------------------------------------------*
|
*----------------------------------------------------BufferedStream-------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static ReturnCode Stream_BufferedRead(struct Stream* stream, UInt8* data, UInt32 count, UInt32* modified) {
|
static ReturnCode Stream_BufferedRead(struct Stream* stream, uint8_t* data, UInt32 count, UInt32* modified) {
|
||||||
if (stream->Meta.Buffered.Left == 0) {
|
if (stream->Meta.Buffered.Left == 0) {
|
||||||
struct Stream* source = stream->Meta.Buffered.Source;
|
struct Stream* source = stream->Meta.Buffered.Source;
|
||||||
stream->Meta.Buffered.Cur = stream->Meta.Buffered.Base;
|
stream->Meta.Buffered.Cur = stream->Meta.Buffered.Base;
|
||||||
@ -243,7 +243,7 @@ static ReturnCode Stream_BufferedRead(struct Stream* stream, UInt8* data, UInt32
|
|||||||
return Stream_MemoryRead(stream, data, count, modified);
|
return Stream_MemoryRead(stream, data, count, modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ReturnCode Stream_BufferedReadU8(struct Stream* stream, UInt8* data) {
|
static ReturnCode Stream_BufferedReadU8(struct Stream* stream, uint8_t* data) {
|
||||||
if (stream->Meta.Buffered.Left) return Stream_MemoryReadU8(stream, data);
|
if (stream->Meta.Buffered.Left) return Stream_MemoryReadU8(stream, data);
|
||||||
return Stream_DefaultReadU8(stream, data);
|
return Stream_DefaultReadU8(stream, data);
|
||||||
}
|
}
|
||||||
@ -264,48 +264,48 @@ void Stream_ReadonlyBuffered(struct Stream* stream, struct Stream* source, void*
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------Read/Write primitives---------------------------------------------------*
|
*-------------------------------------------------Read/Write primitives---------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
UInt16 Stream_GetU16_LE(UInt8* data) {
|
uint16_t Stream_GetU16_LE(uint8_t* data) {
|
||||||
return (UInt16)(data[0] | (data[1] << 8));
|
return (uint16_t)(data[0] | (data[1] << 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 Stream_GetU16_BE(UInt8* data) {
|
uint16_t Stream_GetU16_BE(uint8_t* data) {
|
||||||
return (UInt16)((data[0] << 8) | data[1]);
|
return (uint16_t)((data[0] << 8) | data[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 Stream_GetU32_LE(UInt8* data) {
|
UInt32 Stream_GetU32_LE(uint8_t* data) {
|
||||||
return (UInt32)(
|
return (UInt32)(
|
||||||
(UInt32)data[0] | ((UInt32)data[1] << 8) |
|
(UInt32)data[0] | ((UInt32)data[1] << 8) |
|
||||||
((UInt32)data[2] << 16) | ((UInt32)data[3] << 24));
|
((UInt32)data[2] << 16) | ((UInt32)data[3] << 24));
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 Stream_GetU32_BE(UInt8* data) {
|
UInt32 Stream_GetU32_BE(uint8_t* data) {
|
||||||
return (UInt32)(
|
return (UInt32)(
|
||||||
((UInt32)data[0] << 24) | ((UInt32)data[1] << 16) |
|
((UInt32)data[0] << 24) | ((UInt32)data[1] << 16) |
|
||||||
((UInt32)data[2] << 8) | (UInt32)data[3]);
|
((UInt32)data[2] << 8) | (UInt32)data[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream_SetU16_BE(UInt8* data, UInt16 value) {
|
void Stream_SetU16_BE(uint8_t* data, uint16_t value) {
|
||||||
data[0] = (UInt8)(value >> 8 ); data[1] = (UInt8)(value );
|
data[0] = (uint8_t)(value >> 8 ); data[1] = (uint8_t)(value );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream_SetU32_LE(UInt8* data, UInt32 value) {
|
void Stream_SetU32_LE(uint8_t* data, UInt32 value) {
|
||||||
data[0] = (UInt8)(value ); data[1] = (UInt8)(value >> 8 );
|
data[0] = (uint8_t)(value ); data[1] = (uint8_t)(value >> 8 );
|
||||||
data[2] = (UInt8)(value >> 16); data[3] = (UInt8)(value >> 24);
|
data[2] = (uint8_t)(value >> 16); data[3] = (uint8_t)(value >> 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream_SetU32_BE(UInt8* data, UInt32 value) {
|
void Stream_SetU32_BE(uint8_t* data, UInt32 value) {
|
||||||
data[0] = (UInt8)(value >> 24); data[1] = (UInt8)(value >> 16);
|
data[0] = (uint8_t)(value >> 24); data[1] = (uint8_t)(value >> 16);
|
||||||
data[2] = (UInt8)(value >> 8 ); data[3] = (UInt8)(value);
|
data[2] = (uint8_t)(value >> 8 ); data[3] = (uint8_t)(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnCode Stream_ReadU32_LE(struct Stream* stream, UInt32* value) {
|
ReturnCode Stream_ReadU32_LE(struct Stream* stream, UInt32* value) {
|
||||||
UInt8 data[4]; ReturnCode res;
|
uint8_t data[4]; ReturnCode res;
|
||||||
if ((res = Stream_Read(stream, data, 4))) return res;
|
if ((res = Stream_Read(stream, data, 4))) return res;
|
||||||
*value = Stream_GetU32_LE(data); return 0;
|
*value = Stream_GetU32_LE(data); return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnCode Stream_ReadU32_BE(struct Stream* stream, UInt32* value) {
|
ReturnCode Stream_ReadU32_BE(struct Stream* stream, UInt32* value) {
|
||||||
UInt8 data[4]; ReturnCode res;
|
uint8_t data[4]; ReturnCode res;
|
||||||
if ((res = Stream_Read(stream, data, 4))) return res;
|
if ((res = Stream_Read(stream, data, 4))) return res;
|
||||||
*value = Stream_GetU32_BE(data); return 0;
|
*value = Stream_GetU32_BE(data); return 0;
|
||||||
}
|
}
|
||||||
@ -314,13 +314,13 @@ ReturnCode Stream_ReadU32_BE(struct Stream* stream, UInt32* value) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*--------------------------------------------------Read/Write strings-----------------------------------------------------*
|
*--------------------------------------------------Read/Write strings-----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
ReturnCode Stream_ReadUtf8(struct Stream* stream, UInt16* codepoint) {
|
ReturnCode Stream_ReadUtf8(struct Stream* stream, Codepoint* cp) {
|
||||||
UInt8 data;
|
uint8_t data;
|
||||||
ReturnCode res = stream->ReadU8(stream, &data);
|
ReturnCode res = stream->ReadU8(stream, &data);
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
|
|
||||||
/* Header byte is just the raw codepoint (common case) */
|
/* Header byte is just the raw codepoint (common case) */
|
||||||
if (data <= 0x7F) { *codepoint = data; return 0; }
|
if (data <= 0x7F) { *cp = data; return 0; }
|
||||||
|
|
||||||
/* Header byte encodes variable number of following bytes */
|
/* Header byte encodes variable number of following bytes */
|
||||||
/* The remaining bits of the header form first part of the character */
|
/* The remaining bits of the header form first part of the character */
|
||||||
@ -328,19 +328,19 @@ ReturnCode Stream_ReadUtf8(struct Stream* stream, UInt16* codepoint) {
|
|||||||
for (i = 7; i >= 0; i--) {
|
for (i = 7; i >= 0; i--) {
|
||||||
if (data & (1 << i)) {
|
if (data & (1 << i)) {
|
||||||
byteCount++;
|
byteCount++;
|
||||||
data &= (UInt8)~(1 << i);
|
data &= (uint8_t)~(1 << i);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*codepoint = data;
|
*cp = data;
|
||||||
for (i = 0; i < byteCount - 1; i++) {
|
for (i = 0; i < byteCount - 1; i++) {
|
||||||
if ((res = stream->ReadU8(stream, &data))) return res;
|
if ((res = stream->ReadU8(stream, &data))) return res;
|
||||||
|
|
||||||
*codepoint <<= 6;
|
*cp <<= 6;
|
||||||
/* Top two bits of each are always 10 */
|
/* Top two bits of each are always 10 */
|
||||||
*codepoint |= (UInt16)(data & 0x3F);
|
*cp |= (Codepoint)(data & 0x3F);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -348,41 +348,41 @@ ReturnCode Stream_ReadUtf8(struct Stream* stream, UInt16* codepoint) {
|
|||||||
ReturnCode Stream_ReadLine(struct Stream* stream, String* text) {
|
ReturnCode Stream_ReadLine(struct Stream* stream, String* text) {
|
||||||
text->length = 0;
|
text->length = 0;
|
||||||
bool readAny = false;
|
bool readAny = false;
|
||||||
UInt16 codepoint;
|
Codepoint cp;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ReturnCode res = Stream_ReadUtf8(stream, &codepoint);
|
ReturnCode res = Stream_ReadUtf8(stream, &cp);
|
||||||
if (res == ERR_END_OF_STREAM) break;
|
if (res == ERR_END_OF_STREAM) break;
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
|
|
||||||
readAny = true;
|
readAny = true;
|
||||||
/* Handle \r\n or \n line endings */
|
/* Handle \r\n or \n line endings */
|
||||||
if (codepoint == '\r') continue;
|
if (cp == '\r') continue;
|
||||||
if (codepoint == '\n') return 0;
|
if (cp == '\n') return 0;
|
||||||
String_Append(text, Convert_UnicodeToCP437(codepoint));
|
String_Append(text, Convert_UnicodeToCP437(cp));
|
||||||
}
|
}
|
||||||
return readAny ? 0 : ERR_END_OF_STREAM;
|
return readAny ? 0 : ERR_END_OF_STREAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Stream_WriteUtf8(UInt8* buffer, UInt16 codepoint) {
|
int Stream_WriteUtf8(uint8_t* buffer, Codepoint cp) {
|
||||||
if (codepoint <= 0x7F) {
|
if (cp <= 0x7F) {
|
||||||
buffer[0] = (UInt8)codepoint;
|
buffer[0] = (uint8_t)cp;
|
||||||
return 1;
|
return 1;
|
||||||
} else if (codepoint <= 0x7FF) {
|
} else if (cp <= 0x7FF) {
|
||||||
buffer[0] = 0xC0 | ((codepoint >> 6) & 0x1F);
|
buffer[0] = 0xC0 | ((cp >> 6) & 0x1F);
|
||||||
buffer[1] = 0x80 | ((codepoint) & 0x3F);
|
buffer[1] = 0x80 | ((cp) & 0x3F);
|
||||||
return 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
buffer[0] = 0xE0 | ((codepoint >> 12) & 0x0F);
|
buffer[0] = 0xE0 | ((cp >> 12) & 0x0F);
|
||||||
buffer[1] = 0x80 | ((codepoint >> 6) & 0x3F);
|
buffer[1] = 0x80 | ((cp >> 6) & 0x3F);
|
||||||
buffer[2] = 0x80 | ((codepoint) & 0x3F);
|
buffer[2] = 0x80 | ((cp) & 0x3F);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnCode Stream_WriteLine(struct Stream* stream, String* text) {
|
ReturnCode Stream_WriteLine(struct Stream* stream, String* text) {
|
||||||
UInt8 buffer[2048 + 10];
|
uint8_t buffer[2048 + 10];
|
||||||
UInt32 i, j = 0;
|
int i, j = 0;
|
||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
for (i = 0; i < text->length; i++) {
|
for (i = 0; i < text->length; i++) {
|
||||||
@ -392,12 +392,12 @@ ReturnCode Stream_WriteLine(struct Stream* stream, String* text) {
|
|||||||
j = 0;
|
j = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt8* cur = buffer + j;
|
uint8_t* cur = buffer + j;
|
||||||
UInt16 codepoint = Convert_CP437ToUnicode(text->buffer[i]);
|
Codepoint cp = Convert_CP437ToUnicode(text->buffer[i]);
|
||||||
j += Stream_WriteUtf8(cur, codepoint);
|
j += Stream_WriteUtf8(cur, cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt8* ptr = Platform_NewLine;
|
uint8_t* ptr = Platform_NewLine;
|
||||||
while (*ptr) { buffer[j++] = *ptr++; }
|
while (*ptr) { buffer[j++] = *ptr++; }
|
||||||
return Stream_Write(stream, buffer, j);
|
return Stream_Write(stream, buffer, j);
|
||||||
}
|
}
|
||||||
|
36
src/Stream.h
36
src/Stream.h
@ -11,9 +11,9 @@ enum STREAM_SEEKFROM { STREAM_SEEKFROM_BEGIN, STREAM_SEEKFROM_CURRENT, STREAM_SE
|
|||||||
struct Stream;
|
struct Stream;
|
||||||
/* Represents a stream that can be written to and/or read from. */
|
/* Represents a stream that can be written to and/or read from. */
|
||||||
struct Stream {
|
struct Stream {
|
||||||
ReturnCode (*Read)(struct Stream* stream, UInt8* data, UInt32 count, UInt32* modified);
|
ReturnCode (*Read)(struct Stream* stream, uint8_t* data, UInt32 count, UInt32* modified);
|
||||||
ReturnCode (*ReadU8)(struct Stream* stream, UInt8* data);
|
ReturnCode (*ReadU8)(struct Stream* stream, uint8_t* data);
|
||||||
ReturnCode (*Write)(struct Stream* stream, UInt8* data, UInt32 count, UInt32* modified);
|
ReturnCode (*Write)(struct Stream* stream, uint8_t* data, UInt32 count, UInt32* modified);
|
||||||
ReturnCode (*Seek)(struct Stream* stream, int offset, int seekType);
|
ReturnCode (*Seek)(struct Stream* stream, int offset, int seekType);
|
||||||
ReturnCode (*Position)(struct Stream* stream, UInt32* pos);
|
ReturnCode (*Position)(struct Stream* stream, UInt32* pos);
|
||||||
ReturnCode (*Length)(struct Stream* stream, UInt32* length);
|
ReturnCode (*Length)(struct Stream* stream, UInt32* length);
|
||||||
@ -23,19 +23,19 @@ struct Stream {
|
|||||||
void* File;
|
void* File;
|
||||||
void* Inflate;
|
void* Inflate;
|
||||||
/* NOTE: These structs rely on overlapping Meta_Mem fields being the same! Don't change them */
|
/* NOTE: These structs rely on overlapping Meta_Mem fields being the same! Don't change them */
|
||||||
struct { UInt8* Cur; UInt32 Left, Length; UInt8* Base; } Mem;
|
struct { uint8_t* Cur; UInt32 Left, Length; uint8_t* Base; } Mem;
|
||||||
struct { struct Stream* Source; UInt32 Left, Length; } Portion;
|
struct { struct Stream* Source; UInt32 Left, Length; } Portion;
|
||||||
struct { UInt8* Cur; UInt32 Left, Length; UInt8* Base; struct Stream* Source; } Buffered;
|
struct { uint8_t* Cur; UInt32 Left, Length; uint8_t* Base; struct Stream* Source; } Buffered;
|
||||||
struct { UInt8* Cur; UInt32 Left, Last; UInt8* Base; struct Stream* Source; } Ogg;
|
struct { uint8_t* Cur; UInt32 Left, Last; uint8_t* Base; struct Stream* Source; } Ogg;
|
||||||
struct { struct Stream* Source; UInt32 CRC32; } CRC32;
|
struct { struct Stream* Source; UInt32 CRC32; } CRC32;
|
||||||
} Meta;
|
} Meta;
|
||||||
};
|
};
|
||||||
|
|
||||||
ReturnCode Stream_Read(struct Stream* stream, UInt8* buffer, UInt32 count);
|
ReturnCode Stream_Read(struct Stream* stream, uint8_t* buffer, UInt32 count);
|
||||||
ReturnCode Stream_Write(struct Stream* stream, UInt8* buffer, UInt32 count);
|
ReturnCode Stream_Write(struct Stream* stream, uint8_t* buffer, UInt32 count);
|
||||||
void Stream_Init(struct Stream* stream);
|
void Stream_Init(struct Stream* stream);
|
||||||
ReturnCode Stream_Skip(struct Stream* stream, UInt32 count);
|
ReturnCode Stream_Skip(struct Stream* stream, UInt32 count);
|
||||||
ReturnCode Stream_DefaultReadU8(struct Stream* stream, UInt8* data);
|
ReturnCode Stream_DefaultReadU8(struct Stream* stream, uint8_t* data);
|
||||||
|
|
||||||
NOINLINE_ void Stream_FromFile(struct Stream* stream, void* file);
|
NOINLINE_ void Stream_FromFile(struct Stream* stream, void* file);
|
||||||
/* Readonly Stream wrapping another Stream, only allows reading up to 'len' bytes from the wrapped stream. */
|
/* Readonly Stream wrapping another Stream, only allows reading up to 'len' bytes from the wrapped stream. */
|
||||||
@ -44,19 +44,19 @@ NOINLINE_ void Stream_ReadonlyMemory(struct Stream* stream, void* data, UInt32 l
|
|||||||
NOINLINE_ void Stream_WriteonlyMemory(struct Stream* stream, void* data, UInt32 len);
|
NOINLINE_ void Stream_WriteonlyMemory(struct Stream* stream, void* data, UInt32 len);
|
||||||
NOINLINE_ void Stream_ReadonlyBuffered(struct Stream* stream, struct Stream* source, void* data, UInt32 size);
|
NOINLINE_ void Stream_ReadonlyBuffered(struct Stream* stream, struct Stream* source, void* data, UInt32 size);
|
||||||
|
|
||||||
UInt16 Stream_GetU16_LE(UInt8* data);
|
uint16_t Stream_GetU16_LE(uint8_t* data);
|
||||||
UInt16 Stream_GetU16_BE(UInt8* data);
|
uint16_t Stream_GetU16_BE(uint8_t* data);
|
||||||
UInt32 Stream_GetU32_LE(UInt8* data);
|
UInt32 Stream_GetU32_LE(uint8_t* data);
|
||||||
UInt32 Stream_GetU32_BE(UInt8* data);
|
UInt32 Stream_GetU32_BE(uint8_t* data);
|
||||||
|
|
||||||
void Stream_SetU16_BE(UInt8* data, UInt16 value);
|
void Stream_SetU16_BE(uint8_t* data, uint16_t value);
|
||||||
void Stream_SetU32_LE(UInt8* data, UInt32 value);
|
void Stream_SetU32_LE(uint8_t* data, UInt32 value);
|
||||||
void Stream_SetU32_BE(UInt8* data, UInt32 value);
|
void Stream_SetU32_BE(uint8_t* data, UInt32 value);
|
||||||
ReturnCode Stream_ReadU32_LE(struct Stream* stream, UInt32* value);
|
ReturnCode Stream_ReadU32_LE(struct Stream* stream, UInt32* value);
|
||||||
ReturnCode Stream_ReadU32_BE(struct Stream* stream, UInt32* value);
|
ReturnCode Stream_ReadU32_BE(struct Stream* stream, UInt32* value);
|
||||||
|
|
||||||
ReturnCode Stream_ReadUtf8(struct Stream* stream, UInt16* codepoint);
|
ReturnCode Stream_ReadUtf8(struct Stream* stream, Codepoint* cp);
|
||||||
ReturnCode Stream_ReadLine(struct Stream* stream, String* text);
|
ReturnCode Stream_ReadLine(struct Stream* stream, String* text);
|
||||||
int Stream_WriteUtf8(UInt8* buffer, UInt16 codepoint);
|
int Stream_WriteUtf8(uint8_t* buffer, Codepoint cp);
|
||||||
ReturnCode Stream_WriteLine(struct Stream* stream, String* text);
|
ReturnCode Stream_WriteLine(struct Stream* stream, String* text);
|
||||||
#endif
|
#endif
|
||||||
|
40
src/String.c
40
src/String.c
@ -11,31 +11,31 @@ char Char_ToLower(char c) {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
String String_Init(STRING_REF char* buffer, UInt16 length, UInt16 capacity) {
|
String String_Init(STRING_REF char* buffer, uint16_t length, uint16_t capacity) {
|
||||||
String str = { buffer, length, capacity }; return str;
|
String str = { buffer, length, capacity }; return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
String String_InitAndClear(STRING_REF char* buffer, UInt16 capacity) {
|
String String_InitAndClear(STRING_REF char* buffer, uint16_t capacity) {
|
||||||
String str = String_Init(buffer, 0, capacity);
|
String str = String_Init(buffer, 0, capacity);
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < capacity; i++) { buffer[i] = '\0'; }
|
for (i = 0; i < capacity; i++) { buffer[i] = '\0'; }
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt16 String_CalcLen(const char* raw, UInt16 capacity) {
|
uint16_t String_CalcLen(const char* raw, uint16_t capacity) {
|
||||||
UInt16 length = 0;
|
uint16_t length = 0;
|
||||||
while (length < capacity && *raw) { raw++; length++; }
|
while (length < capacity && *raw) { raw++; length++; }
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
String String_MakeNull(void) { return String_Init(NULL, 0, 0); }
|
String String_MakeNull(void) { return String_Init(NULL, 0, 0); }
|
||||||
|
|
||||||
String String_FromRaw(STRING_REF char* buffer, UInt16 capacity) {
|
String String_FromRaw(STRING_REF char* buffer, uint16_t capacity) {
|
||||||
return String_Init(buffer, String_CalcLen(buffer, capacity), capacity);
|
return String_Init(buffer, String_CalcLen(buffer, capacity), capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String_FromReadonly(STRING_REF const char* buffer) {
|
String String_FromReadonly(STRING_REF const char* buffer) {
|
||||||
UInt16 len = String_CalcLen(buffer, UInt16_MaxValue);
|
uint16_t len = String_CalcLen(buffer, UInt16_MaxValue);
|
||||||
return String_Init(buffer, len, len);
|
return String_Init(buffer, len, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,14 +473,14 @@ void String_Format4(String* str, const char* format, const void* a1, const void*
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------------Conversions-------------------------------------------------------*
|
*-------------------------------------------------------Conversions-------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
UInt16 Convert_ControlChars[32] = {
|
Codepoint Convert_ControlChars[32] = {
|
||||||
0x0000, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,
|
0x0000, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,
|
||||||
0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C,
|
0x25D8, 0x25CB, 0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C,
|
||||||
0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8,
|
0x25BA, 0x25C4, 0x2195, 0x203C, 0x00B6, 0x00A7, 0x25AC, 0x21A8,
|
||||||
0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC
|
0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194, 0x25B2, 0x25BC
|
||||||
};
|
};
|
||||||
|
|
||||||
UInt16 Convert_ExtendedChars[129] = { 0x2302,
|
Codepoint Convert_ExtendedChars[129] = { 0x2302,
|
||||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
|
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
|
||||||
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
|
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
|
||||||
@ -499,26 +499,26 @@ UInt16 Convert_ExtendedChars[129] = { 0x2302,
|
|||||||
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||||
};
|
};
|
||||||
|
|
||||||
UInt16 Convert_CP437ToUnicode(char c) {
|
Codepoint Convert_CP437ToUnicode(char c) {
|
||||||
UInt8 raw = (UInt8)c;
|
UInt8 raw = (UInt8)c;
|
||||||
if (raw < 0x20) return Convert_ControlChars[raw];
|
if (raw < 0x20) return Convert_ControlChars[raw];
|
||||||
if (raw < 0x7F) return raw;
|
if (raw < 0x7F) return raw;
|
||||||
return Convert_ExtendedChars[raw - 0x7F];
|
return Convert_ExtendedChars[raw - 0x7F];
|
||||||
}
|
}
|
||||||
|
|
||||||
char Convert_UnicodeToCP437(UInt16 c) {
|
char Convert_UnicodeToCP437(Codepoint cp) {
|
||||||
char value; Convert_TryUnicodeToCP437(c, &value); return value;
|
char value; Convert_TryUnicodeToCP437(cp, &value); return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Convert_TryUnicodeToCP437(UInt16 c, char* value) {
|
bool Convert_TryUnicodeToCP437(Codepoint cp, char* value) {
|
||||||
if (c >= 0x20 && c < 0x7F) { *value = (char)c; return true; }
|
if (cp >= 0x20 && cp < 0x7F) { *value = (char)cp; return true; }
|
||||||
UInt32 i;
|
UInt32 i;
|
||||||
|
|
||||||
for (i = 0; i < Array_Elems(Convert_ControlChars); i++) {
|
for (i = 0; i < Array_Elems(Convert_ControlChars); i++) {
|
||||||
if (Convert_ControlChars[i] == c) { *value = i; return true; }
|
if (Convert_ControlChars[i] == cp) { *value = i; return true; }
|
||||||
}
|
}
|
||||||
for (i = 0; i < Array_Elems(Convert_ExtendedChars); i++) {
|
for (i = 0; i < Array_Elems(Convert_ExtendedChars); i++) {
|
||||||
if (Convert_ExtendedChars[i] == c) { *value = i + 0x7F; return true; }
|
if (Convert_ExtendedChars[i] == cp) { *value = i + 0x7F; return true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
*value = '?'; return false;
|
*value = '?'; return false;
|
||||||
@ -526,12 +526,12 @@ bool Convert_TryUnicodeToCP437(UInt16 c, char* value) {
|
|||||||
|
|
||||||
void String_DecodeUtf8(String* str, UInt8* data, UInt32 len) {
|
void String_DecodeUtf8(String* str, UInt8* data, UInt32 len) {
|
||||||
struct Stream mem; Stream_ReadonlyMemory(&mem, data, len);
|
struct Stream mem; Stream_ReadonlyMemory(&mem, data, len);
|
||||||
UInt16 codepoint;
|
Codepoint cp;
|
||||||
|
|
||||||
while (mem.Meta.Mem.Left) {
|
while (mem.Meta.Mem.Left) {
|
||||||
ReturnCode res = Stream_ReadUtf8(&mem, &codepoint);
|
ReturnCode res = Stream_ReadUtf8(&mem, &cp);
|
||||||
if (res) break; /* Memory read only returns ERR_END_OF_STREAM */
|
if (res) break; /* Memory read only returns ERR_END_OF_STREAM */
|
||||||
String_Append(str, Convert_UnicodeToCP437(codepoint));
|
String_Append(str, Convert_UnicodeToCP437(cp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,10 +547,10 @@ bool Convert_TryParseInt16(const String* str, Int16* value) {
|
|||||||
*value = (Int16)tmp; return true;
|
*value = (Int16)tmp; return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Convert_TryParseUInt16(const String* str, UInt16* value) {
|
bool Convert_TryParseUInt16(const String* str, uint16_t* value) {
|
||||||
*value = 0; Int32 tmp;
|
*value = 0; Int32 tmp;
|
||||||
if (!Convert_TryParseInt32(str, &tmp) || tmp < 0 || tmp > UInt16_MaxValue) return false;
|
if (!Convert_TryParseInt32(str, &tmp) || tmp < 0 || tmp > UInt16_MaxValue) return false;
|
||||||
*value = (UInt16)tmp; return true;
|
*value = (uint16_t)tmp; return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int Convert_CompareDigits(const char* digits, const char* magnitude) {
|
static int Convert_CompareDigits(const char* digits, const char* magnitude) {
|
||||||
|
32
src/String.h
32
src/String.h
@ -16,29 +16,29 @@ Thus it is **NOT SAFE** to allocate a string on the stack. */
|
|||||||
char Char_ToLower(char c);
|
char Char_ToLower(char c);
|
||||||
|
|
||||||
typedef struct String_ {
|
typedef struct String_ {
|
||||||
char* buffer; /* Pointer to characters, NOT NULL TERMINATED */
|
char* buffer; /* Pointer to characters, NOT NULL TERMINATED */
|
||||||
UInt16 length; /* Number of characters used */
|
uint16_t length; /* Number of characters used */
|
||||||
UInt16 capacity; /* Max number of characters */
|
uint16_t capacity; /* Max number of characters */
|
||||||
} String;
|
} String;
|
||||||
|
|
||||||
UInt16 String_CalcLen(const char* raw, UInt16 capacity);
|
uint16_t String_CalcLen(const char* raw, uint16_t capacity);
|
||||||
String String_MakeNull(void);
|
String String_MakeNull(void);
|
||||||
String String_Init(STRING_REF char* buffer, UInt16 length, UInt16 capacity);
|
String String_Init(STRING_REF char* buffer, uint16_t length, uint16_t capacity);
|
||||||
String String_InitAndClear(STRING_REF char* buffer, UInt16 capacity);
|
String String_InitAndClear(STRING_REF char* buffer, uint16_t capacity);
|
||||||
/* Constructs a new string from a (maybe null terminated) buffer. */
|
/* Constructs a new string from a (maybe null terminated) buffer. */
|
||||||
NOINLINE_ String String_FromRaw(STRING_REF char* buffer, UInt16 capacity);
|
NOINLINE_ String String_FromRaw(STRING_REF char* buffer, uint16_t capacity);
|
||||||
/* Constructs a new string from a null-terminated constant readonly buffer. */
|
/* Constructs a new string from a null-terminated constant readonly buffer. */
|
||||||
NOINLINE_ String String_FromReadonly(STRING_REF const char* buffer);
|
NOINLINE_ String String_FromReadonly(STRING_REF const char* buffer);
|
||||||
|
|
||||||
#define String_ClearedArray(buffer) String_InitAndClear(buffer, (UInt16)sizeof(buffer))
|
#define String_ClearedArray(buffer) String_InitAndClear(buffer, (uint16_t)sizeof(buffer))
|
||||||
/* Constructs a string from a compile time string constant */
|
/* Constructs a string from a compile time string constant */
|
||||||
#define String_FromConst(text) { text, (UInt16)(sizeof(text) - 1), (UInt16)(sizeof(text) - 1)}
|
#define String_FromConst(text) { text, (uint16_t)(sizeof(text) - 1), (uint16_t)(sizeof(text) - 1)}
|
||||||
/* Constructs a string from a compile time array */
|
/* Constructs a string from a compile time array */
|
||||||
#define String_FromArray(buffer) { buffer, 0, (UInt16)sizeof(buffer)}
|
#define String_FromArray(buffer) { buffer, 0, (uint16_t)sizeof(buffer)}
|
||||||
/* Constructs a string from a compile time array, that may have arbitary actual length of data at runtime */
|
/* Constructs a string from a compile time array, that may have arbitary actual length of data at runtime */
|
||||||
#define String_FromRawArray(buffer) String_FromRaw(buffer, (UInt16)sizeof(buffer))
|
#define String_FromRawArray(buffer) String_FromRaw(buffer, (uint16_t)sizeof(buffer))
|
||||||
/* Constructs a string from a compile time array (leaving 1 byte of room for null terminator) */
|
/* Constructs a string from a compile time array (leaving 1 byte of room for null terminator) */
|
||||||
#define String_NT_Array(buffer) { buffer, 0, (UInt16)(sizeof(buffer) - 1)}
|
#define String_NT_Array(buffer) { buffer, 0, (uint16_t)(sizeof(buffer) - 1)}
|
||||||
|
|
||||||
NOINLINE_ void String_StripCols(String* str);
|
NOINLINE_ void String_StripCols(String* str);
|
||||||
NOINLINE_ void String_Copy(String* dst, const String* src);
|
NOINLINE_ void String_Copy(String* dst, const String* src);
|
||||||
@ -82,14 +82,14 @@ void String_Format2(String* str, const char* format, const void* a1, const void*
|
|||||||
void String_Format3(String* str, const char* format, const void* a1, const void* a2, const void* a3);
|
void String_Format3(String* str, const char* format, const void* a1, const void* a2, const void* a3);
|
||||||
void String_Format4(String* str, const char* format, const void* a1, const void* a2, const void* a3, const void* a4);
|
void String_Format4(String* str, const char* format, const void* a1, const void* a2, const void* a3, const void* a4);
|
||||||
|
|
||||||
UInt16 Convert_CP437ToUnicode(char c);
|
Codepoint Convert_CP437ToUnicode(char c);
|
||||||
char Convert_UnicodeToCP437(UInt16 c);
|
char Convert_UnicodeToCP437(Codepoint cp);
|
||||||
bool Convert_TryUnicodeToCP437(UInt16 c, char* value);
|
bool Convert_TryUnicodeToCP437(Codepoint cp, char* value);
|
||||||
void String_DecodeUtf8(String* str, UInt8* data, UInt32 len);
|
void String_DecodeUtf8(String* str, UInt8* data, UInt32 len);
|
||||||
|
|
||||||
NOINLINE_ bool Convert_TryParseUInt8(const String* str, UInt8* value);
|
NOINLINE_ bool Convert_TryParseUInt8(const String* str, UInt8* value);
|
||||||
NOINLINE_ bool Convert_TryParseInt16(const String* str, Int16* value);
|
NOINLINE_ bool Convert_TryParseInt16(const String* str, Int16* value);
|
||||||
NOINLINE_ bool Convert_TryParseUInt16(const String* str, UInt16* value);
|
NOINLINE_ bool Convert_TryParseUInt16(const String* str, uint16_t* value);
|
||||||
NOINLINE_ bool Convert_TryParseInt32(const String* str, Int32* value);
|
NOINLINE_ bool Convert_TryParseInt32(const String* str, Int32* value);
|
||||||
NOINLINE_ bool Convert_TryParseUInt64(const String* str, UInt64* value);
|
NOINLINE_ bool Convert_TryParseUInt64(const String* str, UInt64* value);
|
||||||
NOINLINE_ bool Convert_TryParseFloat(const String* str, float* value);
|
NOINLINE_ bool Convert_TryParseFloat(const String* str, float* value);
|
||||||
|
@ -29,7 +29,7 @@ static ReturnCode Zip_ReadLocalFileHeader(struct ZipState* state, struct ZipEntr
|
|||||||
|
|
||||||
/* contents[0] (2) version needed */
|
/* contents[0] (2) version needed */
|
||||||
/* contents[2] (2) flags */
|
/* contents[2] (2) flags */
|
||||||
UInt16 compressionMethod = Stream_GetU16_LE(&contents[4]);
|
int method = Stream_GetU16_LE(&contents[4]);
|
||||||
/* contents[6] (4) last modified */
|
/* contents[6] (4) last modified */
|
||||||
/* contents[10] (4) CRC32 */
|
/* contents[10] (4) CRC32 */
|
||||||
|
|
||||||
@ -38,8 +38,8 @@ static ReturnCode Zip_ReadLocalFileHeader(struct ZipState* state, struct ZipEntr
|
|||||||
UInt32 uncompressedSize = Stream_GetU32_LE(&contents[18]);
|
UInt32 uncompressedSize = Stream_GetU32_LE(&contents[18]);
|
||||||
if (!uncompressedSize) uncompressedSize = entry->UncompressedSize;
|
if (!uncompressedSize) uncompressedSize = entry->UncompressedSize;
|
||||||
|
|
||||||
UInt16 pathLen = Stream_GetU16_LE(&contents[22]);
|
int pathLen = Stream_GetU16_LE(&contents[22]);
|
||||||
UInt16 extraLen = Stream_GetU16_LE(&contents[24]);
|
int extraLen = Stream_GetU16_LE(&contents[24]);
|
||||||
char pathBuffer[ZIP_MAXNAMELEN];
|
char pathBuffer[ZIP_MAXNAMELEN];
|
||||||
|
|
||||||
if (pathLen > ZIP_MAXNAMELEN) return ZIP_ERR_FILENAME_LEN;
|
if (pathLen > ZIP_MAXNAMELEN) return ZIP_ERR_FILENAME_LEN;
|
||||||
@ -51,16 +51,15 @@ static ReturnCode Zip_ReadLocalFileHeader(struct ZipState* state, struct ZipEntr
|
|||||||
if ((res = Stream_Skip(stream, extraLen))) return res;
|
if ((res = Stream_Skip(stream, extraLen))) return res;
|
||||||
struct Stream portion, compStream;
|
struct Stream portion, compStream;
|
||||||
|
|
||||||
if (compressionMethod == 0) {
|
if (method == 0) {
|
||||||
Stream_ReadonlyPortion(&portion, stream, uncompressedSize);
|
Stream_ReadonlyPortion(&portion, stream, uncompressedSize);
|
||||||
state->ProcessEntry(&path, &portion, entry);
|
state->ProcessEntry(&path, &portion, entry);
|
||||||
} else if (compressionMethod == 8) {
|
} else if (method == 8) {
|
||||||
struct InflateState inflate;
|
struct InflateState inflate;
|
||||||
Stream_ReadonlyPortion(&portion, stream, compressedSize);
|
Stream_ReadonlyPortion(&portion, stream, compressedSize);
|
||||||
Inflate_MakeStream(&compStream, &inflate, &portion);
|
Inflate_MakeStream(&compStream, &inflate, &portion);
|
||||||
state->ProcessEntry(&path, &compStream, entry);
|
state->ProcessEntry(&path, &compStream, entry);
|
||||||
} else {
|
} else {
|
||||||
int method = compressionMethod;
|
|
||||||
Platform_Log1("Unsupported.zip entry compression method: %i", &method);
|
Platform_Log1("Unsupported.zip entry compression method: %i", &method);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -81,9 +80,9 @@ static ReturnCode Zip_ReadCentralDirectory(struct ZipState* state, struct ZipEnt
|
|||||||
entry->CompressedSize = Stream_GetU32_LE(&contents[16]);
|
entry->CompressedSize = Stream_GetU32_LE(&contents[16]);
|
||||||
entry->UncompressedSize = Stream_GetU32_LE(&contents[20]);
|
entry->UncompressedSize = Stream_GetU32_LE(&contents[20]);
|
||||||
|
|
||||||
UInt16 pathLen = Stream_GetU16_LE(&contents[24]);
|
int pathLen = Stream_GetU16_LE(&contents[24]);
|
||||||
UInt16 extraLen = Stream_GetU16_LE(&contents[26]);
|
int extraLen = Stream_GetU16_LE(&contents[26]);
|
||||||
UInt16 commentLen = Stream_GetU16_LE(&contents[28]);
|
int commentLen = Stream_GetU16_LE(&contents[28]);
|
||||||
/* contents[30] (2) disk number */
|
/* contents[30] (2) disk number */
|
||||||
/* contents[32] (2) internal attributes */
|
/* contents[32] (2) internal attributes */
|
||||||
/* contents[34] (4) external attributes */
|
/* contents[34] (4) external attributes */
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#define DATETIME_MILLISECS_PER_DAY (1000 * 60 * 60 * 24)
|
#define DATETIME_MILLISECS_PER_DAY (1000 * 60 * 60 * 24)
|
||||||
|
|
||||||
#define DAYS_IN_400_YEARS 146097 /* (400*365) + 97 */
|
#define DAYS_IN_400_YEARS 146097 /* (400*365) + 97 */
|
||||||
UInt16 DateTime_DaysTotal[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
uint16_t DateTime_DaysTotal[13] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
||||||
UInt16 DateTime_DaysTotalLeap[13] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
|
uint16_t DateTime_DaysTotalLeap[13] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
|
||||||
|
|
||||||
static bool DateTime_IsLeapYear(int year) {
|
static bool DateTime_IsLeapYear(int year) {
|
||||||
if ((year % 4) != 0) return false;
|
if ((year % 4) != 0) return false;
|
||||||
@ -71,7 +71,7 @@ void DateTime_FromTotalMs(DateTime* time, TimeMS ms) {
|
|||||||
}
|
}
|
||||||
time->Year = year;
|
time->Year = year;
|
||||||
|
|
||||||
UInt16* totalDays = leap ? DateTime_DaysTotalLeap : DateTime_DaysTotal;
|
uint16_t* totalDays = leap ? DateTime_DaysTotalLeap : DateTime_DaysTotal;
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i <= 12; i++) {
|
for (i = 1; i <= 12; i++) {
|
||||||
if (days >= totalDays[i]) continue;
|
if (days >= totalDays[i]) continue;
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
/* Represents a particular instance in time in some timezone. Not necessarily UTC time. */
|
/* Represents a particular instance in time in some timezone. Not necessarily UTC time. */
|
||||||
typedef struct DateTime_ {
|
typedef struct DateTime_ {
|
||||||
UInt16 Year; /* Year, ranges from 0 to 65535 */
|
uint16_t Year; /* Year, ranges from 0 to 65535 */
|
||||||
UInt8 Month; /* Month, ranges from 1 to 12 */
|
UInt8 Month; /* Month, ranges from 1 to 12 */
|
||||||
UInt8 Day; /* Day, ranges from 1 to 31 */
|
UInt8 Day; /* Day, ranges from 1 to 31 */
|
||||||
UInt8 Hour; /* Hour, ranges from 0 to 23 */
|
UInt8 Hour; /* Hour, ranges from 0 to 23 */
|
||||||
UInt8 Minute; /* Minute, ranges from 0 to 59 */
|
UInt8 Minute; /* Minute, ranges from 0 to 59 */
|
||||||
UInt8 Second; /* Second, ranges from 0 to 59 */
|
UInt8 Second; /* Second, ranges from 0 to 59 */
|
||||||
UInt16 Milli; /* Milliseconds, ranges from 0 to 999 */
|
uint16_t Milli; /* Milliseconds, ranges from 0 to 999 */
|
||||||
} DateTime;
|
} DateTime;
|
||||||
|
|
||||||
#define DATETIME_MILLIS_PER_SEC 1000
|
#define DATETIME_MILLIS_PER_SEC 1000
|
||||||
|
69
src/Vorbis.c
69
src/Vorbis.c
@ -153,7 +153,7 @@ struct Codebook {
|
|||||||
/* vector quantisation values */
|
/* vector quantisation values */
|
||||||
float MinValue, DeltaValue;
|
float MinValue, DeltaValue;
|
||||||
UInt32 SequenceP, LookupType, LookupValues;
|
UInt32 SequenceP, LookupType, LookupValues;
|
||||||
UInt16* Multiplicands;
|
uint16_t* Multiplicands;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void Codebook_Free(struct Codebook* c) {
|
static void Codebook_Free(struct Codebook* c) {
|
||||||
@ -243,29 +243,29 @@ static ReturnCode Codebook_DecodeSetup(struct VorbisState* ctx, struct Codebook*
|
|||||||
c->Entries = Vorbis_ReadBits(ctx, 24);
|
c->Entries = Vorbis_ReadBits(ctx, 24);
|
||||||
|
|
||||||
UInt8* codewordLens = Mem_Alloc(c->Entries, sizeof(UInt8), "raw codeword lens");
|
UInt8* codewordLens = Mem_Alloc(c->Entries, sizeof(UInt8), "raw codeword lens");
|
||||||
Int32 i, ordered = Vorbis_ReadBits(ctx, 1), usedEntries = 0;
|
int i, ordered = Vorbis_ReadBits(ctx, 1), usedEntries = 0;
|
||||||
|
|
||||||
if (!ordered) {
|
if (!ordered) {
|
||||||
Int32 sparse = Vorbis_ReadBits(ctx, 1);
|
int sparse = Vorbis_ReadBits(ctx, 1);
|
||||||
for (i = 0; i < c->Entries; i++) {
|
for (i = 0; i < c->Entries; i++) {
|
||||||
if (sparse) {
|
if (sparse) {
|
||||||
Int32 flag = Vorbis_ReadBits(ctx, 1);
|
int flag = Vorbis_ReadBits(ctx, 1);
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
codewordLens[i] = 0;
|
codewordLens[i] = 0;
|
||||||
continue; /* unused entry */
|
continue; /* unused entry */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Int32 len = Vorbis_ReadBits(ctx, 5); len++;
|
int len = Vorbis_ReadBits(ctx, 5) + 1;
|
||||||
codewordLens[i] = len;
|
codewordLens[i] = len;
|
||||||
usedEntries++;
|
usedEntries++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Int32 entry;
|
int entry;
|
||||||
Int32 curLength = Vorbis_ReadBits(ctx, 5); curLength++;
|
int curLength = Vorbis_ReadBits(ctx, 5) + 1;
|
||||||
for (entry = 0; entry < c->Entries;) {
|
for (entry = 0; entry < c->Entries;) {
|
||||||
Int32 runBits = iLog(c->Entries - entry);
|
int runBits = iLog(c->Entries - entry);
|
||||||
Int32 runLen = Vorbis_ReadBits(ctx, runBits);
|
int runLen = Vorbis_ReadBits(ctx, runBits);
|
||||||
|
|
||||||
for (i = entry; i < entry + runLen; i++) {
|
for (i = entry; i < entry + runLen; i++) {
|
||||||
codewordLens[i] = curLength;
|
codewordLens[i] = curLength;
|
||||||
@ -287,10 +287,10 @@ static ReturnCode Codebook_DecodeSetup(struct VorbisState* ctx, struct Codebook*
|
|||||||
if (c->LookupType == 0) return 0;
|
if (c->LookupType == 0) return 0;
|
||||||
if (c->LookupType > 2) return VORBIS_ERR_CODEBOOK_LOOKUP;
|
if (c->LookupType > 2) return VORBIS_ERR_CODEBOOK_LOOKUP;
|
||||||
|
|
||||||
c->MinValue = float32_unpack(ctx);
|
c->MinValue = float32_unpack(ctx);
|
||||||
c->DeltaValue = float32_unpack(ctx);
|
c->DeltaValue = float32_unpack(ctx);
|
||||||
Int32 valueBits = Vorbis_ReadBits(ctx, 4); valueBits++;
|
int valueBits = Vorbis_ReadBits(ctx, 4) + 1;
|
||||||
c->SequenceP = Vorbis_ReadBits(ctx, 1);
|
c->SequenceP = Vorbis_ReadBits(ctx, 1);
|
||||||
|
|
||||||
UInt32 lookupValues;
|
UInt32 lookupValues;
|
||||||
if (c->LookupType == 1) {
|
if (c->LookupType == 1) {
|
||||||
@ -300,7 +300,7 @@ static ReturnCode Codebook_DecodeSetup(struct VorbisState* ctx, struct Codebook*
|
|||||||
}
|
}
|
||||||
c->LookupValues = lookupValues;
|
c->LookupValues = lookupValues;
|
||||||
|
|
||||||
c->Multiplicands = Mem_Alloc(lookupValues, sizeof(UInt16), "multiplicands");
|
c->Multiplicands = Mem_Alloc(lookupValues, 2, "multiplicands");
|
||||||
for (i = 0; i < lookupValues; i++) {
|
for (i = 0; i < lookupValues; i++) {
|
||||||
c->Multiplicands[i] = Vorbis_ReadBits(ctx, valueBits);
|
c->Multiplicands[i] = Vorbis_ReadBits(ctx, valueBits);
|
||||||
}
|
}
|
||||||
@ -369,15 +369,15 @@ struct Floor {
|
|||||||
UInt8 ClassMasterbooks[FLOOR_MAX_CLASSES];
|
UInt8 ClassMasterbooks[FLOOR_MAX_CLASSES];
|
||||||
Int16 SubclassBooks[FLOOR_MAX_CLASSES][8];
|
Int16 SubclassBooks[FLOOR_MAX_CLASSES][8];
|
||||||
Int16 XList[FLOOR_MAX_VALUES];
|
Int16 XList[FLOOR_MAX_VALUES];
|
||||||
UInt16 ListOrder[FLOOR_MAX_VALUES];
|
uint16_t ListOrder[FLOOR_MAX_VALUES];
|
||||||
Int32 YList[VORBIS_MAX_CHANS][FLOOR_MAX_VALUES];
|
Int32 YList[VORBIS_MAX_CHANS][FLOOR_MAX_VALUES];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TODO: Make this thread safe */
|
/* TODO: Make this thread safe */
|
||||||
Int16* tmp_xlist;
|
Int16* tmp_xlist;
|
||||||
UInt16* tmp_order;
|
uint16_t* tmp_order;
|
||||||
static void Floor_SortXList(int left, int right) {
|
static void Floor_SortXList(int left, int right) {
|
||||||
UInt16* values = tmp_order; UInt16 value;
|
uint16_t* values = tmp_order; uint16_t value;
|
||||||
Int16* keys = tmp_xlist; Int16 key;
|
Int16* keys = tmp_xlist; Int16 key;
|
||||||
|
|
||||||
while (left < right) {
|
while (left < right) {
|
||||||
@ -405,7 +405,7 @@ static ReturnCode Floor_DecodeSetup(struct VorbisState* ctx, struct Floor* f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i <= maxClass; i++) {
|
for (i = 0; i <= maxClass; i++) {
|
||||||
f->ClassDimensions[i] = Vorbis_ReadBits(ctx, 3); f->ClassDimensions[i]++;
|
f->ClassDimensions[i] = Vorbis_ReadBits(ctx, 3) + 1;
|
||||||
f->ClassSubClasses[i] = Vorbis_ReadBits(ctx, 2);
|
f->ClassSubClasses[i] = Vorbis_ReadBits(ctx, 2);
|
||||||
if (f->ClassSubClasses[i]) {
|
if (f->ClassSubClasses[i]) {
|
||||||
f->ClassMasterbooks[i] = Vorbis_ReadBits(ctx, 8);
|
f->ClassMasterbooks[i] = Vorbis_ReadBits(ctx, 8);
|
||||||
@ -415,7 +415,7 @@ static ReturnCode Floor_DecodeSetup(struct VorbisState* ctx, struct Floor* f) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f->Multiplier = Vorbis_ReadBits(ctx, 2); f->Multiplier++;
|
f->Multiplier = Vorbis_ReadBits(ctx, 2) + 1;
|
||||||
static Int16 ranges[4] = { 256, 128, 84, 64 };
|
static Int16 ranges[4] = { 256, 128, 84, 64 };
|
||||||
f->Range = ranges[f->Multiplier - 1];
|
f->Range = ranges[f->Multiplier - 1];
|
||||||
|
|
||||||
@ -628,16 +628,17 @@ static ReturnCode Residue_DecodeSetup(struct VorbisState* ctx, struct Residue* r
|
|||||||
r->Type = (UInt8)type;
|
r->Type = (UInt8)type;
|
||||||
r->Begin = Vorbis_ReadBits(ctx, 24);
|
r->Begin = Vorbis_ReadBits(ctx, 24);
|
||||||
r->End = Vorbis_ReadBits(ctx, 24);
|
r->End = Vorbis_ReadBits(ctx, 24);
|
||||||
r->PartitionSize = Vorbis_ReadBits(ctx, 24); r->PartitionSize++;
|
r->PartitionSize = Vorbis_ReadBits(ctx, 24) + 1;
|
||||||
r->Classifications = Vorbis_ReadBits(ctx, 6); r->Classifications++;
|
r->Classifications = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
r->Classbook = Vorbis_ReadBits(ctx, 8);
|
r->Classbook = Vorbis_ReadBits(ctx, 8);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < r->Classifications; i++) {
|
for (i = 0; i < r->Classifications; i++) {
|
||||||
r->Cascade[i] = Vorbis_ReadBits(ctx, 3);
|
r->Cascade[i] = Vorbis_ReadBits(ctx, 3);
|
||||||
Int32 moreBits = Vorbis_ReadBits(ctx, 1);
|
int moreBits = Vorbis_ReadBits(ctx, 1);
|
||||||
if (!moreBits) continue;
|
if (!moreBits) continue;
|
||||||
Int32 bits = Vorbis_ReadBits(ctx, 5);
|
|
||||||
|
int bits = Vorbis_ReadBits(ctx, 5);
|
||||||
r->Cascade[i] |= bits << 3;
|
r->Cascade[i] |= bits << 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -771,7 +772,7 @@ static ReturnCode Mapping_DecodeSetup(struct VorbisState* ctx, struct Mapping* m
|
|||||||
|
|
||||||
int couplingSteps = 0, couplingFlag = Vorbis_ReadBits(ctx, 1);
|
int couplingSteps = 0, couplingFlag = Vorbis_ReadBits(ctx, 1);
|
||||||
if (couplingFlag) {
|
if (couplingFlag) {
|
||||||
couplingSteps = Vorbis_ReadBits(ctx, 8); couplingSteps++;
|
couplingSteps = Vorbis_ReadBits(ctx, 8) + 1;
|
||||||
/* TODO: How big can couplingSteps ever really get in practice? */
|
/* TODO: How big can couplingSteps ever really get in practice? */
|
||||||
int couplingBits = iLog(ctx->Channels - 1);
|
int couplingBits = iLog(ctx->Channels - 1);
|
||||||
for (i = 0; i < couplingSteps; i++) {
|
for (i = 0; i < couplingSteps; i++) {
|
||||||
@ -987,7 +988,7 @@ static bool Vorbis_ValidBlockSize(UInt32 size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ReturnCode Vorbis_CheckHeader(struct VorbisState* ctx, UInt8 type) {
|
static ReturnCode Vorbis_CheckHeader(struct VorbisState* ctx, UInt8 type) {
|
||||||
UInt8 header[7];
|
uint8_t header[7];
|
||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
if ((res = Stream_Read(ctx->Source, header, sizeof(header)))) return res;
|
if ((res = Stream_Read(ctx->Source, header, sizeof(header)))) return res;
|
||||||
|
|
||||||
@ -999,7 +1000,7 @@ static ReturnCode Vorbis_CheckHeader(struct VorbisState* ctx, UInt8 type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ReturnCode Vorbis_DecodeIdentifier(struct VorbisState* ctx) {
|
static ReturnCode Vorbis_DecodeIdentifier(struct VorbisState* ctx) {
|
||||||
UInt8 header[23];
|
uint8_t header[23];
|
||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
if ((res = Stream_Read(ctx->Source, header, sizeof(header)))) return res;
|
if ((res = Stream_Read(ctx->Source, header, sizeof(header)))) return res;
|
||||||
|
|
||||||
@ -1038,7 +1039,7 @@ static ReturnCode Vorbis_DecodeComments(struct VorbisState* ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check framing flag */
|
/* check framing flag */
|
||||||
UInt8 flag;
|
uint8_t flag;
|
||||||
if ((res = stream->ReadU8(stream, &flag))) return res;
|
if ((res = stream->ReadU8(stream, &flag))) return res;
|
||||||
return (flag & 1) ? 0 : VORBIS_ERR_FRAMING;
|
return (flag & 1) ? 0 : VORBIS_ERR_FRAMING;
|
||||||
}
|
}
|
||||||
@ -1047,7 +1048,7 @@ static ReturnCode Vorbis_DecodeSetup(struct VorbisState* ctx) {
|
|||||||
int i, count;
|
int i, count;
|
||||||
ReturnCode res;
|
ReturnCode res;
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 8); count++;
|
count = Vorbis_ReadBits(ctx, 8) + 1;
|
||||||
ctx->Codebooks = Mem_Alloc(count, sizeof(struct Codebook), "vorbis codebooks");
|
ctx->Codebooks = Mem_Alloc(count, sizeof(struct Codebook), "vorbis codebooks");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
res = Codebook_DecodeSetup(ctx, &ctx->Codebooks[i]);
|
res = Codebook_DecodeSetup(ctx, &ctx->Codebooks[i]);
|
||||||
@ -1055,13 +1056,13 @@ static ReturnCode Vorbis_DecodeSetup(struct VorbisState* ctx) {
|
|||||||
}
|
}
|
||||||
ctx->NumCodebooks = count;
|
ctx->NumCodebooks = count;
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6); count++;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
int time = Vorbis_ReadBits(ctx, 16);
|
int time = Vorbis_ReadBits(ctx, 16);
|
||||||
if (time != 0) return VORBIS_ERR_TIME_TYPE;
|
if (time != 0) return VORBIS_ERR_TIME_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6); count++;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
ctx->Floors = Mem_Alloc(count, sizeof(struct Floor), "vorbis floors");
|
ctx->Floors = Mem_Alloc(count, sizeof(struct Floor), "vorbis floors");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
int floor = Vorbis_ReadBits(ctx, 16);
|
int floor = Vorbis_ReadBits(ctx, 16);
|
||||||
@ -1070,7 +1071,7 @@ static ReturnCode Vorbis_DecodeSetup(struct VorbisState* ctx) {
|
|||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6); count++;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
ctx->Residues = Mem_Alloc(count, sizeof(struct Residue), "vorbis residues");
|
ctx->Residues = Mem_Alloc(count, sizeof(struct Residue), "vorbis residues");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
int residue = Vorbis_ReadBits(ctx, 16);
|
int residue = Vorbis_ReadBits(ctx, 16);
|
||||||
@ -1079,7 +1080,7 @@ static ReturnCode Vorbis_DecodeSetup(struct VorbisState* ctx) {
|
|||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6); count++;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
ctx->Mappings = Mem_Alloc(count, sizeof(struct Mapping), "vorbis mappings");
|
ctx->Mappings = Mem_Alloc(count, sizeof(struct Mapping), "vorbis mappings");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
int mapping = Vorbis_ReadBits(ctx, 16);
|
int mapping = Vorbis_ReadBits(ctx, 16);
|
||||||
@ -1088,7 +1089,7 @@ static ReturnCode Vorbis_DecodeSetup(struct VorbisState* ctx) {
|
|||||||
if (res) return res;
|
if (res) return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
count = Vorbis_ReadBits(ctx, 6); count++;
|
count = Vorbis_ReadBits(ctx, 6) + 1;
|
||||||
ctx->Modes = Mem_Alloc(count, sizeof(struct Mode), "vorbis modes");
|
ctx->Modes = Mem_Alloc(count, sizeof(struct Mode), "vorbis modes");
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
res = Mode_DecodeSetup(ctx, &ctx->Modes[i]);
|
res = Mode_DecodeSetup(ctx, &ctx->Modes[i]);
|
||||||
|
@ -28,7 +28,7 @@ struct VorbisState {
|
|||||||
struct Stream* Source; /* Source for filling Input buffer */
|
struct Stream* Source; /* Source for filling Input buffer */
|
||||||
|
|
||||||
UInt8 Channels, ModeNumBits;
|
UInt8 Channels, ModeNumBits;
|
||||||
UInt16 CurBlockSize, PrevBlockSize, DataSize, NumCodebooks;
|
uint16_t CurBlockSize, PrevBlockSize, DataSize, NumCodebooks;
|
||||||
Int32 SampleRate; Int32 BlockSizes[2];
|
Int32 SampleRate; Int32 BlockSizes[2];
|
||||||
float* Temp; /* temp array reused in places */
|
float* Temp; /* temp array reused in places */
|
||||||
float* Values[2]; /* swapped each frame */
|
float* Values[2]; /* swapped each frame */
|
||||||
|
@ -1262,8 +1262,8 @@ NOINLINE_ static void InputWidget_Create(struct InputWidget* w, FontDesc* font,
|
|||||||
String caret = String_FromConst("_");
|
String caret = String_FromConst("_");
|
||||||
struct DrawTextArgs args; DrawTextArgs_Make(&args, &caret, font, true);
|
struct DrawTextArgs args; DrawTextArgs_Make(&args, &caret, font, true);
|
||||||
Drawer2D_MakeTextTexture(&w->CaretTex, &args, 0, 0);
|
Drawer2D_MakeTextTexture(&w->CaretTex, &args, 0, 0);
|
||||||
w->CaretTex.Width = (UInt16)((w->CaretTex.Width * 3) / 4);
|
w->CaretTex.Width = (uint16_t)((w->CaretTex.Width * 3) / 4);
|
||||||
w->CaretWidth = (UInt16)w->CaretTex.Width;
|
w->CaretWidth = (uint16_t)w->CaretTex.Width;
|
||||||
|
|
||||||
if (!prefix->length) return;
|
if (!prefix->length) return;
|
||||||
DrawTextArgs_Make(&args, prefix, font, true);
|
DrawTextArgs_Make(&args, prefix, font, true);
|
||||||
@ -1934,7 +1934,7 @@ static void PlayerListWidget_DeleteGroup(struct PlayerListWidget* w, int* i) {
|
|||||||
(*i)--;
|
(*i)--;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PlayerListWidget_AddGroup(struct PlayerListWidget* w, UInt16 id, int* index) {
|
static void PlayerListWidget_AddGroup(struct PlayerListWidget* w, uint16_t id, int* index) {
|
||||||
int i;
|
int i;
|
||||||
for (i = Array_Elems(w->IDs) - 1; i > (*index); i--) {
|
for (i = Array_Elems(w->IDs) - 1; i > (*index); i--) {
|
||||||
w->IDs[i] = w->IDs[i - 1];
|
w->IDs[i] = w->IDs[i - 1];
|
||||||
@ -1949,7 +1949,7 @@ static void PlayerListWidget_AddGroup(struct PlayerListWidget* w, UInt16 id, int
|
|||||||
w->NamesCount++;
|
w->NamesCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int PlayerListWidget_GetGroupCount(struct PlayerListWidget* w, UInt16 id, int idx) {
|
static int PlayerListWidget_GetGroupCount(struct PlayerListWidget* w, uint16_t id, int idx) {
|
||||||
String group = TabList_UNSAFE_GetGroup(id);
|
String group = TabList_UNSAFE_GetGroup(id);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
@ -1961,9 +1961,9 @@ static int PlayerListWidget_GetGroupCount(struct PlayerListWidget* w, UInt16 id,
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int PlayerListWidget_PlayerCompare(UInt16 x, UInt16 y) {
|
static int PlayerListWidget_PlayerCompare(uint16_t x, uint16_t y) {
|
||||||
UInt8 xRank = TabList_GroupRanks[x];
|
uint8_t xRank = TabList_GroupRanks[x];
|
||||||
UInt8 yRank = TabList_GroupRanks[y];
|
uint8_t yRank = TabList_GroupRanks[y];
|
||||||
if (xRank != yRank) return (xRank < yRank ? -1 : 1);
|
if (xRank != yRank) return (xRank < yRank ? -1 : 1);
|
||||||
|
|
||||||
char xNameBuffer[STRING_SIZE];
|
char xNameBuffer[STRING_SIZE];
|
||||||
@ -1979,7 +1979,7 @@ static int PlayerListWidget_PlayerCompare(UInt16 x, UInt16 y) {
|
|||||||
return String_Compare(&xName, &yName);
|
return String_Compare(&xName, &yName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int PlayerListWidget_GroupCompare(UInt16 x, UInt16 y) {
|
static int PlayerListWidget_GroupCompare(uint16_t x, uint16_t y) {
|
||||||
/* TODO: should we use colourless comparison? ClassicalSharp sorts groups with colours */
|
/* TODO: should we use colourless comparison? ClassicalSharp sorts groups with colours */
|
||||||
String xGroup = TabList_UNSAFE_GetGroup(x);
|
String xGroup = TabList_UNSAFE_GetGroup(x);
|
||||||
String yGroup = TabList_UNSAFE_GetGroup(y);
|
String yGroup = TabList_UNSAFE_GetGroup(y);
|
||||||
@ -1987,14 +1987,14 @@ static int PlayerListWidget_GroupCompare(UInt16 x, UInt16 y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PlayerListWidget* List_SortObj;
|
struct PlayerListWidget* List_SortObj;
|
||||||
int (*List_SortCompare)(UInt16 x, UInt16 y);
|
int (*List_SortCompare)(uint16_t x, uint16_t y);
|
||||||
static void PlayerListWidget_QuickSort(int left, int right) {
|
static void PlayerListWidget_QuickSort(int left, int right) {
|
||||||
struct Texture* values = List_SortObj->Textures; struct Texture value;
|
struct Texture* values = List_SortObj->Textures; struct Texture value;
|
||||||
UInt16* keys = List_SortObj->IDs; UInt16 key;
|
uint16_t* keys = List_SortObj->IDs; uint16_t key;
|
||||||
|
|
||||||
while (left < right) {
|
while (left < right) {
|
||||||
int i = left, j = right;
|
int i = left, j = right;
|
||||||
UInt16 pivot = keys[(i + j) / 2];
|
uint16_t pivot = keys[(i + j) / 2];
|
||||||
|
|
||||||
/* partition the list */
|
/* partition the list */
|
||||||
while (i <= j) {
|
while (i <= j) {
|
||||||
@ -2029,7 +2029,7 @@ static void PlayerListWidget_SortEntries(struct PlayerListWidget* w) {
|
|||||||
i = 0;
|
i = 0;
|
||||||
List_SortCompare = PlayerListWidget_PlayerCompare;
|
List_SortCompare = PlayerListWidget_PlayerCompare;
|
||||||
while (i < w->NamesCount) {
|
while (i < w->NamesCount) {
|
||||||
UInt16 id = w->IDs[i];
|
uint16_t id = w->IDs[i];
|
||||||
PlayerListWidget_AddGroup(w, id, &i);
|
PlayerListWidget_AddGroup(w, id, &i);
|
||||||
int count = PlayerListWidget_GetGroupCount(w, id, i);
|
int count = PlayerListWidget_GetGroupCount(w, id, i);
|
||||||
PlayerListWidget_QuickSort(i, i + (count - 1));
|
PlayerListWidget_QuickSort(i, i + (count - 1));
|
||||||
@ -2157,7 +2157,7 @@ void PlayerListWidget_Create(struct PlayerListWidget* w, FontDesc* font, bool cl
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
#define TextGroupWidget_LineBuffer(w, i) ((w)->Buffer + (i) * TEXTGROUPWIDGET_LEN)
|
#define TextGroupWidget_LineBuffer(w, i) ((w)->Buffer + (i) * TEXTGROUPWIDGET_LEN)
|
||||||
String TextGroupWidget_UNSAFE_Get(struct TextGroupWidget* w, int i) {
|
String TextGroupWidget_UNSAFE_Get(struct TextGroupWidget* w, int i) {
|
||||||
UInt16 length = w->LineLengths[i];
|
uint16_t length = w->LineLengths[i];
|
||||||
return String_Init(TextGroupWidget_LineBuffer(w, i), length, length);
|
return String_Init(TextGroupWidget_LineBuffer(w, i), length, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2220,7 +2220,7 @@ void TextGroupWidget_SetUsePlaceHolder(struct TextGroupWidget* w, int index, boo
|
|||||||
w->PlaceholderHeight[index] = placeHolder;
|
w->PlaceholderHeight[index] = placeHolder;
|
||||||
if (w->Textures[index].ID) return;
|
if (w->Textures[index].ID) return;
|
||||||
|
|
||||||
UInt16 newHeight = placeHolder ? w->DefaultHeight : 0;
|
uint16_t newHeight = placeHolder ? w->DefaultHeight : 0;
|
||||||
w->Textures[index].Y = TextGroupWidget_CalcY(w, index, newHeight);
|
w->Textures[index].Y = TextGroupWidget_CalcY(w, index, newHeight);
|
||||||
w->Textures[index].Height = newHeight;
|
w->Textures[index].Height = newHeight;
|
||||||
}
|
}
|
||||||
@ -2416,7 +2416,7 @@ static bool TextGroupWidget_GetUrl(struct TextGroupWidget* w, String* text, int
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TextGroupWidget_GetSelected(struct TextGroupWidget* w, String* text, int x, int y) {
|
void TextGroupWidget_GetSelected(struct TextGroupWidget* w, String* text, int x, int y) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < w->LinesCount; i++) {
|
for (i = 0; i < w->LinesCount; i++) {
|
||||||
if (!w->Textures[i].ID) continue;
|
if (!w->Textures[i].ID) continue;
|
||||||
|
@ -25,7 +25,7 @@ typedef void (*Button_Set)(const String* raw);
|
|||||||
struct ButtonWidget {
|
struct ButtonWidget {
|
||||||
Widget_Layout
|
Widget_Layout
|
||||||
struct Texture Texture;
|
struct Texture Texture;
|
||||||
UInt16 MinWidth;
|
uint16_t MinWidth;
|
||||||
|
|
||||||
const char* OptName;
|
const char* OptName;
|
||||||
Button_Get GetValue;
|
Button_Get GetValue;
|
||||||
@ -89,16 +89,16 @@ struct InputWidget {
|
|||||||
bool (*AllowedChar)(void* elem, char c);
|
bool (*AllowedChar)(void* elem, char c);
|
||||||
|
|
||||||
String Text;
|
String Text;
|
||||||
String Lines[INPUTWIDGET_MAX_LINES]; /* raw text of each line */
|
String Lines[INPUTWIDGET_MAX_LINES]; /* raw text of each line */
|
||||||
Size2D LineSizes[INPUTWIDGET_MAX_LINES]; /* size of each line in pixels */
|
Size2D LineSizes[INPUTWIDGET_MAX_LINES]; /* size of each line in pixels */
|
||||||
struct Texture InputTex;
|
struct Texture InputTex;
|
||||||
String Prefix;
|
String Prefix;
|
||||||
UInt16 PrefixWidth, PrefixHeight;
|
uint16_t PrefixWidth, PrefixHeight;
|
||||||
bool ConvertPercents;
|
bool ConvertPercents;
|
||||||
|
|
||||||
UInt8 Padding;
|
UInt8 Padding;
|
||||||
bool ShowCaret;
|
bool ShowCaret;
|
||||||
UInt16 CaretWidth;
|
uint16_t CaretWidth;
|
||||||
int CaretX, CaretY; /* Coordinates of caret in lines */
|
int CaretX, CaretY; /* Coordinates of caret in lines */
|
||||||
int CaretPos; /* Position of caret, -1 for at end of string */
|
int CaretPos; /* Position of caret, -1 for at end of string */
|
||||||
PackedCol CaretCol;
|
PackedCol CaretCol;
|
||||||
@ -163,7 +163,7 @@ struct TextGroupWidget {
|
|||||||
int LinesCount, DefaultHeight;
|
int LinesCount, DefaultHeight;
|
||||||
FontDesc Font, UnderlineFont;
|
FontDesc Font, UnderlineFont;
|
||||||
bool PlaceholderHeight[TEXTGROUPWIDGET_MAX_LINES];
|
bool PlaceholderHeight[TEXTGROUPWIDGET_MAX_LINES];
|
||||||
UInt8 LineLengths[TEXTGROUPWIDGET_MAX_LINES];
|
uint8_t LineLengths[TEXTGROUPWIDGET_MAX_LINES];
|
||||||
struct Texture* Textures;
|
struct Texture* Textures;
|
||||||
char* Buffer;
|
char* Buffer;
|
||||||
};
|
};
|
||||||
@ -180,11 +180,11 @@ NOINLINE_ void TextGroupWidget_SetText(struct TextGroupWidget* w, int index, con
|
|||||||
struct PlayerListWidget {
|
struct PlayerListWidget {
|
||||||
Widget_Layout
|
Widget_Layout
|
||||||
FontDesc Font;
|
FontDesc Font;
|
||||||
UInt16 NamesCount, ElementOffset;
|
uint16_t NamesCount, ElementOffset;
|
||||||
int XMin, XMax, YHeight;
|
int XMin, XMax, YHeight;
|
||||||
bool Classic;
|
bool Classic;
|
||||||
struct TextWidget Overview;
|
struct TextWidget Overview;
|
||||||
UInt16 IDs[TABLIST_MAX_NAMES * 2];
|
uint16_t IDs[TABLIST_MAX_NAMES * 2];
|
||||||
struct Texture Textures[TABLIST_MAX_NAMES * 2];
|
struct Texture Textures[TABLIST_MAX_NAMES * 2];
|
||||||
};
|
};
|
||||||
NOINLINE_ void PlayerListWidget_Create(struct PlayerListWidget* w, FontDesc* font, bool classic);
|
NOINLINE_ void PlayerListWidget_Create(struct PlayerListWidget* w, FontDesc* font, bool classic);
|
||||||
|
@ -241,7 +241,7 @@ static LRESULT CALLBACK Window_Procedure(HWND handle, UINT message, WPARAM wPara
|
|||||||
case WM_CHAR:
|
case WM_CHAR:
|
||||||
{
|
{
|
||||||
char keyChar;
|
char keyChar;
|
||||||
if (Convert_TryUnicodeToCP437((UInt16)wParam, &keyChar)) {
|
if (Convert_TryUnicodeToCP437((Codepoint)wParam, &keyChar)) {
|
||||||
Event_RaiseInt(&KeyEvents_Press, keyChar);
|
Event_RaiseInt(&KeyEvents_Press, keyChar);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@ -448,7 +448,7 @@ void Window_GetClipboardText(String* value) {
|
|||||||
|
|
||||||
char c;
|
char c;
|
||||||
if (isUnicode) {
|
if (isUnicode) {
|
||||||
UInt16* text = (UInt16*)src;
|
Codepoint* text = (Codepoint*)src;
|
||||||
for (; *text; text++) {
|
for (; *text; text++) {
|
||||||
if (Convert_TryUnicodeToCP437(*text, &c)) String_Append(value, c);
|
if (Convert_TryUnicodeToCP437(*text, &c)) String_Append(value, c);
|
||||||
}
|
}
|
||||||
@ -474,10 +474,10 @@ void Window_SetClipboardText(const String* value) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE hGlobal = GlobalAlloc(GMEM_MOVEABLE, (value->length + 1) * sizeof(UInt16));
|
HANDLE hGlobal = GlobalAlloc(GMEM_MOVEABLE, (value->length + 1) * 2);
|
||||||
if (!hGlobal) { CloseClipboard(); return; }
|
if (!hGlobal) { CloseClipboard(); return; }
|
||||||
|
|
||||||
UInt16* text = GlobalLock(hGlobal);
|
Codepoint* text = GlobalLock(hGlobal);
|
||||||
for (i = 0; i < value->length; i++, text++) {
|
for (i = 0; i < value->length; i++, text++) {
|
||||||
*text = Convert_CP437ToUnicode(value->buffer[i]);
|
*text = Convert_CP437ToUnicode(value->buffer[i]);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user