From df2b550502aa39a8de67784b33d0efb22c090bb0 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 10 Feb 2015 20:37:30 +0100 Subject: [PATCH 1/2] (gfx/math) Updates --- libretro-sdk/gfx/math/matrix_3x3.c | 29 ++++++++++++++++++----------- libretro-sdk/gfx/math/matrix_4x4.c | 9 ++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/libretro-sdk/gfx/math/matrix_3x3.c b/libretro-sdk/gfx/math/matrix_3x3.c index 5231215631..fa2d8c8463 100644 --- a/libretro-sdk/gfx/math/matrix_3x3.c +++ b/libretro-sdk/gfx/math/matrix_3x3.c @@ -24,12 +24,13 @@ #include #include -#define floatsEqual(x, y) (fabs(x - y) <= 0.00001f * ((x) > (y) ? (y) : (x))) -#define floatIsZero(x) (floatsEqual((x) + 1, 1)) +#define floats_are_equal(x, y) (fabs(x - y) <= 0.00001f * ((x) > (y) ? (y) : (x))) +#define float_is_zero(x) (floats_are_equal((x) + 1, 1)) void matrix_3x3_identity(math_matrix_3x3 *mat) { unsigned i; + memset(mat, 0, sizeof(*mat)); for (i = 0; i < 3; i++) MAT_ELEM_3X3(*mat, i, i) = 1.0f; @@ -55,6 +56,7 @@ void matrix_3x3_transpose(math_matrix_3x3 *out, const math_matrix_3x3 *in) { unsigned i, j; math_matrix_3x3 mat; + for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) MAT_ELEM_3X3(mat, j, i) = MAT_ELEM_3X3(*in, i, j); @@ -67,6 +69,7 @@ void matrix_3x3_multiply(math_matrix_3x3 *out, { unsigned r, c, k; math_matrix_3x3 mat; + for (r = 0; r < 3; r++) { for (c = 0; c < 3; c++) @@ -119,11 +122,12 @@ bool matrix_3x3_invert(math_matrix_3x3 *mat) { float det = matrix_3x3_determinant(mat); - if (floatIsZero(det)) + if (float_is_zero(det)) return false; matrix_3x3_adjoint(mat); matrix_3x3_divide_scalar(mat, det); + return true; } @@ -162,13 +166,16 @@ bool matrix_3x3_square_to_quad(const float dx0, const float dy0, float ax = dx0 - dx1 + dx2 - dx3; float ay = dy0 - dy1 + dy2 - dy3; - if (floatIsZero(ax) && floatIsZero(ay)) { + if (float_is_zero(ax) && float_is_zero(ay)) + { /* affine case */ matrix_3x3_inits(mat, - dx1 - dx0, dy1 - dy0, 0, - dx2 - dx1, dy2 - dy1, 0, - dx0, dy0, 1); - } else { + dx1 - dx0, dy1 - dy0, 0, + dx2 - dx1, dy2 - dy1, 0, + dx0, dy0, 1); + } + else + { float a, b, c, d, e, f, g, h; float ax1 = dx1 - dx2; float ax2 = dx3 - dx2; @@ -194,9 +201,9 @@ bool matrix_3x3_square_to_quad(const float dx0, const float dy0, f = dy0; matrix_3x3_inits(mat, - a, d, g, - b, e, h, - c, f, 1.f); + a, d, g, + b, e, h, + c, f, 1.f); } return true; diff --git a/libretro-sdk/gfx/math/matrix_4x4.c b/libretro-sdk/gfx/math/matrix_4x4.c index de31e773cb..9c27ba6419 100644 --- a/libretro-sdk/gfx/math/matrix_4x4.c +++ b/libretro-sdk/gfx/math/matrix_4x4.c @@ -27,6 +27,7 @@ void matrix_4x4_identity(math_matrix_4x4 *mat) { unsigned i; + memset(mat, 0, sizeof(*mat)); for (i = 0; i < 4; i++) MAT_ELEM_4X4(*mat, i, i) = 1.0f; @@ -88,11 +89,13 @@ void matrix_4x4_ortho(math_matrix_4x4 *mat, float bottom, float top, float znear, float zfar) { + float tx, ty, tz; + matrix_4x4_identity(mat); - float tx = -(right + left) / (right - left); - float ty = -(top + bottom) / (top - bottom); - float tz = -(zfar + znear) / (zfar - znear); + tx = -(right + left) / (right - left); + ty = -(top + bottom) / (top - bottom); + tz = -(zfar + znear) / (zfar - znear); MAT_ELEM_4X4(*mat, 0, 0) = 2.0f / (right - left); MAT_ELEM_4X4(*mat, 1, 1) = 2.0f / (top - bottom); From 3b365bb0d7cfa3814383fa528a91a6a1efde9a9d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 10 Feb 2015 20:43:38 +0100 Subject: [PATCH 2/2] Put conditional around pretro_run --- runloop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runloop.c b/runloop.c index 1f95befffa..02ca0badd2 100644 --- a/runloop.c +++ b/runloop.c @@ -1093,7 +1093,8 @@ int rarch_main_iterate(void) /* Run libretro for one frame. */ - pretro_run(); + if (pretro_run) + pretro_run(); for (i = 0; i < g_settings.input.max_users; i++) {