Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Jason Hawks 2015-02-14 07:48:24 -05:00
commit ae1c55b034
22 changed files with 191 additions and 100 deletions

View file

@ -208,7 +208,7 @@ void Agent::run() {
_scriptEngine.init(); // must be done before we set up the viewers
_scriptEngine.registerGlobalObject("SoundCache", &SoundCache::getInstance());
_scriptEngine.registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
_scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer);
_entityViewer.setJurisdictionListener(_scriptEngine.getEntityScriptingInterface()->getJurisdictionListener());

View file

@ -136,7 +136,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) :
// Create Singleton objects on main thread
NetworkAccessManager::getInstance();
SoundCache::getInstance();
auto soundCache = DependencyManager::get<SoundCache>();
}
void AssignmentClient::sendAssignmentRequest() {

View file

@ -147,3 +147,14 @@ void EntityServer::pruneDeletedEntities() {
}
}
void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectionObject) {
bool wantEditLogging = false;
readOptionBool(QString("wantEditLogging"), settingsSectionObject, wantEditLogging);
qDebug("wantEditLogging=%s", debug::valueOf(wantEditLogging));
EntityTree* tree = static_cast<EntityTree*>(_tree);
tree->setWantEditLogging(wantEditLogging);
}

View file

@ -41,6 +41,7 @@ public:
virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent);
virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode);
virtual void readAdditionalConfiguration(const QJsonObject& settingsSectionObject);
public slots:
void pruneDeletedEntities();

View file

@ -409,6 +409,13 @@
"default": "",
"advanced": true
},
{
"name": "wantEditLogging",
"type": "checkbox",
"help": "Logging of all edits to entities",
"default": true,
"advanced": true
},
{
"name": "verboseDebug",
"type": "checkbox",

View file

@ -959,9 +959,18 @@ PropertiesTool = function(opts) {
selectionManager.saveProperties();
for (var i = 0; i < selectionManager.selections.length; i++) {
var properties = selectionManager.savedProperties[selectionManager.selections[i].id];
Entities.editEntity(selectionManager.selections[i], {
dimensions: properties.naturalDimensions,
});
var naturalDimensions = properties.naturalDimensions;
// If any of the natural dimensions are not 0, resize
if (properties.type == "Model" && naturalDimensions.x == 0
&& naturalDimensions.y == 0 && naturalDimensions.z == 0) {
Window.alert("Cannot reset entity to its natural dimensions: Model URL"
+ " is invalid or the model has not yet been loaded.");
} else {
Entities.editEntity(selectionManager.selections[i], {
dimensions: properties.naturalDimensions,
});
}
}
pushCommandForSelections();
selectionManager._update();

View file

@ -65,6 +65,7 @@
#include <HFBackEvent.h>
#include <LogHandler.h>
#include <MainWindow.h>
#include <ModelEntityItem.h>
#include <NetworkAccessManager.h>
#include <OctalCode.h>
#include <OctreeSceneStats.h>
@ -211,6 +212,8 @@ bool setupEssentials(int& argc, char** argv) {
auto addressManager = DependencyManager::set<AddressManager>();
auto nodeList = DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
auto geometryCache = DependencyManager::set<GeometryCache>();
auto scriptCache = DependencyManager::set<ScriptCache>();
auto soundCache = DependencyManager::set<SoundCache>();
auto glowEffect = DependencyManager::set<GlowEffect>();
auto faceshift = DependencyManager::set<Faceshift>();
auto audio = DependencyManager::set<AudioClient>();
@ -523,13 +526,21 @@ void Application::aboutToQuit() {
}
void Application::cleanupBeforeQuit() {
// make sure we don't call the idle timer any more
delete idleTimer;
// save state
QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection);
_settingsThread.quit();
saveSettings();
_window->saveGeometry();
// TODO: now that this is in cleanupBeforeQuit do we really need it to stop and force
// an event loop to send the packet?
UserActivityLogger::getInstance().close();
// let the avatar mixer know we're out
MyAvatar::sendKillAvatar();
// stop the AudioClient
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
@ -540,16 +551,12 @@ void Application::cleanupBeforeQuit() {
}
Application::~Application() {
EntityTree* tree = _entities.getTree();
tree->lockForWrite();
_entities.getTree()->setSimulation(NULL);
tree->unlock();
qInstallMessageHandler(NULL);
_window->saveGeometry();
// make sure we don't call the idle timer any more
delete idleTimer;
// let the avatar mixer know we're out
MyAvatar::sendKillAvatar();
// ask the datagram processing thread to quit and wait until it is done
_nodeThread->quit();
@ -561,13 +568,18 @@ Application::~Application() {
Menu::getInstance()->deleteLater();
_myAvatar = NULL;
ModelEntityItem::cleanupLoadedAnimations() ;
DependencyManager::destroy<GLCanvas>();
qDebug() << "start destroying ResourceCaches Application::~Application() line:" << __LINE__;
DependencyManager::destroy<AnimationCache>();
DependencyManager::destroy<TextureCache>();
DependencyManager::destroy<GeometryCache>();
DependencyManager::destroy<ScriptCache>();
DependencyManager::destroy<SoundCache>();
qDebug() << "done destroying ResourceCaches Application::~Application() line:" << __LINE__;
}
void Application::initializeGL() {
@ -3466,7 +3478,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance());
scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);

View file

@ -59,8 +59,8 @@ CachesSizeDialog::CachesSizeDialog(QWidget* parent) :
void CachesSizeDialog::confirmClicked(bool checked) {
DependencyManager::get<AnimationCache>()->setUnusedResourceCacheSize(_animations->value() * BYTES_PER_MEGABYTES);
DependencyManager::get<GeometryCache>()->setUnusedResourceCacheSize(_geometries->value() * BYTES_PER_MEGABYTES);
ScriptCache::getInstance()->setUnusedResourceCacheSize(_scripts->value() * BYTES_PER_MEGABYTES);
SoundCache::getInstance().setUnusedResourceCacheSize(_sounds->value() * BYTES_PER_MEGABYTES);
DependencyManager::get<ScriptCache>()->setUnusedResourceCacheSize(_scripts->value() * BYTES_PER_MEGABYTES);
DependencyManager::get<SoundCache>()->setUnusedResourceCacheSize(_sounds->value() * BYTES_PER_MEGABYTES);
DependencyManager::get<TextureCache>()->setUnusedResourceCacheSize(_textures->value() * BYTES_PER_MEGABYTES);
QDialog::close();
@ -69,8 +69,8 @@ void CachesSizeDialog::confirmClicked(bool checked) {
void CachesSizeDialog::resetClicked(bool checked) {
_animations->setValue(DependencyManager::get<AnimationCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_geometries->setValue(DependencyManager::get<GeometryCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_scripts->setValue(ScriptCache::getInstance()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_sounds->setValue(SoundCache::getInstance().getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_scripts->setValue(DependencyManager::get<ScriptCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_sounds->setValue(DependencyManager::get<SoundCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
_textures->setValue(DependencyManager::get<TextureCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
}

View file

@ -19,7 +19,9 @@
#include "Rectangle3DOverlay.h"
Rectangle3DOverlay::Rectangle3DOverlay() {
Rectangle3DOverlay::Rectangle3DOverlay() :
_geometryCacheID(DependencyManager::get<GeometryCache>()->allocateID())
{
}
Rectangle3DOverlay::Rectangle3DOverlay(const Rectangle3DOverlay* rectangle3DOverlay) :

View file

@ -15,11 +15,6 @@
static int soundPointerMetaTypeId = qRegisterMetaType<SharedSoundPointer>();
SoundCache& SoundCache::getInstance() {
static SoundCache staticInstance;
return staticInstance;
}
SoundCache::SoundCache(QObject* parent) :
ResourceCache(parent)
{

View file

@ -17,11 +17,11 @@
#include "Sound.h"
/// Scriptable interface for sound loading.
class SoundCache : public ResourceCache {
class SoundCache : public ResourceCache, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
public:
static SoundCache& getInstance();
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
protected:

View file

@ -194,6 +194,7 @@ public:
bool containsBoundsProperties() const { return (_positionChanged || _dimensionsChanged); }
bool containsPositionChange() const { return _positionChanged; }
bool containsDimensionsChange() const { return _dimensionsChanged; }
bool containsAnimationSettingsChange() const { return _animationSettingsChanged; }
float getGlowLevel() const { return _glowLevel; }
float getLocalRenderAlpha() const { return _localRenderAlpha; }
@ -256,12 +257,57 @@ inline void EntityItemProperties::setPosition(const glm::vec3& value)
inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) {
debug << "EntityItemProperties[" << "\n"
<< " position:" << properties.getPosition() << "in meters" << "\n"
<< " velocity:" << properties.getVelocity() << "in meters" << "\n"
<< " last edited:" << properties.getLastEdited() << "\n"
<< " edited ago:" << properties.getEditedAgo() << "\n"
<< "]";
debug << "EntityItemProperties[" << "\n";
// TODO: figure out why position and animationSettings don't seem to like the macro approach
if (properties.containsPositionChange()) {
debug << " position:" << properties.getPosition() << "in meters" << "\n";
}
if (properties.containsAnimationSettingsChange()) {
debug << " animationSettings:" << properties.getAnimationSettings() << "\n";
}
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Dimensions, dimensions, "in meters");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Velocity, velocity, "in meters");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Visible, visible, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Rotation, rotation, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Density, density, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Gravity, gravity, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Damping, damping, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Lifetime, lifetime, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Script, script, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Color, color, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ModelURL, modelURL, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationURL, animationURL, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationFPS, animationFPS, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationFrameIndex, animationFrameIndex, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationIsPlaying, animationIsPlaying, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, RegistrationPoint, registrationPoint, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AngularVelocity, angularVelocity, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AngularDamping, angularDamping, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, IgnoreForCollisions, ignoreForCollisions, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, CollisionsWillMove, collisionsWillMove, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, IsSpotlight, isSpotlight, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, DiffuseColor, diffuseColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AmbientColor, ambientColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, SpecularColor, specularColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ConstantAttenuation, constantAttenuation, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, LinearAttenuation, linearAttenuation, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, QuadraticAttenuation, quadraticAttenuation, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Exponent, exponent, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Cutoff, cutoff, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Locked, locked, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Textures, textures, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, UserData, userData, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Text, text, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, LineHeight, lineHeight, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, TextColor, textColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, BackgroundColor, backgroundColor, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ShapeType, shapeType, "");
debug << " last edited:" << properties.getLastEdited() << "\n";
debug << " edited ago:" << properties.getEditedAgo() << "\n";
debug << "]";
return debug;
}

View file

@ -321,6 +321,10 @@
T _##n; \
bool _##n##Changed;
#define DEBUG_PROPERTY_IF_CHANGED(D, P, N, n, x) \
if (P.n##Changed()) { \
D << " " << #n << ":" << P.get##N() << x << "\n"; \
}
#endif // hifi_EntityItemPropertiesMacros_h

View file

@ -592,6 +592,10 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
// if the EntityItem exists, then update it
if (existingEntity) {
if (wantEditLogging()) {
qDebug() << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID;
qDebug() << " properties:" << properties;
}
updateEntity(entityItemID, properties, senderNode->getCanAdjustLocks());
existingEntity->markAsChangedOnServer();
} else {

View file

@ -151,6 +151,9 @@ public:
void emitEntityScriptChanging(const EntityItemID& entityItemID);
void setSimulation(EntitySimulation* simulation);
bool wantEditLogging() const { return _wantEditLogging; }
void setWantEditLogging(bool value) { _wantEditLogging = value; }
signals:
void deletingEntity(const EntityItemID& entityID);
@ -180,6 +183,8 @@ private:
QHash<EntityItemID, EntityTreeElement*> _entityToElementMap;
EntitySimulation* _simulation;
bool _wantEditLogging = false;
};
#endif // hifi_EntityTree_h

View file

@ -163,16 +163,6 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit
QMap<QString, AnimationPointer> ModelEntityItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s)
// This class/instance will cleanup the animations once unloaded.
class EntityAnimationsBookkeeper {
public:
~EntityAnimationsBookkeeper() {
ModelEntityItem::cleanupLoadedAnimations();
}
};
EntityAnimationsBookkeeper modelAnimationsBookkeeperInstance;
void ModelEntityItem::cleanupLoadedAnimations() {
foreach(AnimationPointer animation, _loadedAnimations) {
animation.clear();

View file

@ -465,9 +465,9 @@ void Bitstream::writeRawDelta(const QScriptValue& value, const QScriptValue& ref
} else if (reference.isArray()) {
if (value.isArray()) {
*this << false;
int length = value.property(ScriptCache::getInstance()->getLengthString()).toInt32();
int length = value.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
*this << length;
int referenceLength = reference.property(ScriptCache::getInstance()->getLengthString()).toInt32();
int referenceLength = reference.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
for (int i = 0; i < length; i++) {
if (i < referenceLength) {
writeDelta(value.property(i), reference.property(i));
@ -555,7 +555,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
QVariant variant;
readRawDelta(variant, reference.toVariant());
value = ScriptCache::getInstance()->getEngine()->newVariant(variant);
value = DependencyManager::get<ScriptCache>()->getEngine()->newVariant(variant);
}
} else if (reference.isQObject()) {
bool typeChanged;
@ -566,7 +566,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
QObject* object;
readRawDelta(object, reference.toQObject());
value = ScriptCache::getInstance()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
value = DependencyManager::get<ScriptCache>()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
}
} else if (reference.isQMetaObject()) {
bool typeChanged;
@ -577,7 +577,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
const QMetaObject* metaObject;
*this >> metaObject;
value = ScriptCache::getInstance()->getEngine()->newQMetaObject(metaObject);
value = DependencyManager::get<ScriptCache>()->getEngine()->newQMetaObject(metaObject);
}
} else if (reference.isDate()) {
bool typeChanged;
@ -588,7 +588,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
QDateTime dateTime;
*this >> dateTime;
value = ScriptCache::getInstance()->getEngine()->newDate(dateTime);
value = DependencyManager::get<ScriptCache>()->getEngine()->newDate(dateTime);
}
} else if (reference.isRegExp()) {
bool typeChanged;
@ -599,7 +599,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
QRegExp regExp;
*this >> regExp;
value = ScriptCache::getInstance()->getEngine()->newRegExp(regExp);
value = DependencyManager::get<ScriptCache>()->getEngine()->newRegExp(regExp);
}
} else if (reference.isArray()) {
bool typeChanged;
@ -610,8 +610,8 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
int length;
*this >> length;
value = ScriptCache::getInstance()->getEngine()->newArray(length);
int referenceLength = reference.property(ScriptCache::getInstance()->getLengthString()).toInt32();
value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(length);
int referenceLength = reference.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
for (int i = 0; i < length; i++) {
QScriptValue element;
if (i < referenceLength) {
@ -630,7 +630,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
} else {
// start by shallow-copying the reference
value = ScriptCache::getInstance()->getEngine()->newObject();
value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
for (QScriptValueIterator it(reference); it.hasNext(); ) {
it.next();
value.setProperty(it.scriptName(), it.value());
@ -1036,7 +1036,7 @@ Bitstream& Bitstream::operator<<(const QScriptValue& value) {
} else if (value.isArray()) {
writeScriptValueType(*this, ARRAY_SCRIPT_VALUE);
int length = value.property(ScriptCache::getInstance()->getLengthString()).toInt32();
int length = value.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
*this << length;
for (int i = 0; i < length; i++) {
*this << value.property(i);
@ -1087,37 +1087,37 @@ Bitstream& Bitstream::operator>>(QScriptValue& value) {
case VARIANT_SCRIPT_VALUE: {
QVariant variantValue;
*this >> variantValue;
value = ScriptCache::getInstance()->getEngine()->newVariant(variantValue);
value = DependencyManager::get<ScriptCache>()->getEngine()->newVariant(variantValue);
break;
}
case QOBJECT_SCRIPT_VALUE: {
QObject* object;
*this >> object;
ScriptCache::getInstance()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
DependencyManager::get<ScriptCache>()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
break;
}
case QMETAOBJECT_SCRIPT_VALUE: {
const QMetaObject* metaObject;
*this >> metaObject;
ScriptCache::getInstance()->getEngine()->newQMetaObject(metaObject);
DependencyManager::get<ScriptCache>()->getEngine()->newQMetaObject(metaObject);
break;
}
case DATE_SCRIPT_VALUE: {
QDateTime dateTime;
*this >> dateTime;
value = ScriptCache::getInstance()->getEngine()->newDate(dateTime);
value = DependencyManager::get<ScriptCache>()->getEngine()->newDate(dateTime);
break;
}
case REGEXP_SCRIPT_VALUE: {
QRegExp regExp;
*this >> regExp;
value = ScriptCache::getInstance()->getEngine()->newRegExp(regExp);
value = DependencyManager::get<ScriptCache>()->getEngine()->newRegExp(regExp);
break;
}
case ARRAY_SCRIPT_VALUE: {
int length;
*this >> length;
value = ScriptCache::getInstance()->getEngine()->newArray(length);
value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(length);
for (int i = 0; i < length; i++) {
QScriptValue element;
*this >> element;
@ -1126,7 +1126,7 @@ Bitstream& Bitstream::operator>>(QScriptValue& value) {
break;
}
case OBJECT_SCRIPT_VALUE: {
value = ScriptCache::getInstance()->getEngine()->newObject();
value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
forever {
QScriptString name;
*this >> name;
@ -1477,7 +1477,7 @@ Bitstream& Bitstream::operator>(QScriptString& string) {
QString rawString;
*this >> rawString;
string = (rawString == INVALID_STRING) ? QScriptString() :
ScriptCache::getInstance()->getEngine()->toStringHandle(rawString);
DependencyManager::get<ScriptCache>()->getEngine()->toStringHandle(rawString);
return *this;
}
@ -1828,7 +1828,7 @@ QJsonValue JSONWriter::getData(const QScriptValue& value) {
} else if (value.isArray()) {
object.insert("type", QString("ARRAY"));
QJsonArray array;
int length = value.property(ScriptCache::getInstance()->getLengthString()).toInt32();
int length = value.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
for (int i = 0; i < length; i++) {
array.append(getData(value.property(i)));
}
@ -2209,31 +2209,31 @@ void JSONReader::putData(const QJsonValue& data, QScriptValue& value) {
} else if (type == "VARIANT") {
QVariant variant;
putData(object.value("value"), variant);
value = ScriptCache::getInstance()->getEngine()->newVariant(variant);
value = DependencyManager::get<ScriptCache>()->getEngine()->newVariant(variant);
} else if (type == "QOBJECT") {
QObject* qObject;
putData(object.value("value"), qObject);
value = ScriptCache::getInstance()->getEngine()->newQObject(qObject, QScriptEngine::ScriptOwnership);
value = DependencyManager::get<ScriptCache>()->getEngine()->newQObject(qObject, QScriptEngine::ScriptOwnership);
} else if (type == "QMETAOBJECT") {
const QMetaObject* metaObject;
putData(object.value("value"), metaObject);
value = ScriptCache::getInstance()->getEngine()->newQMetaObject(metaObject);
value = DependencyManager::get<ScriptCache>()->getEngine()->newQMetaObject(metaObject);
} else if (type == "DATE") {
QDateTime dateTime;
putData(object.value("value"), dateTime);
value = ScriptCache::getInstance()->getEngine()->newDate(dateTime);
value = DependencyManager::get<ScriptCache>()->getEngine()->newDate(dateTime);
} else if (type == "REGEXP") {
QRegExp regExp;
putData(object.value("value"), regExp);
value = ScriptCache::getInstance()->getEngine()->newRegExp(regExp);
value = DependencyManager::get<ScriptCache>()->getEngine()->newRegExp(regExp);
} else if (type == "ARRAY") {
QJsonArray array = object.value("value").toArray();
value = ScriptCache::getInstance()->getEngine()->newArray(array.size());
value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(array.size());
for (int i = 0; i < array.size(); i++) {
QScriptValue element;
putData(array.at(i), element);
@ -2241,7 +2241,7 @@ void JSONReader::putData(const QJsonValue& data, QScriptValue& value) {
}
} else if (type == "OBJECT") {
QJsonObject jsonObject = object.value("value").toObject();
value = ScriptCache::getInstance()->getEngine()->newObject();
value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
for (QJsonObject::const_iterator it = jsonObject.constBegin(); it != jsonObject.constEnd(); it++) {
QScriptValue element;
putData(it.value(), element);

View file

@ -663,7 +663,7 @@ void ParameterizedURLEditor::updateURL() {
QByteArray valuePropertyName = widget->property("valuePropertyName").toByteArray();
const QMetaObject* widgetMetaObject = widget->metaObject();
QMetaProperty widgetProperty = widgetMetaObject->property(widgetMetaObject->indexOfProperty(valuePropertyName));
parameters.insert(ScriptCache::getInstance()->getEngine()->toStringHandle(
parameters.insert(DependencyManager::get<ScriptCache>()->getEngine()->toStringHandle(
widget->property("parameterName").toString()), widgetProperty.read(widget));
}
}
@ -677,7 +677,7 @@ void ParameterizedURLEditor::updateParameters() {
if (_program) {
_program->disconnect(this);
}
_program = ScriptCache::getInstance()->getProgram(_url.getURL());
_program = DependencyManager::get<ScriptCache>()->getProgram(_url.getURL());
if (_program->isLoaded()) {
continueUpdatingParameters();
} else {
@ -698,7 +698,7 @@ void ParameterizedURLEditor::continueUpdatingParameters() {
}
delete form;
}
QSharedPointer<NetworkValue> value = ScriptCache::getInstance()->getValue(_url.getURL());
QSharedPointer<NetworkValue> value = DependencyManager::get<ScriptCache>()->getValue(_url.getURL());
const QList<ParameterInfo>& parameters = static_cast<RootNetworkValue*>(value.data())->getParameterInfo();
if (parameters.isEmpty()) {
return;

View file

@ -57,8 +57,8 @@ bool operator==(const QScriptValue& first, const QScriptValue& second) {
if (!second.isArray()) {
return false;
}
int length = first.property(ScriptCache::getInstance()->getLengthString()).toInt32();
if (second.property(ScriptCache::getInstance()->getLengthString()).toInt32() != length) {
int length = first.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
if (second.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32() != length) {
return false;
}
for (int i = 0; i < length; i++) {
@ -103,11 +103,6 @@ bool operator<(const QScriptValue& first, const QScriptValue& second) {
return first.lessThan(second);
}
ScriptCache* ScriptCache::getInstance() {
static ScriptCache cache;
return &cache;
}
ScriptCache::ScriptCache() :
_engine(NULL)
{

View file

@ -25,13 +25,11 @@ class NetworkProgram;
class NetworkValue;
/// Maintains a cache of loaded scripts.
class ScriptCache : public ResourceCache {
class ScriptCache : public ResourceCache, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
public:
static ScriptCache* getInstance();
ScriptCache();
void setEngine(QScriptEngine* engine);

View file

@ -213,7 +213,9 @@ void OctreePersistThread::persist() {
}
_tree->unlock();
qDebug() << "persist operation calling backup...";
backup(); // handle backup if requested
qDebug() << "persist operation DONE with backup...";
// create our "lock" file to indicate we're saving.
@ -347,6 +349,7 @@ void OctreePersistThread::rollOldBackupVersions(const BackupRule& rule) {
void OctreePersistThread::backup() {
qDebug() << "backup operation wantBackup:" << _wantBackup;
if (_wantBackup) {
quint64 now = usecTimestampNow();
@ -354,10 +357,12 @@ void OctreePersistThread::backup() {
BackupRule& rule = _backupRules[i];
quint64 sinceLastBackup = now - rule.lastBackup;
quint64 SECS_TO_USECS = 1000 * 1000;
quint64 intervalToBackup = rule.interval * SECS_TO_USECS;
qDebug() << "Checking [" << rule.name << "] - Time since last backup [" << sinceLastBackup << "] " <<
"compared to backup interval [" << intervalToBackup << "]...";
if (sinceLastBackup > intervalToBackup) {
qDebug() << "Time since last backup [" << sinceLastBackup << "] for rule [" << rule.name
<< "] exceeds backup interval [" << intervalToBackup << "] doing backup now...";
@ -379,15 +384,22 @@ void OctreePersistThread::backup() {
}
qDebug() << "backing up persist file " << _filename << "to" << backupFileName << "...";
bool result = QFile::copy(_filename, backupFileName);
if (result) {
qDebug() << "DONE backing up persist file...";
QFile persistFile(_filename);
if (persistFile.exists()) {
qDebug() << "backing up persist file " << _filename << "to" << backupFileName << "...";
bool result = QFile::copy(_filename, backupFileName);
if (result) {
qDebug() << "DONE backing up persist file...";
rule.lastBackup = now; // only record successful backup in this case.
} else {
qDebug() << "ERROR in backing up persist file...";
}
} else {
qDebug() << "ERROR in backing up persist file...";
qDebug() << "persist file " << _filename << " does not exist. " <<
"nothing to backup for this rule ["<< rule.name << "]...";
}
rule.lastBackup = now;
} else {
qDebug() << "Backup not needed for this rule ["<< rule.name << "]...";
}
}
}

View file

@ -219,14 +219,14 @@ static QScriptValue createRandomScriptValue(bool complex = false, bool ensureHas
case 4: {
int length = randIntInRange(2, 6);
QScriptValue value = ScriptCache::getInstance()->getEngine()->newArray(length);
QScriptValue value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(length);
for (int i = 0; i < length; i++) {
value.setProperty(i, createRandomScriptValue());
}
return value;
}
default: {
QScriptValue value = ScriptCache::getInstance()->getEngine()->newObject();
QScriptValue value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
if (ensureHashOrder) {
// we can't depend on the iteration order, so if we need it to be the same (as when comparing bytes), we
// can only have one property
@ -747,7 +747,7 @@ static SharedObjectPointer mutate(const SharedObjectPointer& state) {
case 3: {
SharedObjectPointer newState = state->clone(true);
QScriptValue oldValue = static_cast<TestSharedObjectA*>(newState.data())->getBizzle();
QScriptValue newValue = ScriptCache::getInstance()->getEngine()->newObject();
QScriptValue newValue = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
for (QScriptValueIterator it(oldValue); it.hasNext(); ) {
it.next();
newValue.setProperty(it.scriptName(), it.value());
@ -755,8 +755,8 @@ static SharedObjectPointer mutate(const SharedObjectPointer& state) {
switch (randIntInRange(0, 2)) {
case 0: {
QScriptValue oldArray = oldValue.property("foo");
int oldLength = oldArray.property(ScriptCache::getInstance()->getLengthString()).toInt32();
QScriptValue newArray = ScriptCache::getInstance()->getEngine()->newArray(oldLength);
int oldLength = oldArray.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
QScriptValue newArray = DependencyManager::get<ScriptCache>()->getEngine()->newArray(oldLength);
for (int i = 0; i < oldLength; i++) {
newArray.setProperty(i, oldArray.property(i));
}
@ -1203,8 +1203,8 @@ TestSharedObjectA::TestSharedObjectA(float foo, TestEnum baz, TestFlags bong) :
_bong(bong) {
sharedObjectsCreated++;
_bizzle = ScriptCache::getInstance()->getEngine()->newObject();
_bizzle.setProperty("foo", ScriptCache::getInstance()->getEngine()->newArray(4));
_bizzle = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
_bizzle.setProperty("foo", DependencyManager::get<ScriptCache>()->getEngine()->newArray(4));
}
TestSharedObjectA::~TestSharedObjectA() {