Advertisement
Kitomas

kit_core.h as of 8-18-23

Aug 18th, 2023
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.65 KB | None | 0 0
  1. /**
  2.  * \file kit_core.h
  3.  * \brief Header file for KIT SDL2's core library
  4.  */
  5. #ifndef _KIT_CORE_H
  6. #define _KIT_CORE_H
  7. #ifndef _KIT_SDL2_CORE_H
  8. #define _KIT_SDL2_CORE_H
  9.  
  10. #include <SDL2/SDL.h>
  11.  
  12.  
  13.  
  14. /* +kit_core+ */
  15. extern int kit_coreInit();
  16. extern int kit_coreQuit();
  17. /* -kit_core- */
  18.  
  19.  
  20.  
  21. /* +kit_coreThread+ */
  22. typedef struct {
  23.   SDL_Thread* thread;
  24.   void*         data;
  25.   SDL_mutex*    lock;
  26.   int   returnStatus;
  27.   int          state;
  28. } kit_coreThread;
  29. /* -kit_coreThread- */
  30.  
  31.  
  32.  
  33. /* +kit_sdl2_coreVector+ */
  34. //extern void _kit_coreVectorPrintInt(kit_coreVector* Vector,const char* prefix);
  35.  
  36. /**
  37.  * \brief The struct for a contiguous dynamic array.
  38.  */
  39. typedef struct {
  40.   union {
  41.     char    s[4]; ///< \brief String portion of ID (albeit a short string).
  42.     Uint32     n; ///< \brief Integer portion of ID.
  43.   } /* --- */ type; ///< \brief A user-defined type identifier.
  44.   Uint32         x; ///< \brief Length of the vector's x axis.
  45.   Uint32         y; ///< \brief Length of the vector's y axis (0 means the axis is nonexistent).
  46.   Uint32         z; ///< \brief Length of the vector's z axis (0 means the axis is nonexistent).
  47.   Uint32      unit; ///< \brief size of each data element.
  48.   Sint32     _dims; ///< \brief (read only) 1=1D, 2=2D, 3=3D.
  49.   union {
  50.     void *p1d, **p2d, ***p3d, *ptr; ///< \brief The actual array portion of the vector.
  51.   };
  52. } kit_coreVector;
  53.  
  54.  
  55. /**
  56.  * Add to or subtract from size of a kit_coreVector.
  57.  * \param[in,out] Vector_p A pointer to the kit_coreVector* to be altered.
  58.  * \param[in] x_add How much to increase or decrease the x axis.
  59.  * \param[in] y_add How much to increase or decrease the y axis.
  60.  * \param[in] z_add How much to increase or decrease the z axis.
  61.  * \return 0 on success, or a negative error code (call SDL_GetError() for more info).
  62.  *
  63.  * \remark As stated in kit_coreVectorSet, vectors cannot change from 1D -> 2D, 2D -> 3D, etc.
  64.  * \sa kit_coreVectorSet
  65.  */
  66. extern int kit_coreVectorAdd(kit_coreVector** Vector_p, Sint32 x_add, Sint32 y_add, Sint32 z_add);
  67.  
  68. /**
  69.  * Set the size of a kit_coreVector.
  70.  * \param[in,out] Vector_p A pointer to the kit_coreVector* to be altered.
  71.  * \param[in] x_new New size for the x axis (set to 0 to leave x unchanged).
  72.  * \param[in] y_new New size for the y axis (set to 0 to leave y unchanged).
  73.  * \param[in] z_new New size for the z axis (set to 0 to leave z unchanged).
  74.  * \return 0 on success, or a negative error code (call SDL_GetError() for more info).
  75.  *
  76.  * \remark The result of a size change cannot turn a 1D vector to a 2D one, vice versa, and so on.
  77.  * \sa kit_coreVectorAdd
  78.  */
  79. extern int kit_coreVectorSet(kit_coreVector** Vector_p, Uint32 x_new, Uint32 y_new, Uint32 z_new);
  80.  
  81.  
  82. /**
  83.  * Destroy a kit_coreVector.
  84.  * \param[in,out] Vector_p A pointer to the kit_coreVector* to be destroyed (before being set to NULL).
  85.  *
  86.  * \return 0 on success, or a negative error code (call SDL_GetError() for more info).
  87.  * \sa kit_coreVectorCreate
  88.  */
  89. extern int kit_coreVectorDestroy(kit_coreVector** Vector_p);
  90.  
  91. /**
  92.  * Create a new kit_coreVector.
  93.  * \param[in] x Size of the vector on the x axis.
  94.  * \param[in] y Size of the vector on the y axis (set to 0 to disable the axis entirely).
  95.  * \param[in] z Size of the vector on the z axis (set to 0 to disable the axis entirely).
  96.  * \param[in] unit The size of each data element, in bytes.
  97.  * \param[in] type_n A user-defined number which acts as the vector's type identifier.
  98.  * \param[out] returnStatus_p A pointer to an int to be filled with the error code (can be NULL).
  99.  * \return A pointer to a newly-created Vector struct, or NULL on error (call SDL_GetError() for more info).
  100.  *
  101.  * \remark "unit" determines of each DATA element, which is to say, while a 1D vector's element size is
  102.            equal to unit on the x axis, a 2D vector's element size on the x axis will be that of a void*.
  103.  * \remark Whether or not returnStatus_p is NULL, SDL_GetError() will be set in the event of an error.
  104.  * \sa kit_coreVectorDestroy
  105.  */
  106. extern kit_coreVector* kit_coreVectorCreate(Uint32 x, Uint32 y, Uint32 z,
  107.                                             Uint32 unit, Uint32 type_n,
  108.                                             int* returnStatus_p);
  109. /* -kit_sdl2_coreVector- */
  110.  
  111.  
  112.  
  113. /* +kit_coreFstr+ */
  114. #ifndef _WCHAR_T_DEFINED
  115. #  include <wchar.h>
  116. #endif
  117. #ifndef _FSTR
  118. # define _FSTR
  119. #  define fstr kit_coreFstr
  120. #endif
  121. #ifndef _FSTRW
  122. # define _FSTRW
  123. #  define fstrw kit_coreFstrw
  124. #endif
  125. /**
  126.  * \brief This struct contains buffer information for fstr.
  127.  */
  128. typedef struct {
  129.   union {
  130.     char*     s; ///< \brief The char portion of the string union.
  131.     wchar_t*  w; ///< \brief The wchar portion of the string union.
  132.   } /* ----- */ b; ///< \brief The actual string buffer union.
  133.   Uint32 mem_size; ///< \brief The size of the string buffer, in bytes.
  134.   Uint32 _padding; ///< \brief (unused) Another Uint32 to pad to a multiple of 8 bytes.
  135. } kit_coreFstr_t;
  136.  
  137.  
  138. /**
  139.  * Format a string, before returning that string.
  140.  * \param[in,out] buffer A pointer to a kit_coreFstr_t that contains buffer information.
  141.  * \param[in] fmt The format string; used the same way as the first argument to printf.
  142.  * \param[in] ... List of variables to be formatted, if any.
  143.  * \return A pointer to the newly-formatted string, or NULL on error (call SDL_GetError() for more info).
  144.  *
  145.  * \sa kit_coreFstrw
  146.  */
  147. extern char* kit_coreFstr(kit_coreFstr_t* buffer, const char* fmt,...);
  148.  
  149. /**
  150.  * Format a wide string, before returning that wide string.
  151.  * \param[in,out] buffer A pointer to a kit_coreFstr_t that contains buffer information.
  152.  * \param[in] fmt The format string; used the same way as the first argument to wprintf.
  153.  * \param[in] ... List of variables to be formatted, if any.
  154.  * \return A pointer to the newly-formatted wide string, or NULL on error (call SDL_GetError() for more info).
  155.  *
  156.  * \sa kit_coreFstr
  157.  */
  158. extern wchar_t* kit_coreFstrw(kit_coreFstr_t* buffer, const wchar_t* fmt,...);
  159.  
  160.  
  161. /**
  162.  * Destroy a kit_coreFstr_t buffer.
  163.  * \param[in,out] buffer_p A pointer to the kit_coreFstr_t* to be destroyed (before being set to NULL).
  164.  * \return 0 on success, or a negative error code (call SDL_GetError() for more info).
  165.  *
  166.  * \sa kit_coreFstrCreate
  167.  */
  168. extern int kit_coreFstrDestroy(kit_coreFstr_t** buffer_p);
  169.  
  170. /**
  171.  * Create a new kit_coreFstr_t.
  172.  * \param[in] buffer_size the size of the string's buffer, in bytes.
  173.  * \return A pointer to a newly-created Fstr_t struct, or NULL on error (call SDL_GetError() for more info).
  174.  *
  175.  * \sa kit_coreFstrDestroy
  176.  */
  177. extern kit_coreFstr_t* kit_coreFstrCreate(Uint32 buffer_size);
  178. /* -kit_coreFstr- */
  179.  
  180.  
  181.  
  182. #endif /* _KIT_SDL2_CORE_H */
  183. #endif /* _KIT_CORE_H */
  184.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement