Computer running hot

Blitz3D Forums/Blitz3D Beginners Area/Computer running hot

grindalf(Posted 2009) [#1]
Im writeing a 3D rpgmaker and when im testing the editer my computer heats up to a scary amount after about five minutes. it doesent do it with any other programs(i havent tested any other blitz programs out to see if they do it too) any ideas as to what it could be?


Yasha(Posted 2009) [#2]
Are you using Delay in your main loop?

If you don't call Delay, Blitz3D eats all the CPU time (the wait at Flip doesn't seem to free time). You should at the very least add a "Delay 1" somewhere, or if you're feeling a little more adventurous:


Global appheight=768
Global appwidth=1024
Global appdepth=32

AppTitle "";,"Are you sure you want to quit?"

SC_FPS=60	;Set your desired framerate
rtime=Floor(1000.0/SC_FPS)	;Calculate what that gives you in milliseconds
limited=True

Graphics3D appwidth,appheight,appdepth,2
SetBuffer BackBuffer()


;Load up your scene here


While Not KeyDown(1)
	ctime=MilliSecs()	;Get the time at the start of the loop

	;Place Game Here
	
	RenderWorld
	
	n=rtime-(MilliSecs()-ctime)		;Calculate how much "spare" time you have this loop
	Delay n-(limited+1)				;Free that time, with a bit less as error margin
	Flip limited
Wend

End


Run this, and take a look in Task Manager's "Performance" tab - then comment out the Delay and do it again. You'll see a big difference.


grindalf(Posted 2009) [#3]
Im useing delay 1, if i raise the delay will it make the comp run cooler?
cant test the code yet got no blitz on this comp.


Adam Novagen(Posted 2009) [#4]
Well, it depends on your computer, grindalf. Blitz Basic, being so nicely expansive & universal, is also very power-hungry. I use that same Delay() concept in my own programs. Now, on the family PC, which is a double P4 at 3GHz, the CPU usage goes from 98-100% down to about 12-15%. On my personal computer, however, which is a single P3 at 1GHz, it only goes down to about 90-95%.

So basically, unless your computer is pretty fast, you can expect it to keep running hot. I'm not saying you shouldn't bother with the Delay() method - you should absolutely use it - just don't be surprised if it doesn't seem to help.

A quick word about Delay(), in response to your question:

Im useing delay 1, if i raise the delay will it make the comp run cooler?

Yes and No. As I'm sure you're aware, Delay 1 makes the program wait for one millisecond. Thing is, you won't always want your program to wait for that exact length of time.

Here's the deal: most programs are supposed to run at an optimum framerate of 60 Frames Per Second (FPS.) This means that each frame lasts 16.666666... milliseconds, so about 16. Now, if your program is taking 15 milliseconds to do everything, then Delay 1 will work just fine, because 15 + 1 = 16.

However, on a faster computer, your program might only take 5 milliseconds to do it all, and 5 + 1 = 6, which means the remaining 10 milliseconds will be taken up by Flip(), which brings the CPU back up to 100%.

Even worse is if your program takes LONGER than 16 milliseconds because the computer can't handle it all fast enough, and then ANOTHER millisecond gets ADDED to that; then things get really laggy.

Basically, using Delay() in each loop with a fixed time amount is a bad idea. That's where Yasha's code comes in. That code records the number of milliseconds that the computer took to do everything in the frame. It then makes Delay() take up any spare time, cutting down the CPU usage. I use this same kinda code in my own programs; I call it "CPU breathing code."


Anyway, I hope that helps. Good luck!


_Skully(Posted 2009) [#5]
Well, this is nice to know.. I was wondering why my lap gets so hot when I'm running Blitz code (I have a laptop).. I thought it was just the excitement but perhaps not LOL...

good to know... cheers.


Adam Novagen(Posted 2009) [#6]
I thought it was just the excitement but perhaps not

XD

Yeah, my laptop turns its fan on within about two minutes of Blitz, less if it's 3D. Since my old Lappy is just a PIII at 750MHz, the CPU breathing code doesn't even make a dent in the CPU usage. :P


grindalf(Posted 2009) [#7]
Ok thanks for the help :D


grindalf(Posted 2009) [#8]
I ported your code into my program and it saves me about 20% cpu power :)
do you mind if i keep that code?