Engine 3D speed issues - v5.60 beta

Everything related to 3D programming
Krix
User
User
Posts: 65
Joined: Fri Mar 11, 2005 6:24 pm
Location: Toronto

Engine 3D speed issues - v5.60 beta

Post by Krix »

Hey guys!

This is not the createcube() function issue starting with v5.50 that creates sub meshes so any test scene that uses it will be much slower than pre v5.50...

It seems to me that v5.44 LTS overall is fast, with v5.50/5.51 physics got slower, and v5.60 beta inherited the slower physics and also has slower rendering without any physics.

Could you guys do some stress tests to conform this? Thanks!
Fred
Administrator
Administrator
Posts: 16680
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Engine 3D speed issues - v5.60 beta

Post by Fred »

Can you post some small examples showing this ?
Krix
User
User
Posts: 65
Joined: Fri Mar 11, 2005 6:24 pm
Location: Toronto

Re: Engine 3D speed issues - v5.60 beta

Post by Krix »

Hey Fred,

The createcube() and physics slowdown was discussed in these topics.

http://www.purebasic.fr/english/viewtop ... =4&t=67414
http://www.purebasic.fr/english/viewtop ... 36&t=67632


I modified the ThirdPerson demo. Uses the same resources. Compile it with 5.44 LTS first! Don't turn on the physics yet. If it doesn't tax your system, bump up some values. After you had moved around a bit compile it with 5.60b...and there will be a pretty noticeable speed difference. Then compile it with 5.44 LTS now with physics enabled. Check the speed. And then compile it with 5.60b...and the speed difference will be huge. At least 3x slower...

As I said for whatever reason it seems that the v5.60b renders everything slower. Whatever is 60fps with v5.44LTS on my system is around 40fps with 5.60b. But this is nothing else just pure simple rendering without physics. Physics is at least 3x slower with v5.50, v5.51 and now v5.60b.

And please restore createcube() to a single mesh and make sub-meshes optional.

Code: Select all

;
; ------------------------------------------------------------
;
;   Stress Test v0.1 beta of pre alpha  :D
;
;   PureBasic - Third Person Demo shamelessly modified by Krix
;
;   Every mesh is a sphere except the floor.
;
;   Camera control    W/A/S/D + mouse
;   Fast forward      E
;   WireFrame on/off  Q
;
;   Please check the Tools Panel for where you can enable/disable shadows and physics,
;   change segment and ring numbers of spheres, adjust the number of objects/meshes created.
; ------------------------------------------------------------
 

IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

;- Camera Speed
#CameraSpeed  = 5


Enumeration
  
  #Font
  #HelpSprite
  
EndEnumeration


LoadFont(#Font, "Courier New", 11, #PB_Font_Bold)

Declare TG_UpdateSprite()


Structure Vector3
  x.f
  y.f
  z.f
EndStructure

Structure s_Key
  Up.i
  Down.i
  Left.i
  Right.i
  StrafeLeft.i
  StrafeRight.i
  Jump.i
EndStructure

Structure s_Entity
  Entity.i
  EntityBody.i
  BodyOffsetY.f 
  elapsedTime.f
  Key.s_Key
  MainNode.i  
  SightNode.i
  CameraNode.i  
  ForwardNode.i
  StrafeNode.i
EndStructure



Declare MakeStair(PX.f, PY.f, PZ.f, Length.i, Height.i, Width.i, Stair.i)
Declare AddObjects()
Define.f TimeSinceLastFrame = 0
Define.f KeyX, KeyY, MouseX, MouseY



If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  
  
  If Screen3DRequester()
       
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures"        , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models"          , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts"         , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI"             , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
    Parse3DScripts()
    
    
    
    
;- Enable/Disable Physics and Shadows  
; -----------------------------------
    
  EnableWorldPhysics(0)
  WorldShadows(#PB_Shadow_Modulative)  
  
; -----------------------------------  
    
        
    ;Texture
    CreateTexture(1, 256, 256)
    StartDrawing(TextureOutput(1))
    Box(0, 0, 256, 256, RGB(0, 34, 85))
    DrawingMode(#PB_2DDrawing_Outlined)
    Box(0, 0, 256, 256, RGB(255, 255, 255))
    Box(10, 10, 236, 236, RGB(0, 255, 255))
    StopDrawing()
    
    ;Material
    CreateMaterial(1, TextureID(1))
    MaterialFilteringMode(1, #PB_Material_Trilinear)
    
    CreateMaterial(2, LoadTexture(2, "Dirt.jpg"))
    CreateMaterial(3, LoadTexture(3, "Wood.jpg"))
    GetScriptMaterial(4, "Scene/GroundBlend")
    
         
    
    ;Ground
    CreatePlane(2, 5000, 5000, 200, 200, 100, 100)
    CreateEntity(2, MeshID(2), MaterialID(1), 0, 0, 0)
    CreateEntityBody(2, #PB_Entity_StaticBody)
     
        
    ;- Number of sphere segments and rings 
    ;Add some statics and dynamics objects
    CreateSphere(3,0.5,32,32)
    
    AddObjects()  
    
    ;Add some stairs 
    MakeStair(360, 0, 220, 130, 11, 48, 15)
    
    
    CreateLight(0,RGB(255,255,220),700,500,0, #PB_Light_Directional)
    RotateLight(0,45,45,0) 
    
    AmbientColor(RGB(80,80,90))
    
    
    SkyBox("desert07.jpg")
    
    
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 350, 250, -500)
    RotateCamera(0,10,180,0)
    
    CreateSprite(#HelpSprite, 200, 80)
    
    
    
    
    ;Main loop    

    Repeat
      
      
      Screen3DEvents()
           
       If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
      
        If KeyboardPushed(#PB_Key_A)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_D)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_W)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_E)
          KeyY = -#CameraSpeed*4
        ElseIf KeyboardPushed(#PB_Key_S)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      
        If KeyboardReleased(#PB_Key_Q)
          If RenderMode = 0
            CameraRenderMode(0, #PB_Camera_Wireframe)
            RenderMode = 1
          Else
            CameraRenderMode(0, #PB_Camera_Textured)
            RenderMode = 0
          EndIf
        EndIf
        
        RotateCamera(0, MouseY*2, MouseX*2, 0, #PB_Relative)
        MoveCamera  (0, KeyX, 0, KeyY)

                  
                 
        TimeSinceLastFrame = RenderWorld(50) / 1000
        TG_UpdateSprite() 
        DisplaySprite(#HelpSprite, 0, 0)
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End








Procedure MakeStair(PX.f, PY.f, PZ.f, Length.i, Height.i, Width.i, Stair.i)
  Protected.i a, Ent, Nb
  Protected.f Size, SizeD, Delta, H  

  For a = 1 To Stair
    Ent = CreateEntity(#PB_Any, MeshID(3), MaterialID(2))
    ScaleEntity(Ent, Length*3, Height, Width)
    MoveEntity(Ent, PX, PY + (a-1) * Height, PZ + (a-1) * Width*0.85, #PB_Absolute)
    CreateEntityBody(Ent, #PB_Entity_StaticBody)
  Next a
  
  ;Add a platform
  Ent = CreateEntity(#PB_Any, MeshID(3), MaterialID(2))
  ScaleEntity(Ent, Length*7, Height, Width*5)
  MoveEntity(Ent, PX, 200, PZ + (a-1) * Width, #PB_Absolute)
  RotateEntity(Ent, -10,0,0)
  CreateEntityBody(Ent, #PB_Entity_StaticBody)
  
  ;- Number of Physics Spheres (Pyramid)!
  ;Add Pyramid          
  Nb = 30                
  Delta = 0.01
  Size = 20 
  SizeD = Size + 0.5 
  H = EntityY(Ent) + Height/2 + Delta
  For j = 0 To Nb
    For i= 0 To Nb-j
      Ent = CreateEntity(#PB_Any, MeshID(3), MaterialID(4))
      ScaleEntity(Ent, Size, Size, Size) 
      CreateEntityBody(Ent, #PB_Entity_SphereBody, 0.5)
      MoveEntity(Ent, 52 +  j * (SizeD / 2) + i * SizeD, H + (SizeD / 2) + (j * SizeD), 890, #PB_Absolute)
    Next 
  Next 
EndProcedure


Procedure AddObjects()
  Protected Size.Vector3
  Protected.f x, z
  Protected.i Ent, i  
  
  ;- Number of Surrounding Objects!
 
  For i = 0 To 1000      
    
      Size\x = Random( 60) + 30
      Size\y = Random(160) + 30
      Size\z = Random( 60) + 30     
      
      Repeat
        x = Random(5000)-2500
      Until x < -400 Or x > 400  
      
      Repeat
        z = Random(5000)-2500
      Until z < -400 Or z > 400  
      
      Ent=CreateEntity(#PB_Any, MeshID(3), MaterialID(2), x, Size\y / 2 + Random(90) , z)
      RotateEntity(Ent, 0, Random(360), 0)
      ScaleEntity(Ent, Size\x, Size\y, Size\z)
      CreateEntityBody(Ent, #PB_Entity_StaticBody)   
    
    
  Next 
EndProcedure


Procedure TG_UpdateSprite()
  
  Define.i FPS, Triangles, Batches
  
  FPS       = Engine3DStatus(#PB_Engine3D_CurrentFPS)
  MinFPS    = Engine3DStatus(#PB_Engine3D_MinimumFPS)
  MaxFPS    = Engine3DStatus(#PB_Engine3D_MaximumFPS)
  AveFPS    = Engine3DStatus(#PB_Engine3D_AverageFPS)
  Triangles = Engine3DStatus(#PB_Engine3D_NbRenderedTriangles)
  Batches   = Engine3DStatus(#PB_Engine3D_NbRenderedBatches)
  
  StartDrawing(SpriteOutput(#HelpSprite))
    DrawingMode(#PB_2DDrawing_Default)
    Box(0, 0, SpriteWidth(#HelpSprite), SpriteHeight(#HelpSprite), RGB(20,20,20))
    DrawingFont(FontID(#Font))
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(5,  5, "FPS       : " + Str(FPS), RGB(255,0,0))
    DrawText(5, 15, "Min FPS   : " + Str(MinFPS), RGB(255,255,255))
    DrawText(5, 25, "Max FPS   : " + Str(MaxFPS), RGB(255,255,255))
    DrawText(5, 35, "Ave FPS   : " + Str(AveFPS), RGB(255,255,255))
    DrawText(5, 45, "Triangles : " + Str(Triangles), RGB(0,255,0))
    DrawText(5, 55, "Batches   : " + Str(Batches), RGB(0,128,255))
  StopDrawing()
  EndProcedure

Procedure OnGround(*Entity.s_Entity)
  With *Entity
    ProcedureReturn RayCollide(NodeX(\MainNode),  NodeY(\MainNode)+3, NodeZ(\MainNode), NodeX(\MainNode), NodeY(\MainNode),  NodeZ(\MainNode)) 
  EndWith  
EndProcedure

Procedure IsStair(*Entity.s_Entity)
  Protected.f x, y, z
  With *Entity
    x = (NodeX(\ForwardNode) - NodeX(\MainNode))*30
    y = (NodeY(\ForwardNode) - NodeY(\MainNode))*30
    z = (NodeZ(\ForwardNode) - NodeZ(\MainNode))*30
    ;CreateLine3D(20, NodeX(\MainNode), NodeY(\MainNode)+20, NodeZ(\MainNode), $FFFF, NodeX(\MainNode)+x, NodeY(\MainNode)+y+20,  NodeZ(\MainNode)+z, $FFFF) 
    Ray1 = RayCollide(NodeX(\MainNode), NodeY(\MainNode)+10, NodeZ(\MainNode),  NodeX(\MainNode)+x, NodeY(\MainNode)+y+10,  NodeZ(\MainNode)+z) 
    Ray2 = RayCollide(NodeX(\MainNode), NodeY(\MainNode)+20, NodeZ(\MainNode),  NodeX(\MainNode)+x, NodeY(\MainNode)+y+20,  NodeZ(\MainNode)+z) 
    If Ray1>-1 And Ray2=-1
      ProcedureReturn 1
    EndIf
    ProcedureReturn 0
  EndWith  
EndProcedure
Last edited by Krix on Sun Mar 12, 2017 1:47 am, edited 1 time in total.
Fred
Administrator
Administrator
Posts: 16680
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Engine 3D speed issues - v5.60 beta

Post by Fred »

In beta 4, CreateCube() should be single mesh again
Post Reply