Archived

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

Mescalito

How much do you use C++ in your games ???

Recommended Posts

Mescalito    122
This can be a strange question but I was wondering if every C++ programmer build their games completly using C++ methods. Personnaly I can be called a C++ programmer (2 years of C++ studying...) But when I write games I don''t use all possibilities it gives. My programs are a mix of C and C++. (I used classes to make a OOP game but for implementation I generally C instead of C++ STL with things like , , ...) So what about you ? Do you make Pure C games, Pure C++ games or it''s a mix of both ?

Share this post


Link to post
Share on other sites
Mescalito    122
Oops there''s was a problem when writing the post (it didn''t write text between characters greater than and lower than...)

So here''s the complete sentence
"instead of C++ STL Things like string, vector, map ..."

Share this post


Link to post
Share on other sites
RizMan    146
I am quite new to game programming and am working on my first real project after being through lots of OpenGL Tutorials. So I don''t know if what I''m using is what is used in general.
So what I do is I use C++ for object creation like every tile in my world is an instance of a class. However, stuff like initialization, reading in the map, rendering the scene etc...is done using C. So I use a mix of both. Depending on what I wanna do.

Share this post


Link to post
Share on other sites
Mathematix    259
I use both where I see fit. There are no set rules that say you should use only C or C++. Of course, before C++ was so mainstream in game development C was the sole language for game development. Do a google search for the Quake 2 source to see what I mean.

I''m sure that there are purest game programmers out there who will insist on using either on or the other, but do not accept this as chapter and verse.

Share this post


Link to post
Share on other sites
Mescalito    122
You know if I post this it was only by curiosity.
I''ll keep writing my games using both C and C++
(I think it''s a good way to make the game running well !)

Share this post


Link to post
Share on other sites
Leffe    301
I use C++ constructors and C libraries(i.e., never include anything without a .h) :)

[Edited by - Leffe on August 31, 2005 12:51:02 PM]

Share this post


Link to post
Share on other sites
xEricx    572
I mainly program in C++, because I like it and that's the way everything is developped here. Everything is written with a OOP design. The engine we license is also plain C++. The only functions we have are util fonctions that didn't really fit in a class.

I also use a lot STL, because it's well written and easy to use. Most distributions of STL are way more advanced that what you could come up with your own implementation of a vector or a linked list...

I respect programmers that still code in C, but in my opinion C++ is more fit for large projects where you have to work in a team of programmers.

For hobby project, I'd pick the language I'm the more used to... which is, in this case, also C++ heheh

[edited by - xEricx on March 6, 2003 9:26:38 AM]

Share this post


Link to post
Share on other sites
Oluseyi    2115
C++ is a superset of C - or at least was - so when you write in "C", you''re also writing in C++. Most of the time anyway. These days there are C constructs that are not valid C++, and vice-versa, but it''s unlikely that you''re using such forms, which means you''re programming entirely in C++.

Gotcha, didn''t I?

Share this post


Link to post
Share on other sites
deadalive    122
I asked this question here a few weeks ago, and I got basically the same answer,
"How much c++?!? use as much as you want!"

"in my opinion C++ is more fit for large projects where you have to work in a team of programmers."
I think this guy is right, I think you could use more OOP/C++ stuff if you are:

a)Writing a large, complex library that needs to be very flexible, maybe open source, where alot of people will be looking at and possibly modifying or adding new version to a CVS..

b)working on a large team where seperating code into modules is more important because you have different people doing the sound engine, graphics, physics, etc..

If you don''t fit into those categories I see no probs with using "just a little" C++ like STL and some classes.. thats what I''ve been doing lately, and everything seems to be working out fine.

Share this post


Link to post
Share on other sites
YoshiN    122
I almost exclusively use C++ for game development since it makes a lot of the actual logic programming easier. I use a lot of polymorphism so that I can have lists containing everything and the like. However since my current project uses SDL, I can''t say it''s pure C++ (SDL uses C).

Share this post


Link to post
Share on other sites
Ready4Dis    180
I don''t think the STL is more advanced than what I can write. That aside, I use C and C++ depending on the project. My raytracer had to be AS FAST AS POSSIBLE, and just switching all the classes (the important ones) over to structs netted me near a 400% gain in speed, and that was using BASIC classes (no polymorphism, no virtual functions, or inheritance, just data members, and methods). I use classes for things like loading of the world, loading images, etc, but I mostly reserve the inner most engine sections in C, although this isn''t the case for my terrain engine or GUI, at the moment, they are both mostly C++ because it was easier (well, partially C++). I still do all my own linked lists, because I needed it done a specific way, and I like to create things myself. I am not sure whether the STL implementation does what I needed it to do, and I wasn''t spending hours to figure out if it''d work or not, when it only took me a few minutes to write my own linked list. I did however have extensive use of class inheritance and virtual functions in my GUI due to the nature of objects being similar, although it would have been almost as easy to write it with structs and function pointers, and probably would have run faster (hmmm... maybe i''ll do a speed test on that later). Oh well, I just use whatever I feel like using at the moment. There is NOTHING you can accomplish in C++ that I can''t do in C, and NOTHING I can accomplish in C that you can''t accomplish in C++, it''s just a matter of who''s takes longer to develope.

Share this post


Link to post
Share on other sites
Bashar    122
I code more in C++, but I have a C mentality. ie. I want speed, and also simplicity. I hate templates, they''re powerful but ugly to understand. Also, I don''t make use of RTTI, and I must admit that I''ve never over dosed on multiple-inheritance. Basically, I use C++ as if it were "C with Classes" - as its original name was

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I call the language C/C++ and I use it that way

prototyping systems in C-like or mixed code and then, MAYBE, refactor them into proper classes and stuff

Share this post


Link to post
Share on other sites
Shannon Barber    1681
quote:
Original post by Ready4Dis
...just switching all the classes (the important ones) over to structs netted me near a 400% gain in speed, and that was using BASIC classes (no polymorphism, no virtual functions, or inheritance, just data members, and methods).


This is most intriguing. Could you please tell us the compiler you are using, so that rest of us can avoid it like the bubonic plague?
Class and struct are nearly *identical*. The *only* difference is that class defaults to private and struct defaults to public.

PS You can put virtual function and even constructors and destructors inside of struct''s. You can even use inheritance.

...
Using C++ does not mean writing OO code. The whole C++ mentality is that you can write code in many different ways. You are free to use it as a better C, and make modular or procedural designs using only member functions (no virtual''s) and operator overloading for syntactic convenience.

If you ever find yourself using more than one function pointer, you are better off using the built-in virtual members of C++ than bothering to implement all the details yourself in C-style code.

- Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]

[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]
[Free C Libraries | zlib ]

Share this post


Link to post
Share on other sites
Ziphnor    122
I use the STL all the time, im a big fan of hashmaps for example(which isnt really part of the STL but is included in most STL implementations).I also use templates alot.

The only time i use the C headers are for things like strtok and other small utility functions, but im sure even they can be avoided.

But then, i learned Java first, then C++, so i find C++ more natural than C. If you come from a different angle, its understandable that youd prefer C style.
Doesnt really matter, as long as we can make games with it...

Share this post


Link to post
Share on other sites
Dark Rain    157
I go for C++ 95% of the time, my only vice is atof or toupper etc, I dont feel like creating a stringstream when I have a small function. Course I use it when I have to do number to text.

As for STL, I must say I plaster it everywhere in my programs. My teachers get a bit annoyed sometimes when they look at my code ^_^. It's mostly because it makes the assignements too easy most of the time and well when you dont really know STL, it can get quite weird for the uniniated.

[edited by - Dark Rain on March 7, 2003 6:12:02 AM]

Share this post


Link to post
Share on other sites
marijnh    182
I used to be quite an STL/iostream junkie but i recently started coding my own library with a small (and simplified) subset of stl and iostream functionality, because i wasnt sure all the stl methods were optimized enough and i resented the bloated executables that the iostream classes caused (about 350k extra for opening a file? eeew). So far i have a vector (container) template, input/output streams and a string class, all working exactly like i want them to, and without any redundant code.

Marijn

Share this post


Link to post
Share on other sites
Oluseyi    2115
quote:
Original post by marijnh
I used to be quite an STL/iostream junkie but i recently started coding my own library with a small (and simplified) subset of stl and iostream functionality, because i wasnt sure all the stl methods were optimized enough and i resented the bloated executables that the iostream classes caused (about 350k extra for opening a file? eeew). So far i have a vector (container) template, input/output streams and a string class, all working exactly like i want them to, and without any redundant code.

I don''t know that STL or iostreams add to code bloat in release mode. Did you do a release build?

On the one hand, I feel that you should be free to make your own mistakes and by doing so gain valuable experience. On the other hand, I think you''re bypassing a huge opportunity and learning to create code that may not play as nicely or be as useful to the rest of the development community. Rather than reimplementing STL containers because you feel they underperform, customize them. Write custom allocators to change how they allocate and deallocate memory and supplied custom predicates to optimize comparisons and various other operations. The tremendous benefit to this technique is that your code works with everybody else''s (do you really think that other people will use your code that depends on CYourCustomList over code that uses std::list?) Consider in particular the multitude of adapters, algorithms and functions that they (and you) lose access to once they switch to your "optimized" classes.

Writing efficient C++ is by no means intuitive, in part because the C++ object model is much more complicated than the C object model. Relatively inexperienced C++ programmers also often suffer from a focus on micro-optimizations. Remember Dijkstra''s Law: "Premature optimization is the root of all evil." There''s a sig I love around here: "Make it work. Make it right. Make it fast. Make it small." (I think I got it right.)

The antidote to the programming ills that plague us C++ programmers is to learn from those who''ve gone before. I''ve been reading some back issues of The C++ Report, and am amazed at how old some of the techniques I''ve just recently been introduced to are! Interestingly, in virtually every case in the four issues I''ve read so far (this is a dense publication, feature articles from such experts as Stan Lipmann, Scott Meyers, Doug Smith, John Vlissides, etc) the first approach considered to improve code quality and performance is improved design.

In summary, and this is intended without insult to anyone, I thin Ready4Dis and marijnh are completely wrong when they think that simply switching to C or eliminating STL use can improve code performance. The assumption that leaps at me is that they were making poor use of the C++ language in the first place. Note that there are legitimate situations where those approaches are known to give a performance boost, but they''re somewhat more esoteric (more than one PS2 developer has mentioned having to write a customized implementation of several STL containers and/or algorithms, while embedded platforms simply don''t have as robust C++ development environments as they do for C).

Okay, I''ll shut up now.

Share this post


Link to post
Share on other sites
marijnh    182
Gotta love it when you try to post, get a http error, and can start over.

In short, i tried to say that i am by no means rejecting the stl and in fact basing my libary on the way it works. I know that makes my code a little harder to read for others but since i am the only one reading it at current and since it can be changed back to using the stl real easily, i do not care very much.

I know for a fact that on my computer the iostream/fstream lib adds a huge chunk to my exe size. I am using mingw with the libaries that came with a recent version, so i guess that i am using a release version. When i create the same program using and i get a size difference of about 300k, that definitely is code bloat. I have seen others complain about this on the web so i don''t think i am completely clueless here.

Marijn

Share this post


Link to post
Share on other sites
marijnh    182
Well sometimes it works, sometimes i get a blank message. I have taken to copying everything in my message before hitting submit, just to be sure

Marijn

Share this post


Link to post
Share on other sites
Oluseyi    2115
quote:
Original post by marijnh
I know for a fact that on my computer the iostream/fstream lib adds a huge chunk to my exe size. I am using mingw with the libaries that came with a recent version, so i guess that i am using a release version. When i create the same program using <stdio> and <fstream> i get a size difference of about 300k, that definitely is code bloat. I have seen others complain about this on the web so i don''t think i am completely clueless here.

Oh no, code bloat is definitely a side effect of using the STL... ineffectively (which is how most of us use it, and why we need to always keep learning). Techniques for eliminating code bloat are nearly ten years old! I''ll go home and find an article on the subject and post tomorrow.

Cheers!

Share this post


Link to post
Share on other sites
xEricx    572
Reading "Effective STL" from Scott Meyers could be a good start

I guess I should read it also hehe... heard great words about it

Share this post


Link to post
Share on other sites
Oluseyi    2115
A review of the resources I promised to look at pointed to lack of sufficient knowledge of the performance and memory management characteristics of various STL containers, algorithms and methods as the primary culrpit. Most of us use STL as a "black box" toolkit, not bothering to find out how each component works (for example, the pre-1995 HP reference implementation of list did class allocation instead of per-object allocation, which meant that a node, once allocated for any instance of the class, was not released until all instances of the class were destroyed!)

Know your toolkit. As suspected, the author pointed to the use of allocators as one method for customizing STL behavior to obtain the desired characteristics. The STL is highly generic and flexible by design, and I think the benefits of using a common framework - even for custom behavior - in terms of reuse and comprehensibility are well worth the effort. I''ve been threatening for a long time to write an article on STL allocators and the like; I think this is a good time to actually get around to it.

Share this post


Link to post
Share on other sites