Skip to content

Commit

Permalink
Merge pull request #185 from overte-org/feature/v8
Browse files Browse the repository at this point in the history
V8 scripting engine
  • Loading branch information
ksuprynowicz committed May 27, 2023
2 parents 26fe78f + 6192416 commit e578fe2
Show file tree
Hide file tree
Showing 443 changed files with 25,281 additions and 13,872 deletions.
53 changes: 27 additions & 26 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@ CMakeCache.txt
CMakeFiles/
CMakeScripts/
cmake_install.cmake
build*/
/build*/
cmake-build-minsizerelease-visual-studio/
cmake-build-release-visual-studio/
cmake-build-relwithdebinfo-visual-studio/
release*/
debug*/
gprof*/
valgrind*/
ext/
cmake-build-debug-visual-studio/
/release*/
/debug*/
/gprof*/
/valgrind*/
/ext/
Makefile
*.user

# Android Studio
*.iml
*.class
local.properties
android/gradle*
android/.gradle
android/**/src/main/jniLibs
android/**/libs
android/**/bin
android/**/src/main/res/values/libs.xml
android/**/src/main/assets
android/**/gradle*
/android/gradle*
/android/.gradle
/android/**/src/main/jniLibs
/android/**/libs
/android/**/bin
/android/**/src/main/res/values/libs.xml
/android/**/src/main/assets
/android/**/gradle*
*.class

# Visual Studio
Expand Down Expand Up @@ -73,19 +76,16 @@ DerivedData
*.hmap

# ignore interface optional externals
interface/external/*/*
/interface/external/*/*
!interface/external/*/readme.txt

# Ignore interfaceCache for Linux users
interface/interfaceCache/
/interface/interfaceCache/

# ignore audio-client externals
libraries/audio-client/external/*/*
/libraries/audio-client/external/*/*
!libraries/audio-client/external/*/readme.txt

gvr-interface/assets/oculussig*
gvr-interface/libs/*

# ignore files for various dev environments
TAGS
*.sw[po]
Expand All @@ -108,21 +108,22 @@ interface/compiledResources
*.rcc

# GPUCache
interface/resources/GPUCache/*
/interface/resources/GPUCache/*

# package lock file for JSDoc tool
tools/jsdoc/package-lock.json
/tools/jsdoc/package-lock.json

# Python compile artifacts
**/__pycache__

# ignore local unity project files for avatar exporter
tools/unity-avatar-exporter
/tools/unity-avatar-exporter

server-console/package-lock.json
vcpkg/
/server-console/package-lock.json
/vcpkg/
/tools/nitpick/compiledResources
qt/
/qt/

# Act local GitHub Actions
.secret

6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2013-2019 High Fidelity, Inc.
# Copyright 2019-2021 Vircadia contributors.
# Copyright 2020-2022 Overte e.V.
# Copyright 2020-2023 Overte e.V.
# SPDX-License-Identifier: Apache-2.0

# If we're running under the gradle build, HIFI_ANDROID will be set here, but
Expand All @@ -12,6 +12,8 @@ else()
cmake_minimum_required(VERSION 3.2)
endif()

# 3.14 is the minimum version that supports symlinks on Windows
cmake_minimum_required(VERSION 3.14)

# Passing of variables to vcpkg
#
Expand Down Expand Up @@ -192,7 +194,7 @@ else()
set(VCPKG_BUILD_TYPE_PARAM --vcpkg-build-type ${VCPKG_BUILD_TYPE})
endif()
execute_process(
COMMAND ${HIFI_PYTHON_EXEC} ${CMAKE_CURRENT_SOURCE_DIR}/prebuild.py --vcpkg-skip-clean --release-type ${RELEASE_TYPE} --build-root ${CMAKE_BINARY_DIR} ${VCPKG_BUILD_TYPE_PARAM}
COMMAND ${HIFI_PYTHON_EXEC} ${CMAKE_CURRENT_SOURCE_DIR}/prebuild.py --release-type ${RELEASE_TYPE} --build-root ${CMAKE_BINARY_DIR} ${VCPKG_BUILD_TYPE_PARAM}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} RESULTS_VARIABLE PREBUILD_RET
)
# squelch the Policy CMP0074 warning without requiring an update to cmake 3.12.
Expand Down
6 changes: 5 additions & 1 deletion assignment-client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Copyright 2013-2019 High Fidelity, Inc.
# Copyright 2021-2022 Overte e.V.
# SPDX-License-Identifier: Apache-2.0

set(TARGET_NAME assignment-client)

setup_hifi_project(Core Gui Network Script Quick WebSockets)
setup_hifi_project(Core Gui Network Quick WebSockets)

# Fix up the rpath so macdeployqt works
if (APPLE)
Expand Down
48 changes: 27 additions & 21 deletions assignment-client/src/Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
//
// Created by Stephen Birarda on 7/1/13.
// Copyright 2013 High Fidelity, Inc.
// Copyright 2023 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// SPDX-License-Identifier: Apache-2.0
//

#include "Agent.h"
Expand All @@ -27,14 +29,17 @@
#include <DebugDraw.h>
#include <EntityScriptingInterface.h>
#include <LocationScriptingInterface.h>
#include <AudioScriptingInterface.h>
#include <MessagesClient.h>
#include <NetworkAccessManager.h>
#include <NodeList.h>
#include <udt/PacketHeaders.h>
#include <ResourceCache.h>
#include <ResourceScriptingInterface.h>
#include <ScriptCache.h>
#include <ScriptEngine.h>
#include <ScriptEngines.h>
#include <ScriptManager.h>
#include <SoundCacheScriptingInterface.h>
#include <SoundCache.h>
#include <UserActivityLoggerScriptingInterface.h>
Expand All @@ -56,7 +61,7 @@

#include "entities/AssignmentParentFinder.h"
#include "AssignmentDynamicFactory.h"
#include "RecordingScriptingInterface.h"
#include <recording/RecordingScriptingInterface.h>
#include "AbstractAudioInterface.h"
#include "AgentScriptingInterface.h"

Expand Down Expand Up @@ -180,7 +185,7 @@ static const QString AGENT_LOGGING_NAME = "agent";

void Agent::run() {
// Create ScriptEngines on threaded-assignment thread then move to main thread.
DependencyManager::set<ScriptEngines>(ScriptEngine::AGENT_SCRIPT)->moveToThread(qApp->thread());
DependencyManager::set<ScriptEngines>(ScriptManager::AGENT_SCRIPT)->moveToThread(qApp->thread());

DependencyManager::set<ScriptCache>();

Expand Down Expand Up @@ -372,7 +377,7 @@ void Agent::executeScript() {
// the following block is scoped so that any shared pointers we take here
// are cleared before we call setFinished at the end of the function
{
_scriptEngine = scriptEngineFactory(ScriptEngine::AGENT_SCRIPT, _scriptContents, _payload);
_scriptManager = scriptManagerFactory(ScriptManager::AGENT_SCRIPT, _scriptContents, _payload);

// setup an Avatar for the script to use
auto scriptedAvatar = DependencyManager::get<ScriptableAvatar>();
Expand All @@ -386,10 +391,11 @@ void Agent::executeScript() {
scriptedAvatar->getHeadOrientation();

// give this AvatarData object to the script engine
_scriptEngine->registerGlobalObject("Avatar", scriptedAvatar.data());
auto scriptEngine = _scriptManager->engine();
scriptEngine->registerGlobalObject("Avatar", scriptedAvatar.data());

// give scripts access to the Users object
_scriptEngine->registerGlobalObject("Users", DependencyManager::get<UsersScriptingInterface>().data());
scriptEngine->registerGlobalObject("Users", DependencyManager::get<UsersScriptingInterface>().data());

auto player = DependencyManager::get<recording::Deck>();
connect(player.data(), &recording::Deck::playbackStateChanged, [&player, &scriptedAvatar] {
Expand Down Expand Up @@ -493,26 +499,26 @@ void Agent::executeScript() {
});

auto avatarHashMap = DependencyManager::set<AvatarHashMap>();
_scriptEngine->registerGlobalObject("AvatarList", avatarHashMap.data());
scriptEngine->registerGlobalObject("AvatarList", avatarHashMap.data());

// register ourselves to the script engine
_scriptEngine->registerGlobalObject("Agent", new AgentScriptingInterface(this));
scriptEngine->registerGlobalObject("Agent", new AgentScriptingInterface(this));

_scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
_scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCacheScriptingInterface>().data());
scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());

QScriptValue webSocketServerConstructorValue = _scriptEngine->newFunction(WebSocketServerClass::constructor);
_scriptEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);
ScriptValue webSocketServerConstructorValue = scriptEngine->newFunction(WebSocketServerClass::constructor);
scriptEngine->globalObject().setProperty("WebSocketServer", webSocketServerConstructorValue);

auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();

_scriptEngine->registerGlobalObject("EntityViewer", &_entityViewer);
scriptEngine->registerGlobalObject("EntityViewer", &_entityViewer);

_scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
LocationScriptingInterface::locationSetter);

auto recordingInterface = DependencyManager::get<RecordingScriptingInterface>();
_scriptEngine->registerGlobalObject("Recording", recordingInterface.data());
scriptEngine->registerGlobalObject("Recording", recordingInterface.data());

entityScriptingInterface->init();

Expand All @@ -522,8 +528,8 @@ void Agent::executeScript() {

DependencyManager::set<AssignmentParentFinder>(_entityViewer.getTree());

DependencyManager::get<ScriptEngines>()->runScriptInitializers(_scriptEngine);
_scriptEngine->run();
DependencyManager::get<ScriptEngines>()->runScriptInitializers(_scriptManager);
_scriptManager->run();

Frame::clearFrameHandler(AUDIO_FRAME_TYPE);
Frame::clearFrameHandler(AVATAR_FRAME_TYPE);
Expand Down Expand Up @@ -602,7 +608,7 @@ void Agent::setIsAvatar(bool isAvatar) {
// start the timer
_avatarQueryTimer->start(AVATAR_VIEW_PACKET_SEND_INTERVAL_MSECS);

connect(_scriptEngine.data(), &ScriptEngine::update,
connect(_scriptManager.get(), &ScriptManager::update,
scriptableAvatar.data(), &ScriptableAvatar::update, Qt::QueuedConnection);

// tell the avatarAudioTimer to start ticking
Expand Down Expand Up @@ -638,7 +644,7 @@ void Agent::setIsAvatar(bool isAvatar) {
nodeList->sendPacket(std::move(packet), *node);
});

disconnect(_scriptEngine.data(), &ScriptEngine::update,
disconnect(_scriptManager.get(), &ScriptManager::update,
scriptableAvatar.data(), &ScriptableAvatar::update);

QMetaObject::invokeMethod(&_avatarAudioTimer, "stop");
Expand Down Expand Up @@ -875,7 +881,7 @@ void Agent::aboutToFinish() {

// drop our shared pointer to the script engine, then ask ScriptEngines to shutdown scripting
// this ensures that the ScriptEngine goes down before ScriptEngines
_scriptEngine.clear();
_scriptManager.reset();

{
DependencyManager::get<ScriptEngines>()->shutdownScripting();
Expand All @@ -895,8 +901,8 @@ void Agent::aboutToFinish() {
}

void Agent::stop() {
if (_scriptEngine) {
_scriptEngine->stop();
if (_scriptManager) {
_scriptManager->stop();
} else {
setFinished(true);
}
Expand Down
12 changes: 10 additions & 2 deletions assignment-client/src/Agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
//
// Created by Stephen Birarda on 7/1/13.
// Copyright 2013 High Fidelity, Inc.
// Copyright 2023 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// SPDX-License-Identifier: Apache-2.0
//

#ifndef hifi_Agent_h
Expand All @@ -15,12 +17,12 @@
#include <memory>
#include <vector>

#include <QtScript/QScriptEngine>
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>
#include <QtCore/QUrl>
#include <QtCore/QTimer>
#include <QUuid>
#include <QtCore/QSharedPointer>

#include <EntityEditPacketSender.h>
#include <EntityTree.h>
Expand All @@ -29,11 +31,17 @@

#include <plugins/CodecPlugin.h>

#include <Sound.h>
#include "AudioGate.h"
#include "MixedAudioStream.h"
#include "entities/EntityTreeHeadlessViewer.h"
#include "avatars/ScriptableAvatar.h"

class ScriptEngine;
class ScriptManager;
using ScriptEnginePointer = std::shared_ptr<ScriptEngine>;
using ScriptManagerPointer = std::shared_ptr<ScriptManager>;

class Agent : public ThreadedAssignment {
Q_OBJECT

Expand Down Expand Up @@ -90,7 +98,7 @@ private slots:
void encodeFrameOfZeros(QByteArray& encodedZeros);
void computeLoudness(const QByteArray* decodedBuffer, QSharedPointer<ScriptableAvatar>);

ScriptEnginePointer _scriptEngine;
ScriptManagerPointer _scriptManager;
EntityEditPacketSender _entityEditSender;
EntityTreeHeadlessViewer _entityViewer;

Expand Down
Loading

0 comments on commit e578fe2

Please sign in to comment.