foxygit / fake-08-xbox360 Log in
commit ebbcd6900506c4495625758618a2f3032fdbb192
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Thu Apr 23 08:56:30 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Thu Apr 23 08:56:30 2020 -0600

    Add line overloads and persist line state
---
 source/graphics.cpp   | 33 +++++++++++++++++++++++++++++++++
 source/graphics.h     | 11 +++++++++++
 source/picoluaapi.cpp | 45 +++++++++++++++++++++++++++++++++++++++------
 3 files changed, 83 insertions(+), 6 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 55c0203..99631c9 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -221,7 +221,40 @@ void Graphics::color(uint8_t col){
 	this->_gfxState_color = col;
 }

+void Graphics::line () {
+	//just invalidate line state
+	this->_gfxState_line_x = 0;
+	this->_gfxState_line_y = 0;
+	this->_gfxState_line_valid = false;
+}
+
+void Graphics::line (uint8_t col){
+	color(col);
+
+	this->line();
+}
+
+void Graphics::line (short x1, short y1){
+	if (this->_gfxState_line_valid){
+		this->line(_gfxState_line_x, _gfxState_line_y, x1, y1, this->_gfxState_color);
+	}
+}
+
+void Graphics::line (short x1, short y1, uint8_t col){
+	if (this->_gfxState_line_valid){
+		this->line(_gfxState_line_x, _gfxState_line_y, x1, y1, col);
+	}
+}
+
+void Graphics::line (short x1, short y1, short x2, short y2){
+	this->line(_gfxState_line_x, _gfxState_line_y, x1, y1, this->_gfxState_color);
+}
+
 void Graphics::line (short x1, short y1, short x2, short y2, uint8_t col) {
+	this->_gfxState_line_x = x2;
+	this->_gfxState_line_y = y2;
+	this->_gfxState_line_valid = true;
+
 	sortPointsLtoR(&x1, &y1, &x2, &y2);

 	float run = x2 - x1;
diff --git a/source/graphics.h b/source/graphics.h
index ff84d43..6ffaae8 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -43,6 +43,12 @@ class Graphics {
     short _gfxState_text_x;
 	short _gfxState_text_y;

+	//not actually part of graphics state memory?
+	short _gfxState_line_x;
+	short _gfxState_line_y;
+	bool _gfxState_line_valid;
+
+
 	void copySpriteToScreen(
 		uint8_t spritebuffer[],
 		short scr_x,
@@ -90,6 +96,11 @@ class Graphics {

 	void color(uint8_t c);

+	void line ();
+	void line (uint8_t col);
+	void line (short x1, short y1);
+	void line (short x1, short y1, uint8_t col);
+	void line (short x1, short y1, short x2, short y2);
 	void line (short x1, short y1, short x2, short y2, uint8_t col);

 	void circ(short ox, short oy, short r, uint8_t col);
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index c171431..8089d8d 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -59,6 +59,7 @@ int pget(lua_State *L){

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

@@ -66,15 +67,47 @@ int color(lua_State *L){

     return 0;
 }
+
 int line (lua_State *L){
-    double x1 = lua_tonumber(L,1);
-    double y1 = lua_tonumber(L,2);
-    double x2 = lua_tonumber(L,3);
-    double y2 = lua_tonumber(L,4);
-    double c = lua_tonumber(L,5);
+    if (lua_gettop(L) == 0) {
+        _graphicsForLuaApi->line();
+    }
+    else if (lua_gettop(L) == 1) {
+        uint8_t c = lua_tointeger(L,1);

-    _graphicsForLuaApi->line((short)x1, (short)y1, (short)x2, (short)y2, (uint8_t)c);
+        _graphicsForLuaApi->line(c);
+    }
+    else if (lua_gettop(L) == 2) {
+        short x1 = lua_tointeger(L,1);
+        short y1 = lua_tointeger(L,2);
+
+        _graphicsForLuaApi->line(x1, y1);
+    }
+    else if (lua_gettop(L) == 3) {
+        short x1 = lua_tointeger(L,1);
+        short y1 = lua_tointeger(L,2);
+        uint8_t c = lua_tointeger(L,3);
+
+        _graphicsForLuaApi->line(x1, y1, c);
+    }
+    else if (lua_gettop(L) == 4) {
+        short x1 = lua_tointeger(L,1);
+        short y1 = lua_tointeger(L,2);
+        short x2 = lua_tointeger(L,3);
+        short y2 = lua_tointeger(L,4);

+        _graphicsForLuaApi->line(x1, y1, x2, y2);
+    }
+    else {
+        short x1 = lua_tointeger(L,1);
+        short y1 = lua_tointeger(L,2);
+        short x2 = lua_tointeger(L,3);
+        short y2 = lua_tointeger(L,4);
+        uint8_t c = lua_tointeger(L,5);
+
+        _graphicsForLuaApi->line(x1, y1, x2, y2, c);
+    }
+
     return 0;
 }
 int circ(lua_State *L){