Public Group

This topic is 2238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I recently decided to try my hand at my first game project. Currently, I have something running, but it's practically just a stub:

https://github.com/pervycreeper/game1/

I have so many questions, though. While I have a background in math, I never really learned to code properly, so there are a lot of details I'm lacking in my knowledge. I'm essentially paralyzed by the profusion of information out there. Maybe some people here would care to comment.

Compiling and development environment:

Currently, I have set this project up in MS Visual c++ express 2010, and it compiles, etc. All the good cross-platform open source stuff seems to get compiled from the command line, though. Is it common to write everything in an IDE like I have done, or do they use a text editor like VIM entirely? How do you automatically produce makefiles, etc? Is there a good quickstart tutorial for the vim+make method out there? What are the advantages to using the VC++ editor (or more generally, an IDE)?

Also: so, apparently, global variables are bad. I don't really know what the alternative would be to using them in a game would be (where would 'worldmap' live in my project, for instance?). Should I be passing a pointer to variables like this to every function that uses it? Is there a performance overhead for having local variables (say in a function that gets called millions of times).

initializing/ typecasting:

if you prefix every variable assignment with its type (like, in a loop: 'int a = b;'), would this obviate the need to declare "int a;" earlier and then have "a=b;" when you actually need it? Is there a style/ performance penalty?

Lastly, where can I get more help along these lines?

Share on other sites
Going to snipe a couple of these questions, some I don't necessarily feel qualified to answer:

Is it common to write everything in an IDE like I have done, or do they use a text editor like VIM entirely?[/quote]

Yes, the using of an IDE is usually preferable to not. (At least for me, of course one could argue not using one is the quicker path to manhood...)

What are the advantages to using the VC++ editor (or more generally, an IDE)?[/quote]

Most times: compiler integration, type inspection, debugger integration, refactoring support, intellisense, etc. IDEs tend to bring a lot more to the table for any given language than a flat text editor.

Also: so, apparently, global variables are bad. I don't really know what the alternative would be to using them in a game would be (where would 'worldmap' live in my project, for instance?). Should I be passing a pointer to variables like this to every function that uses it?[/quote]

In C there's nothing wrong with global variables. Consider static memory allocation to keep your names from colliding across compilation units. [Edit: original answer (falsely?) assumed C++]

Is there a performance overhead for having local variables (say in a function that gets called millions of times).[/quote]

Local to the function there is a memory overhead (each value must have space on the Stack).

if you prefix every variable assignment with its type (like, in a loop: 'int a = b;'), would this obviate the need to declare "int a;" earlier and then have "a=b;" when you actually need it? Is there a style/ performance penalty?[/quote]

 //1 int a = 0, b; for(; a < 10; ++a) { a = b; } //2 int b; for(int a = 0; a < 10; ++a) { a = b; } //3 for(int a = 0; a < 10; ++a) { int b = a; } 

#1 and #2 are equivalent. #3 is not. [Scope]

Lastly, where can I get more help along these lines?[/quote]

If you're looking for more interactive help, you can try http://freenode.net/. There are channels devoted to pretty much any language you could hope for. Otherwise, here's always a good resource... Edited by greenvertex

Share on other sites
Aha, fantastic, that actually clears up a lot of my concerns.
Yes, the using of an IDE is usually preferable to not. (At least for me, of course one could argue not using one is the quicker path to manhood...)
Haha, yes, I do have some kind of underlying desire to become a 'Real Programmer', but it seems like such a far off goal.
 //1 int a = 0, b; for(; a < 10; ++a) {      a = b; } //2 int b; for(int a = 0; a < 10; ++a) {      a = b; } //3 for(int a = 0; a < 10; ++a) {      int b = a; } 

Yes, that's kindof what I mean. In example (3), is that considered correct? The first time the inner line is executed, it's a declaration, then subsequently it's a typecast. Is that a reason to prefer://2' int b; for(int a = 0; a < 10; ++a) {      b = a; }over://3 for(int a = 0; a < 10; ++a) {      int b = a; } both in terms of style and efficiency?

Share on other sites
Yes, that's kindof what I mean. In example (3), is that considered correct? The first time the inner line is executed, it's a declaration, then subsequently it's a typecast. Is that a reason to prefer:
//2' int b; for(int a = 0; a < 10; ++a) { b = a; }
over:
//3 for(int a = 0; a < 10; ++a) { int b = a; }
both in terms of style and efficiency?[/quote]

This really depends. In this example, #3 wins out if you only ever use b within the loop. Integer copy by value is about as fast as you could want and no extra memory is allocated per iteration. The name 'b' is kept to an area that will use it and doesn't pollute another scope that never intends to use it. Because of that, you're less prone to using that variable improperly outside the loop.

#1 or #2 win out when you're dealing with more complex types in C++. While memory is only allocated once per function call, these objects would be constructed and destructed each iteration if declared inside a loop. Sometimes you want this, most times you want to steer clear of it. Edited by greenvertex

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 14
• 10
• 23
• 9
• 55
• Forum Statistics

• Total Topics
632638
• Total Posts
3007598
• Who's Online (See full list)

There are no registered users currently online

×