HomeHome  CalendarCalendar  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log inLog in  

Share | 
 

 Make Constructors protected instead of private

View previous topic View next topic Go down 
AuthorMessage
MonRoyal



Messages : 6
Date d'inscription : 2011-11-17

PostSubject: Make Constructors protected instead of private   Wed Nov 23, 2011 6:31 am

Hi Spark-Team,

thanks for the great support for my previous question Smile.

Is it possible to change the constructors to protected instead of private? I would like to extend your classes and to tweak them for me. For example I would like to replace the linear interpolation of the Interpolator by a more sophisticated approach, where e.g. a bezier curve can be used. At the moment it's not possible for me to add this behaviour without changing your code.

Is there any special reason for making them private?

Best Regards
Damir


Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: Make Constructors protected instead of private   Sun Nov 27, 2011 6:46 am

Hi, constructors are private and destructors are not virtual because those classes are not supposed to be derived. The correct way of doing it would be to create a new interpolator ("BezierInterpolator or CubicInterpolator").

Not that there is the graph interpolator which allows to have complex behavior without using expensive interpolation method.
Back to top Go down
View user profile http://spark.developpez.com
MonRoyal



Messages : 6
Date d'inscription : 2011-11-17

PostSubject: Re: Make Constructors protected instead of private   Sun Nov 27, 2011 12:42 pm

I meant no offense Smile. My english is not the best and it probably sound a little bit rude...

I'm very thankfull for your great work and your great source code design. I've evaluated many different approaches and yours was the best by far for my needs.

I would like to change the linear interpolation because I've already have a GUI class which constructs for me bezier curves and other stuff and I would like to reuse this class, so that I don't need to code something new. But anyway it's not a big deal for me.

So sorry, if it sounds unpolite and keep up the good work.

Thanks
Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: Make Constructors protected instead of private   Sun Nov 27, 2011 3:39 pm

Hi, your first post was not impolite and I didnt felt offended at all. I dont know what made you think so...

Anyway, I just realized you were talking about SPARK 1 and not SPARK 2... Sorry about that. In SPARK 2 there s a base class called Interpolator which you can derive to interpolate particles values the way you want. That is why I was suggesting you to make your own interpolator...

Regarding SPARK 1, I am not going to modify it anymore, but if you want need some modifications on the API you can do it and submit your changes to me, and I will update the library if they are pertinent.

The interpolator class in SPARK 1 was added after the library was designed, therefore it is not very flexible. Maybe you want to take a look at SPARK 2 which has a far better design (event if it is not out yet it is relatively stable)

Sorry about the misunderstanding Wink
Back to top Go down
View user profile http://spark.developpez.com
MonRoyal



Messages : 6
Date d'inscription : 2011-11-17

PostSubject: Re: Make Constructors protected instead of private   Tue Nov 29, 2011 7:48 am

Hi, sorry for the misinterpretation of your reply Smile.

I'm using Spark 2 and you have a base class for all interpolators with the mehtod interpolateParam(..) which is called by all other interpolators. I would like to override this method for your modifiers, so that I can use my own interpolation functions. Otherwise I had to copy all of your interpolator classes to only change the interpolation function.

From my point of view it would be great if (almost) everything would be a protected instead of private, so that there everyone can easily adjust the classes so they fit their needs. At the moment I don't have any other idea what I could or should modify, but who knows which ideas I get, when I work longer with spark2.

Thanks
Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: Make Constructors protected instead of private   Tue Nov 29, 2011 2:38 pm

Ok I got what you said.

Actually this method interpolateParam which is a helper method should rather be called interpolateParamLinearly.

When designing SPARK 2 I tried to avoid having virtual methods called for each particle when iterating through a group to avoid the virtual table lookup overhead. Moreover having not virtual method like this one allows inlining and saving the method call. So this is far more performant than having a interpolateParam which can be overidden.

A way to add flexibility by keeping those optimization at the same time, is to use function as template parameter. Those function should theorically be inlined and optimized fine.

But still, it wont be possible to use say cubic interpolation with the function having this signature as I am passing 2 values to interpolate between while a cubic interpolation requires 4 values. So I dont even see how you would use cubic interpolation (or even quadratic) by overriding interpolateParam.

There may be a way to get flexibility, performance and code factorization by using template but i need to think a bot more about it
Back to top Go down
View user profile http://spark.developpez.com
MonRoyals



Messages : 3
Date d'inscription : 2011-11-29

PostSubject: Re: Make Constructors protected instead of private   Tue Nov 29, 2011 7:06 pm

Ok, I got your point too Smile.
I would like to have this interpolateParam method hidden behind an interface, so that I could configure the interpolator with an "InterpolationFunctionClass" which implements the interface interpolateParam(float x, float y, float time).
The "InterpolationFunctionClass" could be configured in all different shapes: Linearly, Bezier, Cubic,... The input parameters for performing the interpolation would always be same like in your current implementation.

I have more a Java background than a C++ background, so I don't care so much about virtual lookup tables and such stuff Smile. But I got your point that performance is crucial especially for a particle system. Maybe you find a way to add flexibility without loosing performance...

Thanks for the great support

Back to top Go down
View user profile
Juff
Developer


Messages : 539
Date d'inscription : 2009-07-14
Age : 34

PostSubject: Re: Make Constructors protected instead of private   Tue Nov 29, 2011 7:17 pm

Ok but tell me how do you want to perform other interpolation than linear with only 2 values and a ratio ?

Ok in case of an interpolator using a start and end value you can use arbitraty horizontal tangents and then only need 2 entry points but in case of a complete track of value you gonna need (p-1,p,p+1,p+2) so that you can derive the tangent. If you use arbitrary horizontal tangent in that case, the interpolation will just be awful so 2 values are not enough. Its the rule : you need n+1 values for an interpolation of degree n.
Back to top Go down
View user profile http://spark.developpez.com
MonRoyal



Messages : 6
Date d'inscription : 2011-11-17

PostSubject: Re: Make Constructors protected instead of private   Wed Nov 30, 2011 5:36 am

In a case where I need n values for an interpolation I would e.g. use your GraphInterpolator and configure n values. For the interpolation between x and x + 1 I could use an interpolation function like a bezier curve. The bezier curve could be configured with m control points. And for each point in time you would have 2 values from your GraphInterpolator and a configred bezier curve for the interpolation.
Also the performance issue would not be crucial in my case, because I would precompute an array with interpolated bezier values, so that in each frame only one array access would be needed.

I hope I got your point Wink
Back to top Go down
View user profile
Sponsored content




PostSubject: Re: Make Constructors protected instead of private   Today at 9:29 am

Back to top Go down
 
Make Constructors protected instead of private
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Ten Ways to Make Peace With the Past and Create a New Future
» How do I make the login popup show an Image, instead of it's bland colors
» can i make the poster details in the topic above the topic
» Do migraines ever make you mean or irritable?
» Does throwing up make it go away quicker for you?

Permissions in this forum:You cannot reply to topics in this forum
 :: English Forum :: Evolution (en)-
Jump to: