Fix for issue #1163 (#1332)

* Clamped power variable before assignment to params in object manager. Attempted to fix formatting issues.

* Fixed Clamp function not implemented correctly.

* Fixed formatting issue, space after commas.

* Created ClampPower method in object_manager.h and implemented in object_manager.cpp, Removed similar code from robotmain.cpp

* Removed redundant call to ClampPower in object_manager.cpp

* Added second call to ClampPower back to object_manager.cpp. Made ClampPower method private. Attempted to fix whitespace issues.

* Fixed missing assignment to params.power in CreateObject method of object_manager.cpp

* fixed white space at end of line 182 in object_manager.h

* Fixed doxygen compatibility issue.
fix-quicksave-sim-speed-crash
Droog71 2020-07-20 15:55:44 -04:00 committed by GitHub
parent f1d6787b08
commit c4385961c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -142,6 +142,8 @@ CObject* CObjectManager::CreateObject(ObjectCreateParams params)
} }
} }
params.power = ClampPower(params.type,params.power);
assert(m_objects.find(params.id) == m_objects.end()); assert(m_objects.find(params.id) == m_objects.end());
auto objectUPtr = m_objectFactory->CreateObject(params); auto objectUPtr = m_objectFactory->CreateObject(params);
@ -163,10 +165,20 @@ CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType
params.angle = angle; params.angle = angle;
params.type = type; params.type = type;
params.power = power; params.power = power;
return CreateObject(params); return CreateObject(params);
} }
float CObjectManager::ClampPower(ObjectType type, float power)
{
float min = 0;
float max = 100;
if (type == OBJECT_POWER || type == OBJECT_ATOMIC)
{
max = 1;
}
return Math::Clamp(power, min, max);
}
std::vector<CObject*> CObjectManager::GetObjectsOfTeam(int team) std::vector<CObject*> CObjectManager::GetObjectsOfTeam(int team)
{ {
std::vector<CObject*> result; std::vector<CObject*> result;

View File

@ -303,6 +303,8 @@ public:
//@} //@}
private: private:
//! Prevents creation of overcharged power cells
float ClampPower(ObjectType type, float power);
void CleanRemovedObjectsIfNeeded(); void CleanRemovedObjectsIfNeeded();
private: private: