mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
more fleshing out of Agent class to interpret javascript
This commit is contained in:
parent
f8e7e1de66
commit
890d2e40ec
6 changed files with 89 additions and 12 deletions
|
@ -22,4 +22,4 @@ include(${MACRO_DIR}/LinkHifiLibrary.cmake)
|
|||
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
||||
|
||||
# link in the hifi voxels library
|
||||
link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR})
|
||||
link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR})
|
|
@ -9,11 +9,21 @@
|
|||
#import <QtScript/QScriptEngine>
|
||||
#import <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();
|
||||
|
||||
|
@ -29,10 +39,50 @@ void Agent::run(QUrl scriptURL) {
|
|||
|
||||
QScriptEngine engine;
|
||||
|
||||
AvatarData *someObject = new AvatarData;
|
||||
AvatarData *testAvatarData = new AvatarData;
|
||||
|
||||
QScriptValue objectValue = engine.newQObject(someObject);
|
||||
engine.globalObject().setProperty("AvatarData", objectValue);
|
||||
QScriptValue avatarDataValue = engine.newQObject(testAvatarData);
|
||||
engine.globalObject().setProperty("AvatarData", 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_MSECS = (1 / 60) * 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_MSECS * 1000) - (usecTimestampNow() - usecTimestamp(&thisSend))) > 0) {
|
||||
usleep(numMicrosecondsSleep);
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Execution of script:" << engine.evaluate(scriptString).toString();
|
||||
}
|
|
@ -16,14 +16,19 @@
|
|||
|
||||
#include "SharedUtil.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QUrl>
|
||||
|
||||
class Agent {
|
||||
public:
|
||||
bool volatile shouldStop;
|
||||
class Agent : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Agent();
|
||||
|
||||
bool volatile _shouldStop;
|
||||
|
||||
void run(QUrl scriptUrl);
|
||||
private:
|
||||
signals:
|
||||
void preSendCallback();
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__Operative__) */
|
||||
|
|
|
@ -10,8 +10,9 @@
|
|||
#include <cstring>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <SharedUtil.h>
|
||||
#include <NodeList.h>
|
||||
#include <PacketHeaders.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "AvatarData.h"
|
||||
//#include <VoxelConstants.h>
|
||||
|
@ -50,6 +51,24 @@ AvatarData::~AvatarData() {
|
|||
delete _handData;
|
||||
}
|
||||
|
||||
void AvatarData::sendData() {
|
||||
|
||||
// called from Agent visual loop to send data
|
||||
if (Node* avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER)) {
|
||||
unsigned char packet[MAX_PACKET_SIZE];
|
||||
|
||||
unsigned char* endOfPacket = packet;
|
||||
endOfPacket += populateTypeAndVersion(endOfPacket, PACKET_TYPE_HEAD_DATA);
|
||||
endOfPacket += packNodeId(endOfPacket, NodeList::getInstance()->getOwnerID());
|
||||
|
||||
int numPacketBytes = (endOfPacket - packet) + getBroadcastData(endOfPacket);
|
||||
|
||||
qDebug("The current body yaw is %f\n", _bodyYaw);
|
||||
|
||||
NodeList::getInstance()->getNodeSocket()->send(avatarMixer->getActiveSocket(), packet, numPacketBytes);
|
||||
}
|
||||
}
|
||||
|
||||
int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
||||
unsigned char* bufferStart = destinationBuffer;
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ public:
|
|||
|
||||
// Body Rotation
|
||||
float getBodyYaw() const { return _bodyYaw; }
|
||||
void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; }
|
||||
float getBodyPitch() const { return _bodyPitch; }
|
||||
void setBodyPitch(float bodyPitch) { _bodyPitch = bodyPitch; }
|
||||
float getBodyRoll() const {return _bodyRoll; }
|
||||
|
@ -108,6 +107,8 @@ public:
|
|||
|
||||
public slots:
|
||||
void setPosition(float x, float y, float z) { _position = glm::vec3(x, y, z); }
|
||||
void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; }
|
||||
void sendData();
|
||||
|
||||
protected:
|
||||
glm::vec3 _position;
|
||||
|
|
|
@ -117,8 +117,10 @@ void NodeList::processNodeData(sockaddr* senderAddress, unsigned char* packetDat
|
|||
sockaddr_in domainServerSocket = *(sockaddr_in*) senderAddress;
|
||||
const char* domainSenderIP = inet_ntoa(domainServerSocket.sin_addr);
|
||||
|
||||
processDomainServerList(packetData, dataBytes);
|
||||
|
||||
if (memcmp(domainSenderIP, _domainIP, strlen(domainSenderIP)) == 0) {
|
||||
processDomainServerList(packetData, dataBytes);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue