LUBE issue

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Cowinatub
Prole
Posts: 9
Joined: Fri Nov 09, 2012 6:13 am

LUBE issue

Post by Cowinatub »

I've been using LUBE to program a network game for a couple weeks now, and recently I've noticed that the server I'm using gradually slows down over time. This is starting to get really annoying, and sometimes completely unplayable. Is there anything I can do about this, or is it just an issue with the library?
Attachments
Server.love
(20.03 KiB) Downloaded 84 times
Client.love
(1.1 MiB) Downloaded 102 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: LUBE issue

Post by Robin »

This looks suspect:

Code: Select all

function addline(text)
    LineNumber = LineNumber + 1
    Lines = Lines .. '\n' .. text
end
Try commenting out the last line in the function. You'll get no backlog, but hopefully it won't slow down any more either.

What I would do:
  • Replace Lines = '' by Lines = {}
  • Change addline to

    Code: Select all

    function addline(text)
        if #Lines > 100 then -- something like that
            table.remove(Lines, 1)
        else
            LineNumber = LineNumber + 1
        end
        Lines[#Lines+1] = text
    end
  • Change the drawing code to: (you might want to experiment with that)

    Code: Select all

    for i, line in ipairs(Lines) do
        love.graphics.print(line, 0, 780 + (i - LineNumber) * 14)
    end
EDIT: to be clear, the first part was a test to see if the slowing down was really due to addline. The second part is a proposed solution. Also, here's why:
Your string variable Lines kept on growing, and when you do "a = a .. b", Lua makes a new string object every time, and that gets more and more expensive when your string grows. My proposed solution uses a table, because it is easier to remove the lines you can no longer see and can thus be safely removed.
Help us help you: attach a .love.
Cowinatub
Prole
Posts: 9
Joined: Fri Nov 09, 2012 6:13 am

Re: LUBE issue

Post by Cowinatub »

Thanks for the help! I can sleep easy now knowing that the library I chose is efficient enough for my purposes.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests