LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_misc.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2025
3  * All rights reserved
4  */
5 
6 #ifndef LG_MISC_H
7 #define LG_MISC_H
8 
9 #define CHECK_GL_E lg_check_gl_errors(lg_log_time(), __FILE__ , __LINE__, __func__)
10 
11 #define CHECK_GL_E_2 {if (lg_check_gl_errors(lg_log_time(), __FILE__, __LINE__, __func__) != LG_OK) exit(-1);}
12 
13 #define STH_WRONG_HERE \
14  { \
15  static int i = 0; \
16  if (i == 0) { \
17  INFO_OUT("VARO TÄSSÄ\n%s [%s: %d] %s(): jotain pitää korjata\n", UTF8_RW_ROUNDED_ARROW, __FILE__, __LINE__, __func__) \
18  i++; \
19  } \
20  }
21 
22 /* IS_IN() is exclusive / IS_IN2() is inclusive -> IS_IN_exc() / IS_IN_inc() ? */
23 
24 /* Not inclusive */
25 #define IS_IN(x, y, z) (x > y && x < z ? TRUE : FALSE)
26 
27 /* Inclusive */
28 #define IS_IN2(x, y, z) (x >= y && x <= z ? TRUE : FALSE)
29 
30 typedef enum {LG_LITTLE_ENDIAN, LG_BIG_ENDIAN} lg_endianness;
31 
32 /*
33  * A few conversions helpers
34  *
35  * 1 knot (KT) = 1 nautical mile (NM) / h
36  */
37 #define FEET_TO_METERS 0.3048
38 #define METERS_TO_FEET (1 / FEET_TO_METERS)
39 #define MILES_TO_KM 1.852
40 #define KM_TO_MILES (1 / MILES_TO_KM)
41 #define KNOTS_TO_KMH MILES_TO_KM
42 #define KMH_TO_KNOTS KM_TO_MILES
43 
44 /* Only for backward compatibility */
45 #define UTF8_RW_ROUNDED_ARROW RW_ROUNDED_ARROW_UTF8
46 
47 // === Tokens, UTF-8 hex codes and drawings ===
48 
49 #define LEFT_ARROW_LIGHT_UTF8 "\u2190" // ←
50 #define RIGHT_ARROW_LIGHT_UTF8 "\u2192" // →
51 #define UP_ARROW_LIGHT_UTF8 "\u2191" // ↑
52 #define DOWN_ARROW_LIGHT_UTF8 "\u2193" // ↓
53 #define RW_ROUNDED_ARROW_UTF8 "\u279c" // ➜
54 
55 /*
56  BOX_N_UTF8
57 
58  1--2--3-----4
59  5 | |
60  6-----7-----8
61  | | |
62  9----10----11
63 */
64 
65 #define BOX_1_UTF8 "\u250c" // ┌
66 #define BOX_2_UTF8 "\u2500" // ─
67 #define BOX_3_UTF8 "\u252c" // ┬
68 #define BOX_4_UTF8 "\u2510" // ┐
69 #define BOX_5_UTF8 "\u2502" // │
70 #define BOX_6_UTF8 "\u251c" // ├
71 #define BOX_7_UTF8 "\u253c" // ┼
72 #define BOX_8_UTF8 "\u2524" // ┤
73 #define BOX_9_UTF8 "\u2514" // └
74 #define BOX_10_UTF8 "\u2534" // ┴
75 #define BOX_11_UTF8 "\u2518" // ┘
76 
77 #define STACK_N_MAX_ELEMENTS 1024
78 
79 /* Dynamic stacks */
80 typedef struct {
81  int *v;
82  int max_n;
83  int i;
84 } LG_Stack_i;
85 
86 typedef struct {
87  float *v;
88  int max_n;
89  int i;
90 } LG_Stack_f;
91 
92 /* Width in bytes */
93 typedef enum {
94  WBY_8_BIT = 1,
95  WBY_16_BIT = 2,
96  WBY_32_BIT = 4,
97  WBY_64_BIT = 8
98 } WidthInBytes;
99 
101 
103 
104 int lg_check_gl_errors(long long, const char *, int, const char *);
105 
106 int lg_check_gl_context();
107 
108 lg_endianness lg_get_arch_endianness();
109 
110 float lg_tv_diff(struct timeval *, struct timeval *, struct timeval *);
111 
112 int delta_i(int);
113 
114 float delta_f(float);
115 
116 zboolean has_changed_i(int);
117 
118 zboolean has_changed_f(float);
119 
120 double clamp(double, double, double);
121 
123 
125 
126 void lg_swap_values(void *, void *, WidthInBytes);
127 
129 
130 void debug_max_int_in_loop(unsigned long, const char *, int);
131 
133 
135 
136 void debug_max_float_in_loop(float, const char *, int);
137 
139 
141 
142 void lg_show_struct_sizes(zboolean);
143 
145 
146 void lg_show_utf8_drawings(zboolean);
147 
148 #endif /* LG_MISC_H */
lg_show_pixel_format_info_from_sdl_display_mode
int lg_show_pixel_format_info_from_sdl_display_mode(SDL_DisplayMode *display_mode)
Definition: lg_misc.c:604
has_changed_i
zboolean has_changed_i(int i)
Definition: lg_misc.c:189
lg_tv_diff
float lg_tv_diff(struct timeval *t_diff, struct timeval *t2, struct timeval *t1)
Definition: lg_misc.c:133
lg_get_arch_endianness
lg_endianness lg_get_arch_endianness()
Definition: lg_misc.c:100
lg_show_struct_sizes
void lg_show_struct_sizes(zboolean everything)
Definition: lg_misc.c:506
LG_Stack_i
Definition: lg_misc.h:80
lg_check_gl_context
int lg_check_gl_context()
Definition: lg_misc.c:74
has_changed_f
zboolean has_changed_f(float f)
Definition: lg_misc.c:200
LG_Stack_f
Definition: lg_misc.h:86
clamp
double clamp(double v, double min, double max)
Definition: lg_misc.c:213
debug_end_max_float_in_loop
void debug_end_max_float_in_loop()
Definition: lg_misc.c:401
lg_disable_transparency
void lg_disable_transparency()
Definition: lg_misc.c:26
lg_align_up_to_next_8_bytes_boundary
void * lg_align_up_to_next_8_bytes_boundary(void *addr)
Definition: lg_misc.c:248
lg_align_up_to_next_4_bytes_boundary
void * lg_align_up_to_next_4_bytes_boundary(void *addr)
Definition: lg_misc.c:229
delta_i
int delta_i(int i)
Definition: lg_misc.c:161
debug_end_max_int_in_loop
void debug_end_max_int_in_loop()
Definition: lg_misc.c:363
debug_start_max_int_in_loop
void debug_start_max_int_in_loop()
Definition: lg_misc.c:323
delta_f
float delta_f(float f)
Definition: lg_misc.c:175
debug_max_float_in_loop
void debug_max_float_in_loop(float f, const char *file, int line)
Definition: lg_misc.c:390
debug_start_max_float_in_loop
void debug_start_max_float_in_loop()
Definition: lg_misc.c:376
lg_swap_values
void lg_swap_values(void *x, void *y, WidthInBytes width)
Definition: lg_misc.c:301
lg_check_gl_errors
int lg_check_gl_errors(long long log_time, const char *file, int line, const char *func)
Definition: lg_misc.c:40
lg_enable_transparency
void lg_enable_transparency()
Definition: lg_misc.c:17
lg_check_datatype_sizes
int lg_check_datatype_sizes()
Definition: lg_misc.c:413
debug_max_int_in_loop
void debug_max_int_in_loop(unsigned long i, const char *file, int line)
Definition: lg_misc.c:352
lg_show_utf8_drawings
void lg_show_utf8_drawings(zboolean extra_n)
Definition: lg_misc.c:648