I'm new to DBPro but have some coding experience.
I'm making a small scale physics based game (5 levels) as part of a project for college.
For now, I'm using the basic objects that come with DBPro (cubes, spheres, etc).
At load, it creates 1000 cubes and puts them randomly in the map.
Now, I can make all 1000 of them fall with gravity, and it's very smooth - about 120FPS.
As soon as I try to check for them colliding with each other, it goes really slow - about 14FPS.
My code:
// ----------------------------------------------------------------------------------------------------
// Test Project - Main Source File
// ----------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------
// Declarations
// ----------------------------------------------------------------------------------------------------
Global flt_timer as Float = 0.0
Global flt_old_timer as Float = 0.0
Global flt_game_speed as Float = 0.0
Global flt_x as Float = 700.0
Global flt_y as Float = 0.0
Global flt_z as Float = 0.0
Global bol_shift_z as Boolean = 0
Global flt_targ_z as Float = 0.0
Global bol_shift_x as Boolean = 0
Global flt_targ_x as Float = 700.0
Global flt_gravity as Float = 0.0
Global bol_jump_press as Boolean = 0
Global bol_can_jump as Boolean = 0
// ----------------------------------------------------------------------------------------------------
// Game Setup
// ----------------------------------------------------------------------------------------------------
Sync On
Sync Rate 0
AutoCam Off
Global max_objects as DWord = 1000 // Change this variable to increase/decrease number of objects
For int_i = 1 to max_objects
Make Object Cube int_i, 100
Position Object int_i, RND( 10000 ), RND( 1000 ), 0
Next int_i
// ----------------------------------------------------------------------------------------------------
// Main Loop
// ----------------------------------------------------------------------------------------------------
Do
Get_Game_Speed()
Get_Controls()
For int_i = 1 to max_objects
Get_Physics( int_i )
For int_j = 1 to max_objects
Get_Collision( int_i, int_j )
Next int_i
Next int_i
FastSync
Loop
// ----------------------------------------------------------------------------------------------------
// Functions
// ----------------------------------------------------------------------------------------------------
Function Get_Game_Speed()
flt_old_timer = Timer()
flt_game_speed = flt_old_timer - flt_timer
flt_timer = Timer()
Text 32, 32, "FPS: " + STR$( Screen FPS() ) + ", Speed: " + STR$( flt_game_speed )
EndFunction
Function Get_Controls()
If KeyState( 30 ) = 0 and KeyState( 32 ) = 0
bol_shift_x = 0
Endif
If KeyState( 30 ) = 1
If bol_shift_x = 0
bol_shift_x = 0
If flt_targ_x = flt_x
DEC flt_targ_x, 100
Endif
Endif
Endif
If KeyState( 32 ) = 1
If bol_shift_x = 0
bol_shift_x = 0
If flt_targ_x = flt_x
INC flt_targ_x, 100
Endif
Endif
Endif
If flt_x < flt_targ_x
INC flt_x, 10
Endif
If flt_x > flt_targ_X
DEC flt_x, 10
Endif
If KeyState( 17 ) = 0 and KeyState( 31 ) = 0
bol_shift_z = 0
Endif
If KeyState( 17 ) = 1
If bol_shift_z = 0
bol_shift_z = 1
If flt_z = 0 then flt_targ_z = 100
If flt_z = -100 then flt_targ_z = 0
Endif
Endif
If KeyState( 31 ) = 1
If bol_shift_z = 0
bol_shift_z = 1
If flt_z = 0 then flt_targ_z = -100
If flt_z = 100 then flt_targ_z = 0
Endif
Endif
If flt_z < flt_targ_z - flt_game_speed
INC flt_z, flt_game_speed
Endif
If flt_z > flt_targ_z + flt_game_speed
DEC flt_z, flt_game_speed
Endif
If flt_y <= 0
flt_y = 0
flt_gravity = 0
bol_can_jump = 1
Endif
If KeyState( 57 ) = 1
If bol_jump_press = 0
bol_jump_press = 1
If bol_can_jump = 1
flt_gravity = -10
bol_can_jump = 0
Endif
Endif
Else
bol_jump_press = 0
Endif
INC flt_gravity, flt_game_speed / 16
DEC flt_y, flt_gravity
If flt_z > flt_targ_z - flt_game_speed and flt_z < flt_targ_z + flt_game_speed
flt_z = flt_targ_z
Endif
If Object Exist( 9999 ) = 0
Make Object Cube 9999, 100
Else
Position Object 9999, flt_x, flt_y, flt_z
Endif
Position Camera flt_x, flt_y + 250, flt_z - 500
EndFunction
Function Get_Physics( int_i as DWord )
If Object Exist( int_i ) = 1
If Object Position Y( int_i ) > 50
Position Object int_i, Object Position X( int_i ), Object Position Y( int_i ) - 10, Object Position Z( int_i )
Else
Position Object int_i, Object Position X( int_i ), 50, Object Position Z( int_i )
Endif
Endif
EndFunction
Function Get_Collision( int_i as Dword, int_j as DWord )
If Object Exist( int_i ) = 1 and Object Exist( int_j ) = 1 and int_i <> int_j
If Object Position X( int_i ) > Object Position X( int_j ) - 100 and Object Position X( int_i ) < Object Position X( int_j ) + 100
If Object Position Y( int_i ) > Object Position Y( int_j ) - 100 and Object Position Y( int_i ) < Object Position Y( int_j ) + 100
If Object Position Y( int_i ) > Object Position Y( int_j )
Position Object int_i, Object Position X( int_i ), Object Position Y( int_j ) + 100, Object Position Z( int_i )
Endif
Endif
Endif
Endif
EndFunction
My PC is:
OS: Windows 7 Pro 64Bit
Processor: Intel Xeon @ 2.4GHz (2 Processors)
RAM: 16GB
HDD: 1TB
Graphics: Radeon X1550
Runs Portal on max settings at 60FPS
Any help and advice is hugely appreciated.