Level editor takes too long to load

For questions about using Classic.

Post » Fri Sep 09, 2011 2:45 am

I'm making a level editor that saves each block value to an .ini file. It takes roughly 25 seconds to load a level 100x100 blocks. I'm using 2 loops to read the ini, one for the X and one for the Y
How can I speed it up? Would an array be faster?
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Fri Sep 09, 2011 3:21 am

[QUOTE=7Soul]Would an array be faster?[/QUOTE]

Way.

edit:Actually, 25 seconds?! To my knowledge INIs are slower but not THAT much slower. It should still take under a second to load that..maybe it's something with your code? Sounds like you might be loading multiple instances of the same tile or something.Tokinsom2011-09-09 03:23:43
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Fri Sep 09, 2011 3:46 am

Its basicaly this:


At the start of the frame I start loop X, and it starts loop Y. Then I select a tile by comparing its X and Y to the current Loop Index. Then I compare the array value, if its 1 or greater, the tile is visible, if its 0 the tile is invisible
- this takes roughly 12 seconds

Then I have this:

If the value is 2,3,4 or higher, it means there's an object to be loaded
- now it takes 36 seconds :/
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Fri Sep 09, 2011 4:18 am

This is not the way you should use an ini-file. An array is more suitable for a 2-dimensional grid form like this one.
Even worse, you are not loading the ini-data to RAM, but constantly read from the file. You force the file to be read at least 11 times per iteration. With 100x100 positions that's 110000 file accesses in just 36 seconds. It's not slow, it is pretty fast :D

A better way to use the ini-file would be to not orient to the grid, but make groups of object types (and give the items the x/y values):
[lights]
L1=2,3
L2=25,9

[cages]
C1=13,36
C2=14,52

etc.

You'd then, instead of those x/y loops, access the ini-file with:
+ For each item in group "lights"
->Create object tile_light on layer "Tiles" at (GetToken(INI.CurrentItem, 1, ",")* whatever, GetToken(INI.CurrentItem, 2, ",") * whatever)

Add this for every type of object and you're done. this would only access the file once for every item and therefore will be a lot faster than your way.

But if you for whatever reason want to stick to the grid method, then use an array. Arrays will be loaded to RAM, so multiple access to it will be much, much faster.tulamide2011-09-09 04:20:42
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Sep 09, 2011 8:23 pm

Just replaced the INI with an Array and it only takes 9 seconds to load now, thx for the help!
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Fri Sep 09, 2011 10:38 pm

Should still take a split second to load O_o..
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Sat Sep 10, 2011 12:23 am

It probably takes a little longer because I'm not using 2 loops anymore. The X "loop" I made using a global variable, and the Y loop is an actual loop. I did this because using only loops freeze the game during it, and by doing it this way, I can have a cool loading bar that works

I made a level which is 65x45 and it takes 4 seconds to load, but takes 6 seconds once I export the game (can anybody explain this?).

The game is in alpha stage, you can download it here and have a look: Download: direct link - 4mb
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Sat Sep 10, 2011 1:19 am

There's no need to create your own "loops," which I'm assuming is what's slowing things down.

Arrays can do this themselves with 'for each element' and are capable of loading incredibly large levels with many layers instantly.

There are some very simple array-based level editor/loading examples around the forum you might want to check out!
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Sat Sep 10, 2011 2:36 am

I can't believe my eyes @_@, this "for each element" is impressive, it loads instantly! Thanks a lot!!!
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Sat Sep 10, 2011 2:51 am

Hey, just something I noticed, if my array has 3 Z layers, it creates everything 3 times. Is it better to have 3 arrays with 1 Z layer then?
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests