Archived

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

Azrael

Power render and C++

Recommended Posts

This is an important topic about PR, So I think i could start a thread about it, heres a few pointers about using PR and C++ 1.-Power render is pure C This is probably the most important point, using C++ OOP and PR must be considered as PORTING it will work but it wont be "automatic switching". 2.-Use globals, some variables in PR need to be accessed by almost all functions, the best way to do this is to use globals, this totally brakes OOP laws, but it works so what the heck? Some globals recomended to be used... viewport, cameras, terrain, etc. if a variable is giving you problems to access it, use it as a global. Eventually you could make them work into a class somehow, but my advice is to simply avoid the headache and make it work as a global. 3.-Some things wont work as C++ There are some PR functions, variables,methods that wont work from inside a class, like callback functions and such, learn what this are, and take them out of the class and to another c file then call it as an extern c. 3.-Use Extern C, this will solve a lot of problems... you can use an actual function from c in c++ with total c syntax by using this carefully. 4.-Remember to change .c to .cpp this solves problems, and yes in the heat of a project and a deadline you can forget that classes wont work in .c files 5.-changing the winutil.c is possible, of course it is, as a matter of fact winutil didnt existed back in PR 2.5 and it still worked, thats like saying you cant make landscapes without landscape studio. It just gets a bit more dificult... and you will probably have to touch win32 and dx coding, newbies should avoid this. extra tip for visual c++ users: are you tired of seing the pr dialog?, just take it off your project and compile it, pr will switch to defaults automatically, you will have to put settings by hand if you are not using defaults but is nice to know. I usually do this for quick testing, and add a dialog for release(a modified dialog that is) 6.-Check the oop example very, very carefully to see more pointers. 7.- add your pointers and opinions, to this thread

Share this post


Link to post
Share on other sites
...must be considered as PORTING...

Not really. ;-)

...this totally brakes OOP laws...

Truthfully, a mix of procedural and OOP programming can be a good thing. Bjarne said so himself.

...you can use an actual function from c in c++ with total c syntax by using this carefully.

Generally it''s not syntax, as C++ and C are nearly identical, it''s the linking methodology. C creates fairly clean linking names, and C++ creates fairly cluttered, gruesome names. By saying "extern ''C''", you''re saying to use the C linking convention and thereby be able to look for the info in the C LIB file by it''s C name, not the C++ name.

..yes in the heat of a project and a deadline you can forget that classes wont work in .c files...

Then you need a little positive reinforcement. ;-)

You can force the compiler to treat C files as C++ or the other way around, but that''s really a bad option, as it invites the really bad behaviour of actually doing so.

==

In the end, it''s really just common sense using PR with C++.

Share this post


Link to post
Share on other sites
Well you can wrap up pr within classes. If lets say one part of pr needs acces to the other just write up classes that will return the varibale need to the other system. Anyways I was writting something unfortunanlty wiork got me so < iwll try to finish this soon


Also the way I do it most of the time for c/c++ is...


I will write my ddraw studd using play oll c style procedures, and for example I will write a sprite class...

Another thing thats has ppl confused is things like malloc and new, sometimes within my class I will use mallonc instead of new but to allocate memory space for a certain data type.

Share this post


Link to post
Share on other sites
I''m using PR with C++. There are some issues... The C/C++ mix gets messy. There are some issues creating wrappers... But in the long run, it turns out pretty well. Yesterday I got the initialization to work. Looks good, darn it!

Share this post


Link to post
Share on other sites
The C/C++ mix gets messy.

Ouch. Blanket statement!

Not necessarily - ANYTHING can get messy. A mix can sometimes be an elegant solution to a problem.

Share this post


Link to post
Share on other sites
perhaps you guys you guys could help me with this..
im trying to turn land1 into c++.
So I simply went in and changed everything to .cpp
i got a bunch of errors as expected... I fixed the ->lptbl declarations and all, no problem there...
But some functions like function callbacks.. give an error like this:
unable to convert from function (___cdecl)(void *) to X
you should use C-style conversion or casting...
I tried to solve it using the offending function outside as a separated c file and calling it like an extern "C" (this had worked before), but it didnt worked neither...

on a side note...im trying to use STL code for the first time, but I always get an error at this line...
list something;
I always get a sintax error when compiling this. thanks I apreciate your help...

Share this post


Link to post
Share on other sites
I don''t know what to tell you... I usually got those errors during linking, not compiling... I used to have a bunch of unresolved externals. Moving them to .c, usually helped. But your case... I think it''s more of a question to Chris

Share this post


Link to post
Share on other sites
unable to convert from function (___cdecl)(void *) to X...

Could you tell me what "X" is? How about showing the declarations?

on a side note...im trying to use STL code for the first time, but I always get an error at this line...
list something;


STL is the Standard Template Libary...meaning they're templates. Thereby, you need to specify what the list is of, like:

list[CMyObject] MyObjectList;

or

queue[CMyObject] MyObjectQueue;

replace the square brackets with angle brackets, of course.

Edited by - revolver on June 16, 2000 2:17:40 PM

Share this post


Link to post
Share on other sites
First of .c or .cpp is just a file extension, you can name your files what ever you want and use any type of extension you want

Share this post


Link to post
Share on other sites
First of .c or .cpp is just a file extension, you can name your files what ever you want and use any type of extension you want or are you guys jusr refering the .c and .cpp as the languages!?

Share this post


Link to post
Share on other sites
Thanks whirlwind there were the proper minus signs on that line but this forum didnt showed them

I will send you the errors I get maybe we can fix this together

And voodoo if you change the extensions from .c to .cpp the compiler automatically reads it as C and C++ code, (almost all c++ compilers do, Im assuming you use visual c)if you dont believe me try it, you will notice the compiler gives you warning or errors you didnt before.. (if you are using classes or c++ code of course )

On a curious note: In unix and GNU you can even use c and C to or c and cc and the compiler takes it as c and C++ code respectively..

Share this post


Link to post
Share on other sites
Has anyone tried to convert land1 to cpp?
Im getting some weird error in the winutil.cpp file...
should I leave that file as it is?

btw the (void *) errors can be fixed by using a cast...
no problem there...

Share this post


Link to post
Share on other sites
I have an idea, maybe this wont fly but is worth to try...
why dont we start a community effort
and post CPP versions of the Pr examples?
maybe chris can upload them to the egerter web page...
this may seem silly but I think we may all get benefit from...

diferent winutil files...
c++ classes wrapping pr.. etc.
I think this is a good idea

Share this post


Link to post
Share on other sites
I leave town for 3 days (no computer access by the way), and I end up helping Azreal somehow... is that good?? If I go on vacation for a week, will that fix all the compile time errors he is having?

Share this post


Link to post
Share on other sites
Well... since I did this thread I should also continue it..
so heres another pointer...

Wrapper classes: This is probably the best (and in some cases the only way) to convert some examples or PR based engines into actual working c++.

How does this work? use higher level functions that execute PR code inside them but leave this original code as it is.. just call it... in our dear Land1 that means calling LoadTerrain from load.c or a function inside load.c made in c per example setfogrange...
Also you can subdivide the function in c and call it from a more complex wrapper function.
Per example:
Terrain::LoadTerrain
{
setfogrange; //This function is set on load.c
loadterrainsections //this function is also set on load.c
LoadCharacters //This can be a function from your own code
}
(this is what im using now to compile in c++ land1 )

Correct me if im wrong.. I will be a real fool, if im not able to accept and learn from my own mistakes.

Share this post


Link to post
Share on other sites
ChrisE was nice enough to group things in the lstudio.h file for lstudio. It shouldn''t be too hard (yeah, ok like anything is..) to port 75% of it to C++. So you are just making land1 functions accessible as a single call from C++, and globals are kept globals?

Share this post


Link to post
Share on other sites