proc/Oxygen()
set background = 1
var/tmp/turf/space/S
for(S)
//sleep()<---brings CPU use to 3%
var/tmp/turf/ground/G
for(G)
//sleep()<---brings CPU use to 3%
spawn(50) Oxygen()
using the below CPU& output
obj
cpu_display
screen_loc = "1,1"
plane = 3
maptext_width = 256
New()
..()
spawn(1)
while(src)
maptext = "<font color=white>CPU: [world.cpu]%</font>"
sleep(10)
Problem description:
Seems that if I sleep then CPU use goes up to 3%, but if I don't CPU use stays at 1%. Is this because it actually is using more CPU or because it is just "detecting" that because of the delays involved?
Okay I am trying to implement oxygen in a game and my thoughts were that I needed 3 things.
#1 Loop through every space tile and find neighboring tiles that weren't density == 1 and also weren't space and take away some of their oxygen.
#2 Loop through every surface tile and find neighboring tiles that aren't density == 1 and if they have lower oxygen share some oxygen with them.
#3 Loop through and generate oxygen above vent tiles.
Am I going about this right and is it better to put sleep() in the working parts of the loops or not when used in this fashion?
Also, you should probably not be using recursion for your Oxygen(), instead you should be calling it as a controlled infinite loop. Calling the proc over and over incurs extra overhead and is far harder to keep control over.
As for the question at hand, using sleep() will show CPU increasing because that proc has to do more work, but the delay prevents it from overflowing and crashing out.
Now say you wanted that loop to hit everything on the list at approximately the same time, and not subsequently? You'd spawn() off the stuff inside of the loop so that the loop can continue while that code executes.
You have to be very careful when it comes to spawn() though, things can change during that delay, things like src being deleted or variables getting new values, so always be sure to double-check things after the spawn() has be fulfilled.