Page 1 of 1

How often can I update the window title?

Posted: Fri Aug 16, 2024 8:25 pm
by ncrecc
https://love2d.org/wiki/love.window.setTitle :
Constantly updating the window title can lead to issues on some systems and therefore is discouraged.
How often is "constantly"? What could be considered a safe minimum time between setTitle calls? (And what sort of issues emerge?)

My game changes its window title based on what area you're in. In some situations, the player (of their own volition) might be able to straddle between areas 2-3 times per second, which causes the window title to change each time. Would this generally cause issues?

Re: How often can I update the window title?

Posted: Fri Aug 16, 2024 10:05 pm
by dusoft
I mean isn't it easier to test it? If you are in luck, you might get someone from the dev team to answer this.

Re: How often can I update the window title?

Posted: Tue Aug 20, 2024 6:22 am
by zorg
Without vsync, i had a game freeze my OS due to setTitle being called hundreds of times per second... granted it was back on Win7, but still not a good thing.

That would be a potential issue; recommended minimum time i can only suggest something not faster than 1/4 seconds simply because that should be enough for the most dynamically updating windows title you might need. That said, with your explanation, your usecase should be fine.

Re: How often can I update the window title?

Posted: Tue Aug 20, 2024 7:19 am
by RNavega
This sounds related to "event de-bouncing" (edit: "throttling" actually, not "de-bouncing") that people do in JavaScript, to not clog up the interpreter when you're flooded with events and each event is costly to process:
https://www.inkoop.io/blog/debounce-and ... t-edition/

I think zorg's suggestion of a constant update rate (refreshing the window title at even timesteps, say, every 1 second), is probably the safest way.

Re: How often can I update the window title?

Posted: Tue Aug 20, 2024 7:51 am
by RNavega
Relevant source code:
love.window.setTitle() calls SDL_SetWindowTitle():
https://github.com/love2d/love/blob/mai ... .cpp#L1244

SDL in turn calls different functions depending on the platform, these are a few:

Windows: https://github.com/libsdl-org/SDL/blob/ ... dow.c#L634
X11 (Linux): https://github.com/libsdl-org/SDL/blob/ ... ow.c#L1891
Cocoa (Apple): https://github.com/libsdl-org/SDL/blob/ ... ow.m#L1882

Re: How often can I update the window title?

Posted: Tue Aug 20, 2024 11:21 am
by pgimeno
I'm not a big fan of the proposal to use a constant update rate, as it wil cause a bit of lag in the display of the updated title. Instead, a cooldown timer will provide instant reaction time in all situations except those that are potential trouble makers.

For example, something like:

Code: Select all

local currentTitle = "\0"
local newTitle = currentTitle
local titleCoolDown = 0.25 -- Cool-down time
-- Initialize the timer to expired
local titleTimer = love.timer.getTime()

local function setTitle(title)
  newTitle = title
  if title == currentTitle then return end
  local time = love.timer.getTime()
  if time < titleTimer then return end
  currentTitle = title
  love.window.setTitle(title)
  titleTimer = time + titleCoolDown
end

function love.update()
  -- Add this somewhere within your actual love.update()
  setTitle(newTitle)
end
You can test it e.g. with:

Code: Select all

local n = 0
function love.keypressed()
  n = n + 1
  setTitle(tostring(n))
end
(press any key to change the title)

Re: How often can I update the window title?

Posted: Tue Aug 20, 2024 6:18 pm
by RNavega
ncrecc wrote: Fri Aug 16, 2024 8:25 pm My game changes its window title based on what area you're in.
In another direction, design-wise, I can't remember playing a game that did that kind of thing (having important info outside of the game screen).
Isn't there a way for the text to be on screen, in a way that fits with your game? This would make the text a graphic like any other, and extremely fast to draw. You can have it at the top of the screen like a notification banner, or a tooltip that follows the player, or something else.
locationName.gif
locationName.gif (868.26 KiB) Viewed 3541 times

Re: How often can I update the window title?

Posted: Sat Aug 24, 2024 3:06 pm
by BrotSagtMist
Window titles are a bad idea to place information in because you never know what window management your users have and how it will be cut away.
Does the user even have a Title?
This also affects how changable it is, different OS and WMs and such, likely you can do framerate speed for 90% of users but also may end up crashing on the rest 10%.