Jump to: navigation, search

Tutorial Managing Workloads

What's a workload?

When you are writing Java-script you must remember that you have a limited amount of Java-script processing time per simulation step (A server simulation step is currently 33ms long). The reason for this is simple, it's to stop people writing Java-script that causes the server to slow down or stop responding due to a infinite loop.

This poses a problem for those who wish to do some interesting long lived Java-script processing, such as generating a mandelbrot set, because this often takes seconds to generate the data (which you may want to visualise). It's not just processing tasks that are limited per simulation step, you can only add or remove a certain amount of voxels or issue a number of HUD commands. See the "limitations per step" page for full details.

What happens when I exceed things?

If you write some Java-Script that takes too long then your world will be killed. This means the world stops running and is removed from Cubiverse, you may float around the world but all players will be disconnected and nothing will run (mob's, voxels, etc.)

Is there a way to do long-lived JS operations?

The key things to do is used timers (setTimeout, setInterval, etc.) to do little bits of your routine per simulation step. Take the mandelbrot set, you would divide the operation into two parts.. the generation of the mandelbrot set and the visualisation (i.e. setting all the ground to the same colours as the mandelbrot set). The generation routine has an inner loop that calculates the set, this would be placed in a timer to do one (or possible a few) iterations per timer. When the set is produced you would then start running a visualisation timer, which would set the voxel's in the ground (a few each timer) to show the mandelbrot set.

If you decide to make a mandelbrot set, let me know and I`ll link to it here!!