A collection of basic/generally desirable code I use across multiple C++ projects.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.6 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #ifndef ULE_TYPES_H
  2. #define ULE_TYPES_H
  3. #include <stddef.h> // size_t
  4. #define null 0
  5. #ifndef ULE_TYPES_H_FTAG
  6. #ifdef ULE_CONFIG_OPTION_FTAG
  7. #define ULE_TYPES_H_FTAG ULE_CONFIG_OPTION_FTAG
  8. #else
  9. #define ULE_TYPES_H_FTAG
  10. #endif
  11. #endif
  12. // The restrict declspec is used on functions that return unaliased pointers. This keyword is used for the C-Runtime Library implementation of malloc since it will never return a pointer value that is already in use in the current program (unless you are doing something illegal, such as using memory after it has been freed).
  13. // https://learn.microsoft.com/en-us/cpp/cpp/restrict?view=msvc-170
  14. // @NOTE(gingerbill posted this):
  15. //#if !defined(restrict)
  16. // #if defined(_MSC_VER)
  17. // #define shard_restrict __restrict
  18. // #elif defined(__STDC_VERSION__)
  19. // #define shard_restrict restrict
  20. // #else
  21. // #define shard_restrict
  22. // #endif
  23. //#endif
  24. // The noalias declspec is also applied only to functions, and indicates that the function is a semi-pure function. A semi-pure function is one that references or modifies only locals, arguments, and first-level indirections of arguments. This declspec is a promise to the compiler, and if the function references globals or second-level indirections of pointer arguments then the compiler may generate code that breaks the application.
  25. // https://learn.microsoft.com/en-us/cpp/cpp/noalias?view=msvc-170
  26. // char
  27. // unsigned char
  28. #include <stdint.h>
  29. typedef uint64_t u64;
  30. typedef uint32_t u32;
  31. typedef uint16_t u16;
  32. typedef uint8_t u8;
  33. typedef int64_t s64;
  34. typedef int32_t s32;
  35. typedef int16_t s16;
  36. typedef int8_t s8;
  37. //typedef size_t size_t;
  38. // we use the standard C names for IEEE-754 binary64 and binary32 (double, float). we don't use 'extended'.
  39. //typedef float float;
  40. //typedef double double;
  41. //typedef long double extended;
  42. // if we're using the glm vector/matrix types, or other types, define them here
  43. #ifdef ULE_CONFIG_OPTION_USE_GLM
  44. // force high precision for everything
  45. #define GLM_PRECISION_HIGHP_FLOAT
  46. #define GLM_PRECISION_HIGHP_DOUBLE
  47. #define GLM_PRECISION_HIGHP_INT
  48. #define GLM_PRECISION_HIGHP_UINT
  49. #include <glm/glm.hpp>
  50. #include <glm/gtc/matrix_transform.hpp>
  51. #endif
  52. typedef enum TypeEnum {
  53. TypeEnum_bool,
  54. TypeEnum_char,
  55. TypeEnum_uchar,
  56. TypeEnum_u8,
  57. TypeEnum_u16,
  58. TypeEnum_u32,
  59. TypeEnum_u64,
  60. TypeEnum_s8,
  61. TypeEnum_s16,
  62. TypeEnum_s32,
  63. TypeEnum_s64,
  64. #ifndef _WIN32
  65. TypeEnum_size_t,
  66. #endif
  67. TypeEnum_float,
  68. TypeEnum_double,
  69. #ifdef _USING_GLM_TYPES__
  70. TypeEnum_vec2,
  71. TypeEnum_vec3,
  72. TypeEnum_vec4,
  73. TypeEnum_mat2,
  74. TypeEnum_mat3,
  75. TypeEnum_mat4,
  76. #endif
  77. } TypeEnum;
  78. #endif