Author Topic: text input field parameter  (Read 2703 times)

0 Members and 1 Guest are viewing this topic.

CKlosters

  • World Machine Veteran
  • ***
  • Posts: 20
    • View Profile
text input field parameter
« on: October 26, 2011, 03:27:01 AM »
Hi,

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
« Last Edit: October 26, 2011, 07:00:54 AM by CKlosters »

Remnant

  • Author
  • World Machine Guru
  • *****
  • Posts: 2311
    • View Profile
    • http://www.world-machine.com/
Re: text input field parameter
« Reply #1 on: October 31, 2011, 07:41:01 PM »
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!

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

....
In your device activate function

char *str = params.GetParam(0)->getHelpString();
...
-- Stephen Schmitt
- Creator of World Machine

CKlosters

  • World Machine Veteran
  • ***
  • Posts: 20
    • View Profile
Re: text input field parameter
« Reply #2 on: November 02, 2011, 07:30:39 AM »
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

Remnant

  • Author
  • World Machine Guru
  • *****
  • Posts: 2311
    • View Profile
    • http://www.world-machine.com/
Re: text input field parameter
« Reply #3 on: November 02, 2011, 04:34:34 PM »
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)

Anyways.

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)
Code: [Select]
...
        HField *resource = other->resource;
if (resource )
resource ->AddRef();

in the device's destructor:
Code: [Select]
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 .
« Last Edit: November 02, 2011, 04:37:09 PM by Remnant »
-- Stephen Schmitt
- Creator of World Machine

CKlosters

  • World Machine Veteran
  • ***
  • Posts: 20
    • View Profile
Re: text input field parameter
« Reply #4 on: November 07, 2011, 03:25:03 AM »
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