I'm working on creating a thruster system for my space game with sprites. So far, it looks very pretty and I can run the thing at a good 60 FPS with my ship and a bot or two. However, when I add another AI bot, lag occurs heavily. Is there something i'm doing wrong with my thruster system?
Sorry if the code is a bit messy. I originally have it in a function and I pulled the types out from earlier in the program so that you can see what each field is.
;MY TYPES: ;;;;;;;;;;; Type EFFECT Field kind,active,parent Field startscale#,endscale#,scalemodpercycle# Field startalpha#,endalpha#,alphamodpercycle# Field randompositioning,randomoffset# Field entitytocopy Field parentship.SHIP End Type Type SHIP Field ship,x#,y#,z#,xv#,yv#,zv#,throttle#,shipmaxspd# Field camera,camtrailpiv,cymod#,czmod#,tx#,ty#,tz# Field thrusterpiv[2] Field ai,aiVars.AIVARCOLLECTION End Type Type THRUSTER Field flame,parent.EFFECT Field scale#,alpha# End Type ;;;;;;;;;;;;;;;;;;;;;; Local PX#,PY#,PZ# Local TX#,TY#,TZ# Local RX#,RY#,RZ# Local PSS,TRO# For t.THRUSTER = Each THRUSTER If t\alpha# > t\parent\endalpha# Or t\scale# > t\parent\endscale# ScaleSprite t\flame,t\scale#,t\scale# EntityAlpha t\flame,t\alpha# t\scale# = t\scale# - t\parent\scalemodpercycle# t\alpha# = t\alpha# - t\parent\alphamodpercycle# EndIf If t\alpha# =< t\parent\endalpha# Or t\scale# =< t\parent\endscale# Then FreeEntity t\flame Delete t.THRUSTER EndIf Next For e.EFFECT = Each EFFECT PSS = e\parentship\ship Select e\kind Case 1 If e\parentship\throttle# > 0 Then PX# = EntityX#(e\parent,True) PY# = EntityY#(e\parent,True) PZ# = EntityZ#(e\parent,True) t.THRUSTER = New THRUSTER t\parent.EFFECT = e.EFFECT t\flame = CopyEntity(e\entitytocopy) t\scale# = e\startscale# * e\parentship\throttle# t\alpha# = e\startalpha# If t\alpha# =< e\endalpha# Or t\scale# =< e\endscale# Then FreeEntity t\flame Delete t.THRUSTER Else If e\randompositioning = False PositionEntity t\flame,PX#,PY#,PZ# Else If e\randompositioning = True TRO# = t\parent\randomoffset# TX# = Rnd(-TRO#,TRO#) * e\parentship\throttle# TY# = Rnd(-TRO#,TRO#) * e\parentship\throttle# TZ# = Rnd(-TRO#,TRO#) * e\parentship\throttle# RX# = PX# + TX# RY# = PY# + TY# RZ# = PZ# + TZ# PositionEntity t\flame,RX#,RY#,RZ# EndIf ScaleSprite t\flame,t\scale#,t\scale# EntityAlpha t\flame,t\alpha# EndIf EndIf End Select Next
Sorry if the code is a bit messy. I originally have it in a function and I pulled the types out from earlier in the program so that you can see what each field is.