get Agent working with ScriptEngine

This commit is contained in:
ZappoMan 2013-12-17 14:13:16 -08:00
parent 43054ad893
commit 7b3a778fb4
4 changed files with 19 additions and 17 deletions
assignment-client/src
libraries
scriptengine/src
shared/src

View file

@ -24,8 +24,8 @@
Agent::Agent(const unsigned char* dataBuffer, int numBytes) :
ThreadedAssignment(dataBuffer, numBytes)
{
_particleScriptingInterface.init();
_voxelScriptingInterface.init();
//_particleScriptingInterface.init();
//_voxelScriptingInterface.init();
}
void Agent::processDatagram(const QByteArray& dataByteArray, const HifiSockAddr& senderSockAddr) {
@ -34,12 +34,12 @@ void Agent::processDatagram(const QByteArray& dataByteArray, const HifiSockAddr&
// PACKET_TYPE_JURISDICTION, first byte is the node type...
switch (dataByteArray[headerBytes]) {
case NODE_TYPE_VOXEL_SERVER:
_voxelScriptingInterface.getJurisdictionListener()->queueReceivedPacket(senderSockAddr,
_scriptEngine.getVoxelScriptingInterface()->getJurisdictionListener()->queueReceivedPacket(senderSockAddr,
(unsigned char*) dataByteArray.data(),
dataByteArray.size());
break;
case NODE_TYPE_PARTICLE_SERVER:
_particleScriptingInterface.getJurisdictionListener()->queueReceivedPacket(senderSockAddr,
_scriptEngine.getParticleScriptingInterface()->getJurisdictionListener()->queueReceivedPacket(senderSockAddr,
(unsigned char*) dataByteArray.data(),
dataByteArray.size());
break;
@ -94,10 +94,10 @@ void Agent::run() {
connect(pingNodesTimer, SIGNAL(timeout()), nodeList, SLOT(pingInactiveNodes()));
pingNodesTimer->start(PING_INACTIVE_NODE_INTERVAL_USECS / 1000);
const unsigned int VISUAL_DATA_CALLBACK_USECS = (1.0 / 60.0) * 1000 * 1000;
//const unsigned int VISUAL_DATA_CALLBACK_USECS = (1.0 / 60.0) * 1000 * 1000;
// let the VoxelPacketSender know how frequently we plan to call it
_voxelScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS);
_particleScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS);
//_voxelScriptingInterface.getVoxelPacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS);
//_particleScriptingInterface.getParticlePacketSender()->setProcessCallIntervalHint(VISUAL_DATA_CALLBACK_USECS);
_scriptEngine.setScriptContents(scriptContents);

View file

@ -34,8 +34,8 @@ signals:
void willSendAudioDataCallback();
void willSendVisualDataCallback();
private:
VoxelScriptingInterface _voxelScriptingInterface;
ParticleScriptingInterface _particleScriptingInterface;
//VoxelScriptingInterface _voxelScriptingInterface;
//ParticleScriptingInterface _particleScriptingInterface;
ScriptEngine _scriptEngine;
};

View file

@ -116,16 +116,14 @@ void ScriptEngine::run() {
if (usecToSleep > 0) {
usleep(usecToSleep);
}
if (_isFinished) {
//qDebug() << "line: " << __LINE__ << " _isFinished... breaking loop\n";
break;
}
QCoreApplication::processEvents();
if (_isFinished) {
//qDebug() << "line: " << __LINE__ << " _isFinished... breaking loop\n";
break;
}
@ -138,7 +136,9 @@ void ScriptEngine::run() {
_voxelScriptingInterface.getVoxelPacketSender()->releaseQueuedMessages();
// since we're in non-threaded mode, call process so that the packets are sent
//_voxelScriptingInterface.getVoxelPacketSender()->process();
if (!_voxelScriptingInterface.getVoxelPacketSender()->isThreaded()) {
_voxelScriptingInterface.getVoxelPacketSender()->process();
}
}
if (_particleScriptingInterface.getParticlePacketSender()->serversExist()) {
@ -149,14 +149,15 @@ void ScriptEngine::run() {
_particleScriptingInterface.getParticlePacketSender()->releaseQueuedMessages();
// since we're in non-threaded mode, call process so that the packets are sent
//_particleScriptingInterface.getParticlePacketSender()->process();
if (!_particleScriptingInterface.getParticlePacketSender()->isThreaded()) {
_particleScriptingInterface.getParticlePacketSender()->process();
}
}
if (willSendVisualDataCallBack) {
emit willSendVisualDataCallback();
}
if (engine.hasUncaughtException()) {
int line = engine.uncaughtExceptionLineNumber();
qDebug() << "Uncaught exception at line" << line << ":" << engine.uncaughtException().toString() << "\n";
@ -177,3 +178,4 @@ void ScriptEngine::stop() {
_isFinished = true;
}

View file

@ -33,6 +33,8 @@ public:
/// Override this function to do whatever your class actually does, return false to exit thread early.
virtual bool process() = 0;
bool isThreaded() const { return _isThreaded; }
protected:
/// Locks all the resources of the thread.
@ -43,8 +45,6 @@ protected:
bool isStillRunning() const { return !_stopThread; }
bool isThreaded() const { return _isThreaded; }
private:
pthread_mutex_t _mutex;