In Depth event optimization questions.

Discussion and feedback on Construct 2

Post » Tue Jun 23, 2015 11:42 am

Throughout my project i have lots objects where their position is set every tick to the position to another object. Doing a little bit of testing turning off these particular event saves me a lot of CPU budget, but then again objects wont follow. It's not really the draw calls that make up for these CPU usage, but rather the setting of all the numbers every tick.

I've read all the optimization guides but want to go more in depth on how to optimize the events as I'm aiming to make a quite complex game for Mobile so every tiny bit of CPU usuage i can save on seems like a very good idea. I've identified the "on every tick" event as a major resource hog. So....

Will (Pin Behaviour) Pinning an object to another one instead of using On every tick > set position to > sprite.X sprite.Y or is there any other way that I've missed that might be better.

I know we're talking minimal tiny ammounts of CPU per object, but everything adds up quite fast.
Follow my progress on Twitter
or in this thread Archer Devlog
B
38
S
15
G
17
Posts: 949
Reputation: 12,320

Post » Tue Jun 23, 2015 11:47 am

you could save time with each 0.xx sec, instead of each tick. try each 0.05 sec setting a position - it will give some relief to your cpu, but still it will be cpu intense. also there's another factor - if you use each tick - huge cpu usage, if you use each (let's say 1 sec) - you will see "jumps", instead of smooth following.

i know for sure that cartoons run in 24 frames per second and they do look good, fluid. so try setting your options to 0.05 sec (0,04166666666666666666666666666667 s) for 24 frames following. the change should be invisible to eye, but it should give processor 3x less work to do.

oh yeah - pin also works on each tick - so you've done nothing. funny thing also, if you have pathfinding with movable obstacles - use regeneration each 0.2 sec - worked perfect for me.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
42
S
14
G
12
Posts: 624
Reputation: 9,421

Post » Tue Jun 23, 2015 12:46 pm

Another question. I would imagine that the structure of the events would play some role as well. For example... If you have an event, which is false, will any further sub-events be skipped by the system and not checked, or are they still run through and checked?

I would imagine that using sub-events well could limit a lot of checks that way. If the first event is false & placing many related events within that one, instead of creating a new event under, with the same conditions would save on some quite a lot of checks?
Follow my progress on Twitter
or in this thread Archer Devlog
B
38
S
15
G
17
Posts: 949
Reputation: 12,320

Post » Tue Jun 23, 2015 3:45 pm

skipped. if you have

something like this:

Code: Select all
if (a>0)
     do something and then
     if (b>0)
         do something else


each tick you check a>0 if it is true it checks b>0 and does events prior to it. if a>0 is false it skips the rest. if b is false skips all under b and so on..
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
42
S
14
G
12
Posts: 624
Reputation: 9,421

Post » Tue Jun 23, 2015 4:06 pm

I'd be surprised if setting object positions every tick really is the cause of your performance problems - it's one of the fastest and best-optimised parts of the C2 engine. Can you make a new empty .capx demonstrating the performance difference so I can investigate?

As for events, they are all run top-to-bottom and it stops running the event as soon as it comes across a false condition (unless it's an OR block). The C2 engine is not so poorly designed that it would do such wasteful work as running an event it already knows isn't going to run!
Scirra Founder
B
395
S
232
G
88
Posts: 24,368
Reputation: 193,746

Post » Wed Jun 24, 2015 10:06 am

Strange - when I make a new project i don't get the same effect. Have to investigate further. In my project there is a group with events which keeps hovering around 1 to 1.5% CPU usage (mostly this group contains set position every tick on several sprites) even when all the events in the group is disabled - the group still uses around around 0.6% cpu... When i replicate in a blank project the same kind of events only take 0.4% CPU... and 0.1% CPU when disabled.
Follow my progress on Twitter
or in this thread Archer Devlog
B
38
S
15
G
17
Posts: 949
Reputation: 12,320


Return to Construct 2 General

Who is online

Users browsing this forum: gamecorpstudio and 7 guests