From e95cd30be6272c2f9e967a9b734239bbc1fd806f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 20 Jan 2015 16:30:50 -0800 Subject: [PATCH 01/19] better reticle, balls drop properly on table --- examples/billiards.js | 51 +++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/examples/billiards.js b/examples/billiards.js index 9bc21ff611..d671addbe6 100644 --- a/examples/billiards.js +++ b/examples/billiards.js @@ -1,6 +1,7 @@ // Pool Table var tableParts = []; var balls = []; +var cueBall; var LENGTH = 2.84; var WIDTH = 1.42; @@ -13,6 +14,8 @@ var HOLE_SIZE = BALL_SIZE; var DROP_HEIGHT = BALL_SIZE * 3.0; var GRAVITY = -9.8; var BALL_GAP = 0.001; +var tableCenter; +var cuePosition; var startStroke = 0; @@ -23,7 +26,7 @@ var reticle = Overlays.addOverlay("image", { y: screenSize.y / 2 - 16, width: 32, height: 32, - imageURL: HIFI_PUBLIC_BUCKET + "images/reticle.png", + imageURL: HIFI_PUBLIC_BUCKET + "images/billiardsReticle.png", color: { red: 255, green: 255, blue: 255}, alpha: 1 }); @@ -102,7 +105,7 @@ function makeBalls(pos) { { red: 128, green: 128, blue: 128}]; // Gray // Object balls - var ballPosition = { x: pos.x + (LENGTH / 4.0) * SCALE, y: pos.y + DROP_HEIGHT, z: pos.z }; + var ballPosition = { x: pos.x + (LENGTH / 4.0) * SCALE, y: pos.y + HEIGHT / 2.0 + DROP_HEIGHT, z: pos.z }; for (var row = 1; row <= 5; row++) { ballPosition.z = pos.z - ((row - 1.0) / 2.0 * (BALL_SIZE + BALL_GAP) * SCALE); for (var spot = 0; spot < row; spot++) { @@ -113,23 +116,26 @@ function makeBalls(pos) { color: colors[balls.length], gravity: { x: 0, y: GRAVITY, z: 0 }, ignoreCollisions: false, - damping: 0.40, + damping: 0.50, collisionsWillMove: true })); ballPosition.z += (BALL_SIZE + BALL_GAP) * SCALE; } ballPosition.x += (BALL_GAP + Math.sqrt(3.0) / 2.0 * BALL_SIZE) * SCALE; } // Cue Ball - ballPosition = { x: pos.x - (LENGTH / 4.0) * SCALE, y: pos.y + DROP_HEIGHT, z: pos.z }; - balls.push(Entities.addEntity( + cuePosition = { x: pos.x - (LENGTH / 4.0) * SCALE, y: pos.y + HEIGHT / 2.0 + DROP_HEIGHT, z: pos.z }; + cueBall = Entities.addEntity( { type: "Sphere", - position: ballPosition, + position: cuePosition, dimensions: { x: BALL_SIZE * SCALE, y: BALL_SIZE * SCALE, z: BALL_SIZE * SCALE }, color: { red: 255, green: 255, blue: 255 }, gravity: { x: 0, y: GRAVITY, z: 0 }, + angularVelocity: { x: 0, y: 0, z: 0 }, + velocity: {x: 0, y: 0, z: 0 }, ignoreCollisions: false, - damping: 0.40, - collisionsWillMove: true })); + damping: 0.50, + collisionsWillMove: true }); + } function shootCue(velocity) { @@ -140,19 +146,23 @@ function shootCue(velocity) { var velocity = Vec3.multiply(forwardVector, velocity); var BULLET_LIFETIME = 3.0; var BULLET_GRAVITY = 0.0; + var SHOOTER_COLOR = { red: 255, green: 0, blue: 0 }; + var SHOOTER_SIZE = BALL_SIZE / 1.5 * SCALE; + bulletID = Entities.addEntity( { type: "Sphere", position: cuePosition, - dimensions: { x: BALL_SIZE * SCALE, y: BALL_SIZE * SCALE, z: BALL_SIZE * SCALE }, - color: { red: 255, green: 255, blue: 255 }, + dimensions: { x: SHOOTER_SIZE, y: SHOOTER_SIZE, z: SHOOTER_SIZE }, + color: SHOOTER_COLOR, velocity: velocity, lifetime: BULLET_LIFETIME, gravity: { x: 0, y: BULLET_GRAVITY, z: 0 }, damping: 0.10, - density: 1000, + density: 8000, ignoreCollisions: false, collisionsWillMove: true }); + print("Shot, velocity = " + velocity); } function keyReleaseEvent(event) { @@ -185,9 +195,25 @@ function cleanup() { Entities.deleteEntity(balls[i]); } Overlays.deleteOverlay(reticle); + Entities.deleteEntity(cueBall); } -var tableCenter = Vec3.sum(MyAvatar.position, Vec3.multiply(4.0, Quat.getFront(Camera.getOrientation()))); +function update(deltaTime) { + if (!cueBall.isKnownID) { + cueBall = Entities.identifyEntity(cueBall); + } else { + // Check if cue ball has fallen off table, re-drop if so + var cueProperties = Entities.getEntityProperties(cueBall); + if (cueProperties.position.y < tableCenter.y) { + // Replace the cueball + Entities.editEntity(cueBall, { position: cuePosition } ); + + } + } + +} + +tableCenter = Vec3.sum(MyAvatar.position, Vec3.multiply(4.0, Quat.getFront(Camera.getOrientation()))); makeTable(tableCenter); makeBalls(tableCenter); @@ -195,3 +221,4 @@ makeBalls(tableCenter); Script.scriptEnding.connect(cleanup); Controller.keyPressEvent.connect(keyPressEvent); Controller.keyReleaseEvent.connect(keyReleaseEvent); +Script.update.connect(update); From e02e0088afdf911bdb79da43b4192a61b842efea Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 21 Jan 2015 13:58:48 -0800 Subject: [PATCH 02/19] Improvements to gun to add shootable targets on a platform --- examples/controllers/hydra/gun.js | 60 ++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/examples/controllers/hydra/gun.js b/examples/controllers/hydra/gun.js index e3450b708e..d190fff503 100644 --- a/examples/controllers/hydra/gun.js +++ b/examples/controllers/hydra/gun.js @@ -47,7 +47,6 @@ var yawFromMouse = 0; var pitchFromMouse = 0; var isMouseDown = false; -var BULLET_VELOCITY = 5.0; var MIN_THROWER_DELAY = 1000; var MAX_THROWER_DELAY = 1000; var LEFT_BUTTON_3 = 3; @@ -98,7 +97,7 @@ var reticle = Overlays.addOverlay("image", { y: screenSize.y / 2 - 16, width: 32, height: 32, - imageURL: HIFI_PUBLIC_BUCKET + "images/reticle.png", + imageURL: HIFI_PUBLIC_BUCKET + "images/billiardsReticle.png", color: { red: 255, green: 255, blue: 255}, alpha: 1 }); @@ -131,10 +130,12 @@ function printVector(string, vector) { print(string + " " + vector.x + ", " + vector.y + ", " + vector.z); } +var BULLET_VELOCITY = 15.0; + function shootBullet(position, velocity) { var BULLET_SIZE = 0.07; var BULLET_LIFETIME = 10.0; - var BULLET_GRAVITY = 0.0; + var BULLET_GRAVITY = -0.25; bulletID = Entities.addEntity( { type: "Sphere", position: position, @@ -144,7 +145,7 @@ function shootBullet(position, velocity) { lifetime: BULLET_LIFETIME, gravity: { x: 0, y: BULLET_GRAVITY, z: 0 }, damping: 0.01, - density: 5000, + density: 10000, ignoreCollisions: false, collisionsWillMove: true }); @@ -158,6 +159,9 @@ function shootBullet(position, velocity) { } // Kickback the arm + if (elbowKickAngle > 0.0) { + MyAvatar.setJointData("LeftForeArm", rotationBeforeKickback); + } rotationBeforeKickback = MyAvatar.getJointRotation("LeftForeArm"); var armRotation = MyAvatar.getJointRotation("LeftForeArm"); armRotation = Quat.multiply(armRotation, Quat.fromPitchYawRollDegrees(0.0, 0.0, KICKBACK_ANGLE)); @@ -165,6 +169,50 @@ function shootBullet(position, velocity) { elbowKickAngle = KICKBACK_ANGLE; } +function makeGrid(type, gravity, scale, size) { + var separation = scale * 2; + var pos = Vec3.sum(Camera.getPosition(), Vec3.multiply(10.0 * scale * separation, Quat.getFront(Camera.getOrientation()))); + pos.y -= separation * size; + var x, y, z; + var GRID_LIFE = 60.0; + var dimensions; + + for (x = 0; x < size; x++) { + for (y = 0; y < size; y++) { + for (z = 0; z < size; z++) { + if (gravity == 0) { + dimensions = { x: separation/2.0 * (0.5 + Math.random()), y: separation/2.0 * (0.5 + Math.random()), z: separation/2.0 * (0.5 + Math.random()) / 4.0 }; + } else { + dimensions = { x: separation/2.0 * (0.5 + Math.random()), y: separation/4.0 * (0.5 + Math.random()), z: separation/2.0 * (0.5 + Math.random()) }; + } + + Entities.addEntity( + { type: type, + position: { x: pos.x + x * separation, y: pos.y + y * separation, z: pos.z + z * separation }, + dimensions: dimensions, + color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 }, + velocity: { x: 0, y: 0, z: 0 }, + gravity: { x: 0, y: gravity, z: 0 }, + lifetime: GRID_LIFE, + rotation: Camera.getOrientation(), + damping: 0.1, + density: 100.0, + collisionsWillMove: true }); + } + } + } + if (gravity < 0) { + // Make a floor for this stuff to fall onto + Entities.addEntity({ + type: "Box", + position: { x: pos.x, y: pos.y - separation / 2.0, z: pos.z }, + dimensions: { x: 2.0 * separation * size, y: separation / 2.0, z: 2.0 * separation * size }, + color: { red: 128, green: 128, blue: 128 }, + lifetime: GRID_LIFE + }); + } +} + function shootTarget() { var TARGET_SIZE = 0.50; var TARGET_GRAVITY = 0.0; @@ -236,6 +284,10 @@ function keyPressEvent(event) { shootFromMouse(); } else if (event.text == "r") { playLoadSound(); + } else if (event.text == "g") { + makeGrid("Box", 0.0, 0.4, 3); + } else if (event.text == "f") { + makeGrid("Box", -9.8, 0.4, 5); } else if (event.text == "s") { // Hit this key to dump a posture from hydra to log Quat.print("arm = ", MyAvatar.getJointRotation("LeftArm")); From 53a70c43e1b6f2cbd4d99cc522945749b6f2f6d1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 21 Jan 2015 15:08:38 -0800 Subject: [PATCH 03/19] Add width and height to NetworkTexture --- libraries/render-utils/src/TextureCache.cpp | 6 +++++- libraries/render-utils/src/TextureCache.h | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 3bd05a14ee..4c9abc74a1 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -385,7 +385,9 @@ Texture::~Texture() { NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArray& content) : Resource(url, !content.isEmpty()), _type(type), - _translucent(false) { + _translucent(false), + _width(0), + _height(0) { if (!url.isValid()) { _loaded = true; @@ -532,6 +534,8 @@ void NetworkTexture::loadContent(const QByteArray& content) { void NetworkTexture::setImage(const QImage& image, bool translucent, const QColor& averageColor) { _translucent = translucent; _averageColor = averageColor; + _width = image.width(); + _height = image.height(); finishedLoading(true); imageLoaded(image); diff --git a/libraries/render-utils/src/TextureCache.h b/libraries/render-utils/src/TextureCache.h index 54c98a61cb..efcccc4b8c 100644 --- a/libraries/render-utils/src/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -150,6 +150,9 @@ public: /// Returns the lazily-computed average texture color. const QColor& getAverageColor() const { return _averageColor; } + int getWidth() const { return _width; } + int getHeight() const { return _height; } + protected: virtual void downloadFinished(QNetworkReply* reply); @@ -163,6 +166,8 @@ private: TextureType _type; bool _translucent; QColor _averageColor; + int _width; + int _height; }; /// Caches derived, dilated textures. From ba2f7d88ce3cdd7c8ad372457fc5cf9c7c709345 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 21 Jan 2015 15:09:09 -0800 Subject: [PATCH 04/19] Update ImageOverlay to use TextureCache --- interface/src/ui/overlays/ImageOverlay.cpp | 51 ++++++++-------------- interface/src/ui/overlays/ImageOverlay.h | 7 +-- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 1ecfc74e44..164b3916db 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -22,9 +22,7 @@ #include "ImageOverlay.h" ImageOverlay::ImageOverlay() : - _textureID(0), _renderImage(false), - _textureBound(false), _wantClipFromImage(false) { _isLoaded = false; @@ -32,63 +30,48 @@ ImageOverlay::ImageOverlay() : ImageOverlay::ImageOverlay(const ImageOverlay* imageOverlay) : Overlay2D(imageOverlay), + _texture(imageOverlay->_texture), _imageURL(imageOverlay->_imageURL), _textureImage(imageOverlay->_textureImage), - _textureID(0), - _fromImage(), + _fromImage(imageOverlay->_fromImage), _renderImage(imageOverlay->_renderImage), - _textureBound(false), - _wantClipFromImage(false) + _wantClipFromImage(imageOverlay->_wantClipFromImage) { } ImageOverlay::~ImageOverlay() { - if (_parent && _textureID) { - // do we need to call this? - //_parent->deleteTexture(_textureID); - } } // TODO: handle setting image multiple times, how do we manage releasing the bound texture? void ImageOverlay::setImageURL(const QUrl& url) { _imageURL = url; _isLoaded = false; - QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); - QNetworkReply* reply = networkAccessManager.get(QNetworkRequest(url)); - connect(reply, &QNetworkReply::finished, this, &ImageOverlay::replyFinished); -} - -void ImageOverlay::replyFinished() { - QNetworkReply* reply = static_cast(sender()); - - // replace our byte array with the downloaded data - QByteArray rawData = reply->readAll(); - _textureImage.loadFromData(rawData); - _renderImage = true; - _isLoaded = true; - reply->deleteLater(); } void ImageOverlay::render(RenderArgs* args) { - if (!_visible || !_isLoaded) { - return; // do nothing if we're not visible + if (!_isLoaded && !_imageURL.isEmpty()) { + _isLoaded = true; + _renderImage = true; + qDebug() << "Now loding texture for ImageOverlay"; + _texture = DependencyManager::get()->getTexture(_imageURL); } - if (_renderImage && !_textureBound) { - _textureID = _parent->bindTexture(_textureImage); - _textureBound = true; + + if (!_visible || !_isLoaded || !_texture || !_texture->isLoaded()) { + return; } if (_renderImage) { + qDebug() << "Rendering: " << _imageURL << ", " << _texture->getWidth() << ", " << _texture->getHeight(); glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, _textureID); + glBindTexture(GL_TEXTURE_2D, _texture->getID()); } const float MAX_COLOR = 255.0f; xColor color = getColor(); float alpha = getAlpha(); glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); - float imageWidth = _textureImage.width(); - float imageHeight = _textureImage.height(); + float imageWidth = _texture->getWidth(); + float imageHeight = _texture->getHeight(); QRect fromImage; if (_wantClipFromImage) { @@ -111,8 +94,8 @@ void ImageOverlay::render(RenderArgs* args) { glm::vec2 topLeft(left, top); glm::vec2 bottomRight(right, bottom); - glm::vec2 texCoordTopLeft(x, 1.0f - y); - glm::vec2 texCoordBottomRight(x + w, 1.0f - (y + h)); + glm::vec2 texCoordTopLeft(x, y); + glm::vec2 texCoordBottomRight(x + w, y + h); if (_renderImage) { DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); diff --git a/interface/src/ui/overlays/ImageOverlay.h b/interface/src/ui/overlays/ImageOverlay.h index cff557654f..e167c4e755 100644 --- a/interface/src/ui/overlays/ImageOverlay.h +++ b/interface/src/ui/overlays/ImageOverlay.h @@ -24,6 +24,7 @@ #include #include +#include #include "Overlay.h" #include "Overlay2D.h" @@ -49,18 +50,14 @@ public: virtual ImageOverlay* createClone() const; -private slots: - void replyFinished(); // we actually want to hide this... - private: QUrl _imageURL; QImage _textureImage; - GLuint _textureID; + NetworkTexturePointer _texture; QRect _fromImage; // where from in the image to sample bool _renderImage; // is there an image associated with this overlay, or is it just a colored rectangle - bool _textureBound; // has the texture been bound bool _wantClipFromImage; }; From 6567fcfe0b36eb253cd2a8afff31b7eda37d1133 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 21 Jan 2015 16:17:25 -0800 Subject: [PATCH 05/19] Added shootable blocks on platform, grenade, buttons for making grid of targets --- examples/controllers/hydra/gun.js | 214 ++++++++++++++++++------------ 1 file changed, 126 insertions(+), 88 deletions(-) diff --git a/examples/controllers/hydra/gun.js b/examples/controllers/hydra/gun.js index d190fff503..0c0740e12b 100644 --- a/examples/controllers/hydra/gun.js +++ b/examples/controllers/hydra/gun.js @@ -112,6 +112,25 @@ var offButton = Overlays.addOverlay("image", { alpha: 1 }); +var platformButton = Overlays.addOverlay("image", { + x: screenSize.x - 48, + y: 130, + width: 32, + height: 32, + imageURL: HIFI_PUBLIC_BUCKET + "images/city.png", + color: { red: 255, green: 255, blue: 255}, + alpha: 1 + }); +var gridButton = Overlays.addOverlay("image", { + x: screenSize.x - 48, + y: 164, + width: 32, + height: 32, + imageURL: HIFI_PUBLIC_BUCKET + "images/blocks.png", + color: { red: 255, green: 255, blue: 255}, + alpha: 1 + }); + if (showScore) { var text = Overlays.addOverlay("text", { x: screenSize.x / 2 - 100, @@ -126,26 +145,30 @@ if (showScore) { }); } -function printVector(string, vector) { - print(string + " " + vector.x + ", " + vector.y + ", " + vector.z); -} +var BULLET_VELOCITY = 10.0; -var BULLET_VELOCITY = 15.0; - -function shootBullet(position, velocity) { - var BULLET_SIZE = 0.07; +function shootBullet(position, velocity, grenade) { + var BULLET_SIZE = 0.10; var BULLET_LIFETIME = 10.0; var BULLET_GRAVITY = -0.25; + var GRENADE_VELOCITY = 15.0; + var GRENADE_SIZE = 0.35; + var GRENADE_GRAVITY = -9.8; + + var bVelocity = grenade ? Vec3.multiply(GRENADE_VELOCITY, Vec3.normalize(velocity)) : velocity; + var bSize = grenade ? GRENADE_SIZE : BULLET_SIZE; + var bGravity = grenade ? GRENADE_GRAVITY : BULLET_GRAVITY; + bulletID = Entities.addEntity( { type: "Sphere", position: position, - dimensions: { x: BULLET_SIZE, y: BULLET_SIZE, z: BULLET_SIZE }, + dimensions: { x: bSize, y: bSize, z: bSize }, color: { red: 255, green: 0, blue: 0 }, - velocity: velocity, + velocity: bVelocity, lifetime: BULLET_LIFETIME, - gravity: { x: 0, y: BULLET_GRAVITY, z: 0 }, + gravity: { x: 0, y: bGravity, z: 0 }, damping: 0.01, - density: 10000, + density: 8000, ignoreCollisions: false, collisionsWillMove: true }); @@ -168,51 +191,6 @@ function shootBullet(position, velocity) { MyAvatar.setJointData("LeftForeArm", armRotation); elbowKickAngle = KICKBACK_ANGLE; } - -function makeGrid(type, gravity, scale, size) { - var separation = scale * 2; - var pos = Vec3.sum(Camera.getPosition(), Vec3.multiply(10.0 * scale * separation, Quat.getFront(Camera.getOrientation()))); - pos.y -= separation * size; - var x, y, z; - var GRID_LIFE = 60.0; - var dimensions; - - for (x = 0; x < size; x++) { - for (y = 0; y < size; y++) { - for (z = 0; z < size; z++) { - if (gravity == 0) { - dimensions = { x: separation/2.0 * (0.5 + Math.random()), y: separation/2.0 * (0.5 + Math.random()), z: separation/2.0 * (0.5 + Math.random()) / 4.0 }; - } else { - dimensions = { x: separation/2.0 * (0.5 + Math.random()), y: separation/4.0 * (0.5 + Math.random()), z: separation/2.0 * (0.5 + Math.random()) }; - } - - Entities.addEntity( - { type: type, - position: { x: pos.x + x * separation, y: pos.y + y * separation, z: pos.z + z * separation }, - dimensions: dimensions, - color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 }, - velocity: { x: 0, y: 0, z: 0 }, - gravity: { x: 0, y: gravity, z: 0 }, - lifetime: GRID_LIFE, - rotation: Camera.getOrientation(), - damping: 0.1, - density: 100.0, - collisionsWillMove: true }); - } - } - } - if (gravity < 0) { - // Make a floor for this stuff to fall onto - Entities.addEntity({ - type: "Box", - position: { x: pos.x, y: pos.y - separation / 2.0, z: pos.z }, - dimensions: { x: 2.0 * separation * size, y: separation / 2.0, z: 2.0 * separation * size }, - color: { red: 128, green: 128, blue: 128 }, - lifetime: GRID_LIFE - }); - } -} - function shootTarget() { var TARGET_SIZE = 0.50; var TARGET_GRAVITY = 0.0; @@ -222,7 +200,7 @@ function shootTarget() { var DISTANCE_TO_LAUNCH_FROM = 5.0; var ANGLE_RANGE_FOR_LAUNCH = 20.0; var camera = Camera.getPosition(); - //printVector("camera", camera); + var targetDirection = Quat.angleAxis(getRandomFloat(-ANGLE_RANGE_FOR_LAUNCH, ANGLE_RANGE_FOR_LAUNCH), { x:0, y:1, z:0 }); targetDirection = Quat.multiply(Camera.getOrientation(), targetDirection); var forwardVector = Quat.getFront(targetDirection); @@ -253,6 +231,78 @@ function shootTarget() { Audio.playSound(targetLaunchSound, audioOptions); } +function makeGrid(type, scale, size) { + var separation = scale * 2; + var pos = Vec3.sum(Camera.getPosition(), Vec3.multiply(10.0 * scale * separation, Quat.getFront(Camera.getOrientation()))); + var x, y, z; + var GRID_LIFE = 60.0; + var dimensions; + + for (x = 0; x < size; x++) { + for (y = 0; y < size; y++) { + for (z = 0; z < size; z++) { + + dimensions = { x: separation/2.0 * (0.5 + Math.random()), y: separation/2.0 * (0.5 + Math.random()), z: separation/2.0 * (0.5 + Math.random()) / 4.0 }; + + Entities.addEntity( + { type: type, + position: { x: pos.x + x * separation, y: pos.y + y * separation, z: pos.z + z * separation }, + dimensions: dimensions, + color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 }, + velocity: { x: 0, y: 0, z: 0 }, + gravity: { x: 0, y: 0, z: 0 }, + lifetime: GRID_LIFE, + rotation: Camera.getOrientation(), + damping: 0.1, + density: 100.0, + collisionsWillMove: true }); + } + } + } +} +function makePlatform(gravity, scale, size) { + var separation = scale * 2; + var pos = Vec3.sum(Camera.getPosition(), Vec3.multiply(10.0 * scale * separation, Quat.getFront(Camera.getOrientation()))); + pos.y -= separation * size; + var x, y, z; + var TARGET_LIFE = 60.0; + var INITIAL_GAP = 0.5; + var dimensions; + + for (x = 0; x < size; x++) { + for (y = 0; y < size; y++) { + for (z = 0; z < size; z++) { + + dimensions = { x: separation/2.0, y: separation, z: separation/2.0 }; + + Entities.addEntity( + { type: "Box", + position: { x: pos.x - (separation * size / 2.0) + x * separation, + y: pos.y + y * (separation + INITIAL_GAP), + z: pos.z - (separation * size / 2.0) + z * separation }, + dimensions: dimensions, + color: { red: Math.random() * 255, green: Math.random() * 255, blue: Math.random() * 255 }, + velocity: { x: 0, y: 0, z: 0 }, + gravity: { x: 0, y: gravity, z: 0 }, + lifetime: TARGET_LIFE, + damping: 0.1, + density: 100.0, + collisionsWillMove: true }); + } + } + } + + // Make a floor for this stuff to fall onto + Entities.addEntity({ + type: "Box", + position: { x: pos.x, y: pos.y - separation / 2.0, z: pos.z }, + dimensions: { x: 2.0 * separation * size, y: separation / 2.0, z: 2.0 * separation * size }, + color: { red: 128, green: 128, blue: 128 }, + lifetime: TARGET_LIFE + }); + +} + function entityCollisionWithEntity(entity1, entity2, collision) { if (((entity1.id == bulletID.id) || (entity1.id == targetID.id)) && @@ -281,19 +331,16 @@ function keyPressEvent(event) { var time = MIN_THROWER_DELAY + Math.random() * MAX_THROWER_DELAY; Script.setTimeout(shootTarget, time); } else if ((event.text == ".") || (event.text == "SPACE")) { - shootFromMouse(); + shootFromMouse(false); + } else if (event.text == ",") { + shootFromMouse(true); } else if (event.text == "r") { playLoadSound(); - } else if (event.text == "g") { - makeGrid("Box", 0.0, 0.4, 3); - } else if (event.text == "f") { - makeGrid("Box", -9.8, 0.4, 5); } else if (event.text == "s") { // Hit this key to dump a posture from hydra to log Quat.print("arm = ", MyAvatar.getJointRotation("LeftArm")); Quat.print("forearm = ", MyAvatar.getJointRotation("LeftForeArm")); Quat.print("hand = ", MyAvatar.getJointRotation("LeftHand")); - } } @@ -339,18 +386,7 @@ function update(deltaTime) { if (targetID && !targetID.isKnownID) { targetID = Entities.identifyEntity(targetID); } - // Check for mouseLook movement, update rotation - // rotate body yaw for yaw received from mouse - var newOrientation = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Radians( { x: 0, y: yawFromMouse, z: 0 } )); - //MyAvatar.orientation = newOrientation; - yawFromMouse = 0; - // apply pitch from mouse - var newPitch = MyAvatar.headPitch + pitchFromMouse; - //MyAvatar.headPitch = newPitch; - pitchFromMouse = 0; - - if (activeControllers == 0) { if (Controller.getNumberOfSpatialControls() > 0) { activeControllers = Controller.getNumberOfSpatialControls(); @@ -424,19 +460,19 @@ function update(deltaTime) { var velocity = Vec3.multiply(BULLET_VELOCITY, Vec3.normalize(palmToFingerTipVector)); - shootBullet(position, velocity); + shootBullet(position, velocity, false); } } } } -function shootFromMouse() { +function shootFromMouse(grenade) { var DISTANCE_FROM_CAMERA = 1.0; var camera = Camera.getPosition(); var forwardVector = Quat.getFront(Camera.getOrientation()); var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, DISTANCE_FROM_CAMERA)); var velocity = Vec3.multiply(forwardVector, BULLET_VELOCITY); - shootBullet(newPosition, velocity); + shootBullet(newPosition, velocity, grenade); } function mouseReleaseEvent(event) { @@ -444,21 +480,23 @@ function mouseReleaseEvent(event) { isMouseDown = false; } -function mouseMoveEvent(event) { - if (isMouseDown) { - var MOUSE_YAW_SCALE = -0.25; - var MOUSE_PITCH_SCALE = -12.5; - var FIXED_MOUSE_TIMESTEP = 0.016; - yawFromMouse += ((event.x - lastX) * MOUSE_YAW_SCALE * FIXED_MOUSE_TIMESTEP); - pitchFromMouse += ((event.y - lastY) * MOUSE_PITCH_SCALE * FIXED_MOUSE_TIMESTEP); - lastX = event.x; - lastY = event.y; - } +function mousePressEvent(event) { + var clickedText = false; + var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y}); + if (clickedOverlay == offButton) { + Script.stop(); + } else if (clickedOverlay == platformButton) { + makePlatform(-9.8, 1.0, 5); + } else if (clickedOverlay == gridButton) { + makeGrid("Box", 1.0, 3); + } } function scriptEnding() { Overlays.deleteOverlay(reticle); Overlays.deleteOverlay(offButton); + Overlays.deleteOverlay(platformButton); + Overlays.deleteOverlay(gridButton); Overlays.deleteOverlay(pointer[0]); Overlays.deleteOverlay(pointer[1]); Overlays.deleteOverlay(text); @@ -470,7 +508,7 @@ Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity); Script.scriptEnding.connect(scriptEnding); Script.update.connect(update); Controller.mouseReleaseEvent.connect(mouseReleaseEvent); -Controller.mouseMoveEvent.connect(mouseMoveEvent); +Controller.mousePressEvent.connect(mousePressEvent); Controller.keyPressEvent.connect(keyPressEvent); From 2751fab2c360892ac1b629de6d6b68d46b7c0abd Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 21 Jan 2015 18:02:13 -0800 Subject: [PATCH 06/19] don't send collision events for inactive pairs also throttle collision events to 30/sec --- libraries/physics/src/PhysicsEngine.cpp | 30 ++++++++++++++++++++++--- libraries/physics/src/PhysicsEngine.h | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 02304b3b8d..74b792e3c0 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -249,23 +249,47 @@ void PhysicsEngine::stepSimulation() { } void PhysicsEngine::computeCollisionEvents() { - // update all contacts + // update all contacts every frame int numManifolds = _collisionDispatcher->getNumManifolds(); for (int i = 0; i < numManifolds; ++i) { btPersistentManifold* contactManifold = _collisionDispatcher->getManifoldByIndexInternal(i); if (contactManifold->getNumContacts() > 0) { + // TODO: require scripts to register interest in callbacks for specific objects + // so we can filter out most collision events right here. const btCollisionObject* objectA = static_cast(contactManifold->getBody0()); const btCollisionObject* objectB = static_cast(contactManifold->getBody1()); + + if (!(objectA->isActive() || objectB->isActive())) { + // both objects are inactive so stop tracking this contact, + // which will eventually trigger a CONTACT_EVENT_TYPE_END + continue; + } void* a = objectA->getUserPointer(); void* b = objectB->getUserPointer(); if (a || b) { // the manifold has up to 4 distinct points, but only extract info from the first - _contactMap[ContactKey(a, b)].update(_numSubsteps, contactManifold->getContactPoint(0), _originOffset); + _contactMap[ContactKey(a, b)].update(_numContactFrames, contactManifold->getContactPoint(0), _originOffset); } } } + // We harvest collision callbacks every few frames, which contributes the following effects: + // + // (1) There is a maximum collision callback rate per pair: substep_rate / SUBSTEPS_PER_COLLIION_FRAME + // (2) END/START cycles shorter than SUBSTEPS_PER_COLLIION_FRAME will be filtered out + // (3) There is variable lag between when the contact actually starts and when it is reported, + // up to SUBSTEPS_PER_COLLIION_FRAME * time_per_substep + // + const uint32_t SUBSTEPS_PER_COLLISION_FRAME = 2; + if (_numSubsteps - _numContactFrames * SUBSTEPS_PER_COLLISION_FRAME < SUBSTEPS_PER_COLLISION_FRAME) { + // we don't harvest collision callbacks every frame + // this sets a maximum callback-per-contact rate + // and also filters out END/START events that happen on shorter timescales + return; + } + + ++_numContactFrames; // scan known contacts and trigger events ContactMap::iterator contactItr = _contactMap.begin(); while (contactItr != _contactMap.end()) { @@ -289,7 +313,7 @@ void PhysicsEngine::computeCollisionEvents() { } // TODO: enable scripts to filter based on contact event type - ContactEventType type = contactItr->second.computeType(_numSubsteps); + ContactEventType type = contactItr->second.computeType(_numContactFrames); if (type == CONTACT_EVENT_TYPE_END) { ContactMap::iterator iterToDelete = contactItr; ++contactItr; diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index 73a02607e8..d333eef010 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -110,6 +110,7 @@ private: EntityEditPacketSender* _entityPacketSender = NULL; ContactMap _contactMap; + uint32_t _numContactFrames = 0; }; #endif // hifi_PhysicsEngine_h From b2e79a0157ad5786314783acf1ea5be8e0804583 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 21 Jan 2015 18:06:19 -0800 Subject: [PATCH 07/19] don't process results when no simulation --- libraries/physics/src/PhysicsEngine.cpp | 32 +++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 74b792e3c0..55920cf315 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -231,21 +231,23 @@ void PhysicsEngine::stepSimulation() { _numSubsteps += (uint32_t)numSubsteps; unlock(); - // This is step (3) which is done outside of stepSimulation() so we can lock _entityTree. - // - // Unfortunately we have to unlock the simulation (above) before we try to lock the _entityTree - // to avoid deadlock -- the _entityTree may try to lock its EntitySimulation (from which this - // PhysicsEngine derives) when updating/adding/deleting entities so we need to wait for our own - // lock on the tree before we re-lock ourselves. - // - // TODO: untangle these lock sequences. - _entityTree->lockForWrite(); - lock(); - _dynamicsWorld->synchronizeMotionStates(); - unlock(); - _entityTree->unlock(); - - computeCollisionEvents(); + if (_numSubsteps > 0) { + // This is step (3) which is done outside of stepSimulation() so we can lock _entityTree. + // + // Unfortunately we have to unlock the simulation (above) before we try to lock the _entityTree + // to avoid deadlock -- the _entityTree may try to lock its EntitySimulation (from which this + // PhysicsEngine derives) when updating/adding/deleting entities so we need to wait for our own + // lock on the tree before we re-lock ourselves. + // + // TODO: untangle these lock sequences. + _entityTree->lockForWrite(); + lock(); + _dynamicsWorld->synchronizeMotionStates(); + unlock(); + _entityTree->unlock(); + + computeCollisionEvents(); + } } void PhysicsEngine::computeCollisionEvents() { From 77c436299135daac4e28a479305cfc012b3928ec Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 21 Jan 2015 18:14:24 -0800 Subject: [PATCH 08/19] fix typo --- libraries/physics/src/PhysicsEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 55920cf315..7f2b139058 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -231,7 +231,7 @@ void PhysicsEngine::stepSimulation() { _numSubsteps += (uint32_t)numSubsteps; unlock(); - if (_numSubsteps > 0) { + if (numSubsteps > 0) { // This is step (3) which is done outside of stepSimulation() so we can lock _entityTree. // // Unfortunately we have to unlock the simulation (above) before we try to lock the _entityTree From 52193fce387e1d4511838d4d5691de25e8c62771 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 22 Jan 2015 08:35:38 -0800 Subject: [PATCH 09/19] Remove qDebug --- interface/src/ui/overlays/ImageOverlay.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 164b3916db..b5c235d828 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -52,7 +52,6 @@ void ImageOverlay::render(RenderArgs* args) { if (!_isLoaded && !_imageURL.isEmpty()) { _isLoaded = true; _renderImage = true; - qDebug() << "Now loding texture for ImageOverlay"; _texture = DependencyManager::get()->getTexture(_imageURL); } From 0e9e77f1667c15a2ab032ed362c00c5a54e46914 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 22 Jan 2015 08:58:55 -0800 Subject: [PATCH 10/19] Fix broken support for color-only ImageOverlay --- interface/src/ui/overlays/ImageOverlay.cpp | 63 +++++++++++++--------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index b5c235d828..e18f99072f 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -22,10 +22,10 @@ #include "ImageOverlay.h" ImageOverlay::ImageOverlay() : + _imageURL(), _renderImage(false), _wantClipFromImage(false) { - _isLoaded = false; } ImageOverlay::ImageOverlay(const ImageOverlay* imageOverlay) : @@ -45,47 +45,39 @@ ImageOverlay::~ImageOverlay() { // TODO: handle setting image multiple times, how do we manage releasing the bound texture? void ImageOverlay::setImageURL(const QUrl& url) { _imageURL = url; - _isLoaded = false; + + if (url.isEmpty()) { + _isLoaded = true; + _renderImage = false; + _texture.clear(); + } else { + _isLoaded = false; + _renderImage = true; + } } void ImageOverlay::render(RenderArgs* args) { - if (!_isLoaded && !_imageURL.isEmpty()) { + if (!_isLoaded && _renderImage) { _isLoaded = true; - _renderImage = true; _texture = DependencyManager::get()->getTexture(_imageURL); } - if (!_visible || !_isLoaded || !_texture || !_texture->isLoaded()) { + // If we are not visible or loaded, return. If we are trying to render an + // image but the texture hasn't loaded, return. + if (!_visible || !_isLoaded || (_renderImage && !_texture->isLoaded())) { return; } if (_renderImage) { - qDebug() << "Rendering: " << _imageURL << ", " << _texture->getWidth() << ", " << _texture->getHeight(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, _texture->getID()); } + const float MAX_COLOR = 255.0f; xColor color = getColor(); float alpha = getAlpha(); glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); - float imageWidth = _texture->getWidth(); - float imageHeight = _texture->getHeight(); - - QRect fromImage; - if (_wantClipFromImage) { - fromImage = _fromImage; - } else { - fromImage.setX(0); - fromImage.setY(0); - fromImage.setWidth(imageWidth); - fromImage.setHeight(imageHeight); - } - float x = fromImage.x() / imageWidth; - float y = fromImage.y() / imageHeight; - float w = fromImage.width() / imageWidth; // ?? is this what we want? not sure - float h = fromImage.height() / imageHeight; - int left = _bounds.left(); int right = _bounds.right() + 1; int top = _bounds.top(); @@ -93,10 +85,29 @@ void ImageOverlay::render(RenderArgs* args) { glm::vec2 topLeft(left, top); glm::vec2 bottomRight(right, bottom); - glm::vec2 texCoordTopLeft(x, y); - glm::vec2 texCoordBottomRight(x + w, y + h); if (_renderImage) { + float imageWidth = _texture->getWidth(); + float imageHeight = _texture->getHeight(); + + QRect fromImage; + if (_wantClipFromImage) { + fromImage = _fromImage; + } else { + fromImage.setX(0); + fromImage.setY(0); + fromImage.setWidth(imageWidth); + fromImage.setHeight(imageHeight); + } + + float x = fromImage.x() / imageWidth; + float y = fromImage.y() / imageHeight; + float w = fromImage.width() / imageWidth; // ?? is this what we want? not sure + float h = fromImage.height() / imageHeight; + + glm::vec2 texCoordTopLeft(x, y); + glm::vec2 texCoordBottomRight(x + w, y + h); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); } else { DependencyManager::get()->renderQuad(topLeft, bottomRight); @@ -135,7 +146,7 @@ void ImageOverlay::setProperties(const QScriptValue& properties) { subImageRect.setHeight(oldSubImageRect.height()); } setClipFromSource(subImageRect); - } + } QScriptValue imageURL = properties.property("imageURL"); if (imageURL.isValid()) { From 3997b916c1bcccb640f6f2ce8b11cc4426feef4a Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 22 Jan 2015 09:17:51 -0800 Subject: [PATCH 11/19] remove ground collision hack for physics testing --- libraries/physics/src/PhysicsEngine.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 7f2b139058..c374f03705 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -186,22 +186,6 @@ void PhysicsEngine::init(EntityEditPacketSender* packetSender) { // default gravity of the world is zero, so each object must specify its own gravity // TODO: set up gravity zones _dynamicsWorld->setGravity(btVector3(0.0f, 0.0f, 0.0f)); - - // GROUND HACK: add a big planar floor (and walls for testing) to catch falling objects - btTransform groundTransform; - groundTransform.setIdentity(); - for (int i = 0; i < 3; ++i) { - btVector3 normal(0.0f, 0.0f, 0.0f); - normal[i] = 1.0f; - btCollisionShape* plane = new btStaticPlaneShape(normal, 0.0f); - - btCollisionObject* groundObject = new btCollisionObject(); - groundObject->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT); - groundObject->setCollisionShape(plane); - - groundObject->setWorldTransform(groundTransform); - _dynamicsWorld->addCollisionObject(groundObject); - } } assert(packetSender); From 5efc046316d658bca622c585c7983b839734076f Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Thu, 22 Jan 2015 15:03:13 -0600 Subject: [PATCH 12/19] Adding http monitoring for ICE server --- ice-server/CMakeLists.txt | 16 +++++++++++++++- ice-server/src/IceServer.cpp | 36 +++++++++++++++++++++++++++++++++++- ice-server/src/IceServer.h | 14 ++++++++++---- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/ice-server/CMakeLists.txt b/ice-server/CMakeLists.txt index 24e780f9aa..a7b2a206e4 100644 --- a/ice-server/CMakeLists.txt +++ b/ice-server/CMakeLists.txt @@ -4,6 +4,20 @@ set(TARGET_NAME ice-server) setup_hifi_project(Network) # link the shared hifi libraries -link_hifi_libraries(networking shared) +link_hifi_libraries(embedded-webserver networking shared) + +# find OpenSSL +find_package(OpenSSL REQUIRED) + +if (APPLE AND ${OPENSSL_INCLUDE_DIR} STREQUAL "/usr/include") +# this is a user on OS X using system OpenSSL, which is going to throw warnings since they're deprecating for their common crypto +message(WARNING "The found version of OpenSSL is the OS X system version. This will produce deprecation warnings." +"\nWe recommend you install a newer version (at least 1.0.1h) in a different directory and set OPENSSL_ROOT_DIR in your env so Cmake can find it.") +endif () + +include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") + +# append OpenSSL to our list of libraries to link +target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBRARIES}) include_dependency_includes() \ No newline at end of file diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index c06bb0fc88..531dd4ea22 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -20,14 +20,19 @@ const int CLEAR_INACTIVE_PEERS_INTERVAL_MSECS = 1 * 1000; const int PEER_SILENCE_THRESHOLD_MSECS = 5 * 1000; +const quint16 ICE_SERVER_MONITORING_PORT = 40110; + IceServer::IceServer(int argc, char* argv[]) : QCoreApplication(argc, argv), _id(QUuid::createUuid()), _serverSocket(), - _activePeers() + _activePeers(), + _httpManager(ICE_SERVER_MONITORING_PORT, QString("%1/web/").arg(QCoreApplication::applicationDirPath()), this), + _httpsManager(NULL) { // start the ice-server socket qDebug() << "ice-server socket is listening on" << ICE_SERVER_DEFAULT_PORT; + qDebug() << "monitoring http endpoint is listening on " << ICE_SERVER_MONITORING_PORT; _serverSocket.bind(QHostAddress::AnyIPv4, ICE_SERVER_DEFAULT_PORT); // call our process datagrams slot when the UDP socket has packets ready @@ -165,3 +170,32 @@ void IceServer::clearInactivePeers() { } } } + +bool IceServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) { + // + // We need an HTTP handler in order to monitor the health of the ice server + // The correct functioning of the ICE server will first be determined by its HTTP availability, + // and then by the existence of a minimum number of peers in the list, matching the minimum number of + // domains in production by High Fidelity. + // + + int MINIMUM_PEERS = 3; + bool IS_HEALTHY = false; + + IS_HEALTHY = _activePeers.size() >= MINIMUM_PEERS ? true : false; + + if (connection->requestOperation() == QNetworkAccessManager::GetOperation) { + if (url.path() == "/status") { + if (IS_HEALTHY) { + connection->respond(HTTPConnection::StatusCode200, QByteArray::number(_activePeers.size())); + } else { + connection->respond(HTTPConnection::StatusCode404, QByteArray::number(_activePeers.size())); + } + } + } + return true; +} + +bool IceServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler) { + return true; +} diff --git a/ice-server/src/IceServer.h b/ice-server/src/IceServer.h index e15bda1211..effc8b8154 100644 --- a/ice-server/src/IceServer.h +++ b/ice-server/src/IceServer.h @@ -12,17 +12,21 @@ #ifndef hifi_IceServer_h #define hifi_IceServer_h -#include -#include -#include +#include +#include +#include #include +#include typedef QHash NetworkPeerHash; -class IceServer : public QCoreApplication { +class IceServer : public QCoreApplication, public HTTPSRequestHandler { + Q_OBJECT public: IceServer(int argc, char* argv[]); + bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false); + bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler = false); private slots: void processDatagrams(); void clearInactivePeers(); @@ -34,6 +38,8 @@ private: QUdpSocket _serverSocket; NetworkPeerHash _activePeers; QHash > _currentConnections; + HTTPManager _httpManager; + HTTPSManager* _httpsManager; }; #endif // hifi_IceServer_h \ No newline at end of file From 14c7dc8eb9bff4342ebda4b99f27845244aa4ecf Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 22 Jan 2015 13:13:18 -0800 Subject: [PATCH 13/19] debugging stutter --- .../entities/src/EntityEditPacketSender.cpp | 7 +++ libraries/entities/src/EntityItem.cpp | 6 +++ libraries/entities/src/EntityTree.cpp | 4 ++ libraries/entities/src/EntityTreeElement.cpp | 2 + libraries/physics/src/EntityMotionState.cpp | 13 +++++ libraries/physics/src/ObjectMotionState.cpp | 49 ++++++++++++++++++- libraries/physics/src/PhysicsEngine.cpp | 3 ++ 7 files changed, 82 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index f2588d0493..9129cd875e 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -27,7 +27,13 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemID modelID, const EntityItemProperties& properties) { + + qDebug() << "EntityEditPacketSender::queueEditEntityMessage()..."; + qDebug() << " ID:" << modelID; + qDebug() << " properties:" << properties; + if (!_shouldSend) { + qDebug() << " BAIL EARLY! _shouldSend:" << _shouldSend; return; // bail early } @@ -36,6 +42,7 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI int sizeOut = 0; if (EntityItemProperties::encodeEntityEditPacket(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) { + qDebug() << " queueOctreeEditMessage() sizeOut:" << sizeOut; queueOctreeEditMessage(type, bufferOut, sizeOut); } } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 7e3e982fb8..b413ea2b23 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1064,6 +1064,9 @@ const float MIN_SPIN_DELTA = 0.0003f; void EntityItem::updatePosition(const glm::vec3& value) { if (glm::distance(_position, value) * (float)TREE_SCALE > MIN_POSITION_DELTA) { + qDebug() << "EntityItem::updatePosition()... "; + qDebug() << " new position:" << value; + qDebug() << " in meters:" << (value * (float) TREE_SCALE); _position = value; recalculateCollisionShape(); _dirtyFlags |= EntityItem::DIRTY_POSITION; @@ -1073,6 +1076,9 @@ void EntityItem::updatePosition(const glm::vec3& value) { void EntityItem::updatePositionInMeters(const glm::vec3& value) { glm::vec3 position = glm::clamp(value / (float) TREE_SCALE, 0.0f, 1.0f); if (glm::distance(_position, position) * (float)TREE_SCALE > MIN_POSITION_DELTA) { + qDebug() << "EntityItem::updatePositionInMeters()... "; + qDebug() << " new position:" << position; + qDebug() << " in meters:" << value; _position = position; recalculateCollisionShape(); _dirtyFlags |= EntityItem::DIRTY_POSITION; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 580fed8790..1e6fe51916 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -305,6 +305,7 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) /// we're not changing the content of the tree, we're only changing the internal IDs that map entities from creator /// based to known IDs. This means we don't have to recurse the tree to mark the changed path as dirty. void EntityTree::handleAddEntityResponse(const QByteArray& packet) { + qDebug() << "EntityTree::handleAddEntityResponse()"; if (!getIsClient()) { qDebug() << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***"; @@ -329,6 +330,9 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) { searchEntityID.id = entityID; searchEntityID.creatorTokenID = creatorTokenID; + qDebug() << " creatorTokenID:" << creatorTokenID; + qDebug() << " entityID:" << entityID; + lockForWrite(); // find the creator token version, it's containing element, and the entity itself diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index aff6e64f57..923ab8a9ca 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -795,11 +795,13 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int } } else { + qDebug() << "EntityTreeElement::readElementDataFromBuffer() about to construct entity item"; entityItem = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead, args); if (entityItem) { bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); addEntityItem(entityItem); // add this new entity to this elements entities entityItemID = entityItem->getEntityItemID(); + qDebug() << " entityItemID:" << entityItemID; _myTree->setContainingElement(entityItemID, this); _myTree->postAddEntity(entityItem); } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 8b6fb1ea9f..f08683455c 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -159,15 +159,23 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ return; // never update entities that are unknown } if (_outgoingPacketFlags) { + qDebug() << "EntityMotionState::sendUpdate()..."; + qDebug() << " _outgoingPacketFlags:" << _outgoingPacketFlags; + EntityItemProperties properties = _entity->getProperties(); + qDebug() << " _entity->getProperties():" << properties << "line:" << __LINE__; if (_outgoingPacketFlags & EntityItem::DIRTY_POSITION) { btTransform worldTrans = _body->getWorldTransform(); _sentPosition = bulletToGLM(worldTrans.getOrigin()); properties.setPosition(_sentPosition + ObjectMotionState::getWorldOffset()); + qDebug() << " _sentPosition:" << _sentPosition << "line:" << __LINE__; + qDebug() << " ObjectMotionState::getWorldOffset():" << ObjectMotionState::getWorldOffset() << "line:" << __LINE__; _sentRotation = bulletToGLM(worldTrans.getRotation()); properties.setRotation(_sentRotation); + + qDebug() << " after position properties:" << properties << "line:" << __LINE__; } if (_outgoingPacketFlags & EntityItem::DIRTY_VELOCITY) { @@ -197,6 +205,8 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ properties.setGravity(_sentAcceleration); // DANGER! EntityItem stores angularVelocity in degrees/sec!!! properties.setAngularVelocity(glm::degrees(_sentAngularVelocity)); + + qDebug() << " after velocity properties:" << properties << "line:" << __LINE__; } // RELIABLE_SEND_HACK: count number of updates for entities at rest so we can stop sending them after some limit. @@ -217,6 +227,9 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ EntityItemID id(_entity->getID()); EntityEditPacketSender* entityPacketSender = static_cast(packetSender); + qDebug() << "EntityMotionState::sendUpdate()... about to call queueEditEntityMessage()"; + qDebug() << " id:" << id; + qDebug() << " properties:" << properties; entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); // The outgoing flags only itemized WHAT to send, not WHETHER to send, hence we always set them diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index cab36b8370..cacaab614f 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -108,6 +108,18 @@ bool ObjectMotionState::doesNotNeedToSendUpdate() const { bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { assert(_body); + + + // if we've never checked before, our _sentFrame will be 0, and we need to initialize our state + if (_sentFrame == 0) { + _sentPosition = bulletToGLM(_body->getWorldTransform().getOrigin()); + _sentVelocity = bulletToGLM(_body->getLinearVelocity()); + _sentAngularVelocity = bulletToGLM(_body->getAngularVelocity()); + _sentFrame = simulationFrame; + return false; + } + + uint32_t wasSentFrame = _sentFrame; float dt = (float)(simulationFrame - _sentFrame) * PHYSICS_ENGINE_FIXED_SUBSTEP; _sentFrame = simulationFrame; bool isActive = _body->isActive(); @@ -131,6 +143,10 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { // NOTE: math in done the simulation-frame, which is NOT necessarily the same as the world-frame // due to _worldOffset. + + glm::vec3 wasPosition = _sentPosition; + glm::vec3 wasVelocity = _sentVelocity; + glm::vec3 wasAcceleration = _sentAcceleration; // compute position error if (glm::length2(_sentVelocity) > 0.0f) { @@ -141,11 +157,40 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { btTransform worldTrans = _body->getWorldTransform(); glm::vec3 position = bulletToGLM(worldTrans.getOrigin()); - + float dx2 = glm::distance2(position, _sentPosition); const float MAX_POSITION_ERROR_SQUARED = 0.001f; // 0.001 m^2 ~~> 0.03 m if (dx2 > MAX_POSITION_ERROR_SQUARED) { - return true; +qDebug() << "ObjectMotionState::shouldSendUpdate()... computing position error"; + + glm::vec3 bulletVelocity = bulletToGLM(_body->getLinearVelocity()); + +qDebug() << " was _sentFrame:" << wasSentFrame; +qDebug() << " now _sentFrame:" << _sentFrame; +qDebug() << " dt:" << dt; + +qDebug() << " was _sentAcceleration:" << wasAcceleration; +qDebug() << " now _sentAcceleration:" << _sentAcceleration; + +qDebug() << " bulletVelocity:" << bulletVelocity; +qDebug() << " was _sentVelocity:" << wasVelocity; +qDebug() << " now _sentVelocity:" << _sentVelocity; + +qDebug() << " was _sentPosition:" << wasPosition; +qDebug() << " now _sentPosition:" << _sentPosition; +qDebug() << " bullet position:" << position; + +qDebug() << " dx2:" << dx2; +qDebug() << " (dx2 > MAX_POSITION_ERROR_SQUARED)... considering"; + if (wasSentFrame > 0) { +qDebug() << " (wasSentFrame > 0)... return TRUE"; + return true; + } else { +qDebug() << " (wasSentFrame == 0)... ignore use bullet position for next _sentPosition"; + _sentPosition = position; + } + } else { + //qDebug() << " (dx2 <= MAX_POSITION_ERROR_SQUARED)... FALL THROUGH... likely return false"; } if (glm::length2(_sentAngularVelocity) > 0.0f) { diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 7f2b139058..58253d1bd4 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -35,6 +35,9 @@ void PhysicsEngine::updateEntitiesInternal(const quint64& now) { // (3) synchronize outgoing motion states // (4) send outgoing packets + + //qDebug() << "_numSubsteps:" << _numSubsteps; + // this is step (4) QSet::iterator stateItr = _outgoingPackets.begin(); while (stateItr != _outgoingPackets.end()) { From 838a549abefa3549d2f7362686f7c2d2e114276d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 22 Jan 2015 13:31:09 -0800 Subject: [PATCH 14/19] debugging stutter --- .../entities/src/EntityEditPacketSender.cpp | 7 ---- libraries/entities/src/EntityItem.cpp | 6 --- libraries/entities/src/EntityTree.cpp | 4 -- libraries/entities/src/EntityTreeElement.cpp | 2 - libraries/physics/src/EntityMotionState.cpp | 15 -------- libraries/physics/src/ObjectMotionState.cpp | 38 +------------------ libraries/physics/src/PhysicsEngine.cpp | 3 -- 7 files changed, 1 insertion(+), 74 deletions(-) diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index 9129cd875e..f2588d0493 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -27,13 +27,7 @@ void EntityEditPacketSender::adjustEditPacketForClockSkew(PacketType type, void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemID modelID, const EntityItemProperties& properties) { - - qDebug() << "EntityEditPacketSender::queueEditEntityMessage()..."; - qDebug() << " ID:" << modelID; - qDebug() << " properties:" << properties; - if (!_shouldSend) { - qDebug() << " BAIL EARLY! _shouldSend:" << _shouldSend; return; // bail early } @@ -42,7 +36,6 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI int sizeOut = 0; if (EntityItemProperties::encodeEntityEditPacket(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) { - qDebug() << " queueOctreeEditMessage() sizeOut:" << sizeOut; queueOctreeEditMessage(type, bufferOut, sizeOut); } } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index b413ea2b23..7e3e982fb8 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1064,9 +1064,6 @@ const float MIN_SPIN_DELTA = 0.0003f; void EntityItem::updatePosition(const glm::vec3& value) { if (glm::distance(_position, value) * (float)TREE_SCALE > MIN_POSITION_DELTA) { - qDebug() << "EntityItem::updatePosition()... "; - qDebug() << " new position:" << value; - qDebug() << " in meters:" << (value * (float) TREE_SCALE); _position = value; recalculateCollisionShape(); _dirtyFlags |= EntityItem::DIRTY_POSITION; @@ -1076,9 +1073,6 @@ void EntityItem::updatePosition(const glm::vec3& value) { void EntityItem::updatePositionInMeters(const glm::vec3& value) { glm::vec3 position = glm::clamp(value / (float) TREE_SCALE, 0.0f, 1.0f); if (glm::distance(_position, position) * (float)TREE_SCALE > MIN_POSITION_DELTA) { - qDebug() << "EntityItem::updatePositionInMeters()... "; - qDebug() << " new position:" << position; - qDebug() << " in meters:" << value; _position = position; recalculateCollisionShape(); _dirtyFlags |= EntityItem::DIRTY_POSITION; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 1e6fe51916..580fed8790 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -305,7 +305,6 @@ void EntityTree::processRemovedEntities(const DeleteEntityOperator& theOperator) /// we're not changing the content of the tree, we're only changing the internal IDs that map entities from creator /// based to known IDs. This means we don't have to recurse the tree to mark the changed path as dirty. void EntityTree::handleAddEntityResponse(const QByteArray& packet) { - qDebug() << "EntityTree::handleAddEntityResponse()"; if (!getIsClient()) { qDebug() << "UNEXPECTED!!! EntityTree::handleAddEntityResponse() with !getIsClient() ***"; @@ -330,9 +329,6 @@ void EntityTree::handleAddEntityResponse(const QByteArray& packet) { searchEntityID.id = entityID; searchEntityID.creatorTokenID = creatorTokenID; - qDebug() << " creatorTokenID:" << creatorTokenID; - qDebug() << " entityID:" << entityID; - lockForWrite(); // find the creator token version, it's containing element, and the entity itself diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 923ab8a9ca..aff6e64f57 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -795,13 +795,11 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int } } else { - qDebug() << "EntityTreeElement::readElementDataFromBuffer() about to construct entity item"; entityItem = EntityTypes::constructEntityItem(dataAt, bytesLeftToRead, args); if (entityItem) { bytesForThisEntity = entityItem->readEntityDataFromBuffer(dataAt, bytesLeftToRead, args); addEntityItem(entityItem); // add this new entity to this elements entities entityItemID = entityItem->getEntityItemID(); - qDebug() << " entityItemID:" << entityItemID; _myTree->setContainingElement(entityItemID, this); _myTree->postAddEntity(entityItem); } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index f08683455c..9453501407 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -159,23 +159,13 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ return; // never update entities that are unknown } if (_outgoingPacketFlags) { - qDebug() << "EntityMotionState::sendUpdate()..."; - qDebug() << " _outgoingPacketFlags:" << _outgoingPacketFlags; - EntityItemProperties properties = _entity->getProperties(); - qDebug() << " _entity->getProperties():" << properties << "line:" << __LINE__; - if (_outgoingPacketFlags & EntityItem::DIRTY_POSITION) { btTransform worldTrans = _body->getWorldTransform(); _sentPosition = bulletToGLM(worldTrans.getOrigin()); properties.setPosition(_sentPosition + ObjectMotionState::getWorldOffset()); - qDebug() << " _sentPosition:" << _sentPosition << "line:" << __LINE__; - qDebug() << " ObjectMotionState::getWorldOffset():" << ObjectMotionState::getWorldOffset() << "line:" << __LINE__; - _sentRotation = bulletToGLM(worldTrans.getRotation()); properties.setRotation(_sentRotation); - - qDebug() << " after position properties:" << properties << "line:" << __LINE__; } if (_outgoingPacketFlags & EntityItem::DIRTY_VELOCITY) { @@ -205,8 +195,6 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ properties.setGravity(_sentAcceleration); // DANGER! EntityItem stores angularVelocity in degrees/sec!!! properties.setAngularVelocity(glm::degrees(_sentAngularVelocity)); - - qDebug() << " after velocity properties:" << properties << "line:" << __LINE__; } // RELIABLE_SEND_HACK: count number of updates for entities at rest so we can stop sending them after some limit. @@ -227,9 +215,6 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ EntityItemID id(_entity->getID()); EntityEditPacketSender* entityPacketSender = static_cast(packetSender); - qDebug() << "EntityMotionState::sendUpdate()... about to call queueEditEntityMessage()"; - qDebug() << " id:" << id; - qDebug() << " properties:" << properties; entityPacketSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, id, properties); // The outgoing flags only itemized WHAT to send, not WHETHER to send, hence we always set them diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index cacaab614f..effd7c3e4d 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -109,7 +109,6 @@ bool ObjectMotionState::doesNotNeedToSendUpdate() const { bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { assert(_body); - // if we've never checked before, our _sentFrame will be 0, and we need to initialize our state if (_sentFrame == 0) { _sentPosition = bulletToGLM(_body->getWorldTransform().getOrigin()); @@ -119,7 +118,6 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { return false; } - uint32_t wasSentFrame = _sentFrame; float dt = (float)(simulationFrame - _sentFrame) * PHYSICS_ENGINE_FIXED_SUBSTEP; _sentFrame = simulationFrame; bool isActive = _body->isActive(); @@ -143,11 +141,6 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { // NOTE: math in done the simulation-frame, which is NOT necessarily the same as the world-frame // due to _worldOffset. - - glm::vec3 wasPosition = _sentPosition; - glm::vec3 wasVelocity = _sentVelocity; - glm::vec3 wasAcceleration = _sentAcceleration; - // compute position error if (glm::length2(_sentVelocity) > 0.0f) { _sentVelocity += _sentAcceleration * dt; @@ -161,36 +154,7 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { float dx2 = glm::distance2(position, _sentPosition); const float MAX_POSITION_ERROR_SQUARED = 0.001f; // 0.001 m^2 ~~> 0.03 m if (dx2 > MAX_POSITION_ERROR_SQUARED) { -qDebug() << "ObjectMotionState::shouldSendUpdate()... computing position error"; - - glm::vec3 bulletVelocity = bulletToGLM(_body->getLinearVelocity()); - -qDebug() << " was _sentFrame:" << wasSentFrame; -qDebug() << " now _sentFrame:" << _sentFrame; -qDebug() << " dt:" << dt; - -qDebug() << " was _sentAcceleration:" << wasAcceleration; -qDebug() << " now _sentAcceleration:" << _sentAcceleration; - -qDebug() << " bulletVelocity:" << bulletVelocity; -qDebug() << " was _sentVelocity:" << wasVelocity; -qDebug() << " now _sentVelocity:" << _sentVelocity; - -qDebug() << " was _sentPosition:" << wasPosition; -qDebug() << " now _sentPosition:" << _sentPosition; -qDebug() << " bullet position:" << position; - -qDebug() << " dx2:" << dx2; -qDebug() << " (dx2 > MAX_POSITION_ERROR_SQUARED)... considering"; - if (wasSentFrame > 0) { -qDebug() << " (wasSentFrame > 0)... return TRUE"; - return true; - } else { -qDebug() << " (wasSentFrame == 0)... ignore use bullet position for next _sentPosition"; - _sentPosition = position; - } - } else { - //qDebug() << " (dx2 <= MAX_POSITION_ERROR_SQUARED)... FALL THROUGH... likely return false"; + return true; } if (glm::length2(_sentAngularVelocity) > 0.0f) { diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 58253d1bd4..7f2b139058 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -35,9 +35,6 @@ void PhysicsEngine::updateEntitiesInternal(const quint64& now) { // (3) synchronize outgoing motion states // (4) send outgoing packets - - //qDebug() << "_numSubsteps:" << _numSubsteps; - // this is step (4) QSet::iterator stateItr = _outgoingPackets.begin(); while (stateItr != _outgoingPackets.end()) { From c6ad1462e603a71af72727cdea5c112a80b25784 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 22 Jan 2015 13:31:59 -0800 Subject: [PATCH 15/19] debugging stutter --- libraries/physics/src/EntityMotionState.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 9453501407..9be8a8f50e 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -160,10 +160,12 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ } if (_outgoingPacketFlags) { EntityItemProperties properties = _entity->getProperties(); + if (_outgoingPacketFlags & EntityItem::DIRTY_POSITION) { btTransform worldTrans = _body->getWorldTransform(); _sentPosition = bulletToGLM(worldTrans.getOrigin()); properties.setPosition(_sentPosition + ObjectMotionState::getWorldOffset()); + _sentRotation = bulletToGLM(worldTrans.getRotation()); properties.setRotation(_sentRotation); } From 6a9a6968f2ec0e33fbcff24e7f1ddeff5e2db220 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 22 Jan 2015 13:32:57 -0800 Subject: [PATCH 16/19] debugging stutter --- libraries/physics/src/EntityMotionState.cpp | 2 +- libraries/physics/src/ObjectMotionState.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 9be8a8f50e..8b6fb1ea9f 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -165,7 +165,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ btTransform worldTrans = _body->getWorldTransform(); _sentPosition = bulletToGLM(worldTrans.getOrigin()); properties.setPosition(_sentPosition + ObjectMotionState::getWorldOffset()); - + _sentRotation = bulletToGLM(worldTrans.getRotation()); properties.setRotation(_sentRotation); } diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index effd7c3e4d..25910556ff 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -141,6 +141,7 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { // NOTE: math in done the simulation-frame, which is NOT necessarily the same as the world-frame // due to _worldOffset. + // compute position error if (glm::length2(_sentVelocity) > 0.0f) { _sentVelocity += _sentAcceleration * dt; From 162c2f031bd16d5e1a5c33b2397405d6c36463ae Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Thu, 22 Jan 2015 15:33:37 -0600 Subject: [PATCH 17/19] Remove https unneeded crust --- ice-server/CMakeLists.txt | 14 -------------- ice-server/src/IceServer.cpp | 7 +------ ice-server/src/IceServer.h | 4 +--- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/ice-server/CMakeLists.txt b/ice-server/CMakeLists.txt index a7b2a206e4..6a8ca5bd9f 100644 --- a/ice-server/CMakeLists.txt +++ b/ice-server/CMakeLists.txt @@ -6,18 +6,4 @@ setup_hifi_project(Network) # link the shared hifi libraries link_hifi_libraries(embedded-webserver networking shared) -# find OpenSSL -find_package(OpenSSL REQUIRED) - -if (APPLE AND ${OPENSSL_INCLUDE_DIR} STREQUAL "/usr/include") -# this is a user on OS X using system OpenSSL, which is going to throw warnings since they're deprecating for their common crypto -message(WARNING "The found version of OpenSSL is the OS X system version. This will produce deprecation warnings." -"\nWe recommend you install a newer version (at least 1.0.1h) in a different directory and set OPENSSL_ROOT_DIR in your env so Cmake can find it.") -endif () - -include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") - -# append OpenSSL to our list of libraries to link -target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBRARIES}) - include_dependency_includes() \ No newline at end of file diff --git a/ice-server/src/IceServer.cpp b/ice-server/src/IceServer.cpp index 531dd4ea22..4648656e87 100644 --- a/ice-server/src/IceServer.cpp +++ b/ice-server/src/IceServer.cpp @@ -27,8 +27,7 @@ IceServer::IceServer(int argc, char* argv[]) : _id(QUuid::createUuid()), _serverSocket(), _activePeers(), - _httpManager(ICE_SERVER_MONITORING_PORT, QString("%1/web/").arg(QCoreApplication::applicationDirPath()), this), - _httpsManager(NULL) + _httpManager(ICE_SERVER_MONITORING_PORT, QString("%1/web/").arg(QCoreApplication::applicationDirPath()), this) { // start the ice-server socket qDebug() << "ice-server socket is listening on" << ICE_SERVER_DEFAULT_PORT; @@ -195,7 +194,3 @@ bool IceServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, b } return true; } - -bool IceServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler) { - return true; -} diff --git a/ice-server/src/IceServer.h b/ice-server/src/IceServer.h index effc8b8154..5367786d01 100644 --- a/ice-server/src/IceServer.h +++ b/ice-server/src/IceServer.h @@ -21,12 +21,11 @@ typedef QHash NetworkPeerHash; -class IceServer : public QCoreApplication, public HTTPSRequestHandler { +class IceServer : public QCoreApplication, public HTTPRequestHandler { Q_OBJECT public: IceServer(int argc, char* argv[]); bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false); - bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url, bool skipSubHandler = false); private slots: void processDatagrams(); void clearInactivePeers(); @@ -39,7 +38,6 @@ private: NetworkPeerHash _activePeers; QHash > _currentConnections; HTTPManager _httpManager; - HTTPSManager* _httpsManager; }; #endif // hifi_IceServer_h \ No newline at end of file From d34764bd557c811e800b03894b9b9e2319006f5a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 22 Jan 2015 13:33:59 -0800 Subject: [PATCH 18/19] fix whitespace diff --- libraries/physics/src/ObjectMotionState.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index 25910556ff..03f4c47bfa 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -141,7 +141,7 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { // NOTE: math in done the simulation-frame, which is NOT necessarily the same as the world-frame // due to _worldOffset. - + // compute position error if (glm::length2(_sentVelocity) > 0.0f) { _sentVelocity += _sentAcceleration * dt; @@ -151,7 +151,7 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) { btTransform worldTrans = _body->getWorldTransform(); glm::vec3 position = bulletToGLM(worldTrans.getOrigin()); - + float dx2 = glm::distance2(position, _sentPosition); const float MAX_POSITION_ERROR_SQUARED = 0.001f; // 0.001 m^2 ~~> 0.03 m if (dx2 > MAX_POSITION_ERROR_SQUARED) { From 001d6896464cf0f6c3123f99c8b6308b816f96eb Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Thu, 22 Jan 2015 15:37:58 -0600 Subject: [PATCH 19/19] Fixing includes --- ice-server/src/IceServer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ice-server/src/IceServer.h b/ice-server/src/IceServer.h index 5367786d01..be6d298e3d 100644 --- a/ice-server/src/IceServer.h +++ b/ice-server/src/IceServer.h @@ -17,7 +17,8 @@ #include #include -#include +#include +#include typedef QHash NetworkPeerHash;