What is the best practice?

Get help using Construct 2

Post » Fri Feb 05, 2016 11:22 am

Maybe something has changed since last year - I haven't tested it recently. However last year when I was releasing my trivia game I clearly noticed that every layout first loading took on my mobile approx 2s. Then every layout second (and n-th) loading took about 0.5s. So the difference was clerly noticable.

Now regarding RAM. It depends on how the program is written. I am not sure how C2 works atm. But system does not clear any RAM data "by default". Clearing RAM takes time as well so data usually stays there even if it is not used and then some GC (Garbage Collector) clears it periodically. Or you can do it manually by coding as well ofc.

And let's say I have an app exported to desktop. My laptop has 16GB of RAM. It is "strong enough" to keep in RAM whole game even if it is not being used. But access to the RAM memory is much faster than HDD read so the game would be much more optimised if all the data would remain in RAM rather then be cleared and loaded everytime the layout changes.

For mobile devices it is a bit different story cause we usually have 1-3GB of RAM which is not that much and indeed sometimes RAM might be not big enough. In such cases unused data will be overriden by the new data.

I am not an expert, just saying how I see it based on my knowledge and experience.

Now the last thing to say here is that putting all objects in one layout is not a good practice when you think from the perspective of being a good coder. Good code is semantic and hermetised code, which means (in short) that every "thing" should be where it belongs and nowhere else.
But loading everything on first layout is acceptable even for good developers in C2 simply because of performace.

But then again if for some reason data is cleared when you swich to other layout... then there is absolutely no point doing so. It requires testing on various platforms and various mobiles to be sure how it works I believe. Nice topic tho! ;)
ImageImageImage
B
27
S
16
G
74
Posts: 980
Reputation: 41,679

Post » Fri Feb 05, 2016 12:26 pm

BackendFreak wrote:Maybe something has changed since last year - I haven't tested it recently. However last year when I was releasing my trivia game I clearly noticed that every layout first loading took on my mobile approx 2s. Then every layout second (and n-th) loading took about 0.5s. So the difference was clerly noticable.

Now regarding RAM. It depends on how the program is written. I am not sure how C2 works atm. But system does not clear any RAM data "by default". Clearing RAM takes time as well so data usually stays there even if it is not used and then some GC (Garbage Collector) clears it periodically. Or you can do it manually by coding as well ofc.

And let's say I have an app exported to desktop. My laptop has 16GB of RAM. It is "strong enough" to keep in RAM whole game even if it is not being used. But access to the RAM memory is much faster than HDD read so the game would be much more optimised if all the data would remain in RAM rather then be cleared and loaded everytime the layout changes.

For mobile devices it is a bit different story cause we usually have 1-3GB of RAM which is not that much and indeed sometimes RAM might be not big enough. In such cases unused data will be overriden by the new data.

I am not an expert, just saying how I see it based on my knowledge and experience.

Now the last thing to say here is that putting all objects in one layout is not a good practice when you think from the perspective of being a good coder. Good code is semantic and hermetised code, which means (in short) that every "thing" should be where it belongs and nowhere else.
But loading everything on first layout is acceptable even for good developers in C2 simply because of performace.

But then again if for some reason data is cleared when you swich to other layout... then there is absolutely no point doing so. It requires testing on various platforms and various mobiles to be sure how it works I believe. Nice topic tho! ;)


Yeah. I agree, this really depends on what you are exporting to. For I make mobile games, I focus more on cordova exports and less on PC exports. And If I sum up what @BackendFreak said, I would say that since PC's has greater Rams then it would be better if you would preload it on startup because PC's doesn't require a lot of resources that makes clearing of Ram unnecessary, therefore making it faster. But If you use mobile exports then it is better to put each objects that is going to be needed in the layout into that layout for mobile ram's are very limited at the moment. But if you have the time, I really recommend to put the objects in the layout you are using because of unexpected Ram cuts and clearing just to make sure. But these might not be accurate yet, so testing for yourselves will be much better. I will also test this myself on other platforms if I have the time. :D I also think this is a great topic too.
The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
64
S
19
G
90
Posts: 1,119
Reputation: 59,667

Post » Fri Feb 05, 2016 9:16 pm

@chadorireborn
I don't think you are wrong at all! This makes perfect sense and I will have to keep that in mind when designing games.
Now my current (big) game has only one layout for every fights, so I will have to choose in either having a longer loading time before each fight or having a very slight loading delay when a new object is appearing. At least now I know what are the flaws of each solutions.

Thanks a lot, this was very interesting and important! :)
B
30
S
6
G
1
Posts: 348
Reputation: 2,752

Post » Fri Feb 05, 2016 9:33 pm

@BackendFreak
I'm quite confident that the memory is cleared at the beginning of each layout. This has been somewhat hinted by Ashley in this post :
how-to-reduce-the-number-of-crashes-mobile_p896157?#p896157

And as he suggest, you can see it for yourself. Start your game in debugger and look at memory usage. You'll notice that when you switch from one layout to another, memory usage decrease drastically. I learned that the hard way when I needed to optimize my previous mobile game (now I develop for desktop and life is soooooo easier!) ;)

I guess this indeed implies that putting all the objects on a loader layout is pointless, even harmful as it will delay your loading screen with no purpose.
B
30
S
6
G
1
Posts: 348
Reputation: 2,752

Post » Fri Feb 05, 2016 11:19 pm

@Rable thnx for the link! That clears everything.

Let me quote Ashley again here
"In Construct 2, images are loaded layout-by-layout. This means when a layout starts, every object on the layout is loaded in to memory immediately. This is to avoid mid-game pauses as textures are loaded on the fly. When the layout ends, it will free all the images in memory not used by the next layout, and load any new images the next layout uses."


So it is totally pointless to store all images in one layout. And a good practice is to stick to semantic rules - which is also a good news ;).
ImageImageImage
B
27
S
16
G
74
Posts: 980
Reputation: 41,679

Post » Fri Feb 05, 2016 11:46 pm

Thank you very much guys! That's a very interesting discution. But... well, now I have more doubts that before haha
Sorry, but I'll have to call boss... Hey, @Ashley , we need you here!!

What do you think about it?
B
20
S
4
Posts: 385
Reputation: 2,270

Post » Mon Feb 08, 2016 11:36 am

The relevant manual entry is Memory usage, which covers layout-by-layout loading and how objects placed in the layout vs. created at runtime are handled. In short, you should have any objects the layout ever uses placed somewhere offscreen and destroyed on startup if need be - this causes their images to be preloaded when the layout starts. Otherwise, 'create object' can "jank" as it loads images on-demand.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,772

Post » Mon Feb 08, 2016 3:47 pm

Ashley wrote:The relevant manual entry is Memory usage, which covers layout-by-layout loading and how objects placed in the layout vs. created at runtime are handled. In short, you should have any objects the layout ever uses placed somewhere offscreen and destroyed on startup if need be - this causes their images to be preloaded when the layout starts. Otherwise, 'create object' can "jank" as it loads images on-demand.

Hehe thank you, Ashley!
And, of course, thank you very much guys!
B
20
S
4
Posts: 385
Reputation: 2,270

Previous

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 59 guests