making sure the ID of an object in the Selection list is unique and more refined debugging

This commit is contained in:
samcake 2017-12-07 17:45:40 -08:00
parent 298b9be0c2
commit ace8e153c2
4 changed files with 13 additions and 156 deletions

View file

@ -18,7 +18,9 @@ GameplayObjects::GameplayObjects() {
bool GameplayObjects::addToGameplayObjects(const QUuid& avatarID) {
containsData = true;
_avatarIDs.push_back(avatarID);
if (std::find(_avatarIDs.begin(), _avatarIDs.end(), avatarID) == _avatarIDs.end()) {
_avatarIDs.push_back(avatarID);
}
return true;
}
bool GameplayObjects::removeFromGameplayObjects(const QUuid& avatarID) {
@ -28,7 +30,9 @@ bool GameplayObjects::removeFromGameplayObjects(const QUuid& avatarID) {
bool GameplayObjects::addToGameplayObjects(const EntityItemID& entityID) {
containsData = true;
_entityIDs.push_back(entityID);
if (std::find(_entityIDs.begin(), _entityIDs.end(), entityID) == _entityIDs.end()) {
_entityIDs.push_back(entityID);
}
return true;
}
bool GameplayObjects::removeFromGameplayObjects(const EntityItemID& entityID) {
@ -38,7 +42,9 @@ bool GameplayObjects::removeFromGameplayObjects(const EntityItemID& entityID) {
bool GameplayObjects::addToGameplayObjects(const OverlayID& overlayID) {
containsData = true;
_overlayIDs.push_back(overlayID);
if (std::find(_overlayIDs.begin(), _overlayIDs.end(), overlayID) == _overlayIDs.end()) {
_overlayIDs.push_back(overlayID);
}
return true;
}
bool GameplayObjects::removeFromGameplayObjects(const OverlayID& overlayID) {

View file

@ -140,10 +140,11 @@ public:
* Query the list of avatars, entities and overlays stored in a particular selection.
* @function Selection.getList
* @param listName {string} name of the selection
* @return a js object containing the following properties (if the array of obkjects are not empty):
* @return a js object describing the content of a selection list with the following properties:
* - "entities": [ and array of the entityID of the entities in the selection]
* - "avatars": [ and array of the avatarID of the avatars in the selection]
* - "overlays": [ and array of the overlayID of the overlays in the selection]
* If the list name doesn't exist, the function returns an empty js object with no properties.
*/
Q_INVOKABLE QVariantMap getSelectedItemsList(const QString& listName) const;

View file

@ -11,19 +11,9 @@
"use strict";
//
// Luci.js
// tablet-engine app
//
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var TABLET_BUTTON_NAME = "Highlight";
var QMLAPP_URL = Script.resolvePath("./highlight2.qml");
var QMLAPP_URL = Script.resolvePath("./highlight.qml");
var ICON_URL = Script.resolvePath("../../../system/assets/images/luci-i.svg");
var ACTIVE_ICON_URL = Script.resolvePath("../../../system/assets/images/luci-a.svg");
@ -109,143 +99,3 @@
}());
// Set up the qml ui
// Created by Sam Gondelman on 9/7/2017
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/*
(function() { // BEGIN LOCAL_SCOPE
var END_DIMENSIONS = {
x: 0.15,
y: 0.15,
z: 0.15
};
var COLOR = {red: 97, green: 247, blue: 255};
var end = {
type: "sphere",
dimensions: END_DIMENSIONS,
color: COLOR,
ignoreRayIntersection: true,
alpha: 1.0,
visible: true
}
var COLOR2 = {red: 247, green: 97, blue: 255};
var end2 = {
type: "sphere",
dimensions: END_DIMENSIONS,
color: COLOR2,
ignoreRayIntersection: true,
alpha: 1.0,
visible: true
}
var highlightGroupIndex = 0
var isSelectionAddEnabled = false
var isSelectionEnabled = false
var renderStates = [{name: "test", end: end}];
var defaultRenderStates = [{name: "test", distance: 20.0, end: end2}];
var time = 0
var ray = LaserPointers.createLaserPointer({
joint: "Mouse",
filter: RayPick.PICK_ENTITIES | RayPick.PICK_OVERLAYS | RayPick.PICK_AVATARS | RayPick.PICK_INVISIBLE | RayPick.PICK_NONCOLLIDABLE,
renderStates: renderStates,
defaultRenderStates: defaultRenderStates,
enabled: false
});
function getSelectionName() {
var selectionName = "contextOverlayHighlightList"
if (highlightGroupIndex>0) {
selectionName += highlightGroupIndex
}
return selectionName
}
function fromQml(message) {
tokens = message.split(' ')
print("Received '"+message+"' from hightlight.qml")
if (tokens[0]=="highlight") {
highlightGroupIndex = parseInt(tokens[1])
print("Switching to highlight group "+highlightGroupIndex)
} else if (tokens[0]=="pick") {
isSelectionEnabled = tokens[1]=='true'
print("Ray picking set to "+isSelectionEnabled.toString())
if (isSelectionEnabled) {
LaserPointers.enableLaserPointer(ray)
} else {
LaserPointers.disableLaserPointer(ray)
}
time = 0
} else if (tokens[0]=="add") {
isSelectionAddEnabled = tokens[1]=='true'
print("Add to selection set to "+isSelectionAddEnabled.toString())
if (!isSelectionAddEnabled) {
Selection.clearSelectedItemsList(getSelectionName())
}
}
}
window.fromQml.connect(fromQml);
function cleanup() {
LaserPointers.removeLaserPointer(ray);
}
Script.scriptEnding.connect(cleanup);
var prevID = 0
var prevType = ""
var selectedID = 0
var selectedType = ""
function update(deltaTime) {
// you have to do this repeatedly because there's a bug but I'll fix it
LaserPointers.setRenderState(ray, "test");
var result = LaserPointers.getPrevRayPickResult(ray);
var selectionName = getSelectionName()
if (isSelectionEnabled && result.type != RayPick.INTERSECTED_NONE) {
time += deltaTime
if (result.objectID != prevID) {
var typeName = ""
if (result.type == RayPick.INTERSECTED_ENTITY) {
typeName = "entity"
} else if (result.type == RayPick.INTERSECTED_OVERLAY) {
typeName = "overlay"
} else if (result.type == RayPick.INTERSECTED_AVATAR) {
typeName = "avatar"
}
prevID = result.objectID;
prevType = typeName;
time = 0
} else if (time>1.0 && prevID!=selectedID) {
if (prevID != 0 && !isSelectionAddEnabled) {
Selection.removeFromSelectedItemsList(selectionName, selectedType, selectedID)
}
selectedID = prevID
selectedType = prevType
Selection.addToSelectedItemsList(selectionName, selectedType, selectedID)
print("HIGHLIGHT " + highlightGroupIndex + " picked type: " + result.type + ", id: " + result.objectID);
}
} else {
if (prevID != 0 && !isSelectionAddEnabled) {
Selection.removeFromSelectedItemsList(selectionName, prevType, prevID)
}
prevID = 0
selectedID = 0
time = 0
}
}
Script.update.connect(update);
}()); // END LOCAL_SCOPE*/

View file

@ -62,7 +62,6 @@ Item {
print(root.styleList)
styleSelectorLoader.sourceComponent = undefined;
styleSelectorLoader.sourceComponent = selectorWidget;
resetSelectionView();
}
}
@ -87,6 +86,7 @@ Item {
interval: 100; running: false; repeat: false
onTriggered: {
styleWidgetLoader.sourceComponent = styleWidget
resetSelectionView();
}
}
onCurrentIndexChanged: {