foxygit / fake-08-xbox360 Log in
commit 106412ef60a1e990f3cf6c713da85a96f3e1a360
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Wed Nov 11 21:44:26 2020 -0700
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Wed Nov 11 21:44:26 2020 -0700

    Remove some double casts
---
 source/graphics.cpp   | 11 ++++++++---
 source/graphics.h     |  6 ++++--
 source/picoluaapi.cpp | 36 ++++++++++++++++++------------------
 test/Makefile         |  7 ++++---
 4 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 283006f..62890e8 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -13,6 +13,9 @@

 #include "logger.h"

+#include <fix32.h>
+using namespace z8;
+
 const uint8_t PicoScreenWidth = 128;
 const uint8_t PicoScreenHeight = 128;

@@ -688,14 +691,16 @@ void Graphics::spr(
 	int n,
 	int x,
 	int y,
-	double w = 1.0,
-	double h = 1.0,
+	fix32 w = 1.0,
+	fix32 h = 1.0,
 	bool flip_x = false,
 	bool flip_y = false)
 {
 	int spr_x = (n % 16) * 8;
 	int spr_y = (n / 16) * 8;
-	copySpriteToScreen(_memory->spriteSheetData, x, y, spr_x, spr_y, w * 8, h * 8, flip_x, flip_y);
+	int16_t spr_w = (int16_t)(w * (fix32)8);
+	int16_t spr_h = (int16_t)(h * (fix32)8);
+	copySpriteToScreen(_memory->spriteSheetData, x, y, spr_x, spr_y, spr_w, spr_h, flip_x, flip_y);
 }

 void Graphics::sspr(
diff --git a/source/graphics.h b/source/graphics.h
index c808ea8..6542663 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -3,6 +3,8 @@
 #include <string>
 #include "hostVmShared.h"
 #include "PicoRam.h"
+#include <fix32.h>
+using namespace z8;

 #define COLOR_00 {  2,   4,   8, 255}
 #define COLOR_01 { 29,  43,  83, 255}
@@ -122,8 +124,8 @@ class Graphics {
 		int n,
 		int x,
 		int y,
-		double w,
-		double h,
+		fix32 w,
+		fix32 h,
 		bool flip_x,
 		bool flip_y);

diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 06dffa9..2fd7b1c 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -70,8 +70,8 @@ int pset(lua_State *L){
 }

 int pget(lua_State *L){
-    double x = lua_tonumber(L,1);
-    double y = lua_tonumber(L,2);
+    fix32 x = lua_tonumber(L,1);
+    fix32 y = lua_tonumber(L,2);

     uint8_t color = _graphicsForLuaApi->pget((int)x, (int)y);

@@ -81,7 +81,7 @@ int pget(lua_State *L){
 }

 int color(lua_State *L){
-    double c = lua_tonumber(L,1);
+    fix32 c = lua_tonumber(L,1);

     _graphicsForLuaApi->color((uint8_t)c);

@@ -93,7 +93,7 @@ int line (lua_State *L){
         _graphicsForLuaApi->line();
     }
     else if (lua_gettop(L) == 1) {
-        uint8_t c = lua_tonumber(L,1);
+        fix32 c = lua_tonumber(L,1);

         _graphicsForLuaApi->line(c);
     }
@@ -207,7 +207,7 @@ int rectfill(lua_State *L){

         }
         else {
-            double c = lua_tonumber(L,5);
+            fix32 c = lua_tonumber(L,5);

             _graphicsForLuaApi->rectfill(x1, y1, x2, y2, c);
         }
@@ -267,8 +267,8 @@ int spr(lua_State *L) {
     int n = lua_tonumber(L,1);
     int x = lua_tonumber(L,2);
     int y = lua_tonumber(L,3);
-    double w = 1.0;
-    double h = 1.0;
+    fix32 w = 1.0;
+    fix32 h = 1.0;
     bool flip_x = false;
     bool flip_y = false;

@@ -337,14 +337,14 @@ int sspr(lua_State *L) {
 }

 int fget(lua_State *L) {
-    double n = lua_tonumber(L,1);
+    fix32 n = lua_tonumber(L,1);

     if (lua_gettop(L) == 1) {
         uint8_t result = _graphicsForLuaApi->fget((uint8_t)n);
         lua_pushinteger(L, result);
     }
     else {
-        double f = lua_tonumber(L,2);
+        fix32 f = lua_tonumber(L,2);
         bool result = _graphicsForLuaApi->fget((uint8_t)n, (uint8_t)f);
         lua_pushboolean(L, result);
     }
@@ -353,15 +353,15 @@ int fget(lua_State *L) {
 }

 int fset(lua_State *L) {
-    double n = lua_tonumber(L,1);
+    fix32 n = lua_tonumber(L,1);

     if (lua_gettop(L) > 2) {
-        double f = lua_tonumber(L,2);
-        double v = lua_toboolean(L,3);
-        _graphicsForLuaApi->fset((uint8_t)n, (uint8_t)f, (bool)v);
+        fix32 f = lua_tonumber(L,2);
+        bool v = lua_toboolean(L,3);
+        _graphicsForLuaApi->fset((uint8_t)n, (uint8_t)f, v);
     }
     else {
-        double v = lua_tonumber(L,2);
+        fix32 v = lua_tonumber(L,2);
         _graphicsForLuaApi->fset((uint8_t)n, (uint8_t)v);
     }

@@ -520,7 +520,7 @@ int flip(lua_State *L) {

 //input api
 int btn(lua_State *L){
-    double i = lua_tonumber(L,1);
+    fix32 i = lua_tonumber(L,1);

     bool pressed = _inputForLuaApi->btn((int)i);

@@ -529,7 +529,7 @@ int btn(lua_State *L){
     return 1;
 }
 int btnp(lua_State *L){
-    double i = lua_tonumber(L,1);
+    fix32 i = lua_tonumber(L,1);

     bool pressed = _inputForLuaApi->btnp((int)i);

@@ -543,7 +543,7 @@ int time(lua_State *L) {
     int frameCount = _vmForLuaApi->GetFrameCount();
     int targetFps = _vmForLuaApi->GetTargetFps();

-    double seconds = (double)frameCount / (double)targetFps;
+    fix32 seconds = (fix32)frameCount / (fix32)targetFps;

     lua_pushnumber(L, seconds);

@@ -572,7 +572,7 @@ int music(lua_State *L) {
 }

 int sfx(lua_State *L) {
-    double n = lua_tonumber(L,1);
+    fix32 n = lua_tonumber(L,1);
     int channel = -1;
     if (lua_gettop(L) > 1) {
         channel = (int)lua_tonumber(L, 2);
diff --git a/test/Makefile b/test/Makefile
index e7f3d5b..67f7c72 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -31,13 +31,14 @@ fontdatatests.o: fontdatatests.cpp ../source/fontdata.cpp ../source/fontdata.h
 nibblehelperstests.o: nibblehelperstests.cpp ../source/nibblehelpers.cpp ../source/nibblehelpers.h
 	g++ $(CFLAGS) nibblehelperstests.cpp ../source/nibblehelpers.cpp

-graphicstests.o: fontdatatests.o graphicstests.cpp ../source/graphics.cpp ../source/graphics.h \
+graphicstests.o: liblua.a fontdatatests.o graphicstests.cpp ../source/graphics.cpp ../source/graphics.h \
 	../source/fontdata.cpp ../source/fontdata.h \
 	../source/PicoRam.h ../source/hostVmShared.h \
 	../source/stringToDataHelpers.h ../source/stringToDataHelpers.cpp \
 	../source/nibblehelpers.h ../source/nibblehelpers.cpp
-	g++ $(CFLAGS) graphicstests.cpp ../source/graphics.cpp \
-		../source/stringToDataHelpers.cpp ../source/nibblehelpers.cpp
+	g++ $(CFLAGS) -I$(CURDIR)/include -L$(CURDIR)/lib \
+	graphicstests.cpp ../source/graphics.cpp \
+	../source/stringToDataHelpers.cpp ../source/nibblehelpers.cpp

 audiotests.o: audiotests.cpp ../source/Audio.cpp ../source/Audio.h \
 	../source/synth.cpp ../source/synth.h \