コード例 #1
1
        private void OnUpdateSystem(ParticleEmitterComponent particleEmitterComponent)
        {
            if (dragonHead == null)
                dragonHead = EntitySystem.Entities.FirstOrDefault(x => x.Name == "English DragonPelvis");

            var desc = Description;

            if (dragonHead != null)
            {
                var dragonTransform = dragonHead.Transformation;
                if (dragonTransform != null)
                {
                    desc.TargetOld = desc.Target;
                    desc.Target = (Vector3)dragonTransform.WorldMatrix.Row4;
                }
            }

            var animationComponent = RootAnimation.GetOrCreate(AnimationComponent.Key);
            if (animationComponent != null)
            {
                desc.AnimationTime = (float)animationComponent.CurrentTime.TotalSeconds;
                // If we reset, reupload the particle buffer
                if ((animationComponent.CurrentTime.Ticks - lastTime.Ticks) < 0) 
                    particleEmitterComponent.UpdateNextBuffer = true;

                lastTime = animationComponent.CurrentTime;
            }

            Description = desc;
        }
コード例 #2
0
        private void UpdateParticlesData(ParticleEmitterComponent smokeParticleEmitterComponent)
        {
            bool isUptoDate = true;

            if (ParticleData == null || ParticleData.Length != Count)
            {
                ParticleData = new ScriptParticleSmoke.ParticleData[Count];
                isUptoDate   = false;
            }

            if (isUptoDate)
            {
                return;
            }

            var description     = Description;
            var random          = new Random();
            var particlesBuffer = (ScriptParticleSmoke.ParticleData[])ParticleData;

            for (int i = 0; i < particlesBuffer.Length; i++)
            {
                particlesBuffer[i] = new ScriptParticleSmoke.ParticleData
                {
                    Position = description.Position,
                    Velocity = (Half3)(description.Velocity + Vector3.Modulate(new Vector3((float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble())), description.Scatter)),
                    Size     = (Half)description.InitialSize,
                    Time     = (float)random.NextDouble() * description.MaxTime,
                    Opacity  = (Half)description.Opacity,
                    Factors  = new Half4((Half)random.NextDouble(), (Half)0, (Half)description.Opacity, (Half)0),
                    TimeStep = (Half)10.0f,
                };
                particlesBuffer[i].Position += ((Vector3)particlesBuffer[i].Velocity) * particlesBuffer[i].Time * 100.0f / 1000.0f;
            }
        }
コード例 #3
0
        private void OnUpdateSystem(ParticleEmitterComponent particleEmitterComponent)
        {
            if (dragonHead == null)
            {
                dragonHead = EntitySystem.Entities.FirstOrDefault(x => x.Name == "English DragonPelvis");
            }

            var desc = Description;

            if (dragonHead != null)
            {
                var dragonTransform = dragonHead.Transformation;
                if (dragonTransform != null)
                {
                    desc.TargetOld = desc.Target;
                    desc.Target    = (Vector3)dragonTransform.WorldMatrix.Row4;
                }
            }

            var animationComponent = RootAnimation.GetOrCreate(AnimationComponent.Key);

            if (animationComponent != null)
            {
                desc.AnimationTime = (float)animationComponent.CurrentTime.TotalSeconds;
                // If we reset, reupload the particle buffer
                if ((animationComponent.CurrentTime.Ticks - lastTime.Ticks) < 0)
                {
                    particleEmitterComponent.UpdateNextBuffer = true;
                }

                lastTime = animationComponent.CurrentTime;
            }

            Description = desc;
        }
コード例 #4
0
        private void UpdateParticlesData(ParticleEmitterComponent smokeParticleEmitterComponent)
        {
            bool isUptoDate = true;

            if (ParticleData == null || ParticleData.Length != Count)
            {
                ParticleData = new ScriptParticleSmoke.ParticleData[Count];
                isUptoDate   = false;
            }

            if (isUptoDate)
            {
                return;
            }

            var description     = Description;
            var random          = new Random(0);
            var particlesBuffer = (ScriptParticleSmoke.ParticleData[])ParticleData;

            for (int i = 0; i < particlesBuffer.Length; i++)
            {
                var timeProb       = (float)random.NextDouble();
                var timeStepFactor = 50 * Math.Pow(1 - timeProb, 3.0) + 1.0;
                var time           = (((int)(random.NextDouble() * description.MaxTimeTarget / timeStepFactor) + 1) * timeStepFactor) % description.MaxTimeTarget;
                particlesBuffer[i] = new ScriptParticleSmoke.ParticleData
                {
                    Time     = (float)time,
                    Opacity  = (Half)0.0f,
                    Factors  = new Half4(Half.Zero, Half.Zero, Half.One, Half.Zero),
                    TimeStep = (Half)timeStepFactor,
                };
            }
        }
コード例 #5
0
        private void LoadSnowParticleEmitter()
        {
            // Lets find the render camera and attach a particle emitter to it.
            var msgGetRender = ObjectPool.Aquire <MsgGetRenderEntity>();

            this.game.SendInterfaceMessage(msgGetRender, InterfaceType.Camera);

            if (msgGetRender.EntityID == QSGame.UniqueIDEmpty)
            {
                return;
            }

            var msgGetEntity = ObjectPool.Aquire <MsgGetEntityByID>();

            msgGetEntity.EntityID = msgGetRender.EntityID;
            this.game.SendInterfaceMessage(msgGetEntity, InterfaceType.SceneManager);

            if (msgGetEntity.Entity == null)
            {
                return;
            }

            ParticleEmitterComponent snowEmitter = EntityLoader.LoadComponent(msgGetEntity.Entity,
                                                                              ComponentType.ParticleEmitterComponent,
                                                                              this.game.Content,
                                                                              "Entities/ComponentDefinitions/ParticleEmitter/SnowWeatherEmitter")
                                                   as ParticleEmitterComponent;

            // Give the emitter some settings.
            snowEmitter.InitializeEmitterSettings(new Vector3(0.0f, 100.0f, 0.0f), 500, new Vector3(300.0f, 10.0f, 300.0f));
        }
コード例 #6
0
        private void UpdateParticlesData(ParticleEmitterComponent smokeParticleEmitterComponent)
        {
            bool isUptoDate = true;
            if (ParticleData == null || ParticleData.Length != Count)
            {
                ParticleData = new ScriptParticleSmoke.ParticleData[Count];
                isUptoDate = false;
            }

            if (isUptoDate)
                return;

            var description = Description;
            var random = new Random();
            var particlesBuffer = (ScriptParticleSmoke.ParticleData[])ParticleData;

            for (int i = 0; i < particlesBuffer.Length; i++)
            {
                particlesBuffer[i] = new ScriptParticleSmoke.ParticleData
                    {
                        Position = description.Position,
                        Velocity = (Half3)(description.Velocity + Vector3.Modulate(new Vector3((float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble())), description.Scatter)),
                        Size = (Half)description.InitialSize,
                        Time = (float)random.NextDouble() * description.MaxTime,
                        Opacity = (Half)description.Opacity,
                        Factors = new Half4((Half)random.NextDouble(), (Half)0, (Half)description.Opacity, (Half)0),
                        TimeStep = (Half)10.0f,
                    };
                particlesBuffer[i].Position += ((Vector3)particlesBuffer[i].Velocity) * particlesBuffer[i].Time * 100.0f / 1000.0f;
            }
        }
コード例 #7
0
 public void SetParticleData(ParticleEmitterData data)
 {
     if (_emitterEntity != null)
     {
         _emitterEntity.Destroy();
     }
     _emitterEntity = Entity.CreateInstance(_state.EntityManager);
     _emitterEntity.GetTransform().Position = new Vector3(400, 400, 0);
     ParticleEmitterComponent component     = new ParticleEmitterComponent(_emitterEntity, data);
 }
コード例 #8
0
        public MapEventComponent(Entity entity, MapEvent mapEvent)
            : base(entity)
        {
            _particleEmitterComponent = null;

            SetMapEvent(mapEvent);
            SetAnimating(false);
            SetXFrames(4);
            SetYFrames(4);
            _spriteTimer    = 0f;
            _spriteTimerMax = 0.3f;
        }
コード例 #9
0
 private void CreateParticles(ParticleEmitterComponent particleEmitterComponent,
                              TransformComponent transformComponent,
                              TimeSpan createdAt)
 {
     if (particleEmitterComponent.ParticleTemplateType == ParticleTemplateType.Dust &&
         particleEmitterComponent.ParticleEmitterType != ParticleEmitterType.None)
     {
         var position = transformComponent.Position + particleEmitterComponent.ParticleOffset;
         _dustEntityFactory.CreateDustParticleEntitesAndUnwrap(position,
                                                               createdAt);
     }
 }
コード例 #10
0
        private void SetMapEvent(MapEvent mapEvent)
        {
            _mapEvent = mapEvent;
            SetSpriteID(mapEvent.SpriteID);
            SetRealPosition();
            SetYFrame((int)_mapEvent.EventDirection);

            ParticleEmitterData data = ParticleEmitterData.GetEmitterData(_mapEvent.ParticleEmitterID);

            if (data != null)
            {
                _particleEmitterComponent = new ParticleEmitterComponent(Parent, data);
            }
        }
コード例 #11
0
        private void OnMeshUpdate(ParticleEmitterComponent particleEmitterComponent, Entity entity, TrackingCollectionChangedEventArgs arg3)
        {
            if (entity.Name.StartsWith("maguma_"))
            {
                var meshComponent = entity.Get(ModelComponent.Key);
                if (meshComponent == null)
                    return;

                foreach (var effectMesh in meshComponent.SubMeshes)
                {
                    var subMeshData = effectMesh.MeshData.Value.SubMeshDatas[MeshData.StandardSubMeshData];
                    var buffer = subMeshData.GetVertexBufferData<Vector3>("POSITION");
                    var gpuBuffer = Buffer.Structured.New(renderContext.GraphicsDevice, buffer);
                    Parameters.Set(ScriptParticleSmoke.VerticesEmitterKey, gpuBuffer);
                    break;
                }
            }
        }
コード例 #12
0
ファイル: Ball.cs プロジェクト: tdheff/Orbsmash
        public override void onAddedToScene()
        {
            var gameScene = (HandyScene)scene;

            /*
             * SPRITE AND ANIMATION
             */
            var subtextures = Util.ExtractSubtextures(gameScene.Textures[Constants.BallSprites.DEFAULT], 1, 1);

            _sprite             = new AnimatableSprite(subtextures);
            _sprite.renderLayer = RenderLayers.PRIMARY;

            /*
             * COLLISIONS AND KINEMATICS
             */
            // must generate collider after we create the sprite,
            // otherwise the collider doesn't know how big it is (that's how it default works)
            _collider = new CircleCollider(9);
            Flags.setFlagExclusive(ref _collider.collidesWithLayers, PhysicsLayers.BACK_WALLS);
            Flags.setFlag(ref _collider.collidesWithLayers, PhysicsLayers.SIDE_WALLS);
            _kinematic.CollisionType = KinematicComponent.ECollisionType.Bounce;

            /*
             * STATE
             */
            _ballStateComponent = new BallStateComponent();

            /*
             * PARTICLES
             */

            _particleEmitter              = new ParticleEmitterComponent(generateParticleEmitterConfig(gameScene.Textures[BallSprites.DEFAULT]));
            _particleEmitter._active      = true;
            _particleEmitter.renderLayer  = RenderLayers.PRIMARY;
            _particleEmitter.renderOffset = -1;

            addComponent(_kinematic);
            addComponent(_sprite);
            addComponent(_collider);
            addComponent(_ballStateComponent);
            addComponent(_particleEmitter);

            scale = new Vector2(3, 3);
        }
コード例 #13
0
        private void OnMeshUpdate(ParticleEmitterComponent particleEmitterComponent, Entity entity, TrackingCollectionChangedEventArgs arg3)
        {
            if (entity.Name.StartsWith("maguma_"))
            {
                var meshComponent = entity.Get(ModelComponent.Key);
                if (meshComponent == null)
                {
                    return;
                }

                foreach (var effectMesh in meshComponent.SubMeshes)
                {
                    var subMeshData = effectMesh.MeshData.Value.SubMeshDatas[MeshData.StandardSubMeshData];
                    var buffer      = subMeshData.GetVertexBufferData <Vector3>("POSITION");
                    var gpuBuffer   = Buffer.Structured.New(renderContext.GraphicsDevice, buffer);
                    Parameters.Set(ScriptParticleSmoke.VerticesEmitterKey, gpuBuffer);
                    break;
                }
            }
        }
コード例 #14
0
        public static async Task Run(EngineContext engineContext)
        {
            ParticlePlugin particlePlugin;

            if (!engineContext.DataContext.RenderPassPlugins.TryGetValueCast("ParticlePlugin", out particlePlugin))
            {
                return;
            }

            var count = particlePlugin.CapacityCount;

            var particlesBuffer = new ParticleData[count];
            var random          = new Random();

            for (int i = 0; i < particlesBuffer.Length; i++)
            {
                particlesBuffer[i] = new ParticleData
                {
                    Position = new Vector3(1000.0f - (float)random.NextDouble() * 6000, 1500.0f - (float)random.NextDouble() * 3000.0f, 0),
                    Velocity = new Vector3(0, 0, 2.0f + 10.0f * (float)random.NextDouble()),
                    Time     = 5000.0f * (float)random.NextDouble(),
                    Size     = 1.0f + (float)random.NextDouble() * 10.0f,
                    Factors  = new Vector3(1.0f + ((i & 255) == 0 ? (25.0f + 50.0f * (float)random.NextDouble()) : -(float)random.NextDouble() * ((i & 3) == 0 ? 2.0f : 1.0f)), 0, 0),
                    Opacity  = 1.0f,
                };
                particlesBuffer[i].Position.Z = particlesBuffer[i].Velocity.Z * particlesBuffer[i].Time / 100.0f;
            }

            var particleUpdater = new ParticleEmitterComponent()
            {
                Type   = ParticleEmitterType.GpuStatic,
                Count  = count,
                Shader = new ShaderClassSource("ParticleUpdaterTest1"),
            };

            particleUpdater.ParticleData        = particlesBuffer;
            particleUpdater.ParticleElementSize = Utilities.SizeOf <ParticleData>();

            // Add this particle updater to the particle engine
            particlePlugin.Updaters.Add(particleUpdater);
        }
コード例 #15
0
        public void BoxStack(int totalRows, Vector3 offset)
        {
            int currentColumnMax = totalRows;

            float        boxScale = 9.0f;
            StaticModel  mesh     = this.game.ModelLoader.LoadStaticModel("Models/WoodCrate/Crate1");
            BoxShapeDesc boxShape = PhysicsComponent.CreateBoxShapeFromMesh(mesh, boxScale);

            for (int rows = 0; rows < totalRows; ++rows, --currentColumnMax)
            {
                for (int columns = 0; columns < currentColumnMax; ++columns)
                {
                    Vector3 boxPos = offset + new Vector3(columns * boxShape.Extents.X,
                                                          rows * boxShape.Extents.Y + (boxShape.Extents.Y * 0.5f),
                                                          0.0f);

                    boxPos.X -= currentColumnMax * boxShape.Extents.X * 0.5f;

                    int boxTemplate = 2;
                    if (rows == (totalRows - 1))
                    {
                        // Use a smoking box if we're on the top row
                        boxTemplate = 3;
                    }

                    var boxEntity = new BaseEntity(this.game, boxPos, Matrix.Identity, 9.0f);
                    this.game.SceneManager.AddEntityByTemplateID(boxEntity, boxTemplate);

                    if (boxTemplate == 3)
                    {
                        ParticleEmitterComponent emitter = boxEntity.GetComponentByType(ComponentType.ParticleEmitterComponent) as ParticleEmitterComponent;
                        // These give offsets for the emitter and how many particles per second to emit.
                        emitter.InitializeEmitterSettings(Vector3.Zero, 7, Vector3.Zero);
                    }
                }
            }
        }
コード例 #16
0
ファイル: ScriptParticles.cs プロジェクト: Powerino73/paradox
        public static async Task Run(EngineContext engineContext)
        {
            ParticlePlugin particlePlugin;
            if (!engineContext.DataContext.RenderPassPlugins.TryGetValueCast("ParticlePlugin", out particlePlugin))
                return;

            var count = particlePlugin.CapacityCount;

            var particlesBuffer = new ParticleData[count];
            var random = new Random();
            for (int i = 0; i < particlesBuffer.Length; i++)
            {
                particlesBuffer[i] = new ParticleData
                    {
                        Position = new Vector3(1000.0f - (float)random.NextDouble() * 6000, 1500.0f - (float)random.NextDouble() * 3000.0f, 0),
                        Velocity = new Vector3(0, 0, 2.0f + 10.0f * (float)random.NextDouble()),
                        Time = 5000.0f * (float)random.NextDouble(),
                        Size = 1.0f + (float)random.NextDouble() * 10.0f,
                        Factors = new Vector3(1.0f + ((i & 255) == 0 ? (25.0f + 50.0f * (float)random.NextDouble()) : -(float)random.NextDouble() * ((i & 3) == 0 ? 2.0f : 1.0f)), 0, 0),
                        Opacity = 1.0f,
                    };
                particlesBuffer[i].Position.Z = particlesBuffer[i].Velocity.Z * particlesBuffer[i].Time / 100.0f;
            }

            var particleUpdater = new ParticleEmitterComponent()
                {
                    Type = ParticleEmitterType.GpuStatic,
                    Count = count,
                    Shader = new ShaderClassSource("ParticleUpdaterTest1"),
                };
            particleUpdater.ParticleData = particlesBuffer;
            particleUpdater.ParticleElementSize = Utilities.SizeOf<ParticleData>();

            // Add this particle updater to the particle engine
            particlePlugin.Updaters.Add(particleUpdater);
        }
コード例 #17
0
        private void UpdateParticlesData(ParticleEmitterComponent smokeParticleEmitterComponent)
        {
            bool isUptoDate = true;
            if (ParticleData == null || ParticleData.Length != Count)
            {
                ParticleData = new ScriptParticleSmoke.ParticleData[Count];
                isUptoDate = false;
            }

            if (isUptoDate)
                return;

            var description = Description;
            var random = new Random(0);
            var particlesBuffer = (ScriptParticleSmoke.ParticleData[])ParticleData;

            for (int i = 0; i < particlesBuffer.Length; i++)
            {
                var timeProb = (float)random.NextDouble();
                var timeStepFactor = 50 * Math.Pow(1 - timeProb, 3.0) + 1.0;
                var time = (((int)(random.NextDouble() * description.MaxTimeTarget / timeStepFactor) + 1) * timeStepFactor) % description.MaxTimeTarget;
                particlesBuffer[i] = new ScriptParticleSmoke.ParticleData
                    {
                        Time = (float)time,
                        Opacity = (Half)0.0f,
                        Factors = new Half4(Half.Zero, Half.Zero, Half.One, Half.Zero),
                        TimeStep = (Half)timeStepFactor,
                    };
            }
        }
コード例 #18
0
        private void OnFrameUpdate(ThreadContext context)
        {
            updatePasses.Enabled = true; //!RenderContext.IsPaused;

            // Add new updater to the current list
            foreach (var particleUpdater in Updaters)
            {
                ParticleUpdaterState particleUpdaterState = null;
                foreach (ParticleUpdaterState state in currentUpdaters)
                {
                    if (ReferenceEquals(state.UserState, particleUpdater))
                    {
                        particleUpdaterState = state;
                        break;
                    }
                }
                if (particleUpdaterState == null)
                {
                    currentUpdaters.Add(new ParticleUpdaterState()
                    {
                        UserState = particleUpdater, StructureSize = StructureSize
                    });
                }
            }

            // Get updater to remove from current list
            foreach (var particleUpdater in currentUpdaters)
            {
                ParticleEmitterComponent particleUpdaterState = null;
                foreach (ParticleEmitterComponent state in Updaters)
                {
                    if (ReferenceEquals(state, particleUpdater.UserState))
                    {
                        particleUpdaterState = state;
                        break;
                    }
                }
                if (particleUpdaterState == null)
                {
                    updatersToRemove.Add(particleUpdater);
                }
            }

            // Remove from the current list
            foreach (var particleUpdaterState in updatersToRemove)
            {
                currentUpdaters.Remove(particleUpdaterState);

                // Remove the mesh to be rendered
                meshesToRender.RemoveMesh(particleUpdaterState.MeshUpdater);

                // Dispose the previous particule updater as it is no longer used
                particleUpdaterState.DisposeBuffers();
            }

            // Reallocate global buffers if needed
            if (updatersCount > capacityCount)
            {
                CapacityCount = updatersCount;
                OnCapacityCountChange();
            }

            int particleUpdaterIndex = 1;

            currentParticleCount = 0;
            // Update start index into global buffers for all CPU/GPU static buffers.
            int startIndex = 0;

            for (int i = 0; i < currentUpdaters.Count; i++)
            {
                var currentState = currentUpdaters[i];
                var userState    = currentState.UserState;

                if (!userState.IsDynamicEmitter)
                {
                    // If there is a change from dynamic type to CPU/GPU static buffer, we need to deallocate previous Append/ConsumeBuffers
                    if (currentState.IsDynamicEmitter)
                    {
                        currentState.DisposeBuffers();
                    }
                }
                else if (userState.Count > currentState.Count)
                {
                    // This is a dynamic buffer and the new buffer is larger than previous one
                    // or we simply need to allocate new consume/append buffers
                    currentState.AllocateBuffers(context.GraphicsDevice);
                }

                // Create Effect shader
                if (!ReferenceEquals(userState.Shader, currentState.Shader) || currentState.Count != userState.Count)
                {
                    // Remove the effect pass
                    updatePasses.RemovePass(currentState.EffectPass);

                    // Dispose previous effects
                    currentState.DisposeEffects();

                    // Remove mesh
                    if (currentState.MeshUpdater != null)
                    {
                        meshesToRender.RemoveMesh(currentState.MeshUpdater);
                        currentState.MeshUpdater = null;
                    }

                    // Compile new shader
                    if (userState.Shader != null)
                    {
                        string name = userState.Name ?? string.Format("{0}{1}", userState.Shader.ClassName, particleUpdaterIndex++);

                        currentState.EffectPass = new RenderPass(name);
                        updatePasses.AddPass(currentState.EffectPass);

                        // Calculate the best dispatch thread count
                        int dispatchCount = MaximumThreadPerGroup;
                        while (dispatchCount > 0)
                        {
                            // If the maximum count is a multiple of the current dispatchCount use it
                            if ((userState.Count & (dispatchCount - 1)) == 0)
                            {
                                break;
                            }
                            dispatchCount >>= 1;
                        }

                        // Compile the new shader for this count
                        currentState.EffectUpdater = this.EffectSystemOld.BuildEffect(name).Using(
                            new ComputeShaderPlugin(userState.Shader, dispatchCount, 1, 1)
                        {
                            RenderPass = currentState.EffectPass,
                            Macros     = { new ShaderMacro("PARTICLE_STRUCT", StructureName) }
                        });

                        // Instantiate the mesh updater
                        var meshParams = new ParameterCollection(name);
                        currentState.MeshUpdater = new EffectMesh(currentState.EffectUpdater, new Mesh {
                            Parameters = meshParams
                        }).Dispatch(userState.Count / dispatchCount, 1, 1);
                        currentState.MeshUpdater.Parameters.AddSources(Parameters);
                        currentState.MeshUpdater.Parameters.AddSources(MainPlugin.ViewParameters);
                        currentState.MeshUpdater.Parameters.AddSources(userState.Parameters);

                        // Setup Append/Consume
                        if (userState.IsDynamicEmitter)
                        {
                            currentState.MeshUpdater.Parameters.Set(ParticleBaseKeys.ParticleInputBuffer, currentState.ConsumeBuffer);
                            currentState.MeshUpdater.Parameters.Set(ParticleBaseKeys.ParticleOutputBuffer, currentState.AppendBuffer);
                            currentState.MeshUpdater.Parameters.Set(ParticleBaseKeys.ParticleStartIndex, (uint)0);
                        }
                        else
                        {
                            // Setup update on global buffer
                            currentState.MeshUpdater.Parameters.Set(ParticleBaseKeys.ParticleGlobalBuffer, globalBuffer);
                            currentState.MeshUpdater.Parameters.Set(ParticleBaseKeys.ParticleStartIndex, (uint)startIndex);
                        }

                        // Add this updater to the rendering list
                        meshesToRender.AddMesh(currentState.MeshUpdater);
                    }
                }

                // Setup Append/Consume
                if (currentState.MeshUpdater != null && !userState.IsDynamicEmitter && currentState.StartIndex != startIndex)
                {
                    // Setup update on global buffer
                    currentState.MeshUpdater.Parameters.Set(ParticleBaseKeys.ParticleStartIndex, (uint)startIndex);
                }

                // Transfer CPU buffer to GPU
                if (!ReferenceEquals(userState.ParticleData, currentState.ParticleData) ||
                    userState.UpdateNextBuffer ||
                    userState.Type == ParticleEmitterType.CpuDynamic ||
                    currentState.StartIndex != startIndex ||
                    currentState.Count != userState.Count
                    )
                {
                    // Update the data if necessary
                    userState.OnUpdateData();

                    if (userState.ParticleData != null)
                    {
                        var handle = GCHandle.Alloc(userState.ParticleData, GCHandleType.Pinned);
                        globalBuffer.SetData(context.GraphicsDevice, new DataPointer(handle.AddrOfPinnedObject(), userState.Count * StructureSize), startIndex * StructureSize);
                        handle.Free();
                    }
                    userState.UpdateNextBuffer = false;
                }

                // Replicate the shader to the current state
                currentState.Type   = userState.Type;
                currentState.Shader = userState.Shader;
                currentState.Count  = userState.Count;
                currentState.ParticleElementSize = userState.ParticleElementSize;
                currentState.ParticleData        = userState.ParticleData;
                currentState.StartIndex          = startIndex;

                // Copy Maximum count to current state
                currentParticleCount += userState.Count;

                // Update start index
                startIndex += userState.Count;
            }

            // Add mesh to the render list
            if (updatersCount > 0)
            {
                if (!isParticleRenderingEnabled)
                {
                    isParticleRenderingEnabled = true;

                    meshesToRender.AddMesh(effectMeshRender);
                    meshesToRender.AddMesh(effectMeshCopyToSortBuffer);
                }
            }
            else
            {
                isParticleRenderingEnabled = false;
                meshesToRender.RemoveMesh(effectMeshRender);
                meshesToRender.RemoveMesh(effectMeshCopyToSortBuffer);
            }

            // Prepare mesh for rendering
            PrepareForRendering();
        }
コード例 #19
0
ファイル: VisibilitySystem.cs プロジェクト: 0000duck/MiniRTS
 public void ProcessNew(BoundingSphereComponent bounds, TransformComponent transform, ParticleEmitterComponent _)
 => this.Partition.Add(transform.Entity, bounds.Radius, transform.Transform, this.ParticleService);
コード例 #20
0
        static public BaseComponent LoadComponent(BaseEntity parent, ComponentType type, ContentManager contentManager, string XMLDefinitionPath)
        {
            // This is a factory for creating any component based on a ComponentType
            switch (type)
            {
            case ComponentType.RenderComponent:
            {
                BaseComponent newComponent = RenderComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.CameraComponent:
            {
                BaseComponent newComponent = CameraComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.ConstantMovementComponent:
            {
                BaseComponent newComponent = ConstantMovementComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.ConstantRotationComponent:
            {
                BaseComponent newComponent = ConstantRotationComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.FreeCameraInputComponent:
            {
                BaseComponent newComponent = FreeCameraInputComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.LightEmitterComponent:
            {
                BaseComponent newComponent = LightEmitterComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.PhysicsComponent:
            {
                BaseComponent newComponent = PhysicsComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.PhantomPhysicsComponent:
            {
                BaseComponent newComponent = PhantomPhysicsComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.CharacterPhysicsComponent:
            {
                BaseComponent newComponent = CharacterPhysicsComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.CharacterInputComponent:
            {
                BaseComponent newComponent = CharacterInputComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.WaterComponent:
            {
                BaseComponent newComponent = WaterComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.ArcBallCameraInputComponent:
            {
                BaseComponent newComponent = ArcBallCameraInputComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.ParticleEmitterComponent:
            {
                BaseComponent newComponent = ParticleEmitterComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.SkyDomeComponent:
            {
                BaseComponent newComponent = SkyDomeComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.CollisionTriggerComponent:
            {
                BaseComponent newComponent = CollisionTriggerComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.TerrainComponent:
            {
                BaseComponent newComponent = TerrainComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.TerrainPhysicsComponent:
            {
                BaseComponent newComponent = TerrainPhysicsComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.WaterVolumePhysicsComponent:
            {
                BaseComponent newComponent = WaterVolumePhysicsComponent.LoadFromDefinition(contentManager, XMLDefinitionPath, parent);
                CheckComponentLoadedProperly(newComponent, type);

                return(newComponent);
            }

            case ComponentType.Invalid:
            {
                throw new ArgumentException(String.Format("Invalid component type passed, type {0} is not valid", type));
            }

            default:
            {
                throw new ArgumentException(String.Format("Invalid component type passed, type {0} is not valid", type));
            }
            }
        }