I generally make the map file as simple to read and change in a text editor as I can. This generally makes the python code to parse the file a bit more complex, but since this is done only once at start-up I don't notice any speed issues.
Another way of doing it is to write a simple map loader that then pickles the data structure and saves it, and then in your game, load the pickle file. On 12/17/06, spotter . <[EMAIL PROTECTED]> wrote:
Thanks, I just wanted to make it fast because if I start loading the map at the beginning, it might seem to take a while before the game starts due to parsing and caching. Probably just my computer though, its a bit low on ram :( On 12/17/06, Ethan Glasser-Camp <[EMAIL PROTECTED]> wrote: > spotter . wrote: > > Hey everybody, > > > > I am in the process of trying to make a file format for maps. > > > > The meta file will have the info like name, author, date, version, and > > the width and height. > > > > The other file will have the actual map data in it. This method will be > > slower, > > since it involves opening, parsing, and closing two files. > > I think that unless you're going to be opening/reading map files all > the time -- numerous times per frame? -- the performance differential > is likely to be negligible. Get it working, then get it fast. > > If loading maps does turn out to be slow, perhaps you can cache them > once loaded. I do something like this with image files, storing the > images as .png with information like colorkey in a seperate file. > Since I'm caching images anyhow, performance doesn't suffer much. > > > The second method will be easier to read in, but will affect performance. > > How do all of you implement maps? Do you use regular expressions or > > simple search a string ? > > I typically try to write my maps as "pure Python" that call game > engine functions. For instance, I've been toying with something like this: > > setMap(''' > 000001111 > 000000001 > 000001111''') > setTerrain(0, passable=True, tile="grass") > setTerrain(1, passable=False, tile="forest") > > Of course, the last two times I tried to write a tile-based RPG I got > nowhere fast and gave up, so maybe you shouldn't take my advice. :) > > The map format I describe above is inspired by looking at some Wesnoth > maps, which look like a huge block of letters, with some other "meta" > information stored in a seperate file. > > Ethan > > > >
-- Science is open source religion