A fifteenth graphic animation highlighting the interest of the image skipping feature of 'regulateLite()',
with scrolling and above all removing of skipped images
The graphic animation (heavy CPU load) comes from dodicat :
Here.
Some initializations and code lines may have been modified from the author's original in order to better highlight the regulation with
'regulateLite()' and its different configurations of use.
This test code allows to modify:
- the value of the requested FPS (and it visualizes the applied FPS),
- the image skipping activation (false or true),
- and in case of image skipping activated, the mode for skipping images (scrolling or removing).
(the removing skipped images adds only three lines to the user code)
The full status of the image skipping feature is also visualized.
Results
From the requested FPS = 100 (by default), I get on my PC (fbc 32-bit/gas):
- for image skipping activation = false, applied FPS = about 23, CPU load = 4.5 %
- for image skipping activation = true and with scrolling skipped images, applied FPS = about 49, CPU load = 9.9 %
- for image skipping activation = true and with removing skipped images, applied FPS = about 100, CPU load = 3.4 %
(maximum accessible applied FPS in this third configuration: about 500 at limit of N=20)
From requested FPS = 100 (by default), I get on my PC (fbc 64-bit/gcc):
- for image skipping activation = false, applied FPS = about 17, CPU load = 7.0 %
- for image skipping activation = true and with scrolling skipped images, applied FPS = about 24, CPU load = 9.8 %
- for image skipping activation = true and with removing skipped images, applied FPS = about 100, CPU load = 5.5 %
(maximum accessible applied FPS in this third configuration: about 320 at limit of N=20)
Code
Test19:
Code: Select all
'' Graphic animation from dodicat (https://www.freebasic.net/forum/viewtopic.php?p=166803#p166803)
#include "regulateLite.bi" '' defined in https://www.freebasic.net/forum/viewtopic.php?p=299929#p299929
'THE THING
Dim Shared As Integer xres,yres
Screenres 800, 640, 32
Width 800 \ 8, 640 \ 16
Screeninfo xres,yres
Type vector3d
As Single x,y,z
End Type
#define vct type<vector3d>
Dim Shared As vector3d eyepoint
Dim Shared Rx(1 To 3,1 To 3) As Single
Dim Shared Ry(1 To 3,1 To 3) As Single
Dim Shared Rz(1 To 3,1 To 3) As Single
Dim Shared pivot_vector(1 To 3) As Single
Dim Shared new_pos(1 To 3) As Single
Dim Shared temp1(1 To 3) As Single
Dim Shared temp2(1 To 3) As Single
Operator + (Byref v1 As vector3d,Byref v2 As vector3d) As vector3d
Return Type<vector3d>(v1.x+v2.x,v1.y+v2.y,v1.z+v2.z)
End Operator
Operator -(Byref v1 As vector3d,Byref v2 As vector3d) As vector3d
Return Type<vector3d>(v1.x-v2.x,v1.y-v2.y,v1.z-v2.z)
End Operator
Operator * (Byval f As Single,Byref v1 As vector3d) As vector3d
Return Type<vector3d>(f*v1.x,f*v1.y,f*v1.z)
End Operator
Function r(Byval first As Double, Byval last As Double) As Double
Function = Rnd * (last - first) + first
End Function
Function apply_perspective(Byref p As vector3d) As vector3d
Dim As Single w=(p.z*(-1)/300+1)*.75
Return vct((p.x-eyepoint.x)/w+eyepoint.x,(p.y-eyepoint.y)/w+eyepoint.y,(p.z-eyepoint.z)/w+eyepoint.z)
End Function
Function rotatepoint3d(Byref pivot As vector3d,Byref pt As vector3d,Byref angle As vector3d,Byval dilator As Single=1) As vector3d
#macro mv(m1,v,ans)
For i As Integer=1 To 3
s=0
For k As Integer = 1 To 3
s=s+m1(i,k)*v(k)
Next k
ans(i)=s
Next i
#endmacro
#define cr 0.0174532925199433
Dim angle_radians As vector3d=Type<vector3d>(cr*angle.x,cr*angle.y,cr*angle.z)
Dim s As Single=Any
pivot_vector(1)=(pt.x-pivot.x)*dilator
pivot_vector(2)=(pt.y-pivot.y)*dilator
pivot_vector(3)=(pt.z-pivot.z)*dilator
'rotat1on matrices about the three axix
Rx(1,1)=1:Rx(1,2)=0:Rx(1,3)=0
Rx(2,1)=0:Rx(2,2)=Cos(angle_radians.x):Rx(2,3)=-Sin(angle_radians.x)
Rx(3,1)=0:Rx(3,2)=Sin(angle_radians.x):Rx(3,3)=Cos(angle_radians.x)
Ry(1,1)=Cos(angle_radians.y):Ry(1,2)=0:Ry(1,3)=Sin(angle_radians.y)
Ry(2,1)=0:Ry(2,2)=1:Ry(2,3)=0
Ry(3,1)=-Sin(angle_radians.y):Ry(3,2)=0:Ry(3,3)=Cos(angle_radians.y)
Rz(1,1)=Cos(angle_radians.z):Rz(1,2)=-Sin(angle_radians.z):Rz(1,3)=0
Rz(2,1)=Sin(angle_radians.z):Rz(2,2)=Cos(angle_radians.z):Rz(2,3)=0
Rz(3,1)=0:Rz(3,2)=0:Rz(3,3)=1
mv (Rx,pivot_vector,temp1)
mv (Ry,temp1,temp2)
mv (Rz,temp2,new_pos)
new_pos(1)=new_pos(1)+pivot.x
new_pos(2)=new_pos(2)+pivot.y
new_pos(3)=new_pos(3)+pivot.z
Return Type<vector3d>(new_pos(1),new_pos(2),new_pos(3))
End Function
Sub blow(a() As vector3d,Byval mag As Single)
For z As Integer=1 To Ubound(a)
a(z)=mag*a(z)
Next z
End Sub
Sub translate(a() As vector3d,Byref pt As vector3d)
For z As Integer=1 To Ubound(a)
a(z)=a(z)+vct(pt.x,pt.y,pt.z)
Next z
End Sub
Function vertex(Byref piv As vector3d,Byref p1 As vector3d,Byref ang As vector3d,Byval dil As Single,Byref col As Uinteger) As Single
var _temp1=rotatepoint3d(piv,p1,ang,dil)
_temp1=apply_perspective(_temp1)
Circle(_temp1.x,_temp1.y),(20*Abs(dil)+Abs(_temp1.z/2)*1*dil),col,,,,f
Return _temp1.z
End Function
Sub set_perspective(Byval x As Single,byval y As Single,Byval z As Single,Byval minz As Single,Byval maxz As Single)
eyepoint=vct(x,y,z)
End Sub
#macro combsort(array,comp)
Scope
var size=Ubound(array),switch=0,j=0
Dim As Single void=size
Do
void=void/1.3: If void<1 Then void=1
switch=0
For i As Integer =1 To size-void
j=i+void
If comp(i)>comp(j) Then
Swap array(i),array(j): switch=1
Swap comp(i),comp(j)
Swap col(i),col(j)
End If
Next
Loop Until switch =0 And void=1
End Scope
#endmacro
Redim Shared As vector3d e(0)
Dim count As Integer
Redim Shared As Uinteger col(0)
For x As Single=-1 To 1 Step .02
For y As Single=-1 To 1 Step .02
count=count+1
Redim Preserve e(count)
Redim Preserve col(count)
col(count)=Rgb(155*(x+1)/2,155*(y+1)/2,Rnd*155)
e(count)=Type<vector3d>(x,y,(Sin(5*x)+Cos(5*y))/5)
Next y
Next x
blow(e(),800)
translate(e(),vct(xres/2,yres/2,0))
set_perspective(xres/2,yres/2,0,-100,100)
Dim As Single dilation=.2
Dim As vector3d piv,ang
piv=eyepoint
Dim As String i
Dim As Single zeds(Ubound(e)),_mw
Dim As Uinteger colour
Dim As Integer mx,my,mw
Dim As Single startdilation=.17
dilation=startdilation
Dim As Long fps=100,rfps
Dim As Boolean skipping=False,remove=False,skipped
Dim As Long ist,mist
Dim As Ulong averageFps
Dim As Double sumFps
Dim As Long N
Do
ang.y=ang.y+.5
ang.x=ang.x+.5
ang.z=ang.z+.25
If (remove = False) Or (skipped = False) Then
Screenlock
Cls
Getmouse mx,my,mw
_mw=mw/100
combsort(e,zeds)
dilation=startdilation+_mw
For z As Integer=1 To Ubound(e)
zeds(z)=vertex(piv,e(z),ang,dilation,col(z))
Next z
Draw String (16,16),"Requested FPS = " & Right(" " & fps, 3)
Draw String (16,32),"Applied FPS = " & Right(" " & rfps, 3) & " (average = " & Right(" " & averageFps, 3) & ")"
Draw String (16,48),"Status : " & _
iif(skipping = True, "Image skipping activation = true, with " & _
iif(remove = True, "removing images skipped = " & Iif(mist > 0, str(mist) & "/" & str(mist + 1), "0"), _
"scrolling images skipped = " & Iif(mist > 0, str(mist) & "/" & str(mist + 1), "0")), _
"Image skipping activation = false")
Draw String (16,80),"<+> : Increase FPS"
Draw String (16,96),"<-> : Decrease FPS"
Draw String (16,128),"<t> or <T> : True for image skipping activation"
If Skipping = True Then
Draw String (16,144)," <s> or <S> : Scroll image skipped"
Draw String (16,160)," <r> or <R> : Remove image skipped"
Draw String (16,176),"<f> or <F> : False for image skipping activation"
Draw String (16,208),"<escape> : Quit"
Else
Draw String (16,144),"<f> or <F> : False for image skipping activation"
Draw String (16,176),"<escape> : Quit"
End If
Draw String (16,608),"<mouse wheel> : Dilatation/Compression"
Draw String (544,608),"Graphic animation from dodicat"
Screenunlock
End If
rfps = regulateLite(fps,skipping, ,skipped)
If skipped = True Then
ist += 1
Else
mist = ist
ist = 0
End If
sumFps += rfps
N += 1
If N >= rfps / 2 Then
averageFps = sumFps / N
N = 0
sumFps = 0
End If
Dim As String s = Ucase(Inkey)
Select Case s
Case "+"
If fps < 600 Then fps += 1
Case "-"
If fps > 10 Then fps -= 1
Case "T"
skipping = True
Case "F"
skipping = False
Case "S"
If skipping = True Then remove = False
Case "R"
If skipping = True Then remove = True
Case Chr(27)
Exit do
End Select
Loop