Changes in last commit

1 view
Skip to first unread message

Martin Scheffler

unread,
Jul 12, 2012, 7:37:25 AM7/12/12
to dtenti...@googlegroups.com
Hi all,
just a notice about the changes I just committed.

I added a CMake flag CALL_ONPROPERTYCHANGED_METHOD. When this is set
to false, the method PropertyContainer::OnPropertyChanged will be set
to private so it can no longer be overwritten. Also it is no longer
called in the code. If you need to react to property changes, use
properties in dtEntity/dynamicproperty.h instead.

Currently the flag defaults to ON, but I will soon change that, and at
some point I will remove the OnPropertyChanged stuff completely from
the code.

I also did some changes to the way properties of JavaScript components
/ entity systems are created.
These changes are also in when CALL_ONPROPERTYCHANGED_METHOD is on.
Before, all properties of the JS component were converted to dtEntity
properties the first time a js component was accessed from C++.
The type of the properties would be determined from the type of the
javascript property.

function MyComponent() {
this.items = 30;
this.temperature = 30.0;
}

This component, opened in the editor, would show two integer
properties because values with .0 are treated as ints by javascript.
Another problem was that properties not meant for conversion to
dtEntity properties had to begin with "__", forgetting that could
cause problems.

The new way works like this:

function MyComponent() {
createUint32Prop(this, "items", 30);
createNumberProp(this, "temperature", 30.0);
createStringProp(this, "Projection", "3d", function() { return
this.value; }, function(val) { this.value = val; });
}

create*Property has this form:
function(object, propertyname, value, getter, setter);
When value is omitted then value is undefined.
getter and setter, if defined, are functions that are called to set or
get the property. The "this" in these functions references an empty
object that can be used for storage purposes. If omitted, these
functions take the form
getter = function() { return this.value}
setter = function(v) { this.value = v; }

You can set these functions to react to property changes. The values
are converted to the type of the property.

This code is very fresh so expect problems.

Cheers,
Martin

Riccardo Corsi

unread,
Jul 12, 2012, 9:27:58 AM7/12/12
to dtenti...@googlegroups.com
Hi Martin,

thanks for the update. Just a couple of general questions to understand the new framework:
- Properties created by JS are now immediately converted to their dtEntity counterpart?
- if/when converted, are they always dynamic props, or they are dynamic only if getter and setter are specified by the JS code?
- as getter and setter are js methods, is there a way to access/set those property from c++ ?

Thank you!
Ricky



Martin Scheffler

unread,
Jul 12, 2012, 2:58:02 PM7/12/12
to dtenti...@googlegroups.com
Javascript properties always use getter/setter functions. When no
functions are given then a default function is used.
When a js property is created then immediately an object deriving from
dtEntity::Property is created and added to the javascript component
as a hidden property. When the component is accessed from c++ and a
wrapper is created then all hidden properties on the js component are
added to the wrapping component.
These js properties are visible in the editor and can be used just
like the c++ properties. To access them from c++ you can use
component->Get(SID(propertyname))->SetString("bla") or something like
that.

Cheers,
Martin

2012/7/12 Riccardo Corsi <riccard...@kairos3d.it>:
Reply all
Reply to author
Forward
0 new messages