Example #1
0
        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();
        }
            private bool Diff()
            {
                foreach (var ent in MyEntities.GetEntities())
                {
                    if ((ent.PositionComp.GetPosition() - MySession.Static.ControlledEntity.Entity.PositionComp.GetPosition()).Length() > 100)
                    {
                        ent.Close();
                    }
                }
                return(true);

                if (!m_snapA.HasValue)
                {
                    m_snapA = HkBaseSystem.GetMemorySnapshot();
                }
                else
                {
                    var snapB = HkBaseSystem.GetMemorySnapshot();
                    int a, b;
                    HkMemorySnapshot.Diff(m_snapA.Value, snapB, out a, out b);
                    //HkMemorySnapshot.Diff(m_snapA.Value, snapB);
                    m_snapA.Value.RemoveReference();
                    m_snapA = null;
                    snapB.RemoveReference();
                    m_memoryA = a;
                    m_memoryB = b;
                }
                return(true);
            }
        public ModelAssetTranslator(string root, string prefix)
        {
            _exportContentRoot = root;
            _exportPrefix      = prefix;


            HkBaseSystem.Init(new NamedLogger(NullLogger.Instance));
        }
Example #4
0
 private void PhysicsReset( )
 {
     try
     {
         //TODO - Find out the proper way to get Havok to clean everything up so we don't get pointer errors on the next start
         //HkBaseSystem.Quit();
         HkBaseSystem.Quit( );
     }
     catch (Exception)
     {
         //Do nothing for now
     }
 }
Example #5
0
 private bool Diff()
 {
     if (!m_snapA.HasValue)
     {
         m_snapA = HkBaseSystem.GetMemorySnapshot();
     }
     else
     {
         var snapB = HkBaseSystem.GetMemorySnapshot();
         int a, b;
         HkMemorySnapshot.Diff(m_snapA.Value, snapB, out a, out b);
         //HkMemorySnapshot.Diff(m_snapA.Value, snapB);
         m_snapA.Value.RemoveReference();
         m_snapA = null;
         snapB.RemoveReference();
         m_memoryA = a;
         m_memoryB = b;
     }
     return(true);
 }
Example #6
0
        public override void LoadData()
        {
            //HkBaseSystem.EnableAssert((int)0xd8279a05, false);
            HkBaseSystem.EnableAssert(-668493307, false);
            //HkBaseSystem.EnableAssert((int)3626473989, false);
            //float broadphaseSize = 100000.0f; // For unlimited worlds

            //Angular velocities and impulses
            HkBaseSystem.EnableAssert(952495168, false);
            HkBaseSystem.EnableAssert(1501626980, false);
            HkBaseSystem.EnableAssert(-258736554, false);
            HkBaseSystem.EnableAssert(524771844, false);
            HkBaseSystem.EnableAssert(1081361407, false);

            ThreadId = Thread.CurrentThread.ManagedThreadId;

            if (MyPerGameSettings.SingleCluster)
            {
                Clusters = new MyHavokCluster(MySession.Static.WorldBoundaries);
            }
            else
            {
                Clusters = new MyHavokCluster(null);
            }
            Clusters.OnClusterCreated += OnClusterCreated;
            Clusters.OnClusterRemoved += OnClusterRemoved;
            Clusters.OnFinishBatch    += OnFinishBatch;

            if (MyFakes.ENABLE_HAVOK_MULTITHREADING)
            {
                m_threadPool = new HkJobThreadPool();
                m_jobQueue   = new HkJobQueue(m_threadPool.ThreadCount + 1);
            }

            //Needed for smooth wheel movement
            HkCylinderShape.SetNumberOfVirtualSideSegments(128);
        }
        public static void FixPosition(MyFracturedPiece fp)
        {
            //return;
            ProfilerShort.Begin("FixPosition");
            var shape = fp.Physics.BreakableBody.BreakableShape;

            if (shape.GetChildrenCount() == 0)
            {
                ProfilerShort.End();
                return;
            }
            shape.GetChildren(m_tmpInfos);
            var offset = m_tmpInfos[0].GetTransform().Translation;

            if (offset.LengthSquared() < 1)
            {
                m_tmpInfos.Clear();
                ProfilerShort.End();
                return;
            }
            var lst  = new List <HkdConnection>();
            var set  = new HashSet <HkdBreakableShape>();
            var set2 = new HashSet <HkdBreakableShape>();

            set.Add(shape);
            shape.GetConnectionList(lst);
            fp.PositionComp.SetPosition(Vector3D.Transform(offset, fp.PositionComp.WorldMatrix));
            foreach (var child in m_tmpInfos)
            {
                var m = child.GetTransform();
                m.Translation -= offset;
                child.SetTransform(ref m);
                m_tmpInfos2.Add(child);
                HkdBreakableShape par = child.Shape;
                par.GetConnectionList(lst);
                while (par.HasParent)
                {
                    par = par.GetParent();
                    if (set.Add(par))
                    {
                        par.GetConnectionList(lst);
                    }
                    else
                    {
                    }
                }
                set2.Add(child.Shape);
            }
            m_tmpInfos.Clear();
            HkdBreakableShape compound = new HkdCompoundBreakableShape(shape, m_tmpInfos2);

            //HkMassProperties mp = new HkMassProperties();
            ((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
            compound.SetChildrenParent(compound);
            foreach (var c in lst)
            {
                HkBaseSystem.EnableAssert(390435339, true);
                if (!set2.Contains(c.ShapeA) || !set2.Contains(c.ShapeB))
                {
                    continue;
                }
                var cref = c;
                compound.AddConnection(ref cref);
            }
            fp.Physics.BreakableBody.BreakableShape = compound;
            m_tmpInfos2.Clear();

            ((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();

            ProfilerShort.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();
        }
Example #9
0
 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();
 }
Example #10
0
        public static unsafe void FixPosition(MyFracturedPiece fp)
        {
            HkdBreakableShape breakableShape = fp.Physics.BreakableBody.BreakableShape;

            if (breakableShape.GetChildrenCount() != 0)
            {
                breakableShape.GetChildren(m_tmpInfos);
                Vector3 translation = m_tmpInfos[0].GetTransform().Translation;
                if (translation.LengthSquared() < 1f)
                {
                    m_tmpInfos.Clear();
                }
                else
                {
                    List <HkdConnection>        resultList = new List <HkdConnection>();
                    HashSet <HkdBreakableShape> set        = new HashSet <HkdBreakableShape>();
                    HashSet <HkdBreakableShape> set2       = new HashSet <HkdBreakableShape>();
                    set.Add(breakableShape);
                    breakableShape.GetConnectionList(resultList);
                    fp.PositionComp.SetPosition(Vector3D.Transform(translation, fp.PositionComp.WorldMatrix), null, false, true);
                    foreach (HkdShapeInstanceInfo info2 in m_tmpInfos)
                    {
                        Matrix  transform  = info2.GetTransform();
                        Matrix *matrixPtr1 = (Matrix *)ref transform;
                        matrixPtr1.Translation -= translation;
                        info2.SetTransform(ref transform);
                        m_tmpInfos2.Add(info2);
                        HkdBreakableShape shape = info2.Shape;
                        shape.GetConnectionList(resultList);
                        while (true)
                        {
                            if (!shape.HasParent)
                            {
                                set2.Add(info2.Shape);
                                break;
                            }
                            shape = shape.GetParent();
                            if (set.Add(shape))
                            {
                                shape.GetConnectionList(resultList);
                            }
                        }
                    }
                    m_tmpInfos.Clear();
                    HkdBreakableShape parent = (HkdBreakableShape) new HkdCompoundBreakableShape(new HkdBreakableShape?(breakableShape), m_tmpInfos2);
                    parent.RecalcMassPropsFromChildren();
                    ((HkdBreakableShape *)ref parent).SetChildrenParent(parent);
                    foreach (HkdConnection connection in resultList)
                    {
                        HkBaseSystem.EnableAssert(0x1745920b, true);
                        if (set2.Contains(connection.ShapeA) && set2.Contains(connection.ShapeB))
                        {
                            HkdConnection connection2 = connection;
                            parent.AddConnection(ref connection2);
                        }
                    }
                    fp.Physics.BreakableBody.BreakableShape = parent;
                    m_tmpInfos2.Clear();
                    parent.RecalcMassPropsFromChildren();
                }
            }
        }