public override void Initialize(ContentManager contentLoader, ComponentManifest manifest) { mSettings = contentLoader.Load <ParticleSystemSettings>((string)(manifest.Properties[ManifestKeys.PARTICLE_SYSTEM_SETTINGS])); string techniqueName = "StandardParticles"; if (manifest.Properties.ContainsKey(ManifestKeys.TECHNIQUE_NAME)) { techniqueName = (string)(manifest.Properties[ManifestKeys.TECHNIQUE_NAME]); } LoadParticleEffect(contentLoader, techniqueName); // Allocate the particle array, and fill in the corner fields (which never change). mParticles = new ParticleVertex[mSettings.MaxParticles * 4]; for (int i = 0; i < mSettings.MaxParticles; ++i) { mParticles[i * 4 + 0].Corner = new Short2(-1.0f, -1.0f); mParticles[i * 4 + 1].Corner = new Short2(+1.0f, -1.0f); mParticles[i * 4 + 2].Corner = new Short2(+1.0f, +1.0f); mParticles[i * 4 + 3].Corner = new Short2(-1.0f, +1.0f); } mParticleData = new ParticleData(); // Create a dynamic vertex buffer. mParticleData.VertexBuffer = new DynamicVertexBuffer( SharedResources.Game.GraphicsDevice, ParticleVertex.VertexDeclaration, mSettings.MaxParticles * 4, BufferUsage.WriteOnly); // Create and populate the index buffer. ushort[] indices = new ushort[mSettings.MaxParticles * 6]; for (int i = 0; i < mSettings.MaxParticles; i++) { indices[i * 6 + 0] = (ushort)(i * 4 + 0); indices[i * 6 + 1] = (ushort)(i * 4 + 1); indices[i * 6 + 2] = (ushort)(i * 4 + 2); indices[i * 6 + 3] = (ushort)(i * 4 + 0); indices[i * 6 + 4] = (ushort)(i * 4 + 2); indices[i * 6 + 5] = (ushort)(i * 4 + 3); } mParticleData.IndexBuffer = new IndexBuffer( SharedResources.Game.GraphicsDevice, typeof(ushort), indices.Length, BufferUsage.None); mParticleData.IndexBuffer.SetData(indices); mParticleData.MaxParticles = mSettings.MaxParticles; GameResources.ActorManager.PreAnimationUpdateStep += PreAnimationUpdateHandler; GameResources.ActorManager.UpdateComplete += UpdateCompleteHandler; base.Initialize(contentLoader, manifest); }
public ParticleSystemRenderComponent(Actor owner) : base(owner) { mEffect = null; mSettings = null; mParticles = null; mParticleData = null; mCurrentTime = 0.0f; mFirstNewParticleIndex = 0; mFirstRetiredParticleIndex = 0; mDrawCounter = 0; }
public ParticleSystemGeometryNode(ParticleData particleData, IncrementDrawCounterDelegate incrementDrawCounter, EffectApplication defaultMaterial) : base(defaultMaterial) { mParticleData = particleData; mIncrementDrawCounter = incrementDrawCounter; }
public override void Initialize(ContentManager contentLoader, ComponentManifest manifest) { mSettings = contentLoader.Load<ParticleSystemSettings>((string)(manifest.Properties[ManifestKeys.PARTICLE_SYSTEM_SETTINGS])); string techniqueName = "StandardParticles"; if (manifest.Properties.ContainsKey(ManifestKeys.TECHNIQUE_NAME)) techniqueName = (string)(manifest.Properties[ManifestKeys.TECHNIQUE_NAME]); LoadParticleEffect(contentLoader, techniqueName); // Allocate the particle array, and fill in the corner fields (which never change). mParticles = new ParticleVertex[mSettings.MaxParticles * 4]; for (int i = 0; i < mSettings.MaxParticles; ++i) { mParticles[i * 4 + 0].Corner = new Short2(-1.0f, -1.0f); mParticles[i * 4 + 1].Corner = new Short2(+1.0f, -1.0f); mParticles[i * 4 + 2].Corner = new Short2(+1.0f, +1.0f); mParticles[i * 4 + 3].Corner = new Short2(-1.0f, +1.0f); } mParticleData = new ParticleData(); // Create a dynamic vertex buffer. mParticleData.VertexBuffer = new DynamicVertexBuffer( SharedResources.Game.GraphicsDevice, ParticleVertex.VertexDeclaration, mSettings.MaxParticles * 4, BufferUsage.WriteOnly); // Create and populate the index buffer. ushort[] indices = new ushort[mSettings.MaxParticles * 6]; for (int i = 0; i < mSettings.MaxParticles; i++) { indices[i * 6 + 0] = (ushort)(i * 4 + 0); indices[i * 6 + 1] = (ushort)(i * 4 + 1); indices[i * 6 + 2] = (ushort)(i * 4 + 2); indices[i * 6 + 3] = (ushort)(i * 4 + 0); indices[i * 6 + 4] = (ushort)(i * 4 + 2); indices[i * 6 + 5] = (ushort)(i * 4 + 3); } mParticleData.IndexBuffer = new IndexBuffer( SharedResources.Game.GraphicsDevice, typeof(ushort), indices.Length, BufferUsage.None); mParticleData.IndexBuffer.SetData(indices); mParticleData.MaxParticles = mSettings.MaxParticles; GameResources.ActorManager.PreAnimationUpdateStep += PreAnimationUpdateHandler; GameResources.ActorManager.UpdateComplete += UpdateCompleteHandler; base.Initialize(contentLoader, manifest); }