Irevol / minetest-citadel

A minetest game
Other
3 stars 1 forks source link

Ghost text lags the game when fading #44

Open Wuzzy2 opened 8 months ago

Wuzzy2 commented 8 months ago

When the "ghost text" fades in or out, the game starts lagging heavily for a moment. But this only happens for the first time you get to see a particular text. If you see it a second time, it faded in or out smoothly.

Still, the lag is noticable and very irritating. Maybe this has something to do with how the fade effect is implemented?

Warr1024 commented 2 months ago

A lot of this is because the ghost text is implemented as largeish graphics which have to be dynamically drawn using texture modifiers, so the MT client has to build and cache these. IIRC some work was done (e.g. rounding opacity values to get a better cache hit rate) to improve it, but it still varies widely between machines.

Unfortunately MT's HUD system isn't advanced enough to accomplish this stuff well without seriously damaging the artistic vision ... which is also a shame because as it is, these would be hard to translate (though not as hard as the voice acting).

A mitigation is to trick the engine into pre-caching these graphics (along with other "flash/fade effects" like the sepia tone, the time change flashes, the base image for the credit screen, etc. MT always pre-builds and pre-loads all graphics that are associated with the face of a node, so you can pack up to 6 textures into "fake" node definitions (just never allow the nodes to actually be placed in-game) and the images are pre-cached during "initializing nodes" when the game is loading, and are then already available for use during play (though, the GUI scaling filter, if enabled, may still add a bit of lag). This is not always feasible, but for a game with the level of complexity and available node definitions of Citadel, it's probably practical enough. ColourHop takes advantage of this trick for its various-colored screen flashes.

Warr1024 commented 2 months ago

ColourHop's implementation:

https://gitlab.com/talas777/colourhop/-/blob/master/mods/ch_flashscreen/init.lua?ref_type=heads#L13-78

Much of the code might actually be usable. The hardest part is systematically determining what all the different images will be at load time.