creating low-power apps without animations

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
User avatar
Kartik Agaram
Prole
Posts: 14
Joined: Fri Apr 01, 2022 4:46 am

creating low-power apps without animations

Post by Kartik Agaram »

I have this idea for an app that draws to the screen as little as possible. So I tried modifying love.run (from https://love2d.org/wiki/love.run) to only draw on events:

Code: Select all

function love.run()
  love.graphics.setBackgroundColor(1,1,1)

  love.graphics.origin()
  love.graphics.clear(love.graphics.getBackgroundColor())
  -- could call love.draw() here
  love.graphics.present()

  -- Main loop time.
  return function()
    -- Process events.
    if love.event then
      love.event.pump()
      for name, a,b,c,d,e,f in love.event.poll() do
        if name == "quit" then
          if not love.quit or not love.quit() then
            return a or 0
          end
        end
        love.handlers[name](a,b,c,d,e,f)
      end

      -- update screen only on events
      love.graphics.clear(love.graphics.getBackgroundColor())                  -- A
      -- could call love.draw() here
      love.graphics.present()
    end

    love.timer.sleep(0.001)
  end
end
As expected, this prints a white screen.

However, if I delete the line labeled A, because I want to not clear the screen on every frame, the screen starts to flicker.

Does anyone understand why this happens?
Attachments
test.love
(478 Bytes) Downloaded 24 times
User avatar
ReFreezed
Party member
Posts: 571
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: creating low-power apps without animations

Post by ReFreezed »

love.event is the module that lets you handle events, i.e. it's always a table, so the if-condition always passes and love.graphics.present() gets called every frame. You should check if the for-loop runs at least once and only clear+draw+present then.

The flickering if you delete love.graphics.clear() is caused by multiple buffering swapping two buffers back and forth.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
BrotSagtMist
Party member
Posts: 272
Joined: Fri Aug 06, 2021 10:30 pm

Re: creating low-power apps without animations

Post by BrotSagtMist »

little as possible> not having zero cpu usage.
I chuckled a little.
What you want is a check value that signals if there actually is something worth of drawing, if there is not, then just ignore everything.

Anyway this double buffer flickering is explained in the link but the TLDR version is that many/most graphic cards have multiple, usually two, picture buffers that are flip flop. So you dont end up with reading/writing at the same time.
The buffer is switched on each love.graphics.present(), imagine it like having two canvases and each time present is called they are switched.
And a canvas actually helps if you want to get rid of the clear() call, you just draw a canvas instead.

The hard part is to solve that if you only want to change a tiny amount of pixels, like a cursor, you gotta have to repaint the whole screen for having 20 pixels blink.

You can turn of your graphics card and use software rendering instead using an environment variable, this wont double buffer, you can paint single pixels without the rest of the screen. This is a better method for desktop applications BUT it performs VERY terrible on anything non static. And just having any draw at all is non static. Works nice with love.event.wait() tho.
Have fun getting a blinking cursor with that.
obey
User avatar
pgimeno
Party member
Posts: 3223
Joined: Sun Oct 18, 2015 2:58 pm

Re: creating low-power apps without animations

Post by pgimeno »

If you don't draw everything and call present() every frame, your application is not going to refresh the window contents when you place another window over the Löve window. There's no window content storage and no exposure notification; the window needs to be redrawn every frame. See viewtopic.php?f=4&t=81204&p=190914#p190914
User avatar
BrotSagtMist
Party member
Posts: 272
Joined: Fri Aug 06, 2021 10:30 pm

Re: creating low-power apps without animations

Post by BrotSagtMist »

Objection, placing another window on top of löve generates an event with the value nil.
While not being useful for much, it at least can trigger a refresh and you can avoid the frozen program look.
obey
User avatar
Kartik Agaram
Prole
Posts: 14
Joined: Fri Apr 01, 2022 4:46 am

Re: creating low-power apps without animations

Post by Kartik Agaram »

Thanks everyone for the extremely illuminating answers!
Have fun getting a blinking cursor with that.
That is, in fact, the one bit of animation I was hoping to retain :D Which introduces problems of redrawing the character under the cursor as well..
User avatar
BrotSagtMist
Party member
Posts: 272
Joined: Fri Aug 06, 2021 10:30 pm

Re: creating low-power apps without animations

Post by BrotSagtMist »

I see little chance of doing that without redrawing all the pixels.

But i solved the amount of refreshes by creating different draw layers.
So the underlayer is refreshed after actual draw operations, the mid layer on events and the top layer, where the cursor is, has a timer.
obey
User avatar
Kartik Agaram
Prole
Posts: 14
Joined: Fri Apr 01, 2022 4:46 am

Re: creating low-power apps without animations

Post by Kartik Agaram »

That makes sense. This thread also reminded me of Canvas which might be a better way to save power. Do you turn each of your layers into canvases?
User avatar
BrotSagtMist
Party member
Posts: 272
Joined: Fri Aug 06, 2021 10:30 pm

Re: creating low-power apps without animations

Post by BrotSagtMist »

Nope, one canvas.
But still working on these problems myself.
obey
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests