Page 1 of 1

Structuring Your Map Format

Posted: Tue Apr 27, 2010 4:55 am
by dejai
Hello I have a question for everyone who has implemented a map format before. How have you gone about structuring it? For example I use XML which I parse through tinyXML ( a great lightweight xml parsing libraryfor C++ ) I have heard that other people use JSON and a lot of indie game developers just develop their own customized formats. So anyway post how you structure your file formats cheers. ( Note this is not a problem it is a discussion ).

This is a test map we are using in the Kickle Cubicle Remake ( it still needs some refinement but it is shaping up to work quite well, note this has already been implemented and is a working system ):

Code: Select all

<?xml version="1.0"?>
<map>
        <tile_sheet>
                Content/Core/Sheets/levelSheet.png
        </tile_sheet>

        <tile_anims>
                Content/Core/Animations/TileSheet_48x48.xml
        </tile_anims>

        <tile_layout>
                12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
                12 12 12 12 12 12 12  4 12 12 12 12 12 12 12
                12 12 12 12 12 12  6  7  8 12 12 12 12 12 12
                12 12 12 12 12 12 16 17 18 12 12 12 12 12 12
                12 12  3  4  4  4  4  4  4  4  4  4  5 12 12
                12  6  7  7  7  7  7  7  7  7  7  7  7  8 12
                12 16 17 17 17 17 17 17 17 17 17 17 17 18 12
                12  6  1  1  1  1  1  1  1  1  1  1  1  8 12
                12 16  6  1  1  1  1  1  1  1  1  1  8 18 12
                12 13 16  6  1  2  1  1  1  2  1  8 18 15 12
                12 12 13 16  6  1  1  1  1  1  8 18 15 12 12
                12 12 12 13 16  6  1  1  1  8 18 15 12 12 12
                12 12 12 12 13 16  6  1  8 18 15 12 12 12 12
                12 12 12 12 12 13 16  7 18 15 12 12 12 12 12
                12 12 12 12 12 12 13 17 15 12 12 12 12 12 12
        </tile_layout>

        <collision_layout>
                1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
                1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
                1 1 1 1 1 1 0 0 0 1 1 1 1 1 1
                1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
                1 1 0 0 0 0 0 0 0 0 0 0 0 1 1
                1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
                1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
                1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
                1 1 0 0 0 0 0 0 0 0 0 0 0 1 1
                1 1 1 0 0 1 0 0 0 1 0 0 1 1 1
                1 1 1 1 0 0 0 0 0 0 0 1 1 1 1
                1 1 1 1 1 0 0 0 0 0 1 1 1 1 1
                1 1 1 1 1 1 0 0 0 1 1 1 1 1 1
                1 1 1 1 1 1 1 0 1 1 1 1 1 1 1
                1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
        </collision_layout>

        <game_objects>
                <entity data="Content\\Core\\Objects\\Slime.xml">
                        <instance x="3" y="8" />
                        <instance x="11" y="8" />
                </entity>
                <entity data="Content\\Core\\Objects\\DreamBag.xml">
                        <instance x="6" y="2" />
                        <instance x="7" y="2" />
                        <instance x="8" y="2" />
                </entity>
                <entity data="Content\\Core\\Objects\\Kickle.xml">
                        <instance x="7" y="12" />
                </entity>
                <entity data="Content\\Core\\Objects\\SpawnPoint.xml">
                        <instance x="3" y="9" />
                        <instance x="11" y="9" />
                </entity>
        </game_objects>

        <music_playlist>
                <song data="Content\\Core\\Sound\\stage_1.ogg"/>
                <song data="Content\\Core\\Sound\\stage_2.ogg"/>
        </music_playlist>
</map>


Re: Structuring Your Map Format

Posted: Tue Apr 27, 2010 8:43 am
by LeonBlade
Make it binary ;)
But seriously, it looks very well structured.

Re: Structuring Your Map Format

Posted: Tue Apr 27, 2010 1:33 pm
by Ginto8
LeonBlade wrote:Make it binary ;)
not necessarily a good idea, until the game is finished. If you can use text files, use them, but not once you're ready to "release" the game. But I don't think XML is a good idea, as that will make level loading a lot slower. If you can make an easy, text-style format, that'd be better ("[tilesheet filename] [anim config file] 1 12 4 4 ... ") Also, having the anim config in a custom text file would be faster than XML. However, it should be noted that, on PCs, the overhead of XML may not be significant.

Re: Structuring Your Map Format

Posted: Tue Apr 27, 2010 2:13 pm
by Falco Girgis
I'm not a big fan of XML for reason that Ginto8 stated. The only time that XML is worth your time is if you are directly editing the text file. If a Level Editor is editing/saving, you are ten times better off saving resources and lowering your loadtime with a simple format.

Re: Structuring Your Map Format

Posted: Tue Apr 27, 2010 3:58 pm
by eatcomics
I'm just using simple text files, they work wonders, and you could still read in your entities with that format if you just wrote some extra code, not that you have to, you could just load your map in a text file, and enemies in XML. What ever your preference is

Re: Structuring Your Map Format

Posted: Tue Apr 27, 2010 4:20 pm
by Arce
Dejai, I think it looks great. While you're making your game, a nice, easy to read format like this is a great way to do things. That way you can easily modify it with or without an editor.

However, for all of the reasons stated, you may want to consider saving in binary or your own custom format before release.

Any my apologies for not using your topic as intended and showing you how I store shit--Gyro would probably shoot me. After skinning me alive. An filleting my face.

Re: Structuring Your Map Format

Posted: Wed Apr 28, 2010 5:01 am
by MrDeathNote
Ginto8 wrote:
LeonBlade wrote:Make it binary ;)
not necessarily a good idea, until the game is finished. If you can use text files, use them, but not once you're ready to "release" the game. But I don't think XML is a good idea, as that will make level loading a lot slower. If you can make an easy, text-style format, that'd be better ("[tilesheet filename] [anim config file] 1 12 4 4 ... ") Also, having the anim config in a custom text file would be faster than XML. However, it should be noted that, on PCs, the overhead of XML may not be significant.
I agree with this, while i'm making a game my maps are just lists of numbers, then later on you can convert to binary to save space and load time.

Re: Structuring Your Map Format

Posted: Sat May 01, 2010 12:01 am
by dejai
Yup I agree with all of your points on XML and I thought I would post some reasons why we chose it for this project in particular. First off the game is going to be completely based around UGC (user generated content) with community members writing custom maps and scripts for the game. This instantly resonated that we needed something in a human readable format so we had the choice of either designing our own simple file format or going with something more generic such as XML. We decided on XML for a couple of reasons firstly it is very structured which makes it easy to read, secondly we have a very specific target for the game to be based completely around puzzle solving this gave us a lot of headroom in terms of loading maps because frankly the maps are not that complicated and are only 15x15 tile map which we can easily load in with no lag ( less the loading of resources, which are then stored by the resource manager ) also we found TinyXML which provided a very straightforward API for dealing with our xml files. This meant that we could spend more time working directly on polishing the game mechanics. I can see for an RPG for instance that you would actually have significant concern about the size of files due to the sheer volume of activity that takes place in such a level ( which was kind of why I was interested in seeing some other map formats ) and it could actually impact on loading time. Anyway great discussion thanks. On the issue of binary that might just be something we do when we release thanks for the heads up ( or at least support it ).

Re: Structuring Your Map Format

Posted: Mon May 03, 2010 12:09 pm
by captjack
Just a thought: You could support both formats.

Write your engine to support a binary format, optimized and structured as needed.

Then, you can write out a map compiler. Using a compiler, you can write hand-coded maps or editor-"coded" maps. The intermediate map can then be run through your map compiler for the format needed by the engine.

Takes more effort, and proper planning in the design stage is critical, but it's certainly a viable option.

A nice side effect is that people who want to make maps don't need your editor. They just need to know the map format (i.e. your XML structure) and they could use their own, in-house, editor. Submitting a map, then, to your game world could invoke a server-side instance of the compiler. It could sanity check the XML and compile the map into the engine's accepted structure.

Re: Structuring Your Map Format

Posted: Mon May 03, 2010 3:40 pm
by eatcomics
that could be a good learning experience, and it would be more efficient in game, but it might be too complex for the simplicity of his what is it? 15 x 15 map? still a consideration for larger things