Giving CPU power other processes

BlitzMax Forums/BlitzMax Programming/Giving CPU power other processes

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi, do you have any ideas how I can stop some BMax code (non-GUI) like the code below from hogging 50% (viewed in task manager) of the CPU time on my Hyperthreading PC? (assume it would be 100% on non-dual core/hyperthread CPUs)

I know it takes up max CPU power because I'm just looping and drawing so background tasks probably don't get a chance to process, but how could I allow that? In fact the problem would seem to be with Flip 1 as while it's doing VWait it would be nice if it let other processes get in there (as there must be a lot of idle time there), or maybe just let them get in there just generally, say when the loop is going on.

I know I could stick in Delay(1) but that's a bit lame as it reduces the amount of CPU time given to the game if the game really needs it in a busy period, and this only drops it to 40%ish in task manager.

I don't want to make a MaxGUI-based game.

I could not draw every frame if nothing has changed (but then if the window is moved, or another window is moved over it, it won't "repaint" unless I tell it to specifically) except that most games have moving things all the time. I could only do logic if the user inputs something (mouse or keys) but then games have other stuff that need to be checked/processed all the time like moving aliens, animations, time limits, menu mouse overs etc so that doesn't seem feasible.

However, if I could reduce the CPU load, I'm sure that Windows would live in harmony with the game more and then the delta time (in my framework) wouldn't find it self having to catch up so much with big chunks of stolen CPU time from desperate processes instead of just lots of little bits of shared CPU time.

Anyway here's some test code.

Strict
Graphics 800,600,0

While Not KeyHit(Key_ESCAPE)
	Local n = 0 
	For Local i = 1 To 10000
		n:+1
	Next
	Cls
	DrawRect 100,100,200,200
	Flip 1
Wend


I hope what I've written makes sense, anyone got any feedback? Many thanks in advance.