Pick by evaluate using more CPU than For each?

Discussion and feedback on Construct 2

Post » Tue Jul 07, 2015 2:53 pm

I was messing around trying to optimise some parts of my game tried out picking objects (pick by evaluate) instead of using for each, and seemed it used more CPU than a for each loop on ALL objects in the family.

Even when the picking event returned false and not running any actions it was using more CPU than the For each event doing the same thing every tick.

How is that possible?

In my mind the picking would limit the amount of actions to be done as an optimisation but turns out it's using more CPU. If the picking event didn't find a match the event would be false right? nothing to be done... so how come it uses more CPU than running a for each loop with no picking...

Very strange.
Follow my progress on Twitter
or in this thread Archer Devlog
B
35
S
15
G
17
Posts: 944
Reputation: 12,210

Post » Tue Jul 07, 2015 3:02 pm

2 things I guess:

-the evaluation of the expression might be simply taking more time than the actions (don't think conditions are instantaneous, in some cases they take more time that actions).
-the CPU measure of C2 is not accurate enough for a small case (and even for larger ones), it is really a ballpark figure and nothing more, if the difference for the small case is minor, then don't really care about it that much, as the inaccuracy and debug alteration might play a bigger role.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
52
S
22
G
18
Posts: 2,122
Reputation: 17,093

Post » Tue Jul 07, 2015 3:15 pm

Depends on the amounts of objects, and what the for each is supposed to do.
And like Aphrodite mentions, it depends on the evaluation too.

Its like comparing oranges and apples.

Also,
Have you tried pick by unique ID ?
Or pick by comparison ? (without pick all)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Tue Jul 07, 2015 3:33 pm

Aphrodite wrote:2 things I guess:

-the evaluation of the expression might be simply taking more time than the actions (don't think conditions are instantaneous, in some cases they take more time that actions).
-the CPU measure of C2 is not accurate enough for a small case (and even for larger ones), it is really a ballpark figure and nothing more, if the difference for the small case is minor, then don't really care about it that much, as the inaccuracy and debug alteration might play a bigger role.


Thanks. Difference is not that huge. But there are some tradeoffs.

The Picking way, Uses less CPU that the For each way, but as the sprite count increases, and seems fairly constant even with large numbers of sprites in the layout.

The for each way gets more heavy as the number of sprites increases, but is using less CPU when the sprite count is low.

i think i have to do some more experimentation on the picking events.

Right now I'm using picking sprites in several steps with conditions.
Condition1, picks only the sprites on screen.
Condition2, picks only the sprites on the specific layer.
Condition3. picks by evaluating only the sprites(in a family) that are above the player.Y & left of player X & distance is less than 150px from player.

Most of the time this limits the picking to 1 or 2 sprites picked.

If all the conditions are met a function is called & Moves the picked sprites to another layer, so they will not be picked again.
Follow my progress on Twitter
or in this thread Archer Devlog
B
35
S
15
G
17
Posts: 944
Reputation: 12,210

Post » Tue Jul 07, 2015 4:40 pm

Did you try a family variable?

Also it's a process of elimination, so if you have a condition that makes the stack smaller starting out, use it first.
Image ImageImage
B
168
S
50
G
163
Posts: 8,226
Reputation: 105,071

Post » Tue Jul 07, 2015 5:25 pm

tunepunk wrote:Condition1, picks only the sprites on screen.
Condition2, picks only the sprites on the specific layer.
Condition3. picks by evaluating only the sprites(in a family) that are above the player.Y & left of player X & distance is less than 150px from player.



Condition1. picks by evaluating only the sprites(in a family) that are above the player.Y & left of player X
Condition2, picks only the sprites on the specific layer.
Condition3. distance is less than 150px from player.



Try that
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests