diff --git a/README.md b/README.md index 31932cc..c5e6379 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Untested. Actually done: * Color * Controls + * Debug * dsUser * Font * Image @@ -14,6 +15,7 @@ Actually done: * Motion * Rumble * screen + * ScrollMap * Sprite * System * Timer diff --git a/uCompat/Debug.lua b/uCompat/Debug.lua new file mode 100644 index 0000000..800aa5c --- /dev/null +++ b/uCompat/Debug.lua @@ -0,0 +1,61 @@ +--[[ + Debug Images related µLua compatibility layer/lib for ctrµLua +]] + +-- Module + +Debug = {} + +Debug.isDebugOn = false +Debug.listText = {} +Debug.debugText = "" +Debug.debugColor = Color.new(31, 31, 31) + +function Debug.ON() + Debug.isDebugOn = true + Debug.clear() +end + +function Debug.OFF() + Debug.isDebugOn = false +end + +Debug.print = function(text,aff) + local i + if(text == nil) then text = "" + elseif(text == true) then text = "TRUE" + elseif(text == false) then text = "FALSE" + elseif(type(text) == "table") then text = "<"..tostring(text).."["..table.maxn(text).."]>" + elseif(type(text) == "userdata") then text = "<"..tostring(text)..">" + elseif(type(text) == "function") then text = "<"..tostring(text)..">" + elseif(type(text) == "thread") then text = "<"..tostring(text)..">" + end + if(aff ~= nil) then + if(aff ~= true) then aff = false end + end + if(#Debug.listText == 21) then + for i=1,20 do + Debug.listText[i] = Debug.listText[i+1] + end + Debug.listText[21] = text + else + Debug.listText[#Debug.listText] = text + end + Debug.debugText = "" + for i = 1,#Debug.listText do + Debug.debugText = (Debug.debugText..Debug.listText[i].."\n") + end + if aff then render() end +end + +Debug.setColor = function(color) + assert(color ~= nil, "Color can't be null") + Debug.debugColor = color +end + +Debug.clear = function() + local i + for i = 1,#Debug.listText do + table.remove(Debug.listText,1) + end +end diff --git a/uCompat/Map.lua b/uCompat/Map.lua index 0f7976d..21eeb7f 100644 --- a/uCompat/Map.lua +++ b/uCompat/Map.lua @@ -32,7 +32,7 @@ function Map.draw(scr, m, x, y, w, h) local stack = screen.getStack(scr) local offsetX, offsetY = screen.offset() - stack[#stack+1] = {"map", m, {offsetX+(x*math.floor(m.scrollX*m.tileWidth)), offsetY+(y*math.floor(m.scrollY*m.tileHeight))}} + stack[#stack+1] = {"map", m.map, {offsetX+(x*math.floor(m.scrollX*m.tileWidth)), offsetY+(y*math.floor(m.scrollY*m.tileHeight))}} end function Map.scroll(m, x, y) diff --git a/uCompat/ScrollMap.lua b/uCompat/ScrollMap.lua new file mode 100644 index 0000000..51510e7 --- /dev/null +++ b/uCompat/ScrollMap.lua @@ -0,0 +1,48 @@ +--[[ + Scrollps related µLua compatibility layer/lib for ctrµLua +]] + +-- Local + +map = require("ctr.gfx.map") + +-- Module + +require("uCompat.screen") + +ScrollMap = {} + +function ScrollMap.new(image, mapFile, width, height, tileWidth, tileHeight) + local m = map.load(mapFile, image.texture, tileWidth, tileHeight) + return { + map = m, + scrollX = 0, + scrollY = 0, + tileWidth = tileWidth, + tileHeight = tileHeight, + } +end + +function ScrollMap.destroy(m) + m.map:destroy() +end + +function ScrollMap.draw(scr, m) + local stack = screen.getStack(scr) + local offsetX, offsetY = screen.offset() + + stack[#stack+1] = {"map", m.map, {offsetX+m.scrollX, offsetY+m.scrollY}} +end + +function ScrollMap.scroll(m, x, y) + m.scrollX = x + m.scrollY = y +end + +function ScrollMap.setTile(m, x, y, t) + m.map:setTile(x, y, t) +end + +function ScrollMap.getTile(m, x, y) + return m.map:getTile(x, y) +end diff --git a/uCompat/init.lua b/uCompat/init.lua index efe0c9f..aec04c7 100644 --- a/uCompat/init.lua +++ b/uCompat/init.lua @@ -15,9 +15,11 @@ ULUA_BOOT_FULLPATH = (ULUA_DIR..ULUA_BOOT_FILE) -- Other libs require("uCompat.screen") require("uCompat.Color") +require("uCompat.Debug") require("uCompat.Font") require("uCompat.Image") require("uCompat.Map") +require("uCompat.ScrollMap") require("uCompat.Timer") require("uCompat.Sprite") require("uCompat.Controls") diff --git a/uCompat/screen.lua b/uCompat/screen.lua index 02a1654..833dfc9 100644 --- a/uCompat/screen.lua +++ b/uCompat/screen.lua @@ -77,9 +77,22 @@ function stopDrawing() fpstime = ctr.time() fpscount = 0 end + + -- Debug + + if Debug and Debug.isDebugOn then + local buffer="FPS: "..NB_FPS + local xx=255-(string.len(buffer)*6) + screen.print(SCREEN_UP,171,152,"RAM : "..math.floor(collectgarbage("count")).."ko.",Debug.debugColor) + screen.print(SCREEN_UP,171,162,"VRAM: "..System.CurrentVramFree().."o.",Debug.debugColor) + screen.print(SCREEN_UP,171,172,"PRAM: "..System.CurrentPalFree().."o.",Debug.debugColor) + screen.print(SCREEN_UP,171,182,"FPS : "..NB_FPS,Debug.debugColor) + screen.drawTextBox(SCREEN_DOWN, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Debug.debugText, Debug.debugColor) + end -- render screen.endDrawing() + screen.setAlpha(ALPHA_RESET) end function render() @@ -143,7 +156,7 @@ function screen.drawGradientRect(scr, x0, y0, x1, y1, color, color, color, color end function screen.drawTextBox(scr, x0, y0, x1, y1, text, color) - + checkBuffer(scr)[#videoStack[scr]+1] = {"wrappedText", {offsetX+x0, offsetY+y0, text, x1-x0, 8, RGB2RGBA(color)}} end function screen.drawTexturedQuad(scr, x0, y0, x1, y1, x2, y2, x3, y3, img, sx, sy, w, h) @@ -171,8 +184,8 @@ function screen.startDrawing2D() -- unused videoStack[drawScreen] = {} -- 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 + offsetX = math.floor((gfx.BOTTOM_WIDTH-SCREEN_WIDTH)/2) + offsetY = math.floor((gfx.BOTTOM_HEIGHT-SCREEN_HEIGHT)/2) if drawScreen == gfx.GFX_TOP then offsetX = offsetX + 40 end