~and471/+junk/do-with-docky

« back to all changes in this revision

Viewing changes to Do/src/Do.Core/UniverseManager.cs

  • Committer: rugby471 at gmail
  • Date: 2010-10-15 16:08:38 UTC
  • Revision ID: rugby471@gmail.com-20101015160838-z9m3utbf7bxzb5ty
reverted to before docky removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
                UniverseCollection universe;
41
41
                EventHandler initialized;
42
42
                object universe_lock;
43
 
                ManualResetEvent reload_requested;
44
 
 
 
43
                
45
44
                const float epsilon = 0.00001f;
46
45
                
47
46
                /// <value>
81
80
                {
82
81
                        universe = new UniverseCollection ();
83
82
                        universe_lock = new object ();
84
 
                        reload_requested = new ManualResetEvent (false);
85
83
 
86
84
                        update_thread = new Thread (new ThreadStart (UniverseUpdateLoop));
87
85
                        update_thread.IsBackground = true;
88
86
                        update_thread.Priority = ThreadPriority.Lowest;
89
 
                        update_thread.Name = "Universe Update Dispatcher";
90
87
                        
91
88
                        Services.Network.StateChanged += OnNetworkStateChanged;
92
89
                }
118
115
                }
119
116
 
120
117
                public IEnumerable<Item> Search (string query, IEnumerable<Type> filter)
121
 
                {
 
118
                {       
122
119
                        return Search (query, filter, (Item) null);
123
120
                }
124
121
                
165
162
                void UniverseUpdateLoop ()
166
163
                {
167
164
                        Random rand = new Random ();
168
 
                        DateTime startUpdate;
 
165
                        DateTime startUpdate = DateTime.UtcNow;
169
166
 
170
167
                        while (true) {
171
 
                                if (reload_requested.WaitOne (UpdateTimeout)) {
172
 
                                        // We've been asked to do a full reload.  Kick this off, then go back to waiting for the timeout.
173
 
                                        reload_requested.Reset ();
174
 
                                        ReloadUniverse ();
175
 
                                        continue;
176
 
                                }
177
 
 
178
 
                                if (Do.Controller.IsSummoned)
179
 
                                        continue;
 
168
                                Thread.Sleep (UpdateTimeout);
 
169
                                if (Do.Controller.IsSummoned) continue;
180
170
                                startUpdate = DateTime.UtcNow;
181
 
 
 
171
                                
182
172
                                if (rand.Next (10) == 0) {
183
173
                                        ReloadActions (universe);
184
174
                                }
185
 
 
 
175
                                
186
176
                                foreach (ItemSource source in PluginManager.ItemSources) {
187
177
                                        ReloadSource (source, universe);
188
 
 
 
178
                                        
189
179
                                        if (UpdateRunTime < DateTime.UtcNow - startUpdate) {
190
 
                                                // We've exhausted our update timer.  Continue after UpdateTimeout.
191
 
                                                if (reload_requested.WaitOne (UpdateTimeout)) {
192
 
                                                        // We've been asked to reload the universe; break back to the start of the loop
193
 
                                                        break;
194
 
                                                }
195
 
                                                // Start the update timer again, and continue reloading sources…
 
180
                                                Thread.Sleep (UpdateTimeout);
 
181
                                                // sleeping for a bit
196
182
                                                startUpdate = DateTime.UtcNow;
197
183
                                        }
198
184
                                }
322
308
                /// </summary>
323
309
                public void Reload ()
324
310
                {
325
 
                        Log<UniverseManager>.Info ("Requesting universe reload");
326
 
                        reload_requested.Set ();
 
311
                        Services.Application.RunOnThread (ReloadUniverse);
327
312
                }
328
313
        }
329
314
}