Skip to content

Commit

Permalink
Simplify faction IMD display
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Aug 21, 2023
1 parent d00a6e2 commit 854afb1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 35 deletions.
5 changes: 2 additions & 3 deletions src/component.cpp
Expand Up @@ -167,12 +167,11 @@ UDWORD getStructureStatHeight(STRUCTURE_STATS *psStat)

static void draw_player_3d_shape(uint32_t player_index, iIMDShape *shape, const glm::mat4 &modelMatrix)
{
for (iIMDShape *imd = shape; imd != nullptr; imd = imd->next)
for (iIMDShape *imd = getFactionIMD(getPlayerFaction(player_index), shape); imd != nullptr; imd = imd->next)
{
auto faction_shape = getFactionIMD(getPlayerFaction(player_index), imd);
int team = getPlayerColour(player_index);
const PIELIGHT teamcolour = pal_GetTeamColour(team);
pie_Draw3DButton(faction_shape, teamcolour, modelMatrix, glm::mat4(1.f));
pie_Draw3DButton(imd, teamcolour, modelMatrix, glm::mat4(1.f));
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/display3d.cpp
Expand Up @@ -2670,9 +2670,9 @@ void renderStructure(STRUCTURE *psStructure, const glm::mat4 &viewMatrix, const
const Vector3i dv = Vector3i(psStructure->pos.x, psStructure->pos.z, -(psStructure->pos.y));
bool bHitByElectronic = false;
bool defensive = false;
iIMDShape *strImd = psStructure->sDisplay.imd;
MAPTILE *psTile = worldTile(psStructure->pos.x, psStructure->pos.y);
const FACTION *faction = getPlayerFaction(psStructure->player);
iIMDShape *strImd = getFactionIMD(faction, psStructure->sDisplay.imd);
MAPTILE *psTile = worldTile(psStructure->pos.x, psStructure->pos.y);

glm::mat4 modelMatrix = glm::translate(glm::vec3(dv)) * glm::rotate(UNDEG(-psStructure->rot.direction), glm::vec3(0.f, 1.f, 0.f));

Expand Down Expand Up @@ -2766,7 +2766,7 @@ void renderStructure(STRUCTURE *psStructure, const glm::mat4 &viewMatrix, const
}
if (strImd)
{
pie_Draw3DShape(getFactionIMD(faction, strImd), 0, colour, buildingBrightness, pie_HEIGHT_SCALED | pie_SHADOW, static_cast<int>(structHeightScale(psStructure) * pie_RAISE_SCALE), modelMatrix, viewMatrix);
pie_Draw3DShape(strImd, 0, colour, buildingBrightness, pie_HEIGHT_SCALED | pie_SHADOW, static_cast<int>(structHeightScale(psStructure) * pie_RAISE_SCALE), modelMatrix, viewMatrix);
}
setScreenDispWithPerspective(&psStructure->sDisplay, perspectiveViewMatrix * modelMatrix);
return;
Expand Down Expand Up @@ -2797,10 +2797,10 @@ void renderStructure(STRUCTURE *psStructure, const glm::mat4 &viewMatrix, const
{
stretch = psStructure->pos.z - psStructure->foundationDepth;
}
drawShape(psStructure, getFactionIMD(faction, strImd), colour, buildingBrightness, pieFlag, pieFlagData, modelMatrix, viewMatrix, stretch);
if (psStructure->sDisplay.imd->nconnectors > 0)
drawShape(psStructure, strImd, colour, buildingBrightness, pieFlag, pieFlagData, modelMatrix, viewMatrix, stretch);
if (strImd->nconnectors > 0)
{
renderStructureTurrets(psStructure, getFactionIMD(faction, strImd), buildingBrightness, pieFlag, pieFlagData, ecmFlag, modelMatrix, viewMatrix);
renderStructureTurrets(psStructure, strImd, buildingBrightness, pieFlag, pieFlagData, ecmFlag, modelMatrix, viewMatrix);
}
strImd = strImd->next;
}
Expand Down
14 changes: 0 additions & 14 deletions src/faction.cpp
Expand Up @@ -217,17 +217,3 @@ const char* to_localized_string(FactionID faction)
}
return ""; // silence warning - switch above should be complete
}

void addFactionModelNameMapping(FACTION *faction, const WzString& normalFactionName, const WzString& mappedName)
{
auto result = faction->replaceIMD.insert(FACTION::ReplaceIMDMap::value_type(normalFactionName, mappedName));
if (!result.second)
{
debug(LOG_INFO, "Already inserted this mapping (%s: %s -> %s)", faction->name.toUtf8().c_str(), normalFactionName.toUtf8().c_str(), mappedName.toUtf8().c_str());
}
}

void addFactionModelNameMapping(FactionID faction, const WzString& normalFactionName, const WzString& mappedName)
{
addFactionModelNameMapping(&(factions[(uint8_t)faction]), normalFactionName, mappedName);
}
3 changes: 0 additions & 3 deletions src/faction.h
Expand Up @@ -54,7 +54,4 @@ std::unordered_set<FactionID> getEnabledFactions(bool ignoreNormalFaction = fals
const char* to_string(FactionID faction);
const char* to_localized_string(FactionID faction);

void addFactionModelNameMapping(FACTION *faction, const WzString& normalFactionName, const WzString& mappedName);
void addFactionModelNameMapping(FactionID faction, const WzString& normalFactionName, const WzString& mappedName);

#endif
9 changes: 0 additions & 9 deletions src/levels.cpp
Expand Up @@ -987,15 +987,6 @@ bool levLoadData(char const *name, Sha256 const *hash, char *pSaveName, GAME_TYP
iIMDShape *retval = modelGet(factionModel.value());
ASSERT(retval != nullptr, "Cannot find the faction PIE model %s (for normal model: %s)",
factionModel.value().toUtf8().c_str(), modelName.c_str());
for (const iIMDShape *pIMD = retval, *pNormalIMD = &s; pIMD != nullptr && pNormalIMD != nullptr; pIMD = pIMD->next, pNormalIMD = pNormalIMD->next)
{
if (pIMD->modelLevel <= 0)
{
continue;
}
// Must add mapping to faction IMD lookup table for all additional level modelNames (these have _<level> appended)
addFactionModelNameMapping(faction, pNormalIMD->modelName, pIMD->modelName);
}
}
}
});
Expand Down

0 comments on commit 854afb1

Please sign in to comment.