• Welcome to World Machine Community. Please login or sign up.
May 19, 2019, 06:05:20 am


Read the Development Diary for an inside look at World Machine's progress!

text input field parameter

Started by CKlosters, October 26, 2011, 03:27:01 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


October 26, 2011, 03:27:01 am Last Edit: October 26, 2011, 07:00:54 am by CKlosters

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();

-- Stephen Schmitt
- Creator of World Machine


Thanks, that did it for me  :D
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


November 02, 2011, 04:34:34 pm #3 Last Edit: November 02, 2011, 04:37:09 pm by Remnant
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 .
-- Stephen Schmitt
- Creator of World Machine


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

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.

Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S save/post or ALT+P preview