public override void Dispose()
 {
     base.Dispose();
     lock (instanceMutationLock) {
         foreach (PhysicsShapeHandle shapeHandle in activePhysicsShapes.Values.Distinct())
         {
             if (!WorldModelCache.CacheContainsHandle(shapeHandle))
             {
                 shapeHandle.Dispose();
             }
         }
         activePhysicsShapes.Clear();
         currentGameObjects.Values.ForEach(e => e.Dispose());
         currentGameObjects.Clear();
     }
 }
Пример #2
0
        public static void LoadMenuFrontend(SkyLevelDescription preloadedSky = null, MenuState entryPointMenu = MenuState.MainMenu, Action deferenceModeAction = null)
        {
            lock (staticMutationLock) {
                MenuCoordinator.deferenceModeAction = deferenceModeAction;
                inDeferenceMode = deferenceModeAction != null;
                if (!inDeferenceMode)
                {
                    WorldModelCache.ClearAndDisposeCache();
                }
                LoadMenuBackdrop(preloadedSky ?? loadedMenuBackdrop);
                switch (entryPointMenu)
                {
                case MenuState.PlayMenu: PlayMenuTransitionIn(); break;

                case MenuState.MedalsMenu: MedalsMenuTransitionIn(); break;

                case MenuState.OptionsMenu: OptionsTransitionIn(); break;

                default: MainMenuTransitionIn(); break;
                }
            }
        }
Пример #3
0
        public override PhysicsShapeHandle CreatePhysicsShape(out Vector3 shapeOffset)
        {
            shapeOffset = Vector3.ZERO;

            if (this.Transform == Transform.DEFAULT_TRANSFORM)
            {
                var potentialResult = WorldModelCache.GetCachedModel(ModelFileName);
                if (potentialResult.HasValue)
                {
                    return(potentialResult.Value);
                }
            }

            List <DefaultVertex> outVerts;
            List <uint>          outIndices;

            GetVertexDataUnscaled(out outVerts, out outIndices);

            string acdFileName = ModelFileName;

            if (MirrorX)
            {
                acdFileName = Path.GetFileNameWithoutExtension(acdFileName) + "_mirrored" + Path.GetExtension(acdFileName);
            }
            var result = PhysicsManager.CreateConcaveHullShape(
                outVerts.Select(df => df.Position),
                outIndices.Select(@uint => (int)@uint),
                new CollisionShapeOptionsDesc(Transform.Scale),
                AssetLocator.CreateACDFilePath(acdFileName)
                );

            if (this.Transform == Transform.DEFAULT_TRANSFORM)
            {
                WorldModelCache.SetCachedModel(ModelFileName, result);
            }

            return(result);
        }
        public override void ResetEntityPhysics(bool fullReset)
        {
            LosgapSystem.InvokeOnMasterAsync(() => {             // Because creating geometryEntity shapes invoke on master and it can create locking deadlocks
                Vector3 physicsShapeOffset;
                lock (instanceMutationLock) {
                    if (fullReset)
                    {
                        foreach (PhysicsShapeHandle shapeHandle in activePhysicsShapes.Values.Distinct())
                        {
                            if (!WorldModelCache.CacheContainsHandle(shapeHandle))
                            {
                                shapeHandle.Dispose();
                            }
                        }
                        activePhysicsShapes.Clear();
                    }
                    List <PhysicsShapeHandle> unusedHandles = activePhysicsShapes.Values.Distinct().ToList();
                    foreach (KeyValuePair <LevelGeometryEntity, GeometryEntity> kvp in currentGeometryEntities)
                    {
                        PhysicsShapeHandle physicsShape = PhysicsShapeHandle.NULL;
                        if (kvp.Key.Geometry is LevelGeometry_Model)
                        {
                            LevelGeometry_Model geomAsModel = (LevelGeometry_Model)kvp.Key.Geometry;
                            var matchingEntity = activePhysicsShapes.Keys.FirstOrDefault(e => e.Geometry is LevelGeometry_Model && ((LevelGeometry_Model)e.Geometry).HasIdenticalPhysicsShape(geomAsModel));
                            if (matchingEntity != null)
                            {
                                physicsShape = activePhysicsShapes[matchingEntity];
                            }
                        }
                        else
                        {
                            if (activePhysicsShapes.ContainsKey(kvp.Key))
                            {
                                physicsShape = activePhysicsShapes[kvp.Key];
                            }
                        }
                        if (physicsShape == PhysicsShapeHandle.NULL)
                        {
                            physicsShape = kvp.Key.Geometry.CreatePhysicsShape(out physicsShapeOffset);
                        }
                        if (physicsShape == PhysicsShapeHandle.NULL)
                        {
                            continue;                                                                  // Some geometry is non-collidable (i.e. planes)
                        }
                        kvp.Value.SetPhysicsShape(physicsShape, Vector3.ZERO, LevelGeometry.GEOMETRY_MASS, forceIntransigence: true);
                        activePhysicsShapes[kvp.Key] = physicsShape;
                        if (!fullReset && unusedHandles.Contains(physicsShape))
                        {
                            unusedHandles.Remove(physicsShape);
                        }
                    }

                    if (!fullReset)
                    {
                        foreach (var unusedHandle in unusedHandles)
                        {
                            activePhysicsShapes.RemoveWhere(kvp => kvp.Value == unusedHandle);
                            if (!WorldModelCache.CacheContainsHandle(unusedHandle))
                            {
                                unusedHandle.Dispose();
                            }
                        }
                    }
                }
            });
        }