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

Author Topic: SFML.NET and CSFML 2.3  (Read 3734 times)

0 Members and 1 Guest are viewing this topic.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
SFML.NET and CSFML 2.3
« on: October 12, 2015, 12:39:59 am »
I switched to use CSFML 2.3 with SFML.NET binding.
It seems that all works OK and it even don't crashed on app close under windows xp.

But there is strange behavior with mouse buttons.
With CSFML 2.2 I received RenderWindow.MouseButtonPressed but with CSFML 2.3 it didn't works.
I added trace into Window.CallEventHandler and found that CSFML 2.3 sends EventType.MouseButtonReleased only.
Is there is any change in mouse event processing? or it's just a bug?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFML.NET and CSFML 2.3
« Reply #1 on: October 12, 2015, 12:48:42 am »
Are you sure all 3 are same version? I remember having some weird interactions between CSFML/SFML/SFML.Net on Mono on my Linux when I mixed versions, there is a new event enum value (MouseWheelScrolled) just before Released/Pressed so everything after it is offset by one. Some events don't arrive and some are wrong, like Release is Pressed (or vice versa, I don't remember now clearly) because it moved up by one. Check if that's happening.
Back to C++ gamedev with SFML in May 2023

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: SFML.NET and CSFML 2.3
« Reply #2 on: October 12, 2015, 01:07:16 am »
Yeah I just fund it in the source code.
There is very bad change in Event.h
A new value was added in 2.3 to the middle of event list:
    51  sfEvtMouseWheelMoved,
    52  sfEvtMouseWheelScrolled,  // <= added line - very bad practice
    53  sfEvtMouseButtonPressed,
 

So, I inserted this one into EventType and it works OK:
            /// <summary>Event triggered when the mouse wheel is moved</summary>
            MouseWheelMoved,

            /// <summary>Event triggered when the mouse wheel is scrolled</summary>
            MouseWheelScrolled,

            /// <summary>Event triggered when a mouse button is pressed</summary>
            MouseButtonPressed,
 

Actually it's bad practice to insert new code into the middle of list.
It's better to add it into the end of list. Otherwise it will cause version compatibility issues...

Is there any other changes like this for enums?

PS: at a glance it seems that with this change SFML.NET works OK with CSFML 2.3. And I it works a little faster, fps for my test scene grows up from 350 to 450


Update: I compared source code of CSFML 2.2 and CSFML 2.3 and found that there is some changes in the type of function argument. It's not critical for x86 platform. But there is mistake for p/invoke declarations. There is used uint type, which is fixed size 32 bit for all platform in C#. But in C it is declared as size_t.
So, I fixed it with declaring UIntPtr in C#.
This fix affects Shape, Window, Texture and VertexArray.

Also there are minor changes with adding getter of native handle for texture and shader.

Also there are two changes: new mouse wheel event with new struct (the old one still works but it was marked as deprecated) and new field in ContextSettings.

I implemented new changes and fixed p/invoke, so now I have complete SFML.NET binding for CSFML 2.3! :)
I tested it on different systems and it works better than CSFML 2.2. Better fps, no app crash issue under windows xp and now it allows to handle vertical and horizontal mouse wheels.
« Last Edit: October 12, 2015, 07:57:16 am by mkalex777 »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML.NET and CSFML 2.3
« Reply #3 on: October 12, 2015, 01:25:46 pm »
I really don't know why I am bothering to reply.... but for reference if anyone else comes across this topic: All mentioned changes have already been made to CSFML/SFML.Net. Learn to check version tags on github.
« Last Edit: October 12, 2015, 01:35:49 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: SFML.NET and CSFML 2.3
« Reply #4 on: October 12, 2015, 05:16:55 pm »
Omg, so I spent so many time for the thing which is already done :)
Anyway, now I know more details about sfml implementation and how to use it more effective

 

anything