mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-11 05:23:08 +02:00
add a VoxelScriptingInterface to accept voxel addition in JS
This commit is contained in:
parent
8f3de6fb5d
commit
df862c152b
5 changed files with 61 additions and 10 deletions
9
VoxelScriptingInterface.cpp
Normal file
9
VoxelScriptingInterface.cpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
//
|
||||
// VoxelScriptingInterface.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 9/17/13.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "VoxelScriptingInterface.h"
|
|
@ -23,4 +23,5 @@ include_glm(${TARGET_NAME} ${ROOT_DIR})
|
|||
include(${MACRO_DIR}/LinkHifiLibrary.cmake)
|
||||
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
|
||||
link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR})
|
||||
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})
|
||||
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})
|
||||
link_hifi_library(voxels ${TARGET_NAME} ${ROOT_DIR})
|
|
@ -9,11 +9,11 @@
|
|||
#include <QtScript/QScriptEngine>
|
||||
#include <QtNetwork/QtNetwork>
|
||||
|
||||
#include <AvatarData.h>
|
||||
#include <NodeList.h>
|
||||
|
||||
#include "AvatarData.h"
|
||||
|
||||
#include "Agent.h"
|
||||
#include "VoxelScriptingInterface.h"
|
||||
|
||||
Agent::Agent() :
|
||||
_shouldStop(false)
|
||||
|
@ -39,14 +39,13 @@ void Agent::run(QUrl scriptURL) {
|
|||
|
||||
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);
|
||||
|
||||
VoxelScriptingInterface voxelScripter;
|
||||
QScriptValue voxelScripterValue = engine.newQObject(&voxelScripter);
|
||||
engine.globalObject().setProperty("Voxels", voxelScripterValue);
|
||||
|
||||
qDebug() << "Downloaded script:" << scriptString << "\n";
|
||||
qDebug() << "Evaluated script:" << engine.evaluate(scriptString).toString() << "\n";
|
||||
|
||||
|
@ -75,9 +74,10 @@ void Agent::run(QUrl scriptURL) {
|
|||
NodeList::getInstance()->sendDomainServerCheckIn();
|
||||
}
|
||||
|
||||
// allow the scripter's call back to setup visual data
|
||||
emit preSendCallback();
|
||||
|
||||
testAvatarData->sendData();
|
||||
// flush the voxel packet queue
|
||||
voxelScripter.getVoxelPacketSender()->flushQueue();
|
||||
|
||||
if (NodeList::getInstance()->getNodeSocket()->receive((sockaddr*) &senderAddress, receivedData, &receivedBytes)) {
|
||||
NodeList::getInstance()->processNodeData((sockaddr*) &senderAddress, receivedData, receivedBytes);
|
||||
|
|
15
assignment-client/src/VoxelScriptingInterface.cpp
Normal file
15
assignment-client/src/VoxelScriptingInterface.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
//
|
||||
// VoxelScriptingInterface.cpp
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 9/17/13.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#include "VoxelScriptingInterface.h"
|
||||
|
||||
void VoxelScriptingInterface::queueVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) {
|
||||
// setup a VoxelDetail struct with the data
|
||||
VoxelDetail addVoxelDetail = {x, y, z, scale, red, green, blue};
|
||||
_voxelPacketSender.queueVoxelEditMessages(PACKET_TYPE_SET_VOXEL, 1, &addVoxelDetail);
|
||||
}
|
26
assignment-client/src/VoxelScriptingInterface.h
Normal file
26
assignment-client/src/VoxelScriptingInterface.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// VoxelScriptingInterface.h
|
||||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 9/17/13.
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __hifi__VoxelScriptingInterface__
|
||||
#define __hifi__VoxelScriptingInterface__
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <VoxelEditPacketSender.h>
|
||||
|
||||
class VoxelScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
VoxelEditPacketSender* getVoxelPacketSender() { return &_voxelPacketSender; }
|
||||
public slots:
|
||||
void queueVoxelAdd(float x, float y, float z, float scale, uchar red, uchar green, uchar blue);
|
||||
private:
|
||||
VoxelEditPacketSender _voxelPacketSender;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__VoxelScriptingInterface__) */
|
Loading…
Reference in a new issue