after 7 years I'm coming back for my planned 3D-Game. Back then hope left me, because FPS were too low. I want to give it another try, perhaps someone else in this forum had a similar problem.
So, my main problem is low fps. I want to use physics, too. The code below is one of my testing codes.
I´ve done a few tests, but the results are not very promising.
These are my default settings:
Size of static geometry (SG): 10
camera Range: 1000
Cast Shadows: No
Number of Cubes: 15000
And these are results on my Laptop:
Entities without SG: ~20 FPS
Entities in SG: ~43 FPS
Entities in SG, but Entities are deleted afterwards: 60 FPS
Using Static geometries is a no-brainer, but by using static geometry, there is no physics body (At least back then). What's astonishing for me: If the entities (They are not rendered(!), because they're hidden) are deleted, FPS go up to maximum possible FPS (60 Hz panel). Bad thing ist, I also want to pick single entities (picking up stones, selecting buildings etc.), so in my opinion, I need these entities.
My questions are:
1. Why are FPS higher when deleting non-rendered (hidden) entities?
2. Is there a way to pick single objects/entities although using static geometries, deleting used entities AND getting physic boxes?
Kind regards
Bananenfreak
Code: Select all
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>> >>
;>> Name: FPS-Test >>
;>> >>
;>> Author: Bananenfreak >>
;>> >>
;>> Date: 06.01.2021 >>
;>> >>
;>> OS: Windows >>
;>> >>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;Fly around with arrow keys. Press Esc to quit.
EnableExplicit
Define.f KeyX, KeyY, MouseX, MouseY, x, z
Define nx.f, nz.f, Boost.f = 0.2, Yaw.f, Pitch.f, zaehler
Define.i Quit, ground, t, i, mesh, ent, sg
Define.b firster = #True
#kam_0 = 0
#window = 0
#plane = 0
#planent = 0
;-variables for Testing:
; Static geometry
Define.i sgWL = 10 ;Width and Length of static geometry
;Camera
Define.i camR = 1000 ;Camera range
;Entity
Define.b castSh = #False ;Cast Shadows
Define.b delEnt = #False ;Delete Entity
Define.b AddToSG = #True ;Add Ents to Static Geometry
Define.i num = 15000 ;Amount of Cubes
If InitEngine3D();#PB_Engine3D_EnableCG)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(#window, 0, 0, 1800, 1000, "FPS-Test", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#window), 10, 10, 1780, 980, 1, 10, 10, #PB_Screen_SmartSynchronization)
CreateLight(#PB_Any, RGB(255, 255, 255), 0, 30, 0, #PB_Light_Point)
If castSh
WorldShadows(#PB_Shadow_TextureAdditive, 200, RGB(255 , 255, 255), 4096)
EndIf
AmbientColor(RGB(255 * 0.2, 255 * 0.2, 255 * 0.2))
CreatePlane(#plane, 200, 200, 200, 200, 200, 200)
ground = GetScriptMaterial(#PB_Any, "Scene/GroundBlend")
CreateEntity(#planent, MeshID(#plane), MaterialID(ground), 100, -0.5, 100)
EntityRenderMode(#planent, 0) ;- Damit Schatten dargestellt werden
;-Testobject
mesh = CreateCube(#PB_Any, 1)
;-Camera
CreateCamera(#kam_0, 0, 0, 100, 100)
MoveCamera(#kam_0, -50, 50, -50, #PB_Absolute)
CameraLookAt(#kam_0, 100, 0, 100)
CameraBackColor(#kam_0, RGB(255 , 255, 255))
CameraRange(#kam_0, 0, camR)
sg = CreateStaticGeometry(#PB_Any, sgWL, 100, sgWL, 1)
Debug "StaticGeometry: " + sg
For i=0 To num-1
If i >= zaehler * 100 + 100
zaehler = zaehler + 1
Debug "Cubes created: " + Str(zaehler * 100)
EndIf
x = Random(20000, 0)/100
z = Random(20000, 0)/100
ent = CreateEntity(#PB_Any, MeshID(mesh), MaterialID(ground), x, 0, z)
If castSh
EntityRenderMode(ent, #PB_Entity_CastShadow)
Else
EntityRenderMode(ent, #PB_Shadow_None)
EndIf
If AddToSG
AddStaticGeometryEntity(sg, EntityID(ent), EntityX(ent), EntityY(ent), EntityZ(ent))
HideEntity(ent, 1)
EndIf
If delEnt
FreeEntity(ent)
EndIf
Next i
Debug "Alles hinzugefügt"
BuildStaticGeometry(sg)
Debug "SG built!"
Repeat
Debug "--------------------------------------------"
Debug "Tris: " + Engine3DStatus(#PB_Engine3D_NbRenderedTriangles)
Debug "Batches: " + Engine3DStatus(#PB_Engine3D_NbRenderedBatches)
Debug "FPS: " + Engine3DStatus(#PB_Engine3D_CurrentFPS)
Debug "Min FPS: " + Engine3DStatus(#PB_Engine3D_MinimumFPS)
Repeat
Until WindowEvent() = 0
If ExamineMouse()
Yaw = -MouseDeltaX() * 0.05
Pitch = -MouseDeltaY() * 0.05
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
MoveCamera(#kam_0, 0, 0, -1 * Boost *t)
ElseIf KeyboardPushed(#PB_Key_Down)
MoveCamera(#kam_0, 0, 0, 1 * Boost *t)
EndIf
If KeyboardPushed(#PB_Key_Left)
MoveCamera(#kam_0, -1 * Boost *t, 0, 0)
ElseIf KeyboardPushed(#PB_Key_Right)
MoveCamera(#kam_0, 1 * Boost *t, 0, 0)
EndIf
EndIf
RotateCamera(#kam_0, Pitch*t/15, Yaw*t/15, 0, #PB_Relative)
t = RenderWorld(t)
If Not firster
firster = #True
Engine3DStatus(#PB_Engine3D_ResetFPS)
EndIf
Debug "Renderzeit: " + t
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End