text input field parameter


How can I add and set the context of a simple text field parameter?
I can create int/float/bool parameters and enumerators but can’t seem to find a simple method for creating a simple text input field which I can set.

Similar to the file input > file details parm.

Any help would be appreciated, regards, Coen

Hi there,

You want to use a Parameter of type V_STR. The string is stored within the help string for the parameter. This is not well documented behavior unfortunately!

In your device's constructor:
	Parameter p("Example string parameter");
	p.type = V_STR;

In your device activate function

char *str = params.GetParam(0)->getHelpString();

Thanks, that did it for me :smiley:
I couldn’t figure it out through the example files.

Another question (related to the previous one, or causing the previous one)
I noticed that when switching between views (for example from device to lay-out) the objects get destructed and constructed again.
When dealing with data that needs to be imported (and kept around, for example images) this becomes quite heavy. The actual processing times are low compared to loading the image in memory every time.

I tried creating a singleton class holding the image but this results in only one image to be loaded at all times (shared across the generators). The other option would be to create some sort of file manager but that looks (to me) as overkill. How would you approach handling data that needs to be associated with an object (generator for example) and kept around?

Is there any method or functionality in world machine that supports this?

Thanks in advance!

Cheers Coen

Yes, in the current architecture, the device world is copied for the layout/explorer view, and also for tiled builds. This means that each device is essentially deep copied, which is OK for lightweight but not, as you note, for heavyweight.

If it is a simple read-only resource (like a loaded file), then a shared resource via smart pointer/reference counting is the best way to share the resource. More heavyweight shared resources might need a separate resource manager class (the Tiled File Input device does this because it is managing a much more complicated set of files, caching, etc)


In the 2.2 codebase, shared resources are manually reference counted. For example, the File Input device does something like the below.

In the device’s doClone() function (polymorphic copy constructor)

        HField *resource = other->resource;
	if (resource )
		resource ->AddRef();

in the device’s destructor:

	if (resource )
		resource ->Release();

as long as all accesses are read-only, the WMPacket-based objects are thread-safe while shared. If you are writing to the resource you should manually protect it with mutual exclusion.

A last note: In the upcoming WM 2.3 codebase, all raw pointers are internally wrapped in a boost::intrusive_ptr to automatically call AddRef() and Release() as appropriate .

Thanks for clarifying that Remnant.
I’ll have to start looking into building a resource manager, as we’ll need one later on anyway.

Cheers Coen