Archived

This topic is now archived and is closed to further replies.

Amadrias

C/C++ tip

Recommended Posts

hi all, I''d like to submit a class method to LS_RegisterHUDFunction this way : void HANDLERCLASS::SetRenderFunction() { LS_RegisterHUDFunction(myclass.HUDRender); } it do not work correctly as my compiler says when I try to build : error C2664: ''SetRenderFunction'' : cannot convert parameter 1 from ''void'' to ''void (__cdecl *)(void)'' Expressions of type void cannot be converted to other types ANy tip on how to do that using C++ and is there a performance cost ? Thanks, Amadrias

Share this post


Link to post
Share on other sites
It''s got to be a static member function of your class. Define it as:

static void __cdecl HUDRender(void);

No performance cost (as far as I know), but you can''t overload the function or have multiple instances of it because it''s static.

Share this post


Link to post
Share on other sites
thx Dr Pain...
Now I still have another problem.

In that static method, I do have 2 calls to :

PR_TransformEntity(m_pEntity);
PR_RenderEntity(m_pEntity);

where m_pEntity is defined in the current class.

The compiler says I can't use sdata members in a static function...

please help...

Amadrias

PS : Did you get my email in hotmail ?

Edited by - amadrias on December 17, 2001 11:41:43 AM

Share this post


Link to post
Share on other sites
That's right.
You can't use the variables that are object specific, in a static function.

You're only options are:
1) Make the class a regular non-static class function.
2) Pass in the variables as parameters.

Edited by - Gorky on December 17, 2001 12:04:59 PM

Share this post


Link to post
Share on other sites
Gorky is correct, you can''t access members from the static function, because it''s technically not a member of the class. Or perhaps I should say it''s not a member of the instance of that class.

What you could do is have a public member function that returns the variable you want access to, for instance:

Entity * GetEntity(void) { return m_pEntity; }

Then you''ll also need access to the instance of the class within your static function. If it''s a global, just define it as extern within the function. Then you can retrieve the member variable as:

myClass->GetEntity()


And no, I didn''t get your email. Perhaps hotmail is running slow?

Share this post


Link to post
Share on other sites
Thanks guys,

This just gives me the feeling I was getting with PR. Even if it is the best, in my own opinion, Graphics Engine available for indy developers, Chris should willing to get his next version more object oriented and more open minded.

The only way I can get it throught is by doing my own High level engine. I am, and I think I am not the only one, always trying to get some tricky code placed in some globals so I can have the things running properly using an Object Oriented Programing view.

Chris, if you could get us updated with what are your thoughts on that point, it would help a lot.

Thanks anyway to DrPain and Gorky for their helpful tips.

Amadrias

Share this post


Link to post
Share on other sites
I don''t see myself changing the entire API over to C++ and rewriting all of the documentation in the future, unless I run out of other ideas and have a couple of years of spare time.


Share this post


Link to post
Share on other sites
I didn''t mean to get you within that huge work Chris.

I just wanted to tell that you should maybe think on getting some of the new things you will be doing more OOP ?...

I completely understand the amount of work you made until getting where PR is and the no-one man thing that would be considering porting the overall PR engine to C++.

Amadrias

Share this post


Link to post
Share on other sites
C isn''t an object oriented programming language, so I can''t add OOP stuff unless I switch. So basically you''re asking me to learn/use another language and that isn''t going to happen quickly.

Share this post


Link to post
Share on other sites
Maybe users who have been working on PR by doing their tricks to have a C++ way can actually build a C++ wrapper for PR. I think there is already one (Minimal) at the FTP site.

This C++ version of PR can grow only from users I feel.

Share this post


Link to post
Share on other sites
I actually did this Wrapper but it was dedicated to build quick PowerRender applications. There is no stuff from High level engine.

I really appreciate the features available there and I''m now trying to build a class oriented lib of it.

The only problem I may consider is building another version of Landscape studio wto fx the calls.

Amadrias

Share this post


Link to post
Share on other sites