Address reviews

Changed the activator position parsing to have TryParse so that we dont throw an exception trying to load the position.  Should the loading of the activator position fail the game will default to the position of the entity.

change delimiter value to hex

Updated the character delimiter used for rebuild_activator settings to use hex

Remove extra parsing of activator position

in Entity.cpp we were parsing the activator position but when doing so where we were, this was after we had ended up spawning the activator since that is now in the constructor of the rebuild component.  The extra parsing has been removed.

Simplify dirty parent/child info

Simplify the if condition for parent child info.  This info only needs to be written should it be changed (dirty) or if the packet being sent is a construction, meaning that a requesting player needs all base data and needs to know what parents/children an entity has at that time.

get rid of extra parenthesis

Left over extra parenthesis were around these conditions on accident
This commit is contained in:
EmosewaMC 2022-06-16 08:38:38 -07:00
parent 09c459a083
commit 4a39221dd0
2 changed files with 10 additions and 21 deletions

View File

@ -562,19 +562,6 @@ void Entity::Initialize()
comp->SetPostImaginationCost(rebCompData[0].post_imagination_cost);
comp->SetTimeBeforeSmash(rebCompData[0].time_before_smash);
const auto rebuildActivatorValue = GetVarAsString(u"rebuild_activators");
if (!rebuildActivatorValue.empty()) {
std::vector<std::string> split = GeneralUtils::SplitString(rebuildActivatorValue, 0x1f);
NiPoint3 pos;
pos.x = std::stof(split[0]);
pos.y = std::stof(split[1]);
pos.z = std::stof(split[2]);
comp->SetActivatorPosition(pos);
}
const auto rebuildResetTime = GetVar<float>(u"rebuild_reset_time");
if (rebuildResetTime != 0.0f) {
@ -977,8 +964,8 @@ void Entity::WriteBaseReplicaData(RakNet::BitStream* outBitStream, eReplicaPacke
}
// Only serialize parent / child info should the info be dirty (changed) or if this is the construction of the entity.
outBitStream->Write((m_ParentEntity != nullptr || m_ChildEntities.size() > 0) && (m_IsParentChildDirty || packetType == PACKET_TYPE_CONSTRUCTION));
if ((m_ParentEntity != nullptr || m_ChildEntities.size() > 0) && (m_IsParentChildDirty || packetType == PACKET_TYPE_CONSTRUCTION)) {
outBitStream->Write(m_IsParentChildDirty || packetType == PACKET_TYPE_CONSTRUCTION);
if (m_IsParentChildDirty || packetType == PACKET_TYPE_CONSTRUCTION) {
m_IsParentChildDirty = false;
outBitStream->Write(m_ParentEntity != nullptr);
if (m_ParentEntity) {

View File

@ -24,15 +24,17 @@ RebuildComponent::RebuildComponent(Entity* entity) : Component(entity) {
}
// Should a setting that has the build activator position exist, fetch that setting here and parse it for position.
// It is assumed that the user who sets this setting uses the correct character delimiter (character 31)
auto positionAsVector = GeneralUtils::SplitString(m_Parent->GetVarAsString(u"rebuild_activators"), 31);
if (positionAsVector.size() == 3) {
m_ActivatorPosition.x = std::stof(positionAsVector[0]);
m_ActivatorPosition.y = std::stof(positionAsVector[1]);
m_ActivatorPosition.z = std::stof(positionAsVector[2]);
// It is assumed that the user who sets this setting uses the correct character delimiter (character 31 or in hex 0x1F)
auto positionAsVector = GeneralUtils::SplitString(m_Parent->GetVarAsString(u"rebuild_activators"), 0x1F);
if (positionAsVector.size() == 3 &&
GeneralUtils::TryParse(positionAsVector[0], m_ActivatorPosition.x) &&
GeneralUtils::TryParse(positionAsVector[1], m_ActivatorPosition.y) &&
GeneralUtils::TryParse(positionAsVector[2], m_ActivatorPosition.z)) {
} else {
Game::logger->Log("RebuildComponent", "Failed to find activator position for lot %i. Defaulting to parents position.\n", m_Parent->GetLOT());
m_ActivatorPosition = m_Parent->GetPosition();
}
SpawnActivator();
}