Minor XCB changes to test Valgrind... Works good.

This commit is contained in:
Ognjen Milan Robovic 2024-03-13 20:42:58 -04:00
parent 866dda684f
commit 2bbe9e58c0
2 changed files with 68 additions and 30 deletions

View File

@ -4,19 +4,19 @@ default:
gfortran -fPIC -Wall -Wextra -Ofast -fno-underscoring -fstack-check -c -o ai.o ai.f90
gcc -g -ansi -Wall -Wextra -Wpedantic -Ofast -fstack-check -c -fPIC -o system.o system.c
#
gnatmake -O3 -fstack-check -c main.adb
gnatmake -g -O3 -fstack-check -c main.adb
gnatbind main.ali
gcc -g -ansi -Wall -Wextra -Wpedantic -Ofast -fstack-check -c -fPIC -o raylib.o raylib.c
gnatlink main.ali system.o raylib.o ai.o -o xhads -lraylib -lc -lgfortran
mv xhads ../xhads
#
#~ gnatmake -O3 -fstack-check -c main.adb
#~ gnatmake -g -O3 -fstack-check -c main.adb
#~ gnatbind main.ali
#~ gcc -g -ansi -Wall -Wextra -Wpedantic -Ofast -fstack-check -c -fPIC -o sdl2.o sdl2.c
#~ gnatlink main.ali system.o sdl2.o ai.o -o mam_sdl2 -lc -lgfortran -lSDL2 -lSDL2_image
#~ mv mam_sdl2 ../mam_sdl2
#
#~ gnatmake -O3 -fstack-check -c main.adb
#~ gnatmake -g -O3 -fstack-check -c main.adb
#~ gnatbind main.ali
#~ gcc -g -ansi -Wall -Wextra -Wpedantic -Ofast -fstack-check -c -fPIC -o xcb.o xcb.c
#~ gnatlink main.ali system.o xcb.o ai.o -o mam_xcb -lc -lgfortran -lpng -lxcb -lxcb-image

View File

@ -12,10 +12,10 @@
#define FONT_WIDTH ( 9)
#define FONT_HEIGHT (18)
static unsigned int * * render_texture = NULL;
static int * render_texture_w = NULL;
static int * render_texture_h = NULL;
static int render_texture_count = 0;
static unsigned int * * texture_array = NULL;
static int * texture_array_w = NULL;
static int * texture_array_h = NULL;
static int texture_count = 0;
static unsigned int * font = NULL;
static unsigned int * mono = NULL;
@ -54,50 +54,72 @@ static void render_clean_up (void) {
printf ("Deinitializing graphical components...\n");
for (i = 0; i < render_texture_count; ++i)
free (render_texture [i]);
for (i = 0; i < texture_count; ++i) {
free (texture_array [i]);
texture_array [i] = NULL;
}
free (render_texture);
free (texture_array);
free (framebuffer);
free (font);
free (mono);
texture_array = NULL;
font = NULL;
mono = NULL;
xcb_free_gc (connection, context);
xcb_free_pixmap (connection, pixmap);
framebuffer = NULL;
xcb_destroy_window (connection, window);
xcb_disconnect (connection);
}
extern int signal_x;
extern int signal_y;
extern int cursor_x;
extern int cursor_y;
extern int cursor_mode;
extern int signal_mode;
extern int engine_active;
extern int framerate;
extern int window_width (void);
extern int window_height (void);
extern void render_sprite (int sprite, int x, int y, int u, int v, int width, int height);
extern void render_string (char * string, int x, int y, int colour, char monospace);
extern void render_vector (int x1, int y1, int x2, int y2);
extern void engine_configure (void);
extern void engine_synchronize (void);
extern int sprite_import (char * path);
extern int import_texture (char * path);
extern int import_sound (char * path);
extern int sprite_width (int index);
extern int sprite_height (int index);
int signal_x = 0;
int signal_y = 0;
extern void play_sound (int index);
extern void stop_sound (int index);
extern void loop_sound (int index);
int cursor_x = 0;
int cursor_y = 0;
int cursor_mode = 0;
int signal_mode = 0;
int engine_active = 0;
int framerate = 0;
int window_width (void) { return (screen_width); }
int window_height (void) { return (screen_height); }
@ -116,8 +138,8 @@ void render_sprite (int sprite, int x, int y, int u, int v, int width, int heigh
for (sprite_x = 0; sprite_x < width; ++sprite_x) {
int o = (sprite_y + y) * window_width () + (sprite_x + x);
int s = (sprite_y + v) * sprite_width (sprite) + (sprite_x + u);
framebuffer [o] = ((render_texture [sprite] [s] & 0XFF000000) < 0X04) ?
framebuffer [o] : render_texture [sprite] [s];
framebuffer [o] = ((texture_array [sprite] [s] & 0XFF000000) < 0X04) ?
framebuffer [o] : texture_array [sprite] [s];
}
}
}
@ -142,6 +164,13 @@ void render_string (char * string, int x, int y, int colour, char monospace) {
(void) monospace;
}
void render_vector (int x1, int y1, int x2, int y2) {
(void) x1;
(void) y1;
(void) x2;
(void) y2;
}
void engine_configure (void) {
unsigned int values [2] = {
0,
@ -224,8 +253,8 @@ void engine_synchronize (void) {
cursor_mode = button_press_event->detail;
} else if ((event->response_type & 127) == XCB_MOTION_NOTIFY) {
xcb_motion_notify_event_t * button_press_event = (xcb_motion_notify_event_t *) event;
signal_x = button_press_event->event_x;
signal_y = button_press_event->event_y;
cursor_x = button_press_event->event_x;
cursor_y = button_press_event->event_y;
}
free (event);
@ -235,26 +264,35 @@ void engine_synchronize (void) {
signal_mode = 0;
}
int import_sprite (char * path) {
++render_texture_count;
int import_texture (char * path) {
++texture_count;
render_texture = realloc (render_texture, (unsigned long int) render_texture_count * sizeof (* render_texture));
render_texture_w = realloc (render_texture_w, (unsigned long int) render_texture_count * sizeof (* render_texture_w));
render_texture_h = realloc (render_texture_h, (unsigned long int) render_texture_count * sizeof (* render_texture_h));
texture_array = realloc (texture_array, (unsigned long int) texture_count * sizeof (* texture_array));
texture_array_w = realloc (texture_array_w, (unsigned long int) texture_count * sizeof (* texture_array_w));
texture_array_h = realloc (texture_array_h, (unsigned long int) texture_count * sizeof (* texture_array_h));
render_texture [render_texture_count - 1] = import_png (path, & render_texture_w [render_texture_count - 1], & render_texture_h [render_texture_count - 1]);
texture_array [texture_count - 1] = import_png (path, & texture_array_w [texture_count - 1], & texture_array_h [texture_count - 1]);
if (render_texture [render_texture_count - 1] == NULL) {
printf ("\033[1;31m%3i : '%60s';\033[0m\n", render_texture_count - 1, path);
if (texture_array [texture_count - 1] == NULL) {
printf ("\033[1;31m%3i : '%60s';\033[0m\n", texture_count - 1, path);
}
return (render_texture_count - 1);
return (texture_count - 1);
}
int import_sound (char * path) {
(void) path;
return (0);
}
int sprite_width (int index) {
return (render_texture_w [index]);
return (texture_array_w [index]);
}
int sprite_height (int index) {
return (render_texture_h [index]);
return (texture_array_h [index]);
}
void play_sound (int index) { (void) index; }
void stop_sound (int index) { (void) index; }
void loop_sound (int index) { (void) index; }