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 /* Not inclusive */
23 #define IS_IN(x, y, z) (x > y && x < z ? TRUE : FALSE)
24 
25 /* Inclusive */
26 #define IS_IN2(x, y, z) (x >= y && x <= z ? TRUE : FALSE)
27 
28 typedef enum {LG_LITTLE_ENDIAN, LG_BIG_ENDIAN} lg_endianness;
29 
30 /*
31  * A few conversions helpers
32  *
33  * 1 knot (KT) = 1 nautical mile (NM) / h
34  */
35 #define FEET_TO_METERS 0.3048
36 #define METERS_TO_FEET (1 / FEET_TO_METERS)
37 #define MILES_TO_KM 1.852
38 #define KM_TO_MILES (1 / MILES_TO_KM)
39 #define KNOTS_TO_KMH MILES_TO_KM
40 #define KMH_TO_KNOTS KM_TO_MILES
41 
42 /* Only for backward compatibility */
43 #define UTF8_RW_ROUNDED_ARROW RW_ROUNDED_ARROW_UTF8
44 
45 // === Tokens, UTF-8 hex codes and drawings ===
46 
47 #define LEFT_ARROW_LIGHT_UTF8 "\u2190" // ←
48 #define RIGHT_ARROW_LIGHT_UTF8 "\u2192" // →
49 #define UP_ARROW_LIGHT_UTF8 "\u2191" // ↑
50 #define DOWN_ARROW_LIGHT_UTF8 "\u2193" // ↓
51 #define RW_ROUNDED_ARROW_UTF8 "\u279c" // ➜
52 
53 /*
54  BOX_N_UTF8
55 
56  1--2--3-----4
57  5 | |
58  6-----7-----8
59  | | |
60  9----10----11
61 */
62 
63 #define BOX_1_UTF8 "\u250c" // ┌
64 #define BOX_2_UTF8 "\u2500" // ─
65 #define BOX_3_UTF8 "\u252c" // ┬
66 #define BOX_4_UTF8 "\u2510" // ┐
67 #define BOX_5_UTF8 "\u2502" // │
68 #define BOX_6_UTF8 "\u251c" // ├
69 #define BOX_7_UTF8 "\u253c" // ┼
70 #define BOX_8_UTF8 "\u2524" // ┤
71 #define BOX_9_UTF8 "\u2514" // └
72 #define BOX_10_UTF8 "\u2534" // ┴
73 #define BOX_11_UTF8 "\u2518" // ┘
74 
75 #define STACK_N_MAX_ELEMENTS 1024
76 
77 /* Dynamic stacks */
78 typedef struct {
79  int *v;
80  int max_n;
81  int i;
82 } LG_Stack_i;
83 
84 typedef struct {
85  float *v;
86  int max_n;
87  int i;
88 } LG_Stack_f;
89 
91 
93 
94 int lg_check_gl_errors(long long, const char *, int, const char *);
95 
97 
98 lg_endianness lg_get_arch_endianness();
99 
100 float lg_tv_diff(struct timeval *, struct timeval *, struct timeval *);
101 
102 int delta_i(int);
103 
104 float delta_f(float);
105 
106 zboolean has_changed_i(int);
107 
108 zboolean has_changed_f(float);
109 
110 void lg_stack_show_full_empty_errors(zboolean);
111 
113 
115 
116 zboolean push_i(LG_Stack_i *, int);
117 
118 zboolean pop_i(LG_Stack_i *, int *);
119 
121 
123 
124 zboolean push_f(LG_Stack_f *, float);
125 
126 zboolean pop_f(LG_Stack_f *, float *);
127 
128 float lg_swap_float_values(float *, float *);
129 
130 double lg_swap_double_values(double *x, double *y);
131 
132 int32_t lg_swap_int32_values(int32_t *x, int32_t *y);
133 
134 uint32_t lg_swap_uint32_values(uint32_t *x, uint32_t *y);
135 
136 int16_t lg_swap_int16_values(int16_t *x, int16_t *y);
137 
138 uint16_t lg_swap_uint16_values(uint16_t *x, uint16_t *y);
139 
140 int8_t lg_swap_int8_values(int8_t *x, int8_t *y);
141 
142 uint8_t lg_swap_uint8_values(uint8_t *x, uint8_t *y);
143 
145 
146 void debug_max_int_in_loop(unsigned long, const char *, int);
147 
149 
151 
152 void debug_max_float_in_loop(float, const char *, int);
153 
155 
157 
158 void lg_show_struct_sizes(zboolean);
159 
161 
162 void lg_show_utf8_drawings(zboolean);
163 
164 #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:776
lg_swap_double_values
double lg_swap_double_values(double *x, double *y)
Definition: lg_misc.c:391
has_changed_i
zboolean has_changed_i(int i)
Definition: lg_misc.c:178
lg_tv_diff
float lg_tv_diff(struct timeval *t_diff, struct timeval *t2, struct timeval *t1)
Definition: lg_misc.c:122
lg_get_arch_endianness
lg_endianness lg_get_arch_endianness()
Definition: lg_misc.c:101
lg_stack_i_free
void lg_stack_i_free(LG_Stack_i *s)
Definition: lg_misc.c:241
lg_stack_f_free
void lg_stack_f_free(LG_Stack_f *s)
Definition: lg_misc.c:321
push_i
zboolean push_i(LG_Stack_i *s, int v)
Definition: lg_misc.c:254
lg_show_struct_sizes
void lg_show_struct_sizes(zboolean everything)
Definition: lg_misc.c:681
LG_Stack_i
Definition: lg_misc.h:78
lg_check_gl_context
int lg_check_gl_context()
Definition: lg_misc.c:75
lg_stack_show_full_empty_errors
void lg_stack_show_full_empty_errors(zboolean show_errors)
Definition: lg_misc.c:203
has_changed_f
zboolean has_changed_f(float f)
Definition: lg_misc.c:189
LG_Stack_f
Definition: lg_misc.h:84
lg_swap_uint32_values
uint32_t lg_swap_uint32_values(uint32_t *x, uint32_t *y)
Definition: lg_misc.c:421
lg_stack_i_new
LG_Stack_i * lg_stack_i_new(int max_n)
Definition: lg_misc.c:214
lg_swap_float_values
float lg_swap_float_values(float *x, float *y)
Definition: lg_misc.c:376
debug_end_max_float_in_loop
void debug_end_max_float_in_loop()
Definition: lg_misc.c:576
lg_swap_uint16_values
uint16_t lg_swap_uint16_values(uint16_t *x, uint16_t *y)
Definition: lg_misc.c:451
lg_swap_int16_values
int16_t lg_swap_int16_values(int16_t *x, int16_t *y)
Definition: lg_misc.c:436
lg_disable_transparency
void lg_disable_transparency()
Definition: lg_misc.c:27
push_f
zboolean push_f(LG_Stack_f *s, float v)
Definition: lg_misc.c:334
delta_i
int delta_i(int i)
Definition: lg_misc.c:150
lg_swap_uint8_values
uint8_t lg_swap_uint8_values(uint8_t *x, uint8_t *y)
Definition: lg_misc.c:482
debug_end_max_int_in_loop
void debug_end_max_int_in_loop()
Definition: lg_misc.c:538
lg_swap_int8_values
int8_t lg_swap_int8_values(int8_t *x, int8_t *y)
Definition: lg_misc.c:466
lg_stack_f_new
LG_Stack_f * lg_stack_f_new(int max_n)
Definition: lg_misc.c:295
debug_start_max_int_in_loop
void debug_start_max_int_in_loop()
Definition: lg_misc.c:498
delta_f
float delta_f(float f)
Definition: lg_misc.c:164
debug_max_float_in_loop
void debug_max_float_in_loop(float f, const char *file, int line)
Definition: lg_misc.c:565
debug_start_max_float_in_loop
void debug_start_max_float_in_loop()
Definition: lg_misc.c:551
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:41
lg_enable_transparency
void lg_enable_transparency()
Definition: lg_misc.c:18
lg_check_datatype_sizes
int lg_check_datatype_sizes()
Definition: lg_misc.c:588
lg_swap_int32_values
int32_t lg_swap_int32_values(int32_t *x, int32_t *y)
Definition: lg_misc.c:406
pop_f
zboolean pop_f(LG_Stack_f *s, float *v)
Definition: lg_misc.c:355
debug_max_int_in_loop
void debug_max_int_in_loop(unsigned long i, const char *file, int line)
Definition: lg_misc.c:527
lg_show_utf8_drawings
void lg_show_utf8_drawings(zboolean extra_n)
Definition: lg_misc.c:818
pop_i
zboolean pop_i(LG_Stack_i *s, int *v)
Definition: lg_misc.c:275