saving work

This commit is contained in:
Dante Ruiz 2018-09-21 11:42:26 -07:00
parent 3b1e0dc7d9
commit d3368146ce
5 changed files with 84 additions and 82 deletions

View file

@ -122,6 +122,7 @@
#include <RecordingScriptingInterface.h>
#include <UpdateSceneTask.h>
#include <RenderViewTask.h>
#include <render/EngineStats.h>
#include <SecondaryCamera.h>
#include <ResourceCache.h>
#include <ResourceRequest.h>
@ -5346,8 +5347,8 @@ void Application::resetPhysicsReadyInformation() {
// collision information of nearby entities to make running bullet be safe.
_fullSceneReceivedCounter = 0;
_fullSceneCounterAtLastPhysicsCheck = 0;
_nearbyEntitiesCountAtLastPhysicsCheck = 0;
_nearbyEntitiesStabilityCount = 0;
_gpuTextureMemSizeStabilityCount = 0;
_gpuTextureMemSizeAtLastCheck = 0;
_physicsEnabled = false;
_octreeProcessor.startEntitySequence();
}
@ -5586,18 +5587,20 @@ void Application::update(float deltaTime) {
// for nearby entities before starting bullet up.
quint64 now = usecTimestampNow();
if (isServerlessMode() || _octreeProcessor.isLoadSequenceComplete()) {
// we've received a new full-scene octree stats packet, or it's been long enough to try again anyway
_lastPhysicsCheckTime = now;
_fullSceneCounterAtLastPhysicsCheck = _fullSceneReceivedCounter;
_lastQueriedViews.clear(); // Force new view.
if (gpuTextureMemSizeStable()) {
// we've received a new full-scene octree stats packet, or it's been long enough to try again anyway
_lastPhysicsCheckTime = now;
_fullSceneCounterAtLastPhysicsCheck = _fullSceneReceivedCounter;
_lastQueriedViews.clear(); // Force new view.
// process octree stats packets are sent in between full sends of a scene (this isn't currently true).
// We keep physics disabled until we've received a full scene and everything near the avatar in that
// scene is ready to compute its collision shape.
if (getMyAvatar()->isReadyForPhysics()) {
_physicsEnabled = true;
setIsInterstitialMode(false);
getMyAvatar()->updateMotionBehaviorFromMenu();
// process octree stats packets are sent in between full sends of a scene (this isn't currently true).
// We keep physics disabled until we've received a full scene and everything near the avatar in that
// scene is ready to compute its collision shape.
if (getMyAvatar()->isReadyForPhysics()) {
_physicsEnabled = true;
setIsInterstitialMode(false);
getMyAvatar()->updateMotionBehaviorFromMenu();
}
}
}
} else if (domainLoadingInProgress) {
@ -6234,9 +6237,14 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType) {
const bool isModifiedQuery = !_physicsEnabled;
if (isModifiedQuery) {
// Create modified view that is a simple sphere.
ConicalViewFrustum sphericalView;
ConicalViewFrustum farView;
farView.set(_viewFrustum);
sphericalView.setSimpleRadius(INITIAL_QUERY_RADIUS);
_octreeQuery.setConicalViews({ sphericalView });
_octreeQuery.setConicalViews({ sphericalView, farView });
_octreeQuery.setOctreeSizeScale(DEFAULT_OCTREE_SIZE_SCALE);
static constexpr float MIN_LOD_ADJUST = -20.0f;
_octreeQuery.setBoundaryLevelAdjust(MIN_LOD_ADJUST);
@ -6548,69 +6556,23 @@ void Application::trackIncomingOctreePacket(ReceivedMessage& message, SharedNode
}
}
bool Application::nearbyEntitiesAreReadyForPhysics() {
// this is used to avoid the following scenario:
// A table has some items sitting on top of it. The items are at rest, meaning they aren't active in bullet.
// Someone logs in close to the table. They receive information about the items on the table before they
// receive information about the table. The items are very close to the avatar's capsule, so they become
// activated in bullet. This causes them to fall to the floor, because the table's shape isn't yet in bullet.
EntityTreePointer entityTree = getEntities()->getTree();
if (!entityTree) {
return false;
}
bool Application::gpuTextureMemSizeStable() {
auto renderConfig = qApp->getRenderEngine()->getConfiguration();
auto renderStats = renderConfig->getConfig<render::EngineStats>("Stats");
// We don't want to use EntityTree::findEntities(AABox, ...) method because that scan will snarf parented entities
// whose bounding boxes cannot be computed (it is too loose for our purposes here). Instead we manufacture
// custom filters and use the general-purpose EntityTree::findEntities(filter, ...)
QVector<EntityItemPointer> entities;
AABox avatarBox(getMyAvatar()->getWorldPosition() - glm::vec3(PHYSICS_READY_RANGE), glm::vec3(2 * PHYSICS_READY_RANGE));
// create two functions that use avatarBox (entityScan and elementScan), the second calls the first
std::function<bool (EntityItemPointer&)> entityScan = [=](EntityItemPointer& entity) {
if (entity->shouldBePhysical()) {
bool success = false;
AABox entityBox = entity->getAABox(success);
// important: bail for entities that cannot supply a valid AABox
return success && avatarBox.touches(entityBox);
}
return false;
};
std::function<bool(const OctreeElementPointer&, void*)> elementScan = [&](const OctreeElementPointer& element, void* unused) {
if (element->getAACube().touches(avatarBox)) {
EntityTreeElementPointer entityTreeElement = std::static_pointer_cast<EntityTreeElement>(element);
entityTreeElement->getEntities(entityScan, entities);
return true;
}
return false;
};
quint64 textureResourceGPUMemSize = renderStats->textureResourceGPUMemSize;
quint64 texturePopulatedGPUMemSize = renderStats->textureResourcePopulatedGPUMemSize;
entityTree->withReadLock([&] {
// Pass the second function to the general-purpose EntityTree::findEntities()
// which will traverse the tree, apply the two filter functions (to element, then to entities)
// as it traverses. The end result will be a list of entities that match.
entityTree->findEntities(elementScan, entities);
});
uint32_t nearbyCount = entities.size();
if (nearbyCount == _nearbyEntitiesCountAtLastPhysicsCheck) {
_nearbyEntitiesStabilityCount++;
if (_gpuTextureMemSizeAtLastCheck == textureResourceGPUMemSize) {
_gpuTextureMemSizeStabilityCount++;
} else {
_nearbyEntitiesStabilityCount = 0;
_gpuTextureMemSizeStabilityCount = 0;
}
_nearbyEntitiesCountAtLastPhysicsCheck = nearbyCount;
_gpuTextureMemSizeAtLastCheck = textureResourceGPUMemSize;
const uint32_t MINIMUM_NEARBY_ENTITIES_STABILITY_COUNT = 3;
if (_nearbyEntitiesStabilityCount >= MINIMUM_NEARBY_ENTITIES_STABILITY_COUNT) {
// We've seen the same number of nearby entities for several stats packets in a row. assume we've got all
// the local entities.
bool result = true;
foreach (EntityItemPointer entity, entities) {
if (entity->shouldBePhysical() && !entity->isReadyToComputeShape()) {
HIFI_FCDEBUG(interfaceapp(), "Physics disabled until entity loads: " << entity->getID() << entity->getName());
// don't break here because we want all the relevant entities to start their downloads
result = false;
}
}
return result;
const uint32_t MINIMUM_GPU_TEXTURE_MEM_SIZE_STABILITY_COUNT = 10;
if (_gpuTextureMemSizeStabilityCount >= MINIMUM_GPU_TEXTURE_MEM_SIZE_STABILITY_COUNT) {
return (textureResourceGPUMemSize == texturePopulatedGPUMemSize);
}
return false;
}

View file

@ -528,7 +528,7 @@ private:
bool importFromZIP(const QString& filePath);
bool importImage(const QString& urlString);
bool nearbyEntitiesAreReadyForPhysics();
bool gpuTextureMemSizeStable();
int processOctreeStats(ReceivedMessage& message, SharedNodePointer sendingNode);
void trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket);
@ -725,8 +725,10 @@ private:
std::atomic<uint32_t> _fullSceneReceivedCounter { 0 }; // how many times have we received a full-scene octree stats packet
uint32_t _fullSceneCounterAtLastPhysicsCheck { 0 }; // _fullSceneReceivedCounter last time we checked physics ready
uint32_t _nearbyEntitiesCountAtLastPhysicsCheck { 0 }; // how many in-range entities last time we checked physics ready
uint32_t _nearbyEntitiesStabilityCount { 0 }; // how many times has _nearbyEntitiesCountAtLastPhysicsCheck been the same
quint64 _gpuTextureMemSizeStabilityCount { 0 };
quint64 _gpuTextureMemSizeAtLastCheck { 0 };
quint64 _lastPhysicsCheckTime { usecTimestampNow() }; // when did we last check to see if physics was ready
bool _keyboardDeviceHasFocus { true };

View file

@ -171,6 +171,9 @@ bool SafeLanding::isEntityLoadingComplete() {
bool isVisuallyReady = true;
qDebug() << "EntityTpye" << EntityTypes::getEntityTypeName(entity->getType()) << entity->getEntityItemID();
Settings settings;
bool enableInterstitial = settings.value("enableIntersitialMode", false).toBool();
@ -188,6 +191,7 @@ bool SafeLanding::isEntityLoadingComplete() {
entityMapIter++;
}
}
qDebug() << "EntityList size" << _trackedEntities.size() << "\n";
return _trackedEntities.empty();
}

View file

@ -75,4 +75,4 @@ Item {
}
}
}
}

View file

@ -14,7 +14,7 @@
(function() {
Script.include("/~/system/libraries/Xform.js");
var DEBUG = false;
var DEBUG = true;
var MIN_LOADING_PROGRESS = 3.6;
var TOTAL_LOADING_PROGRESS = 3.8;
var EPSILON = 0.01;
@ -186,6 +186,8 @@
var currentDomain = "no domain";
var timer = null;
var target = 0;
var textureMemSizeStabilityCount = 0;
var textureMemSizeAtLastCheck = 0;
var connectionToDomainFailed = false;
@ -228,6 +230,8 @@
updateOverlays(false);
startAudio();
target = 0;
textureMemSizeStabilityCount = 0;
textureMemSizeAtLastCheck = 0;
currentProgress = 0.1;
connectionToDomainFailed = false;
previousCameraMode = Camera.mode;
@ -348,10 +352,11 @@
Overlays.editOverlay(loadingBarPlacard, properties);
Overlays.editOverlay(loadingBarProgress, loadingBarProperties);
Menu.setIsOptionChecked("Show Overlays", physicsEnabled);
if (!HMD.active) {
toolbar.writeProperty("visible", physicsEnabled);
if (!DEBUG) {
Menu.setIsOptionChecked("Show Overlays", physicsEnabled);
if (!HMD.active) {
toolbar.writeProperty("visible", physicsEnabled);
}
}
resetValues();
@ -374,6 +379,7 @@
}
function update() {
var renderStats = Render.getConfig("Stats");
var physicsEnabled = Window.isPhysicsEnabled();
var thisInterval = Date.now();
var deltaTime = (thisInterval - lastInterval);
@ -381,11 +387,39 @@
var domainLoadingProgressPercentage = Window.domainLoadingProgress();
var progress = MIN_LOADING_PROGRESS * domainLoadingProgressPercentage;
var progress = ((TOTAL_LOADING_PROGRESS * 0.4) * domainLoadingProgressPercentage);
if (progress >= target) {
target = progress;
}
if (currentProgress >= (TOTAL_LOADING_PROGRESS * 0.4)) {
var textureResourceGPUMemSize = renderStats.textureResourceGPUMemSize;
var texturePopulatedGPUMemSize = renderStats.textureResourcePopulatedGPUMemSize;
if (textureMemSizeAtLastCheck === textureResourceGPUMemSize) {
textureMemSizeStabilityCount++;
} else {
textureMemSizeStabilityCount = 0;
}
textureMemSizeAtLastCheck = textureResourceGPUMemSize;
if (textureMemSizeStabilityCount >= 15) {
if (textureResourceGPUMemSize > 0) {
print((texturePopulatedGPUMemSize / textureResourceGPUMemSize));
var gpuPercantage = (TOTAL_LOADING_PROGRESS * 0.6) * (texturePopulatedGPUMemSize / textureResourceGPUMemSize);
print("---> gpu: " + gpuPercantage);
print("----> current: " + progress);
var totalProgress = progress + gpuPercantage;
print("------> totalProgress: " + totalProgress + "\n");
if (totalProgress >= target) {
target = totalProgress;
}
}
}
}
if ((physicsEnabled && (currentProgress < TOTAL_LOADING_PROGRESS))) {
target = TOTAL_LOADING_PROGRESS;
}