Sign in to follow this  
gameXcore

XNA content pipeline

Recommended Posts

Hi, Ive just started to learn how the content pipeline in XNA works, and how to add new readers and writers for my own objects. My test program for this is a simple particle system that reads its parameters from an XML file. It all works fine for the first call to: XSpriteParticleSystem particles = content.Load<XSpriteParticleSystem>("basic"); The particle system itself loads up all values fromt he XML file properly and renders correctly, the problem comes the second time i call this, with the intention of having 2 particle systems ont he screen at the same time, but both having their parameters loaded fromt he same XML file. What seems to happen is the second call to content.Load<>() doesnt create a new object like it should do, instead it returns the same object that was loaded last time. My actual content reader code incase ive messed something up here:
[source language="C#"]
 public class XSpriteParticleSystemContentReader : ContentTypeReader<XSpriteParticleSystem>
    {
        protected override XSpriteParticleSystem Read(
            ContentReader input,
            XSpriteParticleSystem existingInstance)
        {

            XSpriteParticleSystem system = new XSpriteParticleSystem();

            system.m_spriteName = input.ReadString();
            system.m_spriteSheetRows = input.ReadInt32();
            system.m_spriteSheetCols = input.ReadInt32();

            system.m_spriteSheet = XSpriteSheetManager.addSpriteSheet(
                                        system.m_spriteName,
                                        system.m_spriteName,
                                        system.m_spriteSheetRows,
                                        system.m_spriteSheetCols);

            system.m_maxNoOfParticles = input.ReadInt32();
            system.m_minAngle = input.ReadSingle();
            system.m_maxAngle = input.ReadSingle();
            system.m_minSpeed = input.ReadSingle();
            system.m_maxSpeed = input.ReadSingle();
            system.m_keepEmmitting = input.ReadBoolean();
            system.m_emitFrequency = input.ReadSingle();
            system.m_emitAmount = input.ReadInt32();

            Vector3 color;

            color = input.ReadVector3();
            system.m_startColor = new Color(color);
            color = input.ReadVector3();
            system.m_endColor = new Color(color);

            system.m_particleMinLifeTime = input.ReadSingle();
            system.m_particleMaxLifeTime = input.ReadSingle();
            system.m_systemLifeTime = input.ReadSingle();

            system.loadContent();

            return system;
        }
    }

Breakpointing this function only actually goes into it the first time. While being competent in C++, im still not completly confident with handing objects in C# as ive only just started in it around 2 weeks ago. If anyone can give me some pointers as to what im doing wrong, or how to fix this i would be greatful, i have spent the last few hours trying to get it to work, and im lost. Thanks, Scott

Share this post


Link to post
Share on other sites
I'm no expert, but I think the content manager for XNA caches everything it loads, so when you try to load two instances of the same texture, file, w/e it will just return the first instance.

I would just make a copy constructor in your particle system.

Share this post


Link to post
Share on other sites
I was thinking that, and hoping to avoid it (its jsut anothe rplace for me to fall down while extending it if i forget to add a new variable into the copy constructor) however it has got me thinking that i could extend the entire system, having a particle system manager that loads up multiple systems from the same XML file into a list and store them as templates, each containing their ID name, then when i want a new system, instead of calling load<>() i could request it from the particle manager instead, which will make a copy of the template and return it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this