Does "grouping" rules improve performance?
Ignis
Member Posts: 72
Let's say that I have 6 actors... "guns" that point in 6 different fixed directions: 60 degrees, 120, 180, etc. When an actor (I'll use the tired "ball" example again) hits one of the guns, the ball is then "grabbed" and fired in the corresponding direction (same direction the gun is pointing) at great velocity.
Now, since actors cannot communicate settings between each other in an efficient manner, I can't have the ball read a variable angle (non-prototype angle setting) of the gun it collides with. Thus the need for 6 different gun actors, each with a Collide With rule associated with the ball, and a corresponding action: fire in that direction.
So my question is, would it increase performance to group these 6 gun Collide With rules under a blanket tag rule, i.e...
`
IF Ball collides with actor of TAG Gun
--IF Ball collides with actor of TYPE Gun60, fire at angle 60
--IF Ball collides with actor of TYPE Gun120, fire at angle 120
--IF Ball collides with actor of TYPE Gun180, fire at angle 180
`
All 6 gun actors would obviously be assigned a TAG of "Gun". Does anybody know if this method would improve performance versus stacking all 6 rules outside the containing tag rule?
Thanks!
Now, since actors cannot communicate settings between each other in an efficient manner, I can't have the ball read a variable angle (non-prototype angle setting) of the gun it collides with. Thus the need for 6 different gun actors, each with a Collide With rule associated with the ball, and a corresponding action: fire in that direction.
So my question is, would it increase performance to group these 6 gun Collide With rules under a blanket tag rule, i.e...
`
IF Ball collides with actor of TAG Gun
--IF Ball collides with actor of TYPE Gun60, fire at angle 60
--IF Ball collides with actor of TYPE Gun120, fire at angle 120
--IF Ball collides with actor of TYPE Gun180, fire at angle 180
`
All 6 gun actors would obviously be assigned a TAG of "Gun". Does anybody know if this method would improve performance versus stacking all 6 rules outside the containing tag rule?
Thanks!
Comments
if the guns are all positioned in a circle, or half circle, you can determine which gun your ball hit by checking the result of:
`vectorToAngle(game.GunCenterX-self.Position.X, game.GunCenterY-self.PositionY)`
another option...
if there is only going to be 1 "hit" at a time, you can tell the gun involved in the collision to write the associated angle value to a game level angle attribute. then, in the ball actor, using a timer for a slight delay, have it accelerate using the angle just passed from the impacted gun. it would also be a good idea to clear the gun angle attribute once it has been used...
In these early stages, I might be too concerned with performance issues, but I figure that if I optimize early, I won't run into problems later when I add more graphics, particle effects, many balls on the screen at once, various interactions between balls and scene objects, etc.
On this topic, does anybody know what kind of performance hit Particles can cause? Since I first started seeing nice particle effects in games like Thief well over a decade ago, I have been somewhat fascinated with their graphical possibilities to enhance game effects. So I was naturally thrilled to see Particles included in GameSalad, but I could easily get TOO fascinated with them and add too many! I wonder what their real-time effect is on game performance, especially on IPhone versus Web/Desktop.
When ball collides with actor GUN then shoot in direction game.direction
You do waste memory by having 6 different actors for shooting.
is it "safe" to say that the gun actor will write in time for the ball actor to pull in the correct angle, or is a timer needed?
Also, would you agree that is is good to have the ball actor reset `game.direction` after it is used in that instance, or is that extraneous logic?
You do not need to reset the direction every time, unless that is just a 'feature' of the game.