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 static MyEntity Spawn(ref MyPhysicalInventoryItem item, Vector3 position, Vector3 speed) { var builder = PrepareBuilder(ref item); var meteorEntity = MyEntities.CreateFromObjectBuilderNoinit(builder, false); MyEntities.CreateFromObjectBuilderParallel(builder, true, delegate() { SetSpawnSettings(meteorEntity, position, speed); }, meteorEntity); return(meteorEntity); }
IMyEntity IMyEntities.CreateFromObjectBuilderNoinit(Common.ObjectBuilders.MyObjectBuilder_EntityBase objectBuilder) { return(MyEntities.CreateFromObjectBuilderNoinit(objectBuilder)); }
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(); }
protected override void OnLoad(BitStream stream, Action <MyVoxelBase> loadingDoneHandler) { MyVoxelBase voxelMap; bool isUserCreated = VRage.Serialization.MySerializer.CreateAndRead <bool>(stream); bool isFromPrefab = VRage.Serialization.MySerializer.CreateAndRead <bool>(stream); bool rangeChanged = VRage.Serialization.MySerializer.CreateAndRead <bool>(stream); byte[] data = null; string asteroidName = null; if (rangeChanged) { data = VRage.Serialization.MySerializer.CreateAndRead <byte[]>(stream); } else if (isUserCreated) { asteroidName = VRage.Serialization.MySerializer.CreateAndRead <string>(stream); } if (isFromPrefab) { var builder = VRage.Serialization.MySerializer.CreateAndRead <MyObjectBuilder_EntityBase>(stream, MyObjectBuilderSerializer.Dynamic); if (rangeChanged && data != null) { IMyStorage storage = MyStorageBase.Load(data); if (MyEntities.TryGetEntityById <MyVoxelBase>(builder.EntityId, out voxelMap)) { if (voxelMap is MyVoxelMap) { ((MyVoxelMap)voxelMap).Storage = storage; } else if (voxelMap is MyPlanet) { ((MyPlanet)voxelMap).Storage = storage; } else { Debug.Fail("Unknown voxel kind"); } } else { voxelMap = (MyVoxelBase)MyEntities.CreateFromObjectBuilderNoinit(builder); if (voxelMap is MyVoxelMap) { ((MyVoxelMap)voxelMap).Init(builder, storage); } else if (voxelMap is MyPlanet) { ((MyPlanet)voxelMap).Init(builder, storage); } else { Debug.Fail("Unknown voxel kind"); } if (voxelMap != null) { MyEntities.Add(voxelMap); } } } else if (isUserCreated) { TryRemoveExistingEntity(builder.EntityId); IMyStorage storage = MyGuiScreenDebugSpawnMenu.CreateAsteroidStorage(asteroidName, 0); voxelMap = (MyVoxelBase)MyEntities.CreateFromObjectBuilderNoinit(builder); if (voxelMap is MyVoxelMap) { ((MyVoxelMap)voxelMap).Init(builder, storage); } if (voxelMap != null) { MyEntities.Add(voxelMap); } } else { TryRemoveExistingEntity(builder.EntityId); voxelMap = (MyVoxelBase)MyEntities.CreateFromObjectBuilderNoinit(builder); if (voxelMap != null) { voxelMap.Init(builder); MyEntities.Add(voxelMap); } } } else { long voxelMapId = VRage.Serialization.MySerializer.CreateAndRead <long>(stream); MyEntities.TryGetEntityById <MyVoxelBase>(voxelMapId, out voxelMap); } if (voxelMap != null) { BoundingBoxD voxelBox = new BoundingBoxD(voxelMap.PositionLeftBottomCorner, voxelMap.PositionLeftBottomCorner + voxelMap.SizeInMetres); m_entities = MyEntities.GetEntitiesInAABB(ref voxelBox); foreach (var entity in m_entities) { MyVoxelBase voxel = entity as MyVoxelBase; if (voxel != null) { if (voxel.Save == false && voxel != voxelMap) { voxel.Close(); break; } } } m_entities.Clear(); } loadingDoneHandler(voxelMap); }
protected override void OnLoad(BitStream stream, Action <MyVoxelBase> loadingDoneHandler) { MyVoxelBase voxelMap; bool isUserCreated = VRage.Serialization.MySerializer.CreateAndRead <bool>(stream); bool isFromPrefab = VRage.Serialization.MySerializer.CreateAndRead <bool>(stream); bool rangeChanged = VRage.Serialization.MySerializer.CreateAndRead <bool>(stream); byte[] data = null; string asteroidName = null; if (rangeChanged) { data = VRage.Serialization.MySerializer.CreateAndRead <byte[]>(stream); } else if (isUserCreated) { asteroidName = VRage.Serialization.MySerializer.CreateAndRead <string>(stream); } if (isFromPrefab) { var builder = VRage.Serialization.MySerializer.CreateAndRead <MyObjectBuilder_EntityBase>(stream, MyObjectBuilderSerializer.Dynamic); if (rangeChanged && data != null) { IMyStorage storage = MyStorageBase.Load(data); if (MyEntities.TryGetEntityById <MyVoxelBase>(builder.EntityId, out voxelMap)) { if (voxelMap is MyVoxelMap) { ((MyVoxelMap)voxelMap).Storage = storage; } else if (voxelMap is MyPlanet) { ((MyPlanet)voxelMap).Storage = storage; } else { Debug.Fail("Unknown voxel kind"); } } else { voxelMap = (MyVoxelBase)MyEntities.CreateFromObjectBuilderNoinit(builder); if (voxelMap is MyVoxelMap) { ((MyVoxelMap)voxelMap).Init(builder, storage); } else if (voxelMap is MyPlanet) { ((MyPlanet)voxelMap).Init(builder, storage); } else { Debug.Fail("Unknown voxel kind"); } MyEntities.Add(voxelMap); } } else if (isUserCreated) { TryRemoveExistingEntity(builder.EntityId); IMyStorage storage = MyGuiScreenDebugSpawnMenu.CreateAsteroidStorage(asteroidName, 0); voxelMap = (MyVoxelBase)MyEntities.CreateFromObjectBuilderNoinit(builder); if (voxelMap is MyVoxelMap) { ((MyVoxelMap)voxelMap).Init(builder, storage); } MyEntities.Add(voxelMap); } else { TryRemoveExistingEntity(builder.EntityId); voxelMap = (MyVoxelBase)MyEntities.CreateFromObjectBuilderNoinit(builder); voxelMap.Init(builder); MyEntities.Add(voxelMap); } } else { long voxelMapId = VRage.Serialization.MySerializer.CreateAndRead <long>(stream); MyEntities.TryGetEntityById <MyVoxelBase>(voxelMapId, out voxelMap); } loadingDoneHandler(voxelMap); }