Timers are for chumps - GS optimization tips

1235

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Place a max iterations check after every single "function".

    Or pre-calculate what you need and construct accordingly.
    That's a non-answer but I'll take it!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • domeniusdomenius Member Posts: 108
    edited March 2013
    Not to be outdone, I've just developed a method which allows for much faster iteration times with no code duplication. Initial testing on my Macbook Pro (early 2011) within the creator is performing 60 loop iterations in 0.082 seconds. The best part is my new method actually performs a full-stop of game execution while the loop is performed. While this isn't always desired, it is very valuable for designing table search algorithms, among other things. I still have some fine-tuning and testing to do, but I expect to have a tutorial up on this method shortly!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @domenius I'm looking forward to seeing what you have developed. RThurman came up with a spawn-the-spawner recursive loop and it was faster but I couldn't figure out how to use it in an actual project as it seemed to hang on devices.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2013
    @domenius I'm looking forward to seeing what you have developed. RThurman came up with a spawn-the-spawner recursive loop and it was faster but I couldn't figure out how to use it in an actual project as it seemed to hang on devices.
    @tatiang

    Spawning a spawner is very dangerous, I know a couple of people who were killed trying that, you need - at the very least - to be wearing protective clothing.

    image
  • SocksSocks London, UK.Member Posts: 12,822
    Not to be outdone, I've just developed a method which allows for much faster iteration times with no code duplication. Initial testing on my Macbook Pro (early 2011) within the creator is performing 60 loop iterations in 0.082 seconds. The best part is my new method actually performs a full-stop of game execution while the loop is performed. While this isn't always desired, it is very valuable for designing table search algorithms, among other things. I still have some fine-tuning and testing to do, but I expect to have a tutorial up on this method shortly!
    @domenius

    Sounds excellent !!

    I can see where this is all going, it's only a matter of time before someone comes up with a loop that iterates into the past.
  • BlueFanStudiosBlueFanStudios Member Posts: 77
    Any chance someone could point me in the direction of a video tutorial for this?? I found one for before/after so many seconds but none for "every X seconds".
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @BlueFanStudios Did you already read the first post in this thread, specifically the part titled "---EVERY X SECONDS TIMER REPLACEMENT---"? I don't know of a video but that explains it pretty well.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • BlueFanStudiosBlueFanStudios Member Posts: 77
    I read it but I couldn't quite get my head around it. Im a visual learner, videos are easier to understand.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    It's pretty much just setting a real attribute mod1 to 0.05 and then making a rule that fires every time mod1>self.time%1 (for every second). If you change it to mod1>self%4, if will fire every 4 seconds.

    image

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • BlueFanStudiosBlueFanStudios Member Posts: 77
    Thanks, I got that idea from it. I think it was trying to work out what the math talk was that was confusing me.
  • spidey906spidey906 Member Posts: 52
    Great Post! Thank your for your input. I have one question though...

    I create a rule using your method to make the bullet destroy in 3 seconds but it quickly destroy right after it fires. (Using this method to spawn the bullet is ok though.

    Thanks for your help.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    @kentcheung2000@yahoo.com Which method are you referring to? And how do you have your Destroy Actor behavior set up? What does the rule look like?

    P.S. You'll want to change your forum account name in your profile because using an email address with the @ symbol causes notifications to fail.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • spidey906spidey906 Member Posts: 52
    Thank you for your reply.

    I create a gun to spawn bullet using the following method. It works fine.

    if mod1(0.05) > self.timer%1
    spawn bullet.

    However, Inside the bullet, when I try to make the bullet to last for 5 second, for example. I run into problem

    Move bullet

    if mod1(0.05) > self.timer%5
    destroy.

    the bullet didn't move the the direction I want and it just flash at the same location...

    Thanks for you help..
  • SomewhatScientificSomewhatScientific Member Posts: 8
    edited March 2013
    Cool stuff! I can't believe that I just found this a few days ago.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @spidey906 The mod1 "timer" is an every x seconds timer. What you really want is just a rule that checks the bullet's time on the screen:

    When self.Time>5
    Destroy [actor]

    If you're still having problems, I'd recommend starting a new discussion and sending me a PM with a link to it so I can continue to help you out.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • domeniusdomenius Member Posts: 108
    As promised, I have completed my new approach to loops, which ive called HyperLoops. I've created a new thread for it to avoid confusion and clutter. It can be found here: http://forums.gamesalad.com/discussion/54922/hyperloops-loop-to-your-hearts-content
  • glyniusglynius Member Posts: 231
    I am trying to replace all timers of my game, but i got problem, i need to start a countdown after 1 second, so i need for 60seconds to remove 1 from an attribute that controls a replicate behavior. The problem is that even that on my player it works almost fine and i manage to match it with the music, when i test it on device (testflight) the replicate behavior is very slow, not 1 sec for 60 seconds. i post my rules and i wish that somebody could help on this.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @glynius Let's take the replicate behavior out of the equation and talk about the timer. Are you saying that the timer isn't counting down seconds correctly on a device?

    Also, is this the effect you are wanting?

    .....Every 1 second
    ..........Decrease counter by 1

    *Note that an Every timer automatically starts after the first iteration meaning that an Every 1 second timer will trigger at 1 second, 2 seconds, 3 seconds, etc., and therefore is already starting "after 1 second."

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • glyniusglynius Member Posts: 231
    @glynius Let's take the replicate behavior out of the equation and talk about the timer. Are you saying that the timer isn't counting down seconds correctly on a device?

    Also, is this the effect you are wanting?

    .....Every 1 second
    ..........Decrease counter by 1

    *Note that an Every timer automatically starts after the first iteration meaning that an Every 1 second timer will trigger at 1 second, 2 seconds, 3 seconds, etc., and therefore is already starting "after 1 second."
    Yes @tatiang this is what i want to achieve, every 1 second decrease counter by 1. Unfortunatelly the way i did it is not precise, and i don't get why. Also i don't understand what is the difference if i setup the mod attribute to 0.02 or 0.05...does this affects the countdown? I apologize for my questions, i a not a programmer and probably i will never be, and if gamesalad wouldn't exist , i would never be able to make any app.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @glynius Not to side-step your question (although I'm not all that comfortable with modding timers myself) but... is there a reason you're needing to replace all of the timers? If it works with timers, then use timers by all means.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • glyniusglynius Member Posts: 231
    @glynius Not to side-step your question (although I'm not all that comfortable with modding timers myself) but... is there a reason you're needing to replace all of the timers? If it works with timers, then use timers by all means.
    i noticed that replacing most of my timers, the game runs smoothly, keep in mind that probably i have too many rules and pointless stuff on my project that i cannot clear out at the moment (i mean with my current knowledge), replacing animation behavior and timers (as much as i understand) the performance is much better. I wish that timers would work better because i find it real mess to have all this rules instead of a beautiful timer expression.
  • SnapFireStudiosSnapFireStudios Member Posts: 1,603
    I'm going to be implementing this in to my game. I'll let you all know what kind of performance increase I get from it. ;)
    - Thomas
  • 8bitninja8bitninja Member Posts: 367
    Thanks domenius, this is an amazing post. I am however having a lil trouble with my shooting actor. Before, I was using.

    every 0.1 sec
    spawn the bullet actor

    Now, when I try using your.

    self attribute.
    Mod1 - 0.5 - real

    self.Mod1>self.timer%1
    spawn the bullet actor

    My bullets are only firing 1 per sec
    I tried changing to self.timer%0.1 but nothing happens.

    If anyone can help me out with this I will very much appreciate it.

    Thanks.
  • domeniusdomenius Member Posts: 108
    @8bitninja

    Change your mod1 value to 0.05 and retry. The mod1 value can not be larger than the modulus you are applying (%0.1) or the rule will never fire.

    Hope this helps!
  • 8bitninja8bitninja Member Posts: 367
    @domenius

    That totally worked. Thanks so much domenius, you're amazing! :D
  • SnapFireStudiosSnapFireStudios Member Posts: 1,603
    @CodeWizard - Any chance you could take a look at why the defualt timers don't use these or similar methods and thus do not work as well? These ways have been working amazingly for me, but they are more inconvenient.
    Thanks,
    - Thomas
  • SnapFireStudiosSnapFireStudios Member Posts: 1,603
    @CodeWizard - When you have a chance, could you please take a look at the Timer code and why it isn't as reliable as these? :)
    - Thomas
  • CodeWizardCodeWizard Inactive, Chef Emeritus Posts: 1,143
    Have looked at it a bit already. There are some clear issues that need to be resolved. Have noted the issue for more work soon.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Wowsers! @ORBZ, I didn't realize that the expression editor could read Boolean operators. This is really cool! (I didn't make it to the yellow actors yet. I was floored with "not( game.Increment )" in the controller actor).

    Boolean logic at the expression editor level changes everything!
Sign In or Register to comment.