performance and every tick

0 favourites
  • 11 posts
From the Asset Store
Firebase: Analytics, Dynamic Links, Remote Config, Performance, Crashlytics on Android, iOS & Web Browser
  • Most games have various counters such as balance, health, position etc.

    As there is no "on value change" event, MVC or similar for such values, rather than duplicate the GUI update code in every place which can update the values, I have 10 "every tick" actions to do things like:

    1) calculated and show the latest balance on screen

    2) show the latest bet amount on screen

    3) set any anchored objects to the right X/Y position based on viewport (anchor behaviour doesnt do what I need)

    etc.

    <img src="http://www.ohds.co.uk/c2/everytick.PNG" border="0" />

    When I run the game, I get 6fps when Idle (I.e. absolutely nothing happening - no movement, no animations) on the iphone 4. If I disable the onticks, I get 60fps. I still only get 1fps if I move a tiled background across the screen, but thats another post.

    I saw someone say that C2 is intelligent enough to only run the ontick action if one of the values has changed. This does not seem to be the case.

    What is the best strategy for this?

    Does everyone store the "last value" of each variable, then do checks to see if it has changed every tick? This will also incur an overhead.

    Any magic solutions, e.g. to make an event out of a value change such that it can be caught and actions can be defined in one place?

    Thanks!

  • It's unlikely to be the on tick actions in themselves - I think - more likely to be something nasty nested in one of them. I can't see anything in the code you've posted which would cause a problem.

    Have you tried disabling the onticks one at a time to find if the problem is specific to one of them. And then disabling code within that ontick.

    If you want to only have the GUI update after variable changes then I think the best thing is to handle it all yourself and have an updateGUI global boolean. Set that to true after you've changed a variable etc. And then have a on updateGui condition with all your code inside it, setting updateGUI to false at the end.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • **

    Just read Foolberry's post, that sounds good too.

    And please report back if you discover that your "on tick" events were not the cause of the poor framerate, as it would be nice to know if "on tick" is actually as intelligent as you believed it to be and another issue was causing the low framerates.

    **

    Original post:

    Why not just "set text" when an action requires the text to change? The text won't go anyway until you tell it to change, i.e. "set text".

    This way the text responds via an event, and you can also 'follow' your actions with global or instances variables (depending on your needs). This can provide you with words or numbers to use in your text.

    Will this not work?

  • Setting the text and object size can be performance intensive, especially on every tick. The text is in fact re-rendered every time it is changed.

    Why don't you use another variable for each value? Then you can on every tick compare if the value has changed since last tick, only then update the GUI and the variable itself.

    Like this:

    + Every tick

    + OldHealth is not equal to Health

    OldHealth = Health

    Text: Set text to Health

  • foolberry - using a single global would be dangerous if there is any multithreaded parts to C2 (I dont know if there are). e.g. if thread A set the "something changed" global to true, the on tick sees this, sets text, then just before it sets the "something changed" back to false, some other thread changes a value and sets the global to true it will be ignored - and the values wont be updated. Anyone one know how multithreaded C2 is? Im familiar with Actionscript, which every one says is single threaded but in fact isnt - e.g. http request callbacks can be executed any time.

    Mipey, this is my backup option, but is tedious.

    teahousemoon I could duplicate the setting of text code in every place its updated, but often I want to add something, then I would have to find and add it to every duplicate place, which in C2 is hard - I often resort to using notepad++ on the xml files.

    The solution I think I will go for is to use rexrainbows function plugin. This is poor second best to a custom event, but will allow me to abstract the updating code into a single maintainable place, but put the calls to it all over the place as required.

    Usually I would not touch a non-C2 plugin for fear of it becoming unsupported in a future version, but I dont think my project will be maintainable without it.

  • Well, I removed each action one by one, and the one which caused to go from 60fps to 6fps was:

    [T] wonAmount -> Set X to (viewportleft("main")+viewportright("main"))/2

    However, I do exactly the same thing with sprites above it, which doesn't cause a problem, so this is odd.

    Interestingly, once I call this line, preview doesnt auto update the iphone any more, I have to refresh after hitting the "play" button at the top of C2.

    This doesnt seem possible, but I've reproduced it about 10 times.

    All the other lines put together make about 2-4fps difference btw if I disable them.

  • Ashley would be best to ask about any multithreading aspects of C2, I'd think.

    teahousemoon I could duplicate the setting of text code in every place its updated, but often I want to add something, then I would have to find and add it to every duplicate place, which in C2 is hard - I often resort to using notepad++ on the xml files.

    What is an example of something you would need to add? So far I'm not convinced that C2 cannot perform your desired result without too much difficulty.

    I'm glad you found the source of the problem with the framerate, though I can't say I understand why it's an issue for you at the moment, either.

  • etting the text and object size can be performance intensive, especially on every tick. The text is in fact re-rendered every time it is changed.

    That can't be right, rendering only occurs once per frame at the end of the event sheet. Setting text and object size just sets values which should be very fast.

  • I know what it might be - the text object which killed performance had an anchor behavior. I was overriding this to make it centered (anchors cant do this). I expect this was the problem.

  • foolberry - using a single global would be dangerous if there is any multithreaded parts to C2

    That I didn't think of. I use this alot - not usually globals actually, but object variables. And I've never had a problem with it. I use it where you'd normally call a method in code. But I see there is a threading problem potentially.

  • It is likely your 'every tick' events have little or no performance impact. If nothing at all on screen changes (as you say is the case when you disable the events), Construct 2 does not actually redraw the screen. Most games spend 80-90% of their time rendering, so if you measure the framerate when nothing is moving (and therefore the screen is not drawing), the result is meaningless. It will basically be doing nothing at all apart from updating the FPS counter. I assume you are enabling an event which causes a per-tick change in the display, which causes rendering every tick, which then results in a real framerate. This may make it look like a single event is having a huge performance impact, but it is very unlikely this is the case. In general you shouldn't worry about event performance anyway.

    Note that moving offscreen objects, or moving an object then putting it back in the same tick, still results in a redraw. Construct 2 doesn't try very hard to detect is nothing has visually changed, because doing so accurately is extremely difficult and most games redraw every tick anyway.

    For the record, C2 does not use a multithreaded engine right now.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)