VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Actor.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ACTOR_H
18 #define ACTOR_H
19 
20 #include <QList>
21 #include <QMap>
22 #include <QQuickItem>
23 
24 class Body;
25 class Logic;
26 
40 class Actor : public QQuickItem {
41  Q_OBJECT
42 public:
43  // TODO: Generalize to ActorTraits of which each actor can have 0-N.
44  Q_ENUMS(ActorType)
49  enum ActorType {
60  };
61 
72  Q_PROPERTY(Body* body READ getBody)
73 
77  Actor();
78 
82  ActorType getActorType() const { return mActorType; }
88 
92  Body* getBody() const;
93 
101  Q_INVOKABLE QObject* findChildByTypeName(const QString& typeName);
102 
103 signals:
107  void actorTypeChanged();
108 
109 protected:
114  virtual void componentComplete() override;
115 
116 private:
117  void invalidateBodyTransform();
118  void indexChildren();
119  QObject* findChildByType(QObject* item, const QMetaObject& metadata);
120 
121  ActorType mActorType = GenericActor;
122  Body* mBody = nullptr;
123 };
124 Q_DECLARE_METATYPE(Actor*)
125 
126 #endif // ACTOR_H
A QObject container for a Box2D b2Body.
Definition: Body.h:57
ActorType actorType
Type of this Actor, as one of ActorType.
Definition: Actor.h:68
ActorType getActorType() const
Returns actorType.
Definition: Actor.h:82
Actor which is controlled by a player (a user).
Definition: Actor.h:59
void actorTypeChanged()
Emitted when actorType changes.
ActorType
Different categories of Actors, used to differentiate among them.
Definition: Actor.h:49
virtual void componentComplete() override
Performs additional initialization, like finding this Actor's associated Body, if one exists...
Non-visual entities in the QML item tree that define behavior for their parent Actor.
Definition: Logic.h:31
void setActorType(ActorType actorType)
Sets actorType.
Representation of an entity within the Game scene.
Definition: Actor.h:40
Actor which is not any other type.
Definition: Actor.h:53
Q_INVOKABLE QObject * findChildByTypeName(const QString &typeName)
Look through our subtree and find a child which is of the type, or a subtype of the type named by str...
Body body
Associated physics Body, if it exists.
Definition: Actor.h:72
Body * getBody() const
Returns body.