GteControlledObject.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
10 using namespace gte;
11 
13 {
14 }
15 
17 {
18 }
19 
20 void ControlledObject::AttachController(std::shared_ptr<Controller> const& controller)
21 {
22  if (controller)
23  {
24  // Test whether the controller is already in the list.
25  for (auto const& element : mControllers)
26  {
27  if (element == controller)
28  {
29  // The controller is in the list, so nothing to do.
30  return;
31  }
32  }
33 
34  // Bind the controller to the object using a regular pointer to avoid
35  // a reference-count cycle.
36  controller->SetObject(this);
37 
38  // The controller is not in the current list, so add it.
39  mControllers.push_back(controller);
40  }
41 }
42 
43 void ControlledObject::DetachController(std::shared_ptr<Controller> const& controller)
44 {
45  for (auto const& element : mControllers)
46  {
47  if (element == controller)
48  {
49  // Unbind the controller from the object.
50  controller->SetObject(nullptr);
51 
52  // Remove the controller from the list.
53  mControllers.remove(controller);
54  return;
55  }
56  }
57 }
58 
60 {
61  for (auto& element : mControllers)
62  {
63  // Unbind the controller from the object.
64  element->SetObject(nullptr);
65  }
66  mControllers.clear();
67 }
68 
69 bool ControlledObject::UpdateControllers(double applicationTime)
70 {
71  bool someoneUpdated = false;
72  for (auto& element : mControllers)
73  {
74  if (element->Update(applicationTime))
75  {
76  someoneUpdated = true;
77  }
78  }
79  return someoneUpdated;
80 }
void AttachController(std::shared_ptr< Controller > const &controller)
bool UpdateControllers(double applicationTime)
void DetachController(std::shared_ptr< Controller > const &controller)


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59