Be a Supporter!

C++ Pawns all other Languages

  • 5,961 Views
  • 130 Replies
New Topic Respond to this Topic
apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 11:00 PM Reply

At 6/27/12 10:00 PM, Diki wrote: jacked code

I enjoyed this copy and paste, do you even make websites, or you fill of shit?

Post links please.


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 27th, 2012 @ 11:34 PM Reply

At 6/27/12 10:55 PM, egg82 wrote: class Pair - public:
class Ty1 as first_type
class Ty2 as second_type
?? first ??
?? second ??

The first three lines are correct. You don't actually need to use typedef to define copies of the Ty1 and Ty2 types. I Just did that mostly out of habit.
Anywhere in the code first_type and Ty1 are the exact same and are interchangeable (and with second_type/Ty2).

Admittedly this example doesn't show any practical use of typedef, and that would take a bit too long for me to explain, so I'll just sum it up in a very short and probably not too helpful sentence: it's useful when you're using the templated types with other templates.

At 6/27/12 10:55 PM, egg82 wrote: run function Pair(Ty1, Ty2)

(the pair constructor seems redundant, as it's pretty much the code above)

The first part is the declaration, the second part is the definition.
You could include the declaration inside of the class block, but that's not good practice.

They are both required though; that's how OOP works in C++.

At 6/27/12 10:55 PM, egg82 wrote: Though I wonder: is there any real benefit in not using the namespace? It seems like using std::cout would be a pain after a while. Why not namespace it so all you have to type is cout?

Technically there is no benefit in either option.
If you do using namespace std; or using std::cout it will save you from having to type a few extra characters, but that's it. There isn't any reason I didn't use it; that's just the way I typed out the code.

Don't ever put that inside a header file though.

At 6/27/12 10:55 PM, egg82 wrote: int&? That's odd. I remember something about the ampersand, but I can't quite recall it.

The ampersand is how you make the variable a reference, just like how the asterisk is used to make the variable a pointer.

At 6/27/12 10:55 PM, egg82 wrote: All i've heard about was pointers and passing by value.

Well actually, passing by value is neither using a pointer or a reference.
This is an example of passing by value:

void myFunc(int val)
{
	val = 1234;
}

int main()
{
	int foo = 42;
	myFunc(foo); // foo will not change
	
	return 0;
}

Since int was used, and not int& or int* the variable was passed by value.
This means that a whole new int was made and only exists in the scope of the function at the time that it is executed, and afterward it is deallocated/destructed.

You were probably thinking of this, passing by pointer:

void myFunc(int* val)
{
	*val = 1234; // Note the asterisk used here; that is required to de-reference the pointer
}

int main()
{
	int foo = 42;
	myFunc(&foo); // Note the ampersand here; that passed the _address_ of foo, not its value
	
	return 0;
}

That will change the value of foo to 1234.
A new int object will not be created, although an int technically will be allocated since a pointer is an address to a memory location, which is just an integer, but I won't get into that.

At 6/27/12 10:55 PM, egg82 wrote: That's... Somewhat hard to imagine. What about sizeof? It seems that it's pulling SOMETHING from the array.

Well what I meant by that is that arrays in C++ can't do something like this:

int main()
{
	int foo[5]; // make an array
	int fooLength = foo.size(); // you can't do this

	return 0;
}

However, if you use sizeof on an array, you will get: SIZE_OF_TYPE_IN_BYTES * NUM_ELEMENTS.

So, if you had an array of 5 integers on a 32bit system you would get 20.
Because a 32bit integer is 4 bytes, and there are 5 elements. 4 * 5 = 20.

If you have an array of 12 integers on a 64bit system then you would get 96.
Because a 64bit integer is 8 bytes, and there are 12 elements. 8 * 12 = 96.

Using that knowledge you can make things like the ARRAY_LENGTH pre-processor macro I wrote in my previous post.

At 6/27/12 10:55 PM, egg82 wrote: Yikes. What if the array is empty? You'd be dividing by zero o.o

You can't make an empty array in C++.
The following will not compile:

int main()
{
	int foo[0];
	return 0;
}

As well arrays in C++ can NEVER CHANGE SIZE.
That concept will seem very alien if you come from higher level languages such as PHP, Python or AS3, but arrays cannot change size in C++. If you make an array of 10 integers then it will always be an array of 10 integers until it is de-allocated.

So, so long as you know for a fact you are giving that macro an array it will always work.

At 6/27/12 10:55 PM, egg82 wrote: Why do you even need to divide, anyway? It'd seem that sizeof() would get the size of the array object, would it not?

As I explained above using sizeof on an array returns the total amount of memory the array is using up.
So you need to divide that by the amount of memory the base type uses up, which you get by doing sizeof(myArray[0]).

Arrays can never change size, and arrays can only contain one type, so that's how you do it.

At 6/27/12 10:55 PM, egg82 wrote: I would assume that #ifndef and #endif means something to the C++ compiler, I just have no idea what.

The compiler never sees that code. The pre-processor handles it, and then afterward the result is sent to the compiler.

everette00
everette00
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages Jun. 28th, 2012 @ 12:15 PM Reply

At 6/27/12 11:00 PM, apocalypseven wrote:
At 6/27/12 10:00 PM, Diki wrote: jacked code
I enjoyed this copy and paste, do you even make websites, or you fill of shit?

Post links please.

You're kidding me, right? First, you're lame for copying/pasting code. Secondly, what's with the run-on sentence? Third, you're going to sit there and question Diki's competence? I can say for sure that Diki knows what he is doing, and I go as far as saying that he is a useful resource on this forum. By-the-way, he's provided full examples, as well as clear and thorough posts. You haven't. Period. Yet. Period.

With all of my might, I say thanks and regards.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to C++ Pawns all other Languages Jun. 28th, 2012 @ 01:39 PM Reply

At 6/27/12 11:34 PM, Diki wrote: The first part is the declaration, the second part is the definition.
You could include the declaration inside of the class block, but that's not good practice.

They are both required though; that's how OOP works in C++.

Declaration and definition seem awfully redundant in C++, then. You already created and assigned your variables above, then did it again in the constructor.

Technically there is no benefit in either option.
If you do using namespace std; or using std::cout it will save you from having to type a few extra characters, but that's it. There isn't any reason I didn't use it; that's just the way I typed out the code.

Don't ever put that inside a header file though.

Fair enough, and I don't see a scenario in which I may want to.

At 6/27/12 10:55 PM, egg82 wrote: int&? That's odd. I remember something about the ampersand, but I can't quite recall it.
The ampersand is how you make the variable a reference, just like how the asterisk is used to make the variable a pointer.

Oh, duh. I remembered the asterisk, but not the ampersand.

Well actually, passing by value is neither using a pointer or a reference.

That's what I was talking about. I forgot that I learned about passing by reference (and the actual benefits), so I thought that in C++ all I could do was pass by value (make a copy) or pass by pointer (integer copy of the memory address of the variable you want to change)

So, if you had an array of 5 integers on a 32bit system you would get 20.
Because a 32bit integer is 4 bytes, and there are 5 elements. 4 * 5 = 20.

If you have an array of 12 integers on a 64bit system then you would get 96.
Because a 64bit integer is 8 bytes, and there are 12 elements. 8 * 12 = 96.

Using that knowledge you can make things like the ARRAY_LENGTH pre-processor macro I wrote in my previous post.

ahh,I see. I've never learned about getting the actual number of the array elements, so that will come in handy at some point.

You can't make an empty array in C++.
As well arrays in C++ can NEVER CHANGE SIZE.
That concept will seem very alien if you come from higher level languages such as PHP, Python or AS3, but arrays cannot change size in C++. If you make an array of 10 integers then it will always be an array of 10 integers until it is de-allocated.

So, so long as you know for a fact you are giving that macro an array it will always work.

Interesting. I suppose you could always create a larger (or smaller) array, move the elements to that array, and de-allocate the first array. You'd just have to watch out for overflows if you're moving to a smaller array.

The compiler never sees that code. The pre-processor handles it, and then afterward the result is sent to the compiler.

Okay, fair enough, but what exactly does the pre-processor see in that? Is writing code for it like a whole different language, or what?


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 28th, 2012 @ 02:14 PM Reply

At 6/28/12 01:39 PM, egg82 wrote: Declaration and definition seem awfully redundant in C++, then. You already created and assigned your variables above, then did it again in the constructor.

It's not redundant, that's how it works. First you need to tell the compiler what the thing is, then you tell it what it does.
You're probably just too accustomed to high level languages like AS3 where you would just make a constructor like this:

class MyClass
{
	public function MyClass():void
	{
		// ...
	}
}

But remember that, although C++ and AS3 do share some similarities, they are worlds apart.
Here's an example of a class that is implemented using a header and source file, the way C++ should be written:

FooBar.hpp

#ifndef _FOOBAR_HPP_
#define _FOOBAR_HPP_

#include <string>

class FooBar
{
private:
	int __mId;
	std::string __mName;
public:
	FooBar(int, char*);
	
	int getId() const;
	std::string getName() const;
};

#endif

FooBar.cpp

#include "foobar.hpp"

FooBar::FooBar(int id, char* name)
: __mId(id), __mName(name)
{}

int FooBar::getId() const
{
	return __mId;
}

std::string FooBar::getName() const
{
	return __mName;
}

You declare the class in the header file, and then define it in the source file.
If you were to create this class into a library then the .CPP file would be turned into a .LIB file and the .HPP file would be used in conjunction with it.

So if you ever download a library for C++ you will get a bunch of .H/.HPP files and .LIB files.
The headers will contain the declarations, and .LIB files the definitions.

At 6/28/12 01:39 PM, egg82 wrote: That's what I was talking about. I forgot that I learned about passing by reference (and the actual benefits), so I thought that in C++ all I could do was pass by value (make a copy) or pass by pointer (integer copy of the memory address of the variable you want to change)

That's actually another example of when to use a reference. If you're just changing the value you should pass the variable by reference.
Passing by pointer can be useful, for example, if you wanted to find the "distance" in memory between the values.

Memory positions are just the numbers 0 to a maximum of 4294967296 on a 32bit platform, and 0 to a maximum of 18446744073709551616 on a 64bit system (64bit computers can use a lot of memory).
So if you want the "distance" between two pointers you can simply do this:

unsigned int getDistance(int* first, int* second)
{
	return (second - first); // Remember these are pointers, _not_ values
}

int main()
{
	int a = 42;
	int b = 1234;
	unsigned int distance = getDistance(&a, &b);

	return 0;
}

Note: this code is susceptible to an integer overflow.

At 6/28/12 01:39 PM, egg82 wrote: Interesting. I suppose you could always create a larger (or smaller) array, move the elements to that array, and de-allocate the first array. You'd just have to watch out for overflows if you're moving to a smaller array.

That is precisely how you would make a dynamically resizing array in C++.
It's also how the vector container works. Although, the vector container will never shrink; it only grows.
Personally I find that to be kind of stupid, especially since the only way to actually de-allocate a vector's contents is kind of hacky:

#include <vector>

int main()
{
	std::vector<int> vec(10); // Create a vector of 10 integers.
	
	vec.clear(); // Vector is now "empty" but the memory has _not_ been de-allocated
	vec.swap(std::vector<int>()); // Swap this vector with a new, empty, vector, making this vector de-allocated

	return 0;
}

The swap method does exactly what it sounds like: it swaps all contents of the vector with the one that it passed to it.
So if you pass an empty vector (which is created via its constructor) the contents are copied into said empty vector, and the empty vector's contents are copied into vec (in other words: vec is now empty).

Since the value of the empty-constructed vector was not stored in a variable it is de-allocated, and the memory allocated by the 10 integers is freed.

Sorry if I didn't explain that well. :)

At 6/28/12 01:39 PM, egg82 wrote: Okay, fair enough, but what exactly does the pre-processor see in that? Is writing code for it like a whole different language, or what?

It just looks for macros that are pre-fixed with the # symbol and perform the necessary actions on the text of your code.
It does literally nothing but alter the plaintext that you type out before it's compiled.

So when you do this:

#define INT_TYPE int
#define FOURTY_TWO 42

INT_TYPE myCoolInteger = FOURTY_TWO;

It sees that you defined values for INT_TYPE and FOURTY_TWO.
So anywhere you typed the literal text "INT_TYPE" it will replace that with :int". Anywhere you typed the literal text "FOURTY_TWO" it will replace it with 42.

Note that it's smart enough not to fuck up strings are or anything like that:

#define INT_TYPE int
#define FOURTY_TWO 42

INT_TYPE myCoolInteger = FOURTY_TWO;

char* str = "INT_TYPE FOURTY_TWO"; // Will not be affected
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 28th, 2012 @ 03:38 PM Reply

I just realised that saying the preprocessor "literally" only alters the plaintext version of your code was a little bit inaccurate/disingenuous.
It can do other things, but chances are you won't need to use them that way.

This article does a good job of explaining the preprocessor in detail.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to C++ Pawns all other Languages Jun. 28th, 2012 @ 05:26 PM Reply

Sorry about the late reply, i've been running around like a chicken with my head cut off since I learned we were choosing teams for the jam. So much to do, so little time! Good thing energy drinks were on sale today.

At 6/28/12 02:14 PM, Diki wrote: It's not redundant, that's how it works. First you need to tell the compiler what the thing is, then you tell it what it does.
You're probably just too accustomed to high level languages like AS3 where you would just make a constructor like this:

well, it seems like you've defined them twice. It's like saying:

public class newClass{
	public var vec:Vector.<Boolean> = new Vector.<Boolean>;
	
	public function newClass(){
		vec = new Vector.<Boolean>;
	}

It just seems redundant.

So if you ever download a library for C++ you will get a bunch of .H/.HPP files and .LIB files.
The headers will contain the declarations, and .LIB files the definitions.

I probably won't be working with libraries just yet :P

That's actually another example of when to use a reference. If you're just changing the value you should pass the variable by reference.
Passing by pointer can be useful, for example, if you wanted to find the "distance" in memory between the values.

I don't see finding the distance as useful. I mean, if it was static, then maybe... Maybe... But memory addresses aren't static, so I don't see what's useful about knowing the memory address of a variable (besides changing it via a pointer)

That is precisely how you would make a dynamically resizing array in C++.
It's also how the vector container works. Although, the vector container will never shrink; it only grows.

Yay, I figured something out! xD

Since the value of the empty-constructed vector was not stored in a variable it is de-allocated, and the memory allocated by the 10 integers is freed.

So basically if you have a null variable, it de-allocates after the function ends?

It just looks for macros that are pre-fixed with the # symbol and perform the necessary actions on the text of your code.
It does literally nothing but alter the plaintext that you type out before it's compiled.
Note that it's smart enough not to fuck up strings are or anything like that:

I would expect it not to screw with strings :P

though i'm still not sure what the #endif and all of that really means. It seems like a whole new programming language to me.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 28th, 2012 @ 08:15 PM Reply

At 6/28/12 05:26 PM, egg82 wrote: well, it seems like you've defined them twice. It's like saying:

public class newClass{
public var vec:Vector.<Boolean> = new Vector.<Boolean>;

public function newClass(){
vec = new Vector.<Boolean>;
}

It just seems redundant.

I don't know what else to tell ya man, that's just how C++ works.
You can't compare to AS3; it's comparing apples to oranges, it doesn't work.

Low level languages like C++ can often require you to do a lot of work to achieve a little.

At 6/28/12 05:26 PM, egg82 wrote: I don't see finding the distance as useful. I mean, if it was static, then maybe... Maybe... But memory addresses aren't static, so I don't see what's useful about knowing the memory address of a variable (besides changing it via a pointer)

You're still new to C++ so you haven't learnt enough to really appreciate pointers.
For example, I'm assuming you haven't learnt about the new operator yet, or how arrays can be treated as pointers.

For example, you could calculate the number of elements in an array like this:

int main()
{
	int foo[10];
	int numElements = (&foo[9]) - (&foo[0]); // 10

	return 0;
}

Of course that example doesn't serve any real purpose, but I'm just showing you how you can calculate the length of an array.
However when you allocate memory using the new operator it works pretty much the same way as an array (emphasis on "pretty much").

This specific topic is getting too complicated for someone just starting out with C++, but there you go.

At 6/28/12 05:26 PM, egg82 wrote: So basically if you have a null variable, it de-allocates after the function ends?

No. Variables are de-allocated under two conditions:

1) They fall out of scope. For example, if you create a variable inside of a function, once that function ends the variable will be de-allocated, because the scope ends. Remember that your main is just a function, so when that ends, everything not already de-allocated will be.

2) When you use the delete operator on memory allocated with the new operator, but again, don't worry about that; if you're just starting out you don't need to learn this stuff yet.

A NULL variable has not been allocated; that's specifically what it means.
Think of it like null/undefined in AS3; you know what the variable is, but it hasn't been allocated and cannot be used for anything.

Having said that, there is something about NULL in C++ that you should understand: there's no such thing as NULL.
NULL in C++ is actually a #define macro that is actually just the number zero. Basically think of NULL as this:

#define NULL 0

When using pointers in C++ the integer 0 means "not allocated". The word NULL was created just to make a word that can be specifically used with pointers which makes code easier to understand.

At 6/28/12 05:26 PM, egg82 wrote: though i'm still not sure what the #endif and all of that really means. It seems like a whole new programming language to me.

If the condition is true then the text inside the block is not touched.
If the condition is false then the text inside the block is removed.

Here's an example:

#define HELLO_WORLD "hello world"

#ifdef HELLO_WORLD
int foo = 42;
#endif

int bar = 1234;

Since HELLO_WORLD has been defined, the line int foo = 42; will not be touched.
The code above is literally the exact same as just this:

int foo = 42;
int bar = 1234;

However, change that code to this:

#define HELLO_WORLD "hello world"

#ifdef GOODBYE_WORLD
int foo = 42;
#endif

int bar = 1234;

And you will end up with this:

int bar = 1234;

That is because GOODBYE_WORLD was never defined, so anything inside of that block will be removed from your source code before it is sent to the compiler.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 28th, 2012 @ 08:29 PM Reply

At 6/28/12 08:15 PM, Diki wrote: I don't know what else to tell ya man, that's just how C++ works.
You can't compare to AS3; it's comparing apples to oranges, it doesn't work.

Low level languages like C++ can often require you to do a lot of work to achieve a little.

Wow those first two sentences were poorly written.
What I meant to say was that comparing AS3 to C++ won't ever make sense because the languages are too different. They were created for entirely different purposes, and follow/allow entirely different paradigms.

I understand where you are coming from; C++ is a difficult language to learn, as well as wrap your head around.
Always keep in mind that AS3 is a very high level language; C++, while still comprising of high level features, is, in my opinion, a low level language; it will will always be more cumbersome and confusing by comparison.

kiwi-kiwi
kiwi-kiwi
  • Member since: Mar. 6, 2009
  • Offline.
Forum Stats
Member
Level 09
Programmer
Response to C++ Pawns all other Languages Jun. 28th, 2012 @ 08:51 PM Reply

At 6/28/12 05:26 PM, egg82 wrote: public class newClass{
public var vec:Vector.<Boolean> = new Vector.<Boolean>;

public function newClass(){
vec = new Vector.<Boolean>;
}

It just seems redundant.

You have to understand that C++ was made a long time ago and due to the way it works it has to make things this way.
A very simple example would be this:
Let's say you have a main.cpp that just prints hello world. This isn't a problem you can compile it as is and everyone is fine with that.
You start to build on this example and add a class, then another class etc until the source file gets too big and you start losing yourself in the code. Well when that happens you would ideally want to separate your code and have it in multiple files. This poses a problem because now that the classes are in other files, the compiler alone wouldn't be able to make a program out of that main.cpp because it won't be able to find the classes you used.
That's when the idea behind the extern keyword was born. Basically what happens is that you say somewhere in your code that you promise that sometime in the future some program will be able to find what's marked with extern, just not when it's going to get compiled into bytecode, so the compiler basically flags that piece as missing and then passes what comes out to the linker. So the compiler will spit out object files(that's what the .o files are) which are basically programs that are almost finished but are missing the part that you promised will be there sometime by adding extern. This is where the linker comes in. It takes all the .o files you give it and starts to fill in the gaps until you have an executable file at the end.

Now the next problem is that whenever you want to use your class somewhere, you will have to declare it as extern first so that you won't have troubles compiling it. It helps that the standard specifies that anything you declare will be treated as extern by default, but then whenever you'd have to use a class somewhere you'd have to write it all over again, all the functions and members so that the compiler knows that they will be there.

This is why you have .h files, #include will just replace that line with the actual contents of the file, so if you declare your class in a .h file you can then use #include to add all the definitions the compiler needs at once without having to remember where you put all of them in case you need to add a function definition.

Of course you still need to implement them somewhere, you could do that in the .h file by making the body of the function right after the declaration, but that would be inefficient because it would mean that the compiler has to process the same class over and over again for each appearance, so the preferred method is to have a separate file with the actual implementation of the functions.

If you think something is unclear do tell.
Also sorry if I missed anything

Cheers

apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 29th, 2012 @ 03:44 AM Reply

At 6/28/12 12:15 PM, everette00 wrote:
You're kidding me, right? First, you're lame for copying/pasting code.

I never posted any code.

Secondly, what's with the run-on sentence?

I like my sentences long like my cock.

Third, you're going to sit there and question Diki's competence?

Just wanted to see a website.


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
everette00
everette00
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages Jun. 29th, 2012 @ 10:25 AM Reply

At 6/29/12 03:44 AM, apocalypseven wrote:
At 6/28/12 12:15 PM, everette00 wrote:
You're kidding me, right? First, you're lame for copying/pasting code.
I never posted any code.

And I never said "posted".

Secondly, what's with the run-on sentence?
I like my sentences long like my cock.

That statement clearly shows your maturity.

Third, you're going to sit there and question Diki's competence?
Just wanted to see a website.

What you said did not indicate innocent curiosity; it was clearly smug and arrogant.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 29th, 2012 @ 10:42 AM Reply

At 6/29/12 10:25 AM, everette00 wrote: What you said did not indicate innocent curiosity; it was clearly smug and arrogant.

Which is why I ignored him.
That and the websites I make are for multimillion dollar companies whom would sue the fuck out of the company I work for if I posted links to their sites on a message board.

everette00
everette00
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages Jun. 29th, 2012 @ 11:09 AM Reply

At 6/29/12 10:42 AM, Diki wrote: Which is why I ignored him.
That and the websites I make are for multimillion dollar companies whom would sue the fuck out of the company I work for if I posted links to their sites on a message board.

I did the same thing on my account.

apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 29th, 2012 @ 01:57 PM Reply

At 6/29/12 10:42 AM, Diki wrote:
That and the websites I make are for multimillion dollar companies whom would sue the fuck out of the company I work for if I posted links to their sites on a message board.

And you wanted me to post my video game code, shame on you DIki.


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
everette00
everette00
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages Jun. 29th, 2012 @ 02:16 PM Reply

At 6/29/12 01:57 PM, apocalypseven wrote: And you wanted me to post my video game code, shame on you DIki.

No one asked you post any code pertaining to any projects you're working on. Only thieves do that - bad ones at that. What we're saying here is you should post C++ code that you're capable of writing. If you're so good, then you should have no problem whipping up some random code that shows your ability.

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jun. 29th, 2012 @ 04:43 PM Reply

At 6/29/12 01:57 PM, apocalypseven wrote: And you wanted me to post my video game code, shame on you DIki.

I never requested you post anything, actually.
Feel free to quote me and prove me wrong though.

apocalypseven
apocalypseven
  • Member since: Mar. 13, 2012
  • Offline.
Forum Stats
Member
Level 01
Movie Buff
Response to C++ Pawns all other Languages Jun. 29th, 2012 @ 04:47 PM Reply

At 6/29/12 04:43 PM, Diki wrote:
I never requested you post anything, actually.
Feel free to quote me and prove me wrong though.

I am not a whore, I do not flaunt my pussy in public.


" Women are dumb sheep who would rather fuck a Silverback than Einstein." - EisUndStahl

BBS Signature
everette00
everette00
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages Jun. 29th, 2012 @ 08:27 PM Reply

At 6/29/12 04:47 PM, apocalypseven wrote: I am not a whore, I do not flaunt my pussy in public.

Nice expletive vocabulary. Do you always value yourself as highly as you do? I mean, there has to be a point at which you say to yourself, "I'm so full of it right now." I realize you're trolling, but I doubt that you have any aforementioned skills.

Jaface
Jaface
  • Member since: Aug. 26, 2010
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to C++ Pawns all other Languages Jul. 1st, 2012 @ 01:21 PM Reply

At 6/13/12 08:52 PM, apocalypseven wrote: I'm using Actionscript 3 for the games, thanks for the tip for the conversion, but I'll use this dumbed down language for now, because if I use C++ now you thieves will jack my source code, LMAO.

You could have been a legendary troll in my eyes if you had stopped posting after this.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to C++ Pawns all other Languages Jul. 2nd, 2012 @ 03:20 AM Reply

after 14 hours of sleep in 4 days, I am incredibly tired, so I will make this short.
Sorry, Diki, I really wanted to give a longer response and ask more questions.

I will learn C++ at some point (it's required for my major, anyway) so I figure it's not too terribly important that I start right now. I will finish learning AS3 first, and then I will learn C++ the way I do best.
How do I do that? I'm going to make a 3d multiplayer game as soon as I pick up a compiler. Yes, that really is the best way I learn. Jump in the deepest practical end and start asking questions the second I feel my feet hit water.

Anyway, sorry for the short response, g'night folks!

and i'm pretty sure apocalypse is a troll - though either somewhat unintentionally or one with a lot of time and patience, but i've seen quite a few of his/her posts, and he/she is no "ordinary" troll

Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jul. 2nd, 2012 @ 02:06 PM Reply

At 7/2/12 03:20 AM, egg82 wrote: How do I do that? I'm going to make a 3d multiplayer game as soon as I pick up a compiler. Yes, that really is the best way I learn. Jump in the deepest practical end and start asking questions the second I feel my feet hit water.

Don't do this. Trust me: you will not finish.
You have no idea how complicated 3D programming in C++ is. Combine that with how complicated socket programming in C++ is and you're in a for a world of trouble.

When I was in college, in my second semester, our final project was to make a basic 3D game; we had five people in our group, three of us programmers, two of us artists.
The five of us, after working our asses off for 3 months, didn't have much to show for it and our end result was an ugly, buggy pile of crap. And that was five of us going to college specifically for developing games with C++.

Here's some examples; this code does nothing but prepare OpenGL for rendering:

bool CGLRenderer::CreateGLContext(CDC* pDC)
{
	PIXELFORMATDESCRIPTOR pfd;
	memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
	pfd.nSize  = sizeof(PIXELFORMATDESCRIPTOR);
	pfd.nVersion   = 1;
	pfd.dwFlags    = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
	pfd.cDepthBits = 32;
	pfd.iLayerType = PFD_MAIN_PLANE;
 
	int nPixelFormat = ChoosePixelFormat(pDC->m_hDC, &pfd);
 
	if (nPixelFormat == 0) return false;
 
	BOOL bResult = SetPixelFormat (pDC->m_hDC, nPixelFormat, &pfd);
 
	if (!bResult) return false; 
 
	HGLRC tempContext = wglCreateContext(pDC->m_hDC);
	wglMakeCurrent(pDC->m_hDC, tempContext);
 
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		AfxMessageBox(_T("GLEW is not initialized!"));
	}
 
	int attribs[] =
	{
		WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
		WGL_CONTEXT_MINOR_VERSION_ARB, 1,
		WGL_CONTEXT_FLAGS_ARB, 0,
		0
	};
 
        if(wglewIsSupported("WGL_ARB_create_context") == 1)
        {
		m_hrc = wglCreateContextAttribsARB(pDC->m_hDC,0, attribs);
		wglMakeCurrent(NULL,NULL);
		wglDeleteContext(tempContext);
		wglMakeCurrent(pDC->m_hDC, m_hrc);
	}
	else
	{	//It's not possible to make a GL 3.x context. Use the old style context (GL 2.1 and before)
		m_hrc = tempContext;
	}
 
	//Checking GL version
	const char *GLVersionString = glGetString(GL_VERSION);
 
	//Or better yet, use the GL3 way to get the version number
	int OpenGLVersion[2];
	glGetIntegerv(GL_MAJOR_VERSION, &OpenGLVersion[0])
	glGetIntegerv(GL_MINOR_VERSION, &OpenGLVersion[1])
 
	if (!m_hrc) return false;
 
	return true;
}

And this is what very rudimentary socket code looks like.
Much like the OpenGL code above this pretty much just prepares the socket server, and doesn't actually do anything:

int main(int argc, char* argv[])
{
    int iRet = 1;
    WSADATA wsaData;

    cout << "Initializing winsock... ";

    if (WSAStartup(MAKEWORD(REQ_WINSOCK_VER,0), &wsaData)==0)
    {
        // Check if major version is at least REQ_WINSOCK_VER
        if (LOBYTE(wsaData.wVersion) >= REQ_WINSOCK_VER)
        {
            cout << "initialized.\n";

            int port = DEFAULT_PORT;
            if (argc > 1)
                port = atoi(argv[1]);
            iRet = !RunServer(port);
        }
        else
        {
            cerr << "required version not supported!";
        }

        cout << "Cleaning up winsock... ";

        // Cleanup winsock
        if (WSACleanup()!=0)
        {
            cerr << "cleanup failed!\n";
            iRet = 1;
        }
        cout << "done.\n";
    }
    else
    {
        cerr << "startup failed!\n";
    }
    return iRet;
}

(Note: this will only work on Windows. The code will be completely different for Linux.)

So just trust me when I say to not attempt a multiplayer 3D game as your first C++ project.
Try something simple like a text-adventure game that uses the console (seriously; this will be more complicated than you think).

Don't try to run before you can walk; you will learn far less if you do that.

TheZaaL
TheZaaL
  • Member since: Apr. 13, 2012
  • Offline.
Forum Stats
Member
Level 02
Audiophile
Response to C++ Pawns all other Languages Jul. 2nd, 2012 @ 03:15 PM Reply

At 7/2/12 02:06 PM, Diki wrote: So just trust me when I say to not attempt a multiplayer 3D game as your first C++ project.

I second. Found out the hard way. Trust me.


Computer has no brain. DEAL WITH IT!
Stupidity is a dangerous and contagious disease. It can happen to you. It can happen to me

sharpnova
sharpnova
  • Member since: Feb. 19, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to C++ Pawns all other Languages Jul. 17th, 2012 @ 02:16 AM Reply

Diki,

I haven't done much flash programming so I don't really know. But isn't AS3 pretty much like Java and AS2 was more like C++?


= + ^ e * i pi 1 0

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to C++ Pawns all other Languages Jul. 17th, 2012 @ 09:44 AM Reply

I don't really know what you would compare AS2 to, but other than AS2 being a C-like language it's not comparable to C++; they're too different. Plus ActionScript is a dialect of ECMAScript, making it even less comparable to C++.

AS3 certainly took some pages from the Java, so they are similar, but they're languages used for different purposes (with some exceptions, such as making games, which, in my opinion, Java sucks at).

kngsnghun
kngsnghun
  • Member since: Jul. 26, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to C++ Pawns all other Languages Jul. 27th, 2012 @ 09:25 PM Reply

wow Im learning so much just by watching these selfish bastards clawing at each others faces


ã„·ã„·

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to C++ Pawns all other Languages Aug. 2nd, 2012 @ 06:00 PM Reply

At 7/2/12 02:06 PM, Diki wrote: When I was in college, in my second semester, our final project was to make a basic 3D game; we had five people in our group, three of us programmers, two of us artists.
The five of us, after working our asses off for 3 months, didn't have much to show for it and our end result was an ugly, buggy pile of crap. And that was five of us going to college specifically for developing games with C++.

speaking of college, I finally signed up for the beginner's C++ and beginner's Javascript for the fall semester. Wish me luck! o.o

anyway, preparing a socket doesn't seem like too much trouble, but openGL looks nightmarish.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to C++ Pawns all other Languages Aug. 2nd, 2012 @ 06:02 PM Reply

At 8/2/12 06:00 PM, egg82 wrote: speaking of college, I finally signed up for the beginner's C++ and beginner's Javascript for the fall semester. Wish me luck! o.o

not Javascript; Java. Herp.
I've been working on the 'ol site again .-.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
doodle-bread14
doodle-bread14
  • Member since: Jul. 25, 2012
  • Offline.
Forum Stats
Member
Level 04
Programmer
Response to C++ Pawns all other Languages Aug. 2nd, 2012 @ 06:42 PM Reply

wow Im learning so much just by watching these selfish bastards clawing at each others faces

Most of the users (like Diki and egg82) are trying the best they can to fully answer any of our questions. So get your dirty ass out of here and troll at those threads that deserve trolling!

not Javascript; Java. Herp.
I've been working on the 'ol site again .-.

How's C++ going? What have you learned so far?


At least not a muffin.

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to C++ Pawns all other Languages Aug. 4th, 2012 @ 01:13 PM Reply

At 8/2/12 06:42 PM, doodle-bread14 wrote: Most of the users (like Diki and egg82) are trying the best they can to fully answer any of our questions. So get your dirty ass out of here and troll at those threads that deserve trolling!

well, only some of the thread was dedicated to "clawing at eachothers' faces"
the rest of it was real learning.

besides, I wasn't exactly answering a whole bunch of questions; just asking a whole bunch.
Thank Diki for pretty much all of the answers O.o

How's C++ going? What have you learned so far?

haven't started yet. I'm pretty much still in the same boat I was in before.
I have a feeling that I chose correctly when I decided to only take two classes this semester. It seems that learning C++ and Java at the same time may be a bit of an overload by themselves.

besides, none of the other classes fit into my schedule.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature