mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-10 20:58:37 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into textEntity
This commit is contained in:
commit
05fa3c89a7
49 changed files with 1274 additions and 65 deletions
|
@ -1020,7 +1020,7 @@ void OctreeServer::readConfiguration() {
|
||||||
bool noPersist;
|
bool noPersist;
|
||||||
readOptionBool(QString("NoPersist"), settingsSectionObject, noPersist);
|
readOptionBool(QString("NoPersist"), settingsSectionObject, noPersist);
|
||||||
_wantPersist = !noPersist;
|
_wantPersist = !noPersist;
|
||||||
qDebug("wantPersist=%s", debug::valueOf(_wantPersist));
|
qDebug() << "wantPersist=" << _wantPersist;
|
||||||
|
|
||||||
if (_wantPersist) {
|
if (_wantPersist) {
|
||||||
QString persistFilename;
|
QString persistFilename;
|
||||||
|
@ -1029,6 +1029,26 @@ void OctreeServer::readConfiguration() {
|
||||||
}
|
}
|
||||||
strcpy(_persistFilename, qPrintable(persistFilename));
|
strcpy(_persistFilename, qPrintable(persistFilename));
|
||||||
qDebug("persistFilename=%s", _persistFilename);
|
qDebug("persistFilename=%s", _persistFilename);
|
||||||
|
|
||||||
|
_persistInterval = OctreePersistThread::DEFAULT_PERSIST_INTERVAL;
|
||||||
|
readOptionInt(QString("persistInterval"), settingsSectionObject, _persistInterval);
|
||||||
|
qDebug() << "persistInterval=" << _persistInterval;
|
||||||
|
|
||||||
|
bool noBackup;
|
||||||
|
readOptionBool(QString("NoBackup"), settingsSectionObject, noBackup);
|
||||||
|
_wantBackup = !noBackup;
|
||||||
|
qDebug() << "wantBackup=" << _wantBackup;
|
||||||
|
|
||||||
|
if (_wantBackup) {
|
||||||
|
_backupExtensionFormat = OctreePersistThread::DEFAULT_BACKUP_EXTENSION_FORMAT;
|
||||||
|
readOptionString(QString("backupExtensionFormat"), settingsSectionObject, _backupExtensionFormat);
|
||||||
|
qDebug() << "backupExtensionFormat=" << _backupExtensionFormat;
|
||||||
|
|
||||||
|
_backupInterval = OctreePersistThread::DEFAULT_BACKUP_INTERVAL;
|
||||||
|
readOptionInt(QString("backupInterval"), settingsSectionObject, _backupInterval);
|
||||||
|
qDebug() << "backupInterval=" << _backupInterval;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug("persistFilename= DISABLED");
|
qDebug("persistFilename= DISABLED");
|
||||||
}
|
}
|
||||||
|
@ -1112,7 +1132,8 @@ void OctreeServer::run() {
|
||||||
if (_wantPersist) {
|
if (_wantPersist) {
|
||||||
|
|
||||||
// now set up PersistThread
|
// now set up PersistThread
|
||||||
_persistThread = new OctreePersistThread(_tree, _persistFilename);
|
_persistThread = new OctreePersistThread(_tree, _persistFilename, _persistInterval,
|
||||||
|
_wantBackup, _backupInterval, _backupExtensionFormat);
|
||||||
if (_persistThread) {
|
if (_persistThread) {
|
||||||
_persistThread->initialize(true);
|
_persistThread->initialize(true);
|
||||||
}
|
}
|
||||||
|
@ -1197,6 +1218,9 @@ void OctreeServer::aboutToFinish() {
|
||||||
qDebug() << qPrintable(_safeServerName) << "server about to finish while node still connected node:" << *node;
|
qDebug() << qPrintable(_safeServerName) << "server about to finish while node still connected node:" << *node;
|
||||||
forceNodeShutdown(node);
|
forceNodeShutdown(node);
|
||||||
}
|
}
|
||||||
|
if (_persistThread) {
|
||||||
|
_persistThread->aboutToFinish();
|
||||||
|
}
|
||||||
qDebug() << qPrintable(_safeServerName) << "server ENDING about to finish...";
|
qDebug() << qPrintable(_safeServerName) << "server ENDING about to finish...";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,11 @@ protected:
|
||||||
JurisdictionSender* _jurisdictionSender;
|
JurisdictionSender* _jurisdictionSender;
|
||||||
OctreeInboundPacketProcessor* _octreeInboundPacketProcessor;
|
OctreeInboundPacketProcessor* _octreeInboundPacketProcessor;
|
||||||
OctreePersistThread* _persistThread;
|
OctreePersistThread* _persistThread;
|
||||||
|
|
||||||
|
int _persistInterval;
|
||||||
|
bool _wantBackup;
|
||||||
|
QString _backupExtensionFormat;
|
||||||
|
int _backupInterval;
|
||||||
|
|
||||||
static OctreeServer* _instance;
|
static OctreeServer* _instance;
|
||||||
|
|
||||||
|
|
|
@ -276,6 +276,52 @@
|
||||||
"label": "Entity Server Settings",
|
"label": "Entity Server Settings",
|
||||||
"assignment-types": [6],
|
"assignment-types": [6],
|
||||||
"settings": [
|
"settings": [
|
||||||
|
{
|
||||||
|
"name": "persistFilename",
|
||||||
|
"label": "Persistant Filename",
|
||||||
|
"help": "the filename for your entities",
|
||||||
|
"placeholder": "resources/models.svo",
|
||||||
|
"default": "resources/models.svo",
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "persistInterval",
|
||||||
|
"label": "Persist Interval",
|
||||||
|
"help": "Interval between persist checks in msecs.",
|
||||||
|
"placeholder": "30000",
|
||||||
|
"default": "30000",
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NoPersist",
|
||||||
|
"type": "checkbox",
|
||||||
|
"help": "Don't persist your entities to a file.",
|
||||||
|
"default": false,
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "backupExtensionFormat",
|
||||||
|
"label": "Backup File Extension Format:",
|
||||||
|
"help": "Format used to create the extension for the backup of your persisted entities.",
|
||||||
|
"placeholder": ".backup.%Y-%m-%d.%H:%M:%S.%z",
|
||||||
|
"default": ".backup.%Y-%m-%d.%H:%M:%S.%z",
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "backupInterval",
|
||||||
|
"label": "Backup Interval",
|
||||||
|
"help": "Interval between backup checks in msecs.",
|
||||||
|
"placeholder": "1800000",
|
||||||
|
"default": "1800000",
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NoBackup",
|
||||||
|
"type": "checkbox",
|
||||||
|
"help": "Don't regularly backup your persisted entities to a backup file.",
|
||||||
|
"default": false,
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "statusHost",
|
"name": "statusHost",
|
||||||
"label": "Status Hostname",
|
"label": "Status Hostname",
|
||||||
|
@ -330,7 +376,52 @@
|
||||||
"label": "Voxel Server Settings",
|
"label": "Voxel Server Settings",
|
||||||
"assignment-types": [3],
|
"assignment-types": [3],
|
||||||
"settings": [
|
"settings": [
|
||||||
|
{
|
||||||
|
"name": "persistFilename",
|
||||||
|
"label": "Persistant Filename",
|
||||||
|
"help": "the filename for your voxels",
|
||||||
|
"placeholder": "resources/voxels.svo",
|
||||||
|
"default": "resources/voxels.svo",
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "persistInterval",
|
||||||
|
"label": "Persist Interval",
|
||||||
|
"help": "Interval between persist checks in msecs.",
|
||||||
|
"placeholder": "30000",
|
||||||
|
"default": "30000",
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NoPersist",
|
||||||
|
"type": "checkbox",
|
||||||
|
"help": "Don't persist your voxels to a file.",
|
||||||
|
"default": false,
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "backupExtensionFormat",
|
||||||
|
"label": "Backup File Extension Format:",
|
||||||
|
"help": "Format used to create the extension for the backup of your persisted voxels.",
|
||||||
|
"placeholder": ".backup.%Y-%m-%d.%H:%M:%S.%z",
|
||||||
|
"default": ".backup.%Y-%m-%d.%H:%M:%S.%z",
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "backupInterval",
|
||||||
|
"label": "Backup Interval",
|
||||||
|
"help": "Interval between backup checks in msecs.",
|
||||||
|
"placeholder": "1800000",
|
||||||
|
"default": "1800000",
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NoBackup",
|
||||||
|
"type": "checkbox",
|
||||||
|
"help": "Don't regularly backup your persisted voxels to a backup file.",
|
||||||
|
"default": false,
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "statusHost",
|
"name": "statusHost",
|
||||||
"label": "Status Hostname",
|
"label": "Status Hostname",
|
||||||
|
|
8
examples/cleanupChessboards.js
Normal file
8
examples/cleanupChessboards.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
var entities = Entities.findEntities(MyAvatar.position, 10000);
|
||||||
|
var URL = "https://s3.amazonaws.com/hifi-public/models/props/chess/";
|
||||||
|
|
||||||
|
for(var i in entities) {
|
||||||
|
if (Entities.getEntityProperties(entities[i]).modelURL.slice(0, URL.length) === URL) {
|
||||||
|
Entities.deleteEntity(entities[i]);
|
||||||
|
}
|
||||||
|
}
|
294
examples/clonedOverlaysExample.js
Normal file
294
examples/clonedOverlaysExample.js
Normal file
|
@ -0,0 +1,294 @@
|
||||||
|
//
|
||||||
|
// clonedOverlaysExample.js
|
||||||
|
// examples
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 11/13/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Demonstrates the use of the overlay cloning function.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
const NUM_OF_TREES = 40;
|
||||||
|
const NUM_OF_SANTAS = 20;
|
||||||
|
|
||||||
|
// Image source: https://openclipart.org/detail/447/christmas-tree-by-theresaknott (heavily edited by Maximillian Merlin)
|
||||||
|
const CHRISTMAS_TREE_SPRITES_URL = "http://test.thoys.nl/hifi/images/santa/christmas-tree.svg";
|
||||||
|
|
||||||
|
// Image source: http://opengameart.org/content/santa-claus (CC-BY 3.0)
|
||||||
|
const SANTA_SPRITES_URL = "http://test.thoys.nl/hifi/images/santa/Santa.png";
|
||||||
|
|
||||||
|
Array.prototype.contains = function(obj) {
|
||||||
|
var i = this.length;
|
||||||
|
while (i--) {
|
||||||
|
if (this[i] === obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
function getRandomPosAroundMyAvatar(radius, height_offset) {
|
||||||
|
if (height_offset == undefined) {
|
||||||
|
height_offset = 0;
|
||||||
|
}
|
||||||
|
return {x: MyAvatar.position.x + Math.floor(Math.random() * radius * 2) - radius, y: MyAvatar.position.y + height_offset, z: MyAvatar.position.z + Math.floor(Math.random() * radius * 2) - radius};
|
||||||
|
}
|
||||||
|
|
||||||
|
function OverlayPreloader(overlay_type, overlay_properties, loaded_callback) {
|
||||||
|
var _this = this;
|
||||||
|
this.loaded_callback = loaded_callback;
|
||||||
|
this.overlay = Overlays.addOverlay(overlay_type, overlay_properties);
|
||||||
|
this.timer = null;
|
||||||
|
this.timer = Script.setInterval(function() {
|
||||||
|
if (Overlays.isLoaded(_this.overlay)) {
|
||||||
|
Script.clearInterval(_this.timer);
|
||||||
|
_this.loaded_callback();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpriteBillboard(sprite_properties, overlay) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
// set properties
|
||||||
|
this.overlay = overlay;
|
||||||
|
this.overlay_properties = {};
|
||||||
|
this.sprite_properties = sprite_properties;
|
||||||
|
this.edited_overlay_properties = [];
|
||||||
|
this.defaultFPS = 30;
|
||||||
|
this.currentSequence = "";
|
||||||
|
this.sequenceIndex = 0;
|
||||||
|
this.sequenceFPS = 0;
|
||||||
|
this.sequenceStepToNext = false;
|
||||||
|
this.sequenceTimer = null;
|
||||||
|
this.prevSequenceIndex = -1;
|
||||||
|
this.sequenceX = 0;
|
||||||
|
this.sequenceY = 0;
|
||||||
|
|
||||||
|
this.spriteSize = {x: 0, y: 0, width: 32, height: 64};
|
||||||
|
|
||||||
|
this.editedProperty = function(prop_name) {
|
||||||
|
if (!_this.edited_overlay_properties.contains(prop_name)) {
|
||||||
|
_this.edited_overlay_properties.push(prop_name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// function definitions
|
||||||
|
this.getPosition = function() {
|
||||||
|
return _this.overlay_properties.position ?
|
||||||
|
_this.overlay_properties.position : {x: 0, y: 0, z: 0};
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setPosition = function(newPosition) {
|
||||||
|
this.overlay_properties.position = newPosition;
|
||||||
|
this.editedProperty("position");
|
||||||
|
return _this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setAlpha = function(alpha) {
|
||||||
|
this.overlay_properties.alpha = alpha;
|
||||||
|
this.editedProperty("alpha");
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setScale = function(scale) {
|
||||||
|
this.overlay_properties.scale = scale;
|
||||||
|
this.editedProperty("scale");
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setSpriteSize = function(spriteSize) {
|
||||||
|
this.overlay_properties.subImage = spriteSize;
|
||||||
|
this.editedProperty("subImage");
|
||||||
|
return _this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setSpriteXIndex = function(x_index) {
|
||||||
|
_this.sequenceX = x_index;
|
||||||
|
_this.overlay_properties.subImage.x = x_index * _this.overlay_properties.subImage.width;
|
||||||
|
_this.editedProperty("subImage");
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setSpriteYIndex = function(y_index) {
|
||||||
|
_this.sequenceY = y_index;
|
||||||
|
_this.overlay_properties.subImage.y = y_index * _this.overlay_properties.subImage.height;
|
||||||
|
_this.editedProperty("subImage");
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.editOverlay = function(properties) {
|
||||||
|
for (var key in properties) {
|
||||||
|
_this.overlay_properties[attrname] = properties[key];
|
||||||
|
_this.editedProperty(key);
|
||||||
|
}
|
||||||
|
return _this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.commitChanges = function() {
|
||||||
|
var changed_properties = {};
|
||||||
|
for (var i = 0; i < _this.edited_overlay_properties.length; i++) {
|
||||||
|
var key = _this.edited_overlay_properties[i];
|
||||||
|
changed_properties[key] = _this.overlay_properties[key];
|
||||||
|
}
|
||||||
|
if (Object.keys(changed_properties).length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Overlays.editOverlay(_this.overlay, changed_properties);
|
||||||
|
_this.edited_overlay_properties = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
this._renderFrame = function() {
|
||||||
|
var currentSequence = _this.sprite_properties.sequences[_this.currentSequence];
|
||||||
|
var currentItem = currentSequence[_this.sequenceIndex];
|
||||||
|
var indexChanged = _this.sequenceIndex != _this.prevSequenceIndex;
|
||||||
|
var canMoveToNext = true;
|
||||||
|
_this.prevSequenceIndex = _this.sequenceIndex;
|
||||||
|
if (indexChanged) {
|
||||||
|
if (currentItem.loop != undefined) {
|
||||||
|
_this.loopSequence = currentItem.loop;
|
||||||
|
}
|
||||||
|
if (currentItem.fps !== undefined && currentItem.fps != _this.sequenceFPS) {
|
||||||
|
_this.startSequenceTimerFPS(currentItem.fps);
|
||||||
|
}
|
||||||
|
if (currentItem.step_to_next !== undefined) {
|
||||||
|
_this.sequenceStepToNext = currentItem.step_to_next;
|
||||||
|
}
|
||||||
|
if (currentItem.x !== undefined) {
|
||||||
|
_this.setSpriteXIndex(currentItem.x);
|
||||||
|
}
|
||||||
|
if (currentItem.y !== undefined) {
|
||||||
|
_this.setSpriteYIndex(currentItem.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_this.sequenceStepToNext) {
|
||||||
|
canMoveToNext = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_this.prevSequenceIndex = _this.sequenceIndex;
|
||||||
|
var nextIndex = (_this.sequenceIndex + 1) % currentSequence.length;
|
||||||
|
var nextItem = currentSequence[nextIndex];
|
||||||
|
var nextX = nextItem.x != undefined ? nextItem.x : _this.sequenceX;
|
||||||
|
var nextY = nextItem.Y != undefined ? nextItem.Y : _this.sequenceY;
|
||||||
|
|
||||||
|
if (_this.sequenceStepToNext && !indexChanged) {
|
||||||
|
var XMoveNext = true;
|
||||||
|
var YMoveNext = true;
|
||||||
|
if (Math.abs(nextX - _this.sequenceX) > 1) {
|
||||||
|
_this.setSpriteXIndex(_this.sequenceX + (nextX > _this.sequenceX ? 1 : -1));
|
||||||
|
XMoveNext = Math.abs(nextX - _this.sequenceX) == 1;
|
||||||
|
}
|
||||||
|
if (Math.abs(nextY - _this.sequenceY) > 1) {
|
||||||
|
_this.setSpriteYIndex(_this.sequenceY + (nextY > _this.sequenceY ? 1 : -1));
|
||||||
|
YMoveNext = Math.abs(nextY - _this.sequenceY) == 1;
|
||||||
|
}
|
||||||
|
canMoveToNext = XMoveNext && YMoveNext;
|
||||||
|
}
|
||||||
|
if (canMoveToNext) {
|
||||||
|
_this.sequenceIndex = nextIndex;
|
||||||
|
}
|
||||||
|
_this.commitChanges();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.clone = function() {
|
||||||
|
var clone = {};
|
||||||
|
clone.prototype = this.prototype;
|
||||||
|
for (property in this) {
|
||||||
|
clone[property] = this[property];
|
||||||
|
}
|
||||||
|
return clone;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.startSequenceTimerFPS = function(fps) {
|
||||||
|
_this.sequenceFPS = fps;
|
||||||
|
if (_this.sequenceTimer != null) {
|
||||||
|
Script.clearInterval(_this.sequenceTimer);
|
||||||
|
}
|
||||||
|
_this.sequenceTimer = Script.setInterval(_this._renderFrame, 1000 / fps);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.start = function(sequenceName) {
|
||||||
|
this.currentSequence = sequenceName;
|
||||||
|
this.sequenceFPS = this.defaultFPS;
|
||||||
|
this.startSequenceTimerFPS(this.defaultFPS);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.sprite_properties.url !== undefined) {
|
||||||
|
this.setURL(this.sprite_properties.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.sprite_properties.sprite_size !== undefined) {
|
||||||
|
this.setSpriteSize(this.sprite_properties.sprite_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.sprite_properties.scale !== undefined) {
|
||||||
|
this.setScale(this.sprite_properties.scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.sprite_properties.alpha !== undefined) {
|
||||||
|
this.setAlpha(this.sprite_properties.alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.sprite_properties.position !== undefined) {
|
||||||
|
this.setPosition(this.sprite_properties.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
_this.commitChanges();
|
||||||
|
|
||||||
|
if (this.sprite_properties.startup_sequence != undefined) {
|
||||||
|
this.start(this.sprite_properties.startup_sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(function () {
|
||||||
|
if (_this.sequenceTimer != null) {
|
||||||
|
Script.clearInterval(_this.sequenceTimer);
|
||||||
|
}
|
||||||
|
Overlays.deleteOverlay(_this.overlay);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var christmastree_loader = null;
|
||||||
|
christmastree_loader = new OverlayPreloader("billboard",
|
||||||
|
{url: CHRISTMAS_TREE_SPRITES_URL, alpha: 0}, function() {
|
||||||
|
for (var i = 0; i < NUM_OF_TREES; i++) {
|
||||||
|
var clonedOverlay = Overlays.cloneOverlay(christmastree_loader.overlay);
|
||||||
|
new SpriteBillboard({
|
||||||
|
position: getRandomPosAroundMyAvatar(20),
|
||||||
|
sprite_size: {x: 0, y: 0, width: 250.000, height: 357.626},
|
||||||
|
scale: 6,
|
||||||
|
alpha: 1,
|
||||||
|
sequences: {"idle": [{x: 0, y: 0, step_to_next: true, fps: 3}, {x: 3, step_to_next: false}]},
|
||||||
|
startup_sequence: "idle"
|
||||||
|
}, clonedOverlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var santa_loader = null;
|
||||||
|
santa_loader = new OverlayPreloader("billboard",
|
||||||
|
{url: SANTA_SPRITES_URL, alpha: 0}, function() {
|
||||||
|
for (var i = 0; i < NUM_OF_SANTAS; i++) {
|
||||||
|
var clonedOverlay = Overlays.cloneOverlay(santa_loader.overlay);
|
||||||
|
new SpriteBillboard({
|
||||||
|
position: getRandomPosAroundMyAvatar(18, -1),
|
||||||
|
sprite_size: {x: 0, y: 0, width: 64, height: 72},
|
||||||
|
scale: 4,
|
||||||
|
alpha: 1,
|
||||||
|
sequences: {
|
||||||
|
"walk_left": [{x: 2, y: 0, step_to_next: true, fps: 4}, {x: 10, step_to_next: false}],
|
||||||
|
"walk_right": [{x: 10, y: 1, step_to_next: true, fps: 4}, {x: 2, step_to_next: false}],
|
||||||
|
},
|
||||||
|
startup_sequence: (i % 2 == 0) ? "walk_left" : "walk_right"
|
||||||
|
}, clonedOverlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(function () {
|
||||||
|
Overlays.deleteOverlay(christmastree_loader.overlay);
|
||||||
|
Overlays.deleteOverlay(santa_loader.overlay);
|
||||||
|
});
|
201
examples/entityScripts/chessPiece.js
Normal file
201
examples/entityScripts/chessPiece.js
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
(function(){
|
||||||
|
this.FIRST_TILE = null; // Global position of the first tile (1a)
|
||||||
|
this.TILE_SIZE = null; // Size of one tile
|
||||||
|
|
||||||
|
this.wantDebug = false;
|
||||||
|
this.active = false;
|
||||||
|
|
||||||
|
this.entityID = null;
|
||||||
|
this.properties = null;
|
||||||
|
this.boardID = null;
|
||||||
|
this.boardUserData = null;
|
||||||
|
|
||||||
|
this.sound = null;
|
||||||
|
this.startingTile = null;
|
||||||
|
this.pieces = new Array();
|
||||||
|
|
||||||
|
// All callbacks start by updating the properties
|
||||||
|
this.updateProperties = function(entityID) {
|
||||||
|
// Piece ID
|
||||||
|
if (this.entityID === null || !this.entityID.isKnownID) {
|
||||||
|
this.entityID = Entities.identifyEntity(entityID);
|
||||||
|
}
|
||||||
|
// Piece Properties
|
||||||
|
this.properties = Entities.getEntityProperties(this.entityID);
|
||||||
|
|
||||||
|
// Board ID
|
||||||
|
if (this.boardID === null) {
|
||||||
|
// Read user data string and update boardID
|
||||||
|
var userData = JSON.parse(this.properties.userData);
|
||||||
|
var boardID = Entities.identifyEntity(userData.boardID);
|
||||||
|
if (boardID.isKnownID) {
|
||||||
|
this.boardID = boardID;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Board User Data
|
||||||
|
this.updateUserData();
|
||||||
|
}
|
||||||
|
// Get an entity's user data
|
||||||
|
this.getEntityUserData = function(entityID) {
|
||||||
|
var properties = Entities.getEntityProperties(entityID);
|
||||||
|
|
||||||
|
if (properties && properties.userData){
|
||||||
|
return JSON.parse(properties.userData);
|
||||||
|
} else {
|
||||||
|
print("No user data found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Updates user data related objects
|
||||||
|
this.updateUserData = function() {
|
||||||
|
// Get board's user data
|
||||||
|
if (this.boardID !== null && this.boardID.isKnownID) {
|
||||||
|
this.boardUserData = this.getEntityUserData(this.boardID);
|
||||||
|
|
||||||
|
if (!(this.boardUserData &&
|
||||||
|
this.boardUserData.firstTile &&
|
||||||
|
this.boardUserData.tileSize)) {
|
||||||
|
print("Incomplete boardUserData " + this.boardID.id);
|
||||||
|
} else {
|
||||||
|
this.FIRST_TILE = this.boardUserData.firstTile;
|
||||||
|
this.TILE_SIZE = this.boardUserData.tileSize;
|
||||||
|
|
||||||
|
this.active = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("Missing boardID:" + JSON.stringify(this.boardID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Returns whether pos is inside the grid or not
|
||||||
|
this.isOutsideGrid = function(pos) {
|
||||||
|
return !(pos.i >= 0 && pos.j >= 0 && pos.i < 8 && pos.j < 8);
|
||||||
|
}
|
||||||
|
// Returns the tile coordinate
|
||||||
|
this.getIndexPosition = function(position) {
|
||||||
|
var halfTile = this.TILE_SIZE / 2.0;
|
||||||
|
var corner = Vec3.sum(this.FIRST_TILE, { x: -halfTile, y: 0.0, z: -halfTile });
|
||||||
|
var relative = Vec3.subtract(position, corner);
|
||||||
|
return {
|
||||||
|
i: Math.floor(relative.x / this.TILE_SIZE),
|
||||||
|
j: Math.floor(relative.z / this.TILE_SIZE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Returns the world position
|
||||||
|
this.getAbsolutePosition = function(pos, halfHeight) {
|
||||||
|
var relative = {
|
||||||
|
x: pos.i * this.TILE_SIZE,
|
||||||
|
y: halfHeight,
|
||||||
|
z: pos.j * this.TILE_SIZE
|
||||||
|
}
|
||||||
|
return Vec3.sum(this.FIRST_TILE, relative);
|
||||||
|
}
|
||||||
|
// Pr, Vr are respectively the Ray's Point of origin and Vector director
|
||||||
|
// Pp, Np are respectively the Plane's Point of origin and Normal vector
|
||||||
|
this.rayPlaneIntersection = function(Pr, Vr, Pp, Np) {
|
||||||
|
var d = -Vec3.dot(Pp, Np);
|
||||||
|
var t = -(Vec3.dot(Pr, Np) + d) / Vec3.dot(Vr, Np);
|
||||||
|
return Vec3.sum(Pr, Vec3.multiply(t, Vr));
|
||||||
|
}
|
||||||
|
// Download sound if needed
|
||||||
|
this.maybeDownloadSound = function() {
|
||||||
|
if (this.sound === null) {
|
||||||
|
this.sound = SoundCache.getSound("http://public.highfidelity.io/sounds/Footsteps/FootstepW3Left-12db.wav");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Play drop sound
|
||||||
|
this.playSound = function() {
|
||||||
|
if (this.sound && this.sound.downloaded) {
|
||||||
|
Audio.playSound(this.sound, { position: this.properties.position });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// updates the piece position based on mouse input
|
||||||
|
this.updatePosition = function(mouseEvent) {
|
||||||
|
var pickRay = Camera.computePickRay(mouseEvent.x, mouseEvent.y)
|
||||||
|
var upVector = { x: 0, y: 1, z: 0 };
|
||||||
|
var intersection = this.rayPlaneIntersection(pickRay.origin, pickRay.direction,
|
||||||
|
this.properties.position, upVector);
|
||||||
|
// if piece outside grid then send it back to the starting tile
|
||||||
|
if (this.isOutsideGrid(this.getIndexPosition(intersection))) {
|
||||||
|
intersection = this.getAbsolutePosition(this.startingTile, this.properties.dimensions.y / 2.0);
|
||||||
|
}
|
||||||
|
Entities.editEntity(this.entityID, { position: intersection });
|
||||||
|
}
|
||||||
|
// Snap piece to the center of the tile it is on
|
||||||
|
this.snapToGrid = function() {
|
||||||
|
var pos = this.getIndexPosition(this.properties.position);
|
||||||
|
var finalPos = this.getAbsolutePosition((this.isOutsideGrid(pos)) ? this.startingTile : pos,
|
||||||
|
this.properties.dimensions.y / 2.0);
|
||||||
|
Entities.editEntity(this.entityID, { position: finalPos });
|
||||||
|
}
|
||||||
|
this.moveDeadPiece = function() {
|
||||||
|
var myPos = this.getIndexPosition(this.properties.position);
|
||||||
|
var others = Entities.findEntities(this.properties.position, this.properties.dimensions.y);
|
||||||
|
|
||||||
|
for (var i = 0; i < others.length; i++) {
|
||||||
|
var piece = others[i];
|
||||||
|
|
||||||
|
if (piece.id != this.entityID.id) {
|
||||||
|
var properties = Entities.getEntityProperties(piece);
|
||||||
|
|
||||||
|
var isWhite = properties.modelURL.search("White") !== -1;
|
||||||
|
var type = (properties.modelURL.search("King") !== -1) ? 4 :
|
||||||
|
(properties.modelURL.search("Queen") !== -1) ? 3 :
|
||||||
|
(properties.modelURL.search("Rook") !== -1) ? 2 :
|
||||||
|
(properties.modelURL.search("Knight") !== -1) ? 1 :
|
||||||
|
(properties.modelURL.search("Bishop") !== -1) ? 0 :
|
||||||
|
(properties.modelURL.search("Pawn") !== -1) ? -1 : -2;
|
||||||
|
|
||||||
|
var piecePos = this.getIndexPosition(properties.position);
|
||||||
|
if (myPos.i === piecePos.i && myPos.j === piecePos.j && type !== -2) {
|
||||||
|
var position = this.getAbsolutePosition((isWhite) ? { i: type, j: -1 } : { i: 7 - type, j: 8 },
|
||||||
|
properties.dimensions.y / 2.0);
|
||||||
|
Entities.editEntity(piece, {
|
||||||
|
position: position
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.grab = function(mouseEvent) {
|
||||||
|
if (this.active) {
|
||||||
|
this.startingTile = this.getIndexPosition(this.properties.position);
|
||||||
|
this.updatePosition(mouseEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.move = function(mouseEvent) {
|
||||||
|
if (this.active) {
|
||||||
|
this.updatePosition(mouseEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.release = function(mouseEvent) {
|
||||||
|
if (this.active) {
|
||||||
|
this.updatePosition(mouseEvent);
|
||||||
|
this.snapToGrid();
|
||||||
|
this.moveDeadPiece();
|
||||||
|
this.playSound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.preload = function(entityID) {
|
||||||
|
this.updateProperties(entityID); // All callbacks start by updating the properties
|
||||||
|
this.maybeDownloadSound();
|
||||||
|
}
|
||||||
|
this.clickDownOnEntity = function(entityID, mouseEvent) {
|
||||||
|
this.preload(entityID); // TODO : remove
|
||||||
|
this.updateProperties(entityID); // All callbacks start by updating the properties
|
||||||
|
this.grab(mouseEvent);
|
||||||
|
};
|
||||||
|
this.holdingClickOnEntity = function(entityID, mouseEvent) {
|
||||||
|
this.updateProperties(entityID); // All callbacks start by updating the properties
|
||||||
|
this.move(mouseEvent);
|
||||||
|
};
|
||||||
|
this.clickReleaseOnEntity = function(entityID, mouseEvent) {
|
||||||
|
this.updateProperties(entityID); // All callbacks start by updating the properties
|
||||||
|
this.release(mouseEvent);
|
||||||
|
};
|
||||||
|
})
|
262
examples/playChess.js
Normal file
262
examples/playChess.js
Normal file
|
@ -0,0 +1,262 @@
|
||||||
|
//
|
||||||
|
// playChess.js
|
||||||
|
// examples
|
||||||
|
//
|
||||||
|
// Created by Clement Brisset on 11/08/2014
|
||||||
|
// Copyright 2014 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
|
||||||
|
|
||||||
|
var gamePosition = { x: 1.0, y: 1.0, z: 1.0 };
|
||||||
|
var gameSize = 1.0;
|
||||||
|
|
||||||
|
// Script namespace
|
||||||
|
var extraDebug = extraDebug || true;
|
||||||
|
var ChessGame = ChessGame || {
|
||||||
|
BOARD: {
|
||||||
|
modelURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/Board.fbx",
|
||||||
|
dimensions: { x: 773.191, y: 20.010, z: 773.191 },
|
||||||
|
rotation: Quat.fromPitchYawRollDegrees(0, 90, 0),
|
||||||
|
numTiles: 10.0
|
||||||
|
},
|
||||||
|
KING: 0, QUEEN: 1, BISHOP: 2, KNIGHT: 3, ROOK: 4, PAWN: 5,
|
||||||
|
|
||||||
|
board: null,
|
||||||
|
pieces: new Array()
|
||||||
|
};
|
||||||
|
|
||||||
|
ChessGame.getPieceInfo = function(type, isWhite) {
|
||||||
|
var info = {
|
||||||
|
modelURL: "https://s3.amazonaws.com/hifi-public/models/props/chess/",
|
||||||
|
dimensions: { x: 1.0, y: 1.0, z: 1.0 },
|
||||||
|
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case ChessGame.KING:
|
||||||
|
info.modelURL += "King";
|
||||||
|
info.dimensions = { x: 110.496, y: 306.713, z: 110.496 };
|
||||||
|
info.rotation = Quat.fromPitchYawRollDegrees(0, 90, 0);
|
||||||
|
break;
|
||||||
|
case ChessGame.QUEEN:
|
||||||
|
info.modelURL += "Queen";
|
||||||
|
info.dimensions = { x: 110.496, y: 257.459, z: 110.496 };
|
||||||
|
break;
|
||||||
|
case ChessGame.BISHOP:
|
||||||
|
info.modelURL += "Bishop";
|
||||||
|
info.dimensions = { x: 102.002, y: 213.941, z: 102.002 };
|
||||||
|
info.rotation = Quat.fromPitchYawRollDegrees(0, 90, 0);
|
||||||
|
break;
|
||||||
|
case ChessGame.KNIGHT:
|
||||||
|
info.modelURL += "Knight";
|
||||||
|
info.dimensions = { x: 95.602, y: 186.939, z: 95.602 };
|
||||||
|
info.rotation = Quat.fromPitchYawRollDegrees(0, 180, 0);
|
||||||
|
break;
|
||||||
|
case ChessGame.ROOK:
|
||||||
|
info.modelURL += "Rook";
|
||||||
|
info.dimensions = { x: 101.024, y: 167.523, z: 101.024 };
|
||||||
|
break;
|
||||||
|
case ChessGame.PAWN:
|
||||||
|
info.modelURL += "Pawn";
|
||||||
|
info.dimensions = { x: 93.317, y: 138.747, z: 93.317 };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
info.modelURL += ((isWhite) ? "_White" : "_Black") + ".fbx"
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Board class
|
||||||
|
ChessGame.Board = (function(position, scale) {
|
||||||
|
this.dimensions = Vec3.multiply(1.0 / ChessGame.BOARD.dimensions.x, ChessGame.BOARD.dimensions); // 1 by 1
|
||||||
|
this.dimensions = Vec3.multiply(scale, this.dimensions); // scale by scale
|
||||||
|
this.position = position
|
||||||
|
this.tileSize = scale / ChessGame.BOARD.numTiles;
|
||||||
|
|
||||||
|
this.userDataObject = {
|
||||||
|
firstTile: this.tilePosition(1, 1),
|
||||||
|
tileSize: this.tileSize,
|
||||||
|
whitesDeadPieces: this.tilePosition(0,0),
|
||||||
|
blacksDeadPieces: this.tilePosition(9,9)
|
||||||
|
}
|
||||||
|
this.entityProperties = {
|
||||||
|
type: "Model",
|
||||||
|
modelURL: ChessGame.BOARD.modelURL,
|
||||||
|
position: this.position,
|
||||||
|
dimensions: this.dimensions,
|
||||||
|
userData: this.buildUserDataString()
|
||||||
|
}
|
||||||
|
this.entity = null;
|
||||||
|
});
|
||||||
|
// Returns the top center point of tile i,j
|
||||||
|
ChessGame.Board.prototype.tilePosition = function(i, j) {
|
||||||
|
if (!(this.position || this.dimensions || this.tileSize || ChessGame.BOARD.numTiles)) {
|
||||||
|
print("ChessGame.Board.prototype.tilePosition(): Called before proper initialisation, bailing.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
x: this.position.x + (i - ChessGame.BOARD.numTiles / 2.0 + 0.5) * this.tileSize,
|
||||||
|
y: this.position.y + this.dimensions.y / 2.0,
|
||||||
|
z: this.position.z + (j - ChessGame.BOARD.numTiles / 2.0 + 0.5) * this.tileSize
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Checks the color of the tile
|
||||||
|
ChessGame.Board.prototype.isWhite = function(i, j) {
|
||||||
|
return (i + j) % 2 != 0;
|
||||||
|
}
|
||||||
|
// Build the user data string
|
||||||
|
ChessGame.Board.prototype.buildUserDataString = function() {
|
||||||
|
return JSON.stringify(this.userDataObject);
|
||||||
|
}
|
||||||
|
// Updates the user data stored by the board
|
||||||
|
ChessGame.Board.prototype.updateUserData = function() {
|
||||||
|
var userDataString = this.buildUserDataString();
|
||||||
|
this.entityProperties.userData = userDataString;
|
||||||
|
Entities.editEntity(this.entity, { userData: userDataString });
|
||||||
|
}
|
||||||
|
// Spawns the board using entities
|
||||||
|
ChessGame.Board.prototype.spawn = function() {
|
||||||
|
if (extraDebug) {
|
||||||
|
print("Spawning board...");
|
||||||
|
}
|
||||||
|
this.entity = Entities.addEntity(this.entityProperties);
|
||||||
|
print("Board spawned");
|
||||||
|
}
|
||||||
|
// Cleans up the entities of the board
|
||||||
|
ChessGame.Board.prototype.cleanup = function() {
|
||||||
|
if (extraDebug) {
|
||||||
|
print("Cleaning up board...");
|
||||||
|
}
|
||||||
|
Entities.deleteEntity(this.entity);
|
||||||
|
print("Board cleaned up");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Piece class
|
||||||
|
ChessGame.Piece = (function(position, dimensions, url, rotation) {
|
||||||
|
this.dimensions = dimensions;
|
||||||
|
this.position = position;
|
||||||
|
this.position.y += this.dimensions.y / 2.0;
|
||||||
|
|
||||||
|
this.entityProperties = {
|
||||||
|
type: "Model",
|
||||||
|
position: this.position,
|
||||||
|
rotation: rotation,
|
||||||
|
dimensions: this.dimensions,
|
||||||
|
modelURL: url,
|
||||||
|
/**/
|
||||||
|
script: "https://s3.amazonaws.com/hifi-public/scripts/entityScripts/chessPiece.js",
|
||||||
|
/*/
|
||||||
|
script: "file:/Users/clement/hifi/examples/entityScripts/chessPiece.js",
|
||||||
|
/**/
|
||||||
|
userData: this.buildUserDataString()
|
||||||
|
}
|
||||||
|
this.entity = null;
|
||||||
|
});
|
||||||
|
// Build the user data string
|
||||||
|
ChessGame.Piece.prototype.buildUserDataString = function() {
|
||||||
|
if (!(ChessGame.board !== null || ChessGame.board.entity.isKnownID)) {
|
||||||
|
print("ChessGame.Piece.prototype.buildUserDataString(): Called before proper initialization, bailing.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var userDataObject = {
|
||||||
|
boardID: ChessGame.board.entity,
|
||||||
|
};
|
||||||
|
return JSON.stringify(userDataObject);
|
||||||
|
}
|
||||||
|
// Spawns the piece
|
||||||
|
ChessGame.Piece.prototype.spawn = function() {
|
||||||
|
this.entity = Entities.addEntity(this.entityProperties);
|
||||||
|
}
|
||||||
|
// Cleans up the piece
|
||||||
|
ChessGame.Piece.prototype.cleanup = function() {
|
||||||
|
Entities.deleteEntity(this.entity);
|
||||||
|
}
|
||||||
|
ChessGame.makePiece = function(piece, i, j, isWhite) {
|
||||||
|
var info = ChessGame.getPieceInfo(piece, isWhite);
|
||||||
|
var url = info.modelURL;
|
||||||
|
var size = Vec3.multiply(0.5 * (1.0 / ChessGame.BOARD.dimensions.x), info.dimensions);
|
||||||
|
var rotation = (isWhite) ? info.rotation
|
||||||
|
: Quat.multiply(Quat.fromPitchYawRollDegrees(0, 180, 0),
|
||||||
|
info.rotation);
|
||||||
|
var position = ChessGame.board.tilePosition(i, j);
|
||||||
|
|
||||||
|
var piece = new ChessGame.Piece(position, size, url, rotation);
|
||||||
|
piece.spawn();
|
||||||
|
ChessGame.pieces.push(piece);
|
||||||
|
return piece;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChessGame.scriptStarting = function() {
|
||||||
|
print("playChess.js started");
|
||||||
|
gamePosition = Vec3.sum(MyAvatar.position,
|
||||||
|
Vec3.multiplyQbyV(MyAvatar.orientation,
|
||||||
|
{ x: 0, y: 0, z: -1 }));
|
||||||
|
// Setup board
|
||||||
|
ChessGame.board = new ChessGame.Board(gamePosition, gameSize);
|
||||||
|
ChessGame.board.spawn();
|
||||||
|
}
|
||||||
|
|
||||||
|
ChessGame.update = function() {
|
||||||
|
ChessGame.board.entity = Entities.identifyEntity(ChessGame.board.entity);
|
||||||
|
|
||||||
|
if (ChessGame.board.entity.isKnownID && ChessGame.pieces.length == 0) {
|
||||||
|
// Setup white pieces
|
||||||
|
var isWhite = true;
|
||||||
|
var row = 1;
|
||||||
|
// King
|
||||||
|
ChessGame.makePiece(ChessGame.KING, row, 5, isWhite);
|
||||||
|
// Queen
|
||||||
|
ChessGame.makePiece(ChessGame.QUEEN, row, 4, isWhite);
|
||||||
|
// Bishop
|
||||||
|
ChessGame.makePiece(ChessGame.BISHOP, row, 3, isWhite);
|
||||||
|
ChessGame.makePiece(ChessGame.BISHOP, row, 6, isWhite);
|
||||||
|
// Knight
|
||||||
|
ChessGame.makePiece(ChessGame.KNIGHT, row, 2, isWhite);
|
||||||
|
ChessGame.makePiece(ChessGame.KNIGHT, row, 7, isWhite);
|
||||||
|
// Rook
|
||||||
|
ChessGame.makePiece(ChessGame.ROOK, row, 1, isWhite);
|
||||||
|
ChessGame.makePiece(ChessGame.ROOK, row, 8, isWhite);
|
||||||
|
for(var j = 1; j <= 8; j++) {
|
||||||
|
ChessGame.makePiece(ChessGame.PAWN, row + 1, j, isWhite);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup black pieces
|
||||||
|
isWhite = false;
|
||||||
|
row = 8;
|
||||||
|
// King
|
||||||
|
ChessGame.makePiece(ChessGame.KING, row, 5, isWhite);
|
||||||
|
// Queen
|
||||||
|
ChessGame.makePiece(ChessGame.QUEEN, row, 4, isWhite);
|
||||||
|
// Bishop
|
||||||
|
ChessGame.makePiece(ChessGame.BISHOP, row, 3, isWhite);
|
||||||
|
ChessGame.makePiece(ChessGame.BISHOP, row, 6, isWhite);
|
||||||
|
// Knight
|
||||||
|
ChessGame.makePiece(ChessGame.KNIGHT, row, 2, isWhite);
|
||||||
|
ChessGame.makePiece(ChessGame.KNIGHT, row, 7, isWhite);
|
||||||
|
// Rook
|
||||||
|
ChessGame.makePiece(ChessGame.ROOK, row, 1, isWhite);
|
||||||
|
ChessGame.makePiece(ChessGame.ROOK, row, 8, isWhite);
|
||||||
|
for(var j = 1; j <= 8; j++) {
|
||||||
|
ChessGame.makePiece(ChessGame.PAWN, row - 1, j, isWhite);
|
||||||
|
}
|
||||||
|
Script.update.disconnect(ChessGame.update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ChessGame.scriptEnding = function() {
|
||||||
|
// Cleaning up board
|
||||||
|
ChessGame.board.cleanup();
|
||||||
|
|
||||||
|
// Cleaning up pieces
|
||||||
|
for(var i in ChessGame.pieces) {
|
||||||
|
ChessGame.pieces[i].cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
print("playChess.js finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(ChessGame.scriptEnding);
|
||||||
|
Script.update.connect(ChessGame.update);
|
||||||
|
ChessGame.scriptStarting();
|
|
@ -165,10 +165,12 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
||||||
|
|
||||||
QString scriptContents = loadScriptContents(entity->getScript());
|
QString scriptContents = loadScriptContents(entity->getScript());
|
||||||
|
|
||||||
if (QScriptEngine::checkSyntax(scriptContents).state() != QScriptSyntaxCheckResult::Valid) {
|
QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(scriptContents);
|
||||||
|
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
|
||||||
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
||||||
qDebug() << " INVALID SYNTAX";
|
qDebug() << " " << syntaxCheck.errorMessage() << ":"
|
||||||
qDebug() << " SCRIPT:" << scriptContents;
|
<< syntaxCheck.errorLineNumber() << syntaxCheck.errorColumnNumber();
|
||||||
|
qDebug() << " SCRIPT:" << entity->getScript();
|
||||||
return QScriptValue(); // invalid script
|
return QScriptValue(); // invalid script
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +179,7 @@ QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
|
||||||
if (!entityScriptConstructor.isFunction()) {
|
if (!entityScriptConstructor.isFunction()) {
|
||||||
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
|
||||||
qDebug() << " NOT CONSTRUCTOR";
|
qDebug() << " NOT CONSTRUCTOR";
|
||||||
qDebug() << " SCRIPT:" << scriptContents;
|
qDebug() << " SCRIPT:" << entity->getScript();
|
||||||
return QScriptValue(); // invalid script
|
return QScriptValue(); // invalid script
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,17 @@ Base3DOverlay::Base3DOverlay() :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Base3DOverlay::Base3DOverlay(const Base3DOverlay* base3DOverlay) :
|
||||||
|
Overlay(base3DOverlay),
|
||||||
|
_position(base3DOverlay->_position),
|
||||||
|
_lineWidth(base3DOverlay->_lineWidth),
|
||||||
|
_rotation(base3DOverlay->_rotation),
|
||||||
|
_isSolid(base3DOverlay->_isSolid),
|
||||||
|
_isDashedLine(base3DOverlay->_isDashedLine),
|
||||||
|
_ignoreRayIntersection(base3DOverlay->_ignoreRayIntersection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Base3DOverlay::~Base3DOverlay() {
|
Base3DOverlay::~Base3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,8 +189,4 @@ void Base3DOverlay::drawDashedLine(const glm::vec3& start, const glm::vec3& end)
|
||||||
glVertex3f(end.x, end.y, end.z);
|
glVertex3f(end.x, end.y, end.z);
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Base3DOverlay : public Overlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Base3DOverlay();
|
Base3DOverlay();
|
||||||
|
Base3DOverlay(const Base3DOverlay* base3DOverlay);
|
||||||
~Base3DOverlay();
|
~Base3DOverlay();
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
|
@ -64,6 +65,5 @@ protected:
|
||||||
bool _isDashedLine;
|
bool _isDashedLine;
|
||||||
bool _ignoreRayIntersection;
|
bool _ignoreRayIntersection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_Base3DOverlay_h
|
#endif // hifi_Base3DOverlay_h
|
||||||
|
|
|
@ -24,6 +24,17 @@ BillboardOverlay::BillboardOverlay() :
|
||||||
_isLoaded = false;
|
_isLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BillboardOverlay::BillboardOverlay(const BillboardOverlay* billboardOverlay) :
|
||||||
|
Base3DOverlay(billboardOverlay),
|
||||||
|
_newTextureNeeded(true),
|
||||||
|
_scale(billboardOverlay->_scale),
|
||||||
|
_isFacingAvatar(billboardOverlay->_isFacingAvatar),
|
||||||
|
_fromImage(billboardOverlay->_fromImage),
|
||||||
|
_url(billboardOverlay->_url),
|
||||||
|
_billboard(billboardOverlay->_billboard)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void BillboardOverlay::render(RenderArgs* args) {
|
void BillboardOverlay::render(RenderArgs* args) {
|
||||||
if (!_visible || !_isLoaded) {
|
if (!_visible || !_isLoaded) {
|
||||||
return;
|
return;
|
||||||
|
@ -215,3 +226,6 @@ bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::v
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BillboardOverlay* BillboardOverlay::createClone() const {
|
||||||
|
return new BillboardOverlay(this);
|
||||||
|
}
|
||||||
|
|
|
@ -22,7 +22,8 @@ class BillboardOverlay : public Base3DOverlay {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
BillboardOverlay();
|
BillboardOverlay();
|
||||||
|
BillboardOverlay(const BillboardOverlay* billboardOverlay);
|
||||||
|
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
|
|
||||||
// setters
|
// setters
|
||||||
|
@ -36,6 +37,8 @@ public:
|
||||||
|
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||||
|
|
||||||
|
virtual BillboardOverlay* createClone() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void replyFinished();
|
void replyFinished();
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,22 @@ Circle3DOverlay::Circle3DOverlay() :
|
||||||
_minorTickMarksColor.red = _minorTickMarksColor.green = _minorTickMarksColor.blue = (unsigned char)0;
|
_minorTickMarksColor.red = _minorTickMarksColor.green = _minorTickMarksColor.blue = (unsigned char)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Circle3DOverlay::Circle3DOverlay(const Circle3DOverlay* circle3DOverlay) :
|
||||||
|
Planar3DOverlay(circle3DOverlay),
|
||||||
|
_startAt(circle3DOverlay->_startAt),
|
||||||
|
_endAt(circle3DOverlay->_endAt),
|
||||||
|
_outerRadius(circle3DOverlay->_outerRadius),
|
||||||
|
_innerRadius(circle3DOverlay->_innerRadius),
|
||||||
|
_hasTickMarks(circle3DOverlay->_hasTickMarks),
|
||||||
|
_majorTickMarksAngle(circle3DOverlay->_majorTickMarksAngle),
|
||||||
|
_minorTickMarksAngle(circle3DOverlay->_minorTickMarksAngle),
|
||||||
|
_majorTickMarksLength(circle3DOverlay->_majorTickMarksLength),
|
||||||
|
_minorTickMarksLength(circle3DOverlay->_minorTickMarksLength),
|
||||||
|
_majorTickMarksColor(circle3DOverlay->_majorTickMarksColor),
|
||||||
|
_minorTickMarksColor(circle3DOverlay->_minorTickMarksColor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Circle3DOverlay::~Circle3DOverlay() {
|
Circle3DOverlay::~Circle3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,9 +374,6 @@ bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin,
|
||||||
return intersects;
|
return intersects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Circle3DOverlay* Circle3DOverlay::createClone() const {
|
||||||
|
return new Circle3DOverlay(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ class Circle3DOverlay : public Planar3DOverlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Circle3DOverlay();
|
Circle3DOverlay();
|
||||||
|
Circle3DOverlay(const Circle3DOverlay* circle3DOverlay);
|
||||||
~Circle3DOverlay();
|
~Circle3DOverlay();
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
|
@ -48,6 +49,8 @@ public:
|
||||||
void setMinorTickMarksColor(const xColor& value) { _minorTickMarksColor = value; }
|
void setMinorTickMarksColor(const xColor& value) { _minorTickMarksColor = value; }
|
||||||
|
|
||||||
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const;
|
||||||
|
|
||||||
|
virtual Circle3DOverlay* createClone() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float _startAt;
|
float _startAt;
|
||||||
|
|
|
@ -22,6 +22,11 @@
|
||||||
Cube3DOverlay::Cube3DOverlay() {
|
Cube3DOverlay::Cube3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cube3DOverlay::Cube3DOverlay(const Cube3DOverlay* cube3DOverlay) :
|
||||||
|
Volume3DOverlay(cube3DOverlay)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Cube3DOverlay::~Cube3DOverlay() {
|
Cube3DOverlay::~Cube3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,3 +107,7 @@ void Cube3DOverlay::render(RenderArgs* args) {
|
||||||
delete glower;
|
delete glower;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cube3DOverlay* Cube3DOverlay::createClone() const {
|
||||||
|
return new Cube3DOverlay(this);
|
||||||
|
}
|
||||||
|
|
|
@ -18,8 +18,11 @@ class Cube3DOverlay : public Volume3DOverlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Cube3DOverlay();
|
Cube3DOverlay();
|
||||||
|
Cube3DOverlay(const Cube3DOverlay* cube3DOverlay);
|
||||||
~Cube3DOverlay();
|
~Cube3DOverlay();
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
|
|
||||||
|
virtual Cube3DOverlay* createClone() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,13 @@ Grid3DOverlay::Grid3DOverlay() : Base3DOverlay(),
|
||||||
_majorGridEvery(5) {
|
_majorGridEvery(5) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Grid3DOverlay::Grid3DOverlay(const Grid3DOverlay* grid3DOverlay) :
|
||||||
|
Base3DOverlay(grid3DOverlay),
|
||||||
|
_minorGridWidth(grid3DOverlay->_minorGridWidth),
|
||||||
|
_majorGridEvery(grid3DOverlay->_majorGridEvery)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Grid3DOverlay::~Grid3DOverlay() {
|
Grid3DOverlay::~Grid3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,3 +134,7 @@ QScriptValue Grid3DOverlay::getProperty(const QString& property) {
|
||||||
|
|
||||||
return Base3DOverlay::getProperty(property);
|
return Base3DOverlay::getProperty(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Grid3DOverlay* Grid3DOverlay::createClone() const {
|
||||||
|
return new Grid3DOverlay(this);
|
||||||
|
}
|
||||||
|
|
|
@ -29,12 +29,15 @@ class Grid3DOverlay : public Base3DOverlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Grid3DOverlay();
|
Grid3DOverlay();
|
||||||
|
Grid3DOverlay(const Grid3DOverlay* grid3DOverlay);
|
||||||
~Grid3DOverlay();
|
~Grid3DOverlay();
|
||||||
|
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
|
virtual Grid3DOverlay* createClone() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float _minorGridWidth;
|
float _minorGridWidth;
|
||||||
int _majorGridEvery;
|
int _majorGridEvery;
|
||||||
|
|
|
@ -27,6 +27,17 @@ ImageOverlay::ImageOverlay() :
|
||||||
_isLoaded = false;
|
_isLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageOverlay::ImageOverlay(const ImageOverlay* imageOverlay) :
|
||||||
|
Overlay2D(imageOverlay),
|
||||||
|
_textureID(0),
|
||||||
|
_textureBound(false),
|
||||||
|
_wantClipFromImage(false),
|
||||||
|
_renderImage(imageOverlay->_renderImage),
|
||||||
|
_imageURL(imageOverlay->_imageURL),
|
||||||
|
_textureImage(imageOverlay->_textureImage)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ImageOverlay::~ImageOverlay() {
|
ImageOverlay::~ImageOverlay() {
|
||||||
if (_parent && _textureID) {
|
if (_parent && _textureID) {
|
||||||
// do we need to call this?
|
// do we need to call this?
|
||||||
|
@ -161,3 +172,6 @@ QScriptValue ImageOverlay::getProperty(const QString& property) {
|
||||||
|
|
||||||
return Overlay2D::getProperty(property);
|
return Overlay2D::getProperty(property);
|
||||||
}
|
}
|
||||||
|
ImageOverlay* ImageOverlay::createClone() const {
|
||||||
|
return new ImageOverlay(this);
|
||||||
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ class ImageOverlay : public Overlay2D {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImageOverlay();
|
ImageOverlay();
|
||||||
|
ImageOverlay(const ImageOverlay* imageOverlay);
|
||||||
~ImageOverlay();
|
~ImageOverlay();
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
|
|
||||||
|
@ -46,6 +47,8 @@ public:
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
|
virtual ImageOverlay* createClone() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void replyFinished(); // we actually want to hide this...
|
void replyFinished(); // we actually want to hide this...
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,12 @@
|
||||||
Line3DOverlay::Line3DOverlay() {
|
Line3DOverlay::Line3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Line3DOverlay::Line3DOverlay(const Line3DOverlay* line3DOverlay) :
|
||||||
|
Base3DOverlay(line3DOverlay),
|
||||||
|
_end(line3DOverlay->_end)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Line3DOverlay::~Line3DOverlay() {
|
Line3DOverlay::~Line3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,3 +93,7 @@ QScriptValue Line3DOverlay::getProperty(const QString& property) {
|
||||||
|
|
||||||
return Base3DOverlay::getProperty(property);
|
return Base3DOverlay::getProperty(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Line3DOverlay* Line3DOverlay::createClone() const {
|
||||||
|
return new Line3DOverlay(this);
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ class Line3DOverlay : public Base3DOverlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Line3DOverlay();
|
Line3DOverlay();
|
||||||
|
Line3DOverlay(const Line3DOverlay* line3DOverlay);
|
||||||
~Line3DOverlay();
|
~Line3DOverlay();
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
|
|
||||||
|
@ -30,6 +31,8 @@ public:
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
|
virtual Line3DOverlay* createClone() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
glm::vec3 _end;
|
glm::vec3 _end;
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,13 @@ LocalModelsOverlay::LocalModelsOverlay(EntityTreeRenderer* entityTreeRenderer) :
|
||||||
_entityTreeRenderer(entityTreeRenderer) {
|
_entityTreeRenderer(entityTreeRenderer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalModelsOverlay::LocalModelsOverlay(const LocalModelsOverlay* localModelsOverlay) :
|
||||||
|
Volume3DOverlay(localModelsOverlay),
|
||||||
|
_entityTreeRenderer(localModelsOverlay->_entityTreeRenderer)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
LocalModelsOverlay::~LocalModelsOverlay() {
|
LocalModelsOverlay::~LocalModelsOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,3 +55,7 @@ void LocalModelsOverlay::render(RenderArgs* args) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalModelsOverlay* LocalModelsOverlay::createClone() const {
|
||||||
|
return new LocalModelsOverlay(this);
|
||||||
|
}
|
||||||
|
|
|
@ -20,11 +20,14 @@ class LocalModelsOverlay : public Volume3DOverlay {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LocalModelsOverlay(EntityTreeRenderer* entityTreeRenderer);
|
LocalModelsOverlay(EntityTreeRenderer* entityTreeRenderer);
|
||||||
|
LocalModelsOverlay(const LocalModelsOverlay* localModelsOverlay);
|
||||||
~LocalModelsOverlay();
|
~LocalModelsOverlay();
|
||||||
|
|
||||||
virtual void update(float deltatime);
|
virtual void update(float deltatime);
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
|
|
||||||
|
virtual LocalModelsOverlay* createClone() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EntityTreeRenderer* _entityTreeRenderer;
|
EntityTreeRenderer* _entityTreeRenderer;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,6 +28,12 @@ LocalVoxelsOverlay::LocalVoxelsOverlay() :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalVoxelsOverlay::LocalVoxelsOverlay(const LocalVoxelsOverlay* localVoxelsOverlay) :
|
||||||
|
Volume3DOverlay(localVoxelsOverlay),
|
||||||
|
_voxelCount(localVoxelsOverlay->_voxelCount)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
LocalVoxelsOverlay::~LocalVoxelsOverlay() {
|
LocalVoxelsOverlay::~LocalVoxelsOverlay() {
|
||||||
_voxelSystem->changeTree(new VoxelTree());
|
_voxelSystem->changeTree(new VoxelTree());
|
||||||
_voxelSystem.clear();
|
_voxelSystem.clear();
|
||||||
|
@ -103,6 +109,10 @@ void LocalVoxelsOverlay::setProperties(const QScriptValue &properties) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalVoxelsOverlay* LocalVoxelsOverlay::createClone() const {
|
||||||
|
return new LocalVoxelsOverlay(this);
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue LocalVoxelsOverlay::getProperty(const QString& property) {
|
QScriptValue LocalVoxelsOverlay::getProperty(const QString& property) {
|
||||||
if (property == "scale") {
|
if (property == "scale") {
|
||||||
return vec3toScriptValue(_scriptEngine, getDimensions());
|
return vec3toScriptValue(_scriptEngine, getDimensions());
|
||||||
|
|
|
@ -32,6 +32,7 @@ class LocalVoxelsOverlay : public Volume3DOverlay {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LocalVoxelsOverlay();
|
LocalVoxelsOverlay();
|
||||||
|
LocalVoxelsOverlay(const LocalVoxelsOverlay* localVoxelsOverlay);
|
||||||
~LocalVoxelsOverlay();
|
~LocalVoxelsOverlay();
|
||||||
|
|
||||||
virtual void update(float deltatime);
|
virtual void update(float deltatime);
|
||||||
|
@ -40,6 +41,7 @@ public:
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
|
virtual LocalVoxelsOverlay* createClone() const;
|
||||||
private:
|
private:
|
||||||
static QMap<QString, WeakVoxelSystemPointer> _voxelSystemMap; // treeName/voxelSystem
|
static QMap<QString, WeakVoxelSystemPointer> _voxelSystemMap; // treeName/voxelSystem
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,22 @@ ModelOverlay::ModelOverlay()
|
||||||
_isLoaded = false;
|
_isLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModelOverlay::ModelOverlay(const ModelOverlay* modelOverlay) :
|
||||||
|
Base3DOverlay(modelOverlay),
|
||||||
|
_model(),
|
||||||
|
_modelTextures(QVariantMap()),
|
||||||
|
_scale(modelOverlay->_scale),
|
||||||
|
_updateModel(false),
|
||||||
|
_url(modelOverlay->_url),
|
||||||
|
_rotation(modelOverlay->_rotation)
|
||||||
|
{
|
||||||
|
_model.init();
|
||||||
|
if (_url.isValid()) {
|
||||||
|
_updateModel = true;
|
||||||
|
_isLoaded = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ModelOverlay::update(float deltatime) {
|
void ModelOverlay::update(float deltatime) {
|
||||||
if (_updateModel) {
|
if (_updateModel) {
|
||||||
_updateModel = false;
|
_updateModel = false;
|
||||||
|
@ -166,4 +182,6 @@ bool ModelOverlay::findRayIntersectionExtraInfo(const glm::vec3& origin, const g
|
||||||
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo);
|
return _model.findRayIntersectionAgainstSubMeshes(origin, direction, distance, face, extraInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModelOverlay* ModelOverlay::createClone() const {
|
||||||
|
return new ModelOverlay(this);
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ class ModelOverlay : public Base3DOverlay {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ModelOverlay();
|
ModelOverlay();
|
||||||
|
ModelOverlay(const ModelOverlay* modelOverlay);
|
||||||
|
|
||||||
virtual void update(float deltatime);
|
virtual void update(float deltatime);
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
|
@ -29,8 +30,10 @@ public:
|
||||||
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
virtual bool findRayIntersectionExtraInfo(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face, QString& extraInfo) const;
|
float& distance, BoxFace& face, QString& extraInfo) const;
|
||||||
|
|
||||||
|
virtual ModelOverlay* createClone() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Model _model;
|
Model _model;
|
||||||
QVariantMap _modelTextures;
|
QVariantMap _modelTextures;
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,30 @@ Overlay::Overlay() :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Overlay::Overlay(const Overlay* overlay) :
|
||||||
|
_parent(NULL),
|
||||||
|
_alpha(overlay->_alpha),
|
||||||
|
_lastPulseUpdate(usecTimestampNow()),
|
||||||
|
_alphaPulse(overlay->_alphaPulse),
|
||||||
|
_anchor(overlay->_anchor),
|
||||||
|
_color(overlay->_color),
|
||||||
|
_colorPulse(overlay->_colorPulse),
|
||||||
|
_glowLevel(overlay->_glowLevel),
|
||||||
|
_glowLevelPulse(overlay->_glowLevelPulse),
|
||||||
|
_pulseDirection(overlay->_pulseDirection),
|
||||||
|
_pulseMax(overlay->_pulseMax),
|
||||||
|
_pulseMin(overlay->_pulseMin),
|
||||||
|
_pulsePeriod(overlay->_pulsePeriod),
|
||||||
|
_visible(overlay->_visible),
|
||||||
|
_isLoaded(overlay->_isLoaded)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void Overlay::init(QGLWidget* parent, QScriptEngine* scriptEngine) {
|
void Overlay::init(QGLWidget* parent, QScriptEngine* scriptEngine) {
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
_scriptEngine = scriptEngine;
|
_scriptEngine = scriptEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Overlay::~Overlay() {
|
Overlay::~Overlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
Overlay();
|
Overlay();
|
||||||
|
Overlay(const Overlay* overlay);
|
||||||
~Overlay();
|
~Overlay();
|
||||||
void init(QGLWidget* parent, QScriptEngine* scriptEngine);
|
void init(QGLWidget* parent, QScriptEngine* scriptEngine);
|
||||||
virtual void update(float deltatime) {}
|
virtual void update(float deltatime) {}
|
||||||
|
@ -78,6 +79,7 @@ public:
|
||||||
void setAlphaPulse(float value) { _alphaPulse = value; }
|
void setAlphaPulse(float value) { _alphaPulse = value; }
|
||||||
|
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
|
virtual Overlay* createClone() const = 0;
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -22,6 +22,12 @@
|
||||||
Overlay2D::Overlay2D() {
|
Overlay2D::Overlay2D() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Overlay2D::Overlay2D(const Overlay2D* overlay2D) :
|
||||||
|
Overlay(overlay2D),
|
||||||
|
_bounds(overlay2D->_bounds)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Overlay2D::~Overlay2D() {
|
Overlay2D::~Overlay2D() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ class Overlay2D : public Overlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Overlay2D();
|
Overlay2D();
|
||||||
|
Overlay2D(const Overlay2D* overlay2D);
|
||||||
~Overlay2D();
|
~Overlay2D();
|
||||||
|
|
||||||
virtual bool is3D() const { return false; }
|
virtual bool is3D() const { return false; }
|
||||||
|
@ -43,7 +44,7 @@ public:
|
||||||
void setX(int x) { _bounds.setX(x); }
|
void setX(int x) { _bounds.setX(x); }
|
||||||
void setY(int y) { _bounds.setY(y); }
|
void setY(int y) { _bounds.setY(y); }
|
||||||
void setWidth(int width) { _bounds.setWidth(width); }
|
void setWidth(int width) { _bounds.setWidth(width); }
|
||||||
void setHeight(int height) { _bounds.setHeight(height); }
|
void setHeight(int height) { _bounds.setHeight(height); }
|
||||||
void setBounds(const QRect& bounds) { _bounds = bounds; }
|
void setBounds(const QRect& bounds) { _bounds = bounds; }
|
||||||
|
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
|
|
|
@ -196,6 +196,16 @@ unsigned int Overlays::addOverlay(Overlay* overlay) {
|
||||||
return thisID;
|
return thisID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int Overlays::cloneOverlay(unsigned int id) {
|
||||||
|
Overlay* thisOverlay = NULL;
|
||||||
|
if (_overlays2D.contains(id)) {
|
||||||
|
thisOverlay = _overlays2D[id];
|
||||||
|
} else if (_overlays3D.contains(id)) {
|
||||||
|
thisOverlay = _overlays3D[id];
|
||||||
|
}
|
||||||
|
return addOverlay(thisOverlay->createClone());
|
||||||
|
}
|
||||||
|
|
||||||
bool Overlays::editOverlay(unsigned int id, const QScriptValue& properties) {
|
bool Overlays::editOverlay(unsigned int id, const QScriptValue& properties) {
|
||||||
Overlay* thisOverlay = NULL;
|
Overlay* thisOverlay = NULL;
|
||||||
QWriteLocker lock(&_lock);
|
QWriteLocker lock(&_lock);
|
||||||
|
@ -397,15 +407,15 @@ void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& object, R
|
||||||
|
|
||||||
bool Overlays::isLoaded(unsigned int id) {
|
bool Overlays::isLoaded(unsigned int id) {
|
||||||
QReadLocker lock(&_lock);
|
QReadLocker lock(&_lock);
|
||||||
Overlay* overlay = _overlays2D.value(id);
|
Overlay* thisOverlay = NULL;
|
||||||
if (!overlay) {
|
if (_overlays2D.contains(id)) {
|
||||||
_overlays3D.value(id);
|
thisOverlay = _overlays2D[id];
|
||||||
}
|
} else if (_overlays3D.contains(id)) {
|
||||||
if (!overlay) {
|
thisOverlay = _overlays3D[id];
|
||||||
|
} else {
|
||||||
return false; // not found
|
return false; // not found
|
||||||
}
|
}
|
||||||
|
return thisOverlay->isLoaded();
|
||||||
return overlay->isLoaded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Overlays::textWidth(unsigned int id, const QString& text) const {
|
float Overlays::textWidth(unsigned int id, const QString& text) const {
|
||||||
|
|
|
@ -62,6 +62,9 @@ public slots:
|
||||||
/// adds an overlay that's already been created
|
/// adds an overlay that's already been created
|
||||||
unsigned int addOverlay(Overlay* overlay);
|
unsigned int addOverlay(Overlay* overlay);
|
||||||
|
|
||||||
|
/// clones an existing overlay
|
||||||
|
unsigned int cloneOverlay(unsigned int id);
|
||||||
|
|
||||||
/// edits an overlay updating only the included properties, will return the identified OverlayID in case of
|
/// edits an overlay updating only the included properties, will return the identified OverlayID in case of
|
||||||
/// successful edit, if the input id is for an unknown overlay this function will have no effect
|
/// successful edit, if the input id is for an unknown overlay this function will have no effect
|
||||||
bool editOverlay(unsigned int id, const QScriptValue& properties);
|
bool editOverlay(unsigned int id, const QScriptValue& properties);
|
||||||
|
|
|
@ -26,6 +26,12 @@ Planar3DOverlay::Planar3DOverlay() :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Planar3DOverlay::Planar3DOverlay(const Planar3DOverlay* planar3DOverlay) :
|
||||||
|
Base3DOverlay(planar3DOverlay),
|
||||||
|
_dimensions(planar3DOverlay->_dimensions)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Planar3DOverlay::~Planar3DOverlay() {
|
Planar3DOverlay::~Planar3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ class Planar3DOverlay : public Base3DOverlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Planar3DOverlay();
|
Planar3DOverlay();
|
||||||
|
Planar3DOverlay(const Planar3DOverlay* planar3DOverlay);
|
||||||
~Planar3DOverlay();
|
~Planar3DOverlay();
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
|
|
|
@ -20,6 +20,11 @@
|
||||||
Rectangle3DOverlay::Rectangle3DOverlay() {
|
Rectangle3DOverlay::Rectangle3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle3DOverlay::Rectangle3DOverlay(const Rectangle3DOverlay* rectangle3DOverlay) :
|
||||||
|
Planar3DOverlay(rectangle3DOverlay)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle3DOverlay::~Rectangle3DOverlay() {
|
Rectangle3DOverlay::~Rectangle3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,9 +111,6 @@ void Rectangle3DOverlay::setProperties(const QScriptValue &properties) {
|
||||||
Planar3DOverlay::setProperties(properties);
|
Planar3DOverlay::setProperties(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle3DOverlay* Rectangle3DOverlay::createClone() const {
|
||||||
|
return new Rectangle3DOverlay(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,12 @@ class Rectangle3DOverlay : public Planar3DOverlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Rectangle3DOverlay();
|
Rectangle3DOverlay();
|
||||||
|
Rectangle3DOverlay(const Rectangle3DOverlay* rectangle3DOverlay);
|
||||||
~Rectangle3DOverlay();
|
~Rectangle3DOverlay();
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
|
|
||||||
|
virtual Rectangle3DOverlay* createClone() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,11 @@
|
||||||
Sphere3DOverlay::Sphere3DOverlay() {
|
Sphere3DOverlay::Sphere3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sphere3DOverlay::Sphere3DOverlay(const Sphere3DOverlay* Sphere3DOverlay) :
|
||||||
|
Volume3DOverlay(Sphere3DOverlay)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Sphere3DOverlay::~Sphere3DOverlay() {
|
Sphere3DOverlay::~Sphere3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,3 +75,7 @@ void Sphere3DOverlay::render(RenderArgs* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sphere3DOverlay* Sphere3DOverlay::createClone() const {
|
||||||
|
return new Sphere3DOverlay(this);
|
||||||
|
}
|
||||||
|
|
|
@ -18,8 +18,11 @@ class Sphere3DOverlay : public Volume3DOverlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Sphere3DOverlay();
|
Sphere3DOverlay();
|
||||||
|
Sphere3DOverlay(const Sphere3DOverlay* Sphere3DOverlay);
|
||||||
~Sphere3DOverlay();
|
~Sphere3DOverlay();
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
|
|
||||||
|
virtual Sphere3DOverlay* createClone() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,19 @@ Text3DOverlay::Text3DOverlay() :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Text3DOverlay::Text3DOverlay(const Text3DOverlay* text3DOverlay) :
|
||||||
|
Planar3DOverlay(text3DOverlay),
|
||||||
|
_text(text3DOverlay->_text),
|
||||||
|
_backgroundColor(text3DOverlay->_backgroundColor),
|
||||||
|
_lineHeight(text3DOverlay->_lineHeight),
|
||||||
|
_leftMargin(text3DOverlay->_leftMargin),
|
||||||
|
_topMargin(text3DOverlay->_topMargin),
|
||||||
|
_rightMargin(text3DOverlay->_rightMargin),
|
||||||
|
_bottomMargin(text3DOverlay->_bottomMargin),
|
||||||
|
_isFacingAvatar(text3DOverlay->_isFacingAvatar)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Text3DOverlay::~Text3DOverlay() {
|
Text3DOverlay::~Text3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +185,6 @@ void Text3DOverlay::setProperties(const QScriptValue& properties) {
|
||||||
setBottomMargin(properties.property("bottomMargin").toVariant().toFloat());
|
setBottomMargin(properties.property("bottomMargin").toVariant().toFloat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QScriptValue isFacingAvatarValue = properties.property("isFacingAvatar");
|
QScriptValue isFacingAvatarValue = properties.property("isFacingAvatar");
|
||||||
if (isFacingAvatarValue.isValid()) {
|
if (isFacingAvatarValue.isValid()) {
|
||||||
_isFacingAvatar = isFacingAvatarValue.toVariant().toBool();
|
_isFacingAvatar = isFacingAvatarValue.toVariant().toBool();
|
||||||
|
@ -208,6 +220,10 @@ QScriptValue Text3DOverlay::getProperty(const QString& property) {
|
||||||
return Planar3DOverlay::getProperty(property);
|
return Planar3DOverlay::getProperty(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Text3DOverlay* Text3DOverlay::createClone() const {
|
||||||
|
return new Text3DOverlay(this);;
|
||||||
|
}
|
||||||
|
|
||||||
float Text3DOverlay::textWidth(const QString& text) const {
|
float Text3DOverlay::textWidth(const QString& text) const {
|
||||||
QFont font(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE); // Same font properties as render()
|
QFont font(SANS_FONT_FAMILY, FIXED_FONT_POINT_SIZE); // Same font properties as render()
|
||||||
QFontMetrics fontMetrics(font);
|
QFontMetrics fontMetrics(font);
|
||||||
|
@ -215,3 +231,4 @@ float Text3DOverlay::textWidth(const QString& text) const {
|
||||||
return scaleFactor * (float)fontMetrics.width(qPrintable(text));
|
return scaleFactor * (float)fontMetrics.width(qPrintable(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Text3DOverlay : public Planar3DOverlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Text3DOverlay();
|
Text3DOverlay();
|
||||||
|
Text3DOverlay(const Text3DOverlay* text3DOverlay);
|
||||||
~Text3DOverlay();
|
~Text3DOverlay();
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
|
|
||||||
|
@ -51,6 +52,8 @@ public:
|
||||||
|
|
||||||
float textWidth(const QString& text) const; // Meters
|
float textWidth(const QString& text) const; // Meters
|
||||||
|
|
||||||
|
virtual Text3DOverlay* createClone() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void enableClipPlane(GLenum plane, float x, float y, float z, float w);
|
void enableClipPlane(GLenum plane, float x, float y, float z, float w);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,16 @@ TextOverlay::TextOverlay() :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextOverlay::TextOverlay(const TextOverlay* textOverlay) :
|
||||||
|
Overlay2D(textOverlay),
|
||||||
|
_text(textOverlay->_text),
|
||||||
|
_backgroundColor(textOverlay->_backgroundColor),
|
||||||
|
_leftMargin(textOverlay->_leftMargin),
|
||||||
|
_topMargin(textOverlay->_topMargin),
|
||||||
|
_fontSize(textOverlay->_fontSize)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
TextOverlay::~TextOverlay() {
|
TextOverlay::~TextOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +134,10 @@ void TextOverlay::setProperties(const QScriptValue& properties) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextOverlay* TextOverlay::createClone() const {
|
||||||
|
return new TextOverlay(this);
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue TextOverlay::getProperty(const QString& property) {
|
QScriptValue TextOverlay::getProperty(const QString& property) {
|
||||||
if (property == "font") {
|
if (property == "font") {
|
||||||
QScriptValue font = _scriptEngine->newObject();
|
QScriptValue font = _scriptEngine->newObject();
|
||||||
|
@ -146,7 +160,6 @@ QScriptValue TextOverlay::getProperty(const QString& property) {
|
||||||
return Overlay2D::getProperty(property);
|
return Overlay2D::getProperty(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float TextOverlay::textWidth(const QString& text) const {
|
float TextOverlay::textWidth(const QString& text) const {
|
||||||
QFont font(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT); // Same font properties as render()
|
QFont font(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT); // Same font properties as render()
|
||||||
QFontMetrics fontMetrics(font);
|
QFontMetrics fontMetrics(font);
|
||||||
|
|
|
@ -37,6 +37,7 @@ class TextOverlay : public Overlay2D {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TextOverlay();
|
TextOverlay();
|
||||||
|
TextOverlay(const TextOverlay* textOverlay);
|
||||||
~TextOverlay();
|
~TextOverlay();
|
||||||
virtual void render(RenderArgs* args);
|
virtual void render(RenderArgs* args);
|
||||||
|
|
||||||
|
@ -53,12 +54,12 @@ public:
|
||||||
void setFontSize(int fontSize) { _fontSize = fontSize; }
|
void setFontSize(int fontSize) { _fontSize = fontSize; }
|
||||||
|
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
|
virtual TextOverlay* createClone() const;
|
||||||
virtual QScriptValue getProperty(const QString& property);
|
virtual QScriptValue getProperty(const QString& property);
|
||||||
|
|
||||||
float textWidth(const QString& text) const; // Pixels
|
float textWidth(const QString& text) const; // Pixels
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QString _text;
|
QString _text;
|
||||||
xColor _backgroundColor;
|
xColor _backgroundColor;
|
||||||
int _leftMargin;
|
int _leftMargin;
|
||||||
|
|
|
@ -28,6 +28,12 @@ Volume3DOverlay::Volume3DOverlay() :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Volume3DOverlay::Volume3DOverlay(const Volume3DOverlay* volume3DOverlay) :
|
||||||
|
Base3DOverlay(volume3DOverlay),
|
||||||
|
_dimensions(volume3DOverlay->_dimensions)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Volume3DOverlay::~Volume3DOverlay() {
|
Volume3DOverlay::~Volume3DOverlay() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ class Volume3DOverlay : public Base3DOverlay {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Volume3DOverlay();
|
Volume3DOverlay();
|
||||||
|
Volume3DOverlay(const Volume3DOverlay* volume3DOverlay);
|
||||||
~Volume3DOverlay();
|
~Volume3DOverlay();
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
|
|
|
@ -1089,7 +1089,6 @@ bool DebugOperator::preRecursion(OctreeElement* element) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::dumpTree() {
|
void EntityTree::dumpTree() {
|
||||||
// First, look for the existing entity in the tree..
|
|
||||||
DebugOperator theOperator;
|
DebugOperator theOperator;
|
||||||
recurseTreeWithOperator(&theOperator);
|
recurseTreeWithOperator(&theOperator);
|
||||||
}
|
}
|
||||||
|
@ -1107,7 +1106,6 @@ bool PruneOperator::postRecursion(OctreeElement* element) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityTree::pruneTree() {
|
void EntityTree::pruneTree() {
|
||||||
// First, look for the existing entity in the tree..
|
|
||||||
PruneOperator theOperator;
|
PruneOperator theOperator;
|
||||||
recurseTreeWithOperator(&theOperator);
|
recurseTreeWithOperator(&theOperator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,18 +9,31 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
#include "OctreePersistThread.h"
|
#include "OctreePersistThread.h"
|
||||||
|
|
||||||
OctreePersistThread::OctreePersistThread(Octree* tree, const QString& filename, int persistInterval) :
|
const int OctreePersistThread::DEFAULT_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds
|
||||||
|
const int OctreePersistThread::DEFAULT_BACKUP_INTERVAL = 1000 * 60 * 30; // every 30 minutes
|
||||||
|
const QString OctreePersistThread::DEFAULT_BACKUP_EXTENSION_FORMAT(".backup.%Y-%m-%d.%H:%M:%S.%z");
|
||||||
|
|
||||||
|
|
||||||
|
OctreePersistThread::OctreePersistThread(Octree* tree, const QString& filename, int persistInterval,
|
||||||
|
bool wantBackup, int backupInterval, const QString& backupExtensionFormat) :
|
||||||
_tree(tree),
|
_tree(tree),
|
||||||
_filename(filename),
|
_filename(filename),
|
||||||
|
_backupExtensionFormat(backupExtensionFormat),
|
||||||
_persistInterval(persistInterval),
|
_persistInterval(persistInterval),
|
||||||
|
_backupInterval(backupInterval),
|
||||||
_initialLoadComplete(false),
|
_initialLoadComplete(false),
|
||||||
_loadTimeUSecs(0)
|
_loadTimeUSecs(0),
|
||||||
|
_lastCheck(0),
|
||||||
|
_lastBackup(0),
|
||||||
|
_wantBackup(wantBackup)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,16 +64,22 @@ bool OctreePersistThread::process() {
|
||||||
unsigned long leafNodeCount = OctreeElement::getLeafNodeCount();
|
unsigned long leafNodeCount = OctreeElement::getLeafNodeCount();
|
||||||
qDebug("Nodes after loading scene %lu nodes %lu internal %lu leaves", nodeCount, internalNodeCount, leafNodeCount);
|
qDebug("Nodes after loading scene %lu nodes %lu internal %lu leaves", nodeCount, internalNodeCount, leafNodeCount);
|
||||||
|
|
||||||
double usecPerGet = (double)OctreeElement::getGetChildAtIndexTime() / (double)OctreeElement::getGetChildAtIndexCalls();
|
bool wantDebug = false;
|
||||||
qDebug() << "getChildAtIndexCalls=" << OctreeElement::getGetChildAtIndexCalls()
|
if (wantDebug) {
|
||||||
<< " getChildAtIndexTime=" << OctreeElement::getGetChildAtIndexTime() << " perGet=" << usecPerGet;
|
double usecPerGet = (double)OctreeElement::getGetChildAtIndexTime()
|
||||||
|
/ (double)OctreeElement::getGetChildAtIndexCalls();
|
||||||
|
qDebug() << "getChildAtIndexCalls=" << OctreeElement::getGetChildAtIndexCalls()
|
||||||
|
<< " getChildAtIndexTime=" << OctreeElement::getGetChildAtIndexTime() << " perGet=" << usecPerGet;
|
||||||
|
|
||||||
double usecPerSet = (double)OctreeElement::getSetChildAtIndexTime() / (double)OctreeElement::getSetChildAtIndexCalls();
|
double usecPerSet = (double)OctreeElement::getSetChildAtIndexTime()
|
||||||
qDebug() << "setChildAtIndexCalls=" << OctreeElement::getSetChildAtIndexCalls()
|
/ (double)OctreeElement::getSetChildAtIndexCalls();
|
||||||
<< " setChildAtIndexTime=" << OctreeElement::getSetChildAtIndexTime() << " perset=" << usecPerSet;
|
qDebug() << "setChildAtIndexCalls=" << OctreeElement::getSetChildAtIndexCalls()
|
||||||
|
<< " setChildAtIndexTime=" << OctreeElement::getSetChildAtIndexTime() << " perSet=" << usecPerSet;
|
||||||
|
}
|
||||||
|
|
||||||
_initialLoadComplete = true;
|
_initialLoadComplete = true;
|
||||||
_lastCheck = usecTimestampNow(); // we just loaded, no need to save again
|
_lastBackup = _lastCheck = usecTimestampNow(); // we just loaded, no need to save again
|
||||||
|
time(&_lastPersistTime);
|
||||||
|
|
||||||
emit loadCompleted();
|
emit loadCompleted();
|
||||||
}
|
}
|
||||||
|
@ -78,19 +97,62 @@ bool OctreePersistThread::process() {
|
||||||
quint64 intervalToCheck = _persistInterval * MSECS_TO_USECS;
|
quint64 intervalToCheck = _persistInterval * MSECS_TO_USECS;
|
||||||
|
|
||||||
if (sinceLastSave > intervalToCheck) {
|
if (sinceLastSave > intervalToCheck) {
|
||||||
// check the dirty bit and persist here...
|
_lastCheck = now;
|
||||||
_lastCheck = usecTimestampNow();
|
persist();
|
||||||
if (_tree->isDirty()) {
|
|
||||||
qDebug() << "pruning Octree before saving...";
|
|
||||||
_tree->pruneTree();
|
|
||||||
qDebug() << "DONE pruning Octree before saving...";
|
|
||||||
|
|
||||||
qDebug() << "saving Octree to file " << _filename << "...";
|
|
||||||
_tree->writeToSVOFile(_filename.toLocal8Bit().constData());
|
|
||||||
_tree->clearDirtyBit(); // tree is clean after saving
|
|
||||||
qDebug("DONE saving Octree to file...");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isStillRunning(); // keep running till they terminate us
|
return isStillRunning(); // keep running till they terminate us
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OctreePersistThread::aboutToFinish() {
|
||||||
|
qDebug() << "Persist thread about to finish...";
|
||||||
|
persist();
|
||||||
|
qDebug() << "Persist thread done with about to finish...";
|
||||||
|
}
|
||||||
|
|
||||||
|
void OctreePersistThread::persist() {
|
||||||
|
if (_tree->isDirty()) {
|
||||||
|
_tree->lockForWrite();
|
||||||
|
{
|
||||||
|
qDebug() << "pruning Octree before saving...";
|
||||||
|
_tree->pruneTree();
|
||||||
|
qDebug() << "DONE pruning Octree before saving...";
|
||||||
|
}
|
||||||
|
_tree->unlock();
|
||||||
|
|
||||||
|
backup(); // handle backup if requested
|
||||||
|
|
||||||
|
qDebug() << "saving Octree to file " << _filename << "...";
|
||||||
|
_tree->writeToSVOFile(qPrintable(_filename));
|
||||||
|
time(&_lastPersistTime);
|
||||||
|
_tree->clearDirtyBit(); // tree is clean after saving
|
||||||
|
qDebug() << "DONE saving Octree to file...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OctreePersistThread::backup() {
|
||||||
|
if (_wantBackup) {
|
||||||
|
quint64 now = usecTimestampNow();
|
||||||
|
quint64 sinceLastBackup = now - _lastBackup;
|
||||||
|
quint64 MSECS_TO_USECS = 1000;
|
||||||
|
quint64 intervalToBackup = _backupInterval * MSECS_TO_USECS;
|
||||||
|
|
||||||
|
if (sinceLastBackup > intervalToBackup) {
|
||||||
|
struct tm* localTime = localtime(&_lastPersistTime);
|
||||||
|
|
||||||
|
char backupExtension[256];
|
||||||
|
strftime(backupExtension, sizeof(backupExtension), qPrintable(_backupExtensionFormat), localTime);
|
||||||
|
|
||||||
|
QString backupFileName = _filename + backupExtension;
|
||||||
|
|
||||||
|
qDebug() << "backing up persist file " << _filename << "to" << backupFileName << "...";
|
||||||
|
int result = rename(qPrintable(_filename), qPrintable(backupFileName));
|
||||||
|
if (result == 0) {
|
||||||
|
qDebug() << "DONE backing up persist file...";
|
||||||
|
} else {
|
||||||
|
qDebug() << "ERROR in backing up persist file...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -22,27 +22,41 @@
|
||||||
class OctreePersistThread : public GenericThread {
|
class OctreePersistThread : public GenericThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static const int DEFAULT_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds
|
static const int DEFAULT_PERSIST_INTERVAL;
|
||||||
|
static const int DEFAULT_BACKUP_INTERVAL;
|
||||||
|
static const QString DEFAULT_BACKUP_EXTENSION_FORMAT;
|
||||||
|
|
||||||
OctreePersistThread(Octree* tree, const QString& filename, int persistInterval = DEFAULT_PERSIST_INTERVAL);
|
OctreePersistThread(Octree* tree, const QString& filename, int persistInterval = DEFAULT_PERSIST_INTERVAL,
|
||||||
|
bool wantBackup = false, int backupInterval = DEFAULT_BACKUP_INTERVAL,
|
||||||
|
const QString& backupExtensionFormat = DEFAULT_BACKUP_EXTENSION_FORMAT);
|
||||||
|
|
||||||
bool isInitialLoadComplete() const { return _initialLoadComplete; }
|
bool isInitialLoadComplete() const { return _initialLoadComplete; }
|
||||||
quint64 getLoadElapsedTime() const { return _loadTimeUSecs; }
|
quint64 getLoadElapsedTime() const { return _loadTimeUSecs; }
|
||||||
|
|
||||||
|
void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loadCompleted();
|
void loadCompleted();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Implements generic processing behavior for this thread.
|
/// Implements generic processing behavior for this thread.
|
||||||
virtual bool process();
|
virtual bool process();
|
||||||
|
|
||||||
|
void persist();
|
||||||
|
void backup();
|
||||||
private:
|
private:
|
||||||
Octree* _tree;
|
Octree* _tree;
|
||||||
QString _filename;
|
QString _filename;
|
||||||
|
QString _backupExtensionFormat;
|
||||||
int _persistInterval;
|
int _persistInterval;
|
||||||
|
int _backupInterval;
|
||||||
bool _initialLoadComplete;
|
bool _initialLoadComplete;
|
||||||
|
|
||||||
quint64 _loadTimeUSecs;
|
quint64 _loadTimeUSecs;
|
||||||
quint64 _lastCheck;
|
quint64 _lastCheck;
|
||||||
|
quint64 _lastBackup;
|
||||||
|
bool _wantBackup;
|
||||||
|
time_t _lastPersistTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_OctreePersistThread_h
|
#endif // hifi_OctreePersistThread_h
|
||||||
|
|
Loading…
Reference in a new issue