~ubuntu-branches/ubuntu/natty/plee-the-bear/natty

« back to all changes in this revision

Viewing changes to bear-engine/lib/src/generic_items/timer.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Bear Engine
 
3
 
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
6
  This program is free software; you can redistribute it and/or modify it
 
7
  under the terms of the GNU General Public License as published by the
 
8
  Free Software Foundation; either version 2 of the License, or (at your
 
9
  option) any later version.
 
10
 
 
11
  This program is distributed in the hope that it will be useful, but WITHOUT
 
12
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
14
  more details.
 
15
 
 
16
  You should have received a copy of the GNU General Public License along
 
17
  with this program; if not, write to the Free Software Foundation, Inc.,
 
18
  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 
 
20
  contact: plee-the-bear@gamned.org
 
21
 
 
22
  Please add the tag [Bear] in the subject of your mails.
 
23
*/
 
24
/**
 
25
 * \file timer.hpp
 
26
 * \brief A simple timer.
 
27
 * \author Julien Jorge
 
28
 */
 
29
#ifndef __BEAR_TIMER_HPP__
 
30
#define __BEAR_TIMER_HPP__
 
31
 
 
32
#include "engine/base_item.hpp"
 
33
#include "engine/item_brick/item_with_toggle.hpp"
 
34
 
 
35
#include "universe/derived_item_handle.hpp"
 
36
 
 
37
#include "engine/export.hpp"
 
38
#include "generic_items/class_export.hpp"
 
39
 
 
40
namespace bear
 
41
{
 
42
  /**
 
43
   * \brief A simple timer.
 
44
   *
 
45
   * The custom fields of this class are :
 
46
   * - \a countdown (boolean): Indicates if the timer is a countdown
 
47
   *   (default = false),
 
48
   * - \a loop (boolean): tell if the timer restarts automatically when the
 
49
   *   time is over (default = false),
 
50
   * _ \a reset_when_reactivated : Indicates if the timer is initialized
 
51
   * when the timer is reactivated (default = true),
 
52
   * - \a time (real): the initial time, in seconds (default = 0),
 
53
   * - \a toggle (item): a toggle to toggle when the countdown is over
 
54
   *   (default = none),
 
55
   *
 
56
   * \author Julien Jorge
 
57
   */
 
58
  class GENERIC_ITEMS_EXPORT timer:
 
59
    public engine::item_with_toggle<engine::base_item>
 
60
  {
 
61
    DECLARE_BASE_ITEM(timer);
 
62
 
 
63
  public:
 
64
    /** \brief The type of the parent class. */
 
65
    typedef engine::item_with_toggle<engine::base_item> super;
 
66
 
 
67
  private:
 
68
    /** \brief An handle on a toggle. */
 
69
    typedef
 
70
      universe::derived_item_handle_maker<engine::with_toggle>::handle_type
 
71
      toggle_handle;
 
72
 
 
73
  public:
 
74
    timer();
 
75
 
 
76
    void progress_on( bear::universe::time_type elapsed_time );
 
77
 
 
78
    bool set_bool_field( const std::string& name, bool value );
 
79
    bool set_real_field( const std::string& name, double value );
 
80
    bool set_item_field( const std::string& name, engine::base_item* value );
 
81
 
 
82
    universe::time_type get_time() const;
 
83
    universe::time_type get_initial_time() const;
 
84
    universe::time_type get_elapsed_time() const;
 
85
    bool is_countdown() const;
 
86
    std::size_t get_loops() const;
 
87
 
 
88
    engine::base_item* get_toggle() const;
 
89
    void set_toggle( engine::base_item* t );
 
90
 
 
91
  private:
 
92
    void on_toggle_on( engine::base_item* activator );
 
93
 
 
94
  private:
 
95
    /** \brief Elapsed time since the creation of the item. */
 
96
    universe::time_type m_elapsed_time;
 
97
 
 
98
    /** \brief The initial time. */
 
99
    universe::time_type m_initial_time;
 
100
 
 
101
    /** \brief Indicates if the timer is a countdown. */
 
102
    bool m_countdown;
 
103
 
 
104
    /** \brief Tell if the timer restarts automatically on a timeout. */
 
105
    bool m_loop;
 
106
 
 
107
    /** \brief A toggle to be turned on when the timer is over. */
 
108
    toggle_handle m_toggle;
 
109
 
 
110
    /** \brief How many loops have we done. */
 
111
    std::size_t m_loops_count;
 
112
 
 
113
    /** \brief Indicates if the timer is initialized
 
114
     * when the timer is reactivated. */
 
115
    bool m_reset_when_reactivated;
 
116
  }; // class timer
 
117
} // namespace bear
 
118
 
 
119
#endif // __BEAR_TIMER_HPP__