/*
* ParticleReader.cs
* Authors: Brian Murphy
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using TACParticleEngine.Emitters;
using TACParticleEngine.FileProcessing;
namespace TACParticleEngine.Particles
{
///
/// Reads & process Particle Engines
///
public class ParticleReader : ContentTypeReader
{
///
/// Content Reader for particle engine files
///
/// File to read from
/// An instance of desired return type so that Read is recognized
/// by the XNA content pipeline
/// A new particle engine filled with emitters made from the read in data
protected override ParticleEngine Read(ContentReader input, ParticleEngine existingInstance)
{
List emitterInfoList = input.ReadObject>();
List emitters = new List();
foreach (EmitterInfo info in emitterInfoList)
{
//SpriteResourceManager.getSingleton.load(info.TextureName);
if (info.MinVel.Equals(Vector3.Zero) && info.MaxVel.Equals(Vector3.Zero))
{
if (info.Positions.Count > 1)
{
emitters.Add(new SplineEmitter(info.Positions,
info.BlendEffect, info.TextureName, info.ParticlePersSec, info.ParticleAmount,
info.EmitLifetime, info.ParticleLifetime, info.MinStartSize, info.MaxStartSize,
info.MinEndSize, info.MaxEndSize, info.MinStartSpeed, info.MaxStartSpeed, info.MinEndSpeed,
info.MaxEndSpeed, info.MinStartColor, info.MaxStartColor, info.MinEndColor, info.MaxEndColor));
}
else if (info.Positions.Count == 1)
{
emitters.Add(new PointEmitter(info.Positions[0],
info.BlendEffect, info.TextureName, info.ParticlePersSec, info.ParticleAmount,
info.EmitLifetime, info.ParticleLifetime, info.MinStartSize, info.MaxStartSize,
info.MinEndSize, info.MaxEndSize, info.MinStartSpeed, info.MaxStartSpeed, info.MinEndSpeed,
info.MaxEndSpeed, info.MinStartColor, info.MaxStartColor, info.MinEndColor, info.MaxEndColor));
}
else
{
continue;
}
}
else
{
if (info.Positions.Count == 1)
{
if (info.MinVel.X < -1 || info.MinVel.Y < -1 || info.MinVel.Z < -1 ||
info.MinVel.X > 1 || info.MinVel.Y > 1 || info.MinVel.Z > 1 ||
info.MaxVel.X < -1 || info.MaxVel.Y < -1 || info.MaxVel.Z < -1 ||
info.MaxVel.X > 1 || info.MaxVel.Y > 1 || info.MaxVel.Z > 1)
{
emitters.Add(new SprayEmitter(info.Positions[0], info.MinVel, info.MaxVel,
info.BlendEffect, info.TextureName, info.ParticlePersSec, info.ParticleAmount,
info.EmitLifetime, info.ParticleLifetime, info.MinStartSize, info.MaxStartSize,
info.MinEndSize, info.MaxEndSize, info.MinStartSpeed, info.MaxStartSpeed,
info.MinEndSpeed, info.MaxEndSpeed, info.MinStartColor, info.MaxStartColor,
info.MinEndColor, info.MaxEndColor));
}
else
{
emitters.Add(new DirectionalEmitter(info.Positions[0], info.MinVel, info.MaxVel,
info.BlendEffect, info.TextureName, info.ParticlePersSec, info.ParticleAmount,
info.EmitLifetime, info.ParticleLifetime, info.MinStartSize, info.MaxStartSize,
info.MinEndSize, info.MaxEndSize, info.MinStartSpeed, info.MaxStartSpeed, info.MinEndSpeed,
info.MaxEndSpeed, info.MinStartColor, info.MaxStartColor, info.MinEndColor, info.MaxEndColor));
}
}
else
{
continue;
}
}
}
return new ParticleEngine(emitters);
}
}
}