|
|
BMAP* to char ... and ... char to BMAP* ???
#243523
12/30/08 15:14
12/30/08 15:14
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
OP
Serious User
|
OP
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
Hi,
is it possible to write the data of a BMAP* into a char array and back ???
I have a struct that looks like this:
typedef struct SAVEGAME { char savegameName[64]; char picture[20000]; char currentRoomName[100]; char currentPlayerName[100]; char player1IsInRoom[100]; VECTOR player1Position; ANGLE player1Rotation; char player1Inventory[1024]; char player2IsInRoom[100]; VECTOR player2Position; ANGLE player2Rotation; char player2Inventory[1024]; char player3IsInRoom[100]; VECTOR player3Position; ANGLE player3Rotation; char player3Inventory[1024]; int playtime; char objectStates[2000]; } SAVEGAME;
Later in my code I use the following code to store the BMAP*:
BMAP* picture = bmap_createblack(245,110,24); bmap_for_screen(picture, 4, 0); wait(1); savegame->picture = (char*)picture;
But I don't know how the get the BMAP* back from the char. I tried:
BMAP* picture = bmap_createblack(245,110,24); picture = (BMAP*)savegame->picture;
But that doesn't seem to work.
Can someone help?
Regards, Pegamode.
|
|
|
Re: BMAP* to char ... and ... char to BMAP* ???
[Re: pegamode]
#243921
01/01/09 18:10
01/01/09 18:10
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
OP
Serious User
|
OP
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
|
|
|
Re: BMAP* to char ... and ... char to BMAP* ???
[Re: Saturnus]
#243937
01/01/09 20:06
01/01/09 20:06
|
Joined: Oct 2007
Posts: 5,209 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
20000 chars array feels like he is trying to store file in struct.
3333333333
|
|
|
Re: BMAP* to char ... and ... char to BMAP* ???
[Re: pegamode]
#244142
01/02/09 22:36
01/02/09 22:36
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
The actual picture data is larger than you've planned for, so you will need to change you're struct definition from "char picture[20000];" to "char picture[81000];" [or 80500 to be exact]. To store the picture in your struct, replace BMAP* picture = bmap_createblack(245,110,24);
bmap_for_screen(picture, 4, 0);
wait(1);
savegame->picture = (char*)picture; with BMAP* pic = bmap_createblack(245,110,24);
bmap_for_screen(pic, 4, 0);
wait(1);
var picsize = pic.width*pic.height*pic.bytespp; //number of bytes in snapshot == Width X Height X BytesPerPixel. BytesPerPixel= color bits / 8
var byt; for(byt=0; byt<picsize; byt++) savegame->picture[byt] = (pic.pixels)[byt]; //copy pixels to struct->picture from BMAP Then to retrieve the snapshot, use this BMAP* pic = bmap_createblack(245,110,24);
var byt; for(byt=0; byt<picsize; byt++) (pic.pixels)[byt] = savegame->picture[byt]; //copy pixels from struct->picture to BMAP I havent compiled this, so we may need to tweak it to get it to compile, but I believe the design is right. Any problems or questions from anyone, let me know. [EDIT] Ive changed your BMAP name from picture to pic JUST for ease of reading. Change my code to match its old name if you wish.
Last edited by EvilSOB; 01/02/09 22:40. Reason: Footnote Added
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: BMAP* to char ... and ... char to BMAP* ???
[Re: pegamode]
#244200
01/03/09 11:24
01/03/09 11:24
|
Joined: Feb 2006
Posts: 1,011 Germany
pegamode
OP
Serious User
|
OP
Serious User
Joined: Feb 2006
Posts: 1,011
Germany
|
Hi EvilSOB, I tested the code. Saving seems to work, but when I try to retrieve the snapshot with
for(byt=0; byt<savegame->picsize; byt++) {
(pic.pixels)[byt] = savegame->picture[byt]; //copy pixels from struct->picture to BMAP
}
the line: (pic.pixels)[byt] = savegame->picture[byt]; results in an error "crash in ...". Any ideas??? Regards, Pegamode.
|
|
|
|