mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 04:03:59 +02:00
remove ParticleEditHandle, and change ParticleCollisionSystem to use new particle edit API
This commit is contained in:
parent
135f96a18c
commit
9231c1d80a
6 changed files with 31 additions and 184 deletions
|
@ -136,6 +136,9 @@ public:
|
|||
ParticleID(uint32_t id, uint32_t creatorTokenID, bool isKnownID) :
|
||||
id(id), creatorTokenID(creatorTokenID), isKnownID(isKnownID) { };
|
||||
|
||||
ParticleID(uint32_t id) :
|
||||
id(id), creatorTokenID(UNKNOWN_TOKEN), isKnownID(true) { };
|
||||
|
||||
uint32_t id;
|
||||
uint32_t creatorTokenID;
|
||||
bool isKnownID;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "Particle.h"
|
||||
#include "ParticleCollisionSystem.h"
|
||||
#include "ParticleEditHandle.h"
|
||||
#include "ParticleEditPacketSender.h"
|
||||
#include "ParticleTree.h"
|
||||
|
||||
|
@ -117,19 +116,23 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particleA)
|
|||
float massB = (particleB->getInHand()) ? MAX_MASS : particleB->getMass();
|
||||
float totalMass = massA + massB;
|
||||
|
||||
// handle A particle
|
||||
particleA->setVelocity(particleA->getVelocity() - axialVelocity * (2.0f * massB / totalMass));
|
||||
ParticleProperties propertiesA;
|
||||
ParticleID particleAid(particleA->getID());
|
||||
propertiesA.copyFromParticle(*particleA);
|
||||
propertiesA.setVelocity(particleA->getVelocity() * (float)TREE_SCALE);
|
||||
_packetSender->queueParticleEditMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleAid, propertiesA);
|
||||
|
||||
ParticleEditHandle particleEditHandle(_packetSender, _particles, particleA->getID());
|
||||
particleEditHandle.updateParticle(particleA->getPosition(), particleA->getRadius(), particleA->getXColor(),
|
||||
particleA->getVelocity(), particleA->getGravity(), particleA->getDamping(), particleA->getLifetime(),
|
||||
particleA->getInHand(), particleA->getScript());
|
||||
|
||||
// handle B particle
|
||||
particleB->setVelocity(particleB->getVelocity() + axialVelocity * (2.0f * massA / totalMass));
|
||||
ParticleProperties propertiesB;
|
||||
ParticleID particleBid(particleB->getID());
|
||||
propertiesB.copyFromParticle(*particleB);
|
||||
propertiesB.setVelocity(particleB->getVelocity() * (float)TREE_SCALE);
|
||||
_packetSender->queueParticleEditMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleBid, propertiesB);
|
||||
|
||||
ParticleEditHandle penetratedparticleEditHandle(_packetSender, _particles, particleB->getID());
|
||||
penetratedparticleEditHandle.updateParticle(particleB->getPosition(), particleB->getRadius(),
|
||||
particleB->getXColor(), particleB->getVelocity(), particleB->getGravity(), particleB->getDamping(),
|
||||
particleB->getLifetime(), particleB->getInHand(), particleB->getScript());
|
||||
_packetSender->releaseQueuedMessages();
|
||||
|
||||
penetration /= (float)(TREE_SCALE);
|
||||
updateCollisionSound(particleA, penetration, COLLISION_FREQUENCY);
|
||||
|
@ -256,10 +259,17 @@ void ParticleCollisionSystem::applyHardCollision(Particle* particle, float elast
|
|||
particle->getID(), velocity.x, velocity.y, velocity.z, debug::valueOf(particle->getInHand()));
|
||||
}
|
||||
|
||||
ParticleEditHandle particleEditHandle(_packetSender, _particles, particle->getID());
|
||||
particleEditHandle.updateParticle(position, particle->getRadius(), particle->getXColor(), velocity,
|
||||
particle->getGravity(), particle->getDamping(), particle->getLifetime(),
|
||||
particle->getInHand(), particle->getScript());
|
||||
// send off the result to the particle server
|
||||
ParticleProperties properties;
|
||||
ParticleID particleID(particle->getID());
|
||||
properties.copyFromParticle(*particle);
|
||||
properties.setPosition(position * (float)TREE_SCALE);
|
||||
properties.setVelocity(velocity * (float)TREE_SCALE);
|
||||
_packetSender->queueParticleEditMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, particleID, properties);
|
||||
|
||||
// change the local particle too...
|
||||
particle->setPosition(position);
|
||||
particle->setVelocity(velocity);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
//
|
||||
// ParticleEditHandle.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/4/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
//
|
||||
|
||||
#include "Particle.h"
|
||||
#include "ParticleEditHandle.h"
|
||||
#include "ParticleEditPacketSender.h"
|
||||
#include "ParticleTree.h"
|
||||
|
||||
std::map<uint32_t,ParticleEditHandle*> ParticleEditHandle::_allHandles;
|
||||
|
||||
ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree, uint32_t id) {
|
||||
if (id == NEW_PARTICLE) {
|
||||
_creatorTokenID = Particle::getNextCreatorTokenID();
|
||||
_id = NEW_PARTICLE;
|
||||
_isKnownID = false;
|
||||
_allHandles[_creatorTokenID] = this;
|
||||
} else {
|
||||
_creatorTokenID = UNKNOWN_TOKEN;
|
||||
_id = id;
|
||||
_isKnownID = true;
|
||||
// don't add to _allHandles because we already know it...
|
||||
}
|
||||
_packetSender = packetSender;
|
||||
_localTree = localTree;
|
||||
|
||||
}
|
||||
|
||||
ParticleEditHandle::~ParticleEditHandle() {
|
||||
// remove us from our _allHandles map
|
||||
if (_creatorTokenID != UNKNOWN_TOKEN) {
|
||||
_allHandles.erase(_allHandles.find(_creatorTokenID));
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleEditHandle::createParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity,
|
||||
glm::vec3 gravity, float damping, float lifetime, bool inHand, QString updateScript) {
|
||||
|
||||
// setup a ParticleDetail struct with the data
|
||||
/****
|
||||
uint64_t now = usecTimestampNow();
|
||||
ParticleDetail addParticleDetail = { NEW_PARTICLE, now,
|
||||
position, radius, {color.red, color.green, color.blue },
|
||||
velocity, gravity, damping, lifetime, inHand, updateScript, _creatorTokenID };
|
||||
|
||||
// queue the packet
|
||||
_packetSender->queueParticleEditMessage(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, 1, &addParticleDetail);
|
||||
|
||||
// release them
|
||||
_packetSender->releaseQueuedMessages();
|
||||
|
||||
// if we have a local tree, also update it...
|
||||
if (_localTree) {
|
||||
// we can't really do this here, because if we create a particle locally, we'll get a ghost particle
|
||||
// because we can't really handle updating/deleting it locally
|
||||
}
|
||||
****/
|
||||
|
||||
}
|
||||
|
||||
bool ParticleEditHandle::updateParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity,
|
||||
glm::vec3 gravity, float damping, float lifetime, bool inHand, QString updateScript) {
|
||||
|
||||
if (!isKnownID()) {
|
||||
return false; // not allowed until we know the id
|
||||
}
|
||||
|
||||
// setup a ParticleDetail struct with the data
|
||||
/****
|
||||
uint64_t now = usecTimestampNow();
|
||||
ParticleDetail newParticleDetail = { _id, now,
|
||||
position, radius, {color.red, color.green, color.blue },
|
||||
velocity, gravity, damping, lifetime, inHand, updateScript, _creatorTokenID };
|
||||
|
||||
// queue the packet
|
||||
_packetSender->queueParticleEditMessages(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, 1, &newParticleDetail);
|
||||
|
||||
// release them
|
||||
_packetSender->releaseQueuedMessages();
|
||||
|
||||
// if we have a local tree, also update it...
|
||||
if (_localTree) {
|
||||
rgbColor rcolor = {color.red, color.green, color.blue };
|
||||
Particle tempParticle(position, radius, rcolor, velocity, gravity, damping, lifetime, inHand, updateScript, _id);
|
||||
_localTree->storeParticle(tempParticle);
|
||||
}
|
||||
***/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ParticleEditHandle::handleAddResponse(unsigned char* packetData , int packetLength) {
|
||||
unsigned char* dataAt = packetData;
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
||||
dataAt += numBytesPacketHeader;
|
||||
|
||||
uint32_t creatorTokenID;
|
||||
memcpy(&creatorTokenID, dataAt, sizeof(creatorTokenID));
|
||||
dataAt += sizeof(creatorTokenID);
|
||||
|
||||
uint32_t particleID;
|
||||
memcpy(&particleID, dataAt, sizeof(particleID));
|
||||
dataAt += sizeof(particleID);
|
||||
|
||||
// find this particle in the _allHandles map
|
||||
if (_allHandles.find(creatorTokenID) != _allHandles.end()) {
|
||||
ParticleEditHandle* theHandle = _allHandles[creatorTokenID];
|
||||
theHandle->_id = particleID;
|
||||
theHandle->_isKnownID = true;
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
//
|
||||
// ParticleEditHandle.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/4/13.
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef __hifi__ParticleEditHandle__
|
||||
#define __hifi__ParticleEditHandle__
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
#include <OctreePacketData.h>
|
||||
|
||||
#include "Particle.h"
|
||||
|
||||
class ParticleEditPacketSender;
|
||||
class ParticleTree;
|
||||
|
||||
class ParticleEditHandle {
|
||||
public:
|
||||
ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree, uint32_t id = NEW_PARTICLE);
|
||||
~ParticleEditHandle();
|
||||
|
||||
uint32_t getCreatorTokenID() const { return _creatorTokenID; }
|
||||
uint32_t getID() const { return _id; }
|
||||
|
||||
bool isKnownID() const { return _isKnownID; }
|
||||
|
||||
void createParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity,
|
||||
glm::vec3 gravity, float damping, float lifetime, bool inHand, QString updateScript);
|
||||
|
||||
bool updateParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity,
|
||||
glm::vec3 gravity, float damping, float lifetime, bool inHand, QString updateScript);
|
||||
|
||||
static void handleAddResponse(unsigned char* packetData , int packetLength);
|
||||
private:
|
||||
uint32_t _creatorTokenID;
|
||||
uint32_t _id;
|
||||
bool _isKnownID;
|
||||
static std::map<uint32_t,ParticleEditHandle*> _allHandles;
|
||||
ParticleEditPacketSender* _packetSender;
|
||||
ParticleTree* _localTree;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__ParticleEditHandle__) */
|
|
@ -42,7 +42,8 @@ void ParticleEditPacketSender::adjustEditPacketForClockSkew(unsigned char* codeC
|
|||
}
|
||||
|
||||
|
||||
void ParticleEditPacketSender::queueParticleEditMessage(PACKET_TYPE type, ParticleID particleID, const ParticleProperties& properties) {
|
||||
void ParticleEditPacketSender::queueParticleEditMessage(PACKET_TYPE type, ParticleID particleID,
|
||||
const ParticleProperties& properties) {
|
||||
if (!_shouldSend) {
|
||||
return; // bail early
|
||||
}
|
||||
|
|
|
@ -21,11 +21,13 @@ public:
|
|||
~ParticleEditPacketSender() { }
|
||||
|
||||
/// Send particle add message immediately
|
||||
/// NOTE: ParticleProperties assumes that all distances are in meter units
|
||||
void sendEditParticleMessage(PACKET_TYPE type, ParticleID particleID, const ParticleProperties& properties);
|
||||
|
||||
/// Queues an array of several voxel edit messages. Will potentially send a pending multi-command packet. Determines
|
||||
/// which voxel-server node or nodes the packet should be sent to. Can be called even before voxel servers are known, in
|
||||
/// which case up to MaxPendingMessages will be buffered and processed when voxel servers are known.
|
||||
/// NOTE: ParticleProperties assumes that all distances are in meter units
|
||||
void queueParticleEditMessage(PACKET_TYPE type, ParticleID particleID, const ParticleProperties& properties);
|
||||
|
||||
// My server type is the particle server
|
||||
|
|
Loading…
Reference in a new issue