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

Author Topic: Help with Events  (Read 4443 times)

0 Members and 1 Guest are viewing this topic.

pencils

  • Newbie
  • *
  • Posts: 5
    • View Profile
Help with Events
« on: October 18, 2010, 03:19:18 pm »
Hi there,

First, thanks for the great library. I really appreciate all your hard work!

I am trying to use the .NET interface in an application I am designing. The language I am programming in is called LabVIEW, and is a graphical programming language. Attached is a picture of a simple demo I have got working which just displays a background and draws some text to the screen.
I include the picture just for information purposes, the grey box around the render code signifies a while loop.



Uploaded with ImageShack.us

I have successfully used the Window.Input.GetMouseX etc in a polled loop and these all work fine.

My next step is to try and register these events to work as a callback, and this is where I am getting stuck. In LabVIEW there is a mechanism for registering a .NET object as an event, but I cannot seem to use any of the constructed objects from your library. When I "wire" in the input I get a broken wire which is LabVIEW telling me I am trying to perform an invalid operation.

I know this is probably all nonsense to you, sorry! Just putting this out there in case someone has any clues. I have zero .NET experience :-(

I am using .NET version of the library (1.6) downloaded from the main site.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Help with Events
« Reply #1 on: October 18, 2010, 03:41:36 pm »
What have you tried so far?

I don't know what class(es) can be used as LabVIEW events, but I think the best candidate are native events (window.Closed, window.Resized, etc.).

I'm curious: what the hell are you doing with SFML + LabVIEW? :D
Laurent Gomila - SFML developer

pencils

  • Newbie
  • *
  • Posts: 5
    • View Profile
Help with Events
« Reply #2 on: October 18, 2010, 04:10:28 pm »
Quote from: "Laurent"

I'm curious: what the hell are you doing with SFML + LabVIEW? :D


Just for fun really! Coding in LabVIEW is my day-job
Building a game with LabVIEW and SFML is my night-job :-)

As I said, I do not have very much .NET experience, but I have managed to get several other .NET objects to work with events. For example, the NotifyIcon.

HAHA!

You are a genius! I was trying to create an instance of an Event (for example a MouseMoveEvent) and register that. Instead if I take the reference from the Window object I created at the beginning, when I wire it into my Register node (the LabVIEW primitive that allows me to register a callback), then all of a sudden I get a bunch of events listed and I can then pick the event I want and it works as I expected :-)

Parfait! :-)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Help with Events
« Reply #3 on: October 18, 2010, 04:17:14 pm »
That sounds fun indeed :)

Let us know when you have something working ;)
Laurent Gomila - SFML developer

pencils

  • Newbie
  • *
  • Posts: 5
    • View Profile
Help with Events
« Reply #4 on: October 23, 2010, 11:59:46 pm »
been playing more with SFML as I get the time, busy wrapping the .NET classes in native LabVIEW classes. Fun!

I have a few problems though, mostly still related to events (I think). I get odd lock-ups and sometimes crashes, or the RenderWindow does not dispose properly at the end of my app and then my LabVIEW IDE crashes.

My test app is quite simple, I am trying to draw a filled circle at the current cursor position, using a Circle Shape. I cant really post the code (as its LabVIEW!), but it would be something like this:

create RenderWindow

while (not stop button)
{
   RenderWindow.DispatchEvents
   RenderWindow.Clear
   Update Position of Circle
   RenderWindow.Draw (circle)
   RenderWindow.Display
}

 I am using DispatchEvents and separately registering callback code for the events. At the moment the only event registered is MouseMoved. The event reads the mouse position from MouseMoveEventArgs and updates a global variable.

LabVIEW is naturally multithreaded, and I suspect my callback event code is being called (sometimes) during a call to one of the above functions.

The above code is quite laggy, and if I move the mouse to quickly the Renderwindow gets very confused and just draws two circles (alternating in different but close places) for a while before figuring out what it should be doing...

Q 1: Is the .NET interface thread-safe?
Q 2: If I plot the mouse position in a native labview plot at the same time as I draw the circle on the screen (from the same loop) the labview graph shows the position updated nice and smoothly but the SFML RenderWindow is very jerky. Any ideas on this? (This is a dumb question, sorry!)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Help with Events
« Reply #5 on: October 24, 2010, 10:30:30 am »
Quote
Q 1: Is the .NET interface thread-safe?

No. And there are things that the OS will never let you do, for example handling events in a thread different than the one where the window was created.

Quote
Q 2: If I plot the mouse position in a native labview plot at the same time as I draw the circle on the screen (from the same loop) the labview graph shows the position updated nice and smoothly but the SFML RenderWindow is very jerky. Any ideas on this? (This is a dumb question, sorry!)

No, sorry. It's hard to tell.
Laurent Gomila - SFML developer

pencils

  • Newbie
  • *
  • Posts: 5
    • View Profile
Help with Events
« Reply #6 on: October 24, 2010, 02:51:20 pm »
ok, thanks for the reply.

Am unfortunately probably going to be unable to proceed with SFML, which is a real pity as I think it has great potential.

My big problem, from lots of tests I can see that LabVIEW really does not play nicely with SFML. LabVIEW code always runs with a GUI (there is not really an easy way to make a console application), and I have seen from lots of experimentation that this GUI interferes with SFML.

The results are quite unpredictable, but really manifest themselves when I use LabVIEW's native multithreading (parallel loops). Using the SFML FramerateLimit causes the app to behave very inconsistently (crashes, sometimes nothing being displayed etc).

I could perhaps work around this, but am still left with the problem of strange jerks in the framerate. Everything can be going butter smooth and then I get an annoying pause for a fraction of a second which is very noticeable. I have removed events and everything else suspicision from my code, but no joy here :-(