English 0 seconds delay loops

6 replies
Goto Page
To the start Previous 1 Next To the start
18.04.19 03:27:24 am
Up
Goo
User
Offline Off
Hey, I'm not very experienced with mapping's resource management, and I came here to ask a couple questions:

1. Can using a 0 sec delay to activate another 0 sec delay (and repeat that as a loop) cause any issues?
2. Should #1 be placed in Lua instead (such as ms100 hook)?
3. How does it compare to the ms100 hook in terms of resources?
4. How fast is it looping?
5. How fast are delays triggered in general? (Could be the same as #4)
6. Should I use it to call a trigger_if (for a math.random)?

Thanks!
18.04.19 05:55:27 am
Up
Devil-Thanh
GAME BANNED
Offline Off
Cs2d is single threaded, so 0s delay is impossible, it must be at least some ms and use the @cs2d lua cmd timer to re trigger
18.04.19 06:25:26 pm
Up
Goo
User
Offline Off
Yes but can you answer in a more detailed way? So I'll know if I should use the ms100 hook or the 0 delay loop.
18.04.19 07:41:14 pm
Up
DC
Admin
Offline Off
In general, infinite entity trigger loops (and also infinite loops in scripts) are something that must be avoided at all cost. Having an infinite trigger loop would make CS2D crash in some cases (depending on the type of entities involved).

This is because - like user Devil-Thanh pointed out correctly - CS2D is single threaded and it would keep updating the trigger stuff forever and couldn't update anything else anymore (the rest of the game).

cs2d entity trigger_delay is a special case because when you trigger a trigger delay it will only set a timer. The actual trigger action will be executed one frame earlier (in case of 0 delay or only a few ms delay) or later. This allows CS2D to move on instead of staying in a trigger loop. (I actually didn't test that but I had a short look at the code and it looks like it should behave like that)

1. With cs2d entity trigger_delay? You can do that (see explanation above) but depending on what you're doing it can be quite expensive. Especially when you run stuff which needs to be sent to clients. Then this would cause a lot of additional network traffic. If possible try to use a higher delay. You can also use fractions of a second. e.g. 0.2 for 200 ms = 5 times per second.

2. Depends on what you want to do. If other Lua code is involved anyway (via trigger_if) I would recommend to do everything in Lua instead of using entities.

3.
• trigger_delay with 0 delay should be executed every frame (if it directly triggers itself or another 0 delay trigger_delay again) = ~60 times per second (comparable to cs2d lua hook always which executes about 50 times per second for backward compatibility reasons)

• cs2d lua hook ms100 is executed ~10 times a seconds. Way less frequently and therefore it costs less resources.

4. See above explanations. There is no real looping! CS2D is single threaded. So if you want to execute something over a longer period of game play time you can do that only as fast as CS2Ds mainloop executes and that is capped by the FPS.

5. See 3/4

6. See 2. If you want to do Lua stuff you should probably just do the whole thing in Lua. It's cleaner. Performance wise there probably isn't a huge difference.


Hope that helps. If it doesn't you should maybe tell us what you plan to do
edited 1×, last 18.04.19 07:51:35 pm
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
18.04.19 07:56:31 pm
Up
Goo
User
Offline Off
Delay 1 calls Delay 2

Delay 2 calls Delay 1 + If

If checks a math.random(1,5)
√ Enable or disable light source
× Do nothing

That's to make a flickering light source.

Though I didn't know delays can use floats... Gonna give it a go!
18.04.19 08:05:56 pm
Up
DC
Admin
Offline Off
I see. Should be okay to do this with entities only. Shouldn't really make a difference performance wise.

Note that this causes internet traffic though if you play a map with this online. Each time the light state is changed via triggering. It's okay with one light but if you have many flickering lights which flicker with a high frequency then this may become a problem ( = quite a lot of additional traffic just for a simple effect).
edited 1×, last 18.04.19 08:07:04 pm
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
18.04.19 08:06:58 pm
Up
Goo
User
Offline Off
For now it's only used once in a 32x32 light source, I don't plan to use it more than 3 times (hell I barely found a use for it once).

This is how it looks in case you're interested https://youtu.be/b8njfuhuPIo
To the start Previous 1 Next To the start