gcmartijn wrote: ↑Wed Jun 01, 2022 2:48 pm
But now I see a glitch when loading a newImage when the game is already running.
This is because this image loading is on the main thread.
Accessing PhysFS to decompress the .love takes its time, and decompressing a .png or .jpg image typically even more. It's quite unlikely that you can do that in less than a frame time, as MrFariator has pointed out. There's a reason why asset loading screens exist
But I wonder about the difference in loading time between newImage from a file and newImage from an ImageData object. One way to tell, which I think should be easy to test, would be to load the file into an ImageData object the first time and cache it, creating a newImage from it and destroying the Image (but not the ImageData) when closing the dialog. Later, when invoking the dialog again, creating another Image from the ImageData, which is still cached. The difference between the first invocation and the second should tell you whether it's worth loading the image from a thread or not. If the second is instantaneous, then it's pretty much worth it.
pgimeno wrote: ↑Wed Jun 01, 2022 10:27 pm
Accessing PhysFS to decompress the .love takes its time, and decompressing a .png or .jpg image typically even more. It's quite unlikely that you can do that in less than a frame time, as MrFariator has pointed out. There's a reason why asset loading screens exist
The complexity/time of image loading is one reason to use QOI format for images. It's a little less efficient in terms of disk space (which is SUPER cheap), but WAY faster to encode/decode.
EDIT: Typo
Last edited by milon on Mon Jun 06, 2022 6:24 pm, edited 1 time in total.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Even with a faster format it's not advisable to load assets during gameplay. Keep in mind that if you tell your game to load something in a synchronous manner, the game will effectively halt until it receives the data it needs from the host computer. Even in a scenario where you have some the quickest, latest m.2 SSD, it's possible that the OS scheduler might just delay things enough that any speed gain between QOI and PNG is moot.
That's to say, QOI isn't the solution to this particular problem, but it can be helpful in other cases.