Unify the library on an akgl_ namespace
This commit is contained in:
48
src/util.c
48
src/util.c
@@ -10,7 +10,7 @@
|
||||
#include <sdl3game/registry.h>
|
||||
#include <sdl3game/game.h>
|
||||
|
||||
akerr_ErrorContext *rectangle_points(RectanglePoints *dest, SDL_FRect *rect)
|
||||
akerr_ErrorContext *akgl_rectangle_points(RectanglePoints *dest, SDL_FRect *rect)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL RectanglePoints reference");
|
||||
@@ -26,7 +26,7 @@ akerr_ErrorContext *rectangle_points(RectanglePoints *dest, SDL_FRect *rect)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *collide_point_rectangle(point *p, RectanglePoints *rp, bool *collide)
|
||||
akerr_ErrorContext *akgl_collide_point_rectangle(point *p, RectanglePoints *rp, bool *collide)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, p, AKERR_NULLPOINTER, "NULL Point reference");
|
||||
@@ -41,7 +41,7 @@ akerr_ErrorContext *collide_point_rectangle(point *p, RectanglePoints *rp, bool
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide)
|
||||
akerr_ErrorContext *akgl_collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide)
|
||||
{
|
||||
RectanglePoints r1p;
|
||||
RectanglePoints r2p;
|
||||
@@ -51,39 +51,39 @@ akerr_ErrorContext *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *colli
|
||||
FAIL_ZERO_RETURN(errctx, collide, AKERR_NULLPOINTER, "NULL collision flag reference");
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, rectangle_points(&r1p, r1));
|
||||
CATCH(errctx, rectangle_points(&r2p, r2));
|
||||
CATCH(errctx, akgl_rectangle_points(&r1p, r1));
|
||||
CATCH(errctx, akgl_rectangle_points(&r2p, r2));
|
||||
|
||||
// is the upper left corner of r1 contacting r2?
|
||||
CATCH(errctx, collide_point_rectangle(&r1p.topleft, &r2p, collide));
|
||||
CATCH(errctx, akgl_collide_point_rectangle(&r1p.topleft, &r2p, collide));
|
||||
if ( *collide == true ) { SUCCEED_RETURN(errctx); }
|
||||
|
||||
// is the upper left corner of r2 contacting r1?
|
||||
CATCH(errctx, collide_point_rectangle(&r2p.topleft, &r1p, collide));
|
||||
CATCH(errctx, akgl_collide_point_rectangle(&r2p.topleft, &r1p, collide));
|
||||
if ( *collide == true ) { SUCCEED_RETURN(errctx); }
|
||||
|
||||
// is the top right corner of r1 contacting r2?
|
||||
CATCH(errctx, collide_point_rectangle(&r1p.topright, &r2p, collide));
|
||||
CATCH(errctx, akgl_collide_point_rectangle(&r1p.topright, &r2p, collide));
|
||||
if ( *collide == true ) { SUCCEED_RETURN(errctx); }
|
||||
|
||||
// is the top right corner of r2 contacting r1?
|
||||
CATCH(errctx, collide_point_rectangle(&r2p.topright, &r1p, collide));
|
||||
CATCH(errctx, akgl_collide_point_rectangle(&r2p.topright, &r1p, collide));
|
||||
if ( *collide == true ) { SUCCEED_RETURN(errctx); }
|
||||
|
||||
// is the bottom left corner of r1 contacting r2?
|
||||
CATCH(errctx, collide_point_rectangle(&r1p.bottomleft, &r2p, collide));
|
||||
CATCH(errctx, akgl_collide_point_rectangle(&r1p.bottomleft, &r2p, collide));
|
||||
if ( *collide == true ) { SUCCEED_RETURN(errctx); }
|
||||
|
||||
// is the bottom left corner of r2 contacting r1?
|
||||
CATCH(errctx, collide_point_rectangle(&r2p.bottomleft, &r1p, collide));
|
||||
CATCH(errctx, akgl_collide_point_rectangle(&r2p.bottomleft, &r1p, collide));
|
||||
if ( *collide == true ) { SUCCEED_RETURN(errctx); }
|
||||
|
||||
// is the bottom right corner of r1 contacting r2?
|
||||
CATCH(errctx, collide_point_rectangle(&r1p.bottomright, &r2p, collide));
|
||||
CATCH(errctx, akgl_collide_point_rectangle(&r1p.bottomright, &r2p, collide));
|
||||
if ( *collide == true ) { SUCCEED_RETURN(errctx); }
|
||||
|
||||
// is the bottom right corner of r2 contacting r1?
|
||||
CATCH(errctx, collide_point_rectangle(&r2p.bottomright, &r1p, collide));
|
||||
CATCH(errctx, akgl_collide_point_rectangle(&r2p.bottomright, &r1p, collide));
|
||||
if ( *collide == true ) { SUCCEED_RETURN(errctx); }
|
||||
|
||||
} CLEANUP {
|
||||
@@ -95,7 +95,7 @@ akerr_ErrorContext *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *colli
|
||||
}
|
||||
|
||||
|
||||
akerr_ErrorContext *compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2)
|
||||
akerr_ErrorContext *akgl_compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, s1, AKERR_NULLPOINTER, "NULL Surface pointer");
|
||||
@@ -104,21 +104,21 @@ akerr_ErrorContext *compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y, int w, int h, char *writeout)
|
||||
akerr_ErrorContext *akgl_render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y, int w, int h, char *writeout)
|
||||
{
|
||||
SDL_Surface *s1 = NULL;
|
||||
SDL_Surface *s2 = NULL;
|
||||
SDL_FRect src = {.x = x, .y = y, .w = w, .h = h};
|
||||
SDL_FRect dest = {.x = x, .y = y, .w = w, .h = h};
|
||||
SDL_Rect read = {.x = x, .y = y, .w = w, .h = h};
|
||||
string *tmpstring = NULL;
|
||||
akgl_String *tmpstring = NULL;
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
FAIL_ZERO_BREAK(errctx, t1, AKERR_NULLPOINTER, "NULL texture");
|
||||
FAIL_ZERO_BREAK(errctx, t2, AKERR_NULLPOINTER, "NULL texture");
|
||||
|
||||
CATCH(errctx, heap_next_string(&tmpstring));
|
||||
CATCH(errctx, akgl_heap_next_string(&tmpstring));
|
||||
SDL_RenderClear(renderer);
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
@@ -127,13 +127,13 @@ akerr_ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x,
|
||||
t1,
|
||||
&src,
|
||||
&dest),
|
||||
AKERR_SDL,
|
||||
AKGL_ERR_SDL,
|
||||
"Failed to render test texture");
|
||||
s1 = SDL_RenderReadPixels(renderer, &read);
|
||||
FAIL_ZERO_BREAK(errctx, s1, AKERR_SDL, "Failed to read pixels from renderer");
|
||||
FAIL_ZERO_BREAK(errctx, s1, AKGL_ERR_SDL, "Failed to read pixels from renderer");
|
||||
|
||||
if ( writeout != NULL ) {
|
||||
snprintf((char *)&tmpstring->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), writeout);
|
||||
snprintf((char *)&tmpstring->data, AKGL_MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), writeout);
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
IMG_SavePNG(s1, (char *)&tmpstring->data),
|
||||
@@ -152,18 +152,18 @@ akerr_ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x,
|
||||
t2,
|
||||
&src,
|
||||
&dest),
|
||||
AKERR_SDL,
|
||||
AKGL_ERR_SDL,
|
||||
"Failed to render test texture");
|
||||
s2 = SDL_RenderReadPixels(renderer, &read);
|
||||
FAIL_ZERO_BREAK(errctx, s2, AKERR_SDL, "Failed to read pixels from renderer");
|
||||
FAIL_ZERO_BREAK(errctx, s2, AKGL_ERR_SDL, "Failed to read pixels from renderer");
|
||||
|
||||
CATCH(errctx, compare_sdl_surfaces(s1, s2));
|
||||
CATCH(errctx, akgl_compare_sdl_surfaces(s1, s2));
|
||||
} CLEANUP {
|
||||
if ( s1 != NULL )
|
||||
SDL_DestroySurface(s1);
|
||||
if ( s2 != NULL )
|
||||
SDL_DestroySurface(s2);
|
||||
IGNORE(heap_release_string(tmpstring));
|
||||
IGNORE(akgl_heap_release_string(tmpstring));
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
SUCCEED_RETURN(errctx);
|
||||
|
||||
Reference in New Issue
Block a user