mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 03:55:19 -04:00
initial plugin api support
This commit is contained in:
parent
0d84f4d7a8
commit
3fbf254f16
@ -473,7 +473,7 @@ static void Game_Load(void) {
|
|||||||
Game_AddComponent(&Audio_Component);
|
Game_AddComponent(&Audio_Component);
|
||||||
Game_AddComponent(&AxisLinesRenderer_Component);
|
Game_AddComponent(&AxisLinesRenderer_Component);
|
||||||
|
|
||||||
//Game_LoadPlugins();
|
Game_LoadPlugins();
|
||||||
for (comp = comps_head; comp; comp = comp->Next) {
|
for (comp = comps_head; comp; comp = comp->Next) {
|
||||||
if (comp->Init) comp->Init();
|
if (comp->Init) comp->Init();
|
||||||
}
|
}
|
||||||
|
@ -55,94 +55,94 @@ extern ScheduledTaskCallback Gfx_LostContextFunction;
|
|||||||
/* Creates a new texture. (and also generates mipmaps if mipmaps) */
|
/* Creates a new texture. (and also generates mipmaps if mipmaps) */
|
||||||
/* NOTE: Only set mipmaps to true if Gfx_Mipmaps is also true, because whether textures
|
/* NOTE: Only set mipmaps to true if Gfx_Mipmaps is also true, because whether textures
|
||||||
use mipmapping may be either a per-texture or global state depending on the backend. */
|
use mipmapping may be either a per-texture or global state depending on the backend. */
|
||||||
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps);
|
CC_API GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool, bool mipmaps);
|
||||||
/* Updates a region of the given texture. (and mipmapped regions if mipmaps) */
|
/* Updates a region of the given texture. (and mipmapped regions if mipmaps) */
|
||||||
void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, Bitmap* part, bool mipmaps);
|
CC_API void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, Bitmap* part, bool mipmaps);
|
||||||
/* Sets the currently active texture. */
|
/* Sets the currently active texture. */
|
||||||
void Gfx_BindTexture(GfxResourceID texId);
|
CC_API void Gfx_BindTexture(GfxResourceID texId);
|
||||||
/* Deletes the given texture, then sets it to GFX_NULL. */
|
/* Deletes the given texture, then sets it to GFX_NULL. */
|
||||||
void Gfx_DeleteTexture(GfxResourceID* texId);
|
CC_API void Gfx_DeleteTexture(GfxResourceID* texId);
|
||||||
/* Sets whether texture colour is used when rendering vertices. */
|
/* Sets whether texture colour is used when rendering vertices. */
|
||||||
void Gfx_SetTexturing(bool enabled);
|
CC_API void Gfx_SetTexturing(bool enabled);
|
||||||
/* Turns on mipmapping. (if Gfx_Mipmaps is enabled) */
|
/* Turns on mipmapping. (if Gfx_Mipmaps is enabled) */
|
||||||
/* NOTE: You must have created textures with mipmaps true for this to work. */
|
/* NOTE: You must have created textures with mipmaps true for this to work. */
|
||||||
void Gfx_EnableMipmaps(void);
|
CC_API void Gfx_EnableMipmaps(void);
|
||||||
/* Turns off mipmapping. (if GfX_Mipmaps is enabled) */
|
/* Turns off mipmapping. (if GfX_Mipmaps is enabled) */
|
||||||
/* NOTE: You must have created textures with mipmaps true for this to work. */
|
/* NOTE: You must have created textures with mipmaps true for this to work. */
|
||||||
void Gfx_DisableMipmaps(void);
|
CC_API void Gfx_DisableMipmaps(void);
|
||||||
|
|
||||||
/* Returns whether fog blending is enabled. */
|
/* Returns whether fog blending is enabled. */
|
||||||
bool Gfx_GetFog(void);
|
CC_API bool Gfx_GetFog(void);
|
||||||
/* Sets whether fog blending is enabled. */
|
/* Sets whether fog blending is enabled. */
|
||||||
void Gfx_SetFog(bool enabled);
|
CC_API void Gfx_SetFog(bool enabled);
|
||||||
/* Sets the colour of the blended fog. */
|
/* Sets the colour of the blended fog. */
|
||||||
void Gfx_SetFogCol(PackedCol col);
|
CC_API void Gfx_SetFogCol(PackedCol col);
|
||||||
/* Sets thickness of fog for FOG_EXP/FOG_EXP2 modes. */
|
/* Sets thickness of fog for FOG_EXP/FOG_EXP2 modes. */
|
||||||
void Gfx_SetFogDensity(float value);
|
CC_API void Gfx_SetFogDensity(float value);
|
||||||
/* Sets extent/end of fog for FOG_LINEAR mode. */
|
/* Sets extent/end of fog for FOG_LINEAR mode. */
|
||||||
void Gfx_SetFogEnd(float value);
|
CC_API void Gfx_SetFogEnd(float value);
|
||||||
/* Sets in what way fog is blended. */
|
/* Sets in what way fog is blended. */
|
||||||
void Gfx_SetFogMode(FogFunc func);
|
CC_API void Gfx_SetFogMode(FogFunc func);
|
||||||
|
|
||||||
/* Sets whether backface culling is performed. */
|
/* Sets whether backface culling is performed. */
|
||||||
void Gfx_SetFaceCulling(bool enabled);
|
CC_API void Gfx_SetFaceCulling(bool enabled);
|
||||||
/* Sets whether new pixels may be discarded based on their alpha. */
|
/* Sets whether new pixels may be discarded based on their alpha. */
|
||||||
void Gfx_SetAlphaTest(bool enabled);
|
CC_API void Gfx_SetAlphaTest(bool enabled);
|
||||||
/* Sets in what way pixels may be discarded based on their alpha. */
|
/* Sets in what way pixels may be discarded based on their alpha. */
|
||||||
void Gfx_SetAlphaTestFunc(CompareFunc func, float refValue);
|
CC_API void Gfx_SetAlphaTestFunc(CompareFunc func, float refValue);
|
||||||
/* Sets whether existing and new pixels are blended together. */
|
/* Sets whether existing and new pixels are blended together. */
|
||||||
void Gfx_SetAlphaBlending(bool enabled);
|
CC_API void Gfx_SetAlphaBlending(bool enabled);
|
||||||
/* Sets in what way existing and new pixels are blended. */
|
/* Sets in what way existing and new pixels are blended. */
|
||||||
void Gfx_SetAlphaBlendFunc(BlendFunc srcFunc, BlendFunc dstFunc);
|
CC_API void Gfx_SetAlphaBlendFunc(BlendFunc srcFunc, BlendFunc dstFunc);
|
||||||
/* Sets whether blending between the alpha components of texture and vertex colour is performed. */
|
/* Sets whether blending between the alpha components of texture and vertex colour is performed. */
|
||||||
void Gfx_SetAlphaArgBlend(bool enabled);
|
CC_API void Gfx_SetAlphaArgBlend(bool enabled);
|
||||||
|
|
||||||
/* Clears the colour and depth buffer to default. */
|
/* Clears the colour and depth buffer to default. */
|
||||||
void Gfx_Clear(void);
|
CC_API void Gfx_Clear(void);
|
||||||
/* Sets the colour that the colour buffer is cleared to. */
|
/* Sets the colour that the colour buffer is cleared to. */
|
||||||
void Gfx_ClearCol(PackedCol col);
|
CC_API void Gfx_ClearCol(PackedCol col);
|
||||||
/* Sets whether pixels may be discard based on z/depth. */
|
/* Sets whether pixels may be discard based on z/depth. */
|
||||||
void Gfx_SetDepthTest(bool enabled);
|
CC_API void Gfx_SetDepthTest(bool enabled);
|
||||||
/* Sets in what may pixels may be discarded based on z/depth. */
|
/* Sets in what may pixels may be discarded based on z/depth. */
|
||||||
void Gfx_SetDepthTestFunc(CompareFunc func);
|
CC_API void Gfx_SetDepthTestFunc(CompareFunc func);
|
||||||
/* Sets whether R/G/B/A of pixels are actually written to the colour buffer channels. */
|
/* Sets whether R/G/B/A of pixels are actually written to the colour buffer channels. */
|
||||||
void Gfx_SetColWriteMask(bool r, bool g, bool b, bool a);
|
CC_API void Gfx_SetColWriteMask(bool r, bool g, bool b, bool a);
|
||||||
/* Sets whether z/depth of pixels is actually written to the depth buffer. */
|
/* Sets whether z/depth of pixels is actually written to the depth buffer. */
|
||||||
void Gfx_SetDepthWrite(bool enabled);
|
CC_API void Gfx_SetDepthWrite(bool enabled);
|
||||||
|
|
||||||
/* Creates a new dynamic vertex buffer, whose contents can be updated later. */
|
/* Creates a new dynamic vertex buffer, whose contents can be updated later. */
|
||||||
GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices);
|
CC_API GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices);
|
||||||
/* Creates a new vertex buffer and fills out its contents. */
|
/* Creates a new vertex buffer and fills out its contents. */
|
||||||
GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count);
|
CC_API GfxResourceID Gfx_CreateVb(void* vertices, VertexFormat fmt, int count);
|
||||||
/* Creates a new index buffer and fills out its contents. */
|
/* Creates a new index buffer and fills out its contents. */
|
||||||
GfxResourceID Gfx_CreateIb(void* indices, int indicesCount);
|
CC_API GfxResourceID Gfx_CreateIb(void* indices, int indicesCount);
|
||||||
/* Sets the currently active vertex buffer. */
|
/* Sets the currently active vertex buffer. */
|
||||||
void Gfx_BindVb(GfxResourceID vb);
|
CC_API void Gfx_BindVb(GfxResourceID vb);
|
||||||
/* Sets the currently active index buffer. */
|
/* Sets the currently active index buffer. */
|
||||||
void Gfx_BindIb(GfxResourceID ib);
|
CC_API void Gfx_BindIb(GfxResourceID ib);
|
||||||
/* Deletes the given vertex buffer, then sets it to GFX_NULL. */
|
/* Deletes the given vertex buffer, then sets it to GFX_NULL. */
|
||||||
void Gfx_DeleteVb(GfxResourceID* vb);
|
CC_API void Gfx_DeleteVb(GfxResourceID* vb);
|
||||||
/* Deletes the given index buffer, then sets it to GFX_NULL. */
|
/* Deletes the given index buffer, then sets it to GFX_NULL. */
|
||||||
void Gfx_DeleteIb(GfxResourceID* ib);
|
CC_API void Gfx_DeleteIb(GfxResourceID* ib);
|
||||||
|
|
||||||
/* Sets the format of the rendered vertices. */
|
/* Sets the format of the rendered vertices. */
|
||||||
void Gfx_SetVertexFormat(VertexFormat fmt);
|
CC_API void Gfx_SetVertexFormat(VertexFormat fmt);
|
||||||
/* Updates the data of a dynamic vertex buffer. */
|
/* Updates the data of a dynamic vertex buffer. */
|
||||||
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount);
|
CC_API void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount);
|
||||||
/* Renders vertices from the currently bound vertex buffer as lines. */
|
/* Renders vertices from the currently bound vertex buffer as lines. */
|
||||||
void Gfx_DrawVb_Lines(int verticesCount);
|
CC_API void Gfx_DrawVb_Lines(int verticesCount);
|
||||||
/* Renders vertices from the currently bound vertex and index buffer as triangles. */
|
/* Renders vertices from the currently bound vertex and index buffer as triangles. */
|
||||||
/* NOTE: Offsets each index by startVertex. */
|
/* NOTE: Offsets each index by startVertex. */
|
||||||
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex);
|
CC_API void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex);
|
||||||
/* Renders vertices from the currently bound vertex and index buffer as triangles. */
|
/* Renders vertices from the currently bound vertex and index buffer as triangles. */
|
||||||
void Gfx_DrawVb_IndexedTris(int verticesCount);
|
CC_API void Gfx_DrawVb_IndexedTris(int verticesCount);
|
||||||
/* Special case Gfx_DrawVb_IndexedTris_Range for map renderer */
|
/* Special case Gfx_DrawVb_IndexedTris_Range for map renderer */
|
||||||
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex);
|
void Gfx_DrawIndexedVb_TrisT2fC4b(int verticesCount, int startVertex);
|
||||||
|
|
||||||
/* Loads the given matrix over the currently active matrix. */
|
/* Loads the given matrix over the currently active matrix. */
|
||||||
void Gfx_LoadMatrix(MatrixType type, struct Matrix* matrix);
|
CC_API void Gfx_LoadMatrix(MatrixType type, struct Matrix* matrix);
|
||||||
/* Loads the identity matrix over the currently active matrix. */
|
/* Loads the identity matrix over the currently active matrix. */
|
||||||
void Gfx_LoadIdentityMatrix(MatrixType type);
|
CC_API void Gfx_LoadIdentityMatrix(MatrixType type);
|
||||||
/* Calculates an orthographic matrix suitable with this backend. (usually for 2D) */
|
/* Calculates an orthographic matrix suitable with this backend. (usually for 2D) */
|
||||||
void Gfx_CalcOrthoMatrix(float width, float height, struct Matrix* matrix);
|
void Gfx_CalcOrthoMatrix(float width, float height, struct Matrix* matrix);
|
||||||
/* Calculates a projection matrix suitable with this backend. (usually for 3D) */
|
/* Calculates a projection matrix suitable with this backend. (usually for 3D) */
|
||||||
|
45
src/Stream.c
45
src/Stream.c
@ -364,7 +364,7 @@ void Stream_ReadonlyBuffered(struct Stream* s, struct Stream* source, void* data
|
|||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------CRC32Stream---------------------------------------------------------*
|
*-------------------------------------------------CRC32Stream/ReadU32-----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static ReturnCode Stream_Crc32Write(struct Stream* stream, const uint8_t* data, uint32_t count, uint32_t* modified) {
|
static ReturnCode Stream_Crc32Write(struct Stream* stream, const uint8_t* data, uint32_t count, uint32_t* modified) {
|
||||||
struct Stream* source;
|
struct Stream* source;
|
||||||
@ -388,48 +388,6 @@ void Stream_WriteonlyCrc32(struct Stream* s, struct Stream* source) {
|
|||||||
s->Meta.CRC32.CRC32 = 0xFFFFFFFFUL;
|
s->Meta.CRC32.CRC32 = 0xFFFFFFFFUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
|
||||||
*-------------------------------------------------Read/Write primitives---------------------------------------------------*
|
|
||||||
*#########################################################################################################################*/
|
|
||||||
uint16_t Stream_GetU16_LE(const uint8_t* data) {
|
|
||||||
return (uint16_t)(data[0] | (data[1] << 8));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Stream_GetU16_BE(const uint8_t* data) {
|
|
||||||
return (uint16_t)((data[0] << 8) | data[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Stream_GetU32_LE(const uint8_t* data) {
|
|
||||||
return (uint32_t)(
|
|
||||||
(uint32_t)data[0] | ((uint32_t)data[1] << 8) |
|
|
||||||
((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Stream_GetU32_BE(const uint8_t* data) {
|
|
||||||
return (uint32_t)(
|
|
||||||
((uint32_t)data[0] << 24) | ((uint32_t)data[1] << 16) |
|
|
||||||
((uint32_t)data[2] << 8) | (uint32_t)data[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Stream_SetU16_LE(uint8_t* data, uint16_t value) {
|
|
||||||
data[0] = (uint8_t)(value ); data[1] = (uint8_t)(value >> 8 );
|
|
||||||
}
|
|
||||||
|
|
||||||
void Stream_SetU16_BE(uint8_t* data, uint16_t value) {
|
|
||||||
data[0] = (uint8_t)(value >> 8 ); data[1] = (uint8_t)(value );
|
|
||||||
}
|
|
||||||
|
|
||||||
void Stream_SetU32_LE(uint8_t* data, uint32_t value) {
|
|
||||||
data[0] = (uint8_t)(value ); data[1] = (uint8_t)(value >> 8 );
|
|
||||||
data[2] = (uint8_t)(value >> 16); data[3] = (uint8_t)(value >> 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Stream_SetU32_BE(uint8_t* data, uint32_t value) {
|
|
||||||
data[0] = (uint8_t)(value >> 24); data[1] = (uint8_t)(value >> 16);
|
|
||||||
data[2] = (uint8_t)(value >> 8 ); data[3] = (uint8_t)(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnCode Stream_ReadU32_LE(struct Stream* s, uint32_t* value) {
|
ReturnCode Stream_ReadU32_LE(struct Stream* s, uint32_t* value) {
|
||||||
uint8_t data[4]; ReturnCode res;
|
uint8_t data[4]; ReturnCode res;
|
||||||
if ((res = Stream_Read(s, data, 4))) return res;
|
if ((res = Stream_Read(s, data, 4))) return res;
|
||||||
@ -442,7 +400,6 @@ ReturnCode Stream_ReadU32_BE(struct Stream* s, uint32_t* value) {
|
|||||||
*value = Stream_GetU32_BE(data); return 0;
|
*value = Stream_GetU32_BE(data); return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*--------------------------------------------------Read/Write strings-----------------------------------------------------*
|
*--------------------------------------------------Read/Write strings-----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
58
src/Stream.h
58
src/Stream.h
@ -70,29 +70,51 @@ CC_API void Stream_ReadonlyBuffered(struct Stream* s, struct Stream* source, voi
|
|||||||
/* Wraps another Stream, calculating a running CRC32 as data is written. */
|
/* Wraps another Stream, calculating a running CRC32 as data is written. */
|
||||||
/* To get the final CRC32, xor it with 0xFFFFFFFFUL */
|
/* To get the final CRC32, xor it with 0xFFFFFFFFUL */
|
||||||
void Stream_WriteonlyCrc32(struct Stream* s, struct Stream* source);
|
void Stream_WriteonlyCrc32(struct Stream* s, struct Stream* source);
|
||||||
|
|
||||||
/* Reads a little-endian 16 bit unsigned integer from memory. */
|
|
||||||
uint16_t Stream_GetU16_LE(const uint8_t* data);
|
|
||||||
/* Reads a big-endian 16 bit unsigned integer from memory. */
|
|
||||||
uint16_t Stream_GetU16_BE(const uint8_t* data);
|
|
||||||
/* Reads a little-endian 32 bit unsigned integer from memory. */
|
|
||||||
uint32_t Stream_GetU32_LE(const uint8_t* data);
|
|
||||||
/* Reads a big-endian 32 bit unsigned integer from memory. */
|
|
||||||
uint32_t Stream_GetU32_BE(const uint8_t* data);
|
|
||||||
|
|
||||||
/* Writes a little-endian 16 bit unsigned integer to memory. */
|
|
||||||
void Stream_SetU16_LE(uint8_t* data, uint16_t value);
|
|
||||||
/* Writes a big-endian 16 bit unsigned integer to memory. */
|
|
||||||
void Stream_SetU16_BE(uint8_t* data, uint16_t value);
|
|
||||||
/* Writes a little-endian 32 bit unsigned integer to memory. */
|
|
||||||
void Stream_SetU32_LE(uint8_t* data, uint32_t value);
|
|
||||||
/* Writes a big-endian 32 bit unsigned integer to memory. */
|
|
||||||
void Stream_SetU32_BE(uint8_t* data, uint32_t value);
|
|
||||||
/* Reads a little-endian 32 bit unsigned integer from the stream. */
|
/* Reads a little-endian 32 bit unsigned integer from the stream. */
|
||||||
ReturnCode Stream_ReadU32_LE(struct Stream* s, uint32_t* value);
|
ReturnCode Stream_ReadU32_LE(struct Stream* s, uint32_t* value);
|
||||||
/* Reads a big-endian 32 bit unsigned integer from the stream. */
|
/* Reads a big-endian 32 bit unsigned integer from the stream. */
|
||||||
ReturnCode Stream_ReadU32_BE(struct Stream* s, uint32_t* value);
|
ReturnCode Stream_ReadU32_BE(struct Stream* s, uint32_t* value);
|
||||||
|
|
||||||
|
/* Reads a little-endian 16 bit unsigned integer from memory. */
|
||||||
|
static CC_INLINE uint16_t Stream_GetU16_LE(const uint8_t* data) {
|
||||||
|
return (uint16_t)(data[0] | (data[1] << 8));
|
||||||
|
}
|
||||||
|
/* Reads a big-endian 16 bit unsigned integer from memory. */
|
||||||
|
static CC_INLINE uint16_t Stream_GetU16_BE(const uint8_t* data) {
|
||||||
|
return (uint16_t)((data[0] << 8) | data[1]);
|
||||||
|
}
|
||||||
|
/* Reads a little-endian 32 bit unsigned integer from memory. */
|
||||||
|
static CC_INLINE uint32_t Stream_GetU32_LE(const uint8_t* data) {
|
||||||
|
return (uint32_t)(
|
||||||
|
(uint32_t)data[0] | ((uint32_t)data[1] << 8) |
|
||||||
|
((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24));
|
||||||
|
}
|
||||||
|
/* Reads a big-endian 32 bit unsigned integer from memory. */
|
||||||
|
static CC_INLINE uint32_t Stream_GetU32_BE(const uint8_t* data) {
|
||||||
|
return (uint32_t)(
|
||||||
|
((uint32_t)data[0] << 24) | ((uint32_t)data[1] << 16) |
|
||||||
|
((uint32_t)data[2] << 8) | (uint32_t)data[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Writes a little-endian 16 bit unsigned integer to memory. */
|
||||||
|
static CC_INLINE void Stream_SetU16_LE(uint8_t* data, uint16_t value) {
|
||||||
|
data[0] = (uint8_t)(value ); data[1] = (uint8_t)(value >> 8 );
|
||||||
|
}
|
||||||
|
/* Writes a big-endian 16 bit unsigned integer to memory. */
|
||||||
|
static CC_INLINE void Stream_SetU16_BE(uint8_t* data, uint16_t value) {
|
||||||
|
data[0] = (uint8_t)(value >> 8 ); data[1] = (uint8_t)(value );
|
||||||
|
}
|
||||||
|
/* Writes a little-endian 32 bit unsigned integer to memory. */
|
||||||
|
static CC_INLINE void Stream_SetU32_LE(uint8_t* data, uint32_t value) {
|
||||||
|
data[0] = (uint8_t)(value ); data[1] = (uint8_t)(value >> 8 );
|
||||||
|
data[2] = (uint8_t)(value >> 16); data[3] = (uint8_t)(value >> 24);
|
||||||
|
}
|
||||||
|
/* Writes a big-endian 32 bit unsigned integer to memory. */
|
||||||
|
static CC_INLINE void Stream_SetU32_BE(uint8_t* data, uint32_t value) {
|
||||||
|
data[0] = (uint8_t)(value >> 24); data[1] = (uint8_t)(value >> 16);
|
||||||
|
data[2] = (uint8_t)(value >> 8 ); data[3] = (uint8_t)(value);
|
||||||
|
}
|
||||||
|
|
||||||
/* Reads a line of UTF8 encoded character from the stream. */
|
/* Reads a line of UTF8 encoded character from the stream. */
|
||||||
/* NOTE: Reads one byte at a time. May want to use Stream_ReadonlyBuffered. */
|
/* NOTE: Reads one byte at a time. May want to use Stream_ReadonlyBuffered. */
|
||||||
CC_API ReturnCode Stream_ReadLine(struct Stream* s, String* text);
|
CC_API ReturnCode Stream_ReadLine(struct Stream* s, String* text);
|
||||||
|
92
src/String.h
92
src/String.h
@ -51,93 +51,93 @@ CC_NOINLINE String String_FromReadonly(STRING_REF const char* buffer);
|
|||||||
#define String_InitArray_NT(str, buffr) str.buffer = buffr; str.length = 0; str.capacity = sizeof(buffr) - 1;
|
#define String_InitArray_NT(str, buffr) str.buffer = buffr; str.length = 0; str.capacity = sizeof(buffr) - 1;
|
||||||
|
|
||||||
/* Removes all colour codes from the given string. */
|
/* Removes all colour codes from the given string. */
|
||||||
CC_NOINLINE void String_StripCols(String* str);
|
CC_API void String_StripCols(String* str);
|
||||||
/* Sets length of dst to 0, then appends all characters in src. */
|
/* Sets length of dst to 0, then appends all characters in src. */
|
||||||
CC_NOINLINE void String_Copy(String* dst, const String* src);
|
CC_API void String_Copy(String* dst, const String* src);
|
||||||
/* UNSAFE: Returns a substring of the given string. (sub.buffer is within str.buffer + str.length) */
|
/* UNSAFE: Returns a substring of the given string. (sub.buffer is within str.buffer + str.length) */
|
||||||
CC_NOINLINE String String_UNSAFE_Substring(STRING_REF const String* str, int offset, int length);
|
CC_API String String_UNSAFE_Substring(STRING_REF const String* str, int offset, int length);
|
||||||
/* UNSAFE: Returns a substring of the given string. (sub.buffer is within str.buffer + str.length) */
|
/* UNSAFE: Returns a substring of the given string. (sub.buffer is within str.buffer + str.length) */
|
||||||
#define String_UNSAFE_SubstringAt(str, offset) (String_UNSAFE_Substring(str, offset, (str)->length - (offset)))
|
#define String_UNSAFE_SubstringAt(str, offset) (String_UNSAFE_Substring(str, offset, (str)->length - (offset)))
|
||||||
/* UNSAFE: Splits a string of the form [str1][c][str2][c][str3].. into substrings. */
|
/* UNSAFE: Splits a string of the form [str1][c][str2][c][str3].. into substrings. */
|
||||||
/* e.g., "abc:id:xyz" becomes "abc","id","xyz" */
|
/* e.g., "abc:id:xyz" becomes "abc","id","xyz" */
|
||||||
CC_NOINLINE int String_UNSAFE_Split(STRING_REF const String* str, char c, String* subs, int maxSubs);
|
CC_API int String_UNSAFE_Split(STRING_REF const String* str, char c, String* subs, int maxSubs);
|
||||||
/* UNSAFE: Splits a string of the form [key][c][value] into two substrings. */
|
/* UNSAFE: Splits a string of the form [key][c][value] into two substrings. */
|
||||||
/* e.g., "allowed =true" becomes "allowed" and "true", and excludes the space. */
|
/* e.g., "allowed =true" becomes "allowed" and "true", and excludes the space. */
|
||||||
/* If c is not found, sets key to str and value to String_Empty, returns false. */
|
/* If c is not found, sets key to str and value to String_Empty, returns false. */
|
||||||
CC_NOINLINE bool String_UNSAFE_Separate(STRING_REF const String* str, char c, String* key, String* value);
|
CC_API bool String_UNSAFE_Separate(STRING_REF const String* str, char c, String* key, String* value);
|
||||||
|
|
||||||
/* Whether all characters of the strings are equal. */
|
/* Whether all characters of the strings are equal. */
|
||||||
CC_NOINLINE bool String_Equals(const String* a, const String* b);
|
CC_API bool String_Equals(const String* a, const String* b);
|
||||||
/* Whether all characters of the strings are case-insensitively equal. */
|
/* Whether all characters of the strings are case-insensitively equal. */
|
||||||
CC_NOINLINE bool String_CaselessEquals(const String* a, const String* b);
|
CC_API bool String_CaselessEquals(const String* a, const String* b);
|
||||||
/* Whether all characters of the strings are case-insensitively equal. */
|
/* Whether all characters of the strings are case-insensitively equal. */
|
||||||
/* NOTE: Faster than String_CaselessEquals(a, String_FromReadonly(b)) */
|
/* NOTE: Faster than String_CaselessEquals(a, String_FromReadonly(b)) */
|
||||||
CC_NOINLINE bool String_CaselessEqualsConst(const String* a, const char* b);
|
CC_API bool String_CaselessEqualsConst(const String* a, const char* b);
|
||||||
/* Breaks down an integer into an array of digits. */
|
/* Breaks down an integer into an array of digits. */
|
||||||
/* NOTE: Digits are in reverse order, so e.g. '200' becomes '0','0','2' */
|
/* NOTE: Digits are in reverse order, so e.g. '200' becomes '0','0','2' */
|
||||||
CC_NOINLINE int String_MakeUInt32(uint32_t num, char* digits);
|
CC_API int String_MakeUInt32(uint32_t num, char* digits);
|
||||||
|
|
||||||
/* Attempts to append a character. */
|
/* Attempts to append a character. */
|
||||||
/* Does nothing if str->length == str->capcity. */
|
/* Does nothing if str->length == str->capcity. */
|
||||||
void String_Append(String* str, char c);
|
void String_Append(String* str, char c);
|
||||||
/* Attempts to append "true" if value is non-zero, "false" otherwise. */
|
/* Attempts to append "true" if value is non-zero, "false" otherwise. */
|
||||||
CC_NOINLINE void String_AppendBool(String* str, bool value);
|
CC_API void String_AppendBool(String* str, bool value);
|
||||||
/* Attempts to append the digits of an integer (and -sign if negative). */
|
/* Attempts to append the digits of an integer (and -sign if negative). */
|
||||||
CC_NOINLINE void String_AppendInt(String* str, int num);
|
CC_API void String_AppendInt(String* str, int num);
|
||||||
/* Attempts to append the digits of an unsigned 32 bit integer. */
|
/* Attempts to append the digits of an unsigned 32 bit integer. */
|
||||||
CC_NOINLINE void String_AppendUInt32(String* str, uint32_t num);
|
CC_API void String_AppendUInt32(String* str, uint32_t num);
|
||||||
/* Attempts to append the digits of an integer, padding left with 0. */
|
/* Attempts to append the digits of an integer, padding left with 0. */
|
||||||
CC_NOINLINE void String_AppendPaddedInt(String* str, int num, int minDigits);
|
CC_API void String_AppendPaddedInt(String* str, int num, int minDigits);
|
||||||
/* Attempts to append the digits of an unsigned 64 bit integer. */
|
/* Attempts to append the digits of an unsigned 64 bit integer. */
|
||||||
CC_NOINLINE void String_AppendUInt64(String* str, uint64_t num);
|
CC_API void String_AppendUInt64(String* str, uint64_t num);
|
||||||
|
|
||||||
/* Attempts to append the digits of a float as a decimal. */
|
/* Attempts to append the digits of a float as a decimal. */
|
||||||
/* NOTE: If the number is an integer, no decimal point is added. */
|
/* NOTE: If the number is an integer, no decimal point is added. */
|
||||||
/* Otherwise, fracDigits digits are added after a decimal point. */
|
/* Otherwise, fracDigits digits are added after a decimal point. */
|
||||||
/* e.g. 1.0f produces "1", 2.6745f produces "2.67" when fracDigits is 2 */
|
/* e.g. 1.0f produces "1", 2.6745f produces "2.67" when fracDigits is 2 */
|
||||||
CC_NOINLINE void String_AppendFloat(String* str, float num, int fracDigits); /* TODO: Need to account for , or . for decimal */
|
CC_API void String_AppendFloat(String* str, float num, int fracDigits); /* TODO: Need to account for , or . for decimal */
|
||||||
/* Attempts to append characters. src MUST be null-terminated. */
|
/* Attempts to append characters. src MUST be null-terminated. */
|
||||||
CC_NOINLINE void String_AppendConst(String* str, const char* src);
|
CC_API void String_AppendConst(String* str, const char* src);
|
||||||
/* Attempts to append characters of a string. */
|
/* Attempts to append characters of a string. */
|
||||||
CC_NOINLINE void String_AppendString(String* str, const String* src);
|
CC_API void String_AppendString(String* str, const String* src);
|
||||||
/* Attempts to append characters of a string, skipping any colour codes. */
|
/* Attempts to append characters of a string, skipping any colour codes. */
|
||||||
CC_NOINLINE void String_AppendColorless(String* str, const String* src);
|
CC_API void String_AppendColorless(String* str, const String* src);
|
||||||
/* Attempts to append the two hex digits of a byte. */
|
/* Attempts to append the two hex digits of a byte. */
|
||||||
CC_NOINLINE void String_AppendHex(String* str, uint8_t value);
|
CC_API void String_AppendHex(String* str, uint8_t value);
|
||||||
|
|
||||||
/* Returns first index of the given character in the given string, -1 if not found. */
|
/* Returns first index of the given character in the given string, -1 if not found. */
|
||||||
CC_NOINLINE int String_IndexOf(const String* str, char c, int offset);
|
CC_API int String_IndexOf(const String* str, char c, int offset);
|
||||||
/* Returns last index of the given character in the given string, -1 if not found. */
|
/* Returns last index of the given character in the given string, -1 if not found. */
|
||||||
CC_NOINLINE int String_LastIndexOf(const String* str, char c);
|
CC_API int String_LastIndexOf(const String* str, char c);
|
||||||
/* Inserts the given character into the given string. Exits process if this fails. */
|
/* Inserts the given character into the given string. Exits process if this fails. */
|
||||||
/* e.g. inserting 'd' at offset '1' into "abc" produces "adbc" */
|
/* e.g. inserting 'd' at offset '1' into "abc" produces "adbc" */
|
||||||
CC_NOINLINE void String_InsertAt(String* str, int offset, char c);
|
CC_API void String_InsertAt(String* str, int offset, char c);
|
||||||
/* Deletes a character from the given string. Exits process if this fails. */
|
/* Deletes a character from the given string. Exits process if this fails. */
|
||||||
/* e.g. deleting at offset '1' from "adbc" produces "abc" */
|
/* e.g. deleting at offset '1' from "adbc" produces "abc" */
|
||||||
CC_NOINLINE void String_DeleteAt(String* str, int offset);
|
CC_API void String_DeleteAt(String* str, int offset);
|
||||||
/* Trims leading spaces from the given string. */
|
/* Trims leading spaces from the given string. */
|
||||||
/* NOTE: Works by adjusting buffer/length, the characters in memory are not shifted. */
|
/* NOTE: Works by adjusting buffer/length, the characters in memory are not shifted. */
|
||||||
CC_NOINLINE void String_UNSAFE_TrimStart(String* str);
|
CC_API void String_UNSAFE_TrimStart(String* str);
|
||||||
/* Trims trailing spaces from the given string. */
|
/* Trims trailing spaces from the given string. */
|
||||||
/* NOTE: Works by adjusting buffer/length, the characters in memory are not shifted. */
|
/* NOTE: Works by adjusting buffer/length, the characters in memory are not shifted. */
|
||||||
CC_NOINLINE void String_UNSAFE_TrimEnd(String* str);
|
CC_API void String_UNSAFE_TrimEnd(String* str);
|
||||||
|
|
||||||
/* Returns first index of the given substring in the given string, -1 if not found. */
|
/* Returns first index of the given substring in the given string, -1 if not found. */
|
||||||
/* e.g. index of "ab" within "cbabd" is 2 */
|
/* e.g. index of "ab" within "cbabd" is 2 */
|
||||||
CC_NOINLINE int String_IndexOfString(const String* str, const String* sub);
|
CC_API int String_IndexOfString(const String* str, const String* sub);
|
||||||
/* Returns whether given substring is inside the given string. */
|
/* Returns whether given substring is inside the given string. */
|
||||||
#define String_ContainsString(str, sub) (String_IndexOfString(str, sub) >= 0)
|
#define String_ContainsString(str, sub) (String_IndexOfString(str, sub) >= 0)
|
||||||
/* Returns whether given substring is case-insensitively inside the given string. */
|
/* Returns whether given substring is case-insensitively inside the given string. */
|
||||||
CC_NOINLINE bool String_CaselessContains(const String* str, const String* sub);
|
CC_API bool String_CaselessContains(const String* str, const String* sub);
|
||||||
/* Returns whether given substring is case-insensitively equal to the beginning of the given string. */
|
/* Returns whether given substring is case-insensitively equal to the beginning of the given string. */
|
||||||
CC_NOINLINE bool String_CaselessStarts(const String* str, const String* sub);
|
CC_API bool String_CaselessStarts(const String* str, const String* sub);
|
||||||
/* Returns whether given substring is case-insensitively equal to the ending of the given string. */
|
/* Returns whether given substring is case-insensitively equal to the ending of the given string. */
|
||||||
CC_NOINLINE bool String_CaselessEnds(const String* str, const String* sub);
|
CC_API bool String_CaselessEnds(const String* str, const String* sub);
|
||||||
/* Compares the length of the given strings, then compares the characters if same length. Returns: */
|
/* Compares the length of the given strings, then compares the characters if same length. Returns: */
|
||||||
/* -X if a.length < b.length, X if a.length > b.length */
|
/* -X if a.length < b.length, X if a.length > b.length */
|
||||||
/* -X if a.buffer[i] < b.buffer[i], X if a.buffer[i] > b.buffer[i] */
|
/* -X if a.buffer[i] < b.buffer[i], X if a.buffer[i] > b.buffer[i] */
|
||||||
/* else returns 0. NOTE: The return value is not just in -1,0,1! */
|
/* else returns 0. NOTE: The return value is not just in -1,0,1! */
|
||||||
CC_NOINLINE int String_Compare(const String* a, const String* b);
|
CC_API int String_Compare(const String* a, const String* b);
|
||||||
|
|
||||||
/* See String_Format4 */
|
/* See String_Format4 */
|
||||||
void String_Format1(String* str, const char* format, const void* a1);
|
void String_Format1(String* str, const char* format, const void* a1);
|
||||||
@ -164,20 +164,20 @@ int Convert_Utf8ToUnicode(Codepoint* cp, const uint8_t* data, uint32_t len);
|
|||||||
int Convert_UnicodeToUtf8(Codepoint cp, uint8_t* data);
|
int Convert_UnicodeToUtf8(Codepoint cp, uint8_t* data);
|
||||||
|
|
||||||
/* Attempts to convert the given string into an unsigned 8 bit integer. */
|
/* Attempts to convert the given string into an unsigned 8 bit integer. */
|
||||||
CC_NOINLINE bool Convert_ParseUInt8(const String* str, uint8_t* value);
|
CC_API bool Convert_ParseUInt8(const String* str, uint8_t* value);
|
||||||
/* Attempts to convert the given string into an signed 16 bit integer. */
|
/* Attempts to convert the given string into an signed 16 bit integer. */
|
||||||
CC_NOINLINE bool Convert_ParseInt16(const String* str, int16_t* value);
|
CC_API bool Convert_ParseInt16(const String* str, int16_t* value);
|
||||||
/* Attempts to convert the given string into an unsigned 16 bit integer. */
|
/* Attempts to convert the given string into an unsigned 16 bit integer. */
|
||||||
CC_NOINLINE bool Convert_ParseUInt16(const String* str, uint16_t* value);
|
CC_API bool Convert_ParseUInt16(const String* str, uint16_t* value);
|
||||||
/* Attempts to convert the given string into an integer. */
|
/* Attempts to convert the given string into an integer. */
|
||||||
CC_NOINLINE bool Convert_ParseInt(const String* str, int* value);
|
CC_API bool Convert_ParseInt(const String* str, int* value);
|
||||||
/* Attempts to convert the given string into an unsigned 64 bit integer. */
|
/* Attempts to convert the given string into an unsigned 64 bit integer. */
|
||||||
CC_NOINLINE bool Convert_ParseUInt64(const String* str, uint64_t* value);
|
CC_API bool Convert_ParseUInt64(const String* str, uint64_t* value);
|
||||||
/* Attempts to convert the given string into a floating point number. */
|
/* Attempts to convert the given string into a floating point number. */
|
||||||
CC_NOINLINE bool Convert_ParseFloat(const String* str, float* value);
|
CC_API bool Convert_ParseFloat(const String* str, float* value);
|
||||||
/* Attempts to convert the given string into a bool. */
|
/* Attempts to convert the given string into a bool. */
|
||||||
/* NOTE: String must case-insensitively equal "true" or "false" */
|
/* NOTE: String must case-insensitively equal "true" or "false" */
|
||||||
CC_NOINLINE bool Convert_ParseBool(const String* str, bool* value);
|
CC_API bool Convert_ParseBool(const String* str, bool* value);
|
||||||
|
|
||||||
#define STRINGSBUFFER_BUFFER_DEF_SIZE 4096
|
#define STRINGSBUFFER_BUFFER_DEF_SIZE 4096
|
||||||
#define STRINGSBUFFER_FLAGS_DEF_ELEMS 256
|
#define STRINGSBUFFER_FLAGS_DEF_ELEMS 256
|
||||||
@ -192,23 +192,23 @@ typedef struct StringsBuffer_ {
|
|||||||
} StringsBuffer;
|
} StringsBuffer;
|
||||||
|
|
||||||
/* Resets counts to 0, and frees any allocated memory. */
|
/* Resets counts to 0, and frees any allocated memory. */
|
||||||
CC_NOINLINE void StringsBuffer_Clear(StringsBuffer* buffer);
|
CC_API void StringsBuffer_Clear(StringsBuffer* buffer);
|
||||||
/* Copies the characters from the i'th string in the given buffer into the given string. */
|
/* Copies the characters from the i'th string in the given buffer into the given string. */
|
||||||
CC_NOINLINE void StringsBuffer_Get(StringsBuffer* buffer, int i, String* str);
|
CC_API void StringsBuffer_Get(StringsBuffer* buffer, int i, String* str);
|
||||||
/* UNSAFE: Returns a direct pointer to the i'th string in the given buffer. */
|
/* UNSAFE: Returns a direct pointer to the i'th string in the given buffer. */
|
||||||
CC_NOINLINE STRING_REF String StringsBuffer_UNSAFE_Get(StringsBuffer* buffer, int i);
|
CC_API STRING_REF String StringsBuffer_UNSAFE_Get(StringsBuffer* buffer, int i);
|
||||||
/* Adds a given string to the end of the given buffer. */
|
/* Adds a given string to the end of the given buffer. */
|
||||||
CC_NOINLINE void StringsBuffer_Add(StringsBuffer* buffer, const String* str);
|
CC_API void StringsBuffer_Add(StringsBuffer* buffer, const String* str);
|
||||||
/* Removes the i'th string from the given buffer, shifting following strings downwards. */
|
/* Removes the i'th string from the given buffer, shifting following strings downwards. */
|
||||||
CC_NOINLINE void StringsBuffer_Remove(StringsBuffer* buffer, int index);
|
CC_API void StringsBuffer_Remove(StringsBuffer* buffer, int index);
|
||||||
|
|
||||||
/* Performs line wrapping on the given string. */
|
/* Performs line wrapping on the given string. */
|
||||||
/* e.g. "some random tex|t* (| is lineLen) becomes "some random" "text" */
|
/* e.g. "some random tex|t* (| is lineLen) becomes "some random" "text" */
|
||||||
CC_NOINLINE void WordWrap_Do(STRING_REF String* text, String* lines, int numLines, int lineLen);
|
void WordWrap_Do(STRING_REF String* text, String* lines, int numLines, int lineLen);
|
||||||
/* Calculates the position of a raw index in the wrapped lines. */
|
/* Calculates the position of a raw index in the wrapped lines. */
|
||||||
CC_NOINLINE void WordWrap_GetCoords(int index, const String* lines, int numLines, int* coordX, int* coordY);
|
void WordWrap_GetCoords(int index, const String* lines, int numLines, int* coordX, int* coordY);
|
||||||
/* Returns number of characters from current character to end of previous word. */
|
/* Returns number of characters from current character to end of previous word. */
|
||||||
CC_NOINLINE int WordWrap_GetBackLength(const String* text, int index);
|
int WordWrap_GetBackLength(const String* text, int index);
|
||||||
/* Returns number of characters from current character to start of next word. */
|
/* Returns number of characters from current character to start of next word. */
|
||||||
CC_NOINLINE int WordWrap_GetForwardLength(const String* text, int index);
|
int WordWrap_GetForwardLength(const String* text, int index);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user