blitz3d is CPU killing :S

Blitz3D Forums/Blitz3D Beginners Area/blitz3d is CPU killing :S

GC-Martijn(Posted 2004) [#1]
H!,

Why does Blitz3D using 100% CPU ?

For example this code
----------------------
Graphics 350,200,32,2
While Not KeyHit(1)
Wend


I know that this is cool for big games.
But i'm making a desktop tool and I don't want that blitz uses 100% so you can't work with other programs (or slower)

Is this the only way:
[code]
Graphics 350,200,32,2
While Not KeyHit(1)
delay 20
Wend
[code]

Thanks


_PJ_(Posted 2004) [#2]
I think that's only due to the debugger running. Have you tried this with a compiled .exe???


Beaker(Posted 2004) [#3]
Delay is the only way. And it works fine. You probably don't need to Delay for so long tho, even Delay 1 will make a difference.


GC-Martijn(Posted 2004) [#4]
Ow k MasterBreak.

I place Delay 1 and it works oke.

I'm wondering if using 100% for is better then using delay 1

Thanks.


Warren(Posted 2004) [#5]
Weird, I find that anything less than "delay 8" doesn't give up the processor reliably. I go with "delay 10" myself.


Bouncer(Posted 2004) [#6]
You really shouldn't do any hardcoded delays... as on slower machine your game might need 100% to run correctly. Best way is to adjust the delay so that your game runs with same speed always... and delays rest of the time, leaving resources free for another programs.

So use this kind of dynamic frame limiting...
http://www.blitzbasic.com/codearcs/codearcs.php?code=749


Kanati(Posted 2004) [#7]
And while it may work... Best tool for the job doesn't usually include B3D when talking about apps. :)

Kanati


Warren(Posted 2004) [#8]
We're talking about giving up less than 10 milliseconds a frame. I really don't think it's a major concern.


Hansie(Posted 2004) [#9]
For Applications I highly recommend BlitzPlus. Blitz3D is for games only - well in my opinion


Ice9(Posted 2004) [#10]
Delay 10 causes stutter on my game running on delta time
Delay 1 runs OK maybe a stutter here and there.
No Delay runs smooth
on all it runs

Delay 10 drops fps to 76fps
Delay 1 drops it to 259fps
No Delay is a whopping 480fps

On RareEarth
http://www.blitzbasic.com/gallery/view_pic.php?id=196&gallery=&page=3

If your progam is a tool then a delay may stop crashes
If it's a full 3D game then I would say let it hog the
processor.

It seems using Delay at all, even to limit frame rate kills the processor time for your game. I might suggest
writing your own delay routine since it seems Delay is
doing some other things than just waiting in a loop.


Bouncer(Posted 2004) [#11]
Epicboy: If game runnning at 50fps... 10 millisec is half of the frametime... so it IS a major concern.


Warren(Posted 2004) [#12]
So you have to decide - are you going to take 100% of the CPU or are you going to be a good Windows citizen?

The trade offs are personal and no one solution is right for everyone.

*shrug*


WolRon(Posted 2004) [#13]
This is why Mark created BlitzPLUS. It's an application creation tool. Blitz3D wasn't designed to share the processor.


GC-Martijn(Posted 2004) [#14]
Ow k ,
I read all the idea's and comments.
And I think that I must buy BlitzPlus.

And I try this script:
http://www.blitzbasic.com/codearcs/codearcs.php?code=749

Thanks for all the info


mearrin69(Posted 2004) [#15]
Well, for 3D level/effect/etc. editors you'd probably want to have 3D which B+ doesn't have without jumping through some hoops. Also, for 3D windowed puzzle or simple games, I'd rather not have my laptop throw a gasket. For these things, using a delay makes sense to *me* at least.

A full-screen FPS, on the other hand? I guess delta time with no delay makes the best sense.

No need to make this into a religious debate though - whatever works for you is what you should do.
M


Zethrax(Posted 2004) [#16]
Also check out http://www.purebasic.com/ for developing apps. It's probably a better choice than BlitzPlus at the moment.

For a Blitz3D map editor I'm working on, I use the system below to get CPU utilization down to below 0.5% when the program is idle.


; Example psuedocode.
---------------------------

Global do_update


Function check_for_control_input()

; If control input detected.
do_update = True

End Function


; Main program loop code.
If do_update

do_update = False

; Do UpdateWorld, RenderWorld, draw 2d graphics, do scheduled pick operations, etc.

Delay ( 1 )

Else

Delay ( 20 )

EndIf


Klaas(Posted 2004) [#17]
why not use a timer ?

Graphics 350,200,32,2

timer = CreateTimer(20) ;20 hz timer
While Not KeyHit(1)
	WaitTimer(timer)
Wend



sswift(Posted 2004) [#18]
I have a better suggestion...

Do what I do.

PS:
Hasfocus() is a function available in the code archives.


This code allows you to specify a maximum framerate at which your game runs, and any extra time at the end of each frame is returned to windows. Since your screen can only flip between 60 to 85 times a second depending on your frefresh rate, you can set this value to 80 and still get back time. Also note that even a delay of 0 gives windows focus for a little while as far as I know.

This code also handles alt tabbing out of the app greacefully, and switching to another app normally when in windowed mode. It detects if the app has focus, and if not, it runs in a loop with a delay(100) waiting for focus to return. It then resets the timers so that the game is none the wiser that it has been paused.

This code also allows one o slow down time merely by dividing the Time_Delta_Sec# value by some amount. Of course, this presumes that you use the Time_Delta_Sec value to adjust the movements of all your objects my specifying their movement in meters per second and multiplkying that value by the time passed in a particular frame to move them.

The only drawbacks of this method vs frame interpolation is that it can make physics a little more unstable and it makes recording and playing back demos impossible. But that's a small price to pay for the incredible simplicity of it compared to frame interpolation methods.


Const MAX_FPS = 60

Min_Frame_Time  = Floor(1000.0/Float(MAX_FPS))
Current_Time	= MilliSecs()
Game_Start_Time = Current_Time
	
Repeat
		
	Time_Old		= Current_Time									; Store the time the last frame began.							
	Current_Time 	= MilliSecs()									; Store the time at the start of this frame.
	Time_Delta 		= Current_Time - Time_Old						; Calculate how long the last frame took.
	Time_Delta_Sec# = Float(Time_Delta)/1000.0

	UpdateWorld														; Handle collisions.
	RenderWorld														; Render the current 3D view to the back buffer.
	Flip True														; Swap the back buffer with the front buffer.
				
	Time_Passed = MilliSecs() - Time_Old							; Calculate how long this frame took to render including the flip.
	Time_Left   = Min_Frame_Time-Time_Passed						; Calculate the amount of additional time we should wait to stay below MAX_FPS.
	Delay(Time_Left)												; Delay for that amount of time.
		
	If Not HasFocus()												; If the game lost focus...
	
		Repeat														; Pause the game until focus has been regained.
			Delay(100) 												; Using delay dramatically reduces the amount of CPU power the game uses!
		Until HasFocus()	
	
		Current_Time = MilliSecs()									; Correct the time.  
			
	EndIf
				
Until Quit_Game