ID:2345869
 
MrStonedOne has already provided with a better explained topic on how to do this, my version is just the simpler method of copypaste&use, if you'd like a more detailed explanation then I can possibly give, please check it out:
http://www.byond.com/forum/?post=2055964

____________________________________________________________ ____
SS13 has always had the issue of lag and shit performance, it was usually playable, but the freezes and lagspikes eventually ended up being quite irritating. Since a few years we've had a new controller (basically process manager), and some nifty additions to the code that really helped on performance. I am here to show you the 'key', which you can apply anywhere in laggy for/while loops. It is:

(make sure to add it in a file that is above most, since otherwise it will not recognize it)
#define CHECK_TICK if(world.tick_usage > 80) sleep(world.tick_lag)


You can apply CHECK_TICK under your loops (Not movement though, since it does add a small delay) that should streamline your functions more and spread it over multiple ticks. Its been a very useful addition to SS13, and it may help you too. Just put it at the end (inside) your expensive loops that aren't reliant on ('immediate') performance. (like movement!)

Why 80 as a value? From what I've gathered the server also sends map updates at the end of you ticks, 80 seemed to be the perfect value to keeping performance in line with lag, but you can always give it a bump up to 85ish to see how that fares.


I do not take any credit, I'm just posting it here because I feel many games could do with some improved speeds, and this is the most simple approach to try and balance it out. Good, efficient coding is still key!

With this, you can also potentially reduce your tick_lag rate, providing you with a smoother looking game.

Enjoy!
Here I thought some general BYOND code would, lie you know for the masses.

But this is just for SS13 what has BYOND become, do we not make games anymore and focus on SS13?

P.s change the title, very misleading..
This is not just for SS13? this code can be thrown in anywhere and it will work completely.

All this does is spread the load over multiple ticks, keeping the tick_usage from going over 100 and causing a lagspike/freeze. Performance is something most complain about, this is a rather simple approach to smoothening out a game.

Not misleading, not just for SS13. And frankly I've been on SS13 since 2012, I make my own version of a game so what's the difference?
In response to A.T.H.K
A.T.H.K wrote:
Here I thought some general BYOND code would, lie you know for the masses.

But this is just for SS13 what has BYOND become, do we not make games anymore and focus on SS13?

P.s change the title, very misleading..

Not misleading at all -- you just stopped reading at "SS13".
In response to FKI
FKI wrote:
A.T.H.K wrote:
Here I thought some general BYOND code would, lie you know for the masses.

But this is just for SS13 what has BYOND become, do we not make games anymore and focus on SS13?

P.s change the title, very misleading..

Not misleading at all -- you just stopped reading at "SS13".

In response to MrStonedOne
MrStonedOne wrote:
ID:2055964

Edited main post, hadn't seen it yet. Should be pinned somewhere on top imo.
In response to MrStonedOne
What if I'm not getting any missed ticks? (At least playing solo). Should I add this?
You probably wouldn't see too many missed ticks locally, if any cropped up they'd probably pass before you noticed. This is more of an online thing in instances where you have heavy loops and the sort that are running across many players.
In response to Nadrew
I see. Better safe than sorry then!
In response to NSBR
NSBR wrote:
What if I'm not getting any missed ticks? (At least playing solo). Should I add this?


Fully depends on how heavy your loops/functions are, if they appear too heavy (profiler-wise or feel-wise) or the game freezes for split seconds it may be useful to do.

For anything smaller I'd recommend going for the fastest (without the 'lag fix' applied)
In response to NSBR
NSBR wrote:
I see. Better safe than sorry then!

No, not better safe than sorry. Not all behavior needs to be able to happen distributed over multiple ticks. Some behavior needs to be processed instantly and can't sleep at will. Some can.

When in doubt, don't use the above trick, rather than the opposite.

Generally speaking, anything a player does should be instantaneously handled, or the player should be forced to wait until it completes before triggering another action.

Anything your world does, on the other hand, can generally wait a little bit provided it doesn't need to be finished before players can do something.
In response to Ter13
Ter13 wrote:
NSBR wrote:
I see. Better safe than sorry then!

No, not better safe than sorry. Not all behavior needs to be able to happen distributed over multiple ticks. Some behavior needs to be processed instantly and can't sleep at will. Some can.

I didn't say that all behavior needed to. Was just asking if I should use this in general, even if my game (At least in solo) isn't showing missing ticks.
In response to NSBR
NSBR wrote:
Ter13 wrote:
NSBR wrote:
I see. Better safe than sorry then!

No, not better safe than sorry. Not all behavior needs to be able to happen distributed over multiple ticks. Some behavior needs to be processed instantly and can't sleep at will. Some can.

I didn't say that all behavior needed to. Was just asking if I should use this in general, even if my game (At least in solo) isn't showing missing ticks.

The substance of what I said was that you shouldn't use this in general. If you don't know that you need to use it, don't.