make construction lazy loaded as well

This commit is contained in:
Tim Felgentreff 2022-04-27 21:27:54 +02:00
parent 875f438778
commit 2cfbbed268
3 changed files with 13 additions and 3 deletions

View file

@ -135,7 +135,7 @@ public:
}
~CConstruction();
void Clean();
void Load();
void Load(bool force = false);
public:
std::string Ident; /// construction identifier

View file

@ -85,7 +85,7 @@ void CConstruction::Clean()
this->ShadowFile.Height = 0;
}
void CConstruction::Load()
void CConstruction::Load(bool force)
{
if (this->Ident.empty()) {
return;
@ -94,6 +94,11 @@ void CConstruction::Load()
this->Width = this->File.Width;
this->Height = this->File.Height;
#ifdef DYNAMIC_LOAD
if (!force) {
return;
}
#endif
if (!file.empty()) {
ShowLoadProgress(_("Construction %s"), file.c_str());
this->Sprite = CPlayerColorGraphic::New(file, this->Width, this->Height);

View file

@ -882,9 +882,14 @@ static void DrawConstruction(const int player, const CConstructionFrame *cframe,
{
PixelPos pos = screenPos;
if (cframe->File == ConstructionFileConstruction) {
const CConstruction &construction = *type.Construction;
CConstruction &construction = *type.Construction;
pos.x -= construction.Width / 2;
pos.y -= construction.Height / 2;
#ifdef DYNAMIC_LOAD
if (!construction.Sprite) {
construction.Load(true);
}
#endif
if (frame < 0) {
construction.Sprite->DrawPlayerColorFrameClipX(player, -frame - 1, pos.x, pos.y);
} else {