Fixed Create App

This commit is contained in:
ksuprynowicz 2023-02-12 15:29:47 +01:00
parent c3417b807c
commit 5809576577
13 changed files with 3124 additions and 3067 deletions

View file

@ -45,6 +45,7 @@
* {@link InteractiveWindow}: none, top left, top right, bottom right, or bottom left of the Interface window.
* <em>Read-only.</em>
*/
class DesktopScriptingInterface : public QObject, public Dependency {
Q_OBJECT
Q_PROPERTY(int width READ getWidth) // Physical width of screen(s) including task bars and system menus

View file

@ -129,6 +129,7 @@ public:
virtual void compileTest() = 0;
virtual QString scriptValueDebugDetails(const ScriptValue &value) = 0;
virtual QString scriptValueDebugListMembers(const ScriptValue &value) = 0;
virtual void logBacktrace(const QString &title) = 0;
public:
// helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways
bool IS_THREADSAFE_INVOCATION(const QString& method);

View file

@ -2508,3 +2508,7 @@ ScriptValue ScriptManager::evaluate(const QString& program, const QString& fileN
void ScriptManager::requestGarbageCollection() {
_engine->requestCollectGarbage();
}
void ScriptManager::logBacktrace(const QString &title) {
_engine->logBacktrace(title);
}

View file

@ -564,6 +564,13 @@ public:
*/
Q_INVOKABLE void requestGarbageCollection();
/**jsdoc
* Prints out current backtrace to the log.
* @function Script.logBacktrace
* @param {string} title - Title added to the printed out backtrace.
*/
Q_INVOKABLE void logBacktrace(const QString &title);
/*@jsdoc
* @function Script.loadEntityScript
* @param {Uuid} entityID - Entity ID.

View file

@ -1714,6 +1714,14 @@ QString ScriptEngineV8::scriptValueDebugDetailsV8(const V8ScriptValue &v8Value)
}
}*/
void ScriptEngineV8::logBacktrace(const QString &title) {
QStringList backtrace = currentContext()->backtrace();
qDebug(scriptengine) << title;
for (int n = 0; n < backtrace.length(); n++) {
qDebug(scriptengine) << backtrace[n];
}
}
QStringList ScriptEngineV8::getCurrentScriptURLs() const {
auto isolate = _v8Isolate;
v8::Locker locker(isolate);

View file

@ -136,6 +136,7 @@ public: // ScriptEngine implementation
QString scriptValueDebugDetailsV8(const V8ScriptValue &value);
virtual QString scriptValueDebugListMembers(const ScriptValue &value) override;
QString scriptValueDebugListMembersV8(const V8ScriptValue &v8Value);
virtual void logBacktrace(const QString &title) override;
// helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways
inline bool IS_THREADSAFE_INVOCATION(const QString& method) { return ScriptEngine::IS_THREADSAFE_INVOCATION(method); }

View file

@ -49,6 +49,7 @@ void ScriptEngineV8::registerCustomType(int type,
}
Q_DECLARE_METATYPE(ScriptValue);
Q_DECLARE_METATYPE(QVariantMap);
/*static V8ScriptValue ScriptValueToV8ScriptValue(ScriptEngineV8* engine, const ScriptValue& src) {
return ScriptValueV8Wrapper::fullUnwrap(static_cast<ScriptEngineV8*>(engine), src);

View file

@ -1144,10 +1144,20 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
for (ConnectionList::iterator iter = _connections.begin(); iter != _connections.end(); ++iter) {
Connection& conn = *iter;
{
//auto functionContext = callback->CreationContext();
auto functionContext = _v8Context.Get(_engine->getIsolate());
_engine->pushContext(functionContext);
/*if (!conn.callback.get()->IsFunction()) {
auto stringV8 = conn.callback.get()->ToDetailString(context).ToLocalChecked();
QString error = *v8::String::Utf8Value(_engine->getIsolate(), stringV8);
qDebug() << error;
Q_ASSERT(false);
}
v8::Local<v8::Function> callback = v8::Local<v8::Function>::Cast(conn.callback.get());
auto functionContext = callback->CreationContext();
v8::Context::Scope functionContextScope(functionContext);
_engine->pushContext(functionContext);*/
/*auto functionContext = _v8Context.Get(_engine->getIsolate());
_engine->pushContext(functionContext);
v8::Context::Scope functionContextScope(functionContext);*/
auto functionContext = context;
Q_ASSERT(!conn.callback.get().IsEmpty());
Q_ASSERT(!conn.callback.get()->IsUndefined());
@ -1178,7 +1188,7 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
<< _engine->formatErrorMessageFromTryCatch(tryCatch)
<< "\nThis provided: " << conn.thisValue.get()->IsObject();
}
_engine->popContext();
//_engine->popContext();
}
}
});

View file

@ -91,6 +91,7 @@ ScriptValue ScriptValueV8Wrapper::call(const ScriptValue& thisObject, const Scri
//qDebug() << "V8 This: " << _engine->scriptValueDebugDetailsV8(v8This);
}else{
recv = _engine->getContext()->Global();
//recv = v8::Null(isolate);
//qDebug() << "global";
}
//qDebug() << "V8 Call: " << *v8::String::Utf8Value(isolate, v8This.get()->TypeOf(isolate));

File diff suppressed because it is too large Load diff

View file

@ -218,7 +218,7 @@ var EntityListTool = function(shouldUseEditTabletApp) {
url = properties.imageURL;
}
//print("Global object before getParentState call: " + JSON.stringify(globalThis));
var parentStatus = getParentState(ids[i]);
var parentStatus = that.createApp.getParentState(ids[i]);
var parentState = "";
if (parentStatus === "PARENT") {
parentState = "A";

View file

@ -83,12 +83,15 @@ SelectionManager = (function() {
// FUNCTION: HANDLE ENTITY SELECTION TOOL UPDATES
function handleEntitySelectionToolUpdates(channel, message, sender) {
//print("Channel: " + channel + " Sender: " + sender + " Message: " + JSON.stringify(message));
if (channel !== 'entityToolUpdates') {
return;
}
print("handleEntitySelectionToolUpdates entityToolUpdates");
if (sender !== MyAvatar.sessionUUID) {
return;
}
print("handleEntitySelectionToolUpdates MyAvatar.sessionUUID");
var wantDebug = false;
var messageParsed;
@ -99,6 +102,7 @@ SelectionManager = (function() {
return;
}
print("handleEntitySelectionToolUpdates JSON.parse(message): " + messageParsed.method);
if (messageParsed.method === "selectEntity") {
if (!that.editEnabled) {
return;
@ -125,7 +129,7 @@ SelectionManager = (function() {
}
selectionDisplay.moveSelection(Vec3.sum(messageParsed.intersection, Vec3.multiplyQbyV( normalRotation, {"x": 0.0, "y":0.0, "z": distanceFromSurface})));
that._update(false, this);
pushCommandForSelections();
that.createApp.pushCommandForSelections();
expectingRotateAsClickedSurface = false;
audioFeedback.action();
}
@ -147,6 +151,7 @@ SelectionManager = (function() {
that.clearSelections();
}
} else if (messageParsed.method === "pointingAt") {
print("handleEntitySelectionToolUpdates pointingAt");
if (messageParsed.hand === Controller.Standard.RightHand) {
that.pointingAtDesktopWindowRight = messageParsed.desktopWindow;
that.pointingAtTabletRight = messageParsed.tablet;
@ -232,6 +237,8 @@ SelectionManager = (function() {
};
that.setSelections = function(entityIDs, caller) {
print("setSelections: " + JSON.stringify(entityIDs));
Script.logBacktrace("setSelections");
that.selections = [];
for (var i = 0; i < entityIDs.length; i++) {
var entityID = entityIDs[i];
@ -723,7 +730,7 @@ SelectionManager = (function() {
var newPosition = Vec3.sum(relativePosition, targetPosition);
Entities.editEntity(id, { "position": newPosition });
}
pushCommandForSelections();
that.createApp.pushCommandForSelections();
that._update(false, this);
} else {
audioFeedback.rejection();
@ -2002,7 +2009,7 @@ SelectionDisplay = (function() {
var handleBoundingBoxColor = COLOR_BOUNDING_EDGE;
if (SelectionManager.selections.length === 1) {
var parentState = getParentState(SelectionManager.selections[0]);
var parentState = that.createApp.getParentState(SelectionManager.selections[0]);
if (parentState === "CHILDREN") {
handleBoundingBoxColor = COLOR_BOUNDING_EDGE_CHILDREN;
} else if (parentState === "PARENT") {
@ -2504,7 +2511,7 @@ SelectionDisplay = (function() {
}
updateSelectionsRotation(axisRotation, SelectionManager.worldPosition);
SelectionManager._update(false, this);
pushCommandForSelections();
that.createApp.pushCommandForSelections();
audioFeedback.action();
}
};
@ -2585,7 +2592,7 @@ SelectionDisplay = (function() {
print(" starting elevation: " + startingElevation);
}
initialPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
initialPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
if (debugPickPlaneEnabled) {
that.showDebugPickPlane(pickPlanePosition, pickPlaneNormal);
@ -2598,7 +2605,7 @@ SelectionDisplay = (function() {
}
},
onEnd: function(event, reason) {
pushCommandForSelections(duplicatedEntityIDs);
that.createApp.pushCommandForSelections(duplicatedEntityIDs);
if (isConstrained) {
Entities.editEntity(xRailToolEntity, {
visible: false,
@ -2617,7 +2624,7 @@ SelectionDisplay = (function() {
var wantDebug = false;
var pickRay = generalComputePickRay(event.x, event.y);
var newPick = rayPlaneIntersection2(pickRay, pickPlanePosition, pickPlaneNormal);
var newPick = that.createApp.rayPlaneIntersection2(pickRay, pickPlanePosition, pickPlaneNormal);
// If the pick ray doesn't hit the pick plane in this direction, do nothing.
// this will happen when someone drags across the horizon from the side they started on.
@ -2722,7 +2729,7 @@ SelectionDisplay = (function() {
var negateAndHalve = -0.5;
var cornerPosition = Vec3.sum(startPosition, Vec3.multiply(negateAndHalve, SelectionManager.worldDimensions));
vector = Vec3.subtract(
grid.snapToGrid(Vec3.sum(cornerPosition, vector), constrainMajorOnly),
that.grid.snapToGrid(Vec3.sum(cornerPosition, vector), constrainMajorOnly),
cornerPosition);
// editing a parent will cause all the children to automatically follow along, so don't
@ -2801,7 +2808,7 @@ SelectionDisplay = (function() {
axisVector = Vec3.multiplyQbyV(rotation, axisVector);
pickPlaneNormal = Vec3.cross(Vec3.cross(pickRay.direction, axisVector), axisVector);
pickPlanePosition = SelectionManager.worldPosition;
initialPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
initialPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
SelectionManager.saveProperties();
that.resetPreviousHandleColor();
@ -2822,7 +2829,7 @@ SelectionDisplay = (function() {
}
},
onEnd: function(event, reason) {
pushCommandForSelections(duplicatedEntityIDs);
that.createApp.pushCommandForSelections(duplicatedEntityIDs);
},
onMove: function(event) {
var pickRay = generalComputePickRay(event.x, event.y);
@ -2832,7 +2839,7 @@ SelectionDisplay = (function() {
pickRay = previousPickRay;
}
var newPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
var newPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
if (debugPickPlaneEnabled) {
that.showDebugPickPlaneHit(newPick);
}
@ -2850,8 +2857,8 @@ SelectionDisplay = (function() {
var dotVector = Vec3.dot(vector, projectionVector);
vector = Vec3.multiply(dotVector, projectionVector);
var gridOrigin = grid.getOrigin();
vector = Vec3.subtract(grid.snapToGrid(Vec3.sum(vector, gridOrigin)), gridOrigin);
var gridOrigin = that.grid.getOrigin();
vector = Vec3.subtract(that.grid.snapToGrid(Vec3.sum(vector, gridOrigin)), gridOrigin);
var wantDebug = false;
if (wantDebug) {
@ -2962,7 +2969,7 @@ SelectionDisplay = (function() {
pickPlaneNormal = Vec3.cross(Vec3.cross(pickRay.direction, axisVector), axisVector);
pickPlanePosition = Vec3.sum(initialPosition, Vec3.multiplyQbyV(rotation, scaledOffsetWorld));
initialPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
initialPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
that.setHandleTranslateVisible(false);
that.setHandleRotateVisible(false);
@ -3008,8 +3015,8 @@ SelectionDisplay = (function() {
Entities.editEntity(stretchPanel, { visible: false, ignorePickIntersection: true });
}
activeStretchCubePanelOffset = null;
pushCommandForSelections();
that.createApp.pushCommandForSelections();
},
onMove: function(event) {
var pickRay = generalComputePickRay(event.x, event.y);
@ -3019,7 +3026,7 @@ SelectionDisplay = (function() {
pickRay = previousPickRay;
}
var newPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
var newPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
if (debugPickPlaneEnabled) {
that.showDebugPickPlaneHit(newPick);
}
@ -3029,7 +3036,7 @@ SelectionDisplay = (function() {
changeInDimensions = Vec3.multiply(dotVector, axisVector);
changeInDimensions = Vec3.multiplyQbyV(Quat.inverse(rotation), changeInDimensions);
changeInDimensions = Vec3.multiplyVbyV(mask, changeInDimensions);
changeInDimensions = grid.snapToSpacing(changeInDimensions);
changeInDimensions = that.grid.snapToSpacing(changeInDimensions);
changeInDimensions = Vec3.multiply(NEGATE_VECTOR, Vec3.multiplyVbyV(signs, changeInDimensions));
var newDimensions = Vec3.sum(initialDimensions, changeInDimensions);
@ -3088,7 +3095,7 @@ SelectionDisplay = (function() {
pickPlanePosition = initialPosition;
pickPlaneNormal = Vec3.subtract(pickRay.origin, pickPlanePosition);
initialPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
initialPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
that.setHandleTranslateVisible(false);
that.setHandleRotateVisible(false);
@ -3120,8 +3127,8 @@ SelectionDisplay = (function() {
Entities.editEntity(SelectionManager.selections[0], {collidesWith: newCollidesWith});
that.replaceCollisionsAfterStretch = false;
}
pushCommandForSelections();
that.createApp.pushCommandForSelections();
},
onMove: function(event) {
var pickRay = generalComputePickRay(event.x, event.y);
@ -3131,7 +3138,7 @@ SelectionDisplay = (function() {
pickRay = previousPickRay;
}
var newPick = rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
var newPick = that.createApp.rayPlaneIntersection(pickRay, pickPlanePosition, pickPlaneNormal);
if (debugPickPlaneEnabled) {
that.showDebugPickPlaneHit(newPick);
}
@ -3140,7 +3147,7 @@ SelectionDisplay = (function() {
var dimensionsMultiple = toCameraDistance * SCALE_DIMENSIONS_CAMERA_DISTANCE_MULTIPLE;
var changeInDimensions = Vec3.subtract(newPick, initialPick);
changeInDimensions = Vec3.multiplyQbyV(Quat.inverse(Camera.orientation), changeInDimensions);
changeInDimensions = grid.snapToSpacing(changeInDimensions);
changeInDimensions = that.grid.snapToSpacing(changeInDimensions);
changeInDimensions = Vec3.multiply(changeInDimensions, dimensionsMultiple);
var averageDimensionChange = (changeInDimensions.x + changeInDimensions.y + changeInDimensions.z) / 3;
@ -3309,7 +3316,7 @@ SelectionDisplay = (function() {
// editOverlays may not have committed rotation changes.
// Compute zero position based on where the toolEntity will be eventually.
var initialPick = rayPlaneIntersection(pickRay, rotationCenter, rotationNormal);
var initialPick = that.createApp.rayPlaneIntersection(pickRay, rotationCenter, rotationNormal);
// In case of a parallel ray, this will be null, which will cause early-out
// in the onMove helper.
rotationZero = initialPick;
@ -3343,7 +3350,7 @@ SelectionDisplay = (function() {
}
});
Entities.editEntity(handleRotateCurrentRing, { visible: false, ignorePickIntersection: true });
pushCommandForSelections();
that.createApp.pushCommandForSelections();
if (wantDebug) {
print("================== " + getMode() + "(addHandleRotateTool onEnd) <- =======================");
}
@ -3364,7 +3371,7 @@ SelectionDisplay = (function() {
}
var pickRay = generalComputePickRay(event.x, event.y);
var result = rayPlaneIntersection(pickRay, rotationCenter, rotationNormal);
var result = that.createApp.rayPlaneIntersection(pickRay, rotationCenter, rotationNormal);
if (result) {
var centerToZero = Vec3.subtract(rotationZero, rotationCenter);
var centerToIntersect = Vec3.subtract(result, rotationCenter);

View file

@ -292,8 +292,8 @@ GridTool = function(opts) {
var dataString = JSON.stringify(data);
webView.emitScriptEvent(dataString);
createToolsWindow.emitScriptEvent(dataString);
if (selectionDisplay) {
selectionDisplay.updateHandles();
if (that.selectionDisplay) {
that.selectionDisplay.updateHandles();
}
});