private void UpdateInternal() { using (Stats.Generic.Measure("BeforeUpdate")) { ProfilerShort.Begin("UpdateInternal::BeforeUpdate"); VRageRender.MyRenderProxy.BeforeUpdate(); ProfilerShort.End(); } ProfilerShort.Begin("UpdateInternal::Update"); //VRage.Trace.MyTrace.Send(VRage.Trace.TraceWindow.Default, "Update Start"); m_updateTime = m_gameTimer.Elapsed; Update(); ProfilerShort.End(); if (!IsDedicated) { ProfilerShort.Begin("UpdateInternal::PrepareForDraw"); PrepareForDraw(); ProfilerShort.End(); } using (Stats.Generic.Measure("AfterUpdate")) { ProfilerShort.Begin("UpdateInternal::AfterUpdate"); VRageRender.MyRenderProxy.AfterUpdate(m_updateTime); ProfilerShort.End(); } ProfilerShort.Commit(); MySimpleProfiler.Commit(); //VRage.Trace.MyTrace.Send(VRage.Trace.TraceWindow.Default, "Update End"); }
void ThreadProc() { Thread.CurrentThread.Name = "Entity creation thread"; HkBaseSystem.InitThread("Entity creation thread"); ProfilerShort.Autocommit = false; Item item; while (!m_exitting) { if (ConsumeWork(out item)) { if (item.Result == null) { item.Result = MyEntities.CreateFromObjectBuilderNoinit(item.ObjectBuilder); } item.InScene = (item.ObjectBuilder.PersistentFlags & MyPersistentEntityFlags2.InScene) == MyPersistentEntityFlags2.InScene; item.ObjectBuilder.PersistentFlags &= ~MyPersistentEntityFlags2.InScene; item.Result.DebugAsyncLoading = true; MyEntities.InitEntity(item.ObjectBuilder, ref item.Result); if (item.Result != null) { m_resultQueue.Enqueue(item); } } ProfilerShort.Commit(); } HkBaseSystem.QuitThread(); }
public override void Run(VoidAction tickCallback) { // 59.75 is sort of compensation long ticksPerFrame = (int)Math.Round(MyGameTimer.Frequency / 59.75f); long targetTicks = 0; MyLog.Default.WriteLine("Timer Frequency: " + MyGameTimer.Frequency); MyLog.Default.WriteLine("Ticks per frame: " + ticksPerFrame); ManualResetEventSlim waiter = new ManualResetEventSlim(false, 0); MyTimer.TimerEventHandler handler = new MyTimer.TimerEventHandler((a, b, c, d, e) => { waiter.Set(); }); base.Run(delegate { using (Stats.Generic.Measure("WaitForUpdate")) { var currentTicks = m_gameTimer.ElapsedTicks; // Wait for correct frame start targetTicks += ticksPerFrame; if (currentTicks > targetTicks + ticksPerFrame * 5) { // We're more behind than 5 frames, don't try to catch up targetTicks = currentTicks; } else { // For until correct tick comes if (MyFakes.ENABLE_UPDATE_WAIT) { var remaining = MyTimeSpan.FromTicks(targetTicks - currentTicks); int waitMs = (int)(remaining.Miliseconds - 0.1); // To handle up to 0.1ms inaccuracy of timer if (waitMs > 0) { waiter.Reset(); MyTimer.StartOneShot(waitMs, handler); waiter.Wait(17); // Never wait more than 17ms //Debug.Assert(MyPerformanceCounter.ElapsedTicks < targetTicks); //VRageRender.MyRenderStats.Write("WaitRemaining", (float)MyPerformanceCounter.TicksToMs(targetTicks - MyPerformanceCounter.ElapsedTicks), VRageRender.MyStatTypeEnum.MinMaxAvg, 300, 3); } } while (m_gameTimer.ElapsedTicks < targetTicks) { ; } } } //UpdateInternal(); tickCallback(); ProfilerShort.Commit(); }); }
/// <summary> /// Parallel thread - listener. /// </summary> private void ServerListenerProc() { Thread.CurrentThread.Name = "External Debugging Listener"; ProfilerShort.Autocommit = false; m_listener = new TcpListener(IPAddress.Any, GameDebugPort) { ExclusiveAddressUse = false }; try { m_listener.Start(); } catch (SocketException e) { MyLog.Default.WriteLine("Cannot start debug listener."); MyLog.Default.WriteLine(e); m_listener = null; m_active = false; return; } MyLog.Default.WriteLine("External debugger: listening..."); while (true) { try { var client = m_listener.AcceptTcpClient(); client.Client.Blocking = true; MyLog.Default.WriteLine("External debugger: accepted client."); m_clients.Add(new MyDebugClientInfo() { TcpClient = client, LastHeader = MyExternalDebugStructures.CommonMsgHeader.Create("UNKNOWN") }); m_clients.ApplyAdditions(); } catch (SocketException e) { if (e.SocketErrorCode == SocketError.Interrupted) { m_listener.Stop(); m_listener = null; MyLog.Default.WriteLine("External debugger: interrupted."); ProfilerShort.Commit(); ProfilerShort.DestroyThread(); return; } else { MyLog.Default.WriteLine(e); break; } } } m_listener.Stop(); m_listener = null; ProfilerShort.Commit(); ProfilerShort.DestroyThread(); }
private void UpdateInternal() { using (Stats.Generic.Measure("BeforeUpdate")) { ProfilerShort.Begin("UpdateInternal::BeforeUpdate"); VRageRender.MyRenderProxy.BeforeUpdate(); ProfilerShort.End(); } ProfilerShort.Begin("UpdateInternal::Update"); //VRage.Trace.MyTrace.Send(VRage.Trace.TraceWindow.Default, "Update Start"); m_updateTime = m_gameTimer.Elapsed; m_updateCounter++; if (VRage.MyCompilationSymbols.EnableNetworkPacketTracking) { System.Diagnostics.Debug.WriteLine("----- Tick # " + m_updateTime.Milliseconds); } Update(); ProfilerShort.End(); if (!IsDedicated) { ProfilerShort.Begin("UpdateInternal::PrepareForDraw"); PrepareForDraw(); ProfilerShort.End(); } using (Stats.Generic.Measure("AfterUpdate")) { ProfilerShort.Begin("UpdateInternal::AfterUpdate"); VRageRender.MyRenderProxy.AfterUpdate(m_updateTime); ProfilerShort.End(); } ProfilerShort.Commit(); MySimpleProfiler.Commit(); //VRage.Trace.MyTrace.Send(VRage.Trace.TraceWindow.Default, "Update End"); }
void ThreadProc() { Thread.CurrentThread.Name = "Entity creation thread"; HkBaseSystem.InitThread("Entity creation thread"); ProfilerShort.Autocommit = false; MyEntityIdentifier.InitPerThreadStorage(2048); Item item; while (!m_exitting) { if (ConsumeWork(out item)) { if (item.ObjectBuilder != null) { if (item.Result == null) { item.Result = MyEntities.CreateFromObjectBuilderNoinit(item.ObjectBuilder); } item.Result.SentFromServer = true; item.InScene = (item.ObjectBuilder.PersistentFlags & MyPersistentEntityFlags2.InScene) == MyPersistentEntityFlags2.InScene; item.ObjectBuilder.PersistentFlags &= ~MyPersistentEntityFlags2.InScene; item.Result.DebugAsyncLoading = true; MyEntities.InitEntity(item.ObjectBuilder, ref item.Result); if (item.Result != null) { if (item.SubgridBuilders != null) { item.SubGrids = new List <MyEntity>(); foreach (var subGridbulider in item.SubgridBuilders) { MyEntity subGrid = MyEntities.CreateFromObjectBuilderNoinit(subGridbulider); subGridbulider.PersistentFlags &= ~MyPersistentEntityFlags2.InScene; item.Result.DebugAsyncLoading = true; MyEntities.InitEntity(subGridbulider, ref subGrid); item.SubGrids.Add(subGrid); } item.SubgridBuilders.Clear(); item.SubgridBuilders = null; } item.EntityIds = new List <IMyEntity>(); MyEntityIdentifier.GetPerThreadEntities(item.EntityIds); MyEntityIdentifier.ClearPerThreadEntities(); m_resultQueue.Enqueue(item); } } else { if (item.Result != null) { item.Result.DebugAsyncLoading = true; } // This is ok, just invoking action asynchronously m_resultQueue.Enqueue(item); } } ProfilerShort.Commit(); } MyEntityIdentifier.DestroyPerThreadStorage(); HkBaseSystem.QuitThread(); ProfilerShort.DestroyThread(); }