2009-11-13 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / timemanager.h
blob2ff1a1dd15cb8b2d949bbdafc3ab7f5af986ccce
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 /* @Namespace=None,ManagedEvents=Manual */
24 class TimeManager : public EventObject {
25 public:
26 TimeManager ();
28 void Start ();
29 void Stop ();
31 void Shutdown ();
33 TimeSource *GetSource() { return source; }
35 void AddClock (Clock *clock);
37 virtual TimeSpan GetCurrentTime () { return current_global_time - start_time; }
38 virtual TimeSpan GetLastTime () { return last_global_time - start_time; }
39 TimeSpan GetCurrentTimeUsec () { return current_global_time_usec - start_time_usec; }
41 /* @GenerateCBinding,GeneratePInvoke */
42 void AddTickCall (TickCallHandler handler, EventObject *tick_data);
43 /* @GenerateCBinding,GeneratePInvoke */
44 void RemoveTickCall (TickCallHandler handler, EventObject *tick_data);
45 /* @GenerateCBinding,GeneratePInvoke */
46 void AddDispatcherCall (TickCallHandler handler, EventObject *tick_data);
48 void NeedRedraw ();
49 void NeedClockTick ();
51 void InvokeTickCalls ();
53 /* @GenerateCBinding, GeneratePInvoke */
54 guint AddTimeout (gint priority, guint ms_interval, GSourceFunc func, gpointer timeout_data);
55 /* @GenerateCBinding, GeneratePInvoke */
56 void RemoveTimeout (guint timeout_id);
58 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal,Version=2 */
59 void SetMaximumRefreshRate (int hz);
60 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal,Version=2 */
61 int GetMaximumRefreshRate () { return max_fps; }
63 // Events you can AddHandler to
64 const static int UpdateInputEvent;
65 const static int RenderEvent;
67 void ListClocks ();
68 Applier* GetApplier () { return applier; }
70 protected:
71 virtual ~TimeManager ();
73 private:
75 TimelineGroup *timeline;
76 ClockGroup *root_clock;
77 Applier *applier;
79 void SourceTick ();
81 void RemoveAllRegisteredTimeouts ();
83 TimeSpan current_global_time;
84 TimeSpan last_global_time;
85 TimeSpan start_time;
87 TimeSpan current_global_time_usec;
88 TimeSpan start_time_usec;
90 static void source_tick_callback (EventObject *sender, EventArgs *calldata, gpointer closure);
91 bool source_tick_pending;
92 int current_timeout;
93 int max_fps;
94 bool first_tick;
95 bool emitting;
97 TimeSpan previous_smoothed;
99 enum TimeManagerOp {
100 TIME_MANAGER_UPDATE_CLOCKS = 0x01,
101 TIME_MANAGER_RENDER = 0x02,
102 TIME_MANAGER_TICK_CALL = 0x04,
103 TIME_MANAGER_UPDATE_INPUT = 0x08
106 TimeManagerOp flags;
108 TimeSource *source;
110 Queue tick_calls;
111 Queue dispatcher_calls;
113 GList *registered_timeouts;
116 G_BEGIN_DECLS
118 bool find_tick_call (List::Node *node, void *data);
120 G_END_DECLS
122 #endif /* MOON_TIMEMANAGER_H */