Howto do Threading the right way in SP?
Posted: Fri Jul 08, 2016 10:59 am
Hey guys,
I really appreciate your help. This forum is very active and because of that I'm getting my little mods better and better. In another thread you mentioned that I should use "Delay" for "outsourcing" things that just need time e.G. 3 seconds in the future.
For my modification I need to calculate a player position to an object over and over again. I use this function for that:
[
And yes I'm careful that it's nothing bad at all. So I didn't have a performance problem with this thing. Now: if I use Delay (to respawn a player in e.G. 3 Seconds after death) the OnTick listener stops for at least 3 seconds. That's a problem because I need some math done over and over again otherwise the player would think that something went wrong or does "lag" - even if he can move normally some information messages from the server do not appear at the right time. I tried different things to avoid that (e.G. using queues and make a respawn wave instead of an "normal" respawn).
My question is: how can I do my math stuff indepently from the main thread because the Delay function seems to interrupt my OnTick event. If I just comment out the Delay all is fine.
I know I have to use the GameThread instead of Thread itself but with both (Thread and GameThread) I used to crash the whole server after starting the thread. I also used this tutorial and picked up the neccessary things from it https://pymotw.com/2/threading/
[
Seems I'm to dumb to find a solution myself.
I really appreciate your help. This forum is very active and because of that I'm getting my little mods better and better. In another thread you mentioned that I should use "Delay" for "outsourcing" things that just need time e.G. 3 seconds in the future.
For my modification I need to calculate a player position to an object over and over again. I use this function for that:
[
Syntax: Select all
]
from listeners import OnTick
@OnTick
def tick_listener():
And yes I'm careful that it's nothing bad at all. So I didn't have a performance problem with this thing. Now: if I use Delay (to respawn a player in e.G. 3 Seconds after death) the OnTick listener stops for at least 3 seconds. That's a problem because I need some math done over and over again otherwise the player would think that something went wrong or does "lag" - even if he can move normally some information messages from the server do not appear at the right time. I tried different things to avoid that (e.G. using queues and make a respawn wave instead of an "normal" respawn).
My question is: how can I do my math stuff indepently from the main thread because the Delay function seems to interrupt my OnTick event. If I just comment out the Delay all is fine.
I know I have to use the GameThread instead of Thread itself but with both (Thread and GameThread) I used to crash the whole server after starting the thread. I also used this tutorial and picked up the neccessary things from it https://pymotw.com/2/threading/
[
Syntax: Select all
]
from listeners.tick import GameThread
Seems I'm to dumb to find a solution myself.