Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 4 files). Show all
Unified · Split
| @@ -40,7 +40,9 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng · 39 unmodified lines | |||
| 40 | 40 | ||
| 41 | ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, | 41 | ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, |
| 42 | const char* scriptMenuName, AbstractMenuInterface* menu, | 42 | const char* scriptMenuName, AbstractMenuInterface* menu, |
| 43 | AbstractControllerScriptingInterface* controllerScriptingInterface) { | 43 | AbstractControllerScriptingInterface* controllerScriptingInterface) : |
| 44 | _avatarData(NULL) | ||
| 45 | { | ||
| 44 | _scriptContents = scriptContents; | 46 | _scriptContents = scriptContents; |
| 45 | _isFinished = false; | 47 | _isFinished = false; |
| 46 | _isRunning = false; | 48 | _isRunning = false; |
| @@ -65,6 +67,15 @@ ScriptEngine::~ScriptEngine() { · 18 unmodified lines | |||
| 65 | //printf("ScriptEngine::~ScriptEngine()...\n"); | 67 | //printf("ScriptEngine::~ScriptEngine()...\n"); |
| 66 | } | 68 | } |
| 67 | 69 | ||
| 70 | void ScriptEngine::setAvatarData(AvatarData* avatarData) { | ||
| 71 | _avatarData = avatarData; | ||
| 72 | |||
| 73 | // remove the old Avatar property, if it exists | ||
| 74 | _engine.globalObject().setProperty("Avatar", QScriptValue()); | ||
| 75 | |||
| 76 | // give the script engine the new Avatar script property | ||
| 77 | registerGlobalObject("Avatar", _avatarData); | ||
| 78 | } | ||
| 68 | 79 | ||
| 69 | void ScriptEngine::setupMenuItems() { | 80 | void ScriptEngine::setupMenuItems() { |
| 70 | if (_menu && _wantMenuItems) { | 81 | if (_menu && _wantMenuItems) { |
| @@ -178,6 +189,8 @@ void ScriptEngine::run() { · 107 unmodified lines | |||
| 178 | gettimeofday(&startTime, NULL); | 189 | gettimeofday(&startTime, NULL); |
| 179 | 190 | ||
| 180 | int thisFrame = 0; | 191 | int thisFrame = 0; |
| 192 | |||
| 193 | NodeList* nodeList = NodeList::getInstance(); | ||
| 181 | 194 | ||
| 182 | while (!_isFinished) { | 195 | while (!_isFinished) { |
| 183 | int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * VISUAL_DATA_CALLBACK_USECS) - usecTimestampNow(); | 196 | int usecToSleep = usecTimestamp(&startTime) + (thisFrame++ * VISUAL_DATA_CALLBACK_USECS) - usecTimestampNow(); |
| @@ -221,6 +234,26 @@ void ScriptEngine::run() { · 37 unmodified lines | |||
| 221 | _particlesScriptingInterface.getParticlePacketSender()->process(); | 234 | _particlesScriptingInterface.getParticlePacketSender()->process(); |
| 222 | } | 235 | } |
| 223 | } | 236 | } |
| 237 | |||
| 238 | if (_isAvatar && _avatarData) { | ||
| 239 | static unsigned char avatarPacket[MAX_PACKET_SIZE]; | ||
| 240 | static int numAvatarHeaderBytes = 0; | ||
| 241 | |||
| 242 | if (numAvatarHeaderBytes == 0) { | ||
| 243 | // pack the avatar header bytes the first time | ||
| 244 | // unlike the _avatar.getBroadcastData these won't change | ||
| 245 | numAvatarHeaderBytes = populateTypeAndVersion(avatarPacket, PACKET_TYPE_HEAD_DATA); | ||
| 246 | |||
| 247 | // pack the owner UUID for this script | ||
| 248 | QByteArray ownerUUID = nodeList->getOwnerUUID().toRfc4122(); | ||
| 249 | memcpy(avatarPacket, ownerUUID.constData(), ownerUUID.size()); | ||
| 250 | numAvatarHeaderBytes += ownerUUID.size(); | ||
| 251 | } | ||
| 252 | |||
| 253 | int numAvatarPacketBytes = _avatarData->getBroadcastData(avatarPacket + numAvatarHeaderBytes) + numAvatarHeaderBytes; | ||
| 254 | |||
| 255 | nodeList->broadcastToNodes(avatarPacket, numAvatarPacketBytes, &NODE_TYPE_AVATAR_MIXER, 1); | ||
| 256 | } | ||
| 224 | 257 | ||
| 225 | if (willSendVisualDataCallBack) { | 258 | if (willSendVisualDataCallBack) { |
| 226 | emit willSendVisualDataCallback(); | 259 | emit willSendVisualDataCallback(); |