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.

111 lines
3.0 KiB

1 year ago
  1. #ifndef TYPES_H
  2. #define TYPES_H
  3. #include <stddef.h> // size_t
  4. #define null 0
  5. // long term, it would be nice to not have to '#include' tracy here,
  6. // a client using the library should include it and use a define to instruct
  7. // the library what to put at the beginning of function calls for profiling needs,
  8. // but i've had trouble implementing that.
  9. #ifndef TYPES_H_FTAG
  10. #include <Tracy.hpp>
  11. #define TYPES_H_FTAG ZoneScoped
  12. #endif
  13. // bool is included by default for C++11
  14. #ifndef __cplusplus
  15. typedef _Bool bool;
  16. #define true 1
  17. #define false 0
  18. #endif
  19. // 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).
  20. // https://learn.microsoft.com/en-us/cpp/cpp/restrict?view=msvc-170
  21. // @NOTE(gingerbill posted this):
  22. //#if !defined(restrict)
  23. // #if defined(_MSC_VER)
  24. // #define shard_restrict __restrict
  25. // #elif defined(__STDC_VERSION__)
  26. // #define shard_restrict restrict
  27. // #else
  28. // #define shard_restrict
  29. // #endif
  30. //#endif
  31. // 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.
  32. // https://learn.microsoft.com/en-us/cpp/cpp/noalias?view=msvc-170
  33. // char
  34. // unsigned char
  35. #include <stdint.h>
  36. typedef uint64_t u64;
  37. typedef uint32_t u32;
  38. typedef uint16_t u16;
  39. typedef uint8_t u8;
  40. typedef int64_t s64;
  41. typedef int32_t s32;
  42. typedef int16_t s16;
  43. typedef int8_t s8;
  44. //typedef size_t size_t;
  45. // we use the standard C names for IEEE-754 binary64 and binary32 (double, float). we don't use 'extended'.
  46. //typedef float float;
  47. //typedef double double;
  48. //typedef long double extended;
  49. // if we're using the glm vector/matrix types, or other types, define them here
  50. #define _USING_GLM_TYPES__
  51. #ifdef _USING_GLM_TYPES__
  52. // force high precision for everything
  53. #define GLM_PRECISION_HIGHP_FLOAT
  54. #define GLM_PRECISION_HIGHP_DOUBLE
  55. #define GLM_PRECISION_HIGHP_INT
  56. #define GLM_PRECISION_HIGHP_UINT
  57. #include <glm/glm.hpp>
  58. #include <glm/gtc/matrix_transform.hpp>
  59. #endif
  60. typedef enum TypeEnum {
  61. TypeEnum_bool,
  62. TypeEnum_char,
  63. TypeEnum_uchar,
  64. TypeEnum_u8,
  65. TypeEnum_u16,
  66. TypeEnum_u32,
  67. TypeEnum_u64,
  68. TypeEnum_s8,
  69. TypeEnum_s16,
  70. TypeEnum_s32,
  71. TypeEnum_s64,
  72. #ifndef _WIN32
  73. TypeEnum_size_t,
  74. #endif
  75. TypeEnum_float,
  76. TypeEnum_double,
  77. #ifdef _USING_GLM_TYPES__
  78. TypeEnum_vec2,
  79. TypeEnum_vec3,
  80. TypeEnum_vec4,
  81. TypeEnum_mat2,
  82. TypeEnum_mat3,
  83. TypeEnum_mat4,
  84. #endif
  85. } TypeEnum;
  86. #endif