Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

making a filetype?

This topic is 6034 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i sorta have an idea on how to do it, but not really, are there any tutorials on it, or anything that can give me the basics, like a tutorial on loading a certain filetype would probably help me, and, is it hard? btw i want to make a filetype that can put a displacement map, texture for the disp map, and 3d objects kinda into a "level" it would tell were the objects were in the "level" you get what im saying? if you dont i understand lol would this be like really hard for a intermediate programmer? thanks, samith

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
It''s easy if you use you''re own format. I made my own version if a bitmap file format, and it''s smaller than a normal one. Bitmaps are very wasteful, they pad every 24-bit colour with another 8 bits, could easily be used for an alpha channel, but isn''t, and every row of pixels is padded with zeros to make it a multiple of 4 bytes.

As for actually doing it, some file formats (such as the bitmap file format) just dump structures into the file, and they can be read back later in the same order.

Something asdf;
FILE *asdf2 = fopen("asdf.asd","rb");
{/*Ahh! Noooo! Argh!!!!!!! Cruel, grousome Death!*/ return;}

/*asdf was loaded from asdf.asd*/

Something could be a structure, a class, a typedef''d predefined type, what ever. There is one thing to note, though. Some compilers, or even the same compiler with different levels of optimization, will move things around in the structure to make everything aligned by a multiple of 4, so that stuff can be processed faster (32 bit is faster than 24-bit, but storing a 24 bit image as a 32 bit one makes it bigger, but faster to use. I think that''s why the bitmap file format is so wasteful.) So, using data created by a program compiled on a compiler that is different that yours may result in screwy things happening. One way to fix that is to put the smallest things first in your structures/classes, and scatter dummy data in the structure to make sure that everything is aligned. The other is to read/write everything individually in the structure, but you would have to do that anyway if it contained pointers to other data.

The ''never fail'' method is to use ASCII, which is very wasteful, slow, but almost always works, and can eaisly be hacked with windows notepad.

Of course, you probably want to load some one elses data. Usually, if they wanted you to be able to read their data, they would write routiens to read it. If not, well, hex editors can be useful for debugging what your program is doing against what it should be reading. What it should look like is here. You probably already know how this works. I''m just guessing, I haven''t ever tried this. Good luck.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!