Physics

Options
I have a room, i have a physics world created by room at start

All's good

I want to do those things with 10hz:
Take input from clients inside room (not lockstep, just as fresh as possible)(Clients update those with ~10hz also).
Do physics step with those values.
Send new positions to clients.

So what is better solution?

1)Queue that UpdateAndSend method into room's fiber
+ : no locks, just works, no new threads, scales
- : can be delayed

2)Create another fiber specially for that method and schedule there (so it will be called with exactly that delay (0.1s)
+ : can't be delayed, no new threads, scales
- : should use ReadWriteLockSlim on positions and inputs

3)Create async Task and while loop inside with use of cancellation tokens
+ : can't be delayed, no new threads, scales
- : should use ReadWriteLockSlim on positions and inputs

4)Explicit thread
+ : can't be delayed
- : not scales, should use locks, explicit thread creation,

The reason why i want to send resulting positions right after calculating physics is to not do irrelevant calculations

Best Answer

Answers

  • TomatoFromTheSky
    edited December 2017
    Options
    yep, we need to increase step by delay between it's estimated time and time when we actually starting step
    chvetsov said:

    1) and 2) basically are same

    Hm, is it true only when "tasks" in room's fiber executes very fast? I mean if some of queued "tasks" will take 1 second (impossible, but still), then second fiber will still call physics with relatively same delays , so they are not so same.. But i guess those 1s long "tasks" will never happen in real world with good architecture, so i'm overthinking it :)

    thank you, Илья :D