4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
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.
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
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
20
contact: plee-the-bear@gamned.org
22
Please add the tag [Bear] in the subject of your mails.
26
* \brief A simple timer.
27
* \author Julien Jorge
29
#ifndef __BEAR_TIMER_HPP__
30
#define __BEAR_TIMER_HPP__
32
#include "engine/base_item.hpp"
33
#include "engine/item_brick/item_with_toggle.hpp"
35
#include "universe/derived_item_handle.hpp"
37
#include "engine/export.hpp"
38
#include "generic_items/class_export.hpp"
43
* \brief A simple timer.
45
* The custom fields of this class are :
46
* - \a countdown (boolean): Indicates if the timer is a countdown
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
56
* \author Julien Jorge
58
class GENERIC_ITEMS_EXPORT timer:
59
public engine::item_with_toggle<engine::base_item>
61
DECLARE_BASE_ITEM(timer);
64
/** \brief The type of the parent class. */
65
typedef engine::item_with_toggle<engine::base_item> super;
68
/** \brief An handle on a toggle. */
70
universe::derived_item_handle_maker<engine::with_toggle>::handle_type
76
void progress_on( bear::universe::time_type elapsed_time );
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 );
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;
88
engine::base_item* get_toggle() const;
89
void set_toggle( engine::base_item* t );
92
void on_toggle_on( engine::base_item* activator );
95
/** \brief Elapsed time since the creation of the item. */
96
universe::time_type m_elapsed_time;
98
/** \brief The initial time. */
99
universe::time_type m_initial_time;
101
/** \brief Indicates if the timer is a countdown. */
104
/** \brief Tell if the timer restarts automatically on a timeout. */
107
/** \brief A toggle to be turned on when the timer is over. */
108
toggle_handle m_toggle;
110
/** \brief How many loops have we done. */
111
std::size_t m_loops_count;
113
/** \brief Indicates if the timer is initialized
114
* when the timer is reactivated. */
115
bool m_reset_when_reactivated;
119
#endif // __BEAR_TIMER_HPP__