Pie Noon
An open source project by FPL.
 All Classes Pages
controller.h
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef PIE_NOON_CONTROLLER_H_
16 #define PIE_NOON_CONTROLLER_H_
17 
18 #include <cstdint>
19 #include "common.h"
20 
21 namespace fpl {
22 namespace pie_noon {
23 
24 static const CharacterId kNoCharacter = -1;
25 
26 class Controller {
27  public:
28  enum ControllerType {
29  kTypeUndefined,
30  kTypePlayer,
31  kTypeAI,
32  kTypeGamepad,
33  kTypeTouchScreen,
34  kTypeCardboard,
35  kTypeMultiplayer
36  };
37 
38  explicit Controller(ControllerType controller_type = kTypeUndefined)
39  : is_down_(0u),
40  went_down_(0u),
41  went_up_(0u),
42  character_id_(kNoCharacter),
43  controller_type_(controller_type) {}
44 
45  virtual ~Controller() {}
46 
47  // Update the current state of this controller.
48  virtual void AdvanceFrame(WorldTime delta_time) = 0;
49 
50  ControllerType controller_type() const { return controller_type_; }
51 
52  // Returns the current set of active logical input bits.
53  uint32_t is_down() const { return is_down_; }
54  uint32_t went_down() const { return went_down_; }
55  uint32_t went_up() const { return went_up_; }
56 
57  // Updates a one or more bits.
58  void SetLogicalInputs(uint32_t bitmap, bool set);
59 
60  CharacterId character_id() const { return character_id_; }
61  void set_character_id(CharacterId new_id) { character_id_ = new_id; }
62 
63  CharacterId target_id() const { return target_id_; }
64  void set_target_id(CharacterId new_id) { target_id_ = new_id; }
65 
66  // Clear all the currently set logical inputs.
67  void ClearAllLogicalInputs();
68 
69  protected:
70  // A bitfield of currently active logical input bits.
71  uint32_t is_down_;
72  uint32_t went_down_;
73  uint32_t went_up_;
74  CharacterId character_id_; // the ID of the player we're controlling
75  CharacterId target_id_; // the ID of the player we want to target
76  ControllerType controller_type_;
77 };
78 
79 } // pie_noon
80 } // fpl
81 
82 #endif // PIE_NOON_CONTROLLER_H_
Definition: controller.h:26