TomenetGame / tomenet

TomeNET is an online multiplayer roguelike role-playing game
https://www.tomenet.eu/
Other
69 stars 11 forks source link

Graphics: strong freezes when there a lot of graphic tiles on the screen #59

Closed EvgenijK closed 6 months ago

EvgenijK commented 7 months ago

Description

There are some strong freezing on client side if many graphical tiles are on the screen.

You can see it on the attached video.

On the video terrain(sand) has graphic tile. I also have smaller freezes with objects.(i mapped almost all objects from k_info)

I'm using this tileset (terrain branch): https://github.com/EvgenijK/TomeNET-Tileset/tree/terrain

I hope @jezek can look at this.

https://github.com/TomenetGame/tomenet/assets/8179946/595021e7-e61f-4d95-8d90-6735e705657e

jezek commented 7 months ago

Strong freezing? I don't see any freezing in your video. Maybe we have different definitions for strong freezing. ;)

If you mean that the graphics is not as fluent as font, especially when many graphic tiles are present on screen. I'm aware of that. Drawing font is very fast (I think, there are some optimizations in the font drawing library). When drawing tiles, this is done "manually", every tile has to be prepared from 3 layers (bg, image, fg) and then drawn. I've made it just work. When you have many graphic tiles, speed reduction is noticeable.

I've also thought about it, how it can be improved. I think some sort of dynamic cache for the composed graphic tiles would speed up the drawing (many of the tiles on screen are same). Or using some graphics library with HW acceleration like SDL would definitely speed it up.

But now I have a little to no free time. I will try to make some improvements, when I have some more free time (and no one figures it out until then).

Note: Thanks for the link to your tileset. Nice work.

EvgenijK commented 6 months ago

Maybe look into Angband or Mangband source code?
IIRC they use SDL for graphics

mhirki commented 6 months ago

Are you running the Windows or the Linux client? I tried your tileset with the Windows client but it seems to hang forever. Very Sleepy profiler shows it's stuck calling NtGdiGetPixel and NtGdiSetPixel inside recreateGraphicsObjects. Looks like it's stuck in an infinite loop there.

I'll try with the Linux client next.

mhirki commented 6 months ago

I go the tileset working with the Linux client. I can confirm I'm seeing small freezes when running around inside the Training Tower. CPU usage looks a bit high for the Xorg process. Running "perf top" shows wfbPixmapToRegion from libwfb.so at the top eating a lot of CPU cycles.

mhirki commented 6 months ago

Apparently the Windows client starts much faster when running it under Wine on Linux. So the graphical tile resizing is just extremely slow on native Windows. The faster alternative on Windows would be to call GdipBitmapLockBits and GdipBitmapUnlockBits functions.

EvgenijK commented 6 months ago

I'm using linux client.

Yeah, there is a big delay in game launch time on windows, was too lazy to create issue for that. One of the players said that it took around 5 minutes for him.

mhirki commented 6 months ago

Commit b5a96afdb7c328b1b45683504bb0b968cc685e2e adds a cache for composed graphical tiles which speeds up drawing significantly. I also decided to simply call StretchBlt() to resize the tiles in the Windows client because it is much faster (commit aadce1a8eb9b8bbb90793e7a7e1d7e9aacacc2f0).

EvgenijK commented 6 months ago

@mhirki saw your commits, awesome work, i'm very happy to see that graphics is fast now)