diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-04-02 09:38:05 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-04-02 09:38:05 +0400 |
commit | fcc23faa3a5ec3c697e85e9a6b604ac7db80a05b (patch) | |
tree | 83203f4bdf0f56d6de7b659449aade290fe0d90b /source/gameengine/Expressions/Value.h | |
parent | 48e4a4834092a8772141e6240e5e70d67110f126 (diff) |
Added getitem/setitem access for KX_GameObject
ob.someProp = 10
can now be...
ob["someProp"] = 10
For simple get/set test with an objects 10 properties, this is ~30% faster.
Though I like the attribute access, its slower because it needs to lookup BGE attributes and methods (for parent classes as well as KX_GameObject class).
This could also be an advantage if there are collisions between new attributes added for 2.49 and existing properties a game uses.
Made some other small optimizations,
- Getting and setting property can use const char* as well as STR_String (avoids making new STR_Strings just to do the lookup).
- CValue::SetPropertiesModified() and CValue::SetPropertiesModified(), were looping through all items in the std::map, advancing from the beginning each time.
Diffstat (limited to 'source/gameengine/Expressions/Value.h')
-rw-r--r-- | source/gameengine/Expressions/Value.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h index caf1064dc32..4678ab1f0c2 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/Value.h @@ -283,10 +283,12 @@ public: /// Property Management virtual void SetProperty(const STR_String& name,CValue* ioProperty); // Set property <ioProperty>, overwrites and releases a previous property with the same name if needed - virtual CValue* GetProperty(const STR_String & inName); // Get pointer to a property with name <inName>, returns NULL if there is no property named <inName> + virtual void SetProperty(const char* name,CValue* ioProperty); + virtual CValue* GetProperty(const char* inName); // Get pointer to a property with name <inName>, returns NULL if there is no property named <inName> + virtual CValue* GetProperty(const STR_String & inName); STR_String GetPropertyText(const STR_String & inName,const STR_String& deftext=""); // Get text description of property with name <inName>, returns an empty string if there is no property named <inName> float GetPropertyNumber(const STR_String& inName,float defnumber); - virtual bool RemoveProperty(const STR_String & inName); // Remove the property named <inName>, returns true if the property was succesfully removed, false if property was not found or could not be removed + virtual bool RemoveProperty(const char *inName); // Remove the property named <inName>, returns true if the property was succesfully removed, false if property was not found or could not be removed virtual vector<STR_String> GetPropertyNames(); virtual void ClearProperties(); // Clear all properties |