Hello to all!
I've got a question. You surely all know about packed files, very often used in games. In these big files there are many others, smaller files (images, sounds etc.). So the question is, how can I read the content into the memory and then - using pointers - access these different files?
For example we have data.dat with 3 files in it (file1.bmp, file2.bmp, file3.bmp). I open data.dat like that:
Code:
ifstream file("data.dat", ios::binary);
Now I have some pointers, like
Code:
// This structure is from Allegro if someone happen to know that
BITMAP** bmp = new BITMAP*[3];
//Normally it's used like that:
BITMAP* img = load_bitmap("file.bmp", NULL);
What I would like to do now is to let all the 3 pointers to show to the beginning of each file in memory, without creating any temporary files. I know that it works pretty fine for integers for example or some user defined structures using
Code:
int* x = 0;
myStruct* s = new myStruct;
file.read((char*)x, 4);
file.read((char*)s, sizeof(myStruct));
...
delete x;
delete s;
file.close();
But how can I access bigger files, about 100 and more KBytes? I want to have bmp[0], bmp[1], bmp[2] be ready to use with file1.bmp, file2.bmp, file3.bmp, just if I would write:
Code:
// BITMAP *load_bitmap(const char *filename, RGB *pal);
BITMAP* bmp1 = load_bitmap("file1.bmp", NULL);
BITMAP* bmp2 = load_bitmap("file2.bmp", NULL);
BITMAP* bmp3 = load_bitmap("file3.bmp", NULL);
// I tried it this way but it doesn't work
for(int i = 0; i < 3; i++)
file.read((char*)bmp[i], 12345); // assuming each bitmap has the same size
/* I tried out different possibilities, don't remember them all but sometimes
I got compiler errors, another time the program crashes like it doe's because
of memory access violation ...*/
Does anyone have any suggestions? I would appreciate any help I can get!
Thanks in advance