dry up custom setters, per code review

This commit is contained in:
howard-stearns 2017-01-31 12:07:48 -08:00
parent 1ddc804e10
commit 8d8b338c66

View file

@ -710,55 +710,45 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
// Note: duplicate packets are expected and not wrong. They may be sent for any number of // Note: duplicate packets are expected and not wrong. They may be sent for any number of
// reasons and the contract is that the client handles them in an idempotent manner. // reasons and the contract is that the client handles them in an idempotent manner.
auto lastEdited = lastEditedFromBufferAdjusted; auto lastEdited = lastEditedFromBufferAdjusted;
auto customUpdatePositionFromNetwork = [this, lastEdited, overwriteLocalData, weOwnSimulation, filterRejection](glm::vec3 value){ bool otherOverwrites = overwriteLocalData && !weOwnSimulation;
bool simulationChanged = lastEdited > _lastUpdatedPositionTimestamp; auto shouldUpdate = [lastEdited, otherOverwrites, filterRejection](quint64 updatedTimestamp, bool valueChanged) {
bool valueChanged = value != _lastUpdatedPositionValue; bool simulationChanged = lastEdited > updatedTimestamp;
bool shouldUpdate = overwriteLocalData && !weOwnSimulation && simulationChanged && (valueChanged || filterRejection); return otherOverwrites && simulationChanged && (valueChanged || filterRejection);
if (shouldUpdate) { };
auto customUpdatePositionFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){
if (shouldUpdate(_lastUpdatedPositionTimestamp, value != _lastUpdatedPositionValue)) {
updatePositionFromNetwork(value); updatePositionFromNetwork(value);
_lastUpdatedPositionTimestamp = lastEdited; _lastUpdatedPositionTimestamp = lastEdited;
_lastUpdatedPositionValue = value; _lastUpdatedPositionValue = value;
} }
}; };
auto customUpdateRotationFromNetwork = [this, lastEdited, overwriteLocalData, weOwnSimulation, filterRejection](glm::quat value){ auto customUpdateRotationFromNetwork = [this, shouldUpdate, lastEdited](glm::quat value){
bool simulationChanged = lastEdited > _lastUpdatedRotationTimestamp; if (shouldUpdate(_lastUpdatedRotationTimestamp, value != _lastUpdatedRotationValue)) {
bool valueChanged = value != _lastUpdatedRotationValue;
bool shouldUpdate = overwriteLocalData && !weOwnSimulation && simulationChanged && (valueChanged || filterRejection);
if (shouldUpdate) {
updateRotationFromNetwork(value); updateRotationFromNetwork(value);
_lastUpdatedRotationTimestamp = lastEdited; _lastUpdatedRotationTimestamp = lastEdited;
_lastUpdatedRotationValue = value; _lastUpdatedRotationValue = value;
} }
}; };
auto customUpdateVelocityFromNetwork = [this, lastEdited, overwriteLocalData, weOwnSimulation, filterRejection](glm::vec3 value){ auto customUpdateVelocityFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){
bool simulationChanged = lastEdited > _lastUpdatedVelocityTimestamp; if (shouldUpdate(_lastUpdatedVelocityTimestamp, value != _lastUpdatedVelocityValue)) {
bool valueChanged = value != _lastUpdatedVelocityValue;
bool shouldUpdate = overwriteLocalData && !weOwnSimulation && simulationChanged && (valueChanged || filterRejection);
if (shouldUpdate) {
updateVelocityFromNetwork(value); updateVelocityFromNetwork(value);
_lastUpdatedVelocityTimestamp = lastEdited; _lastUpdatedVelocityTimestamp = lastEdited;
_lastUpdatedVelocityValue = value; _lastUpdatedVelocityValue = value;
} }
}; };
auto customUpdateAngularVelocityFromNetwork = [this, lastEdited, overwriteLocalData, weOwnSimulation, filterRejection](glm::vec3 value){ auto customUpdateAngularVelocityFromNetwork = [this, shouldUpdate, lastEdited](glm::vec3 value){
bool simulationChanged = lastEdited > _lastUpdatedAngularVelocityTimestamp; if (shouldUpdate(_lastUpdatedAngularVelocityTimestamp, value != _lastUpdatedAngularVelocityValue)) {
bool valueChanged = value != _lastUpdatedAngularVelocityValue;
bool shouldUpdate = overwriteLocalData && !weOwnSimulation && simulationChanged && (valueChanged || filterRejection);
if (shouldUpdate) {
updateAngularVelocityFromNetwork(value); updateAngularVelocityFromNetwork(value);
_lastUpdatedAngularVelocityTimestamp = lastEdited; _lastUpdatedAngularVelocityTimestamp = lastEdited;
_lastUpdatedAngularVelocityValue = value; _lastUpdatedAngularVelocityValue = value;
} }
}; };
auto customSetAcceleration = [this, lastEdited, overwriteLocalData, weOwnSimulation, filterRejection](glm::vec3 value){ auto customSetAcceleration = [this, shouldUpdate, lastEdited](glm::vec3 value){
bool simulationChanged = lastEdited > _lastUpdatedAccelerationTimestamp; if (shouldUpdate(_lastUpdatedAccelerationTimestamp, value != _lastUpdatedAccelerationValue)) {
bool valueChanged = value != _lastUpdatedAccelerationValue;
bool shouldUpdate = overwriteLocalData && !weOwnSimulation && simulationChanged && (valueChanged || filterRejection);
if (shouldUpdate) {
setAcceleration(value); setAcceleration(value);
_lastUpdatedAccelerationTimestamp = lastEdited; _lastUpdatedAccelerationTimestamp = lastEdited;
_lastUpdatedAccelerationValue = value; _lastUpdatedAccelerationValue = value;