2009-06-17 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / timemanager.h
blob5f4e82cf299b9ff04f458107c2387af20012f05a
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);
45 void NeedRedraw ();
46 void NeedClockTick ();
48 /* @GenerateCBinding, GeneratePInvoke */
49 guint AddTimeout (gint priority, guint ms_interval, GSourceFunc func, gpointer timeout_data);
50 /* @GenerateCBinding, GeneratePInvoke */
51 void RemoveTimeout (guint timeout_id);
53 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal,Version=2 */
54 void SetMaximumRefreshRate (int hz);
55 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal,Version=2 */
56 int GetMaximumRefreshRate () { return max_fps; }
58 // Events you can AddHandler to
59 const static int UpdateInputEvent;
60 const static int RenderEvent;
62 void ListClocks ();
63 Applier* GetApplier () { return applier; }
65 protected:
66 virtual ~TimeManager ();
68 private:
70 TimelineGroup *timeline;
71 ClockGroup *root_clock;
72 Applier *applier;
74 void SourceTick ();
76 void RemoveAllRegisteredTimeouts ();
78 bool InvokeTickCall ();
80 TimeSpan current_global_time;
81 TimeSpan last_global_time;
82 TimeSpan start_time;
84 TimeSpan current_global_time_usec;
85 TimeSpan start_time_usec;
87 static void source_tick_callback (EventObject *sender, EventArgs *calldata, gpointer closure);
88 bool source_tick_pending;
89 int current_timeout;
90 int max_fps;
91 bool first_tick;
93 TimeSpan previous_smoothed;
95 enum TimeManagerOp {
96 TIME_MANAGER_UPDATE_CLOCKS = 0x01,
97 TIME_MANAGER_RENDER = 0x02,
98 TIME_MANAGER_TICK_CALL = 0x04,
99 TIME_MANAGER_UPDATE_INPUT = 0x08
102 TimeManagerOp flags;
104 TimeSource *source;
106 Queue tick_calls;
108 GList *registered_timeouts;
111 G_BEGIN_DECLS
113 bool find_tick_call (List::Node *node, void *data);
115 G_END_DECLS
117 #endif /* MOON_TIMEMANAGER_H */