Archived

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

RageMatrix

C or C++? Opinions.

Recommended Posts

Hey all, I''m having some trouble with the design aspects of my game and this lead me to think about recoding what I''ve done so far in C++ rather than C. Would this make the game more "modular" and therefore easier to manage? From a design/implementation perspective, this is the largest project I''ve done. What are peoples opinions on C vs C++? Which do you use? Can anyone give me an idea of the kind of game "framework" that people here use in whichever language floats your boat? If it helps any, I''m using DX7.0 and its a 2D game. Opinions from the font of collective wisdom please! RM. -=Kicking Butt and Writing Code=-

Share this post


Link to post
Share on other sites
Personally I use C++ and object oriented design. But without starting a language war, just choose the approach that works best for you. I think more logically when I think in terms of objects rather than procedures. I also like to use software design tool, and UML to help me design my software. And those tools are built around object oriented programming.


This is also somewhat of a deciding factor, what does everyone in your group prefer. In my amature game group, we are C++ people. So any people in our group who may not have a preference, will end up using C++ and an object oriented approach simple because the rest of us are.


Also look at prolog and ada, I think these are the future of game programming j/k.

Share this post


Link to post
Share on other sites
Why on earth wouldn''t you post this flame-bait in the languages forum? Or search the archives for the 80,000 messages that have this exact same title?

Share this post


Link to post
Share on other sites
quote:
Original post by Stoffel
Why on earth wouldn't you post this flame-bait in the languages forum? Or search the archives for the 80,000 messages that have this exact same title?


Steady on! This isn't flame bait, but a legitimate question. I want to know which language you use and depending on your chioce, the game framework you use (file, structs, globals, classes, etc). I am having design/implementation problems with my game and wanted some outside input on languages/design considerations.

I didn't post this in the Languages forum because I felt that the design aspects of my question and possible answers made it off-topic. Frankly, I am slightly annoyed that I even have to explain myself to you.

I have NO wish to start a flame-war, but only wanted some input on this subject.

Why is everyone so hostile on GameDev lately?

RM.

-=Kicking Butt and Writing Code=-

Edited by - RageMatrix on June 22, 2001 6:55:58 PM

Share this post


Link to post
Share on other sites
C++ is better. My reason (Iread this in a book) is you know how ++ is the incremets an integer by one. Will lets say are variavle is C. Now if we wanted to incremnt one number up it would be C++. That is why C++ is better. Its the next step up. I like so much better because of classes and OO design. In C there is a brother of the class keyword, struct. The only difference it for classes everything is private by default and sturts everything public. Not to be a flame war of which is better C or C++. I just think C++ is best in this situation because of its OO design and classes. Its also has a lot more advantages. Well long, but that was my 2 cents

Share this post


Link to post
Share on other sites
It really doesn''t matter which way you go. With C you get an executable. With C++ you get an executable. I wrote the last version of my engine in C. The current one is in C++. It works they same way in the end.

Share this post


Link to post
Share on other sites
why on earth would anyone want to program with OOD??? It''s over rated! First off, C++ class function calls are slower that a straight function call! Second they suck to use and work with....why in the hell would you want a private member to!?!?!? I never understood that...sure it prevents someone from editting the variable from outside the class...but who gives a shit...if he does it his loss, his program could crash. The only nice thing I can think of about classes is the intellisense feature that msvc6 has, so when you type in the class and put the nice little [ . ] next to it, it gives a list of everything inside it. I don''t know why every one thinks OOD is so great, anything that can be done in C++ can be dont better with C

-Andrew

Share this post


Link to post
Share on other sites
quote:
Original post by RageMatrix
Steady on! This isn't flame bait, but a legitimate question. I want to know which language you use and depending on your chioce, the game framework you use (file, structs, globals, classes, etc). I am having design/implementation problems with my game and wanted some outside input on languages/design considerations.


Really? Not flame bait? See Assembler015's post, and the 20 posts that will follow saying OOD has merit, and the 20 posts that follow that saying nuh-uh.

quote:

I didn't post this in the Languages forum because I felt that the design aspects of my question and possible answers made it off-topic. Frankly, I am slightly annoyed that I even have to explain myself to you.


Frankly, I'm annoyed you didn't search the site. I'm tired of these bologna "which is better" posts. They're sophomoric, and all the sophomoric people drag the responses out for millenia. I'm hostile because I used to have a good time on this board, and it used to be useful, but that usefulness is quickly waning.

Look here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=49938
and here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=49109

..for answers to your question that have been beaten to death, not to mention the first friggin' line of the FAQ .

quote:

I have NO wish to start a flame-war, but only wanted some input on this subject.
Why is everyone so hostile on GameDev lately?


Becuase |33+ HAX0RS who are "kicking butt and writing code" who don't even know the difference between C and C++ keep asking stupid questions without doing any research on their own, and then all the other |33+ HAX0RS have to put in their two cents--those opinions being worth slightly less than the electricity it took to run their browser for the time it took to punch out their meek response.

Edited by - Stoffel on June 22, 2001 8:22:58 PM

Share this post


Link to post
Share on other sites
assembler:

"why in the hell would you want a private member to!?!?!? I never understood that"

Exactly, you don''t understand it therefore you don''t like it and are uncomfortable with it.

"but who gives a shit...if he does it his loss"

Well, if one department in a co. makes a library and another department uses it. It would make sense to try and keep the using department from fucking themselves over.

"anything that can be done in C++ can be dont better with C"

I assume you mean ''done better''. I disagree, simulating c++ features in C leads to ugly inelegant and probably wasteful code.
Your better off just doing it the C way and not trying to simulate c++ features in C.


ECKILLER

Share this post


Link to post
Share on other sites
The main benefit I think you would get from using c++ in your project would be in enforcing modularization. There are a number of language constructs such as namespaces and classes which work towards this.

While it is possible to modularize in c, it involves discipline on the part of the programmer and ( probably ) awkward naming conventions. In c++, once you have learned the syntax and how classes etc... work, it all comes naturally.

The main thing is that on a project of reasonable size using modules becomes a must and thats where design comes in. What ever method you use it must be stuck to. C++ just makes it easier to do this.

Also, just because you use c++ does not mean you have to use all the OO features. If your worried about speed, then dont'' use inheritence and virtual method stuff. 80% of the time it''s not needed anyway.

point being: it''s not the tool''s you use, it''s how you use them.

thi sis my si gitzt hebezt

Share this post


Link to post
Share on other sites
quote:
Original post by Assembler015
First off, C++ class function calls are slower that a straight function call!

-Andrew


This is one of my personal ''favorite'' C++ myths. The only difference between a C and C++ (non-virtual) function call is that an additional pointer (this) is passed as a function argument. Other than that it is EXACTLY the same. And chances are good that you would be passing along a pointer to some structure anyway, so you aren''t even taking a hit from having an extra argument.

Now, a virtual function is a tiny tiny TINY bit slower because it has to do a vtable lookup, which is the same speed as an array access (ie. couple of clock cycles) and then dereference the pointer to the function it is supposed to call. You are only going to add a couple of cycles per function call. This is hardly a big problem.

Share this post


Link to post
Share on other sites
quote:
Becuase |33+ HAX0RS who are "kicking butt and writing code" who don't even know the difference between C and C++ keep asking stupid questions without doing any research on their own, and then all the other |33+ HAX0RS have to put in their two cents--those opinions being worth slightly less than the electricity it took to run their browser for the time it took to punch out their meek response.

Edited by - Stoffel on June 22, 2001 8:22:58 PM


For the last time, I wanted to know people opinions on C and C++ from a game design point of view, use of globals, etc. I am well aware of the textbook technical merits of each, but I wanted to know about other peoples experiences I hardly think that merits the kind of hostility you've been throwing my way. I wanted to know about the differently designed game frameworks that people use for each. Okay, so the post header my have been slightly misleading (it obviously attracted you like a bull to a red blanket). I don't know what your problem is, friend, but I hope you'll take it elsewhere. And taking the piss out of my sig doesn't exactly improve your argument. I'm a professional programmer and not some 13 year old script kiddie. I'll put whatever I damn well please on my sig.
I didn't realise that asking a fairly innocent question that is on topic would attract so much abuse. Especially when a 500 post thread which is basically just an argument now (see Christianity thread in the Lounge) gets no insults thrown at the original poster.

Relax, okay?

RM.



-=Kicking Butt and Writing Code=-

Edited by - RageMatrix on June 22, 2001 8:54:44 PM

Share this post


Link to post
Share on other sites
For the most part, it''s like this:

c++:
Map->Draw();

c:
Draw(Map);


If you have a choice between those, I''d recommend c, since c++ does have that slight overhead, and IMO, there''s no readability difference between the two.

But, in c++, Map->Draw(); and Map2->Draw(); could refer to two completely different functions. This can be used to your advantage easily. And then there''s operator overloading, which can enhance readability so much.

c++:
Transform = Translation * XAxis_rotation * ZAxis_rotation;

c:
Matrix_Multiply(temp, Translation, XAxis_rotation);
Matrix_Multiply(Transform, temp, ZAxis_rotation);


c++ has some very nice extensions. Just try to only use them where doing so would be to your advantage, since they do have a minor amount of overhead.

Share this post


Link to post
Share on other sites
C++ function calls from a class are slower... If you look at the instructions generated by the code, a class call has one more instruction than a normal function call -->
lea ecx, offset of class

which is two more cycles added on to the time.
...thus making it slower.Look at the dissasembly if you don't believe me!

The function also takes longer to perform the action, depending on what it does...a class function generally produces MORE instructions than a standard C function.

-Andrew

Edited by - Assembler015 on June 22, 2001 9:06:28 PM

Edited by - Assembler015 on June 22, 2001 9:09:15 PM

Edited by - Assembler015 on June 22, 2001 9:40:38 PM

Share this post


Link to post
Share on other sites
....Although from the above, I can see this degenerating quickly. Perhaps I either underestimated peoples need for a quick bitch-slap, or I haven't had enough sleep and am now hoplessly naive to the nature of these forums now. In all honesty, I *did* want people perspectives on C/C++ from a game framework design POV. I was hoping to provoke some intelligent dialog about language and design rather than the age old debate.


So, in part, I've got to side with the ever cynical Stoffel and regretfully request that this thread be closed. I swear it never used to be like this.


Anyone who has an intelligent response or design framework can contact me at: rage@matrix13.freeserve.co.uk


So long,

RM.

-=Kicking Butt and Writing Code=-



Edited by - RageMatrix on June 22, 2001 9:22:22 PM

Share this post


Link to post
Share on other sites
I don''t get what you want.

"Would this make the game more "modular" and therefore easier to manage? From a design/implementation perspective, this is the largest project I''ve done."

Yes c++ is easier to manage then C.

"What are peoples opinions on C vs C++? Which do you use?"

We''ve already given our opinions.

"Can anyone give me an idea of the kind of game "framework" that people here use in whichever language floats your boat? "

I don''t think anyone can explain their framework briefly. If you want, you should probably check out "3D Game Engine And Design", this will help you see how a pro engine is designed.

ECKILLER

Share this post


Link to post
Share on other sites
quote:
Original post by Acer722
C++ is better. My reason (Iread this in a book) is you know how ++ is the incremets an integer by one. Will lets say are variavle is C. Now if we wanted to incremnt one number up it would be C++. That is why C++ is better. Its the next step up.


Actually, C++ is a post descrement operation on the variable called C. What this really means is, use C, and then add 1 to it. So, the very name C++ implies: use C, and then add to it only after we have already used it. I personally can only interpret this one way: C is useful BEFORE any modifications are made to it; and any modifications should only be made AFTER we have already derived all use from it.

So there you have it. C++ is superfulous. If it was really intended to be useful, it would have been named ++C. A pre decrement name would have implied a usage of the language AFTER its modification, thus implying modifications to hte core C language would have actually been useful.



Share this post


Link to post
Share on other sites
quote:
Original post by bishop_pass

Actually, C++ is a post descrement operation on the variable called C. What this really means is, use C, and then add 1 to it. So, the very name C++ implies: use C, and then add to it only after we have already used it. I personally can only interpret this one way: C is useful BEFORE any modifications are made to it; and any modifications should only be made AFTER we have already derived all use from it.

So there you have it. C++ is superfulous. If it was really intended to be useful, it would have been named ++C. A pre decrement name would have implied a usage of the language AFTER its modification, thus implying modifications to hte core C language would have actually been useful.






Aha, but that only works if it were called "Language( C++ );" or something similiar. In the statement "C++" nothing uses C, and as such the only operation on C is an improvement. As for reasoning, I'm not sure how one can prove that nobody used C historically, however I'm sure that if you got into specifics you could come up with some sort of reasoning, like "The people that used C were nobodies" or some other statement to an equal effect.

As for closing the thread, if it remains reasonably civil I'll allow it to remain open, as generally at least some interesting facts come from debates such as this. Plus, It's hard to justify closing a thread based off the topic when I have yet to post a FAQ (I'm getting to it). There's no reason to let emotions become part of this.

Edit: Messed up the quotes.

Edited by - The Senshi on June 22, 2001 12:15:56 AM

Share this post


Link to post
Share on other sites
You all sound like you are arguing Pro-Choice, or Pro-Life. Neither side can convince the other that they are right. And I dont care. If you want to use C, use C. If you want to use C++, use C++. If you want to use Pascal, I dont care. Everyone just keep their noses in their projects, and let other people do as they please with theirs. Otherwise, you may end up being shot (metaphorically speaking).

This has been a general flame, to anyone who insists on acting like a child.

Z.

Edited by - Zaei on June 23, 2001 2:13:08 AM

Share this post


Link to post
Share on other sites
Whats wrong with being a child? With out us "children" where would new ideas come from, most adults lose their creativity side when they grow older....if ALL adults lost it....new invention would never have been thought up because we NEED creativity. So if you want to insult me for being a child okay, thank you. And besides, RageMatrix wanted to know peoples OPINIONS about C & C++---it says in his post. He also wanted to know pros and cons....I gave those...and they were true.

-Andrew

Share this post


Link to post
Share on other sites
Stoffel >>

There is nothing wrong with the question by the orignial poster.

It´s not his fault that people like yourself visit GameDev.



Share this post


Link to post
Share on other sites
My take on it:

C++ may be a little bit slower than C in the execution of a function call. But where you are concerned about the loss of 1 or 2 clock ticks you should not be calling a function anyways you should be inlining that function in your loop. Todays processors are not the same as the 100Mhz processors of a few years ago where every clock tick made a difference. The speed difference although it is there is very trivial and should not play a part in determining your choice of language because if it is coded correctly with speed in mind the end result will be the same. You shouldn''t have a function call in the middle of your loop in C anymore than you should in C++ if you are concerned about clock ticks. If it is not in the middle of a loop then the clock ticks you waste will never be noticed unless you have some hardcore multithreading going on.

What C++ lacks in speed it certainly more than makes up for in ease of design and code reusability in most situations. There are still times when straight C is preferrable and I always recommend learning C as a precursor to learning C++, but when it comes to actually creating the complex solutions C++ is my choice 90% of the time.

What would be best for this particular situation depends on the makeup of your game. If you have alot of different objects in your game and some of those objects share properties with other objects using an object-oriented language would certainly make it more manageable.

If you want to know a rough idea of the framework that I am using on my current project this is it in a nutshell:

Game3D is my primary class. This class contains everything else that is related to the game, including objects for sound and graphics. This is the only class accessed in my WinMain or WndProc functions.

Then I have classes for Graphics and Sound to encapsulate the platform-dependent problems. This way when I decide to port to other platforms I should only need to port those 2 classes and my main Windows specific source file and that''s it.

My Level class is responsible for loading, displaying and checking for collisions in regards to my level data. All objects in a level class are derived from a base Object class and kept in a linear array. Anytime the player moves his position is updated and a query is made to the current Level object for collision detection and the player object makes the decision on how to respond.

I am currently in the process of implementing an Octree class which will be sub-referenced from the Level object for collision detection and for generating the array of indices to display out of my Vertex Array after view-frutrum culling is done on the Octree.

It seems that implementing an Octree in C++ is fairly intuitive and I''m not sure I would be having as much success as I am so far if I were working in straight C on this one. I imagine working with a k-d tree would be even more difficult in C without really changing complexity in C++ as well.

I''m not saying that you CAN''T implement these data structures in straight C because I''m pretty sure that was how they were originally implemented but I see it as being more intuitive in an object-oriented approach. Read: Alot cheaper and less buggy to implement.

---

"...why in the hell would you want a private member to!?!?!? I never understood that...sure it prevents someone from editting the variable from outside the class...but who gives a shit...if he does it his loss, his program could crash..."

If that someone happens to be your co-worker and ''his program'' is also ''your program'' then I think you will give a shit. The reasoning behind it is to eliminate bugs and bolster development efficiency. The idea is to make your class a little black box. You have methods that you can perform on the box and things that you can find out about the box but what is going on INSIDE of the box is a mystery and it is probably better that way. If you start trying to operate on a class or data structure that somebody else created and you have some misconceptions about what certain variables mean you will introduce bugs in your code which will be incredibly expensive to find later because the logic is sound but your PERCEPTION is not. If you encapsulate the details and require that access to the data be handled through member functions then your class can be responsible for maintaining it''s own integrity and if something is going wrong it is MUCH easier to find the problem if you know what is responsible for what-else

Seeya
Krippy

Share this post


Link to post
Share on other sites
Sorry, but I side with Stoffel. This question comes up all the time, doesn''t really shed much light, usually gets a few morons who suggest all software should be made in assembly or smalltalk, and nobody comes out any wiser. And just mentioning that it''s a 2d DirectX game doesn''t really make it a ''game programming'' question, it is still a ''general programming'' or ''language specific'' question.

In reply to those who say people like Stoffel shouldn''t get a bit irritated at these posts, I would say in return that RageMatrix, since having been a member here for 6 months, should have seen plenty of previous threads with almost the exact same title and noticed how they degenerate. For someone like me, who actually posts here far more to help others than to ask for help myself, it''s discouraging to see that, no matter how many times something is said, it still doesn''t ''go in'', and that people ask the same futile questions again.

Asking what language to program in, especially 2 very similar languages, is like debating the merits of the Republican and Democrat parties, or Christianity and Islam, or ...(insert contentious choice here). The choices are largely made on personal preferences and the ''reasons'' are often merely ''justifications''.

(Suggestion to moderator ) Hopefully, the ''answer'' to this question will be put in the Forum FAQ, so that future threads like this can have a ''check the Forum FAQ'' post added by the moderator and then closed before they degenerate.

Share this post


Link to post
Share on other sites
I tried out djgpp , Visual c++ , Visual Basic + Delphi. The one i liked best was Delphi. Sometimes logic + common sense go out of the window. Forget what anyone else says just choose the software that you enjoy using the most and the one that enables you to make your idea a reality in the fastest possible time.
We all know that 99% of commercial games are made using c++ but so what? 99% of commercial games are boring , unoriginal rubbish. As Fleetwood Mac said "Go Your Own Way".

Share this post


Link to post
Share on other sites
quote:
Original post by Krippy2k
If you want to know a rough idea of the framework that I am using on my current project this is it in a nutshell:

Game3D is my primary class. This class contains everything else that is related to the game, including objects for sound and graphics. This is the only class accessed in my WinMain or WndProc functions.

Then I have classes for Graphics and Sound to encapsulate the platform-dependent problems. This way when I decide to port to other platforms I should only need to port those 2 classes and my main Windows specific source file and that''s it.

My Level class is responsible for loading, displaying and checking for collisions in regards to my level data. All objects in a level class are derived from a base Object class and kept in a linear array. Anytime the player moves his position is updated and a query is made to the current Level object for collision detection and the player object makes the decision on how to respond.

I am currently in the process of implementing an Octree class which will be sub-referenced from the Level object for collision detection and for generating the array of indices to display out of my Vertex Array after view-frutrum culling is done on the Octree.

It seems that implementing an Octree in C++ is fairly intuitive and I''m not sure I would be having as much success as I am so far if I were working in straight C on this one. I imagine working with a k-d tree would be even more difficult in C without really changing complexity in C++ as well.

I''m not saying that you CAN''T implement these data structures in straight C because I''m pretty sure that was how they were originally implemented but I see it as being more intuitive in an object-oriented approach. Read: Alot cheaper and less buggy to implement.
Seeya
Krippy


Thanks Krippy, this is the sort of information I was after. I''m NOT actually after the relative technical merits of each language as I have a working knowledge of both, but just wanted to know how your choice influenced your design. 2Dgame.nl also has a good design document like this, although he''s using MFC, which I don''t use. Still, all good stuff.

RM.




-=Kicking Butt and Writing Code=-

Share this post


Link to post
Share on other sites