LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_misc.c File Reference

Functions

void lg_enable_transparency ()
 
void lg_disable_transparency ()
 
int lg_check_gl_errors (long long log_time, const char *file, int line, const char *func)
 
int lg_check_gl_context ()
 
lg_endianness lg_get_arch_endianness ()
 
float lg_tv_diff (struct timeval *t_diff, struct timeval *t2, struct timeval *t1)
 
int delta_i (int i)
 
float delta_f (float f)
 
zboolean has_changed_i (int i)
 
zboolean has_changed_f (float f)
 
void lg_stack_show_full_empty_errors (zboolean show_errors)
 
LG_Stack_ilg_stack_i_new (int max_n)
 
void lg_stack_i_free (LG_Stack_i *s)
 
zboolean push_i (LG_Stack_i *s, int v)
 
zboolean pop_i (LG_Stack_i *s, int *v)
 
LG_Stack_flg_stack_f_new (int max_n)
 
void lg_stack_f_free (LG_Stack_f *s)
 
zboolean push_f (LG_Stack_f *s, float v)
 
zboolean pop_f (LG_Stack_f *s, float *v)
 
float lg_swap_float_values (float *x, float *y)
 
double lg_swap_double_values (double *x, double *y)
 
int32_t lg_swap_int32_values (int32_t *x, int32_t *y)
 
uint32_t lg_swap_uint32_values (uint32_t *x, uint32_t *y)
 
int16_t lg_swap_int16_values (int16_t *x, int16_t *y)
 
uint16_t lg_swap_uint16_values (uint16_t *x, uint16_t *y)
 
int8_t lg_swap_int8_values (int8_t *x, int8_t *y)
 
uint8_t lg_swap_uint8_values (uint8_t *x, uint8_t *y)
 
void debug_start_max_int_in_loop ()
 
void debug_max_int_in_loop (unsigned long i, const char *file, int line)
 
void debug_end_max_int_in_loop ()
 
void debug_start_max_float_in_loop ()
 
void debug_max_float_in_loop (float f, const char *file, int line)
 
void debug_end_max_float_in_loop ()
 
int lg_check_datatype_sizes ()
 
void lg_show_struct_sizes (zboolean everything)
 
int lg_show_pixel_format_info_from_sdl_display_mode (SDL_DisplayMode *display_mode)
 
void lg_show_utf8_drawings (zboolean extra_n)
 

Detailed Description

 It's just that, a loose collection of funcs that don't belong to a specific module
 (at least so far ...)

Function Documentation

◆ lg_enable_transparency()

void lg_enable_transparency ( )

Enabling transparency before calling glDraw* funcs

◆ lg_disable_transparency()

void lg_disable_transparency ( )

Disabling transparency (default)

◆ lg_check_gl_errors()

int lg_check_gl_errors ( long long  log_time,
const char *  file,
int  line,
const char *  func 
)

Check GL errors

Parameters
log_timelg_log_time()
file__ FILE __ (without spaces)
line__ LINE __ (without spaces)
func__ func __ (without spaces)
Returns
LG_OK if OK

◆ lg_check_gl_context()

int lg_check_gl_context ( )

Check OpenGL context, ie if the current context is not NULL and whether it has changed since app startup

Returns
LG_OK if OK, LG_ERROR otherwise

◆ lg_get_arch_endianness()

lg_endianness lg_get_arch_endianness ( )

Get architecture endianness

From: https://developer.ibm.com/articles/au-endianc/

Returns
LG_LITTLE_ENDIAN or LG_BIG_ENDIAN

◆ lg_tv_diff()

float lg_tv_diff ( struct timeval *  t_diff,
struct timeval *  t2,
struct timeval *  t1 
)

Compute t2 - t1 (in s and µs) and store the result in t_diff.

Parameters
t_diffA pointer to a struct timeval
t2A pointer to a struct timeval
t1A pointer to a struct timeval
Returns
t_diff in (float) ms

◆ delta_i()

int delta_i ( int  i)

Return delta of an int value since last call

Parameters
iAn int value
Returns
The difference as an int

◆ delta_f()

float delta_f ( float  f)

Return delta of a float value since last call

Parameters
fA float value
Returns
The difference as a float

◆ has_changed_i()

zboolean has_changed_i ( int  i)

Check if an int value has changed since last call

Parameters
iAn int value
Returns
TRUE if value has changed, FALSE otherwise

◆ has_changed_f()

zboolean has_changed_f ( float  f)

Check if a float value has changed since last call, using LG_FLOAT_EPSILON for comparison

Parameters
fA float value
Returns
TRUE if value has changed, FALSE otherwise

◆ lg_stack_show_full_empty_errors()

void lg_stack_show_full_empty_errors ( zboolean  show_errors)

Show / don't show (= default) "Stack is full" / "Stack is empty" errors, which can be numerous

Parameters
show_errors

◆ lg_stack_i_new()

LG_Stack_i* lg_stack_i_new ( int  max_n)

Create and init a new LG_Stack_i instance

Parameters
max_nMax num of elements of the stack
Returns
A new LG_Stack_i instance if OK, NULL on error

◆ lg_stack_i_free()

void lg_stack_i_free ( LG_Stack_i s)

Free a LG_Stack_i instance and all associated resources

Parameters
sA LG_Stack_i instance

◆ push_i()

zboolean push_i ( LG_Stack_i s,
int  v 
)

Push int value into LG_Stack_i

Parameters
sAddr of LG_Stack_i
vint value
Returns
TRUE if OK, FALSE otherwise

◆ pop_i()

zboolean pop_i ( LG_Stack_i s,
int *  v 
)

Pop int value from LG_Stack_i

Parameters
sAddr of LG_Stack_i
vAddr of int
Returns
TRUE if OK, FALSE otherwise

◆ lg_stack_f_new()

LG_Stack_f* lg_stack_f_new ( int  max_n)

Create and init a new LG_Stack_f instance

Parameters
max_nMax num of elements of the stack
Returns
A new LG_Stack_f instance if OK, NULL on error

◆ lg_stack_f_free()

void lg_stack_f_free ( LG_Stack_f s)

Free a LG_Stack_f instance and all associated resources

Parameters
sA LG_Stack_f instance

◆ push_f()

zboolean push_f ( LG_Stack_f s,
float  v 
)

Push float value into LG_Stack_f

Parameters
sAddr of LG_Stack_f
vfloat value
Returns
TRUE if OK, FALSE otherwise

◆ pop_f()

zboolean pop_f ( LG_Stack_f s,
float *  v 
)

Pop float value from LG_Stack_f

Parameters
sAddr of LG_Stack_f
vAddr of float
Returns
TRUE if OK, FALSE otherwise

◆ lg_swap_float_values()

float lg_swap_float_values ( float *  x,
float *  y 
)

Portable value swapping

Parameters
xPointer to float
yPointer to float
Returns
Orig x value

◆ lg_swap_double_values()

double lg_swap_double_values ( double *  x,
double *  y 
)

Portable value swapping

Parameters
xPointer to double
yPointer to double
Returns
Orig x value

◆ lg_swap_int32_values()

int32_t lg_swap_int32_values ( int32_t *  x,
int32_t *  y 
)

Portable value swapping

Parameters
xPointer to int32_t
yPointer to int32_t
Returns
Orig x value

◆ lg_swap_uint32_values()

uint32_t lg_swap_uint32_values ( uint32_t *  x,
uint32_t *  y 
)

Portable value swapping

Parameters
xPointer to uint32_t
yPointer to uint32_t
Returns
Orig x value

◆ lg_swap_int16_values()

int16_t lg_swap_int16_values ( int16_t *  x,
int16_t *  y 
)

Portable value swapping

Parameters
xPointer to int16_t
yPointer to int16_t
Returns
Orig x value

◆ lg_swap_uint16_values()

uint16_t lg_swap_uint16_values ( uint16_t *  x,
uint16_t *  y 
)

Portable value swapping

Parameters
xPointer to uint16_t
yPointer to uint16_t
Returns
Orig x value

◆ lg_swap_int8_values()

int8_t lg_swap_int8_values ( int8_t *  x,
int8_t *  y 
)

Portable value swapping

Parameters
xPointer to int8_t
yPointer to int8_t
Returns
Orig x value

◆ lg_swap_uint8_values()

uint8_t lg_swap_uint8_values ( uint8_t *  x,
uint8_t *  y 
)

Portable value swapping

Parameters
xPointer to uint8_t
yPointer to uint8_t
Returns
Orig x value

◆ debug_start_max_int_in_loop()

void debug_start_max_int_in_loop ( )

For debugging purposes - 'Reset' max_int_in_loop

◆ debug_max_int_in_loop()

void debug_max_int_in_loop ( unsigned long  i,
const char *  file,
int  line 
)

For debugging purposes - Print out max value found so far while running loop

Example use:

 i = 0;
 debug_start_max_int_in_loop();
 for (y = 0; y < h; y++) {
    for (x = 0; x < w; x++) {
            debug_max_int_in_loop((unsigned long)i, __FILE__, __LINE__);
            // ...
            terrain->vbo_data[i].x = (float)x / (float)w;
            terrain->vbo_data[i].y = heightmap[x + y * w] * vert_scaling_k;
            terrain->vbo_data[i].z = (float)y / (float)h;
            // ...
            i++;
    }
 }
 debug_end_max_int_in_loop();
Parameters
iInteger to test
fileShould be "__FILE__"
lineShould be "__LINE__"

◆ debug_end_max_int_in_loop()

void debug_end_max_int_in_loop ( )

For debugging purposes - Just print out closing '\n'

◆ debug_start_max_float_in_loop()

void debug_start_max_float_in_loop ( )

For debugging purposes - 'Reset' max_float_in_loop

◆ debug_max_float_in_loop()

void debug_max_float_in_loop ( float  f,
const char *  file,
int  line 
)

For debugging purposes - Print out max value found so far while running loop

Example use: same as above with float instead of int

Parameters
ffloat to test
fileShould be "__FILE__"
lineShould be "__LINE__"

◆ debug_end_max_float_in_loop()

void debug_end_max_float_in_loop ( )

For debugging purposes - Just print out closing '\n'

◆ lg_check_datatype_sizes()

int lg_check_datatype_sizes ( )

Check C and OpenGL types at runtime - should be at init

Also see: https://www.khronos.org/opengl/wiki/OpenGL_Type

Returns
LG_OK if OK

◆ lg_show_struct_sizes()

void lg_show_struct_sizes ( zboolean  everything)

Mainly for internal testing, but quite informative about memory consumption

Make sure to add new structs

Parameters
everythingEvery structs if TRUE , only big or new/interesting ones otherwise

◆ lg_show_pixel_format_info_from_sdl_display_mode()

int lg_show_pixel_format_info_from_sdl_display_mode ( SDL_DisplayMode *  display_mode)

Show pixel format info bla bla

See: https://wiki.libsdl.org/SDL_PixelFormat

Parameters
display_modePointer to a SDL_DisplayMode struct
Returns
LG_OK if OK

◆ lg_show_utf8_drawings()

void lg_show_utf8_drawings ( zboolean  extra_n)

Is that any useful actually ?

//Pretty handy when trying to draw UTF-8 boxes

Parameters
extra_nAdd an extra "\n" at end of lines (will look less "compact")