Page 3 of 37

Re: My Zelda style adventure engine progress thread

Posted: Tue Aug 11, 2009 10:55 pm
by Robin
Have you tried reading the map bit by bit? You know, read n tiles, go on with update()ing and draw()ing, read n tiles, etcetera.

Re: My Zelda style adventure engine progress thread

Posted: Wed Aug 12, 2009 1:34 am
by Jasoco
Doesn't quite work that way.

Once it enters the for lines in file loop it won't return control until it's done.

Code: Select all

function loadMap(m)
	local mFile = "maps/" .. tostring(m) .. ".map"
	if love.filesystem.exists(mFile) then
		local i = 0
		local mD = {}
		for line in love.filesystem.lines(mFile) do
			mD[i] = line
			i = i + 1
		end
		mapHeight = i * 32
		mapWidth = math.floor((tonumber(string.len(mD[1]))+1) / 22) * 32
		
		for x=0,mapWidth/32-1 do
			for y=0,mapHeight/32-1 do
				mapTiles[x][y] = string.sub(mD[y], (x * 22) + 1, (x * 22) + 4)
				mapDeco1[x][y] = string.sub(mD[y], (x * 22) + 5, (x * 22) + 8)
				mapDeco2[x][y] = string.sub(mD[y], (x * 22) + 9, (x * 22) + 12)
				mapDeco3[x][y] = string.sub(mD[y], (x * 22) + 13, (x * 22) + 16)
				mapDeco4[x][y] = string.sub(mD[y], (x * 22) + 17, (x * 22) + 20)
				mapHit[x][y] = string.sub(mD[y], (x * 22) + 21, (x * 22) + 21)
				mapHitN[x][y] = string.sub(mD[y], (x * 22) + 22, (x * 22) + 22)
			end
		end
	else
		error("Oops! It seems you are missing a certain map file.\nThe map \"" .. mFile .. "\" seems to be missing from its home.\nOr maybe your character has wandered into uncharted territory.")		
	end
end
I know it's not the most optimized way to do it. It's all the filesystem loading that causes the pause. The longest delay is the for lines in file loop. Everything else is fast enough. And while it's in the loadMap function, the draw function doesn't even get called at all so it's not like I can draw the words "loading" on the screen or anything.

Gonna do some tests. See how fast it takes to load 100 characters, 1000 characters, 10000, 100000 and 1000000 and compare the results.

Re: My Zelda style adventure engine progress thread

Posted: Wed Aug 12, 2009 2:17 am
by Jasoco
My findings with loading large files via love.filesystem.lines():

Code: Select all

  Characters  Time in Seconds
       1,000   0.00103759765625
      10,000   0.01397705078125
     100,000   0.12103271484375
   1,000,000   1.2219848632812
  10,000,000  12.185974121094
A 250x250 map has about 1.3 million characters. Currently. Using 22 chars per tile.

Re: My Zelda style adventure engine progress thread

Posted: Wed Aug 12, 2009 8:08 am
by Robin
Jasoco wrote:Once it enters the for lines in file loop it won't return control until it's done.
Well, I think it would be possible to use the iterator lines(mFile) returns to load a line every frame, and set a flag when it's done, so the parsing can start (or maybe just check whether lastline == nil?)

That would require a major rewrite of your map loading code though, because it has to be placed in update() (or update has to call loadmap() as long as the map isn't loaded.)

Re: My Zelda style adventure engine progress thread

Posted: Wed Aug 12, 2009 8:17 am
by Jasoco
There's really no reason though since most maps are gonna be so small they load in a blink anyway. Having an entire world in one map is nice, but it's not really optimal unless you're doing Sim City. (I wonder, how many tiles in width and height was the biggest Sim City map area?

Re: My Zelda style adventure engine progress thread

Posted: Wed Aug 12, 2009 8:23 am
by TechnoCat
Sim City always took a long time to load though, so it might be an unfair comparison.
Reticulating Splines

Re: My Zelda style adventure engine progress thread

Posted: Wed Aug 12, 2009 8:27 am
by Jasoco
Sim City has other problems, loading level map grids is the least of its loading. It also had to load many megabytes of images and other data. Plus it was a lot slower system.

It is a fair comparison, because Sim City is the only time you see a map grid that size. Other games just break maps down into smaller bite-size chunks.

Re: My Zelda style adventure engine progress thread

Posted: Wed Aug 12, 2009 11:07 am
by Robin
Jasoco wrote:There's really no reason though since most maps are gonna be so small they load in a blink anyway.
OK, I didn't thought of that. If you have small maps anyway, there is no reason to mess around with the map loading.

Re: My Zelda style adventure engine progress thread

Posted: Thu Aug 13, 2009 12:06 am
by Jasoco
Games like GTA and Oblivion use sophisticated routines for loading stuff in at runtime. They rely on the ability to reach into a map file/database and grab a specific set of variables from a specific area in the file/database. Which is a huge array of data. X, Y, Z points, image definitions and position data. A lot of stuff. Games like that have inline map loading. The small starting area is loaded at startup, then more areas are loaded as you run around depending on where you go.

With work, I could in theory set up my game to have seamless loading of levels, but really, I'm not that big on it. I mean it'd be cool. But too much for me.

Re: My Zelda style adventure engine progress thread

Posted: Thu Aug 13, 2009 10:01 am
by bartbes
This still seems weird, can it be that big? Anyway, you might load only portions of the map, which means longer loading times in-game, but also way better memory usage.