Type Slowing Game Down
Blitz3D Forums/Blitz3D Programming/Type Slowing Game Down
| ||
| My game speeds having been slowing down dramatically due to the creation of a large type. I go from 340 fps to 15 fps because I do this before the main while loop. Help much appreciated!
Type unit
Field playerNum
Field team
Field ID
Field x#,y#,z#
Field mesh
Field colorR,colorG,colorB
Field ISselected;;if ISselected, sprite is created
Field ISmoving;;
Field selectID;;number given to unit when selected, if 10 units are selected selectID will be 1,2,3,4,5,6,7,8,9,10
Field starthealth#;;used to properly position health bar, when unit is hit, health bar shrinks and moves to the left
Field health#;;currenthealth
Field speed#
;;sprite
Field selectsprite;;the select sprite unit uses when its selected
Field selectspritetexture
Field healthsprite;;sprite displays the units health
;;weapon
Field weapon;;weapon graphic
Field weaponrange#
Field weapondamage#
Field weaponalpha#
Field weaponrate;;how frequently weapon is fired in millisecs
Field weaponlast;;last time(gametime) weapon was fired
;;pivot
Field pivot;;wherever the pivot is the unit goes
Field pivotx#,pivoty#,pivotz#
;;;;AI fields
Field AI;;0 - player controlled, 1 - find and destroy the nearest enemy
End Type
For i = 0 to 300
aunit.unit = new unit
Next
|
| ||
| Just to make sure: you are *only* using this code before the loop, you don't fill in the fields or loop through this type, right ? |
| ||
| Yeah, the speed doesn't decrease progressively, it gets down to 15 fps and stays there. I just found a post about types being slow, I believe the alternative might be to use banks?!?! Although I'm not sure. |
| ||
| i dont any reason why having 300 of those type should slow it down. I wouldnt expect any issues until it came to drawing them. |
| ||
thats odd... I get over 1000 fps when I use the following code...Type unit
Field playerNum
Field team
Field ID
Field x#,y#,z#
Field mesh
Field colorR,colorG,colorB
Field ISselected;;if ISselected, sprite is created
Field ISmoving;;
Field selectID;;number given to unit when selected, if 10 units are selected selectID will be 1,2,3,4,5,6,7,8,9,10
Field starthealth#;;used to properly position health bar, when unit is hit, health bar shrinks and moves to the left
Field health#;;currenthealth
Field speed#
;;sprite
Field selectsprite;;the select sprite unit uses when its selected
Field selectspritetexture
Field healthsprite;;sprite displays the units health
;;weapon
Field weapon;;weapon graphic
Field weaponrange#
Field weapondamage#
Field weaponalpha#
Field weaponrate;;how frequently weapon is fired in millisecs
Field weaponlast;;last time(gametime) weapon was fired
;;pivot
Field pivot;;wherever the pivot is the unit goes
Field pivotx#,pivoty#,pivotz#
;;;;AI fields
Field AI;;0 - player controlled, 1 - find and destroy the nearest enemy
End Type
For i = 0 To 300
aunit.unit = New unit
Next
Graphics 640,480,0,2
SetBuffer BackBuffer()
While Not KeyDown(1)
Cls
dif = MilliSecs()-tim
If dif >0 Then Text 1,1,1000/dif
tim = MilliSecs()
Flip False
Wendis that what you mean? |
| ||
| Oh man do I feel stupid, I figured out what the problem was, I accidentally assigned a game timer to each unit, so every unit was keeping track of how long the game had lasted |
| ||
| Glad it's nothing serious then. :) |