Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: A few small suggestions  (Read 1990 times)

0 Members and 1 Guest are viewing this topic.

Joki

  • Newbie
  • *
  • Posts: 15
    • View Profile
A few small suggestions
« 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.

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;
}
 

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: A few small suggestions
« Reply #1 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.
« Last Edit: July 10, 2014, 09:29:19 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: A few small suggestions
« Reply #2 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.
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: A few small suggestions
« Reply #3 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.
« Last Edit: July 11, 2014, 12:33:14 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: A few small suggestions
« Reply #4 on: July 11, 2014, 07:40:00 am »
Ok, so: please check the latest sources before posting suggestions ;)
Laurent Gomila - SFML developer

 

anything