Overte C++ Documentation
StandardEndpoint.h
1 //
2 // Created by Bradley Austin Davis 2015/10/23
3 // Copyright 2015 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #pragma once
10 #ifndef hifi_Controllers_StandardEndpoint_h
11 #define hifi_Controllers_StandardEndpoint_h
12 
13 #include "../Endpoint.h"
14 
15 #include <DependencyManager.h>
16 
17 #include "../../InputRecorder.h"
18 #include "../../UserInputMapper.h"
19 
20 namespace controller {
21 
22 class StandardEndpoint : public VirtualEndpoint {
23 public:
24  StandardEndpoint(const Input& input) : VirtualEndpoint(input) {}
25  virtual bool writeable() const override { return !_written; }
26  virtual bool readable() const override { return !_read; }
27  virtual void reset() override {
28  apply(AxisValue(), Endpoint::Pointer());
29  apply(Pose(), Endpoint::Pointer());
30  _written = _read = false;
31  }
32 
33  virtual AxisValue value() override {
34  _read = true;
35  return VirtualEndpoint::value();
36  }
37 
38  virtual void apply(AxisValue value, const Pointer& source) override {
39  // For standard endpoints, the first NON-ZERO write counts.
40  if (value != AxisValue()) {
41  _written = true;
42  }
43  VirtualEndpoint::apply(value, source);
44  }
45 
46  virtual Pose pose() override {
47  _read = true;
48  InputRecorder* inputRecorder = InputRecorder::getInstance();
49  if (inputRecorder->isPlayingback()) {
50  auto userInputMapper = DependencyManager::get<UserInputMapper>();
51  QString actionName = userInputMapper->getStandardPoseName(_input.getChannel());
52  return inputRecorder->getPoseState(actionName);
53  }
54  return VirtualEndpoint::pose();
55  }
56 
57  virtual void apply(const Pose& value, const Pointer& source) override {
58  if (value != Pose() && value.isValid()) {
59  _written = true;
60  }
61  VirtualEndpoint::apply(value, source);
62  }
63 
64 private:
65  bool _written { false };
66  bool _read { false };
67 };
68 
69 }
70 
71 #endif