Skip to content

Commit

Permalink
When building a module, don't visually rebuild the whole building.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyp committed Dec 1, 2011
1 parent af8088f commit 999b559
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/display3d.cpp
Expand Up @@ -2218,6 +2218,11 @@ void renderStructure(STRUCTURE *psStructure)
//first check if partially built - ANOTHER HACK!
if (psStructure->status == SS_BEING_BUILT || psStructure->status == SS_BEING_DEMOLISHED)
{
if (psStructure->prebuiltImd != NULL)
{
// strImd is a module, so render the already-built part at full height.
pie_Draw3DShape(psStructure->prebuiltImd, 0, colour, buildingBrightness, pie_SHADOW, 0);
}
pie_Draw3DShape(strImd, 0, colour, buildingBrightness, pie_HEIGHT_SCALED | pie_SHADOW, structHeightScale(psStructure) * pie_RAISE_SCALE);
}
else
Expand Down
14 changes: 13 additions & 1 deletion src/structure.cpp
Expand Up @@ -1734,7 +1734,9 @@ STRUCTURE* buildStructureDir(STRUCTURE_STATS *pStructureType, UDWORD x, UDWORD y
if (bUpgraded)
{
std::vector<iIMDShape *> &IMDs = psBuilding->pStructureType->pIMD;
psBuilding->sDisplay.imd = IMDs[std::min<int>(capacity*2, IMDs.size() - 1)]; // *2 because even-numbered IMDs are structures, odd-numbered IMDs are just the modules.
int imdIndex = std::min<int>(capacity*2, IMDs.size() - 1) - 1; // *2-1 because even-numbered IMDs are structures, odd-numbered IMDs are just the modules, and we want just the module since we cache the fully-built part of the building in psBuilding->prebuiltImd.
psBuilding->prebuiltImd = psBuilding->sDisplay.imd;
psBuilding->sDisplay.imd = IMDs[imdIndex];

//calculate the new body points of the owning structure
psBuilding->body = (uint64_t)structureBody(psBuilding) * bodyDiff / 65536;
Expand Down Expand Up @@ -3794,6 +3796,7 @@ STRUCTURE::STRUCTURE(uint32_t id, unsigned player)
, buildRate(1) // Initialise to 1 instead of 0, to make sure we don't get destroyed first tick due to inactivity.
, lastBuildRate(0)
, psCurAnim(NULL)
, prebuiltImd(NULL)
{}

/* Release all resources associated with a structure */
Expand Down Expand Up @@ -5625,6 +5628,15 @@ void buildingComplete(STRUCTURE *psBuilding)

visTilesUpdate(psBuilding);

if (psBuilding->prebuiltImd != NULL)
{
// We finished building a module, now use the combined IMD.
std::vector<iIMDShape *> &IMDs = psBuilding->pStructureType->pIMD;
int imdIndex = std::min<int>(numStructureModules(psBuilding)*2, IMDs.size() - 1); // *2 because even-numbered IMDs are structures, odd-numbered IMDs are just the modules.
psBuilding->prebuiltImd = NULL;
psBuilding->sDisplay.imd = IMDs[imdIndex];
}

switch (psBuilding->pStructureType->type)
{
case REF_POWER_GEN:
Expand Down
2 changes: 2 additions & 0 deletions src/structuredef.h
Expand Up @@ -280,6 +280,8 @@ struct STRUCTURE : public BASE_OBJECT

STRUCT_ANIM_STATES state;
UDWORD lastStateTime;

iIMDShape * prebuiltImd;
};

#define LOTS_OF 0xFFFFFFFF // highest number the limit can be set to
Expand Down

0 comments on commit 999b559

Please sign in to comment.