performance and every tick

Discussion and feedback on Construct 2

Post » Sat Sep 29, 2012 7:00 pm

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.



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!
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Sep 29, 2012 8:14 pm

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.
B
11
S
4
G
3
Posts: 70
Reputation: 3,071

Post » Sat Sep 29, 2012 8:27 pm

**

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?teahousemoon2012-09-29 20:29:58
B
28
S
6
G
5
Posts: 248
Reputation: 5,463

Post » Sat Sep 29, 2012 9:08 pm

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 HealthMipey2012-09-29 21:10:22
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Sep 29, 2012 9:27 pm

@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.nutmix2012-09-29 21:29:17
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Sep 29, 2012 10:06 pm

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.
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Sep 29, 2012 10:18 pm

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

[QUOTE=nutmix] @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.
[/QUOTE]

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.teahousemoon2012-09-29 22:28:18
B
28
S
6
G
5
Posts: 248
Reputation: 5,463

Post » Sat Sep 29, 2012 10:25 pm

[quote]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.[/quote]
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.R0J0hound2012-09-29 22:28:20
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Sat Sep 29, 2012 10:33 pm

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.
B
15
S
5
G
2
Posts: 357
Reputation: 3,691

Post » Sat Sep 29, 2012 10:40 pm

[QUOTE=nutmix] @foolberry - using a single global would be dangerous if there is any multithreaded parts to C2[/QUOTE]

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.
B
11
S
4
G
3
Posts: 70
Reputation: 3,071

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 18 guests