File: Behavior.h

package info (click to toggle)
pinball 0.3.20201218-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 8,452 kB
  • sloc: cpp: 15,230; makefile: 840; sh: 381; xml: 24
file content (67 lines) | stat: -rw-r--r-- 2,846 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//#ident "$Id: Behavior.h,v 1.7 2003/05/27 11:53:24 rzr Exp $"
/***************************************************************************
                          Behavior.h  -  description
                             -------------------
    begin                : Wed Jan 26 2000
    copyright            : (C) 2000 by Henrik Enqvist GPL
    email                : henqvist@excite.com
 ***************************************************************************/

#ifndef BEHAVIOR_H
#define BEHAVIOR_H

#include "EMath.h"

class Group;
class Light;

/** You add behavior to your objects by creating a subclass to
 * the Behavior class and adding it to a group. All your AI-code, 
 * keyboard-logic should be in a behavior object (or be called from).
 * Important! On each engine tick the 'onTick' function is called first,
 * then the eventual 'onCollision' functions are called. And at last
 * the signals in the signal queue is sent to the 'onSignal' function.
 * Remember the order in which these functions are called when you debug
 * your behaviors. */
class Behavior {
 public:
  /** Simple constructor. You are supposed to create subclasses
   * and add the subclasses to the group. */
  Behavior();
  virtual ~Behavior() {}
  /** reset (needed for static libs) */
  virtual void clear() { m_iType = 0; }
  /** Override this method to create behavior that occurs on each render loop. */
  virtual void onTick() = 0;
  /** Override this method to create behavior that occurs on a collision.
   * @see Shape3D
   * @see CollisionBounds */
  virtual void onCollision(const Vertex3D & vtxWall, const Vertex3D & vtxOwn, Group * g) = 0;
  /** Called each time a signal i sent through the system.
   * Override this method to create behavior that occurs on a signal. */
  virtual void onSignal(int signal, Group * sender) = 0;
  /** Adds a light for subclasses to use. The light must before be added to a group.
   * and to the engine. */
  inline void setLight(Light * l) { p_Light = l; };
  /** Returns to light added the behavior. Returns NULL if no light added. */
  inline Light * getLight() { return p_Light; };
  /** Gets the user defined type for this behavior. Subclasses should set
   * type to a unique id. Defaults to 0. */ 
  inline int getType() { return m_iType; };
  /** Gets the parent group for this behavior. The behavior must be added to
   * a group before we can use this. */
  inline Group * getParent() { return p_Parent; };
 protected:
  /** Subclasses uses this funcition to set the behavior type. */
  inline void setType(int t) { m_iType = t; };
 private:
  friend class Group;
  /** Only for internal use. The Group class uses this when a
   * behavior is added to the group. */
  inline void setParent(Group * g) { p_Parent = g;	};
  Light * p_Light;
  Group * p_Parent;
  int m_iType;
};

#endif // BEHAVIOR_H