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(); }
private unsafe void ThreadProc() { Thread.CurrentThread.Name = "Entity creation thread"; HkBaseSystem.InitThread("Entity creation thread"); MyEntityIdentifier.InEntityCreationBlock = true; MyEntityIdentifier.InitPerThreadStorage(0x800); while (!this.m_exitting) { Item item; if (!this.ConsumeWork(out item)) { continue; } if (item.ReleaseMatrices != null) { foreach (Item item2 in this.m_waitingItems) { if (item2.WaitGroup == item.WaitGroup) { MatrixD xd; if (item.ReleaseMatrices.TryGetValue(item2.Result.EntityId, out xd)) { item2.Result.PositionComp.WorldMatrix = xd; } this.m_waitingItems.Remove(item2, false); this.m_resultQueue.Enqueue(item2); } } this.m_waitingItems.ApplyRemovals(); continue; } if (item.ObjectBuilder == null) { if (item.Result != null) { item.Result.DebugAsyncLoading = true; } if (item.WaitGroup == 0) { this.m_resultQueue.Enqueue(item); } else { this.m_waitingItems.Add(item); this.m_waitingItems.ApplyAdditions(); } continue; } if (item.Result == null) { Item *itemPtr1 = (Item *)ref item; itemPtr1->Result = MyEntities.CreateFromObjectBuilderNoinit(item.ObjectBuilder); } Item *itemPtr2 = (Item *)ref item; itemPtr2->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) { item.Result.Render.FadeIn = item.FadeIn; item.EntityIds = new List <IMyEntity>(); MyEntityIdentifier.GetPerThreadEntities(item.EntityIds); MyEntityIdentifier.ClearPerThreadEntities(); if (item.WaitGroup == 0) { this.m_resultQueue.Enqueue(item); } else { this.m_waitingItems.Add(item); this.m_waitingItems.ApplyAdditions(); } } } MyEntityIdentifier.DestroyPerThreadStorage(); HkBaseSystem.QuitThread(); }