[SOLVED] Help! Reading in binary file C++
Posted: Thu Mar 11, 2010 11:35 pm
Hey guys,
If you've seen my project I've been working on, I want to work on maps.
I've created a map file which documentation can be found here.
My problem is, I know what I want to do, I just don't know how I need to do it.
What I need to do is open the map file, and then start reading in bytes.
First off I need to read in the "magic" value of BBMF for Blade Brothers Map File (the map file type for my engine) which is 4 bytes.
After that is 4 bytes which contains the file size.
Then comes the details section of the file which currently just holds 2 bytes for the tiles wide and tiles high both 2 bytes each like I said so a total of 4 bytes for those two.
Then finally is the map data which is 3 bytes per tile. Tiles get loaded in from top left to bottom right. Each byte is from 0-FF which is 0 to 255 and that represents which tile number to grab on a corresponding tilesheet (to be worked out later).
The bytes are laid out in a left to right/top to bottom approach like you would read standard English text.
NOW, here is my issue.
I need to open the file so that I may read in the bytes.
First I need to start at 0 and read the first 4 bytes of data, the I need to move my read pointer to 4 bytes in and read 4 more bytes for the filesize, then move from there 4 bytes again over and then read in 2 bytes for the tiles wide move 2 bytes read in 2 bytes again for the tiles high move 2 bytes and then start reading in each tile which is reading in 3 bytes then moving 3 bytes from there to the next tile and so and and so forth.
That was a run on sentence, however, I don't care!
My problem is, I don't know how to do this in C++
I've tried a few approaches and everything seems to be leading me in the wrong direction or something.
Can someone assist me? I just need to know a few function calls for what I want to do and I can be on my way
Also, inb4 someone says "you should start off with something more easier" I know what to do, just not how to do it exactly.
Thanks, and hope to get some help soon.
If you've seen my project I've been working on, I want to work on maps.
I've created a map file which documentation can be found here.
My problem is, I know what I want to do, I just don't know how I need to do it.
What I need to do is open the map file, and then start reading in bytes.
First off I need to read in the "magic" value of BBMF for Blade Brothers Map File (the map file type for my engine) which is 4 bytes.
After that is 4 bytes which contains the file size.
Then comes the details section of the file which currently just holds 2 bytes for the tiles wide and tiles high both 2 bytes each like I said so a total of 4 bytes for those two.
Then finally is the map data which is 3 bytes per tile. Tiles get loaded in from top left to bottom right. Each byte is from 0-FF which is 0 to 255 and that represents which tile number to grab on a corresponding tilesheet (to be worked out later).
The bytes are laid out in a left to right/top to bottom approach like you would read standard English text.
NOW, here is my issue.
I need to open the file so that I may read in the bytes.
First I need to start at 0 and read the first 4 bytes of data, the I need to move my read pointer to 4 bytes in and read 4 more bytes for the filesize, then move from there 4 bytes again over and then read in 2 bytes for the tiles wide move 2 bytes read in 2 bytes again for the tiles high move 2 bytes and then start reading in each tile which is reading in 3 bytes then moving 3 bytes from there to the next tile and so and and so forth.
That was a run on sentence, however, I don't care!
My problem is, I don't know how to do this in C++
I've tried a few approaches and everything seems to be leading me in the wrong direction or something.
Can someone assist me? I just need to know a few function calls for what I want to do and I can be on my way
Also, inb4 someone says "you should start off with something more easier" I know what to do, just not how to do it exactly.
Thanks, and hope to get some help soon.