public void UpdateLoop(object frameTotalTime) { int frameTime = (int)frameTotalTime; // 20 ms -> 50 fps Timer timer = new Timer(); timer.Reset(); uint start, end; start = timer.Milliseconds; float timeSinceLastFrame; while (updater.IsAlive) { Monitor.Enter(HydraxManager.Singleton); try { if (stopUpdater) { return; } } finally { Monitor.Exit(HydraxManager.Singleton); } int sleepTime = 50; if (hydrax != null && hydrax.IsCreated) { timeSinceLastFrame = (timer.Milliseconds - start) / 1000.0f; // w sekundach start = timer.Milliseconds; Monitor.Enter(HydraxManager.Singleton); hydrax.Update(timeSinceLastFrame); Monitor.Exit(HydraxManager.Singleton); end = timer.Milliseconds; int duration = (int)(end - start); sleepTime = frameTime - duration; if (sleepTime < 0) { sleepTime = 1; } } Thread.Sleep(sleepTime); } }
private AdManager() { if (EngineConfig.IsEnhancedVersion || EngineConfig.AdManagerDisabled) { return; } timer.Reset(); adAction = new CommercialAdAction(); adHelper3D = new AdHelper3D(0.02f, 80, 2000, 2); int result = AdAction.Init(C_AD_KEY, C_ADS_DIR, C_CONNECT_TIMEOUT); if (result == 0) { } }
public AdStatus GatherAsyncResult(int id, int downloadMsTimeout, out Ad outAd) { outAd = null; if (EngineConfig.IsEnhancedVersion || EngineConfig.AdManagerDisabled) { return(AdStatus.ADS_DISABLED); } if (downloadingAds.ContainsKey(id)) { // jeszcze nie skonczono Timer timer = new Timer(); timer.Reset(); uint start, end; start = timer.Milliseconds; for (; downloadingAds[id];) { // System.Console.Write("."); Work(null); System.Threading.Thread.Sleep(100); end = timer.Milliseconds; if (end - start > downloadMsTimeout) { return(AdStatus.TIMEOUT); } } } else { return(AdStatus.DOWNLOAD_FAILED); } // przypisz dopiero co sciagnieta reklame outAd = ads.Find(delegate(Ad ad) { return(ad.id.Equals(id)); }); return(AdStatus.OK); }
/// <summary> /// /// </summary> /// <param name="zone"></param> /// <param name="downloadMsTimeout"></param> /// <param name="allowedSizes">Jesli null to nie ma ograniczenia wielkosci</param> /// <param name="adDownloadedCallback"></param> /// <returns></returns> public AdStatus GetAd(string zone, int downloadMsTimeout, float ratio, AdManaged.AdDownloaded adDownloadedCallback, out Ad outAd) { outAd = null; if (EngineConfig.IsEnhancedVersion || EngineConfig.AdManagerDisabled) { return(AdStatus.ADS_DISABLED); } int id1 = 0; try { id1 = adAction.Get_Ad_For_Zone(zone, ratio); // Console.WriteLine(id1); } catch (Exception ex) { return(AdStatus.DOWNLOAD_FAILED); } Timer timer = new Timer(); timer.Reset(); uint start, end; start = timer.Milliseconds; if (id1 != 0) { // jesli są reklamy downloadingAds[id1] = true; try { if (!adAction.Download_Ad(id1, adDownloadedCallback)) { return(AdStatus.DOWNLOAD_FAILED); } } catch (Exception ex) { return(AdStatus.DOWNLOAD_FAILED); } // System.Console.Write("Downloading " + id1); for (; downloadingAds[id1];) { // System.Console.Write("."); Work(null); System.Threading.Thread.Sleep(100); end = timer.Milliseconds; if (end - start > downloadMsTimeout) { return(AdStatus.TIMEOUT); } } // przypisz dopiero co sciagnieta reklame outAd = ads.Find(delegate(Ad ad) { return(ad.id.Equals(id1)); }); return(AdStatus.OK); } return(AdStatus.NO_ADS); }
public static void Initialize(SceneViewModel view) { _sceneNodeStore = new SceneNodeStore(); _host = new System.Windows.Forms.Integration.WindowsFormsHost(); _panel = new Panel(); _panel.Name = "MogrePanel"; _panel.Location = new System.Drawing.Point(0, 0); _panel.Size = new System.Drawing.Size((int)view.View.RenderWindow.Width, (int)view.View.RenderWindow.Height); //_panel.Resize += _panel_Resize; _keyboardHandler = new KeyboardHandler(_host, _panel); _mouseHandler = new MouseHandler(_host, _panel); _host.Child = _panel; view.View.RenderWindow.Children.Add(_host); FlexUtility.SpawnThread(() => { RunOnUIThread(() => { _renderer = new MogreRenderer(_panel.Handle.ToString(), (uint)_panel.Width, (uint)_panel.Height); _renderer.CreateScene(); while (_preInitializationActions.Count != 0) { _preInitializationActions.Dequeue().Invoke(); } _mouseHandler.Initialize(); _keyboardHandler.Initialize(); _initialized = true; FlexUtility.SpawnThread(() => { _renderThread = Thread.CurrentThread; Mogre.Timer timer = new Mogre.Timer(); int attemptedFrameRate = 60; bool physicsRender = true; while (true) { while (_renderDispatcherActionQueue.Count != 0) { System.Action action; lock (_renderDispatcherActionQueue) { action = _renderDispatcherActionQueue.Dequeue(); } if (action != null) { action.Invoke(); } } lock (_renderNextDispatcherActionQueue) { lock (_renderDispatcherActionQueue) { while (_renderNextDispatcherActionQueue.Count != 0) { _renderDispatcherActionQueue.Enqueue(_renderNextDispatcherActionQueue.Dequeue()); } } } uint elapsed = timer.Milliseconds; timer.Reset(); int wait = (int)((1000 / attemptedFrameRate) - elapsed); if (wait > 0) { Thread.Sleep(wait); } _keyboardHandler.KeyboardTick(); if (physicsRender) { PhysicsEngine.Step(); } physicsRender = !physicsRender; Renderer.Loop(); } }); }); }); }