Cafu Engine
CompMover.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_GAMESYS_COMPONENT_MOVER_HPP_INCLUDED
8 #define CAFU_GAMESYS_COMPONENT_MOVER_HPP_INCLUDED
9 
10 #include "CompBase.hpp"
11 
12 
13 namespace cf
14 {
15  namespace GameSys
16  {
17  /// This component controls the movement of one or more entities and implements the related effects.
18  ///
19  /// The component can handle a single entity, e.g. a moving platform or a lift, or several entities
20  /// that act together as a team, e.g. the wings of a door.
21  ///
22  /// This component works in concert with a Script component, which must be present in the same entity.
23  /// The Mover component queries the Script component for the desired spatial transformation of each
24  /// team member, and notifies it whenever the movement is blocked by another entity (e.g. a player).
25  /// It also implements the appropriate effects on other entities, e.g. their being pushed by moving
26  /// parts, or their riding on top of them.
28  {
29  public:
30 
31  /// A variable of type `int` that describes the mover's behavior when it is activated at the "dest" position.
32  class VarDestActivatedT : public TypeSys::VarT<int>
33  {
34  public:
35 
36  enum { DESTACT_MOVE_HOME = 0, DESTACT_RESET_TIMEOUT, DESTACT_IGNORE };
37 
38  VarDestActivatedT(const char* Name, const int& Value, const char* Flags[]=NULL);
39 
40  // Base class overrides.
41  void GetChoices(ArrayT<std::string>& Strings, ArrayT<int>& Values) const override;
42  };
43 
44  /// A variable of type `int` that describes the mover's behavior regarding other entities.
45  class VarOtherEntitiesT : public TypeSys::VarT<int>
46  {
47  public:
48 
49  enum { OTHERENTS_IGNORE = 0, OTHERENTS_CANNOT_PUSH, OTHERENTS_CAN_PUSH, OTHERENTS_CAN_FORCE_PUSH };
50 
51  VarOtherEntitiesT(const char* Name, const int& Value, const char* Flags[]=NULL);
52 
53  // Base class overrides.
54  void GetChoices(ArrayT<std::string>& Strings, ArrayT<int>& Values) const override;
55  };
56 
57  /// A variable of type `int` that describes the base function that is used to compute the mover's trajectory.
58  class VarTrajFuncT : public TypeSys::VarT<int>
59  {
60  public:
61 
62  enum { TRAJFUNC_LINEAR = 0, TRAJFUNC_SINE };
63 
64  VarTrajFuncT(const char* Name, const int& Value, const char* Flags[]=NULL);
65 
66  // Base class overrides.
67  void GetChoices(ArrayT<std::string>& Strings, ArrayT<int>& Values) const override;
68  };
69 
70 
71  /// The constructor.
73 
74  /// The copy constructor.
75  /// @param Comp The component to create a copy of.
76  ComponentMoverT(const ComponentMoverT& Comp);
77 
78 
79  // Base class overrides.
80  ComponentMoverT* Clone() const override;
81  const char* GetName() const override { return "Mover"; }
82  unsigned int GetEditorColor() const override { return 0xA00000; }
83  BoundingBox3fT GetEditorBB() const override { return BoundingBox3fT(Vector3fT(-8, -8, -8), Vector3fT(8, 8, 8)); }
84 
85 
86  // The TypeSys related declarations for this class.
87  const cf::TypeSys::TypeInfoT* GetType() const override { return &TypeInfo; }
88  static void* CreateInstance(const cf::TypeSys::CreateParamsT& Params);
89  static const cf::TypeSys::TypeInfoT TypeInfo;
90 
91 
92  protected:
93 
94  // The Lua API methods of this class.
95  static int HandleMove(lua_State* LuaState);
96  static int toString(lua_State* LuaState);
97 
98  static const luaL_Reg MethodsList[]; ///< The list of Lua methods for this class.
99  static const char* DocClass;
100  static const cf::TypeSys::MethsDocT DocMethods[];
101  static const cf::TypeSys::VarsDocT DocVars[];
102 
103 
104  private:
105 
106  bool HandleMove(float t) const;
107 
108  TypeSys::VarT<float> m_MoveDuration; ///< The time in seconds that it takes to move each part from one endpoint to the other.
109  VarDestActivatedT m_DestActivated; ///< Describes the mover's behavior when it is activated at the "dest" position.
110  TypeSys::VarT<float> m_DestTimeout; ///< The timeout in seconds after which the parts move back to their "home" position. A negative value to disables the timeout.
111  VarOtherEntitiesT m_OtherEntities; ///< Describes the mover's behavior regarding other entities.
112  VarTrajFuncT m_TrajFunc; ///< Describes the base function that is used to compute the mover's trajectory.
113  TypeSys::VarT<float> m_TrajExp; ///< The exponent that is applied to `trajFunc`.
114  };
115  }
116 }
117 
118 #endif
ComponentMoverT * Clone() const override
The virtual copy constructor.
Definition: CompMover.cpp:149
void GetChoices(ArrayT< std::string > &Strings, ArrayT< int > &Values) const override
This method returns a list of acceptable input values for this variable, along with a string represen...
Definition: CompMover.cpp:58
unsigned int GetEditorColor() const override
Returns a color that the Map Editor can use to render the representation of this component's entity...
Definition: CompMover.hpp:82
A variable of type int that describes the base function that is used to compute the mover's trajector...
Definition: CompMover.hpp:58
This is a "wrapper" around a normal C++ variable.
Definition: SetCompVar.hpp:15
A variable of type int that describes the mover's behavior when it is activated at the "dest" positio...
Definition: CompMover.hpp:32
BoundingBox3fT GetEditorBB() const override
Returns a bounding-box that the Map Editor can use to render the representation of this component's e...
Definition: CompMover.hpp:83
This component controls the movement of one or more entities and implements the related effects...
Definition: CompMover.hpp:27
void GetChoices(ArrayT< std::string > &Strings, ArrayT< int > &Values) const override
This method returns a list of acceptable input values for this variable, along with a string represen...
Definition: CompMover.cpp:40
static const luaL_Reg MethodsList[]
The list of Lua methods for this class.
Definition: CompMover.hpp:98
void GetChoices(ArrayT< std::string > &Strings, ArrayT< int > &Values) const override
This method returns a list of acceptable input values for this variable, along with a string represen...
Definition: CompMover.cpp:77
const char * GetName() const override
Returns the name of this component.
Definition: CompMover.hpp:81
ComponentMoverT()
The constructor.
Definition: CompMover.cpp:113
Definition: TypeSys.hpp:52
Definition: TypeSys.hpp:57
This class keeps type information (about an entity class that occurs in the game).
Definition: TypeSys.hpp:79
A variable of type int that describes the mover's behavior regarding other entities.
Definition: CompMover.hpp:45
Definition: TypeSys.hpp:68
This is the base class for the components that an entity is composed/aggregated of.
Definition: CompBase.hpp:54