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

Author Topic: Feasibility of providing unsafe field-set methods, e.g. for Vertex in VertexArr?  (Read 3806 times)

0 Members and 1 Guest are viewing this topic.

phunanon

  • Newbie
  • *
  • Posts: 1
    • View Profile
To not necro-bump this previous topic, I've created a new topic.

I've bumped into the same issue: needing to recreate a Vertex, and set an index of VertexArray to the new instance.

Would it be feasible to provide methods such as SetPosition(sf::Vector2f position, uint index), SetColor(sf::Color color, uint index), etc, within VertexArray, which would set relevant fields in an unsafe context? 
I can imagine this is not the only array-type within SFML.NET which suffers from this problem.

Unfortunately I only have access to a C# environment at work, otherwise I'd spend time trying to get the source to work and profile it, so I have only theoretical comment: it would probably be better performance; it would definitely mean more maintenance; it would most likely be found through Intellisense and used above recreation.

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Not added to SFML, but you could get the desired behavior with an extension method. And if you're using C# 7 you actually don't need to use unsafe (if not, you'd return Vertex* instead of ref Vertex):
public static class VertexArrayExt
{
    public static ref Vertex getVertex(this VertexArray va, uint index)
    {
        return ref sfVertexArray_getVertex(va.CPointer, index);
    }

    [DllImport("csfml-graphics-2.dll", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
    private static extern ref Vertex sfVertexArray_getVertex(IntPtr CPointer, uint index);
}