Render Tweening - A must for 3d / A few Questions

Blitz3D Forums/Blitz3D Programming/Render Tweening - A must for 3d / A few Questions

Imperium(Posted 2017) [#1]
The code below I have slightly modified from another authors code. Please look it over and see if my comments make sense. Does anyone have an example of multi-threading? Would breaking up the logic and video renderer into separate threads be more efficient than render tweening? What about combining render tweening and multi-threading?

Local renderTime = Floor(1000.0 / 60), updateTime# = 1000.0 / 30 ;30 standard  / 50 high performance = HIGHER IS SMOOTHER BUT FASTER
Local cTime = MilliSecs(), accum#

;Global RenderTween# = 1.0 ;MOVED TO GLOBAL_CODE

If CRT_Display = 1 Then
;( USE THIS ONE For CAPPING FPS TO THE MONITOR REFRESH RATE 85 HTZ ON NEC CRT ) BEST
;This one also limits TV/LCD/PLASMA screen to 30fps regardless of Vsync or Refresh Rate Setting??? Does not affect actual LCD Monitors as such.
	DoVsync = True
	LimiterOn = False
End If

If LCD_Display = 1 Then
	;Original Setting - Most Compatible
	DoVsync = False
	LimiterOn = True 
End If

If Uncapped_Mode = 1 Then
	;For benchmarking or last dtich attempt for good performance on some systems.
	;On very past machines should max out at 850 fps.
	DoVsync = False
	LimiterOn = False 
End If



;Local DoVsync = False, LimiterOn = True 	   ;( THIS IS THE ORIGINAL ROUTINE - CHANGE BACK To LIMIT FPS To 60 FRAMES ) MOST COMPATIBLE
;Local DoVsync = False, LimiterOn = False      ;( STAYS MOSTLY ABOVE 100 FPS FOR ME ) EXPERIMENTAL - CAN OVERHEAT CARD???

;----------------------------------------------------------------------------------------------------------------------------------------------

While Not KeyDown(1)							;Outermost main loop - rendering and all secondary functions
	accum = accum + (MilliSecs() - cTime)		;Accumulator for update loop
	cTime = MilliSecs()							;Official start of loop
	
	;Update loop (for render tweening) - all movement, input and update happens within this one.
	While accum >= updateTime
		;! CAPTURE STUFF
		CaptureWorld
		
		;! UPDATE STUFF (e.g. input)
		;KEYBOARD - RENAME THIS KEYS

	
		
		
		;! VARIOUS OTHER UPDATE FUNCTIONS
		UpdateWorld		;!If necessary
		accum = accum - updateTime
	Wend
	RenderTween = accum / updateTime
	
	;! SETUP DRAW STUFF
	AmbientLight red#,green#,blue# ;UPDATE THE SETTINGS AND TAKE EFFECT
	;! DRAW STUFF
	;Render World camera view - was this a command or simply a note??????
	RenderWorld RenderTween
	
	;! DRAW OTHER STUFF (e.g. 2D)
	Mousecursor() ;Draws the AIMER in lines on screen.

If LimiterOn Then Delay (renderTime - (MilliSecs() - cTime)) - 1;What does this one do? The timer here frees the spare CPU time.
	If DoVsync Then VWait     ;If Vertical Sync is on then Vwait
	Flip False                ;Flip False 
Wend
End
; MAIN GAME LOOP END
;/////////////////////////////////////////////////////////////////////////////////


At the bottom on the code I am not sure what the -1 actually does?
If LimiterOn Then Delay (renderTime - (MilliSecs() - cTime)) - 1


Dan(Posted 2017) [#2]
The -1 probably lowers the computed number by 1. maybe to reach 0 instead of 1, if there is no need for delay - when the machine is slow ?


Imperium(Posted 2017) [#3]
Commenting it out as it appeared within an older project of mine doesn't appear to affect performance. Maybe I should test this on a slower machine?


RemiD(Posted 2017) [#4]
An alternative to achieve what you want (same turn speed move speed animation speed on all computers whatever the FPS) : http://www.blitzbasic.com/codearcs/codearcs.php?code=2916


Imperium(Posted 2017) [#5]
That will come in very useful when I start doing animations. But with my current routine things shouldn't get screwy unless the frame drop below 30. Blitz3d according to my tests preforms quite well on everything made within the last decade, even intel cards if you keep the resolution low.

I'd really love to see a multi-threaded example. I have a library made from Pure Basic that works with Blitz but do not understand enough to use it considering it is undocumented.