From d81485974cf3789ba7246e0c9230aea7ba292880 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Thu, 14 Mar 2019 22:34:23 -0400 Subject: [PATCH] fixes --- GuiManager/Image-Animation/SetImage.int | 16 +++++ .../Image-Animation/SetThreadedImage.int | 60 +++++++++++++++++++ .../Image-Animation/imageThreadHandler.int | 44 ++++++++++++++ GuiManager/Image-Animation/newAnim.int | 15 ++++- GuiManager/Image-Animation/newImageLabel.int | 1 + GuiManager/Misc/SquareX.int | 8 +++ GuiManager/Misc/SquareY.int | 8 +++ GuiManager/Text/fitFont.int | 5 +- GuiManager/init.lua | 11 ++-- 9 files changed, 157 insertions(+), 11 deletions(-) create mode 100644 GuiManager/Image-Animation/SetImage.int create mode 100644 GuiManager/Image-Animation/SetThreadedImage.int create mode 100644 GuiManager/Image-Animation/imageThreadHandler.int create mode 100644 GuiManager/Misc/SquareX.int create mode 100644 GuiManager/Misc/SquareY.int diff --git a/GuiManager/Image-Animation/SetImage.int b/GuiManager/Image-Animation/SetImage.int new file mode 100644 index 0000000..7ff105f --- /dev/null +++ b/GuiManager/Image-Animation/SetImage.int @@ -0,0 +1,16 @@ +function gui:SetImage(i) + if not i then return end + if type(i) == "userdata" and i:type() == "Image" then + self.Image=i + self.ImageHeigth=self.Image:getHeight() + self.ImageWidth=self.Image:getWidth() + self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth) + elseif type(i)=="string" then + gui.loadImageData(i,nil,function(imagedata) + self.Image = love.graphics.newImage(imagedata) + self.ImageHeigth=self.Image:getHeight() + self.ImageWidth=self.Image:getWidth() + self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth) + end) + end +end \ No newline at end of file diff --git a/GuiManager/Image-Animation/SetThreadedImage.int b/GuiManager/Image-Animation/SetThreadedImage.int new file mode 100644 index 0000000..c791c5a --- /dev/null +++ b/GuiManager/Image-Animation/SetThreadedImage.int @@ -0,0 +1,60 @@ +-- local queueUpload = love.thread.getChannel("ImageUploader") +-- local queueDownload = love.thread.getChannel("ImageDownloader") +-- local code = [[ +-- require("love.image") +-- local queueUpload = love.thread.getChannel("ImageUploader") +-- local queueDownload = love.thread.getChannel("ImageDownloader") +-- local clock = os.clock +-- local idle = clock +-- while true do + -- if not idle then + -- love.timer.sleep(.001) + -- elseif clock()-idle>=15 then + -- love.timer.sleep(.01) + -- end + -- local data = queue:pop() + -- if data then + -- idle = clock() + -- print(data[1],data[2]) + -- end +-- end +-- ]] +-- local t = love.thread.newThread(code) +-- t:start() + + +-- _GuiPro.jobqueue:registerJob("LoadImage",function(path) + -- local dat = love.image.newImageData(path) + -- return dat +-- end) +-- local cache = {} +-- _GuiPro.jobqueue.OnJobCompleted(function(JOBID,n) + -- cache[JOBID].Image=love.graphics.newImage(n) + -- cache[JOBID].ImageHeigth=cache[JOBID].Image:getHeight() + -- cache[JOBID].ImageWidth=cache[JOBID].Image:getWidth() + -- cache[JOBID].Quad=love.graphics.newQuad(0,0,cache[JOBID].width,cache[JOBID].height,cache[JOBID].ImageWidth,cache[JOBID].ImageHeigth) +-- end) +-- function gui:ThreadedSetImage(i) + -- local temp = self.Image + -- if _GuiPro.imagecache[i] then + -- self.Image=_GuiPro.imagecache[i] + -- self.ImageHeigth=self.Image:getHeight() + -- self.ImageWidth=self.Image:getWidth() + -- self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth) + -- else + -- if type(i)=="string" then + -- local ii = _GuiPro.jobqueue:pushJob("LoadImage",i) + -- cache[ii] = self + -- elseif tostring(i):find("ImageData") then + -- self.Image=love.graphics.newImage(i) + -- self.ImageHeigth=self.Image:getHeight() + -- self.ImageWidth=self.Image:getWidth() + -- self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth) + -- elseif i then + -- self.Image=i + -- self.ImageHeigth=self.Image:getHeight() + -- self.ImageWidth=self.Image:getWidth() + -- self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth) + -- end + -- end +-- end \ No newline at end of file diff --git a/GuiManager/Image-Animation/imageThreadHandler.int b/GuiManager/Image-Animation/imageThreadHandler.int new file mode 100644 index 0000000..08d3073 --- /dev/null +++ b/GuiManager/Image-Animation/imageThreadHandler.int @@ -0,0 +1,44 @@ +local queueUpload = love.thread.getChannel("ImageUploader") +local queueDownload = love.thread.getChannel("ImageDownloader") +local code = [[ +require("love.image") +require("love.timer") +local queueUpload = love.thread.getChannel("ImageUploader") +local queueDownload = love.thread.getChannel("ImageDownloader") +while true do + love.timer.sleep(.001) + local data = queueUpload:pop() + if data then + queueDownload:push{data[1],love.image.newImageData(data[2])} + end +end +]] +local count = 0 +local conn = multi:newConnection() +function gui.loadImageData(path,tag,callback) + local c = count + count = count + 1 + queueUpload:push{c,path} + if not callback then + return conn + else + local cd + cd = conn(function(id,data) + if id == c then + callback(data,tag,id) + cd:Destroy() + end + end) + end + return c +end +multi:newLoop(function() + local dat = queueDownload:pop() + if dat then + conn:Fire(dat[1],dat[2]) + end +end) +for i = 1,love.system.getProcessorCount() do + local t = love.thread.newThread(code) + t:start() +end \ No newline at end of file diff --git a/GuiManager/Image-Animation/newAnim.int b/GuiManager/Image-Animation/newAnim.int index 5d40ded..64bcda9 100644 --- a/GuiManager/Image-Animation/newAnim.int +++ b/GuiManager/Image-Animation/newAnim.int @@ -1,19 +1,28 @@ function gui:newAnim(file,delay, x, y, w, h, sx ,sy ,sw ,sh) + local _files=alphanumsort(love.filesystem.getDirectoryItems(file)) local x,y,w,h,sx,sy,sw,sh=filter(file, x, y, w, h, sx ,sy ,sw ,sh) local c=self:newBase("ImageAnimation",file, x, y, w, h, sx ,sy ,sw ,sh) + if not w and not h then + local w,h = love.graphics.newImage(file.."/".._files[1]):getDimensions() + c:setDualDim(nil,nil,w,h) + end c.Visibility=0 c.ImageVisibility=1 c.delay=delay or .05 c.files={} c.AnimStart={} c.AnimEnd={} - local _files=alphanumsort(love.filesystem.getDirectoryItems(file)) + local count = 0 + local max for i=1,#_files do if string.sub(_files[i],-1,-1)~="b" then - table.insert(c.files,love.graphics.newImage(file.."/".._files[i])) + count = count + 1 + gui.loadImageData(file.."/".._files[i],count,function(imagedata,id) + c.files[id] = love.graphics.newImage(imagedata) + end) end end - c.step=multi:newTStep(1,#c.files,1,c.delay) + c.step=multi:newTStep(1,count,1,c.delay) c.step.parent=c c.rotation=0 c.step:OnStart(function(step) diff --git a/GuiManager/Image-Animation/newImageLabel.int b/GuiManager/Image-Animation/newImageLabel.int index 72d1eba..db7d0f3 100644 --- a/GuiManager/Image-Animation/newImageLabel.int +++ b/GuiManager/Image-Animation/newImageLabel.int @@ -1,4 +1,5 @@ function gui:newImageLabel(i,name, x, y, w, h, sx ,sy ,sw ,sh) + if not name then name = "Imagelabel" end x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh) local c=self:newBase("ImageLabel",name, x, y, w, h, sx ,sy ,sw ,sh) c:SetImage(i) diff --git a/GuiManager/Misc/SquareX.int b/GuiManager/Misc/SquareX.int new file mode 100644 index 0000000..a369af3 --- /dev/null +++ b/GuiManager/Misc/SquareX.int @@ -0,0 +1,8 @@ +function gui:SquareX(n) + local n = n or 0 + local w = self.Parent.width + local rw = w*n + local s = (w-rw)/2 + self:setDualDim(self.x+s,self.y+s,rw,rw,sx,sy) + return self.Parent.width +end \ No newline at end of file diff --git a/GuiManager/Misc/SquareY.int b/GuiManager/Misc/SquareY.int new file mode 100644 index 0000000..f55d8ea --- /dev/null +++ b/GuiManager/Misc/SquareY.int @@ -0,0 +1,8 @@ +function gui:SquareY(n) + local n = n or 0 + local w = self.Parent.height + local rw = w*n + local s = (w-rw)/2 + self:setDualDim(self.x+s,self.y+s,rw,rw) + return self.Parent.height +end \ No newline at end of file diff --git a/GuiManager/Text/fitFont.int b/GuiManager/Text/fitFont.int index c0cc3f2..a5bda01 100644 --- a/GuiManager/Text/fitFont.int +++ b/GuiManager/Text/fitFont.int @@ -1,4 +1,4 @@ -function gui:fitFont() +function gui:fitFont(n) local font if self.FontFile then if self.FontFile:match("ttf") then @@ -22,7 +22,8 @@ function gui:fitFont() s = s + 1 Font = font(s) end - Font = font(s - 2) + Font = font(s - (2+(n or 0))) Font:setFilter("linear","nearest",4) self.Font = Font + return s - (2+(n or 0)) end \ No newline at end of file diff --git a/GuiManager/init.lua b/GuiManager/init.lua index 377703e..a1d65f0 100644 --- a/GuiManager/init.lua +++ b/GuiManager/init.lua @@ -1,5 +1,7 @@ local multi = require("multi") local GLOBAL,THREAD=require("multi.integration.loveManager").init() +local p = print +print = multi.print -- automatic resource loading will be added soonish utf8 = require("utf8") gui = {} @@ -9,7 +11,7 @@ gui.Version="VERSION" -- Is it really ready for release? _GuiPro={ GLOBAL = GLOBAL, THREAD = THREAD, - jobqueue = multi:newSystemThreadedJobQueue(4), + jobqueue = multi:newSystemThreadedJobQueue("ImageJobQueue"), imagecache = {}, GBoost=true, hasDrag=false, @@ -25,10 +27,6 @@ _GuiPro={ return self.Children end } -_GuiPro.jobqueue:registerJob("LoadImage",function(path,t) - local dat = love.image.newImageData(path) - return dat,path,t -end) _GuiPro.Clips={} _GuiPro.rotate=0 _defaultfont = love.graphics.setNewFont(12) @@ -69,7 +67,7 @@ gui.LoadAll("GuiManager/Drawing") -- End of Load gui:respectHierarchy() _GuiPro.width,_GuiPro.height=love.graphics.getDimensions() -multi:newLoop(function() _GuiPro.width,_GuiPro.height=love.graphics.getDimensions() end) +multi:newLoop(function() _GuiPro.width,_GuiPro.height=love.graphics.getDimensions() end):setName("gui.mainUpdater") multi:onDraw(function() local items=GetAllChildren(_GuiPro) for i=1,#items do @@ -81,3 +79,4 @@ gui.ff.Color={0,0,0} gui.ff:OnUpdate(function(self) self:BottomStack() end) +print = p