Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * \file kit_core.h
- * \brief Header file for KIT SDL2's core library
- */
- #ifndef _KIT_CORE_H
- #define _KIT_CORE_H
- #ifndef _KIT_SDL2_CORE_H
- #define _KIT_SDL2_CORE_H
- #include <SDL2/SDL.h>
- /* ++++++++++ */
- /* +kit_core+ */
- /* ++++++++++ */
- //bitmask of a Uint16's MSb/MSB
- #define U16_MSb ((Uint16)1<<15)
- #define U16_MSbC (~U16_MSb) //ones' complement of U16_MSb
- #define U16_MSB ((Uint16)0xFF<<8)
- #define U16_MSBC (~U16_MSB) //ones' complement of U16_MSB
- //bitmask of a Uint32's MSb/MSB
- #define U32_MSb ((Uint32)1<<31)
- #define U32_MSbC (~U32_MSb) //ones' complement of U32_MSb
- #define U32_MSB ((Uint32)0xFF<<24)
- #define U32_MSBC (~U32_MSB) //ones' complement of U32_MSB
- //bitmask of a Uint64's MSb/MSB
- #define U64_MSb ((Uint64)1<<63)
- #define U64_MSbC (~U64_MSb) //ones' complement of U64_MSb
- #define U64_MSB ((Uint64)0xFF<<56)
- #define U64_MSBC (~U64_MSB) //ones' complement of U64_MSB
- #define U16_MAX (0xffff)
- #define U32_MAX (0xffffffff)
- #define U64_MAX (0xffffffffffffffff)
- //use something like "0x%08X%08X" in the format string for this to work properly
- #define U64_PRINT(_num) ( (Uint32)((_num)>>32) ),( (Uint32)(_num)&U32_MAX )
- //string to unsigned int
- #define STR_U32(_s) ( *(Uint32*)(_s"\x00\x00\x00") )
- #define STR_U64(_s) ( *(Uint64*)(_s"\x00\x00\x00\x00\x00\x00\x00") )
- #if defined(_KIT_CORE_DEBUG) || defined(_KIT_ALL_DEBUG)
- #define kit_coreLog(...) SDL_Log(__VA_ARGS__)
- #else
- #define kit_coreLog(...) ;
- #endif
- extern const SDL_bool kit_coreIsDebug;
- extern const char kit_coreBoolStr[2][6];
- extern int kit_coreRealloc(void* ptr_p, size_t size_old, size_t size_new);
- extern int kit_coreInit();
- extern int kit_coreQuit();
- /* ---------- */
- /* -kit_core- */
- /* ---------- */
- /* ++++++++++++++++ */
- /* +kit_coreThread+ */
- /* ++++++++++++++++ */
- typedef struct { //32B
- SDL_Thread* thread;
- void* data;
- SDL_mutex* lock;
- int _,returnStatus;
- } kit_coreThread;
- /* ---------------- */
- /* -kit_coreThread- */
- /* ---------------- */
- /* +++++++++++++++++++++ */
- /* +kit_sdl2_coreVector+ */
- /* +++++++++++++++++++++ */
- //assumes that _vector is a vector pointer
- #define PRINT_VECTOR(_pref, _vector) { \
- kit_coreLog(_pref"->type.s=\"%s\"",(_vector)->type.s); \
- kit_coreLog(_pref"->x =%u",(_vector)->x); \
- kit_coreLog(_pref"->y =%u",(_vector)->y); \
- kit_coreLog(_pref"->z =%u",(_vector)->z); \
- kit_coreLog(_pref"->unit =%u",(_vector)->unit); \
- kit_coreLog(_pref"->_dims =0x%08X%08X",U64_PRINT((_vector)->_dims)); \
- kit_coreLog(_pref"->lens =%p",(_vector)->lens.r3D); \
- kit_coreLog(_pref"->ptr =%p",(_vector)->ptr); }
- //now this should be easier to change if i want to alter
- //the struct's size/lengths type
- typedef Uint32 lens_t; ///< \brief The unsigned integer type used for kit_coreVector lengths
- typedef Sint32 diffs_t; ///< \brief The signed integer type used for kit_coreVector length differences
- /**
- * \brief The struct for a contiguous dynamic array (dereference order is [x][y][z]).
- */
- typedef struct { //48B (assuming that lens_t is Uint32, and a void* is 8 bytes)
- union {
- char s[8]; ///< \brief String portion of ID (albeit a short string).
- Uint64 n; ///< \brief Integer portion of ID.
- } /* --- */ type; ///< \brief A user-defined type identifier.
- lens_t x; ///< \brief Length of the vector's (allocated) x axis.
- lens_t y; ///< \brief Length of the vector's (allocated) y axis (0 means the axis is nonexistent).
- lens_t z; ///< \brief Length of the vector's (allocated) z axis (0 means the axis is nonexistent).
- lens_t unit; ///< \brief size of each data element.
- Sint64 _dims; ///< \brief (read only) 1=1D, 2=2D, 3=3D vector respectively.
- union {
- lens_t r1D; ///< \brief real length of x
- lens_t* r2D; ///< \brief real lengths of each y index in x
- lens_t** r3D; ///< \brief real lengths of each z index in y
- } /* --- */ lens; ///< \brief lengths for individual axes (must be <= the actual allocated size)
- union {
- void *p1d, **p2d, ***p3d, *ptr; ///< \brief The actual array portion of the vector.
- };
- } kit_coreVector;
- /**
- * Add to or subtract from size of a kit_coreVector.
- * \param[in,out] Vector_p A pointer to the kit_coreVector* to be altered.
- * \param[in] x_add How much to increase or decrease the x axis.
- * \param[in] y_add How much to increase or decrease the y axis.
- * \param[in] z_add How much to increase or decrease the z axis.
- * \return 0 on success, or a negative error code (call SDL_GetError() for more info).
- *
- * \remark As stated in kit_coreVectorSet, vectors cannot change from 1D -> 2D, 2D -> 3D, etc.
- * \sa kit_coreVectorSet
- * \sa kit_coreVectorAppend
- */
- extern int kit_coreVectorAdd(kit_coreVector** Vector_p, diffs_t x_add, diffs_t y_add, diffs_t z_add);
- /**
- * Set the size of a kit_coreVector.
- * \param[in,out] Vector_p A pointer to the kit_coreVector* to be altered.
- * \param[in] x_new New size for the x axis (set to 0 to leave x unchanged).
- * \param[in] y_new New size for the y axis (set to 0 to leave y unchanged).
- * \param[in] z_new New size for the z axis (set to 0 to leave z unchanged).
- * \return 0 on success, or a negative error code (call SDL_GetError() for more info).
- *
- * \remark The result of a size change cannot turn a 1D vector to a 2D one, vice versa, and so on.
- * \sa kit_coreVectorAdd
- * \sa kit_coreVectorAppend
- */
- extern int kit_coreVectorSet(kit_coreVector** Vector_p, lens_t x_new, lens_t y_new, lens_t z_new);
- /**
- * Append an element to the end of a 1D kit_coreVector*
- * \param[in,out] Vector_p A pointer to the kit_coreVector* to be altered.
- * \param[in] src The data to be copied and appended to the end of the vector
- * \return The newly-created index, or -1 on error (call SDL_GetError() for more info).
- *
- * \remark *src must be *Vector_p->unit bytes in size or bad things will happen.
- * \sa kit_coreVectorAppend2D
- * \sa kit_coreVectorAppend3D
- * \sa kit_coreVectorAppend
- * \sa kit_coreVectorAdd
- * \sa kit_coreVectorSet
- */
- extern lens_t kit_coreVectorAppend1D(kit_coreVector** Vector_p, void* src);
- /**
- * Append an element to the end of a 2D kit_coreVector*
- * \param[in,out] Vector_p A pointer to the kit_coreVector* to be altered.
- * \param[in] src The data to be copied and appended to the end of the vector
- * \param[in] x_pos The x index to append to
- * \return The newly-created index, or 0xffffffff on error (call SDL_GetError() for more info).
- *
- * \remark *src must be *Vector_p->unit bytes in size or bad things will happen.
- * \sa kit_coreVectorAppend1D
- * \sa kit_coreVectorAppend3D
- * \sa kit_coreVectorAppend
- * \sa kit_coreVectorAdd
- * \sa kit_coreVectorSet
- */
- extern lens_t kit_coreVectorAppend2D(kit_coreVector** Vector_p, void* src, lens_t x_pos);
- /**
- * Append an element to the end of a 2D kit_coreVector*
- * \param[in,out] Vector_p A pointer to the kit_coreVector* to be altered.
- * \param[in] src The data to be copied and appended to the end of the vector
- * \param[in] x_pos The x index to append to
- * \param[in] y_pos The y index to append to
- * \return The newly-created index, or 0xffffffff on error (call SDL_GetError() for more info).
- *
- * \remark *src must be *Vector_p->unit bytes in size or bad things will happen.
- * \sa kit_coreVectorAppend1D
- * \sa kit_coreVectorAppend2D
- * \sa kit_coreVectorAppend
- * \sa kit_coreVectorAdd
- * \sa kit_coreVectorSet
- */
- extern lens_t kit_coreVectorAppend3D(kit_coreVector** Vector_p, void* src, lens_t x_pos, lens_t y_pos);
- /**
- * Append an element to the end of a kit_coreVector*
- * \param[in,out] Vector_p A pointer to the kit_coreVector* to be altered.
- * \param[in] src The data to be copied and appended to the end of the vector
- * \param[in] x_pos The x index to append to (ignored for 1D vectors)
- * \param[in] y_pos The y index to append to (ignored for <3D vectors)
- * \return The newly-created index, or 0xffffffff on error (call SDL_GetError() for more info).
- *
- * \remark *src must be *Vector_p->unit bytes in size or bad things will happen.
- * \sa kit_coreVectorAppend1D
- * \sa kit_coreVectorAppend2D
- * \sa kit_coreVectorAppend3D
- * \sa kit_coreVectorAdd
- * \sa kit_coreVectorSet
- */
- extern lens_t kit_coreVectorAppend(kit_coreVector** Vector_p, void* src, lens_t x_pos, lens_t y_pos);
- /**
- * Destroy a kit_coreVector.
- * \param[in,out] Vector_p A pointer to the kit_coreVector* to be destroyed (before being set to NULL).
- * \return 0 on success, or a negative error code (call SDL_GetError() for more info).
- *
- * \sa kit_coreVectorCreate
- */
- extern int kit_coreVectorDestroy(kit_coreVector** Vector_p);
- /**
- * Create a new kit_coreVector.
- * \param[in] x Size of the vector on the x axis.
- * \param[in] y Size of the vector on the y axis (set to 0 to disable the axis entirely).
- * \param[in] z Size of the vector on the z axis (set to 0 to disable the axis entirely).
- * \param[in] unit The size of each data element, in bytes.
- * \param[in] type_n A user-defined number which acts as the vector's type identifier.
- * \return A pointer to a newly-created Vector struct, or NULL on error (call SDL_GetError() for more info).
- *
- * \remark "unit" determines of each DATA element, which is to say, while a 1D vector's element size is
- equal to unit on the x axis, a 2D vector's element size on the x axis will be that of a void*.
- * \remark Whether or not returnStatus_p is NULL, SDL_GetError() will be set in the event of an error.
- * \sa kit_coreVectorDestroy
- */
- extern kit_coreVector* kit_coreVectorCreate(lens_t x, lens_t y, lens_t z, lens_t unit, Uint64 type_n);
- extern void _kit_coreVectorPrintInt(kit_coreVector* Vector,const char* prefix); //debug
- extern int kit_coreVectorTest(); //debug
- /* --------------------- */
- /* -kit_sdl2_coreVector- */
- /* --------------------- */
- /* ++++++++++++++ */
- /* +kit_coreFstr+ */
- /* ++++++++++++++ */
- #ifndef _WCHAR_T_DEFINED
- # include <wchar.h>
- #endif
- #ifndef _FSTR
- # define _FSTR
- # define fstr kit_coreFstr
- #endif
- #ifndef _FSTRW
- # define _FSTRW
- # define fstrw kit_coreFstrw
- #endif
- /**
- * \brief This struct contains buffer information for fstr.
- */
- typedef struct {
- union {
- char* s; ///< \brief The char portion of the string union.
- wchar_t* w; ///< \brief The wchar portion of the string union.
- } /* ----- */ b; ///< \brief The actual string buffer union.
- Uint32 mem_size; ///< \brief The size of the string buffer, in bytes.
- Uint32 _padding; ///< \brief (unused) Another Uint32 to pad to a multiple of 8 bytes.
- } kit_coreFstr_t;
- /**
- * Format a string, before returning that string.
- * \param[in,out] buffer A pointer to a kit_coreFstr_t that contains buffer information.
- * \param[in] fmt The format string; used the same way as the first argument to printf.
- * \param[in] ... List of variables to be formatted, if any.
- * \return A pointer to the newly-formatted string, or NULL on error (call SDL_GetError() for more info).
- *
- * \sa kit_coreFstrw
- */
- extern char* kit_coreFstr(kit_coreFstr_t* buffer, const char* fmt,...);
- /**
- * Format a wide string, before returning that wide string.
- * \param[in,out] buffer A pointer to a kit_coreFstr_t that contains buffer information.
- * \param[in] fmt The format string; used the same way as the first argument to wprintf.
- * \param[in] ... List of variables to be formatted, if any.
- * \return A pointer to the newly-formatted wide string, or NULL on error (call SDL_GetError() for more info).
- *
- * \sa kit_coreFstr
- */
- extern wchar_t* kit_coreFstrw(kit_coreFstr_t* buffer, const wchar_t* fmt,...);
- /**
- * Destroy a kit_coreFstr_t buffer.
- * \param[in,out] buffer_p A pointer to the kit_coreFstr_t* to be destroyed (before being set to NULL).
- * \return 0 on success, or a negative error code (call SDL_GetError() for more info).
- *
- * \sa kit_coreFstrCreate
- */
- extern int kit_coreFstrDestroy(kit_coreFstr_t** buffer_p);
- /**
- * Create a new kit_coreFstr_t.
- * \param[in] buffer_size the size of the string's buffer, in bytes.
- * \return A pointer to a newly-created Fstr_t struct, or NULL on error (call SDL_GetError() for more info).
- *
- * \sa kit_coreFstrDestroy
- */
- extern kit_coreFstr_t* kit_coreFstrCreate(Uint32 buffer_size);
- /* -------------- */
- /* -kit_coreFstr- */
- /* -------------- */
- #endif /* _KIT_SDL2_CORE_H */
- #endif /* _KIT_CORE_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement