Skip to content

Commit

Permalink
Cleaned up entity initialization.
Browse files Browse the repository at this point in the history
Now each one just has to populate EntityInitInfo.
  • Loading branch information
afritz1 committed Jan 6, 2025
1 parent faf39de commit 07b5260
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 218 deletions.
33 changes: 3 additions & 30 deletions OpenTESArena/src/Entities/CitizenUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ namespace
}

void CitizenUtils::CitizenGenInfo::init(EntityDefID maleEntityDefID, EntityDefID femaleEntityDefID,
const EntityDefinition *maleEntityDef, const EntityDefinition *femaleEntityDef,
EntityAnimationInstance &&maleAnimInst, EntityAnimationInstance &&femaleAnimInst, int raceID)
const EntityDefinition *maleEntityDef, const EntityDefinition *femaleEntityDef, int raceID)
{
this->maleEntityDefID = maleEntityDefID;
this->femaleEntityDefID = femaleEntityDefID;
this->maleEntityDef = maleEntityDef;
this->femaleEntityDef = femaleEntityDef;
this->maleAnimInst = std::move(maleAnimInst);
this->femaleAnimInst = std::move(femaleAnimInst);
this->raceID = raceID;
}

Expand All @@ -66,36 +63,12 @@ CitizenUtils::CitizenGenInfo CitizenUtils::makeCitizenGenInfo(int raceID, ArenaT
DebugCrash("Couldn't get citizen entity def ID from library.");
}

// Only two citizen entity definitions for a given climate, based on the gender.
// Two citizen entity definitions per climate.
const EntityDefinition &maleEntityDef = entityDefLibrary.getDefinition(maleEntityDefID);
const EntityDefinition &femaleEntityDef = entityDefLibrary.getDefinition(femaleEntityDefID);

auto initAnimInst = [](EntityAnimationInstance &animInst, const EntityAnimationDefinition &animDef)
{
for (int i = 0; i < animDef.stateCount; i++)
{
const EntityAnimationDefinitionState &animDefState = animDef.states[i];
animInst.addState(animDefState.seconds, animDefState.isLooping);
}

// Idle animation by default.
const std::optional<int> stateIndex = animDef.tryGetStateIndex(EntityAnimationUtils::STATE_IDLE.c_str());
if (!stateIndex.has_value())
{
DebugLogError("Couldn't get idle state index for citizen.");
return;
}

animInst.setStateIndex(*stateIndex);
};

EntityAnimationInstance maleAnimInst, femaleAnimInst;
initAnimInst(maleAnimInst, maleEntityDef.animDef);
initAnimInst(femaleAnimInst, femaleEntityDef.animDef);

CitizenGenInfo citizenGenInfo;
citizenGenInfo.init(maleEntityDefID, femaleEntityDefID, &maleEntityDef, &femaleEntityDef,
std::move(maleAnimInst), std::move(femaleAnimInst), raceID);
citizenGenInfo.init(maleEntityDefID, femaleEntityDefID, &maleEntityDef, &femaleEntityDef, raceID);
return citizenGenInfo;
}

Expand Down
5 changes: 1 addition & 4 deletions OpenTESArena/src/Entities/CitizenUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ namespace CitizenUtils
EntityDefID femaleEntityDefID;
const EntityDefinition *maleEntityDef;
const EntityDefinition *femaleEntityDef;
EntityAnimationInstance maleAnimInst;
EntityAnimationInstance femaleAnimInst;
int raceID;

void init(EntityDefID maleEntityDefID, EntityDefID femaleEntityDefID, const EntityDefinition *maleEntityDef,
const EntityDefinition *femaleEntityDef, EntityAnimationInstance &&maleAnimInst,
EntityAnimationInstance &&femaleAnimInst, int raceID);
const EntityDefinition *femaleEntityDef, int raceID);
};

bool canMapTypeSpawnCitizens(MapType mapType);
Expand Down
Loading

0 comments on commit 07b5260

Please sign in to comment.