SuperTuxKart
user_pointer.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2007-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_USER_POINTER_HPP
20 #define HEADER_USER_POINTER_HPP
21 
25 class AbstractKart;
26 class Flyable;
27 class Moveable;
28 class PhysicalObject;
29 class ThreeDAnimation;
30 class TriangleMesh;
31 
36 {
37 public:
40  enum UserPointerType {UP_UNDEF, UP_KART, UP_FLYABLE, UP_TRACK,
41  UP_PHYSICAL_OBJECT, UP_ANIMATION};
42 private:
43  void* m_pointer;
44  UserPointerType m_user_pointer_type;
45 public:
46  bool is(UserPointerType t) const {return m_user_pointer_type==t; }
47  TriangleMesh* getPointerTriangleMesh() const {return (TriangleMesh*)m_pointer; }
48  Moveable* getPointerMoveable() const {return (Moveable*)m_pointer; }
49  Flyable* getPointerFlyable() const {return (Flyable*)m_pointer; }
50  AbstractKart* getPointerKart() const {return (AbstractKart*)m_pointer; }
51  PhysicalObject *getPointerPhysicalObject() const {return (PhysicalObject*)m_pointer; }
52  ThreeDAnimation*getPointerAnimation() const {return (ThreeDAnimation*)m_pointer;}
53  void set(PhysicalObject* p) { m_user_pointer_type=UP_PHYSICAL_OBJECT;
54  m_pointer =p; }
55  void set(AbstractKart* p) { m_user_pointer_type=UP_KART;
56  m_pointer =p; }
57  void set(Flyable* p) { m_user_pointer_type=UP_FLYABLE;
58  m_pointer =p; }
59  void set(TriangleMesh* p) { m_user_pointer_type=UP_TRACK;
60  m_pointer =p; }
61  void set(ThreeDAnimation* p){ m_user_pointer_type=UP_ANIMATION;
62  m_pointer =p; }
63  UserPointer() { zero(); }
64  void zero() { m_user_pointer_type=UP_UNDEF;
65  m_pointer = NULL; }
66 };
67 #endif
68 /* EOF */
69 
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Definition: flyable.hpp:50
Definition: moveable.hpp:46
Definition: physical_object.hpp:40
A virtual base class for all animations.
Definition: three_d_animation.hpp:45
A special class to store a triangle mesh with a separate material per triangle.
Definition: triangle_mesh.hpp:35
A UserPointer is stored as a user pointer in all bullet bodies.
Definition: user_pointer.hpp:36
UserPointerType
List of all possibles STK objects that are represented in the physics.
Definition: user_pointer.hpp:40