game-info: Add graphics artist, cleanup some stuff

This commit is contained in:
simon.kagstrom 2010-03-27 07:46:40 +00:00
parent 6631286c8a
commit ab72622362
2 changed files with 32 additions and 11 deletions

View File

@ -72,6 +72,7 @@ struct game_info_v2
uint16_t filename_off; uint16_t filename_off;
uint16_t score; uint16_t score;
uint16_t year; uint16_t year;
uint16_t creator_off;
uint16_t musician_off; uint16_t musician_off;
uint16_t graphics_artist_off; uint16_t graphics_artist_off;
uint8_t data[]; /* 4-byte aligned */ uint8_t data[]; /* 4-byte aligned */
@ -100,6 +101,7 @@ static void demarshal_v2(struct game_info_v2 *src)
{ {
demarshal_v1((struct game_info_v1 *)src); demarshal_v1((struct game_info_v1 *)src);
src->musician_off = ntohs(src->musician_off); src->musician_off = ntohs(src->musician_off);
src->creator_off = ntohs(src->creator_off);
src->graphics_artist_off = ntohs(src->graphics_artist_off); src->graphics_artist_off = ntohs(src->graphics_artist_off);
} }
@ -153,8 +155,8 @@ static struct game_info *from_v2(struct game_info_v2 *src)
GameInfo::GameInfo(const char *filename, GameInfo::GameInfo(const char *filename,
const char *name, const char *publisher, const char *name, const char *publisher,
const char *creator, const char *musician, const char *creator, const char *graphics_artist,
SDL_Surface *image) const char *musician, SDL_Surface *image)
{ {
this->filename = xstrdup(filename); this->filename = xstrdup(filename);
if (strcmp(name, " ") == 0) if (strcmp(name, " ") == 0)
@ -163,6 +165,7 @@ GameInfo::GameInfo(const char *filename,
this->name = xstrdup(name); this->name = xstrdup(name);
this->publisher = xstrdup(publisher); this->publisher = xstrdup(publisher);
this->creator = xstrdup(creator); this->creator = xstrdup(creator);
this->graphics_artist = xstrdup(graphics_artist);
this->musician = xstrdup(musician); this->musician = xstrdup(musician);
this->screenshot = image; this->screenshot = image;
this->genre = GENRE_UNKNOWN; this->genre = GENRE_UNKNOWN;
@ -182,6 +185,8 @@ GameInfo::GameInfo(GameInfo *gi)
this->name = xstrdup(gi->name); this->name = xstrdup(gi->name);
this->publisher = xstrdup(gi->publisher); this->publisher = xstrdup(gi->publisher);
this->filename = xstrdup(gi->filename); this->filename = xstrdup(gi->filename);
this->graphics_artist = xstrdup(gi->graphics_artist);
this->creator = xstrdup(gi->creator);
this->musician = xstrdup(gi->musician); this->musician = xstrdup(gi->musician);
this->screenshot = NULL; this->screenshot = NULL;
this->players = gi->players; this->players = gi->players;
@ -194,11 +199,17 @@ GameInfo::GameInfo(GameInfo *gi)
} }
GameInfo::~GameInfo() GameInfo::~GameInfo()
{
this->freeAll();
}
void GameInfo::freeAll()
{ {
free((void*)this->name); free((void*)this->name);
free((void*)this->publisher); free((void*)this->publisher);
free((void*)this->filename); free((void*)this->filename);
free((void*)this->creator); free((void*)this->creator);
free((void*)this->graphics_artist);
free((void*)this->musician); free((void*)this->musician);
SDL_FreeSurface(this->screenshot); SDL_FreeSurface(this->screenshot);
@ -206,15 +217,20 @@ GameInfo::~GameInfo()
void GameInfo::resetDefaults() void GameInfo::resetDefaults()
{ {
free((void*)this->name); this->freeAll();
free((void*)this->publisher);
free((void*)this->filename);
SDL_FreeSurface(this->screenshot);
this->name = xstrdup(" "); this->name = xstrdup(" ");
this->publisher = xstrdup(" "); this->publisher = xstrdup(" ");
this->filename = xstrdup("unknown"); this->filename = xstrdup("unknown");
this->creator = xstrdup(" ");
this->musician = xstrdup(" ");
this->graphics_artist = xstrdup(" ");
this->screenshot = NULL; this->screenshot = NULL;
this->genre = GENRE_UNKNOWN;
this->players = 1;
this->score = 0;
this->year = 1982;
} }
void *GameInfo::dump(size_t *out_sz) void *GameInfo::dump(size_t *out_sz)

View File

@ -23,6 +23,7 @@ public:
GameInfo(const char *filename = "unknown", const char *name = " ", GameInfo(const char *filename = "unknown", const char *name = " ",
const char *publisher = " ", const char *publisher = " ",
const char *creator = " ", const char *creator = " ",
const char *graphics_artist = " ",
const char *musician = " ", const char *musician = " ",
SDL_Surface *image = NULL); SDL_Surface *image = NULL);
@ -38,14 +39,9 @@ public:
void setScreenshot(SDL_Surface *scr); void setScreenshot(SDL_Surface *scr);
void resetDefaults();
/** Returns an allocated dump structure */ /** Returns an allocated dump structure */
void *dump(size_t *out_sz); void *dump(size_t *out_sz);
/** Fill in this game info object from a structure */
bool fromDump(struct game_info *data);
static GameInfo *loadFromFile(const char *fileName); static GameInfo *loadFromFile(const char *fileName);
/* Should perhaps be protected but I trust you - just be careful! */ /* Should perhaps be protected but I trust you - just be careful! */
@ -54,12 +50,21 @@ public:
const char *filename; const char *filename;
const char *creator; const char *creator;
const char *musician; const char *musician;
const char *graphics_artist;
SDL_Surface *screenshot; SDL_Surface *screenshot;
uint16_t genre; uint16_t genre;
uint16_t players; uint16_t players;
uint16_t year; uint16_t year;
uint16_t score; uint16_t score;
private:
/** Fill in this game info object from a structure */
bool fromDump(struct game_info *data);
void freeAll();
void resetDefaults();
}; };
#endif /*__GAME_INFO_HH__ */ #endif /*__GAME_INFO_HH__ */