Merge remote-tracking branch 'upstream/master' into particles

This commit is contained in:
Jeffrey Ventrella 2013-07-17 16:03:38 -07:00
commit 4389389f17
7 changed files with 45 additions and 23 deletions

View file

@ -98,6 +98,7 @@ Avatar::Avatar(Node* owningNode) :
_elapsedTimeMoving(0.0f), _elapsedTimeMoving(0.0f),
_elapsedTimeStopped(0.0f), _elapsedTimeStopped(0.0f),
_elapsedTimeSinceCollision(0.0f), _elapsedTimeSinceCollision(0.0f),
_lastCollisionPosition(0, 0, 0),
_speedBrakes(false), _speedBrakes(false),
_isThrustOn(false), _isThrustOn(false),
_voxels(this) _voxels(this)
@ -541,11 +542,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
// For gravity, always move the avatar by the amount driven by gravity, so that the collision // For gravity, always move the avatar by the amount driven by gravity, so that the collision
// routines will detect it and collide every frame when pulled by gravity to a surface // routines will detect it and collide every frame when pulled by gravity to a surface
// //
const float MIN_DISTANCE_AFTER_COLLISION_FOR_GRAVITY = 0.02f;
_velocity += _scale * _gravity * (GRAVITY_EARTH * deltaTime); if (glm::length(_position - _lastCollisionPosition) > MIN_DISTANCE_AFTER_COLLISION_FOR_GRAVITY) {
_position += _scale * _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime; _velocity += _scale * _gravity * (GRAVITY_EARTH * deltaTime);
}
} }
updateCollisionWithEnvironment(deltaTime); updateCollisionWithEnvironment(deltaTime);
updateCollisionWithVoxels(deltaTime); updateCollisionWithVoxels(deltaTime);
updateAvatarCollisions(deltaTime); updateAvatarCollisions(deltaTime);
@ -890,11 +891,9 @@ void Avatar::updateCollisionWithEnvironment(float deltaTime) {
if (velocityTowardCollision > VISIBLE_GROUND_COLLISION_VELOCITY) { if (velocityTowardCollision > VISIBLE_GROUND_COLLISION_VELOCITY) {
Application::getInstance()->setGroundPlaneImpact(1.0f); Application::getInstance()->setGroundPlaneImpact(1.0f);
} }
_lastCollisionPosition = _position;
updateCollisionSound(penetration, deltaTime, ENVIRONMENT_COLLISION_FREQUENCY); updateCollisionSound(penetration, deltaTime, ENVIRONMENT_COLLISION_FREQUENCY);
applyHardCollision(penetration, ENVIRONMENT_SURFACE_ELASTICITY, ENVIRONMENT_SURFACE_DAMPING); applyHardCollision(penetration, ENVIRONMENT_SURFACE_ELASTICITY, ENVIRONMENT_SURFACE_DAMPING);
} }
} }
@ -908,6 +907,7 @@ void Avatar::updateCollisionWithVoxels(float deltaTime) {
if (Application::getInstance()->getVoxels()->findCapsulePenetration( if (Application::getInstance()->getVoxels()->findCapsulePenetration(
_position - glm::vec3(0.0f, _pelvisFloatingHeight - radius, 0.0f), _position - glm::vec3(0.0f, _pelvisFloatingHeight - radius, 0.0f),
_position + glm::vec3(0.0f, _height - _pelvisFloatingHeight - radius, 0.0f), radius, penetration)) { _position + glm::vec3(0.0f, _height - _pelvisFloatingHeight - radius, 0.0f), radius, penetration)) {
_lastCollisionPosition = _position;
updateCollisionSound(penetration, deltaTime, VOXEL_COLLISION_FREQUENCY); updateCollisionSound(penetration, deltaTime, VOXEL_COLLISION_FREQUENCY);
applyHardCollision(penetration, VOXEL_ELASTICITY, VOXEL_DAMPING); applyHardCollision(penetration, VOXEL_ELASTICITY, VOXEL_DAMPING);
} }

View file

@ -118,7 +118,8 @@ public:
const glm::vec3& amplifyAngle, const glm::vec3& amplifyAngle,
float yawFromTouch, float yawFromTouch,
float pitchFromTouch); float pitchFromTouch);
void addBodyYaw(float y) {_bodyYaw += y;}; void addBodyYaw(float bodyYaw) {_bodyYaw += bodyYaw;};
void addBodyYawDelta(float bodyYawDelta) {_bodyYawDelta += bodyYawDelta;}
void render(bool lookingInMirror, bool renderAvatarBalls); void render(bool lookingInMirror, bool renderAvatarBalls);
//setters //setters
@ -155,6 +156,7 @@ public:
float getElapsedTimeStopped () const { return _elapsedTimeStopped;} float getElapsedTimeStopped () const { return _elapsedTimeStopped;}
float getElapsedTimeMoving () const { return _elapsedTimeMoving;} float getElapsedTimeMoving () const { return _elapsedTimeMoving;}
float getElapsedTimeSinceCollision() const { return _elapsedTimeSinceCollision;} float getElapsedTimeSinceCollision() const { return _elapsedTimeSinceCollision;}
const glm::vec3& getLastCollisionPosition () const { return _lastCollisionPosition;}
float getAbsoluteHeadYaw () const; float getAbsoluteHeadYaw () const;
float getAbsoluteHeadPitch () const; float getAbsoluteHeadPitch () const;
Head& getHead () {return _head; } Head& getHead () {return _head; }
@ -245,6 +247,7 @@ private:
float _elapsedTimeMoving; // Timers to drive camera transitions when moving float _elapsedTimeMoving; // Timers to drive camera transitions when moving
float _elapsedTimeStopped; float _elapsedTimeStopped;
float _elapsedTimeSinceCollision; float _elapsedTimeSinceCollision;
glm::vec3 _lastCollisionPosition;
bool _speedBrakes; bool _speedBrakes;
bool _isThrustOn; bool _isThrustOn;

View file

@ -1114,14 +1114,12 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
return bytesAtThisLevel; return bytesAtThisLevel;
} }
/** Not ready for production - coming soon. // If we're not in delta sending mode, and we weren't asked to do a force send, and the voxel hasn't changed,
// If we're not in delta sending mode, but the voxel hasn't changed, then we can also bail early... // then we can also bail early and save bits
if (!params.deltaViewFrustum && !node->hasChangedSince(params.lastViewFrustumSent - CHANGE_FUDGE)) { if (!params.forceSendScene && !params.deltaViewFrustum &&
printf("not delta sending, and the node hasn't changed, bail early... lastSent=%lld getLastChanged=%lld\n", !node->hasChangedSince(params.lastViewFrustumSent - CHANGE_FUDGE)) {
params.lastViewFrustumSent, node->getLastChanged());
return bytesAtThisLevel; return bytesAtThisLevel;
} }
**/
// If the user also asked for occlusion culling, check if this node is occluded, but only if it's not a leaf. // If the user also asked for occlusion culling, check if this node is occluded, but only if it's not a leaf.
// leaf occlusion is handled down below when we check child nodes // leaf occlusion is handled down below when we check child nodes

View file

@ -51,7 +51,7 @@ public:
long childWasInViewDiscarded; long childWasInViewDiscarded;
int boundaryLevelAdjust; int boundaryLevelAdjust;
uint64_t lastViewFrustumSent; uint64_t lastViewFrustumSent;
bool forceSendScene;
CoverageMap* map; CoverageMap* map;
EncodeBitstreamParams( EncodeBitstreamParams(
@ -65,7 +65,8 @@ public:
bool wantOcclusionCulling= NO_OCCLUSION_CULLING, bool wantOcclusionCulling= NO_OCCLUSION_CULLING,
CoverageMap* map = IGNORE_COVERAGE_MAP, CoverageMap* map = IGNORE_COVERAGE_MAP,
int boundaryLevelAdjust = NO_BOUNDARY_ADJUST, int boundaryLevelAdjust = NO_BOUNDARY_ADJUST,
uint64_t lastViewFrustumSent = IGNORE_LAST_SENT) : uint64_t lastViewFrustumSent = IGNORE_LAST_SENT,
bool forceSendScene = true) :
maxEncodeLevel (maxEncodeLevel), maxEncodeLevel (maxEncodeLevel),
maxLevelReached (0), maxLevelReached (0),
viewFrustum (viewFrustum), viewFrustum (viewFrustum),
@ -78,6 +79,7 @@ public:
childWasInViewDiscarded (0), childWasInViewDiscarded (0),
boundaryLevelAdjust (boundaryLevelAdjust), boundaryLevelAdjust (boundaryLevelAdjust),
lastViewFrustumSent (lastViewFrustumSent), lastViewFrustumSent (lastViewFrustumSent),
forceSendScene (forceSendScene),
map (map) map (map)
{} {}
}; };

View file

@ -20,6 +20,7 @@ VoxelNodeData::VoxelNodeData(Node* owningNode) :
_maxLevelReachedInLastSearch(1), _maxLevelReachedInLastSearch(1),
_lastTimeBagEmpty(0), _lastTimeBagEmpty(0),
_viewFrustumChanging(false), _viewFrustumChanging(false),
_viewFrustumJustStoppedChanging(true),
_currentPacketIsColor(true) _currentPacketIsColor(true)
{ {
_voxelPacket = new unsigned char[MAX_VOXEL_PACKET_SIZE]; _voxelPacket = new unsigned char[MAX_VOXEL_PACKET_SIZE];
@ -69,10 +70,25 @@ bool VoxelNodeData::updateCurrentViewFrustum() {
_currentViewFrustum.calculate(); _currentViewFrustum.calculate();
currentViewFrustumChanged = true; currentViewFrustumChanged = true;
} }
// When we first detect that the view stopped changing, we record this.
// but we don't change it back to false until we've completely sent this
// scene.
if (_viewFrustumChanging && !currentViewFrustumChanged) {
_viewFrustumJustStoppedChanging = true;
}
_viewFrustumChanging = currentViewFrustumChanged; _viewFrustumChanging = currentViewFrustumChanged;
return currentViewFrustumChanged; return currentViewFrustumChanged;
} }
void VoxelNodeData::setViewSent(bool viewSent) {
_viewSent = viewSent;
if (viewSent) {
_viewFrustumJustStoppedChanging = false;
}
}
void VoxelNodeData::updateLastKnownViewFrustum() { void VoxelNodeData::updateLastKnownViewFrustum() {
bool frustumChanges = !_lastKnownViewFrustum.matches(_currentViewFrustum); bool frustumChanges = !_lastKnownViewFrustum.matches(_currentViewFrustum);

View file

@ -48,7 +48,11 @@ public:
void updateLastKnownViewFrustum(); void updateLastKnownViewFrustum();
bool getViewSent() const { return _viewSent; }; bool getViewSent() const { return _viewSent; };
void setViewSent(bool viewSent) { _viewSent = viewSent; } void setViewSent(bool viewSent);
bool getViewFrustumChanging() const { return _viewFrustumChanging; };
bool getViewFrustumJustStoppedChanging() const { return _viewFrustumJustStoppedChanging; };
uint64_t getLastTimeBagEmpty() const { return _lastTimeBagEmpty; }; uint64_t getLastTimeBagEmpty() const { return _lastTimeBagEmpty; };
void setLastTimeBagEmpty(uint64_t lastTimeBagEmpty) { _lastTimeBagEmpty = lastTimeBagEmpty; }; void setLastTimeBagEmpty(uint64_t lastTimeBagEmpty) { _lastTimeBagEmpty = lastTimeBagEmpty; };
@ -69,6 +73,7 @@ private:
ViewFrustum _lastKnownViewFrustum; ViewFrustum _lastKnownViewFrustum;
uint64_t _lastTimeBagEmpty; uint64_t _lastTimeBagEmpty;
bool _viewFrustumChanging; bool _viewFrustumChanging;
bool _viewFrustumJustStoppedChanging;
bool _currentPacketIsColor; bool _currentPacketIsColor;
}; };

View file

@ -205,6 +205,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
} }
} }
// This is the start of "resending" the scene.
nodeData->nodeBag.insert(serverTree.rootNode); nodeData->nodeBag.insert(serverTree.rootNode);
} }
@ -242,15 +243,12 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
EncodeBitstreamParams params(INT_MAX, &nodeData->getCurrentViewFrustum(), wantColor, EncodeBitstreamParams params(INT_MAX, &nodeData->getCurrentViewFrustum(), wantColor,
WANT_EXISTS_BITS, DONT_CHOP, wantDelta, lastViewFrustum, WANT_EXISTS_BITS, DONT_CHOP, wantDelta, lastViewFrustum,
wantOcclusionCulling, coverageMap, boundaryLevelAdjust, wantOcclusionCulling, coverageMap, boundaryLevelAdjust,
nodeData->getLastTimeBagEmpty()); nodeData->getLastTimeBagEmpty(),
nodeData->getViewFrustumJustStoppedChanging());
bytesWritten = serverTree.encodeTreeBitstream(subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, bytesWritten = serverTree.encodeTreeBitstream(subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1,
nodeData->nodeBag, params); nodeData->nodeBag, params);
if (::debugVoxelSending && wantDelta) {
printf("encodeTreeBitstream() childWasInViewDiscarded=%ld\n", params.childWasInViewDiscarded);
}
if (nodeData->getAvailable() >= bytesWritten) { if (nodeData->getAvailable() >= bytesWritten) {
nodeData->writeToPacket(&tempOutputBuffer[0], bytesWritten); nodeData->writeToPacket(&tempOutputBuffer[0], bytesWritten);
} else { } else {