mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
implement OctreeScriptingInterface base class to share common behavior for particle and voxel scripting
This commit is contained in:
parent
e2fbb7beb4
commit
c2d5accbc9
9 changed files with 164 additions and 180 deletions
|
@ -25,6 +25,7 @@ Agent::Agent(const unsigned char* dataBuffer, int numBytes) :
|
|||
ThreadedAssignment(dataBuffer, numBytes)
|
||||
{
|
||||
_particleScriptingInterface.init();
|
||||
_voxelScriptingInterface.init();
|
||||
}
|
||||
|
||||
void Agent::processDatagram(const QByteArray& dataByteArray, const HifiSockAddr& senderSockAddr) {
|
||||
|
|
51
libraries/octree/src/OctreeScriptingInterface.cpp
Normal file
51
libraries/octree/src/OctreeScriptingInterface.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// OctreeScriptingInterface.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/6/13
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "OctreeScriptingInterface.h"
|
||||
|
||||
OctreeScriptingInterface::OctreeScriptingInterface(OctreeEditPacketSender* packetSender,
|
||||
JurisdictionListener* jurisdictionListener)
|
||||
{
|
||||
setPacketSender(packetSender);
|
||||
setJurisdictionListener(jurisdictionListener);
|
||||
}
|
||||
|
||||
OctreeScriptingInterface::~OctreeScriptingInterface() {
|
||||
if (_managedJuridiciontListerner) {
|
||||
delete _jurisdictionListener;
|
||||
}
|
||||
if (_managedPacketSender) {
|
||||
delete _packetSender;
|
||||
}
|
||||
}
|
||||
|
||||
void OctreeScriptingInterface::setPacketSender(OctreeEditPacketSender* packetSender) {
|
||||
_packetSender = packetSender;
|
||||
}
|
||||
|
||||
void OctreeScriptingInterface::setJurisdictionListener(JurisdictionListener* jurisdictionListener) {
|
||||
_jurisdictionListener = jurisdictionListener;
|
||||
}
|
||||
|
||||
void OctreeScriptingInterface::init() {
|
||||
if (_jurisdictionListener) {
|
||||
_managedJuridiciontListerner = false;
|
||||
} else {
|
||||
_managedJuridiciontListerner = true;
|
||||
_jurisdictionListener = new JurisdictionListener(getServerNodeType());
|
||||
_jurisdictionListener->initialize(true);
|
||||
}
|
||||
|
||||
if (_packetSender) {
|
||||
_managedPacketSender = false;
|
||||
} else {
|
||||
_managedPacketSender = true;
|
||||
_packetSender = createPacketSender();
|
||||
_packetSender->setServerJurisdictions(_jurisdictionListener->getJurisdictions());
|
||||
}
|
||||
}
|
95
libraries/octree/src/OctreeScriptingInterface.h
Normal file
95
libraries/octree/src/OctreeScriptingInterface.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
//
|
||||
// OctreeScriptingInterface.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/6/13
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__OctreeScriptingInterface__
|
||||
#define __hifi__OctreeScriptingInterface__
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "JurisdictionListener.h"
|
||||
#include "OctreeEditPacketSender.h"
|
||||
|
||||
/// handles scripting of Particle commands from JS passed to assigned clients
|
||||
class OctreeScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
OctreeScriptingInterface(OctreeEditPacketSender* packetSender = NULL,
|
||||
JurisdictionListener* jurisdictionListener = NULL);
|
||||
|
||||
~OctreeScriptingInterface();
|
||||
|
||||
OctreeEditPacketSender* getPacketSender() const { return _packetSender; }
|
||||
JurisdictionListener* getJurisdictionListener() const { return _jurisdictionListener; }
|
||||
void setPacketSender(OctreeEditPacketSender* packetSender);
|
||||
void setJurisdictionListener(JurisdictionListener* jurisdictionListener);
|
||||
void init();
|
||||
|
||||
virtual NODE_TYPE getServerNodeType() const = 0;
|
||||
virtual OctreeEditPacketSender* createPacketSender() = 0;
|
||||
|
||||
public slots:
|
||||
/// Set the desired max packet size in bytes that should be created
|
||||
void setMaxPacketSize(int maxPacketSize) { return _packetSender->setMaxPacketSize(maxPacketSize); }
|
||||
|
||||
/// returns the current desired max packet size in bytes that will be created
|
||||
int getMaxPacketSize() const { return _packetSender->getMaxPacketSize(); }
|
||||
|
||||
/// set the max packets per second send rate
|
||||
void setPacketsPerSecond(int packetsPerSecond) { return _packetSender->setPacketsPerSecond(packetsPerSecond); }
|
||||
|
||||
/// get the max packets per second send rate
|
||||
int getPacketsPerSecond() const { return _packetSender->getPacketsPerSecond(); }
|
||||
|
||||
/// does a particle server exist to send to
|
||||
bool serversExist() const { return _packetSender->serversExist(); }
|
||||
|
||||
/// are there packets waiting in the send queue to be sent
|
||||
bool hasPacketsToSend() const { return _packetSender->hasPacketsToSend(); }
|
||||
|
||||
/// how many packets are there in the send queue waiting to be sent
|
||||
int packetsToSendCount() const { return _packetSender->packetsToSendCount(); }
|
||||
|
||||
/// returns the packets per second send rate of this object over its lifetime
|
||||
float getLifetimePPS() const { return _packetSender->getLifetimePPS(); }
|
||||
|
||||
/// returns the bytes per second send rate of this object over its lifetime
|
||||
float getLifetimeBPS() const { return _packetSender->getLifetimeBPS(); }
|
||||
|
||||
/// returns the packets per second queued rate of this object over its lifetime
|
||||
float getLifetimePPSQueued() const { return _packetSender->getLifetimePPSQueued(); }
|
||||
|
||||
/// returns the bytes per second queued rate of this object over its lifetime
|
||||
float getLifetimeBPSQueued() const { return _packetSender->getLifetimeBPSQueued(); }
|
||||
|
||||
/// returns lifetime of this object from first packet sent to now in usecs
|
||||
long long unsigned int getLifetimeInUsecs() const { return _packetSender->getLifetimeInUsecs(); }
|
||||
|
||||
/// returns lifetime of this object from first packet sent to now in usecs
|
||||
float getLifetimeInSeconds() const { return _packetSender->getLifetimeInSeconds(); }
|
||||
|
||||
/// returns the total packets sent by this object over its lifetime
|
||||
long long unsigned int getLifetimePacketsSent() const { return _packetSender->getLifetimePacketsSent(); }
|
||||
|
||||
/// returns the total bytes sent by this object over its lifetime
|
||||
long long unsigned int getLifetimeBytesSent() const { return _packetSender->getLifetimeBytesSent(); }
|
||||
|
||||
/// returns the total packets queued by this object over its lifetime
|
||||
long long unsigned int getLifetimePacketsQueued() const { return _packetSender->getLifetimePacketsQueued(); }
|
||||
|
||||
/// returns the total bytes queued by this object over its lifetime
|
||||
long long unsigned int getLifetimeBytesQueued() const { return _packetSender->getLifetimeBytesQueued(); }
|
||||
|
||||
protected:
|
||||
/// attached OctreeEditPacketSender that handles queuing and sending of packets to VS
|
||||
OctreeEditPacketSender* _packetSender;
|
||||
JurisdictionListener* _jurisdictionListener;
|
||||
bool _managedPacketSender;
|
||||
bool _managedJuridiciontListerner;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__OctreeScriptingInterface__) */
|
|
@ -15,7 +15,7 @@
|
|||
#include "Particle.h"
|
||||
|
||||
/// Utility for processing, packing, queueing and sending of outbound edit voxel messages.
|
||||
class ParticleEditPacketSender : public virtual OctreeEditPacketSender {
|
||||
class ParticleEditPacketSender : public OctreeEditPacketSender {
|
||||
public:
|
||||
ParticleEditPacketSender(PacketSenderNotify* notify = NULL) : OctreeEditPacketSender(notify) { }
|
||||
~ParticleEditPacketSender() { }
|
||||
|
|
|
@ -8,53 +8,10 @@
|
|||
|
||||
#include "ParticleScriptingInterface.h"
|
||||
|
||||
ParticleScriptingInterface::ParticleScriptingInterface(ParticleEditPacketSender* particleSender,
|
||||
JurisdictionListener* particleJurisdictionListener) :
|
||||
_nextCreatorTokenID(0)
|
||||
{
|
||||
setParticlePacketSender(particleSender);
|
||||
setJurisdictionListener(particleJurisdictionListener);
|
||||
}
|
||||
|
||||
ParticleScriptingInterface::~ParticleScriptingInterface() {
|
||||
if (_managedJuridiciontListerner) {
|
||||
delete _jurisdictionListener;
|
||||
}
|
||||
if (_managedPacketSender) {
|
||||
delete _particlePacketSender;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ParticleScriptingInterface::setParticlePacketSender(ParticleEditPacketSender* particlePacketSender) {
|
||||
_particlePacketSender = particlePacketSender;
|
||||
}
|
||||
|
||||
void ParticleScriptingInterface::setJurisdictionListener(JurisdictionListener* jurisdictionListener) {
|
||||
_jurisdictionListener = jurisdictionListener;
|
||||
}
|
||||
|
||||
void ParticleScriptingInterface::init() {
|
||||
if (_jurisdictionListener) {
|
||||
_managedJuridiciontListerner = false;
|
||||
} else {
|
||||
_managedJuridiciontListerner = true;
|
||||
_jurisdictionListener = new JurisdictionListener(NODE_TYPE_PARTICLE_SERVER);
|
||||
_jurisdictionListener->initialize(true);
|
||||
}
|
||||
|
||||
if (_particlePacketSender) {
|
||||
_managedPacketSender = false;
|
||||
} else {
|
||||
_managedPacketSender = true;
|
||||
_particlePacketSender = new ParticleEditPacketSender();
|
||||
_particlePacketSender->setServerJurisdictions(_jurisdictionListener->getJurisdictions());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ParticleScriptingInterface::queueParticleAdd(PACKET_TYPE addPacketType, ParticleDetail& addParticleDetails) {
|
||||
_particlePacketSender->queueParticleEditMessages(addPacketType, 1, &addParticleDetails);
|
||||
getParticlePacketSender()->queueParticleEditMessages(addPacketType, 1, &addParticleDetails);
|
||||
}
|
||||
|
||||
unsigned int ParticleScriptingInterface::queueParticleAdd(glm::vec3 position, float radius,
|
||||
|
|
|
@ -12,86 +12,24 @@
|
|||
#include <QtCore/QObject>
|
||||
|
||||
#include <JurisdictionListener.h>
|
||||
#include <OctreeScriptingInterface.h>
|
||||
#include "ParticleEditPacketSender.h"
|
||||
|
||||
/// handles scripting of Particle commands from JS passed to assigned clients
|
||||
class ParticleScriptingInterface : public QObject {
|
||||
class ParticleScriptingInterface : public OctreeScriptingInterface {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParticleScriptingInterface(ParticleEditPacketSender* particleSender = NULL,
|
||||
JurisdictionListener* particleJurisdictionListener = NULL);
|
||||
ParticleEditPacketSender* getParticlePacketSender() const { return (ParticleEditPacketSender*)getPacketSender(); }
|
||||
virtual NODE_TYPE getServerNodeType() const { return NODE_TYPE_PARTICLE_SERVER; }
|
||||
virtual OctreeEditPacketSender* createPacketSender() { return new ParticleEditPacketSender(); }
|
||||
|
||||
~ParticleScriptingInterface();
|
||||
|
||||
ParticleEditPacketSender* getParticlePacketSender() const { return _particlePacketSender; }
|
||||
JurisdictionListener* getJurisdictionListener() const { return _jurisdictionListener; }
|
||||
void setParticlePacketSender(ParticleEditPacketSender* particlePacketSender);
|
||||
void setJurisdictionListener(JurisdictionListener* jurisdictionListener);
|
||||
void init();
|
||||
public slots:
|
||||
/// queues the creation of a Particle which will be sent by calling process on the PacketSender
|
||||
/// returns the creatorTokenID for the newly created particle
|
||||
unsigned int queueParticleAdd(glm::vec3 position, float radius,
|
||||
xColor color, glm::vec3 velocity, glm::vec3 gravity, float damping, QString updateScript);
|
||||
|
||||
/// Set the desired max packet size in bytes that should be created
|
||||
void setMaxPacketSize(int maxPacketSize) { return _particlePacketSender->setMaxPacketSize(maxPacketSize); }
|
||||
|
||||
/// returns the current desired max packet size in bytes that will be created
|
||||
int getMaxPacketSize() const { return _particlePacketSender->getMaxPacketSize(); }
|
||||
|
||||
/// set the max packets per second send rate
|
||||
void setPacketsPerSecond(int packetsPerSecond) { return _particlePacketSender->setPacketsPerSecond(packetsPerSecond); }
|
||||
|
||||
/// get the max packets per second send rate
|
||||
int getPacketsPerSecond() const { return _particlePacketSender->getPacketsPerSecond(); }
|
||||
|
||||
/// does a particle server exist to send to
|
||||
bool serversExist() const { return _particlePacketSender->serversExist(); }
|
||||
|
||||
/// are there packets waiting in the send queue to be sent
|
||||
bool hasPacketsToSend() const { return _particlePacketSender->hasPacketsToSend(); }
|
||||
|
||||
/// how many packets are there in the send queue waiting to be sent
|
||||
int packetsToSendCount() const { return _particlePacketSender->packetsToSendCount(); }
|
||||
|
||||
/// returns the packets per second send rate of this object over its lifetime
|
||||
float getLifetimePPS() const { return _particlePacketSender->getLifetimePPS(); }
|
||||
|
||||
/// returns the bytes per second send rate of this object over its lifetime
|
||||
float getLifetimeBPS() const { return _particlePacketSender->getLifetimeBPS(); }
|
||||
|
||||
/// returns the packets per second queued rate of this object over its lifetime
|
||||
float getLifetimePPSQueued() const { return _particlePacketSender->getLifetimePPSQueued(); }
|
||||
|
||||
/// returns the bytes per second queued rate of this object over its lifetime
|
||||
float getLifetimeBPSQueued() const { return _particlePacketSender->getLifetimeBPSQueued(); }
|
||||
|
||||
/// returns lifetime of this object from first packet sent to now in usecs
|
||||
long long unsigned int getLifetimeInUsecs() const { return _particlePacketSender->getLifetimeInUsecs(); }
|
||||
|
||||
/// returns lifetime of this object from first packet sent to now in usecs
|
||||
float getLifetimeInSeconds() const { return _particlePacketSender->getLifetimeInSeconds(); }
|
||||
|
||||
/// returns the total packets sent by this object over its lifetime
|
||||
long long unsigned int getLifetimePacketsSent() const { return _particlePacketSender->getLifetimePacketsSent(); }
|
||||
|
||||
/// returns the total bytes sent by this object over its lifetime
|
||||
long long unsigned int getLifetimeBytesSent() const { return _particlePacketSender->getLifetimeBytesSent(); }
|
||||
|
||||
/// returns the total packets queued by this object over its lifetime
|
||||
long long unsigned int getLifetimePacketsQueued() const { return _particlePacketSender->getLifetimePacketsQueued(); }
|
||||
|
||||
/// returns the total bytes queued by this object over its lifetime
|
||||
long long unsigned int getLifetimeBytesQueued() const { return _particlePacketSender->getLifetimeBytesQueued(); }
|
||||
|
||||
private:
|
||||
/// attached ParticleEditPacketSender that handles queuing and sending of packets to VS
|
||||
ParticleEditPacketSender* _particlePacketSender;
|
||||
JurisdictionListener* _jurisdictionListener;
|
||||
bool _managedPacketSender;
|
||||
bool _managedJuridiciontListerner;
|
||||
|
||||
void queueParticleAdd(PACKET_TYPE addPacketType, ParticleDetail& addParticleDetails);
|
||||
|
||||
uint32_t _nextCreatorTokenID;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <OctreeEditPacketSender.h>
|
||||
|
||||
/// Utility for processing, packing, queueing and sending of outbound edit voxel messages.
|
||||
class VoxelEditPacketSender : public virtual OctreeEditPacketSender {
|
||||
class VoxelEditPacketSender : public OctreeEditPacketSender {
|
||||
public:
|
||||
VoxelEditPacketSender(PacketSenderNotify* notify = NULL) : OctreeEditPacketSender(notify) { }
|
||||
~VoxelEditPacketSender() { }
|
||||
|
|
|
@ -8,13 +8,8 @@
|
|||
|
||||
#include "VoxelScriptingInterface.h"
|
||||
|
||||
VoxelScriptingInterface::VoxelScriptingInterface() {
|
||||
_jurisdictionListener.initialize(true);
|
||||
_voxelPacketSender.setVoxelServerJurisdictions(_jurisdictionListener.getJurisdictions());
|
||||
}
|
||||
|
||||
void VoxelScriptingInterface::queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails) {
|
||||
_voxelPacketSender.queueVoxelEditMessages(addPacketType, 1, &addVoxelDetails);
|
||||
getVoxelPacketSender()->queueVoxelEditMessages(addPacketType, 1, &addVoxelDetails);
|
||||
}
|
||||
|
||||
void VoxelScriptingInterface::queueVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) {
|
||||
|
@ -39,6 +34,6 @@ void VoxelScriptingInterface::queueVoxelDelete(float x, float y, float z, float
|
|||
// setup a VoxelDetail struct with data
|
||||
VoxelDetail deleteVoxelDetail = {x, y, z, scale, 0, 0, 0};
|
||||
|
||||
_voxelPacketSender.queueVoxelEditMessages(PACKET_TYPE_VOXEL_ERASE, 1, &deleteVoxelDetail);
|
||||
getVoxelPacketSender()->queueVoxelEditMessages(PACKET_TYPE_VOXEL_ERASE, 1, &deleteVoxelDetail);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,16 +12,18 @@
|
|||
#include <QtCore/QObject>
|
||||
|
||||
#include <JurisdictionListener.h>
|
||||
#include <OctreeScriptingInterface.h>
|
||||
#include "VoxelEditPacketSender.h"
|
||||
|
||||
/// handles scripting of voxel commands from JS passed to assigned clients
|
||||
class VoxelScriptingInterface : public QObject {
|
||||
class VoxelScriptingInterface : public OctreeScriptingInterface {
|
||||
Q_OBJECT
|
||||
public:
|
||||
VoxelScriptingInterface();
|
||||
|
||||
VoxelEditPacketSender* getVoxelPacketSender() { return &_voxelPacketSender; }
|
||||
JurisdictionListener* getJurisdictionListener() { return &_jurisdictionListener; }
|
||||
VoxelEditPacketSender* getVoxelPacketSender() { return (VoxelEditPacketSender*)getPacketSender(); }
|
||||
|
||||
virtual NODE_TYPE getServerNodeType() const { return NODE_TYPE_VOXEL_SERVER; }
|
||||
virtual OctreeEditPacketSender* createPacketSender() { return new VoxelEditPacketSender(); }
|
||||
|
||||
public slots:
|
||||
/// queues the creation of a voxel which will be sent by calling process on the PacketSender
|
||||
/// \param x the x-coordinate of the voxel (in VS space)
|
||||
|
@ -50,62 +52,7 @@ public slots:
|
|||
/// \param scale the scale of the voxel (in VS space)
|
||||
void queueVoxelDelete(float x, float y, float z, float scale);
|
||||
|
||||
/// Set the desired max packet size in bytes that should be created
|
||||
void setMaxPacketSize(int maxPacketSize) { return _voxelPacketSender.setMaxPacketSize(maxPacketSize); }
|
||||
|
||||
/// returns the current desired max packet size in bytes that will be created
|
||||
int getMaxPacketSize() const { return _voxelPacketSender.getMaxPacketSize(); }
|
||||
|
||||
/// set the max packets per second send rate
|
||||
void setPacketsPerSecond(int packetsPerSecond) { return _voxelPacketSender.setPacketsPerSecond(packetsPerSecond); }
|
||||
|
||||
/// get the max packets per second send rate
|
||||
int getPacketsPerSecond() const { return _voxelPacketSender.getPacketsPerSecond(); }
|
||||
|
||||
/// does a voxel server exist to send to
|
||||
bool voxelServersExist() const { return _voxelPacketSender.voxelServersExist(); }
|
||||
|
||||
/// are there packets waiting in the send queue to be sent
|
||||
bool hasPacketsToSend() const { return _voxelPacketSender.hasPacketsToSend(); }
|
||||
|
||||
/// how many packets are there in the send queue waiting to be sent
|
||||
int packetsToSendCount() const { return _voxelPacketSender.packetsToSendCount(); }
|
||||
|
||||
/// returns the packets per second send rate of this object over its lifetime
|
||||
float getLifetimePPS() const { return _voxelPacketSender.getLifetimePPS(); }
|
||||
|
||||
/// returns the bytes per second send rate of this object over its lifetime
|
||||
float getLifetimeBPS() const { return _voxelPacketSender.getLifetimeBPS(); }
|
||||
|
||||
/// returns the packets per second queued rate of this object over its lifetime
|
||||
float getLifetimePPSQueued() const { return _voxelPacketSender.getLifetimePPSQueued(); }
|
||||
|
||||
/// returns the bytes per second queued rate of this object over its lifetime
|
||||
float getLifetimeBPSQueued() const { return _voxelPacketSender.getLifetimeBPSQueued(); }
|
||||
|
||||
/// returns lifetime of this object from first packet sent to now in usecs
|
||||
long long unsigned int getLifetimeInUsecs() const { return _voxelPacketSender.getLifetimeInUsecs(); }
|
||||
|
||||
/// returns lifetime of this object from first packet sent to now in usecs
|
||||
float getLifetimeInSeconds() const { return _voxelPacketSender.getLifetimeInSeconds(); }
|
||||
|
||||
/// returns the total packets sent by this object over its lifetime
|
||||
long long unsigned int getLifetimePacketsSent() const { return _voxelPacketSender.getLifetimePacketsSent(); }
|
||||
|
||||
/// returns the total bytes sent by this object over its lifetime
|
||||
long long unsigned int getLifetimeBytesSent() const { return _voxelPacketSender.getLifetimeBytesSent(); }
|
||||
|
||||
/// returns the total packets queued by this object over its lifetime
|
||||
long long unsigned int getLifetimePacketsQueued() const { return _voxelPacketSender.getLifetimePacketsQueued(); }
|
||||
|
||||
/// returns the total bytes queued by this object over its lifetime
|
||||
long long unsigned int getLifetimeBytesQueued() const { return _voxelPacketSender.getLifetimeBytesQueued(); }
|
||||
|
||||
private:
|
||||
/// attached VoxelEditPacketSender that handles queuing and sending of packets to VS
|
||||
VoxelEditPacketSender _voxelPacketSender;
|
||||
JurisdictionListener _jurisdictionListener;
|
||||
|
||||
void queueVoxelAdd(PACKET_TYPE addPacketType, VoxelDetail& addVoxelDetails);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue