SFML community forums

Bindings - other languages => DotNet => Topic started by: Joki on July 10, 2014, 08:28:46 pm

Title: A few small suggestions
Post by: Joki on July 10, 2014, 08:28:46 pm
A few small things that i would like to suggest are:

1.
Instead of having the users override Destroy() of ObjectBase to handle finalizing, let users implement the IDisposable interface and use the standard suggested finalizer (http://msdn.microsoft.com/en-us/library/fs2xkftw(v=vs.110).aspx).

This used to crash at a decent chance, when i just assigning a new AnimatedSprite to the old variable:

class AnimatedSprite : Sprite, IUpdateable, ICloneable, IDisposable
{
        bool disposed = false;

        public void Dispose()
        {
                Dispose(true);
                GC.SuppressFinalize(this);
        }

        void Dispose(bool disposing)
        {
                if (!this.disposed)
                {
                        if (disposing)
                        {
                                // dispose managed ressources
                                EntityManager.Instance.UnregisterDrawable(this);
                                EntityManager.Instance.UnregisterUpdateable(this);
                        }
                        // dispose unmanaged ressources
                }
        }

        ~AnimatedSprite()
        {
                Dispose(false);
        }
}
 

Access violations when i created a new instance of AnimatedSprite, although i handled disposing myself, until i found out i was supposed to overwrite Objectbase.Dispose() (using an almost empty override just to stop the garbage collector from finalizing the sprite, while sfml was still drawing the object).


2.
Remove the /////////////////////////////////////////////// first and last line of the xml doc tags.
Common IDEs such as Visual Studio and MonoDevelop will not display tooltips (i.e. IntelliSense), since they don't understand xml docu that way. (Also documentation compilers such as SandCastle will not be able to create a documentation that way)

3.
- Add explicit conversions for closely related types, such as Vector2f, Vector2i, Vector2u, e.g.

        public static explicit operator Vector2f(Vector2i vector)
        {
                return new Vector2f(vector.X, vector.Y);
        }
 

- Add extension methods for closely related types, such as Vector2f, Vector2i, Vector2u, e.g.

        public static class VectorExtensions
        {
                public static Vector2i ToVec2i(this Vector2f vec)
                {
                        return new Vector2i((int)vec.X, (int)vec.Y);
                }

                public static Vector2u ToVec2u(this     Vector2f vec)
                {
                        return new Vector2u((uint)vec.X, (uint)vec.Y);
                }

                public static Vector2f ToVec2f(this Vector2i vec)
                {
                        return new Vector2f(vec.X, vec.Y);
                }

                public static Vector2u ToVec2u(this Vector2i vec)
                {
                        return new Vector2u((uint)vec.X, (uint)vec.Y);
                }

                public static Vector2f ToVec2f(this Vector2u vec)
                {
                        return new Vector2f(vec.X, vec.Y);
                }

                public static Vector2f ToVec2i(this Vector2u vec)
                {
                        return new Vector2f(vec.X, vec.Y);
                }
        }
 

allowing for a bit more comfort:

static void Main(string[] args)
{
        Vector2f vec2f = new Vector2f(50f, 100f);
        Vector2u displayResolution = vec2f.ToVec2u();

        Vector2i vec2i = new Vector2i(50, 100);
        Vector2f someVec2f = (Vector2f)vec2i;
}
 
Title: Re: A few small suggestions
Post by: zsbzsb on July 10, 2014, 09:24:16 pm
Quote
Instead of having the users override Destroy() of ObjectBase to handle finalizing

You aren't supposed to be inheriting SFML types (unless stated), the same applies to the core SFML and to SFML.NET. Not to mention the InternalBase class is clearly marked for internal use only.

Quote
Common IDEs such as Visual Studio and MonoDevelop will not display tooltips (i.e. IntelliSense), since they don't understand xml docu that way.

Where did you get this from? My IntelliSense works fine. As far as the IDE is concerned it is an empty line.

Quote
Add explicit conversions for closely related types, such as Vector2f, Vector2i, Vector2u, e.g.

Doesn't exist in core SFML for good reasons, and the same applies to the binding. Feel free to write your own extension methods if you want this.
Title: Re: A few small suggestions
Post by: Laurent on July 10, 2014, 09:44:41 pm
Explicit conversion between vector types exist in C++. However I don't see the need for extension methods if we add these cast operators.
Title: Re: A few small suggestions
Post by: zsbzsb on July 10, 2014, 09:49:00 pm
Explicit conversion between vector types exist in C++.

Didn't notice the explicit conversion (thought implicit was suggested) :P, anyways SFML.NET already has explicit casting (https://github.com/SFML/SFML.Net/blob/master/src/System/Vector2.cs#L396).
Title: Re: A few small suggestions
Post by: Laurent on July 11, 2014, 07:40:00 am
Ok, so: please check the latest sources before posting suggestions ;)