It takes like 2 minutes to load the world for my RPG, every time I run the program. The map is 300x300 tiles, and each tile has 1 to 5 layers.
It takes almost a minute to create the tiles and a minute to load them. But the collisionsetup function finishes instantly.
I can't work like this, its too slow.
Does anyone have any tips on how to speed this up?
There are no entrances or guys on this map but there will be.
The map file is over 5 MB.
It takes almost a minute to create the tiles and a minute to load them. But the collisionsetup function finishes instantly.
I can't work like this, its too slow.
Does anyone have any tips on how to speed this up?
There are no entrances or guys on this map but there will be.
The map file is over 5 MB.
Method Load() Local file:tstream file=ReadFile("map/"+id+".dat") sizex=Readint(file) sizey=Readint(file) array=New ttile[sizex+1,sizey+1] Local forx,fory Local tile:ttile Local layer Local idread Local amread Local levelread Local xread,yread Local battleidread Local guy:tguy Local f Local tilelayered:ttilelayered Local rgb tfont.draw "creating tiles",10,10 Flip Cls For fory=1 To sizey For forx=1 To sizex tile=New ttile array[forx,fory]=tile tile.x=forx tile.y=fory tile.guylist=CreateList() Next Next For fory=1 To sizey If fory Mod 20=0 Then tfont.draw "loading tiles: "+100*fory/sizey+"%",10,10 Flip Cls If KeyHit(key_escape) Then End EndIf For forx=1 To sizex tile=array[forx,fory] For layer=1 To ttile.layeram idread=Readint(file) If idread<>0 Then tilelayered=New ttilelayered tile.layers[layer]=tilelayered tilelayered.kind=ttilekind.array[idread] xread=Readint(file) yread=Readint(file) If xread=forx And yread=fory Then 'common speedup tilelayered.drawtile=tile Else tilelayered.drawtile=array[xread,yread] EndIf battleidread=Readint(file) tilelayered.battleid=battleidread If battleidread>battleidlast Then battleidlast=battleidread tilelayered.scalex=ReadFloat(file) tilelayered.scaley=ReadFloat(file) tilelayered.handlex2=Readint(file) tilelayered.handley2=Readint(file) tilelayered.color=New Byte[3] For rgb=0 To 2 tilelayered.color[rgb]=ReadByte(file) Next If tilelayered.color[0]=255 .. And tilelayered.color[1]=255 .. And tilelayered.color[2]=255 Then tilelayered.color=colorfull EndIf EndIf Next 'load entrance on tile idread=Readint(file) If idread<>0 Then tentrance.make(tile) tile.entrance.starttilex=Readint(file) tile.entrance.starttiley=Readint(file) tile.entrance.mapid=idread tile.entrance.areaid=Readint(file) tile.entrance.startareaid=Readint(file) ListAddLast tentrance.list,tile.entrance EndIf 'load guys on tile amread=Readint(file) If amread<0 Or amread>25 Then RuntimeError "guy am read="+amread If amread<>0 Then For f=1 To amread idread=Readint(file) levelread=Readint(file) guy=tguy.make(tguykind.array[idread],False,levelread,False) guy.id=Readint(file) guy.x=Readint(file) guy.y=Readint(file) guy.dir=tdir.array[Readint(file)] guy.map=Self Next EndIf Next Next 'battle id battleidhigh=Readint(file) Local i For f=1 To battleidhigh For i=1 To tguykind.am battleappear[f,i]=ReadShort(file) battlelevel[f,i,1]=ReadShort(file) battlelevel[f,i,2]=ReadShort(file) Next Next Local temp=Readint(file) If temp<>999 Then RuntimeError "the sentinel failed!" CloseFile file tfont.draw "setting tile collision",10,10 Flip Cls self.collisionsetup() EndMethod Method CollisionSetup() Local forx,fory Local areax,areay Local tile:ttile Local addx,addy Local tilelayered:ttilelayered Local layer Local x1,x2,y1,y2 x1=1; x2=sizex y1=1; y2=sizey For fory=y1 To y2 For forx=x1 To x2 tile=array[forx,fory] For areay=0 To 2 For areax=0 To 2 tile.battleid[areax,areay]=-1 Next Next For layer=ttile.layeram To 1 Step -1 tilelayered=tile.layers[layer] If tilelayered<>Null Then addx=tile.x-(tilelayered.drawtile.x-(tilelayered.kind.sizex-1)) addy=tile.y-.. (tilelayered.drawtile.y+tilelayered.kind.drawtileyless-(tilelayered.kind.sizey-1)) For areay=0 To 2 For areax=0 To 2 If tilelayered.kind.area[addx,addy][areax,areay]=1 Then If tile.collision[areax,areay]=0 Then tile.collision[areax,areay] = tilelayered.kind.walk EndIf EndIf If layer<ttile.layeram Then If tilelayered.kind.areawalk[addx,addy][areax,areay]=1.. Or tilelayered.kind.area[addx,addy][areax,areay]=1 Then If tile.battleid[areax,areay]=-1 Then tile.battleid[areax,areay]=tilelayered.battleid EndIf EndIf EndIf Next Next EndIf Next Next Next EndMethod