Custom file formats

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

User avatar
Cole S.
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Sat Dec 06, 2008 2:49 pm

Custom file formats

Post by Cole S. »

Hi, i am trying to make my own file format for 2d maps, and i have googled it, but i can't seem to get any good information on how to create it... any help?
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: Custom file formats

Post by Ginto8 »

Just name the file whatever you want.... You could make it "cow.moo", "chicken.fowl", ANYTHING. ;)

hope I helped ;) :mrgreen:
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
JaxDragon
Chaos Rift Junior
Chaos Rift Junior
Posts: 395
Joined: Mon Aug 04, 2008 2:03 pm
Current Project: Kanoba Engine
Favorite Gaming Platforms: PS3, PC
Programming Language of Choice: C++
Location: Northeast NC

Re: Custom file formats

Post by JaxDragon »

I would recommend saving them all as one format(PNG for example). Once the tiles are saved as a PNG, just rename them to have any extension you want. Load them using the same way you would load a png, except your file name shouldnt end with png ^^
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Custom file formats

Post by avansc »

i think he is refering to making binar files, not noramal ones
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
Cole S.
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Sat Dec 06, 2008 2:49 pm

Re: Custom file formats

Post by Cole S. »

I'm talking about having a custom 2d MAP format that i can load into my game engine... not just renamed files.
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: Custom file formats

Post by Ginto8 »

As in a file containing a list of all the tile types and stuff in a map/level? If so, just name the file whatever you want. ;)

If you're talking about something similar to saving an image from raw data, I have no clue. :(
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
Cole S.
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Sat Dec 06, 2008 2:49 pm

Re: Custom file formats

Post by Cole S. »

i dont mean a file as in "C:\Program Files" i mean a file format, as in map.<format here> that a game engine can load, it contains the tiles for the map as well as the positions and if it is collidable, as well as some other stuff
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: Custom file formats

Post by Ginto8 »

That's what I meant the first time. The format doesn't matter really, so long as it is a text file (not necessarily .txt, just containing text data), unless, of course, there is already a registry entry for that file format, and that entry says that it's, say, an image file (so you wouldn't use .png, .jpg, etc.). Other than those small restrictions, you can make it whatever you want. like I said before, you could make it moose.cow if you wanted to! ;) :mrgreen: :lol:
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
Cole S.
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Sat Dec 06, 2008 2:49 pm

Re: Custom file formats

Post by Cole S. »

So would i use C++ filestream to read chunks of the file or something??? and would there be a way to encrypt the files so you could not read them in notepad or any other text editor?
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Custom file formats

Post by avansc »

well thechnically tou can use any extension you want, even .bmp .jpg .mp3 .wav

anyways. if you are just goint to have something like

Code: Select all

map001
object 5
0,0,10,10,brick.jpg
10,0,10,10,brick.jpg
10,0,10,10,brick.jpg
20,0,10,10,brick.jpg
or whatever, that you read each line parse it and rebuild the level each time its loaded that fine.

another ( better ) option it to do it with binary files.

you would have lets say a level class, with all you data variables inside.

and you would just write the class to a binary file, then read the bytes from the file and store it in a level class object again.

down side to this is that your file will be non human readable, so you will have to have an editor.

nice thing about this is that its alot faster, file size is significantly smaller. parsers are practically non exsistant. easy of use. and scalability is infinate.
(so its a far better option.)
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: Custom file formats

Post by Moosader »

Yeah, you can have it similar to 3D model files, listing each tile like ava said:

mapname

x, y, w, h, image
x, y, w, h, image

so it would load in the information for each tile during the load.

My maps are in a grid, with the number listed representing the x coordinate of the tile (divided by 32).


0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 0 0 0 0 2 0
1 0 0 0 0 2 2 2
1 1 1 1 1 1 1 1
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Custom file formats

Post by avansc »

wht do so few people utilize binary files?
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
andrew
Chaos Rift Regular
Chaos Rift Regular
Posts: 121
Joined: Mon Dec 08, 2008 2:12 pm

Re: Custom file formats

Post by andrew »

Have a look at this.

You should get some ideas from it even though it's specifically for isometric maps. Also it's pretty old (1999) and even though it says it's C/C++, it's really only C.
User avatar
wtetzner
Chaos Rift Regular
Chaos Rift Regular
Posts: 159
Joined: Wed Feb 18, 2009 6:43 pm
Current Project: waterbear, GBA game + editor
Favorite Gaming Platforms: Game Boy Advance
Programming Language of Choice: OCaml
Location: TX
Contact:

Re: Custom file formats

Post by wtetzner »

I've decided to go with SQLite as my level/resource file format. It's embeddable, extremely fast, and cross platform. Also, there are stand-alone applications you can use to query them, so you don't have to write your own editor before you can test your engine. And best of all, you can query it with SQL! :)
The novice realizes that the difference between code and data is trivial. The expert realizes that all code is data. And the true master realizes that all data is code.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Custom file formats

Post by avansc »

wtetzner wrote:I've decided to go with SQLite as my level/resource file format. It's embeddable, extremely fast, and cross platform. Also, there are stand-alone applications you can use to query them, so you don't have to write your own editor before you can test your engine. And best of all, you can query it with SQL! :)
as far as i know you still cant write entire objects to it... i may be wrong. but i think a self made binary file would still be beter in terms of that.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Post Reply