Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


- - - - -

Creating a reference object without modifying base class - Possible?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Little Coding Fox   Members   -  Reputation: 192

Like
0Likes
Like

Posted 13 April 2013 - 03:55 AM

I'm working on some AngelScript bindings for a framework I'm working on, and I have created a generic reference countable class that works fine with AngelScript, but I have some problems when I want to interface the properties of the contained class with the scripts.

 

To give you an idea, let's say I have a class Texture. I have something like this in my Reference class:

 

class ScriptReferenceTexture
{
public:
	SuperSmartPointer<Texture> Object;

	uint32 ReferenceCount;

	ScriptReferenceTexture() : ReferenceCount(1) {};

	void AddReference()
	{
		ReferenceCount++;
	};

	void RemoveReference()
	{
		ReferenceCount--;

		if(ReferenceCount == 0)
		{
			delete this;
		};
	};

	static ScriptReferenceTexture *Factory()
	{
		return new ScriptReferenceTexture();
	};
};

So this works fine for containing the Texture object, but let's say I want to connect a regular Texture to a ScriptTexture stored in another script class, or want to add methods that access the Texture's own methods. I can't do that since the reference counting bit isn't in the Texture class, and I'm using a smart pointer to store the texture class so modifying the Texture class is not going to work.

 

I really don't want to change my resource handling scheme since SuperSmartPointers are too important for the native side (since my framework should be used both with and without scripting), and they also allow for the implicit destruction of their contained object (which goes against the AngelScript reference style).

 

So does anyone have any idea of how I could solve this?



Sponsor:

#2 Little Coding Fox   Members   -  Reputation: 192

Like
0Likes
Like

Posted 13 April 2013 - 05:20 AM

I found a way to solve this. Simply create a new class that inherits from ScriptReferenceTexture and add the new methods there, and if I need to use properties I simply create the Get/Set methods as described by the AS documentation.



#3 AgentC   Members   -  Reputation: 1416

Like
1Likes
Like

Posted 13 April 2013 - 11:37 AM

I know you said you don't want to modify your existing resource handling, but if you made your smart pointer mechanism intrusively reference-counted, ie. Texture would have its own AddRef() and RemoveRef() functions, then using a smart pointer and an AngelScript handle would be essentially equivalent, and there would be no need for the Reference class at all.


Every time you add a boolean member variable, God kills a kitten. Every time you create a Manager class, God kills a kitten. Every time you create a Singleton...

Urho3D (engine)  Hessian (C64 game project)





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS