Advertisement

are you having a hard time?

Started by November 28, 2001 09:11 AM
11 comments, last by mickey 23 years ago
hi! just wondering if i'm the only one having a hard time learning these stuffs about game programming. and could you like also share what part in game programming is hard for you? thanks! Edited by - mickey on November 28, 2001 10:12:50 AM
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Actually making anything is the hardest part for me...
Toying around with API:s concepts and stuff n/p but actually sitting down and coding something that can be called a game.... that just doesn''t work for me
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Advertisement
As far as actual coding goes, I''m getting better but I still have trouble understanding pointers. I know how to use them (kind of), the very basics of when to use them, but still don''t understand a lot about them overall.

If you meant more as in what''s about game programming as a whole, I''d have to say sticking to a project. It''s really hard to decide on a project and actually take it to completion. What''s happened in the past for me is that I''ll come up with a cool idea, start coding the engine, and then get an even better idea. It''s a cruel cycle
Peon
The most important two things you can have as a coder are persitance and patience. Don''t be in a hurry to start coding or your going to end up starting over all the time. Come up with a good plan first. This includes software design and concept design.

Here is a sequence of events I follow when coming up with a design. The first thing to do is get the basic concept design down. What is this program supposed to do ultimately? Answering this question right away will start you on the road toward software design.

Concept design limits software design. You wouldn''t need a 3D engine for a 2-D side scroller as an example.

After you come up with the basic idea of what the program is going to do start to think about some of the ways you''d implement it. This should be VERY VERY general. For instance, you''d say "I need to have some sort of configuration file to specify which pictures belong to an animation." This will lead you to the assumption that you need to write tools for parsing files for configuration information.

Basically start with the big picture and then break the idea down into sub ideas. Then break these ideas down into subideas. Do what we is called "use cases." This is where you come up with scenarios and trace their operation through your design. This will show you if your design is solid and will help you make changes before you start to code.

It is important to be patient and persistent because you need to be able to see the design phase of the project through. Just so you know, the entire design phase doesn''t need to be done right away if you make sure that the portions you do design are general and abstract enough.

Here is an essay I wrote up for new programmers who want to get into game programming. It might be a bit much but I''ve been told that it is quite good.

Programming Advice

As far as pointers go, I can give you guys one good bit of insight that I was never told. Here it is. REALLY REALLY think about this. The "&" and the "*" operators have two contexts. These contexts are "declaration context" and "dereference context". What this means is that the "&" and the "*" mean different things in different situations.

When you are creating something or defining a parameter you are dealing with declaration context. For instance these,

  //object creationsMyClass Object;MyClass *PointerToObject;//parameter definitionvoid function( MyClass &ReferenceToObject);void function2( MyClass *PtrToObject );  


are declaration context because they declare a data type and the context in which it is to be created or passed/used. The first function wants a reference to an object passed in. The second object wants a pointer to an object passed in.

The other context is dereference context and has to do with data objects that already exist. Once you create an object or varialbe, if you use the "*" or the "&" operator in front of it you are doing something to dereference it, thus the dereference context. For instance, using the types we have above:

  main(){	function( *PointerToObject );	function( Object );	function2( &Object );	function2( PointerToObject );}  


Notice the data type of PointerToClass above as it was declared in the previous section. It is a pointer to MyClass. The function want''s us to pass in a reference to MyClass. This means that we need to convert the pointer into a reference. We do this with the "*" operator in the dereference context. So since PointerToClass is a MyClass *, putting *PointerToClass in front of the variable name when we call the function will give us the object at the address pointed to by the variable.

So basically, in declaration context the "*" operator means create an object as a pointer or pass the object as a pointer and the "&" operator means pass the object as a reference.

In dereference context the "*" operator means give us the object pointed to by this variable, and the "&" operator means give us the address of this variable, basically give us a pointer to this variable or pass in a pointer to this variable.

Hope this helps,

RandomTask
We just did this in class today. I will show you what we did.

    #include<iostream>			// For coutusing namespace std;		// Utilize the standard key words.void createDynammicMemory(double*&, float*&);    //used to create two pointersvoid destroyDynammicMemory(double*, float*);     //destroys the dynammic area that was pointed to.int main(){     	double *doublePointer;   //this is a local, automatic pointer to a place in memory that will hold a double     	float *floatPointer;     //this is a local, automatic pointer to a place in memory that will hold a float     		createDynammicMemory(doublePointer, floatPointer);     		cout << "In main, after pointers have been initialized." << endl;     	cout << "The address of the pointer to the double = " << int(doublePointer) << endl;    	cout << "the value stored at the address = " << *doublePointer << endl;    	cout << "The address of the pointer to the float = " << int(floatPointer) << endl;    	cout << "the value stored at the address = " << *floatPointer << endl << endl;     		destroyDynammicMemory(doublePointer, floatPointer);     	cout << "In main, after pointers have been destroyed." << endl;     	cout << "The address of the pointer to the double = " << int(doublePointer) << endl;     	cout << "the value stored at the address = " << *doublePointer << endl;     	cout << "The address of the pointer to the float = " << int(floatPointer) << endl;     	cout << "the value stored at the address = " << *floatPointer << endl << endl;	return 0;} // end of mainvoid createDynammicMemory(double*& dp, float*& fp)//pre: local pointers have been declared, and have been referenced into this function.//post: new memory will be dynamically allocated for the data types of the pointers passed into function, //      and will be initialized.{     	dp = new double(5.0);     	if(dp == NULL) // test to see if there is available memory space     	{		cout << "Error! no space to allocate memory, program endidng! " << endl;     		exit(0);     	} // end if statement     	fp = new float(10.f);    	if(fp == NULL)  // test to see if there is available memory space     	{      		cout << "Error! no space to allocate memory, program endidng! " << endl;  		exit(0);     	} // end if statement     		cout << "In createDynammicMemory, after pointers have been initialized." << endl;    	cout << "The address of the pointer to the double = " << int(dp) << endl;    	cout << "the value stored at the address = " << *dp << endl;     	cout << "The address of the pointer to the float = " << int(fp) << endl;     	cout << "the value stored at the address = " << *fp << endl << endl;}// end createDynammicMemoryvoid destroyDynammicMemory(double* p1, float* p2)//pre: pointers have been used, and are now passed by copy into this function//post: the memory used by pointers will be freed up{	delete p1;	delete p2;} // end destroyDynammicMemory/*OUTPUTIn createDynammicMemory, after pointers have been initialized.The address of the pointer to the double = 8261296the value stored at the address = 5The address of the pointer to the float = 8261248the value stored at the address = 10In main, after pointers have been initialized.The address of the pointer to the double = 8261296the value stored at the address = 5The address of the pointer to the float = 8261248the value stored at the address = 10In main, after pointers have been destroyed.The address of the pointer to the double = 8261296the value stored at the address = -1.45682e+144The address of the pointer to the float = 8261248the value stored at the address = -1.9984e+018Press any key to continue*/  


What you should see is that the pointers in main are local variables, and do not have scope or a lifetime beyond main.

The pointers in the createDynammicMemory funtion point to dynammically allocated memory, but still only have scope within that function. Their values are passed by reference back to the pointers in main.

The last thing that happens is a copy of the addresses stored in the pointers in main are passed to destroyDynammicMemory. The space is deleted, and now there will be no memory leak.

This really has no purpose, except to show how to make and destroy dynammic memory.

Edit: I fixed my many errors, and have the output shown.

Edited by - grandmlee on November 30, 2001 10:00:35 AM
If at first you don't succeed, use profanity and try, try again.
ok.... how do you edit posts?
If at first you don't succeed, use profanity and try, try again.
Advertisement
Just click on the edit image. It''s at the top right of every post.
All I see is profile and mail, no edit.
If at first you don't succeed, use profanity and try, try again.


Scroll over to your right.

Bye!
How is my code?
If at first you don't succeed, use profanity and try, try again.

This topic is closed to new replies.

Advertisement