Sign in to follow this  

My Nascent Game Project; Your Comments Requested

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

If you intended to correct an error in the post then please contact us.

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 this post


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

[quote]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...)

[quote]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.

[quote]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 [url="http://en.wikipedia.org/wiki/Static_memory_allocation"]static memory allocation[/url] to keep your names from colliding across compilation units. [Edit: original answer (falsely?) assumed C++]

[quote]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 [url="http://en.wikipedia.org/wiki/Call_stack"]Stack[/url]).

[quote]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]

[CODE]
//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;
}
[/CODE]

#1 and #2 are equivalent. #3 is not. [[url="http://en.wikipedia.org/wiki/Scope_(computer_science)"]Scope[/url]]

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

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

Share this post


Link to post
Share on other sites
Aha, fantastic, that actually clears up a lot of my concerns.
[quote name='greenvertex' timestamp='1344403151' post='4967259']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...)[/quote]Haha, yes, I do have some kind of underlying desire to become a 'Real Programmer', but it seems like such a far off goal.[quote name='greenvertex' timestamp='1344403151' post='4967259'][CODE]
//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;
}
[/CODE]

[/quote]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:[CODE]//2'
int b;
for(int a = 0; a < 10; ++a) {
     b = a;
}[/CODE]over:[CODE]//3
for(int a = 0; a < 10; ++a) {
     int b = a;
}
[/CODE]both in terms of style and efficiency?

Share this post


Link to post
Share on other sites
[quote]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:
[CODE]//2'
int b;
for(int a = 0; a < 10; ++a) {
b = a;
}[/CODE]
over:
[CODE]//3
for(int a = 0; a < 10; ++a) {
int b = a;
}[/CODE]
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this