private void SpawnPrefabInternal(
            List <MyCubeGrid> resultList,
            String prefabName,
            Vector3D position,
            Vector3 forward,
            Vector3 up,
            Vector3 initialLinearVelocity,
            Vector3 initialAngularVelocity,
            String beaconName,
            SpawningOptions spawningOptions,
            long ownerId,
            bool updateSync,
            Stack <Action> callbacks)
        {
            Debug.Assert(Vector3.IsUnit(ref forward));
            Debug.Assert(Vector3.IsUnit(ref up));
            Debug.Assert(Vector3.ArePerpendicular(ref forward, ref up));

            bool spawnAtOrigin = spawningOptions.HasFlag(SpawningOptions.UseGridOrigin);
            //CreateGridsFromPrefab(resultList, prefabName, MatrixD.CreateWorld(position, forward, up), spawnAtOrigin);
            CreateGridsData createGridsData = new CreateGridsData(resultList, prefabName, MatrixD.CreateWorld(position, forward, up), spawnAtOrigin, callbacks: callbacks);

            Interlocked.Increment(ref PendingGrids);
            callbacks.Push(delegate() { SpawnPrefabInternalSetProperties(resultList, position, forward, up, initialLinearVelocity, initialAngularVelocity, beaconName, spawningOptions, ownerId, updateSync); });
            ParallelTasks.Parallel.Start(createGridsData.CallCreateGridsFromPrefab, createGridsData.OnGridsCreated, createGridsData);
        }
        // Note: This method is not synchronized. If you want synchronized prefab spawning, use SpawnPrefab
        public void AddShipPrefab(string prefabName, Matrix?worldMatrix = null, long factionId = 0, bool spawnAtOrigin = false)
        {
            //m_tmpSpawnedGridList.Clear();
            //CreateGridsFromPrefab(m_tmpSpawnedGridList, prefabName, worldMatrix ?? Matrix.Identity, factionId: factionId, spawnAtOrigin: spawnAtOrigin);
            CreateGridsData createGridsData = new CreateGridsData(new List <MyCubeGrid>(), prefabName, worldMatrix ?? Matrix.Identity, factionId: factionId, spawnAtOrigin: spawnAtOrigin);

            Interlocked.Increment(ref PendingGrids);
            ParallelTasks.Parallel.Start(createGridsData.CallCreateGridsFromPrefab, createGridsData.OnGridsCreated, createGridsData);

            //foreach (var entity in m_tmpSpawnedGridList)
            //{
            //    MyEntities.Add(entity);
            //}

            //m_tmpSpawnedGridList.Clear();
        }
        // Note: This method is not synchronized. If you want synchronized prefab spawning, use SpawnPrefab
        public void AddShipPrefabRandomPosition(string prefabName, Vector3D position, float distance, long factionId = 0, bool spawnAtOrigin = false)
        {
            //m_tmpSpawnedGridList.Clear();

            var prefabDefinition = MyDefinitionManager.Static.GetPrefabDefinition(prefabName);

            Debug.Assert(prefabDefinition != null, "Could not spawn prefab named " + prefabName);
            if (prefabDefinition == null)
            {
                return;
            }

            BoundingSphereD collisionSphere = new BoundingSphereD(Vector3D.Zero, prefabDefinition.BoundingSphere.Radius);
            Vector3         spawnPos;
            MyEntity        collidedEntity;
            int             count = 0;

            do
            {
                spawnPos = position + MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(0.5f, 1.0f) * distance;
                collisionSphere.Center = spawnPos;
                collidedEntity         = MyEntities.GetIntersectionWithSphere(ref collisionSphere);
                count++;
                if (count % 8 == 0)
                {
                    distance += (float)collisionSphere.Radius / 2;
                }
            }while (collidedEntity != null);

            //CreateGridsFromPrefab(m_tmpSpawnedGridList, prefabName, Matrix.CreateWorld(spawnPos, Vector3.Forward, Vector3.Up), factionId: factionId, spawnAtOrigin: spawnAtOrigin);
            CreateGridsData createGridsData = new CreateGridsData(new List <MyCubeGrid>(), prefabName, Matrix.CreateWorld(spawnPos, Vector3.Forward, Vector3.Up), factionId: factionId, spawnAtOrigin: spawnAtOrigin);

            Interlocked.Increment(ref PendingGrids);
            ParallelTasks.Parallel.Start(createGridsData.CallCreateGridsFromPrefab, createGridsData.OnGridsCreated, createGridsData);
            //foreach (var grid in m_tmpSpawnedGridList)
            //{
            //    MyEntities.Add(grid);
            //}

            //m_tmpSpawnedGridList.Clear();
        }
Esempio n. 4
0
        // Note: This method is not synchronized. If you want synchronized prefab spawning, use SpawnPrefab
        public void AddShipPrefab(string prefabName, Matrix? worldMatrix = null, long factionId = 0, bool spawnAtOrigin = false)
        {
            //m_tmpSpawnedGridList.Clear();
            //CreateGridsFromPrefab(m_tmpSpawnedGridList, prefabName, worldMatrix ?? Matrix.Identity, factionId: factionId, spawnAtOrigin: spawnAtOrigin);
            CreateGridsData createGridsData = new CreateGridsData(new List<MyCubeGrid>(), prefabName, worldMatrix ?? Matrix.Identity, factionId: factionId, spawnAtOrigin: spawnAtOrigin);
            Interlocked.Increment(ref PendingGrids);
            ParallelTasks.Parallel.Start(createGridsData.CallCreateGridsFromPrefab, createGridsData.OnGridsCreated, createGridsData);

            //foreach (var entity in m_tmpSpawnedGridList)
            //{			
            //    MyEntities.Add(entity);
            //}

            //m_tmpSpawnedGridList.Clear();
        }
Esempio n. 5
0
        private void SpawnPrefabInternal(
            List<MyCubeGrid> resultList,
            String prefabName,
            Vector3D position,
            Vector3 forward,
            Vector3 up,
            Vector3 initialLinearVelocity,
            Vector3 initialAngularVelocity,
            String beaconName,
            SpawningOptions spawningOptions,
            long ownerId,
            bool updateSync,
            Stack<Action> callbacks)
        {
            Debug.Assert(Vector3.IsUnit(ref forward));
            Debug.Assert(Vector3.IsUnit(ref up));
            Debug.Assert(Vector3.ArePerpendicular(ref forward, ref up));

            bool spawnAtOrigin = spawningOptions.HasFlag(SpawningOptions.UseGridOrigin);
            //CreateGridsFromPrefab(resultList, prefabName, MatrixD.CreateWorld(position, forward, up), spawnAtOrigin);
            CreateGridsData createGridsData = new CreateGridsData(resultList, prefabName, MatrixD.CreateWorld(position, forward, up), spawnAtOrigin, callbacks: callbacks);
            Interlocked.Increment(ref PendingGrids);
            callbacks.Push(delegate() { SpawnPrefabInternalSetProperties(resultList, position, forward, up, initialLinearVelocity, initialAngularVelocity, beaconName, spawningOptions, ownerId, updateSync); });
            ParallelTasks.Parallel.Start(createGridsData.CallCreateGridsFromPrefab, createGridsData.OnGridsCreated, createGridsData);
        }
Esempio n. 6
0
        // Note: This method is not synchronized. If you want synchronized prefab spawning, use SpawnPrefab
        public void AddShipPrefabRandomPosition(string prefabName, Vector3D position, float distance, long factionId = 0, bool spawnAtOrigin = false)
        {
            //m_tmpSpawnedGridList.Clear();

            var prefabDefinition = MyDefinitionManager.Static.GetPrefabDefinition(prefabName);
            Debug.Assert(prefabDefinition != null, "Could not spawn prefab named " + prefabName);
            if (prefabDefinition == null) return;

            BoundingSphereD collisionSphere = new BoundingSphereD(Vector3D.Zero, prefabDefinition.BoundingSphere.Radius);
            Vector3 spawnPos;
            MyEntity collidedEntity;
            int count = 0;
            do
            {
                spawnPos = position + MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(0.5f, 1.0f) * distance;
                collisionSphere.Center = spawnPos;
                collidedEntity = MyEntities.GetIntersectionWithSphere(ref collisionSphere);
                count++;
                if (count % 8 == 0)
                    distance += (float)collisionSphere.Radius / 2;
            }
            while (collidedEntity != null);

            //CreateGridsFromPrefab(m_tmpSpawnedGridList, prefabName, Matrix.CreateWorld(spawnPos, Vector3.Forward, Vector3.Up), factionId: factionId, spawnAtOrigin: spawnAtOrigin);
            CreateGridsData createGridsData = new CreateGridsData(new List<MyCubeGrid>(), prefabName, Matrix.CreateWorld(spawnPos, Vector3.Forward, Vector3.Up), factionId: factionId, spawnAtOrigin: spawnAtOrigin);
            Interlocked.Increment(ref PendingGrids);
            ParallelTasks.Parallel.Start(createGridsData.CallCreateGridsFromPrefab, createGridsData.OnGridsCreated, createGridsData);
            //foreach (var grid in m_tmpSpawnedGridList)
            //{
            //    MyEntities.Add(grid);
            //}

            //m_tmpSpawnedGridList.Clear();
        }