Mail Archives: djgpp/1997/02/07/23:52:45
On 8 Feb 1997 00:23:09 GMT, "Chris" <dingfam AT imag DOT net> wrote:
>typedef struct Map {
> int w, h;
> char name[8];
> BITMAP *tiles[60][60];
>} Map;
Fine. What you wrote next was wrong, though...
> Map *m;
> pack_fwrite(m->name, 8, fl);
I assume some code goes in between these two lines :) Otherwise, there
is no map to save... Make sure there's a malloc in there somewhere
[e.g. m=(Map *)malloc(sizeof(Map));]
> pack_iputw(m->w, fl);
fine (assuming the file is open)
> pack_iputw(m->h, fl);
fine
> for(x=0; x< 60; x++)
> for(y=0; y< 60; y++)
> pack_fwrite(m->tiles[x][y], sizeof(BITMAP), fl);
No. You're saving the wrong thing here... m->tiles[x][y] is a pointer
to the bitmap. So you're writing this to the file followed by a
massive chunk which is nearly as long as the BITMAP struct is. Sorry,
but this is pointless. What you need to save is the image - this
begins at the location pointed to by m->tiles[x][y]->line, and
continues for width*height bytes, I think... Try using this line
instead of the present pack_fwrite line:
pack_fwrite(m->tiles[x][y]->line,width*height,fl);
The loading routine then becomes:
>And a loading routine which looks like this:
> Map *m;
m=(Map *)malloc(sizeof(Map));
> pack_fread(m->name, 8, fl);
> m->w = pack_igetw(fl);
> m->h = pack_igetw(fl);
> for(x=0; x< 60; x++)
> for(y=0; y< 60; y++)
At this stage you need to allocate the bitmaps you're putting the
information into, so we add a create_bitmap and correct the pack_fread
as above:
* {
* m->tiles[x][y]=create_bitmap(width,height);
* pack_fread(m->tiles[x][y]->line,width*height,fl);
* }
You should #include <stdlib.h> for the malloc command.
Hope this helps, if not send me your source and I'd be happy to peruse
it.
George Foot
- Raw text -