Author Topic: Exiting WM & Device IDs  (Read 2380 times)

0 Members and 1 Guest are viewing this topic.

skylerd

  • World Machine Veteran
  • ***
  • Posts: 23
    • View Profile
Exiting WM & Device IDs
« on: April 11, 2013, 02:20:45 PM »
Hi again!

2 questions:
1) How can I tell when my devices are being destroyed due to the app closing down? Is there something I can check on the core interface? I'm registering/unregistering devices as part of the communication between my application and World machine, and I need to know when a device is actually being deleted from a world machine graph vs. being destroyed because the application is closing.

2) I've noticed that when loading a device, the device id in the constructor will differ from the device id after loading - specifically it seems the id gets loaded by my super class' load function. This is somewhat annoying because I am doing the register/unregister of my devices in the constructor/destructor of my device - could I solve this by moving the register to my activate function? Is Activate guaranteed to be called whenever a new device is created, and upon load of an existing device?

Thanks again,
Skyler.

skylerd

  • World Machine Veteran
  • ***
  • Posts: 23
    • View Profile
Re: Exiting WM & Device IDs
« Reply #1 on: April 12, 2013, 11:30:32 AM »
And is there a flag I can check somewhere to see if the world graph is being rebuilt?

Remnant

  • Author
  • World Machine Guru
  • *****
  • Posts: 2311
    • View Profile
    • http://www.world-machine.com/
Re: Exiting WM & Device IDs
« Reply #2 on: April 12, 2013, 01:56:33 PM »
Hi there,

Re Device IDs:

These are assigned on construction and then again on load as you noticed; the reason they are assigned on load as well is because files can be merged into the current world as well as simply loaded, and in the merging case unique IDs need to be given to each incoming device to prevent ID collisions.

Activate is called when a device is initially placed into the world, and then every time the world changes or a dependency changes. Setting a flag and registering on first activate sounds like the best place to do your registration.

There is unfortunately no notice currently available about a world being closed -- your only notice will be the tear-down of the devices. Also, there is also no flag available to check for current rebuilding -- again since WM's processing model is synchronous.


I can definitely see that a notification/threadsafe interaction interface would be very useful for your use case and probably for others too when doing integrations. It's something I'll consider for the next update!
-- Stephen Schmitt
- Creator of World Machine

skylerd

  • World Machine Veteran
  • ***
  • Posts: 23
    • View Profile
Re: Exiting WM & Device IDs
« Reply #3 on: April 17, 2013, 02:34:44 PM »
FYI: Activate is not always called when devices are first placed into the world - I noticed this when placing the device I created inside a macro that someone had created for WM. Is this a bug, and will it be fixed soon?

Thanks.

Remnant

  • Author
  • World Machine Guru
  • *****
  • Posts: 2311
    • View Profile
    • http://www.world-machine.com/
Re: Exiting WM & Device IDs
« Reply #4 on: April 17, 2013, 02:55:57 PM »
Sorry -- this is correct, but its not exactly a bug -- I'm assuming that the macro was not yet connected, yes?

A macro only activates its internal devices when all required ports (those not flagged optional) are connected. So you won't get an activate until the macro has been connected to something else if it has required inputs.

The problem here isn't in activate, but just that we're sort of overloading it into a notifyAdded() call. Properly of course we would just add those notify methods directly to the device class.

Drop me an email at [email protected] with your notification wishlist, and I'll see if its possible for me to get you an advance out-of-band core+pdk version that has this interface added.
-- Stephen Schmitt
- Creator of World Machine

skylerd

  • World Machine Veteran
  • ***
  • Posts: 23
    • View Profile
Re: Exiting WM & Device IDs
« Reply #5 on: April 17, 2013, 03:21:00 PM »
The macro is connected to a graph at the top level - when I add my device in, it's that parameter device, so it only has parameter outputs. The macro in particular was a cracks and dots macro from this tutorial: http://www.world-machine.com/tutorials/craters/craters.html - in fact its parameter node is a similar idea to what I'm trying to do - where did that node come from?

Anyways, I have yet another question (sorry for consistently peppering you with them) - how can I tell if a parameter port is already connected to something else? Looking at the port, its target is null. I'm dynamically sizing my device as I connect to parameter ports, but I have a bug right now where if I try to connect my empty port to a parameter port an existing port on my device is already connected to, I end up just overriding that link, and end up with an empty port where I don't want one - I only get a MakeLink notification on the output port doing the new connection, and no break link notification on the port whose link is getting overridden.

I'll follow up and send you an email shortly.

skylerd

  • World Machine Veteran
  • ***
  • Posts: 23
    • View Profile
Re: Exiting WM & Device IDs
« Reply #6 on: April 19, 2013, 10:10:08 AM »
A note for others who may stumble upon this: I was able to figure out whether or not the device destruction was caused by shutdown vs. deleting the device by checking GetWorld() of the device - if it's null, then the device is being destroyed as part of shutdown (from what I could tell).