From 5eeb78d9eca0e4b76ff2a53dbe931448f1b73947 Mon Sep 17 00:00:00 2001 From: Firew0lf Date: Sun, 4 Oct 2015 15:25:34 +0200 Subject: [PATCH] Added Rumble and Timer libs, implemented the offset system for drawing. --- Rumble.lua | 17 +++++++++++++++++ Timer.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ screen.lua | 34 ++++++++++++++++++---------------- 3 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 Rumble.lua create mode 100644 Timer.lua diff --git a/Rumble.lua b/Rumble.lua new file mode 100644 index 0000000..da0714b --- /dev/null +++ b/Rumble.lua @@ -0,0 +1,17 @@ +--[[ + Rumble pack related µLua compatibility layer/lib for ctrµLua + + As the 3DS doesn't have a rumble function, I couldn't implement this. +]] + +-- Module + +Rumble = {} + +function Rumble.isInserted() + return false +end + +function Rumble.set(s) + +end diff --git a/Timer.lua b/Timer.lua new file mode 100644 index 0000000..5ae94b7 --- /dev/null +++ b/Timer.lua @@ -0,0 +1,53 @@ +--[[ + Timers related µLua compatibility layer/lib for ctrµLua + + The code comes directly from µLua, befores timers were coded in C, but with +the name patch. +]] + +-- Local + +local ctr = require("ctr") + +-- Module + +Timer = { + new = function() + local t = ctr.time() + local isStarted = false + local tick = 0 + + local time = function(self) + if isStarted then return ctr.time() - t + else return tick end + end + + local stop = function(self) + if isStarted then + isStarted = false + tick = ctr.time() - t + end + end + + local start = function(self) + if not isStarted then + isStarted = true + t = ctr.time() - tick + end + end + + local reset = function(self) + t = ctr.time() + isStarted = false + tick = 0 + end + + return{ + time = time, + getTime = time, -- name patch + stop = stop, + start = start, + reset = reset + } + end +} diff --git a/screen.lua b/screen.lua index 3618fd0..829d440 100644 --- a/screen.lua +++ b/screen.lua @@ -39,6 +39,7 @@ local videoStack = {} local alpha = ALPHA_RESET local drawScreen = SCREEN_UP +local offsetX, offsetY = 0,0 local fpscount = 0 local fpstime = ctr.time() @@ -53,12 +54,6 @@ function startDrawing() end function stopDrawing() - -- As you can change the screen size, we have to re-calculate this every time. - local offsetX = (gfx.BOTTOM_WIDTH-SCREEN_WIDTH)/2 - local offsetY = (gfx.BOTTOM_HEIGHT-SCREEN_HEIGHT)/2 - if drawScreen == gfx.SCREEN_UP then - offsetX = offsetX + 40 - end -- FPS counter fpscount = fpscount + 1 @@ -98,35 +93,35 @@ function screen.setAlpha(level, layer) end function screen.print(scr, x, y, text, color) - videoStack[scr][#videoStack[scr]] = {"text", {x, y, text, 8, RGB2RGBA(color), nil}} + videoStack[scr][#videoStack[scr]] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), nil}} end function screen.printFont(scr, x, y, text, color, font) - videoStack[scr][#videoStack[scr]] = {"text", {x, y, text, 8, RGB2RGBA(color), font}} + videoStack[scr][#videoStack[scr]] = {"text", {offsetX+x, offsetY+y, text, 8, RGB2RGBA(color), font}} end function screen.blit(scr, x, y, img, sx, sy, w, h) local sizex, sizey = img:getSize() - videoStack[scr][#videoStack[scr]] = {"img", {x, y, (sx or 0), (sy or 0), (w or sizex), (h or sizey)}} + videoStack[scr][#videoStack[scr]] = {"img", {offsetX+x, offsetY+y, (sx or 0), (sy or 0), (w or sizex), (h or sizey)}} end function screen.drawPoint(scr, x, y, color) - videoStack[scr][#videoStack[scr]] = {"point", {x, y, RGB2RGBA(color)}} + videoStack[scr][#videoStack[scr]] = {"point", {offsetX+x, offsetY+y, RGB2RGBA(color)}} end function screen.drawLine(scr, x0, y0, x1, y1, color) - videoStack[scr][#videoStack[scr]] = {"line", {x0, y0, x1, y1, RGB2RGBA(color)}} + videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetX+y0, offsetX+x1, offsetY+y1, RGB2RGBA(color)}} end function screen.drawRect(scr, x0, y0, x1, y1, color) - videoStack[scr][#videoStack[scr]] = {"line", {x0, y0, x0, y1, RGB2RGBA(color)}} - videoStack[scr][#videoStack[scr]] = {"line", {x0, y0, x1, y0, RGB2RGBA(color)}} - videoStack[scr][#videoStack[scr]] = {"line", {x0, y1, x1, y1, RGB2RGBA(color)}} - videoStack[scr][#videoStack[scr]] = {"line", {x1, y0, x1, y1, RGB2RGBA(color)}} + videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetY+y0, offsetX+x0, offsetY+y1, RGB2RGBA(color)}} + videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetY+y0, offsetX+x1, offsetY+y0, RGB2RGBA(color)}} + videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x0, offsetY+y1, offsetX+x1, offsetY+y1, RGB2RGBA(color)}} + videoStack[scr][#videoStack[scr]] = {"line", {offsetX+x1, offsetY+y0, offsetX+x1, offsetY+y1, RGB2RGBA(color)}} end function screen.drawFillRect(scr, x0, y0, x1, y1, color) - videoStack[scr][#videoStack[scr]] = {"rectangle", {x0, y0, (x1-x0), (y1-y0), 0, RGB2RGBA(color)}} + videoStack[scr][#videoStack[scr]] = {"rectangle", {offsetX+x0, offsetY+y0, offsetX+(x1-x0), offsetY+(y1-y0), 0, RGB2RGBA(color)}} end function screen.drawGradientRect(scr, x0, y0, x1, y1, color, color, color, color) @@ -162,6 +157,13 @@ function screen.startDrawing2D() -- unused videoStack = {} videoStack[0] = {} videoStack[1] = {} + + -- As you can change the screen size, we have to re-calculate this every time. + offsetX = (gfx.BOTTOM_WIDTH-SCREEN_WIDTH)/2 + offsetY = (gfx.BOTTOM_HEIGHT-SCREEN_HEIGHT)/2 + if drawScreen == gfx.SCREEN_UP then + offsetX = offsetX + 40 + end end function screen.endDrawing()