Simple object without AddRef
I have some non-virtual, shallow-copy safe classes that I cannot change, such as vectors and matrices. I want these to be instantiable objects which are automatically created when they are in-scope and deleted out of scope, without reference counting. I will never reference an object created in script from C++.
For example:
{
// myVec should be created here!
Vector3 myVec;
myVec.x=0;
// myVec should be deleted here!
}
The problem is, some of my functions return pointers to vectors. Which means I have to use references "@".
At first I tried reference counting by adding a refCount via inheritance. But that only works for functions I control. Because when the function returns a pointer to the base class, and not to the derived class, the reference counter doesn't get instantiated.
It's not an option to derive/change 200+ functions to return instances of my reference counted class.
What I really need is just a reference/pointer to the true class, forget about reference counting. I already tried SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES,1) but it won't allow me to make a reference without first registering a function ADD_REF
What can I do?
[Edited by - Rakkar2 on May 8, 2007 8:13:12 PM]
Your C++ registered functions should be able to return references to the vector3 objects, without the need for unsafe references or reference counting. Just register them as:
"vector3 &func()"
The script can then use the returned reference on the left side of assignment expressions, if that is what you need.
Of course, you'll have to make sure the pointer returned from the function is never null, as that would crash the application.
Functions declared in scripts are not allowed to return references to these types though.
"vector3 &func()"
The script can then use the returned reference on the left side of assignment expressions, if that is what you need.
Of course, you'll have to make sure the pointer returned from the function is never null, as that would crash the application.
Functions declared in scripts are not allowed to return references to these types though.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement