mirror of https://github.com/OpenTTD/OpenTTD
(svn r10001) -Codechange: Add support for removing dynamically allocated newgrf data
parent
253aa1b0b0
commit
f8da1b6e1a
|
@ -22,6 +22,11 @@ enum {
|
||||||
INVALID_INDUSTRYTILE = NUM_INDUSTRYTILES, ///< one above amount is considered invalid
|
INVALID_INDUSTRYTILE = NUM_INDUSTRYTILES, ///< one above amount is considered invalid
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CLEAN_RANDOMSOUNDS, ///< Free the dynamically allocated sounds table
|
||||||
|
CLEAN_TILELSAYOUT, ///< Free the dynamically allocated tile layout structure
|
||||||
|
};
|
||||||
|
|
||||||
enum IndustryLifeType {
|
enum IndustryLifeType {
|
||||||
INDUSTRYLIFE_NOT_CLOSABLE, ///< Industry can never close
|
INDUSTRYLIFE_NOT_CLOSABLE, ///< Industry can never close
|
||||||
INDUSTRYLIFE_PRODUCTION, ///< Industry can close and change of production
|
INDUSTRYLIFE_PRODUCTION, ///< Industry can close and change of production
|
||||||
|
@ -135,6 +140,7 @@ struct IndustrySpec {
|
||||||
const uint8 *random_sounds; ///< array of random sounds.
|
const uint8 *random_sounds; ///< array of random sounds.
|
||||||
/* Newgrf data */
|
/* Newgrf data */
|
||||||
uint16 callback_flags; ///< Flags telling which grf callback is set
|
uint16 callback_flags; ///< Flags telling which grf callback is set
|
||||||
|
uint8 cleanup_flag; ///< flags indicating which data should be freed upon cleaning up
|
||||||
bool enabled; ///< entity still avaible (by default true).newgrf can disable it, though
|
bool enabled; ///< entity still avaible (by default true).newgrf can disable it, though
|
||||||
struct GRFFileProps grf_prop; ///< properties related the the grf file
|
struct GRFFileProps grf_prop; ///< properties related the the grf file
|
||||||
};
|
};
|
||||||
|
|
|
@ -4326,6 +4326,24 @@ static void ResetCustomIndustries()
|
||||||
IndustrySpec *ind = file->industryspec[i];
|
IndustrySpec *ind = file->industryspec[i];
|
||||||
|
|
||||||
if (ind != NULL) {
|
if (ind != NULL) {
|
||||||
|
/* We need to remove the sounds array */
|
||||||
|
if (HASBIT(ind->cleanup_flag, CLEAN_RANDOMSOUNDS)) {
|
||||||
|
free((void*)ind->random_sounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We need to remove the tiles layouts */
|
||||||
|
if (HASBIT(ind->cleanup_flag, CLEAN_TILELSAYOUT) && ind->table != NULL) {
|
||||||
|
for (int j = 0; j < ind->num_table; j++) {
|
||||||
|
/* remove the individual layouts */
|
||||||
|
if (ind->table[j] != NULL) {
|
||||||
|
free((IndustryTileTable*)ind->table[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* remove the layouts pointers */
|
||||||
|
free((IndustryTileTable**)ind->table);
|
||||||
|
ind->table = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
free(ind);
|
free(ind);
|
||||||
ind = NULL;
|
ind = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1135,7 +1135,7 @@ static const uint8 _plastic_mine_sounds[] = { SND_33_PLASTIC_MINE };
|
||||||
c1, c2, c3, proc, p1, r1, p2, r2, m, a1, im1, a2, im2, a3, im3, pr, clim, bev, in, intx, s1, s2, s3) \
|
c1, c2, c3, proc, p1, r1, p2, r2, m, a1, im1, a2, im2, a3, im3, pr, clim, bev, in, intx, s1, s2, s3) \
|
||||||
{tbl, lengthof(tbl), d, {c1, c2, c3}, proc, {p1, p2}, {r1, r2}, m, \
|
{tbl, lengthof(tbl), d, {c1, c2, c3}, proc, {p1, p2}, {r1, r2}, m, \
|
||||||
{a1, a2, a3}, {{im1, 0}, {im2, 0}, {im3, 0}}, pr, clim, bev, col, in, intx, s1, s2, s3, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \
|
{a1, a2, a3}, {{im1, 0}, {im2, 0}, {im3, 0}}, pr, clim, bev, col, in, intx, s1, s2, s3, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \
|
||||||
sndc, snd, 0, true, {0, 0, NULL, NULL, INVALID_INDUSTRYTYPE}}
|
sndc, snd, 0, 0, true, {0, 0, NULL, NULL, INVALID_INDUSTRYTYPE}}
|
||||||
/* Format:
|
/* Format:
|
||||||
tile table count and sounds table
|
tile table count and sounds table
|
||||||
cost multiplier appear chances(4ingame, 4random) map colour
|
cost multiplier appear chances(4ingame, 4random) map colour
|
||||||
|
|
Loading…
Reference in New Issue