Overte C++ Documentation
ScriptEndpoint.h
1 //
2 // Created by Bradley Austin Davis 2015/10/23
3 // Copyright 2015 High Fidelity, Inc.
4 // Copyright 2023 Overte e.V.
5 //
6 // Distributed under the Apache License, Version 2.0.
7 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
8 // SPDX-License-Identifier: Apache-2.0
9 //
10 
11 #pragma once
12 #ifndef hifi_Controllers_ScriptEndpoint_h
13 #define hifi_Controllers_ScriptEndpoint_h
14 
15 #include <ScriptValue.h>
16 
17 #include "../Endpoint.h"
18 
19 namespace controller {
20 
21 class ScriptEndpoint : public Endpoint {
22  Q_OBJECT;
23 public:
24  using Endpoint::apply;
25  static std::shared_ptr<Endpoint> newEndpoint(const ScriptValue& callable) {
26  return std::shared_ptr<Endpoint>(new ScriptEndpoint(callable));
27  };
28 
29  virtual AxisValue peek() const override;
30  virtual void apply(AxisValue newValue, const Pointer& source) override;
31 
32  virtual Pose peekPose() const override;
33  virtual void apply(const Pose& newValue, const Pointer& source) override;
34 
35  virtual bool isPose() const override { return _returnPose; }
36  virtual const ScriptEngine* getEngine() const { return _callable.engine().get(); }
37 
38 protected:
39  Q_INVOKABLE void updateValue();
40  Q_INVOKABLE virtual void internalApply(float newValue, int sourceID);
41 
42  Q_INVOKABLE void updatePose();
43  Q_INVOKABLE virtual void internalApply(const Pose& newValue, int sourceID);
44 private:
45  ScriptEndpoint(const ScriptValue& callable)
46  : Endpoint(Input::INVALID_INPUT), _callable(callable) {
47  }
48  ScriptValue _callable;
49  float _lastValueRead { 0.0f };
50  AxisValue _lastValueWritten { 0.0f, 0, false };
51 
52  bool _returnPose { false };
53  Pose _lastPoseRead;
54  Pose _lastPoseWritten;
55 };
56 
57 }
58 
59 #endif
Provides an engine-independent interface for a scripting engine.
Definition: ScriptEngine.h:93
[ScriptInterface] Provides an engine-independent interface for QScriptValue
Definition: ScriptValue.h:40