Does "grouping" rules improve performance?

IgnisIgnis Member Posts: 72
edited November -1 in Working with GS (Mac)
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!

Comments

  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    are all of the guns next to each other? if so, how are they positioned?
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    i guess i'll elaborate...

    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...
  • IgnisIgnis Member Posts: 72
    The guns are fairly random... there could be any number of them (within reason), oriented at different positions within the scene...

    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.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    I'm no expert, but my assumption would be that particles would be less or as costly as the same number of actors. my reasoning is based on the fact that particles do not deal with any game rules or collisions, so there is a slightly lower burden on the processor. however, particles are kinda pre-loaded with a bunch of mandatory logic pertaining to their life-cycle, and some actors have no rules/collisions assigned to them...so, I could be totally wrong here!
  • JGary321JGary321 Member Posts: 1,246
    You only need 1 gun actor. The gun actor would set a game.attribute with the direction the ball would shoot.

    When ball collides with actor GUN then shoot in direction game.direction

    You do waste memory by having 6 different actors for shooting.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    JGary321,

    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?
  • JGary321JGary321 Member Posts: 1,246
    It will be fast enough. Whatever way he's spawning the different actors, whether by a button or what not, he will instead just change game.direction to 30, 60, 90, 120, 180, etc....So the direction is set immediately.

    You do not need to reset the direction every time, unless that is just a 'feature' of the game.
Sign In or Register to comment.