English hudtxt performance

4 replies
Goto Page
To the start Previous 1 Next To the start
23.07.19 11:16:24 pm
Up
Quattro
User
Offline Off
Which method is less stressful on bandwidth when displaying hudtxt2?

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
--1)
show:
parse('hudtxt2 1 1 "TEXT" 0 00 1 12')
hide:
parse('hudtxt2 1 1')
show:
parse('hudtxt2 1 1 "TEXT" 0 00 1 12')

--2)
show:
parse('hudtxt2 1 1 "TEXT" 0 00 1 12')
hide:
hudtxtalphafade(1, 1, 0, 0.0)
show:
hudtxtalphafade(1, 1, 0, 1.0)
24.07.19 12:04:08 am
Up
DC
Admin
Offline Off
The second one costs less bandwidth. For a very simple reason: Less (and shorter) parameters = less data which needs to be sent to the server.

The benefit of using the second method gets even larger if:
• you are disabling/enabling the text more often
• the text gets longer

That's because the biggest advantage is that you only send the text itself once when using the second method.

In general:
• Strings* are huge (in comparison to numbers). Avoid sending strings frequently.
• Commands with less parameters mean less traffic in most cases (of course this is only true for commands which do stuff which needs to be synchronized with the server/other players)

*) cs2d lua cmd image paths are strings too but CS2D creates a mapping table which allows to greatly reduce their size in most cases. This does not work for image paths with special tags though. So in general it's a good idea to keep file names and paths short.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
24.07.19 12:45:25 am
Up
Quattro
User
Offline Off
Can the same method be applied to images with imagealpha() ?
My goal is to create ~40 lines of text with hudtxt2 then show/hide it with a button press without causing lag. Displaying gfx background would be cool too but I don't know if it will cause lag when ~20 players hit it at the same time.

Thank you!
24.07.19 12:34:20 pm
Up
VADemon
User
Offline Off
If you have 100 images with alpha=0, the game still has to render them. I don't think anyone still realistically has a too slow CPU/GPU for this, but keep in mind its probably best to unload images in most cases.
24.07.19 07:40:07 pm
Up
DC
Admin
Offline Off
@user Quattro: Yes, same thing. It is much cheaper to set the alpha of images to 0 and back to something else instead of removing and re-creating them.

@user VADemon: You are right in general but wrong in this particular case. CS2D checks the alpha value before rendering. Images with a very low alpha value are not rendered anymore and therefore do not take any GPU time.

Note the yellow info in cs2d lua cmd imagealpha

Your alpha 0 images will only cost a super tiny bit of CPU because the game will iterate over each image each frame. But the time it takes to iterate over thousands of images is still nothing compared to rendering a single image.

√ Whenever you know that you just want to hide an image and show it again later it's advisable to set alpha to 0 and back to a higher value later.

√ Otherwise (if you don't plan to show the same image again) just use cs2d lua cmd freeimage
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
To the start Previous 1 Next To the start