Structuring Your Map Format

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
dejai
Chaos Rift Junior
Chaos Rift Junior
Posts: 207
Joined: Fri Apr 11, 2008 8:44 pm

Structuring Your Map Format

Post 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>

User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: Structuring Your Map Format

Post by LeonBlade »

Make it binary ;)
But seriously, it looks very well structured.
There's no place like ~/
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Structuring Your Map Format

Post 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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Structuring Your Map Format

Post 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.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Structuring Your Map Format

Post 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
Image
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: Structuring Your Map Format

Post 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.
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Structuring Your Map Format

Post 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.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
dejai
Chaos Rift Junior
Chaos Rift Junior
Posts: 207
Joined: Fri Apr 11, 2008 8:44 pm

Re: Structuring Your Map Format

Post 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 ).
User avatar
captjack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 50
Joined: Fri Sep 18, 2009 4:23 pm
Current Project: engine framework
Favorite Gaming Platforms: PC, XBox 360, PS3
Programming Language of Choice: C, C++
Location: Northern Virginia

Re: Structuring Your Map Format

Post 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.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Structuring Your Map Format

Post 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
Image
Post Reply