Revert "temporary removal of QtScript dependency for build on ec2 box"

This reverts commit f29f8701a1.
This commit is contained in:
Stephen Birarda 2013-09-04 16:22:51 -07:00
parent f29f8701a1
commit 609c48214f
3 changed files with 124 additions and 0 deletions

View file

@ -8,9 +8,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cm
set(TARGET_NAME avatars)
find_package(Qt5Script REQUIRED)
include(${MACRO_DIR}/SetupHifiLibrary.cmake)
setup_hifi_library(${TARGET_NAME})
qt5_use_modules(${TARGET_NAME} Script)
include(${MACRO_DIR}/IncludeGLM.cmake)
include_glm(${TARGET_NAME} ${ROOT_DIR})

View file

@ -0,0 +1,88 @@
//
// Agent.cpp
// hifi
//
// Created by Stephen Birarda on 7/1/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
//
#include <QtScript/QScriptEngine>
#include <QtNetwork/QtNetwork>
#include <NodeList.h>
#include "AvatarData.h"
#include "Agent.h"
Agent::Agent() :
_shouldStop(false)
{
}
void Agent::run(QUrl scriptURL) {
NodeList::getInstance()->setOwnerType(NODE_TYPE_AGENT);
NodeList::getInstance()->setNodeTypesOfInterest(&NODE_TYPE_AVATAR_MIXER, 1);
QNetworkAccessManager* manager = new QNetworkAccessManager();
qDebug() << "Attemping download of " << scriptURL;
QNetworkReply* reply = manager->get(QNetworkRequest(scriptURL));
QEventLoop loop;
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QString scriptString = QString(reply->readAll());
QScriptEngine engine;
AvatarData *testAvatarData = new AvatarData;
QScriptValue avatarDataValue = engine.newQObject(testAvatarData);
engine.globalObject().setProperty("Avatar", avatarDataValue);
QScriptValue agentValue = engine.newQObject(this);
engine.globalObject().setProperty("Agent", agentValue);
qDebug() << "Downloaded script:" << scriptString;
qDebug() << "Evaluated script:" << engine.evaluate(scriptString).toString();
timeval thisSend;
timeval lastDomainServerCheckIn = {};
int numMicrosecondsSleep = 0;
const float DATA_SEND_INTERVAL_USECS = (1 / 60.0f) * 1000 * 1000;
sockaddr_in senderAddress;
unsigned char receivedData[MAX_PACKET_SIZE];
ssize_t receivedBytes;
while (!_shouldStop) {
// update the thisSend timeval to the current time
gettimeofday(&thisSend, NULL);
// send a check in packet to the domain server if DOMAIN_SERVER_CHECK_IN_USECS has elapsed
if (usecTimestampNow() - usecTimestamp(&lastDomainServerCheckIn) >= DOMAIN_SERVER_CHECK_IN_USECS) {
gettimeofday(&lastDomainServerCheckIn, NULL);
NodeList::getInstance()->sendDomainServerCheckIn();
}
emit preSendCallback();
testAvatarData->sendData();
if (NodeList::getInstance()->getNodeSocket()->receive((sockaddr*) &senderAddress, receivedData, &receivedBytes)) {
NodeList::getInstance()->processNodeData((sockaddr*) &senderAddress, receivedData, receivedBytes);
}
// sleep for the correct amount of time to have data send be consistently timed
if ((numMicrosecondsSleep = DATA_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&thisSend))) > 0) {
usleep(numMicrosecondsSleep);
}
}
}

View file

@ -0,0 +1,32 @@
//
// Agent.h
// hifi
//
// Created by Stephen Birarda on 7/1/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
//
#ifndef __hifi__Agent__
#define __hifi__Agent__
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include "SharedUtil.h"
#include <QtCore/QObject>
#include <QtCore/QUrl>
class Agent : public QObject {
Q_OBJECT
public:
Agent();
bool volatile _shouldStop;
void run(QUrl scriptUrl);
signals:
void preSendCallback();
};
#endif /* defined(__hifi__Operative__) */