mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use vector instead of mallloc/free for Action 6 data. (#10713)
parent
1697dff744
commit
7535eb65e2
|
@ -378,7 +378,7 @@ struct GRFLocation {
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::map<GRFLocation, SpriteID> _grm_sprites;
|
static std::map<GRFLocation, SpriteID> _grm_sprites;
|
||||||
typedef std::map<GRFLocation, byte*> GRFLineToSpriteOverride;
|
typedef std::map<GRFLocation, std::vector<byte>> GRFLineToSpriteOverride;
|
||||||
static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
|
static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6690,34 +6690,30 @@ static void CfgApply(ByteReader *buf)
|
||||||
size_t pos = file.GetPos();
|
size_t pos = file.GetPos();
|
||||||
uint32 num = file.GetContainerVersion() >= 2 ? file.ReadDword() : file.ReadWord();
|
uint32 num = file.GetContainerVersion() >= 2 ? file.ReadDword() : file.ReadWord();
|
||||||
uint8 type = file.ReadByte();
|
uint8 type = file.ReadByte();
|
||||||
byte *preload_sprite = nullptr;
|
|
||||||
|
|
||||||
/* Check if the sprite is a pseudo sprite. We can't operate on real sprites. */
|
/* Check if the sprite is a pseudo sprite. We can't operate on real sprites. */
|
||||||
if (type == 0xFF) {
|
if (type != 0xFF) {
|
||||||
preload_sprite = MallocT<byte>(num);
|
GrfMsg(2, "CfgApply: Ignoring (next sprite is real, unsupported)");
|
||||||
file.ReadBlock(preload_sprite, num);
|
|
||||||
|
/* Reset the file position to the start of the next sprite */
|
||||||
|
file.SeekTo(pos, SEEK_SET);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get (or create) the override for the next sprite. */
|
||||||
|
GRFLocation location(_cur.grfconfig->ident.grfid, _cur.nfo_line + 1);
|
||||||
|
std::vector<byte> &preload_sprite = _grf_line_to_action6_sprite_override[location];
|
||||||
|
|
||||||
|
/* Load new sprite data if it hasn't already been loaded. */
|
||||||
|
if (preload_sprite.empty()) {
|
||||||
|
preload_sprite.resize(num);
|
||||||
|
file.ReadBlock(preload_sprite.data(), num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset the file position to the start of the next sprite */
|
/* Reset the file position to the start of the next sprite */
|
||||||
file.SeekTo(pos, SEEK_SET);
|
file.SeekTo(pos, SEEK_SET);
|
||||||
|
|
||||||
if (type != 0xFF) {
|
|
||||||
GrfMsg(2, "CfgApply: Ignoring (next sprite is real, unsupported)");
|
|
||||||
free(preload_sprite);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GRFLocation location(_cur.grfconfig->ident.grfid, _cur.nfo_line + 1);
|
|
||||||
GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
|
|
||||||
if (it != _grf_line_to_action6_sprite_override.end()) {
|
|
||||||
free(preload_sprite);
|
|
||||||
preload_sprite = _grf_line_to_action6_sprite_override[location];
|
|
||||||
} else {
|
|
||||||
_grf_line_to_action6_sprite_override[location] = preload_sprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now perform the Action 0x06 on our data. */
|
/* Now perform the Action 0x06 on our data. */
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
uint i;
|
uint i;
|
||||||
uint param_num;
|
uint param_num;
|
||||||
|
@ -9484,7 +9480,7 @@ static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage)
|
||||||
_cur.file->ReadBlock(buf, num);
|
_cur.file->ReadBlock(buf, num);
|
||||||
} else {
|
} else {
|
||||||
/* Use the preloaded sprite data. */
|
/* Use the preloaded sprite data. */
|
||||||
buf = _grf_line_to_action6_sprite_override[location];
|
buf = _grf_line_to_action6_sprite_override[location].data();
|
||||||
GrfMsg(7, "DecodeSpecialSprite: Using preloaded pseudo sprite data");
|
GrfMsg(7, "DecodeSpecialSprite: Using preloaded pseudo sprite data");
|
||||||
|
|
||||||
/* Skip the real (original) content of this action. */
|
/* Skip the real (original) content of this action. */
|
||||||
|
@ -9820,10 +9816,7 @@ static void AfterLoadGRFs()
|
||||||
}
|
}
|
||||||
_string_to_grf_mapping.clear();
|
_string_to_grf_mapping.clear();
|
||||||
|
|
||||||
/* Free the action 6 override sprites. */
|
/* Clear the action 6 override sprites. */
|
||||||
for (GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.begin(); it != _grf_line_to_action6_sprite_override.end(); it++) {
|
|
||||||
free((*it).second);
|
|
||||||
}
|
|
||||||
_grf_line_to_action6_sprite_override.clear();
|
_grf_line_to_action6_sprite_override.clear();
|
||||||
|
|
||||||
/* Polish cargoes */
|
/* Polish cargoes */
|
||||||
|
|
Loading…
Reference in New Issue