Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline elasto  
#1 Posted : Tuesday, February 7, 2012 10:38:10 AM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
I've come across a couple of issues using the Effect class.

I'll start with the unimportant bug first:



When you stop an Effect which has already been stopped earlier, it throws an exception. This does not happen if you call twice during the same frame, only if there is a delay imposed.
(I am assuming it's once all active particles have phased out and the effect is removed from some collection and you then try to stop it again after that.)

Code:
Error: Fatal Error: Unhandled exception occurred (Application is terminated, we cannot recover!): System.NullReferenceException: Object reference not set to an instance of an object.
	at Delta.Rendering.Effects.Effect.tXnsKu9SDOVwMiJBRY(Object , Boolean value)
	at Delta.Rendering.Effects.Effect.Stop(Int32 effectId)




The second is a bit difficult to describe but you'll see what I mean when you see the pictures:

I have rockets producing smoke trails, and the first rockets that get fired have thin, whispy trails whereas later rockets that get fired have thick, dense trails. This is not with the rocket trails overlaying each other, this is each individual rocket's trail changing form. It may be an intended result of the parameters I am using or perhaps a bug. Here are my parameters:

Code:

            EffectData data = EffectData.Get("<SmokeEffect>");
         
            EmitterData emitter = new EmitterData();
            emitter.Modifiers.Add(new SpawnIntervalModifier { SpawnInterval = 0.05f });
            emitter.Modifiers.Add(new ParticleLifetimeModifier { ParticleLifetime = 1f });
            emitter.Modifiers.Add(new TimeRangeModifier { TimeRange = new Range(0f, float.PositiveInfinity) });         
            emitter.Modifiers.Add(new FadeModifier { AdvancedAlphaFade = new Graph().Add(0, 0).Add(0.25f, 1.0f).Add(1.0f, 0.0f) });
            emitter.Modifiers.Add(new MaterialModifier { Material = new Material2DColored("Smoke") });
            emitter.Modifiers.Add(new RandomRotationModifier { RotationRange = new Range(0, 360) });
            emitter.Modifiers.Add(new SizeModifier { WidthRange = new Range(.25f, .5f), HeightRange = new Range(.25f, .5f) });

            data.Emitters.Add(emitter);
            EmitterID = Effect.Spawn(data, this);


I attach two pictures of one rocket spawned early in the game and one spawned later.



The third is not so much a bug as a limitation - one I can't work around since I think the Effects class is currently closed-source.

I am moving the background in response to mousedrags - and everything I am in control of drawing moves along with the drag. However, the positions of the active particles don't move; They just carry on animating at the absolute screen position they were created at. See the attached picture if you don't get what I mean.

It seems to me you need a couple more methods (call them what you wish, obviously!):

Effect.Move(int effectID, Point/Vector movement)
Effect.MoveAll(Point/Vector movement)
- where I can pass in the relative amount the screen/viewpoint has moved during this frame and all live particle positions are adjusted by this offset.
elasto attached the following image(s):
Bug 2a.png (22kb) downloaded 5 time(s).
Bug 2b.png (25kb) downloaded 6 time(s).
Bug 3.png (160kb) downloaded 21 time(s).

You cannot view/download attachments. Try to login or register.

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline bfox  
#2 Posted : Tuesday, February 7, 2012 11:33:29 AM(UTC)
bfox

Joined: 8/22/2011(UTC)
Posts: 170
Location: Moscow

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
Please use the [ code=csharp ] some c# code [ /code ] in post
Russian game developer.
Давайте делать игры в команде. Идет набор.
Offline elasto  
#3 Posted : Tuesday, February 7, 2012 11:46:03 AM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Originally Posted by: BFoX (Russian Developer) Go to Quoted Post
Please use the [ code=csharp ] some c# code [ /code ] in post
Why? It doesn't format any differently for me if I do [ code ] [ /code ] or [ code=csharp ] [ /code ]

Is there a forum option where it renders differently?
Offline bfox  
#4 Posted : Tuesday, February 7, 2012 11:48:56 AM(UTC)
bfox

Joined: 8/22/2011(UTC)
Posts: 170
Location: Moscow

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
Originally Posted by: PG Go to Quoted Post
Originally Posted by: BFoX (Russian Developer) Go to Quoted Post
Please use the [ code=csharp ] some c# code [ /code ] in post
Why? It doesn't format any differently for me if I do [ code ] [ /code ] or [ code=csharp ] [ /code ]

Is there a forum option where it renders differently?

code
Code:
EffectData data = EffectData.Get("<SmokeEffect>");
EmitterData emitter = new EmitterData();

code=csharp
Code:
EffectData data = EffectData.Get("<SmokeEffect>");
EmitterData emitter = new EmitterData();

in preview you can't see differences

Edited by user Tuesday, February 7, 2012 11:50:44 AM(UTC)  | Reason: Not specified

Russian game developer.
Давайте делать игры в команде. Идет набор.
Offline elasto  
#5 Posted : Tuesday, February 7, 2012 11:54:11 AM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Oh, that's interesting. It formats it differently but only after a long delay. Must be javascript or something.

It was slow enough for me to be able to take a screenshot and reply to you that they rendered the same for me and just as I was about to post it changed :p

"in preview you can't see differences"

No, even in your post it rendered the same for me for a long time, then redrew itself.

Edited by user Tuesday, February 7, 2012 11:55:16 AM(UTC)  | Reason: Not specified

Offline bfox  
#6 Posted : Tuesday, February 7, 2012 11:57:03 AM(UTC)
bfox

Joined: 8/22/2011(UTC)
Posts: 170
Location: Moscow

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
Originally Posted by: PG Go to Quoted Post
Oh, that's interesting. It formats it differently but only after a long delay. Must be javascript or something.

It was slow enough for me to be able to take a screenshot and reply to you that they rendered the same for me and just as I was about to post it changed :p

"in preview you can't see differences"

No, even in your post it rendered the same for me for a long time, then redrew itself.

It's javascript work slowly =)

Edited by user Tuesday, February 7, 2012 12:01:19 PM(UTC)  | Reason: Not specified

Russian game developer.
Давайте делать игры в команде. Идет набор.
Offline elasto  
#7 Posted : Tuesday, February 7, 2012 11:59:50 AM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Originally Posted by: BFoX (Russian Developer) Go to Quoted Post
It's javascript work slowly =)
Very slowly! Just timed it, took 30 seconds to change from plain text to coloured & numbered.

I did wonder why there why the different options so thanks for explaining it!
Offline bfox  
#8 Posted : Tuesday, February 7, 2012 12:02:21 PM(UTC)
bfox

Joined: 8/22/2011(UTC)
Posts: 170
Location: Moscow

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
About the your code. Maybe I can try to understand what the problem is. Maybe you send me your project and add to the content manager?
Russian game developer.
Давайте делать игры в команде. Идет набор.
Offline elasto  
#9 Posted : Tuesday, February 7, 2012 12:13:56 PM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Originally Posted by: BFoX (Russian Developer) Go to Quoted Post
About the your code. Maybe I can try to understand what the problem is. Maybe you send me your project and add to the content manager?


There isn't anything more to it than I've quoted - the Effect class being so compact in this case is its downfall! Unfortunately it appears to be closed source to me so I can't debug through it.
Offline bfox  
#10 Posted : Tuesday, February 7, 2012 12:18:40 PM(UTC)
bfox

Joined: 8/22/2011(UTC)
Posts: 170
Location: Moscow

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
Originally Posted by: PG Go to Quoted Post
Originally Posted by: BFoX (Russian Developer) Go to Quoted Post
About the your code. Maybe I can try to understand what the problem is. Maybe you send me your project and add to the content manager?


There isn't anything more to it than I've quoted - the Effect class being so compact in this case is its downfall! Unfortunately it appears to be closed source to me so I can't debug through it.

Ok. Then if i have time, I'll try to reproduce. Are you use bilboards and camera or simple (Material2D.draw)

Edited by user Tuesday, February 7, 2012 12:21:10 PM(UTC)  | Reason: Not specified

Russian game developer.
Давайте делать игры в команде. Идет набор.
Offline elasto  
#11 Posted : Tuesday, February 7, 2012 12:30:23 PM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Originally Posted by: BFoX (Russian Developer) Go to Quoted Post
Originally Posted by: PG Go to Quoted Post
Originally Posted by: BFoX (Russian Developer) Go to Quoted Post
About the your code. Maybe I can try to understand what the problem is. Maybe you send me your project and add to the content manager?


There isn't anything more to it than I've quoted - the Effect class being so compact in this case is its downfall! Unfortunately it appears to be closed source to me so I can't debug through it.

Ok. Then if i have time, I'll try to reproduce. Are you use bilboards and camera or simple (Material2D.draw)
Everything is just Material2D.Draw except for Effect which draws itself fire-and-forget style - hence the problem!

If Benjamin and co are too busy it'd not be too hard to implement my own smoke trail that doesn't have these issues so I'm not too worried, but obviously the Effects class is almost perfect and they'd want to know to fix it.
Offline elasto  
#12 Posted : Tuesday, February 7, 2012 2:35:26 PM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Bug 2 I can reproduce just with a slight modification to the SmokeEffect tutorial. Here's the modified code demonstrating the bug:

Code:

#region SmokeEffect (Static)
/// <summary>
/// Tutorial: Particle Effect Tutorial 2: Smoke Effect
/// Difficulty: Medium
/// Description: Draw a simple smoke effect.
/// Image: http://DeltaEngine.net/Icons/EffectTutorial2.png
/// </summary>
[Test, Category("Visual")]
public static void SmokeEffect()
{
    //********************************************
    //Set max to a large number or set it to 1 and you'll get a different visual effect even though you shouldn't - 
    //because all but the last Effect are killed before ever producing a particle
    //********************************************
    //int max = 40;
    int max = 1;

    for (int i = 0; i < max; i++)
    {

        // Create a new template.
        EffectData data = EffectData.Get("<SmokeEffect>");
        // Add an emitter and modifiers.
        EmitterData emitter = new EmitterData();
        emitter.Modifiers.Add(new SpawnIntervalModifier
        {
            SpawnInterval = 0.05f,
        });
        emitter.Modifiers.Add(new ParticleLifetimeModifier
        {
            ParticleLifetime = 2f
        });
        emitter.Modifiers.Add(new TimeRangeModifier
        {
            TimeRange = new Range(0f, float.PositiveInfinity),
        });
        emitter.Modifiers.Add(new FadeModifier
        {
            // Create simple graph for fading in and out!
            AdvancedAlphaFade =
            new Graph().Add(0, 0).Add(0.25f, 1.0f).Add(1.0f, 0.0f),
        });
        emitter.Modifiers.Add(new MaterialModifier
        {
            Material = new Material2DColored(
            //"SmokeBrightTransparency"),
            "Smoke"),
            //"SmokeAdditive"),
            //"SmokeSmallAdditive"),
        });
        emitter.Modifiers.Add(new RandomVelocityModifier
        {
            MinVelocity = new Vector(-0.05f, -0.1f, 0f),
            MaxVelocity = new Vector(0.05f, -0.1f, 0f),
        });
        emitter.Modifiers.Add(new RandomRotationModifier
        {
            RotationRange = new Range(0, 360),
        });
        data.Emitters.Add(emitter);
        //Effect.Spawn(data, new Vector(0.5f, 0.5f, 0f));
        // Always follow the mouse :)
        int id = Effect.Spawn(data, new MouseTracker());

        //********************************************
        //Insta-kill all but the last effect
        //********************************************
        if (i<max-1) Effect.Kill(id);
    }
    Application.Start();
}
#endregion

Edited by user Tuesday, February 7, 2012 2:38:58 PM(UTC)  | Reason: Not specified

Offline elasto  
#13 Posted : Tuesday, February 7, 2012 3:26:31 PM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
And, to reiterate, bug 3 isn't properly a bug. I'll explain it with an example in case there's any confusion:

I draw a turret at (.5, .5), a rocket at (.7, .5) and a smoke particle is drawn at (.6, .5) by the Effect.

I do a mousedrag which relocates the turret to (.5, .3) and the rocket to (.7, .3) but the smoke particle remains at (.6, .5) because, well, why wouldn't it? It has no idea about my 'camera movement' because there's no way of telling it. If I had the source code I could just slot in a new method but I don't!
Offline bfox  
#14 Posted : Tuesday, February 7, 2012 4:00:24 PM(UTC)
bfox

Joined: 8/22/2011(UTC)
Posts: 170
Location: Moscow

Thanks: 3 times
Was thanked: 2 time(s) in 2 post(s)
if i undestend bug 2.
see this:
Code:

     [Test, Category("Visual")]
        public static void SmokeEffect()
        {
            //********************************************
            //Set max to a large number or set it to 1 and you'll get a different visual effect even though you shouldn't - 
            //because all but the last Effect are killed before ever producing a particle
            //********************************************
            //int max = 40;
            int max = 40;
            // Add an emitter and modifiers.
            // Create a new template.
            EffectData data = EffectData.Get("<SmokeEffect>");
            // Add an emitter and modifiers.
            EmitterData emitter = new EmitterData();
            emitter.Modifiers.Add(new SpawnIntervalModifier
            {
                SpawnInterval = 0.05f,
            });
            emitter.Modifiers.Add(new ParticleLifetimeModifier
            {
                ParticleLifetime = 2f
            });
            emitter.Modifiers.Add(new TimeRangeModifier
            {
                TimeRange = new Range(0f, float.PositiveInfinity),
            });
            emitter.Modifiers.Add(new FadeModifier
            {
                // Create simple graph for fading in and out!
                AdvancedAlphaFade =
                new Graph().Add(0, 0).Add(0.25f, 1.0f).Add(1.0f, 0.0f),
            });
            emitter.Modifiers.Add(new MaterialModifier
            {
                Material = new Material2DColored(
                    //"SmokeBrightTransparency"),
                "Smoke"),
                //"SmokeAdditive"),
                //"SmokeSmallAdditive"),
            });
            emitter.Modifiers.Add(new RandomVelocityModifier
            {
                MinVelocity = new Vector(-0.05f, -0.1f, 0f),
                MaxVelocity = new Vector(0.05f, -0.1f, 0f),
            });
            emitter.Modifiers.Add(new RandomRotationModifier
            {
                RotationRange = new Range(0, 360),
            });
            data.Emitters.Add(emitter);
            for (int i = 0; i < max; i++)
            {
                // Create a new template.

                //Effect.Spawn(data, new Vector(0.5f, 0.5f, 0f));
                // Always follow the mouse :)
                int id = Effect.Spawn(data, new MouseTracker());

                //********************************************
                //Insta-kill all but the last effect
                //********************************************
                if (i < max - 1) Effect.Kill(id);
            }

            Application.Start();
        }


or i found - add in you code:
Code:
if (i < max - 1) Effect.Kill(id);
data.Dispose();


About 3 I can not find a solution Mellow

Try to use the camera and BillboardManager (3d world). You do not need to change the coordinates of all objects

Edited by user Tuesday, February 7, 2012 4:27:01 PM(UTC)  | Reason: Not specified

Russian game developer.
Давайте делать игры в команде. Идет набор.
thanks 1 user thanked bfox for this useful post.
elasto on 2/7/2012(UTC)
Offline elasto  
#15 Posted : Tuesday, February 7, 2012 5:37:28 PM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Originally Posted by: BFoX (Russian Developer) Go to Quoted Post
Code:
if (i < max - 1) Effect.Kill(id);
data.Dispose();
Ooh. I think you're onto something there! I'll try it out, thanks.

Quote:
Try to use the camera and BillboardManager (3d world).
That would be an option. It'd also be easy just to add smoke particles manually though. (I appreciate the Effect class has hardware optimisations for particle effects, so the ideal would be if I could just make the tweak to it.)

Quote:
You do not need to change the coordinates of all objects
Well, naturally, I don't do it quite in that way. I've effectively written my own 2D camera class with scroll, zoom and everything else. Nothing actually changes position; Everything just renders through the camera just like 3D would - including the attributes implementing the IAttachable interface on the class being passed into Effect - hence why new particles always spawn in the correct position for that moment in time; It's just that I can't alter the position of particles already added.

Edited by user Tuesday, February 7, 2012 6:02:35 PM(UTC)  | Reason: Not specified

Offline elasto  
#16 Posted : Tuesday, February 7, 2012 5:46:11 PM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Ok, so, yes, I have a workaround for 2 - which I guess turns it from a bug to a feature. I've added a line of code and now all smoke trails are the same wispy density:

Code:

EffectData data = EffectData.Get("<SmokeEffect>");

//New line of code - clears emitters being carried forward from one Effect.Spawn to the next
data.Emitters.Clear();

EmitterData emitter = new EmitterData();
emitter.Modifiers.Add(new SpawnIntervalModifier { SpawnInterval = 0.05f });
emitter.Modifiers.Add(new ParticleLifetimeModifier { ParticleLifetime = 1f });
emitter.Modifiers.Add(new TimeRangeModifier { TimeRange = new Range(0f, float.PositiveInfinity) }); 
emitter.Modifiers.Add(new FadeModifier { AdvancedAlphaFade = new Graph().Add(0, 0).Add(0.25f, 1.0f).Add(1.0f, 0.0f) });
emitter.Modifiers.Add(new MaterialModifier { Material = new Material2DColored("Smoke") });
emitter.Modifiers.Add(new RandomRotationModifier { RotationRange = new Range(0, 360) });
emitter.Modifiers.Add(new SizeModifier { WidthRange = new Range(.25f, .5f), HeightRange = new Range(.25f, .5f) });

data.Emitters.Add(emitter);
EmitterID = Effect.Spawn(data, this);


So that one can effectively be struck off the list.
Offline Benjamin  
#17 Posted : Tuesday, February 7, 2012 6:02:43 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Hi PG,

Thanks for the detailed bug report. Please keep in mind that the Effect System is NOT final, it will probably change a lot once we find time to focus on Rendering again. For this reason we did not include it into the public release yet (all other Rendering assemblies are in there). There are several issues with high performance rendering I would like to address before marking it stable. The particle effect system runs fine for Arena Wars, SoulCraft and other games (and they use a lot of particles), but it is not as good as it could be. Some issues have been fixed (static lists are used mostly everywhere), but when trying to render thousands of particle effects on very slow devices (2-3 year old mobile devices) things could be better. Luckily we did not have a use case for that yet, but sooner or later we will do some tutorials about that.

Anyone interested about this can check out the performance tests in Delta.Rendering.EffectTests.Effect2DTests and obviously if anyone is willing to dig into the Effect System, improve and refactor bits, we are willing to accept help :)

Originally Posted by: PG Go to Quoted Post

When you stop an Effect which has already been stopped earlier, it throws an exception. This does not happen if you call twice during the same frame, only if there is a delay imposed.
(I am assuming it's once all active particles have phased out and the effect is removed from some collection and you then try to stop it again after that.)

Code:
Error: Fatal Error: Unhandled exception occurred (Application is terminated, we cannot recover!): System.NullReferenceException: Object reference not set to an instance of an object.
	at Delta.Rendering.Effects.Effect.tXnsKu9SDOVwMiJBRY(Object , Boolean value)
	at Delta.Rendering.Effects.Effect.Stop(Int32 effectId)



This is fixed now (check the next nightly release). I found 6 other places where the effect instance is returned (via EffectManager.GetEffectById) that did not check if the effect exists at all. Those are fixed as well.

This issue seems to go by undetected mostly because once you fill the effect system with many particles all lists are filled quickly and deleting or stopping effects will just rearrange ids to entries that have been initialized previously. Thanks for finding it.

Originally Posted by: PG Go to Quoted Post

The second is a bit difficult to describe but you'll see what I mean when you see the pictures:

I have rockets producing smoke trails, and the first rockets that get fired have thin, whispy trails whereas later rockets that get fired have thick, dense trails. This is not with the rocket trails overlaying each other, this is each individual rocket's trail changing form. It may be an intended result of the parameters I am using or perhaps a bug. Here are my parameters:

Code:

            EffectData data = EffectData.Get("<SmokeEffect>");
         
            EmitterData emitter = new EmitterData();
            emitter.Modifiers.Add(new SpawnIntervalModifier { SpawnInterval = 0.05f });
            emitter.Modifiers.Add(new ParticleLifetimeModifier { ParticleLifetime = 1f });
            emitter.Modifiers.Add(new TimeRangeModifier { TimeRange = new Range(0f, float.PositiveInfinity) });         
            emitter.Modifiers.Add(new FadeModifier { AdvancedAlphaFade = new Graph().Add(0, 0).Add(0.25f, 1.0f).Add(1.0f, 0.0f) });
            emitter.Modifiers.Add(new MaterialModifier { Material = new Material2DColored("Smoke") });
            emitter.Modifiers.Add(new RandomRotationModifier { RotationRange = new Range(0, 360) });
            emitter.Modifiers.Add(new SizeModifier { WidthRange = new Range(.25f, .5f), HeightRange = new Range(.25f, .5f) });

            data.Emitters.Add(emitter);
            EmitterID = Effect.Spawn(data, this);


I attach two pictures of one rocket spawned early in the game and one spawned later.


Nice to see you guys figured out a way around this issue, but I suspect that you don't use the spawning correctly (my guess would be creating either too many emitters or reusing them too much). I have to reproduce this issue first and dig into it, so I have written down a feature request, which I will check out later this month if I have time.

Originally Posted by: PG Go to Quoted Post

The third is not so much a bug as a limitation - one I can't work around since I think the Effects class is currently closed-source.

I am moving the background in response to mousedrags - and everything I am in control of drawing moves along with the drag. However, the positions of the active particles don't move; They just carry on animating at the absolute screen position they were created at. See the attached picture if you don't get what I mean.

It seems to me you need a couple more methods (call them what you wish, obviously!):

Effect.Move(int effectID, Point/Vector movement)
Effect.MoveAll(Point/Vector movement)
- where I can pass in the relative amount the screen/viewpoint has moved during this frame and all live particle positions are adjusted by this offset.


I get what you are saying. Obviously creating effects in world position (2d or 3d) won't move with the world if you move the world on your own. If you just move the camera, everything will work fine.

Obviously there are many cases when you want to spawn particle effects (and maybe even attach other things to stuff like physic bodies, etc.). For this reason there is an interface called IAttachable, which can be used at many places in the engine including the Particle Effect System. Some of the Tutorials in Delta.Rendering.EffectTests show how to use it (just create an effect with an IAttachable class instead of a direct position):
Code:

			// Always follow the mouse :)
			Effect.Spawn(data, new MouseTracker());


You probably won't find many uses of the IAttachable interface in the engine or tutorials, but the source code to MouseTracker is all there in Delta.Engine.Game and you can easily extend your own classes to be IAttachable (in your case either your world class with the current screen position or just create a simple helper class). All you need to implement is Position and Rotation (and rotation can mostly be ignored, especially in 2D):
Code:

		#region Position (Public)
		/// <summary>
		/// The current position of the attachable.
		/// </summary>
		public Vector Position
		{
			get
			{
				return new Vector(Input.Mouse.Position, 0.0f);
			}
		}
		#endregion

		#region Rotation (Public)
		/// <summary>
		/// The current rotation of the attachable.
		/// </summary>
		public float Rotation
		{
			get
			{
				// Unused
				return 0.0f;
			}
		}
		#endregion


Hope that helps Cool
Offline elasto  
#18 Posted : Tuesday, February 7, 2012 6:12:43 PM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Originally Posted by: Benjamin Nitschke (DeltaEngine) Go to Quoted Post
Nice to see you guys figured out a way around this issue, but I suspect that you don't use the spawning correctly (my guess would be creating either too many emitters or reusing them too much). I have to reproduce this issue first and dig into it, so I have written down a feature request, which I will check out later this month if I have time.
I'll point out my post #16 in case you didn't spot it (our posts might have crossed).

Basically, I didn't appreciate that EffectData.Get("<SmokeEffect>") carries forward emitters into the next Effect.Spawn. Now I do!

Quote:
I get what you are saying. Obviously creating effects in world position (2d or 3d) won't move with the world if you move the world on your own. If you just move the camera, everything will work fine.
Is there a 2D camera class? I couldn't really see one. (Although, admittedly, I didn't look all that hard as it didn't take me long to write one, as I mentioned in post #15.)

Quote:
Obviously there are many cases when you want to spawn particle effects (and maybe even attach other things to stuff like physic bodies, etc.). For this reason there is an interface called IAttachable, which can be used at many places in the engine including the Particle Effect System. Some of the Tutorials in Delta.Rendering.EffectTests show how to use it (just create an effect with an IAttachable class instead of a direct position):
Yeah, it wasn't obvious from my code example but, as I mentioned (probably while you were writing this post) my rocket class implements IAttachable.

Edited by user Tuesday, February 7, 2012 6:14:12 PM(UTC)  | Reason: Not specified

Offline Benjamin  
#19 Posted : Tuesday, February 7, 2012 6:57:15 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
I did not say the rocket itself should be IAttachable, if you move the world including the rocket around, then you need another outer IAttachable object that helps the effect system to track the movement.

As BFox and me already mentioned it might be easier to use a camera. There was an effort to create a 2D camera (with 3D rendering) some time ago here in the forum, but I guess it was not finished (should not be hard to implement).
Offline elasto  
#20 Posted : Tuesday, February 7, 2012 7:37:45 PM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Originally Posted by: Benjamin Nitschke (DeltaEngine) Go to Quoted Post
I did not say the rocket itself should be IAttachable, if you move the world including the rocket around, then you need another outer IAttachable object that helps the effect system to track the movement.

As BFox and me already mentioned it might be easier to use a camera. There was an effort to create a 2D camera (with 3D rendering) some time ago here in the forum, but I guess it was not finished (should not be hard to implement).
Well, like I say, drags, zooms etc don't change the position of any objects in the world. That would be a pretty inefficient way to code it to my mind. All movement like that goes through my own 2D camera class. I don't see that an IAttachable to the world itself would help therefore but maybe I'm missing something.

Besides, like I say, if I move the camera, newly spawned smoke particles appear in the right place - because the Position property on the Rocket is transformed by my camera class before feeding into the Effect engine. It just can't affect particles already spawned because, well, they're spawned and drawn to a position on screen that I can't alter.

Edit: Or is there some collection inside the emitter object that has the positions of all the particles?

Edited by user Tuesday, February 7, 2012 7:39:53 PM(UTC)  | Reason: Not specified

Offline Benjamin  
#21 Posted : Tuesday, February 7, 2012 8:01:35 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Yes that should be possible, I will forward the question to the guy that made the emitters/particles IAttachable. Dunno of the top of my head.

Maybe you find ways around it in the meantime ^^
Offline elasto  
#22 Posted : Wednesday, February 8, 2012 2:35:13 AM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Hmm. Don't worry too much about that. I've realised another problem that will still occur.

Let me backtrack and explain how my 2D Camera class operates.

- All drawable objects in my world have a position, size and rotation.
- When it is time for them to be drawn, instead of the object's Draw method just calling straight into Material.Draw, it calls Camera.Draw(Material, Position, Size, Rotation)
- the Camera.Draw transforms the object's position and size according to its own viewpoint and then calls Material.Draw if the object intersects the screen (culling)

So, all object positions and sizes remain in 'world coordinates' and the camera converts to 'screen coordinates' for drawing. Same idea as with 3D but it's a true 2D camera.

Now, what this means is that, had I the source code, and were the Effect class to draw using Material.Draw, it would be a one-line fix for me: Inserting Camera.Draw in place of Material.Draw (well, I'd need to pass in the Camera so a two-line chang. Edit: Nope, I made my Camera class static so I was right the first time ^_^). I suspect it's not as simple as that due to hardware-instancing optimisations though.

The flip-size is that you exposing the positions of the live particles for me to transform isn't quite enough, were you to do that: I also need to transform their sizes. Only then could Effect particles act just the same as all the other objects in my game.

I think what I'll do therefore is just have my rocket produce smoke particles periodically outside of the Effect class until I have the Effect source code. The alternative is to redo my code using one of the 3D cameras but I don't want to do that ^_^ My camera has extra features built in like intelligent zooming: You can specify the boundaries of the world and the camera never allows you to look outside of that. So if you are at top-left of the world and zoom out, your view expands down-rightwards; Whereas if you are at the bottom-right of the world and zoom out, your view expands up-leftwards. Likewise if, on Windows, you change the aspect ratio, it will, if necessary, adjust the camera position to keep you inside the world.

(I don't mind donating my Camera class to the community at some point if anyone feels it would be useful to them; I'd like the chance to test it on a mobile device first though ^_^)

So, basically, you can consider this thread resolved in full now. Thank you both for your time :)

Edited by user Wednesday, February 8, 2012 2:43:39 AM(UTC)  | Reason: Not specified

Offline elasto  
#23 Posted : Wednesday, February 8, 2012 4:45:24 AM(UTC)
elasto

Joined: 8/23/2011(UTC)
Posts: 245

Thanks: 6 times
Was thanked: 12 time(s) in 11 post(s)
Ok so quick final question.

I've finishing coding a replacement for the Effect class and it's rendering fine (runs a bit slower than Effect but respects my camera position at least ^_^) - the only thing I can't find out is how to render with a given value of alpha.

ie What's the DE equivalent for when you call SpriteBatch.Draw(... Color color) in XNA to apply an alpha? I must be missing the obvious I think.

Doh. Typical. Worked it out right after I posted haha: Set material.BlendColor

All working now :)

Edited by user Wednesday, February 8, 2012 4:48:12 AM(UTC)  | Reason: Not specified

Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.251 seconds.