2009-10-09 Chris Toshok <toshok@ximian.com>
[moon.git] / src / timemanager.h
blobad42b61a2aec5b73ecf64d72349cc672fb53754a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Contact:
4 * Moonlight List (moonlight-list@lists.ximian.com)
6 * Copyright 2007 Novell, Inc. (http://www.novell.com)
8 * See the LICENSE file included with the distribution for details.
9 *
12 #ifndef MOON_TIMEMANAGER_H
13 #define MOON_TIMEMANAGER_H
15 #include <glib.h>
17 #include "applier.h"
18 #include "timesource.h"
19 #include "dependencyobject.h"
21 // our root level time manager (basically the object that registers
22 // the gtk_timeout and drives all Clock objects
23 class TimeManager : public EventObject {
24 public:
25 TimeManager ();
27 void Start ();
28 void Stop ();
30 void Shutdown ();
32 TimeSource *GetSource() { return source; }
34 void AddClock (Clock *clock);
36 virtual TimeSpan GetCurrentTime () { return current_global_time - start_time; }
37 virtual TimeSpan GetLastTime () { return last_global_time - start_time; }
38 TimeSpan GetCurrentTimeUsec () { return current_global_time_usec - start_time_usec; }
40 /* @GenerateCBinding,GeneratePInvoke */
41 void AddTickCall (TickCallHandler handler, EventObject *tick_data);
42 /* @GenerateCBinding,GeneratePInvoke */
43 void RemoveTickCall (TickCallHandler handler, EventObject *tick_data);
45 void NeedRedraw ();
46 void NeedClockTick ();
48 void InvokeTickCalls ();
50 /* @GenerateCBinding, GeneratePInvoke */
51 guint AddTimeout (gint priority, guint ms_interval, GSourceFunc func, gpointer timeout_data);
52 /* @GenerateCBinding, GeneratePInvoke */
53 void RemoveTimeout (guint timeout_id);
55 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal,Version=2 */
56 void SetMaximumRefreshRate (int hz);
57 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal,Version=2 */
58 int GetMaximumRefreshRate () { return max_fps; }
60 // Events you can AddHandler to
61 const static int UpdateInputEvent;
62 const static int RenderEvent;
64 void ListClocks ();
65 Applier* GetApplier () { return applier; }
67 protected:
68 virtual ~TimeManager ();
70 private:
72 TimelineGroup *timeline;
73 ClockGroup *root_clock;
74 Applier *applier;
76 void SourceTick ();
78 void RemoveAllRegisteredTimeouts ();
80 bool InvokeTickCall ();
82 TimeSpan current_global_time;
83 TimeSpan last_global_time;
84 TimeSpan start_time;
86 TimeSpan current_global_time_usec;
87 TimeSpan start_time_usec;
89 static void source_tick_callback (EventObject *sender, EventArgs *calldata, gpointer closure);
90 bool source_tick_pending;
91 int current_timeout;
92 int max_fps;
93 bool first_tick;
95 TimeSpan previous_smoothed;
97 enum TimeManagerOp {
98 TIME_MANAGER_UPDATE_CLOCKS = 0x01,
99 TIME_MANAGER_RENDER = 0x02,
100 TIME_MANAGER_TICK_CALL = 0x04,
101 TIME_MANAGER_UPDATE_INPUT = 0x08
104 TimeManagerOp flags;
106 TimeSource *source;
108 Queue tick_calls;
110 GList *registered_timeouts;
113 G_BEGIN_DECLS
115 bool find_tick_call (List::Node *node, void *data);
117 G_END_DECLS
119 #endif /* MOON_TIMEMANAGER_H */