Jump to content


C++ Programing


  • This topic is locked This topic is locked
17 replies to this topic

Rinzai #1 Posted 09 April 2012 - 12:16 PM

    Lance-corporal

  • Player
  • 1953 battles
  • 57
  • Member since:
    08-10-2011
Hi everyone, I hope I get some help here =)

So, I wanted to know how to make games, I google and ask people stuff and they say to me that I have to learn C++ and/or other computer languages.

I google stuff like C++ tutorials, how to program a MMORPG, etc. But there are stuff that I don't understand, so any help will be... helpful (lol)


I found this:

"// my first program in C++
This is a comment line. All lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is.
"

This is plain and simple (to me at least). You type "//" and everything that is after doesn't have any effect on the program, it's just a note for whoever is reading the text.

But this I don't understand:

"#include <iostream>  
Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive #include <iostream> tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program."

This one not that clear (to me). I want to understand what directives for the preprocessor mean... I google it and then:


''Preprocessor directives are lines included in the code of our programs that are not program statements but directives for the preprocessor. These lines are always preceded by a hash sign (#). The preprocessor is executed before the actual compilation of code begins, therefore the preprocessor digests all these directives before any code is generated by the statements.''

What is this for? Why would I want the preprocessor to be executed before the actual compilation of code? What does this do? What effects it brings?

(I just want to learn this, but I don't have a teacher to clear some stuff out) I also want to know the relation of what I am learning at the moment with game programation...


Example, imagine a field and a character in it, I want to learn how to bind W to make him go foward, I want to move him to a certain area, and, when he reaches that area an effect is produced (example: a meteor falls from the sky when the character steps in certain area, someone farts etc) Is programing about action and reaction? (cause and effect? Effects are causes of other effects and so on)
I'm also curious on, example, I sculpt some models in Mudbox. Some goblins or whatever, how do I make them animated?

I write the game.
I draw the characters.

How do to link both?

Also, I want to know the conection of this with anything else:

using namespace std;  
All the elements of the standard C++ library are declared within what is called a namespace, the
namespace with the name std. So in order to access its functionality we declare with this expression that
we will be using these entities. This line is very frequent in C++ programs that use the standard library,
and in fact it will be included in most of the source codes included in these tutorials.


GorDoink #2 Posted 09 April 2012 - 12:36 PM

    Warrant Officer

  • Beta Tester
  • 20235 battles
  • 762
  • Member since:
    09-17-2010
Although this is a game forum and you want to write a game, this isn't really the place to try learning C++.  You should probably get yourself a book, C++ For Dummies (I'm not being cheeky here, honest) or C++ In 24 Hours / Lessons (can't remember which it is).

#include <file> literally places the contents of "file" at that point point in your C++ file.  This is done by the preprocessor (automatically) when you compile.  One reason why this is a good idea is that when you get beyond "Hello world" (famously the first program most C / C++ programmers write) you can create loads of manageable size files instead of a single, enormous file.  There are many other reasons, particularly re-usability (don't want to keep re-inventing the wheel).

Sorry I don't have time to answer all your questions, you should definitely buy / borrow a beginner's book.  Good luck.

Gellan #3 Posted 09 April 2012 - 12:41 PM

    Private

  • Beta Tester
  • 2561 battles
  • 3
  • Member since:
    09-01-2010
As GorDoink said you would be best off getting a tutorial book on coding in C++, that the sort of thing I did to get me started in writing games in C#.

As for you looking up lessons on MMORPGs I would strongly advise that you start small, start with the likes of a side-scroller game so you can learn the basic code behind implementing sprites, controls et cetera.

Good luck in learning to code!

Rinzai #4 Posted 09 April 2012 - 01:01 PM

    Lance-corporal

  • Player
  • 1953 battles
  • 57
  • Member since:
    08-10-2011
C++ Tutorial

Is this reliable? I'll buy a c++ programming book anyway.


I wont be trying to learn everything from this OT section of World of Tanks, I'll just be asking some things that I don't understand when reading...

Like what was the function of #include iostream, altho they explain I still don't understand what does it do.


As GorDoink said:
"#include <file> literally places the contents of "file" at that point point in your C++ file. This is done by the preprocessor (automatically) when you compile. One reason why this is a good idea is that when you get beyond "Hello world" (famously the first program most C / C++ programmers write) you can create loads of manageable size files instead of a single, enormous file. There are many other reasons, particularly re-usability (don't want to keep re-inventing the wheel)."

Won't be lieing... Still don't understand, I'll keep reading, maybe it'll make more sense later.

The feeling that I get is that what people are trying to teach is not really the beginning of one that has no experience should learn... explain to me: Why would I want to place the contents of "file" at a certain point in my C++ file?

Rinzai #5 Posted 09 April 2012 - 01:14 PM

    Lance-corporal

  • Player
  • 1953 battles
  • 57
  • Member since:
    08-10-2011
Edited

Gellan #6 Posted 09 April 2012 - 01:28 PM

    Private

  • Beta Tester
  • 2561 battles
  • 3
  • Member since:
    09-01-2010

View PostRinzai, on 09 April 2012 - 01:14 PM, said:

"They are not regular code lines with expressions but indications for the compiler's preprocessor."

What are then - regular code lines with expressions?

As far as I can work out from that PDF you linked and a browse of Google, anything with '#include' in front is telling the preprocessor to include that file with-in the '< >', the reason they are not regular code is because, the preprocessor is executed before the code is complied, the preprocessor then looks for all code with a '#'

There for by writing '#include <iostream>' you are telling the preprocessor to include the file 'iostream' (which contains the declarations for the input-output library).

Hope this helps in some-way.

P.S. Please correct me if I am wrong

Rinzai #7 Posted 09 April 2012 - 01:38 PM

    Lance-corporal

  • Player
  • 1953 battles
  • 57
  • Member since:
    08-10-2011

View PostGellan, on 09 April 2012 - 01:28 PM, said:

As far as I can work out from that PDF you linked and a browse of Google, anything with '#include' in front is telling the preprocessor to include that file with-in the '< >', the reason they are not regular code is because, the preprocessor is executed before the code is compiled, the preprocessor then looks for all code with a '#'

There for by writing '#include <iostream>' you are telling the preprocessor to include the file 'iostream' (which contains the declarations for the input-output library).

Hope this helps in some-way.

P.S. Please correct me if I am wrong

Now I'm going to google what is input-output library lol

//

Whenever I press a key (input) on my keyboard the preprocessor process it?

Gellan #8 Posted 09 April 2012 - 02:02 PM

    Private

  • Beta Tester
  • 2561 battles
  • 3
  • Member since:
    09-01-2010
#include <iostream>
using namespace std;
int main ()
{
  cout << "Hello World!";
  return 0;
}
This piece of code is not for a key input while the program is running.

When the preprocessor executes it finds the line '#include <iostream>' it will then find that file, take what is in side and place it where that 'include' line is in your code (which is the declarations for the I/O library).
'using namespace std'  - this allows you to access the functionality of namespace, "All the elements of the standard C++ library are declared within what is called a namespace" (quoted from that tutorial).

'count'  represents an output stream and this stream is declared within 'iostream'.

Is that any help for the I/O part of that code?

Edit - because I don't want to double post.

I have just looking though most of that tutorial and it seems good, for now don't worry to much on this small section of code, the overall effect is to print

'Hello World!'

to the screen, you should continue working though that tutorial and it does go on the user input et cetera.

Rinzai #9 Posted 09 April 2012 - 02:25 PM

    Lance-corporal

  • Player
  • 1953 battles
  • 57
  • Member since:
    08-10-2011

View PostGellan, on 09 April 2012 - 02:02 PM, said:

This piece of code is not for a key input while the program is running.

ok ;) ty

View PostGellan, on 09 April 2012 - 02:02 PM, said:

When the preprocessor executes it

It = any program?

Quote

finds the line '#include <iostream>' it will then find that file, take what is in side and place it where that 'include' line is in your code (which is the declarations for the I/O library).

So, imagine that I have lots of written things already and then if I write "#include <iostream>" the preprocesser will process this information:

using namespace std;
int main ()
{
  cout << "Hello World!";
  return 0;
}

And in the screen will show "Hello World"?

Gellan #10 Posted 09 April 2012 - 02:37 PM

    Private

  • Beta Tester
  • 2561 battles
  • 3
  • Member since:
    09-01-2010

View PostRinzai, on 09 April 2012 - 02:25 PM, said:


It = any program?

Sorry by 'it' I mean the preprocessor

so - When the preprocessor executes, the preprocessor finds the line '#include <iostream>'

View PostRinzai, on 09 April 2012 - 02:25 PM, said:

So, imagine that I have lots of written things already and then if I write "#include <iostream>" the preprocesser will process this information:

using namespace std;
int main ()
{
  cout << "Hello World!";
  return 0;
}

And in the screen will show "Hello World"?

You could as much information on there as you want, but the preprocessor will only 'see' as it where code with # at the front.




Semaca #11 Posted 09 April 2012 - 02:45 PM

    Staff Sergeant

  • Beta Tester
  • 32125 battles
  • 459
  • Member since:
    10-19-2010
Sorry to burst your bubble, but creating computer games it's not a two step process:
1. Learn C++
2. Write games in C++
If you don't have any background on Computer Science or Math, you started with the wrong foot.

Rinzai #12 Posted 09 April 2012 - 03:42 PM

    Lance-corporal

  • Player
  • 1953 battles
  • 57
  • Member since:
    08-10-2011

View PostSemaca, on 09 April 2012 - 02:45 PM, said:

Sorry to burst your bubble, but creating computer games it's not a two step process:
1. Learn C++
2. Write games in C++
If you don't have any background on Computer Science or Math, you started with the wrong foot.

Aleluia (in portuguese)

This is what I ask...

Tell me the several languages I have to learn please. Of course It's not just programing, there's also the design part, music/sounds, there are several aspects and one of them is the programming, I'm worried with the programming part. Artistic and musical part are easy to find, my-self, I'm in a art school, my sister also has drawing skills... I just want to know programming.

I can come up with ideas (what the game is gonna be about, the story behind it, all that... the theme).

I just need to know programming...

Rinzai #13 Posted 09 April 2012 - 04:10 PM

    Lance-corporal

  • Player
  • 1953 battles
  • 57
  • Member since:
    08-10-2011
Thanks mate, I searched "Computer Science" in google and it's MUCH more clear, it's really the beginning (so far seems to be)

Semaca #14 Posted 09 April 2012 - 04:15 PM

    Staff Sergeant

  • Beta Tester
  • 32125 battles
  • 459
  • Member since:
    10-19-2010
Language itself it's not a big deal. But it's better to start with a high level language. For example Java (it will make an easy transition to C++ later on).
But first you need to learn the fundamentals. Stuff like numeral system, flowchart, pseudocode, algorithms etc.
Then a programming language.
Then stuff related to game programming.

Or you can come up with a brilliant idea, like put 30 random tanks in game, use some off-the-shelf client/server game engine (pick your flavor, it's a big world out there) and start selling promises and lies.

GorDoink #15 Posted 10 April 2012 - 07:35 AM

    Warrant Officer

  • Beta Tester
  • 20235 battles
  • 762
  • Member since:
    09-17-2010

View PostRinzai, on 09 April 2012 - 01:01 PM, said:

C++ Tutorial

Is this reliable? I'll buy a c++ programming book anyway.


I wont be trying to learn everything from this OT section of World of Tanks, I'll just be asking some things that I don't understand when reading...

Like what was the function of #include iostream, altho they explain I still don't understand what does it do.


As GorDoink said:
"#include <file> literally places the contents of "file" at that point point in your C++ file. This is done by the preprocessor (automatically) when you compile. One reason why this is a good idea is that when you get beyond "Hello world" (famously the first program most C / C++ programmers write) you can create loads of manageable size files instead of a single, enormous file. There are many other reasons, particularly re-usability (don't want to keep re-inventing the wheel)."

Won't be lieing... Still don't understand, I'll keep reading, maybe it'll make more sense later.

The feeling that I get is that what people are trying to teach is not really the beginning of one that has no experience should learn... explain to me: Why would I want to place the contents of "file" at a certain point in my C++ file?

The tutorial looks okay but I only gave it a quick scan.  See how far you get with it, you may not need more to get a good start.

It sounds a bit daft but maybe you're looking too deeply at this stage.  Some things are like rules, they just have to be done.  As you learn more, things you just accept in the beginning will become clearer.  My problem, not being a teacher but having a lot of experience, is that I know lots of stuff but not necessarily how to explain it, especially to a beginner.

#include <iostream> - Gellan's code for "hello world" includes just one function, "main", and it uses one other, "cout".  Including the file iostream in your program tells it, amongst other things, how cout can be used and all functions must be declared or defined before they can be used.

BattleMetalChris #16 Posted 12 April 2012 - 01:40 AM

    Lieutenant General

  • Player
  • 9224 battles
  • 7,685
  • [WJDE] WJDE
  • Member since:
    05-18-2011
If you have no programming experience at all, C++ can be quite tough to learn. I recommend trying something like C# or XNA which are similar but simplify a lot of things.


Regarding your query though,

#include statements are used to bring blocks of code in from other files which you want to use.

For example, if you want to write some text to the screen, rather than having to write something to output to the screen from scratch yourself, you can use #include <iostream> at the beginning of the code which makes available various commands for inputting/outputting text (in this case 'cin' and 'cout')

The reason for this is due to the complexity of modern computers and the sheer scope of things the languages can acheive. If everything the language could possibly do was loaded at the beginning of compilation then it would never fit into memory and you'd only be using 0.001% of it anyway, so instead you pick and choose only those parts you want to use in your current program, significantly cutting down the amount the compiler needs to hold in memory.

It's also useful for reusing your own code - say you write something in one program which you want to use in another. Rather than write it all again, you can #include the file you already made and the code is ready to use, for the effort of just writing a single line. This is also important when writing in a large team, as it lets many people work on different parts of the code at the same time and each part is just slotted into place where needed.

As GorDoink said, this also allows you to split your code up into small, manageable blocks, to stop it being one huge unwieldy mess of thousands upon thousands of lines of code (something like WOT is probably around the region of 300,000 lines of source code)

elektrizikekswerk #17 Posted 12 April 2012 - 09:50 AM

    Lieutenant General

  • Beta Tester
  • 7453 battles
  • 7,723
  • Member since:
    01-24-2011
Although C++ is quite common I recommend to you to learn a more easy-to-learn language like Java or C#.

If you want to code a game (or any other complex program) you should begin with an easy goal. There are simple games to write which teach you some basic programming techniques. An easy thing to implement is Tic-tac-toe. The rules are simple, you need no graphics at all and you can implement control flow algorithms for a basic "AI".

But even that is not your first step. Your first step is to learn the very basics.

Programmig languages are learned as natural languages. Well, most of them use English words and some of them may even work with more-or-less natural sentences, but you have to learn specific vocabulary and grammar. And as in all natural languages the best to learn this is by speaking the language - well "speaking" Java means to write small programms, of course ;)

Maybe those can help you:
http://home.cc.gatech.edu/dorn/38
http://netbeans.org/...learn-java.html
http://www.c-sharpco....com/Beginners/

But don't underestimate the effort to learn a programming language to become "fluent" enough to code a complex game. There's a reason why professional programmers get several thousand Euros per month ;)

lbr #18 Posted 08 October 2012 - 12:40 AM

    Staff Sergeant

  • Player
  • 16117 battles
  • 311
  • Member since:
    04-26-2011
Only Assembler! Only Hardcore!

Also, don't listen to 'start with c#/java"
The only major difference between c#/java and c++ is GarbageCollector.
In programming languages when you need something you create an object and this object consumes memory.
So in c++ you need to allocate that memory to an object and then free that memory when object is no longer used.
If you don't, you will have memory leak(red screen bug in WOT f.e.).
c#/java were created because most/all developers find it difficult to free the memory ; ) And memory leaks are very nasty and hard to find and fix..
However c++(memory leaks hunting) teaches you patience, accuracy and not-forgetting-small-things - qualities wich makes a developer successfull.
On the other hand Java and .NET teaches you that program can consume 1GB of RAM and 1GB of HDD space and it's ok, even if it's simple.

Preprocessor.

F.e. you wrote some code and it's awesome) F.e. some method that calculates average ammount of alcohol that will kill someone, depending on their weight and gender. Now you want to include that method in your other big chunk of code, suppose you need to call this method 100 times.
Typically you want to create a procedure/function/method, but they are slower(in theory) than copy-pasting 100 times the same piece of code.
That's when preprocessor comes.. you can create a macros with your method and preprocessor will do the copy-paste for you and then compiler will compile all this stuff..

#include is also handled by preprocessor(actually compilation can take three cycles). The reason of #include is very simple - re-usability, suppose you created(or downloaded from the web) some cool stuff, then you need it somewhere else, in a different project maybe, so you just include your previously created stuff.

Also there is a linker.

Namespaces are used to diffirantiate between your methods and others, f.e. I've created some code with method called "yo" and you created some code with method called "yo". And I need to use your code.. and I can't.. cause there cant be two methods with the same name(not true, but to simplify things lets say it is).. so I'm going through your 10000 lines of code and cursing you ; ) That's how namespaces were invented)



1) Learn types
2) Simple algorythms, like sorting f.e.
3) Learn some maths, if you are up to game dev, linear algebra will help
Usually this stuff is learned in some kind of university..


..Or you can download DirectX SDK, there will be a lot of samples in C#/C++ and start learning from there.
..Or you can start with Nehe OpenGL lessons, maybe it will be even simpler than starting with DX SDK, cause Nehe will start from scratch.


But.. I recommend starting with assembler - you'll learn how PC operates, the price of mistakes, how CPU/FPU operates, how compilers function.. etc.
Also you'll be able to hack stuff once you become asm guru)))




1 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users