How Would You Put All Media In One File?
Moderator: Coders of Rage
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
How Would You Put All Media In One File?
Like putting all images in Images.dat or something. I have no idea how I would do this since I dont exactly know how an OS would handle that stuff... Or am I trying to complicate an easy thing? In other words, how would I encode the data? I can just use a fancy equation and use fstream right? I dont need additional libs?
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: How Would You Put All Media In One File?
If you can read the image file by itself without a library, then you can put multiple ones in the same file and it will work (pending some sort of separation that lets you know where each image begins and ends). As far as the OS handling it, you wouldn't be able to view in any standard image editing software since it's your own personal proprietary format, but you could create tools to read/write/view your new format if you really wanted.davidthefat wrote:Like putting all images in Images.dat or something. I have no idea how I would do this since I dont exactly know how an OS would handle that stuff... Or am I trying to complicate an easy thing? In other words, how would I encode the data? I can just use a fancy equation and use fstream right? I dont need additional libs?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: How Would You Put All Media In One File?
An OS usually allocates your hard drive space into "blocks" and keeps track of what file starts at what block and how long the file is. Blocks are allowed to only be partially filled (in which case the rest of the block is wasted space, another file does not start there). This has obvious parallels to "all images in one file" sort of thing, and I'm answering what I thought you were trying to ask instead of what you actually did ask =)
As for your specific question, if all your images have the same allotted number of bytes, you could just read x bytes and disregard any padding. For instance, if you allot 512 bytes to each image in your engine and an image is only 256 bytes you would read 512 and the last 256 bytes would be, say, all zeroes, and you would throw those away. Or, if you used a standard image format, you could just read the header info which usually says how large your image is or the file itself has a terminal marker, in which case you could do away with padding.
So your image.dat might have a header itself that says which image starts at what offset in the file (this would allow you to read image on-demand). If it doesn't (ie, you want to load all the images at the start, or don't mind a loading time), you would need to read the file sequentially, counting the terminal markers for each image until you found the image you were looking for.
You, yourself, would just append the info for each image to the end of your image.dat file (and pad it if necessary).
As for your specific question, if all your images have the same allotted number of bytes, you could just read x bytes and disregard any padding. For instance, if you allot 512 bytes to each image in your engine and an image is only 256 bytes you would read 512 and the last 256 bytes would be, say, all zeroes, and you would throw those away. Or, if you used a standard image format, you could just read the header info which usually says how large your image is or the file itself has a terminal marker, in which case you could do away with padding.
So your image.dat might have a header itself that says which image starts at what offset in the file (this would allow you to read image on-demand). If it doesn't (ie, you want to load all the images at the start, or don't mind a loading time), you would need to read the file sequentially, counting the terminal markers for each image until you found the image you were looking for.
You, yourself, would just append the info for each image to the end of your image.dat file (and pad it if necessary).
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Re: How Would You Put All Media In One File?
Here's some stuff I have bookmarked:davidthefat wrote:Like putting all images in Images.dat or something. I have no idea how I would do this since I dont exactly know how an OS would handle that stuff... Or am I trying to complicate an easy thing? In other words, how would I encode the data? I can just use a fancy equation and use fstream right? I dont need additional libs?
Creating a PAK File Format
Virtual File System
Programming a Virtual File System
It might be a bit more than you wanted.
- davidthefat
- Chaos Rift Maniac
- Posts: 529
- Joined: Mon Nov 10, 2008 3:51 pm
- Current Project: Fully Autonomous Robot
- Favorite Gaming Platforms: PS3
- Programming Language of Choice: C++
- Location: California
- Contact:
Re: How Would You Put All Media In One File?
Thanks all of you
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: How Would You Put All Media In One File?
Perhaps interesting reads, but its in-depth explanation of the mpq file format blizzard entertainment uses in their games. While it is certainly over-the-top for anything personal, the reading to the links I posted below are a wonderful eye opener on how this is done. I REALLY suggest you read the first link if your at all interested, its very informational / interesting if your sort of into it.
Cheers, and Merry Christmas!
http://shadowflare.samods.org/inside_mopaq/
http://wiki.devklog.net/index.php?title ... ive_Format
Cheers, and Merry Christmas!
http://shadowflare.samods.org/inside_mopaq/
http://wiki.devklog.net/index.php?title ... ive_Format
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson