CHlM3RA 0 Posted November 21, 2014 Share Posted November 21, 2014 I'm currently working on a state machine like function set to maximize efficiency with GPU calls.It is meant for usage with a program that builds its interface dynamically (user input, config file)where thinking about efficiency will give you more then just headaches.It is called like the gpu.set/fill command and returns a id for the given command so you can undo it.if you add commands or remove commands it will take care that the other commands are displayedcorrectly and given the case that a command would be displayed just to be overridden within thesame render sequence its not calling it. To that I'm trying to let it find the most efficient way to executethe commands because GPU calls are the most time taking thing in open computers i found so far. Current version 0.6Graphics_0.6- Optimized memory usage and made id consistent on: - move() - setTop() - Optimized memory usage on - remove() - Added - setBack() - removeAll() - refreshAll()Note: - Move, setTop and remove will no longer return an id in the future because it stays the same. - The memory usage is almost 50% more efficient on those functions now - (It was a get two for the price of one thing).Todo: - cleaning up color sorting and adding fill/set sorting - returning estimated time on how long draw will take to render Graphics_0.4- Improved remove efficiency- Minimized gpu.setBackground calls- added lots of functions- removed lots of bugs- doesn't draw outside of screenI didn't do much testing yet there may be some bugs here and there.Please if you find any bugs then leave a comment so i can fix it thanks.Functions:set(x, y, with, height, background color) or set(x, y, text, background color, text color) returns: id- The id is required to make changes or delete a command. Don't lose it.remove(id) returns: x, y, with, height, background color or x, y, string, background color, text color nil since 0.6- removes command that has given id, thows an error if it does not find it- Memory is only freed after the next draw()draw() returns: nil- Draws any changes on the screenmove(id, x, y) returns: id (nil in 0.7)- Moves a command by x, y and sets it on top.- Important: Important: will return nill in upcoming versions.setTop(id) returns: id(nil in 0.7)- Moves command on top (as if it was the last command given)- Important: Important: will return nill in upcoming versions.setText(id, text [, text color]) returns: boolean(nil in 0.7)- Changes the text. I have no clue what happens if the text is shorter or longer than the old one- Returns true if it found the id, false if not- Uses old text color if not specifiedsetCol(id, color) returns: boolean(nil in 0.7)- Changes the background color- Returns true if it found the id, false if notrefresh(id) returns: boolean(nil in 0.7)- Redraws itself and everything on top of it.- Returns true if it found the id, false if not setBack(color) returns: nil- sets backgroundcolorrefreshAll() returns: nil - refreshes everything removeAll() returns: nil - removes everything example: local gra = dofile "graphics_0.6.txt" local component = require "component" local gpu = component.gpu x, y = gpu.maxResolution() local id = {} gra.setBack(0x000000) id[1] = gra.set(5,5,"moving -->", 0xffffff, 0x000000) gra.draw() os.sleep(0.5) for i = 1, x do gra.move(id[1], 1, 0) gra.draw() os.sleep(0.05) end gra.setBack(0xffffff) gra.setCol(id[1], 0x000000) gra.setText(id[1], "<-- moving", 0xffffff) gra.draw() for i = 1, x do gra.move(id[1], -1, 0) gra.draw() os.sleep(0.05) end os.sleep(0.5) gra.setBack(0x000000) gra.remove(id[1]) gra.draw() gpu.setBackground(0x000000) gpu.setForeground(0xffffff) graphics_0.4.txt test.txt graphics_0.6.txt test_2.txt Quote Link to post Share on other sites
kevinkk525 8 Posted March 13, 2015 Share Posted March 13, 2015 This looks interesting as I am trying to build a good GUI for a shopping client. I will take a look at your code. Thanks for sharing. Quote Link to post Share on other sites