/[adonthell]/adonthell/src/event/time_event.cc
ViewVC logotype

Diff of /adonthell/src/event/time_event.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by ksterker, Tue Dec 7 16:46:27 2004 UTC revision 1.6 by ksterker, Tue Mar 8 09:41:47 2005 UTC
# Line 1  Line 1 
1  /*  /*
2     $Id$     $Id$
3    
4     Copyright (C) 2002/2003/2004 Kai Sterker <kaisterker@linuxgames.com>     Copyright (C) 2002/2003/2004 Kai Sterker <kaisterker@linuxgames.com>
5     Part of the Adonthell Project http://adonthell.linuxgames.com     Part of the Adonthell Project http://adonthell.linuxgames.com
6    
7     Adonthell is free software; you can redistribute it and/or modify     Adonthell is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.     (at your option) any later version.
11    
12     Adonthell is distributed in the hope that it will be useful,     Adonthell is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
18     along with Adonthell; if not, write to the Free Software     along with Adonthell; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */  */
21    
22  /**  /**
23   * @file event/time_event.cc   * @file event/time_event.cc
24   *   *
25   * @author Kai Sterker   * @author Kai Sterker
26   * @brief Implements the time_event class.   * @brief Implements the time_event class.
27   */   */
28    
29  #include "event/time_event.h"  #include "event/time_event.h"
30  #include "event/date.h"  #include "event/date.h"
31    
32  using events::date;  using events::date;
33  using events::time_event;  using events::time_event;
34    
35  // create a new time event  // create a new time event
36  time_event::time_event (const string & time, bool absolute)  time_event::time_event (const string & time, bool absolute) : event ()
37  {  {
38      Repeat = 1;      Repeat = 1;
39      Type = TIME_EVENT;      Absolute = absolute;
40      Absolute = absolute;      Time = date::parse_time (time);
41      Time = date::parse_time (time);      if (!absolute) Time += date::time ();
42      if (!absolute) Time += date::time ();  }
43  }  
44    // specify the interval between two occurances of the event
45  // specify the interval between two occurances of the event  void time_event::set_repeat (const string & interval, s_int32 count)
46  void time_event::set_repeat (const string & interval, s_int32 count)  {
47  {      Interval = date::parse_time (interval);
48      Interval = date::parse_time (interval);      Repeat = count;
49      Repeat = count;  }
50  }  
51    // Save time event to file
52  // Save time event to file  void time_event::put_state (base::flat & out) const
53  void time_event::put_state (base::flat & out) const  {
54  {      // save basic event data first
55      // save basic event data first      event::put_state (out);
56      event::put_state (out);      
57            // save time event data
58      // save time event data      out.put_uint32 ("ttm", Time);
59      out.put_uint32 ("ttm", Time);      out.put_uint32 ("tin", Interval);
60      out.put_uint32 ("tin", Interval);      out.put_bool ("tab", Absolute);
61      out.put_bool ("tab", Absolute);  }
62  }  
63    // load time event from file
64  // load time event from file  bool time_event::get_state (base::flat & in)
65  bool time_event::get_state (base::flat & in)  {
66  {      // get basic event data
67      // get basic event data      if (event::get_state (in))
68      if (event::get_state (in))      {  
69      {            // get time event data
70          // get time event data          Time = in.get_uint32 ("ttm");
71          Time = in.get_uint32 ("ttm");          Interval = in.get_uint32 ("tin");
72          Interval = in.get_uint32 ("tin");          Absolute = in.get_bool ("tab");
73          Absolute = in.get_bool ("tab");      }
74      }      return in.success ();
75      return in.success ();  }
76  }  
77    void time_event::do_repeat ()
78  void time_event::do_repeat ()  {
79  {      // don't repeat multiple times after being resumed
80      // don't repeat multiple times after being resumed      while (Time <= date::time ()) Time += Interval;
81      while (Time <= date::time ()) Time += Interval;      event::do_repeat ();
82      event::do_repeat ();  }
83  }  
   

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26