Level editor takes too long to load

This forum is currently in read-only mode.
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • 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?

  • Would an array be faster?


    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.

  • Its basicaly this:

    <img src="http://i.imgur.com/tKxlC.jpg" border="0" />

    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:

    <img src="http://i.imgur.com/nEiC0.jpg" border="0" />

    If the value is 2,3,4 or higher, it means there's an object to be loaded

    • now it takes 36 seconds :/
  • 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):








    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.

  • Just replaced the INI with an Array and it only takes 9 seconds to load now, thx for the help!

  • Should still take a split second to load O_o..

  • 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

  • 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!

  • I can't believe my eyes @, this "for each element" is impressive, it loads instantly! Thanks a lot!!!

  • 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?

  • No. ^^;

    If it's loading 3 times then you're probably saving a single layer's data to all 3 z dimensions...or something...somehow..

    When you place a tile/object/whatever do you write the value at (array) x,y or x,y,z?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • For each element includes the z.

  • Nop, i'm writing the object only to Z = 2, and i'm loading it only when the Z is 2 too

  • We need an edit button :P

    Just found out I wasn't using Array.CurrentZ

  • Post options => Edit post

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)