CrystalSpace

Public API Reference

csutil/timer.h
Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2003 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_TIMER_H__
00020 #define __CS_TIMER_H__
00021 
00026 #include <stdarg.h>
00027 #include <stdio.h>
00028 #include "csextern.h"
00029 #include "csutil/array.h"
00030 #include "csutil/scf_implementation.h"
00031 #include "iutil/timer.h"
00032 #include "iutil/eventnames.h"
00033 #include "iutil/virtclk.h"
00034 
00035 struct iEvent;
00036 struct iObjectRegistry;
00037 struct iEventHandler;
00038 
00043 class CS_CRYSTALSPACE_EXPORT csEventTimer : 
00044   public scfImplementation1<csEventTimer, iEventTimer>
00045 {
00046 private:
00047   struct timerevent
00048   {
00049     csRef<iTimerEvent> event;
00050     csTicks delay;
00051     int time_left;
00052   };
00053   iObjectRegistry* object_reg;
00054   csEventID Frame;
00055   csArray<timerevent> timerevents;
00056   iEventHandler* handler;
00057   csRef<iVirtualClock> vc;
00058 
00059   size_t FindTimerEvent (iTimerEvent* ev);
00060 
00061   // Optimization: to prevent having to loop over all timer events
00062   // all the time we keep the minimum time needed before the first
00063   // event is triggered.
00064   int32 minimum_time;
00065   int32 accumulate_elapsed;
00066 
00067 public:
00068   csEventTimer (iObjectRegistry* object_reg);
00069   virtual ~csEventTimer ();
00070 
00071   bool HandleEvent (iEvent& e);
00072 
00073   virtual void AddTimerEvent (iTimerEvent* ev, csTicks delay);
00074   virtual void RemoveTimerEvent (iTimerEvent* ev);
00075   virtual void RemoveAllTimerEvents ();
00076 
00077   virtual size_t GetEventCount () const { return timerevents.GetSize (); }
00078   virtual csTicks GetTimeLeft (size_t idx) const;
00079 
00085   static csPtr<iEventTimer> GetStandardTimer (iObjectRegistry* object_reg);
00086 };
00087 
00088 #endif // __CS_TIMER_H__
00089 

Generated for Crystal Space 2.0 by doxygen 1.7.6.1