diff --git a/include/modules/graphics/wrap_Graphics.hpp b/include/modules/graphics/wrap_Graphics.hpp index c1a4b921..ad059cb6 100644 --- a/include/modules/graphics/wrap_Graphics.hpp +++ b/include/modules/graphics/wrap_Graphics.hpp @@ -183,6 +183,8 @@ namespace Wrap_Graphics int points(lua_State* L); + int line(lua_State* L); + int draw(lua_State* L); int newMesh(lua_State* L); diff --git a/platform/ctr/source/modules/graphics/Graphics.cpp b/platform/ctr/source/modules/graphics/Graphics.cpp index b45d8a0c..c912fabc 100644 --- a/platform/ctr/source/modules/graphics/Graphics.cpp +++ b/platform/ctr/source/modules/graphics/Graphics.cpp @@ -364,7 +364,14 @@ namespace love for (int index = 0; index < count; index++) { const auto& position = positions[index]; - auto& color = colors[index]; + + if (!colors) + { + this->circle(DRAW_FILL, position.x, position.y, pointSize); + return; + } + + auto& color = colors[index]; gammaCorrectColor(this->getColor()); diff --git a/source/modules/graphics/wrap_Graphics.cpp b/source/modules/graphics/wrap_Graphics.cpp index 6fdbb084..501341e7 100644 --- a/source/modules/graphics/wrap_Graphics.cpp +++ b/source/modules/graphics/wrap_Graphics.cpp @@ -1556,6 +1556,56 @@ int Wrap_Graphics::points(lua_State* L) return 0; } +int Wrap_Graphics::line(lua_State* L) +{ + int argc = lua_gettop(L); + int arg1Type = lua_type(L, 1); + bool isTable = false; + + if (argc == 1 && arg1Type == LUA_TTABLE) + { + argc = (int)luax_objlen(L, 1); + isTable = true; + } + + if (arg1Type != LUA_TTABLE && arg1Type != LUA_TNUMBER) + return luax_typeerror(L, 1, "table or number"); + else if (argc % 2 != 0) + return luaL_error(L, "Number of vertex components must be a multiple of two."); + else if (argc < 4) + return luaL_error(L, "Need at least two vertices to draw a line."); + + int numVertices = argc / 2; + + auto* coords = instance()->getScratchBuffer(numVertices); + + if (isTable) + { + for (int index = 0; index < numVertices; ++index) + { + lua_rawgeti(L, 1, (index * 2) + 1); + lua_rawgeti(L, 1, (index * 2) + 2); + + coords[index].x = luax_checkfloat(L, -2); + coords[index].y = luax_checkfloat(L, -1); + + lua_pop(L, 2); + } + } + else + { + for (int index = 0; index < numVertices; ++index) + { + coords[index].x = luax_checkfloat(L, (index * 2) + 1); + coords[index].y = luax_checkfloat(L, (index * 2) + 2); + } + } + + luax_catchexcept(L, [&]() { instance()->polyline(std::span(coords, numVertices)); }); + + return 0; +} + int Wrap_Graphics::getWidth(lua_State* L) { lua_pushinteger(L, instance()->getWidth()); @@ -1742,6 +1792,7 @@ static constexpr luaL_Reg functions[] = { "ellipse", Wrap_Graphics::ellipse }, { "arc", Wrap_Graphics::arc }, { "points", Wrap_Graphics::points }, + { "line", Wrap_Graphics::line }, { "newTexture", Wrap_Graphics::newTexture }, { "newImage", Wrap_Graphics::newImage },