Program Runs Real Slow

Blitz3D Forums/Blitz3D Beginners Area/Program Runs Real Slow

YellBellzDotCom(Posted 2006) [#1]
Hello,

I have this program just really for loading models. The first time I launch it in fullscreen it works great. I press escape and it closes and goes back to the IDE. IF I launch again, the model shows up, un-animating this time, there is no text on the screen. If I wait for a minute or 2 the text will show up. The program runs real slow the second time around. Like some dx devices didnt get released the first time after closing the program? A major memory leak? or just bad code?

Oh yeah, the program runs fine in window mode. It never happens in window mode.

Any help would be greatly appreciated!

Global ScreenW = 1280
Global ScreenH = 960


Graphics3D ScreenW,ScreenH,32,0
SetBuffer BackBuffer()
AmbientLight 120,120,90

;-------------FPS Stuff--------------------
WireFrame 0
AntiAlias 0
SeedRnd MilliSecs()
Global frame_count%
Global fps%
Global slowest_fps%
Global fps_timeout%
Global frame_time%
Global slowest_frame%
Global frame_start%
fps_timer = CreateTimer(60) ; Lock to 60FPS.
slowmo% = False
wiref% = False
;--------------end FPS Stuff----------------

;--------------KeyPress Stuff---------------
Include "C:\Program Files\Blitz3D\MyProjects\KeyPress\KeyPress.bb"
;--------------End KeyPress Stuff-----------

Global mesh_3ds=LoadAnimMesh( "C:\The Docs\3d Modeling and Games\My Stuff\Models\Human Male\Male B\688 Poly\Animations\MaleWalk_Forward2.b3d" )	;anim seq 0	
;RotateEntity mesh_3ds,0,180,0 
PositionEntity mesh_3ds,-15,-15,0

Global mesh_Shirt1=LoadAnimMesh( "C:\The Docs\3d Modeling and Games\My Stuff\Models\Human Male\Male B\688 Poly\Clothing\Shirt.b3d" )	;anim seq 0
;RotateEntity mesh_Shirt1,0,180,0 
PositionEntity mesh_Shirt1,-15,-15,0


pivot=CreatePivot()
Global cam=CreateCamera( pivot )
PositionEntity cam,0,234,-300
PointEntity cam, mesh_3ds

lit=CreateLight()
RotateEntity lit,45,45,0

DressAnimMesh(mesh_3ds,mesh_shirt1)

Animate mesh_3ds,1

trans=10

;----------------------------------------------------------------------------------------------------------------Main Loop
While Not KeyHit(1)

	;-------------FPS Stuff--------------------
	frame_start = MilliSecs()
	; Press ENTER to toggle slow motion.
	If KeyHit(28) Then slowmo = Not slowmo
	; Press BACKSPACE To toggle WireFrame.
	If KeyHit(14) Then wiref = Not wiref : WireFrame wiref
	;--------------end FPS Stuff----------------
	

	If KeyHit(57)
		If trans > 0 trans=10-1
		If trans = 0 trans = 10
	EndIf

	If KeyDown(27)
		If AnimSeq(mesh_3ds)=0 Animate mesh_3ds,1,.5,1,trans
	Else
		If AnimSeq(mesh_3ds)=1 Animate mesh_3ds,2,1,0,trans
	EndIf
	
	If KeyDown(30) 
		MoveEntity cam,0,0,10
	EndIf
	If KeyDown(44) 
		MoveEntity cam,0,0,-10
	EndIf
	If KeyDown(203) 
		TurnEntity pivot,0,3,0
	EndIf
	If KeyDown(205) 
		TurnEntity pivot,0,-3,0
	EndIf
	
	GetKeyName()
	


	
	UpdateWorld
	RenderWorld
	
	;-------------FPS Stuff--------------------
	frame_time = MilliSecs() - frame_start	
	show_info()
	WaitTimer(fps_timer)
	;Flip True
	Flip
	;Flip False ;Does not run Vsync, shows full FPS
	;VWait : Flip False
	
	If slowmo Then Delay 200
	;--------------end FPS Stuff----------------
	
Wend

End
;----------------------------------------------------------------------------------------------------------------End Main Loop

;----------------------------------------------------------------------------------------------------------------show_info Func
Function show_info()
	If fps_timeout
		frame_count = frame_count + 1
		If MilliSecs() > fps_timeout Then
			fps_timeout = MilliSecs() + 1000 
			fps = frame_count 
			frame_count = 0 
			If fps < slowest_fps Or slowest_fps = 0 Then slowest_fps = fps
		
		EndIf 
		
		If frame_time > slowest_frame Then slowest_frame = frame_time
		
		
		Color 0,255,0
		Text 10,10," Triangles: " + TrisRendered()
		Color 255,255,0
		Text 10,25," Millisecs: " + frame_time
		Text 10,40,"   Slowest: " + slowest_frame
		Color 0,255,255
		Text 10,55,"       FPS: " + fps
		Text 10,70,"     Worst: " + slowest_fps
		Color 255,255,255

		Text 10,85,"Anim len: "+AnimLength( mesh_3ds )
		Text 10,100,"Anim time:"+AnimTime( mesh_3ds )
		Text 10,115,"Transition time="+trans
		Text 10,130,"KeyName = "+KeyName$
		
		Text 10,145,"Entity Coords = "+EntityX(cam,True)+", "+EntityY(cam,True)+", "+EntityZ(cam,True)
	Else
		; First call initialization.
		fps_timeout = MilliSecs() + 1000 
	EndIf
End Function
;----------------------------------------------------------------------------------------------------------------End show_Info Func



semar(Posted 2006) [#2]
Hi Xyle.

Just a couple of suggestions:

1) in the main loop, use "While not KeyDown(1)" instead of "While not KeyHit(1)"

2) put an "EndGraphics" command just before the "End" command

3) give to the user some option for the full-screen mode with more standard resolutions, like 640X480, 800X600, 1024X768, because not all the graphics cards are capable of the resolution you set (1280X960).

Hope it helps,
Sergio.


Ross C(Posted 2006) [#3]
The TEXT command can have a big hit on performance. Try taking it out and see the difference in frame rate.


Bobysait(Posted 2006) [#4]
maybe the processus was not killed when you second tryed...

In any way, there are things in your code that can't let it goes on...
=> U use a frame limiter, and the vertical Sync ...
=> U use 5 or 6 times the "millisecs() " command ...
Don't know if every body knows it, but it is a very slow command on computers that have not been restarted since weeks !
+> Use a local variable like Lt%=Millisecs() after your fisrt instruction of the main loop, then use lt instead of Millisecs() !

You can see an other thing => using millisecs() is not a logical solution. You try to get the time of ONE loop, and, during the loop, the millisecs() command will grow up . So at first use of it, it will be lower than at the last call of the command. So your variables may be wrong.
So, why don't you use Time Based Movement ? It 's maybe better than frame limiting no ?

And if you want be sure everything is cleared
=> simply use 'ClearWorld 1,1,1' before ending program . And if you use big aray , don't forget "freeing" them ( I don't know if we can say "freeing" => i'm French ;) )


Damien Sturdy(Posted 2006) [#5]
the millisecs() command would not be slow enough to cause problems using 5 or 6 times.

This sound's like a driver issue :) WHat card do you have?


Bobysait(Posted 2006) [#6]
I use this command one time by program. If i don't ( i never power off my Pc it has not been restarted since... pfiouuuu long long time ago ! ) my fps fall like a stone.

But you can beleive it or not. I say what I know, but I don't expect you to beleive it or not...


YellBellzDotCom(Posted 2006) [#7]
I apologize for not getting back, I commenced in a 6 hour session of attempting code (laugh), and the problem didnt repeat itself. I was able to do some coding, run the program, do some coding, run the program, all night long without the program slowing down like before. I will still try out the suggestions just to try and improve the code. I appreciate the help. Thanks.

By the way I have an Nvidia 5500. Thanks.


Damien Sturdy(Posted 2006) [#8]
I'm going to guess your millisecs() has wrapped down to the negatives, and your logic might be wrong.

I ran a server for quite a few months and developed the racer on the same machine, using millisecs() probrably hundreds of times in the loop and functions.

Millisecs() is not where your problem lies :)


Dodgy drivers and various other things can make a system slow.

If you want to check Millisecs() however, for it to be causing a big slowdown, each millisecs() call must take above 1ms of time. So, run the program and write it out to a file three times in a row like this:

FS=Writefile("TEST.TXT")
Writeline fs,str$(millisecs())
Writeline fs,str$(millisecs())
Writeline fs,str$(millisecs())
Writeline fs,str$(millisecs())
Writeline fs,str$(millisecs())
closefile fs
execfile"test.txt")
end


if millisecs is the prob, each line in that file will come out a different value, whereas it should just change once, if any, normally.


Bobysait(Posted 2006) [#9]
using value returned by millisecs() slow down ! not calling the command.

You can call it how many times you want, it won't appear anything.
But, operating variables with it, and you 'll mention lot of problems !
;	<! LOOP ===================================
	Repeat
		; <! Time based Movement ===========
			mt%=
			dt#=float(MilliSecs()-LT)
			lt%=millisecs()
		; ==========/! Time based Movement >
	Forever
;	 ===================================/! LOOP>

Use this code for a fps view , and turn the camera using dt => you'll have real problems !


now, an other version
;	<! LOOP ===================================
	st%		=	MilliSecs()
	lt%		=	0
	Repeat
		; <! Time based Movement ===========
			mt%		=	MilliSecs()
			rdt%	=	mt-(lt+st)
			dt#		=	Float(rdt)
			If rdt<2	rdt=2
			If rdt>60	rdt=60
			lt		=	lt+dt
		; ==========/! Time based Movement >
	Forever
;	 ===================================/! LOOP>

Like this, you'll have a smooth variation when turning camera.
Here, you can notice, that the millisecs() command return too big value, and there is not enough precision to allow to calculate dt with precision !
else, the command is just calling the time system, so we can't say the command is slow. i repeat, it's the use of the value returned that can really slow down !

And that' s a know issue from Blitz3D ( and maybe from general system ) that bigger is the value the less is the precision !


Damien Sturdy(Posted 2006) [#10]
AH I see what you mean :) I thought you meant that Millisecs() itself was a slow command hehe.


Inaccuracies will slip in when the PC has been turned on for long periods of time :)


jfk EO-11110(Posted 2006) [#11]
I have seen a slowdown when there are some task hanging around in the nirvana, maybe from crashed apps. Reboot your machine and see if it is fixed.

Also check your autorun tasks, if there are any malware suckers.

Also try to remark your show_info() function, so it isn't called. As it was already suggested, 2D text can be slow on some graphics cards.

I have also seem strange jittering motion with Zonealarm on a machine that was connected directly to the web (no router), so whenever a hacker or script-kid tried to connect eg. to my Netbios port (several thousand times a day), there was a millisecond or so pause. Since this even affected delta-corrected motion, I came to the conclusion that Zonealarm may PAUSE the millisecs counter.

In rare occasions it may also be a 3D model. Try to use an other model instead and see if it helps.