How often can I update the window title?

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
ncrecc
Prole
Posts: 4
Joined: Sat Jul 18, 2015 4:40 pm

How often can I update the window title?

Post 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?
User avatar
dusoft
Party member
Posts: 634
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: How often can I update the window title?

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How often can I update the window title?

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
RNavega
Party member
Posts: 353
Joined: Sun Aug 16, 2020 1:28 pm

Re: How often can I update the window title?

Post 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.
RNavega
Party member
Posts: 353
Joined: Sun Aug 16, 2020 1:28 pm

Re: How often can I update the window title?

Post 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
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: How often can I update the window title?

Post 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)
RNavega
Party member
Posts: 353
Joined: Sun Aug 16, 2020 1:28 pm

Re: How often can I update the window title?

Post 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 5721 times
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: How often can I update the window title?

Post 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%.
obey
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests