Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Standard C, C++

Reply
 
LinkBack Thread Tools Display Modes
Old 12-28-2003, 04:51 PM   #16 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
I am just curious but what are you planning to do?
Do some serious recap (up to intermediate level) C++ first?
If so then here is something worth wile since it's nicely up to date as well.
Title: Accelerated C++
By: Andrew Koenig & Barbara Moo
ISBN: 0 201 70353 X
Publisher: Addison-Wesley
Pages: 333pp
Price: $30
__________________
Valmont is offline   Reply With Quote
Old 12-28-2003, 05:34 PM   #17 (permalink)
L06@N
Registered User
 
L06@N's Avatar
 
Join Date: Dec 2003
Location: Nebraska, USA
Posts: 17
L06@N is on a distinguished road
I am wanting to start working on a gaming project. Not sure where I will take it yet; but I have some idea's (some 2D and some 3D), storeline, etc. of where to go with this. I know it's gonna take me a long time to see anything come of this, but I am well willing to wait
But a recap is always nice as it has been about a 6 months since I really did much with C/C++. And since I have mis-placed the books I used to have for reference it'd be cool to get some new ones (evne just to keep around to thumb through if needed).



EDITED EXTRA: I do hope to port whatever I make, over to Linux someday. Should I worry about that now or later? If now, any good books?
L06@N is offline   Reply With Quote
Old 12-30-2003, 03:15 AM   #18 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
If porting is important then it demands attention from the start.
If you don't, then when you need it, you will be stuck in habits and a way of thinking that makes "programming for portability" problematic.

Programming for portability is not as much a matter of "good books".
It is more a matter of knowing your programming language very well.
When you make some code, think like this:
"Did I use stuff that is typical for MS Windows?".
"If so, what can I do to achieve the same, but without the help of typical MS Windows features.".
"If so, how can I minimize problems when I need to re-code later?"

Test:
Is DirectX a typical MS Windows thing?
And Direct3D? And DirectSound? And DirectInput?
How about OpenGL?
How about system(PAUSE) (C++)?
How about <conio.h> ?
And <Windows.h> ?
__________________
Valmont is offline   Reply With Quote
Old 12-30-2003, 07:01 AM   #19 (permalink)
L06@N
Registered User
 
L06@N's Avatar
 
Join Date: Dec 2003
Location: Nebraska, USA
Posts: 17
L06@N is on a distinguished road
Very true. Well portabilty isn't a big thing to me, no.
For my 1st project I throw together I'll start out not worring about that (since it's my first dive at doing a gaming engine).
Maybe on a later date I'll try to do soemthing else for the *nix world.

Is that about it for good books though (Windows or *nix based)?
L06@N is offline   Reply With Quote
Old 12-30-2003, 05:00 PM   #20 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
If portability is an issue in one or maybe two years, then portability is important right now.
__________________
Valmont is offline   Reply With Quote
Old 12-31-2003, 06:22 AM   #21 (permalink)
L06@N
Registered User
 
L06@N's Avatar
 
Join Date: Dec 2003
Location: Nebraska, USA
Posts: 17
L06@N is on a distinguished road
Portability won't be an issue for anything I do at first. It won't need to worry about it until a few projects down the road (I wanna get a grip on Windows gaming engines/making and then I can go from there)
L06@N is offline   Reply With Quote
Old 12-31-2003, 06:36 AM   #22 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
What I mean is that it is better to adapt a programming style that fits in a context of easy porting, as soon as possible.
If you say that one (or maybe) two projects won't be ported then it means to me that you have every reason to read your c++ material well, to get familiar with modern standards.
From there you will build up a discipline that takes you beyond just coding technique.

Most less seasoned programmers think this is a hard thing to do. But it isn't at all. Don't let the difficult words scare you. Make it easy on you and try to find out what "ANSI C++" means. From there you can make a start. This discipline will give you a headstart.

I also gave you the title of a book. I did that on purpose. The book has an approach where you will be taught to program more or less a slightly better way.

I hope you see now what I am getting at.

- Val -
__________________
Valmont is offline   Reply With Quote
Old 12-31-2003, 06:51 AM   #23 (permalink)
L06@N
Registered User
 
L06@N's Avatar
 
Join Date: Dec 2003
Location: Nebraska, USA
Posts: 17
L06@N is on a distinguished road
I fully see what your saying. That is a very good point; to not get stuck in bad habits or using propritary includes, etc.
I will also read through that book (along with the other review C++ book that was suggest, before I hit the gaming portion of the books).

Man, this forum is sure a good one


EDIT NOTE: Is that the exact name of the book or? I was checking out Amazon I didn't see it (I was an old out of print listing), but did see a couple books that has "ANSI C++" in the title of them. Just wanna make sure I grab the right one
L06@N is offline   Reply With Quote
Old 12-31-2003, 07:52 AM   #24 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
First the link to the book I suggested.
CLICK THIS LINK

Quote:
...to not get stuck in bad habits...
You go bro!
Quote:
...or using propritary includes...
What? Start even more simple!
Check for example -this page to get a nice idea.
See? Start simple just to get started. Play around when you learn from books. Ask around. You can go only downhill this way.

Good luck!
- Val
__________________
Valmont is offline   Reply With Quote
Old 12-31-2003, 08:09 AM   #25 (permalink)
L06@N
Registered User
 
L06@N's Avatar
 
Join Date: Dec 2003
Location: Nebraska, USA
Posts: 17
L06@N is on a distinguished road
I sweet man. Ya, I got it now

Hehe, I know where I'll ask around if I ever get losts in a book...

Ya, bad habbits are hard to break once you start them...
L06@N is offline   Reply With Quote
Old 12-31-2003, 09:05 AM   #26 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
These are my very last hours (possibly minutes) online. I will be offline for the next two months or so. Then I will be back.

Since you want to program games in the (near) future, I'll give you advice on typical relevant issues (coding wise). I won't be able to do that later.

1) Learn ALL the basics of classes.
- Constructors
- Destructors
- Virtual Destructors.
2) Learn all the basics of derriving classes and what that means.
- Virtual methods (functions).
- Pure Virtual functions.
3) Learn the ways of pointers and references.
- What does the pointer in this function want:
void Function(SomeType* type);
Answer: it wants to receive an adress. Not a variable.

//Scenario One:
SomeType MyFirstObject;
Function( & MyFirstObject); // need ampersand for adress!
//Scenario Two:
SomeType* MySecondObject = new SomeType;
Function( MySecondObject ); // no need for '&' because MySecondObject is a pointer, therefore it hold an adress!
- Can you figure out how it works with arrays? Very simple but try to create something that works.

4) What is this code below doing? (Now we are going to do some real stuff). I will ask typical questions later after the code.

Code:
//**** BaseOne.h ****

#include "ISomeInterface.h"

class BaseOne
{
public:
	void SetIface(ISomeInterface* iface) { delete IFace; IFace = iface;	}

public:
	BaseOne(ISomeInterface* iface) : IFace(iface){}
	BaseOne () : IFace(0) {}
	~BaseOne() { }

private:
	ISomeInterface* IFace;
};

//**** BaseTwo.h ****

#include "ISomeInterface.h"

class BaseTwo
{
public:
	void SetIface(ISomeInterface* iface) { delete IFace; IFace = iface;	}

public:
	BaseTwo(ISomeInterface* iface) : IFace(iface){}
	BaseTwo() : IFace(0) {}
	~BaseTwo() { }

private:
	ISomeInterface *IFace;
};

//**** ISomeInterface.h ****

#ifndef ISOMEINTERFACE_H
#define ISOMEINTERFACE_H

class ISomeInterface
{
public:
	ISomeInterface() {}

private:
	ISomeInterface& operator=(const ISomeInterface&){}
	ISomeInterface(const ISomeInterface&) {}
	
};


#endif // ISOMEINTERFACE_H



//**** Main.cpp **** Our entry point for the app.

#include "BaseOne.h"
#include "BaseTwo.h"
#include "ISomeInterface.h"
#include <iostream>

using namespace std;

int main()
{
	/*
	BaseOne(new ISomeInterface);
	BaseTwo(new ISomeInterface);
	*/
	

	/* 
	ISomeInterface* IF = new ISomeInterface;
	BaseOne B_1 = IF;
	BaseTwo B_2 = IF;
	delete IF; //*/

	/* 
	ISomeInterface* IF = new ISomeInterface;
	BaseOne B_1;
	BaseTwo B_2;
	B_1.SetIface(IF);
	B_2.SetIface(IF);
	delete IF; //*/

return EXIT_SUCCESS;
}
Phew!
Ok.
1a) Do you know what this is good for: BaseOne(ISomeInterface* iface) : IFace(iface){}
1b) This does the same (but not automatic like a constructor): void SetIface(ISomeInterface* iface) { delete IFace; IFace = iface;}
Answer: This is a 'plug-in' system. The user can plug-in ISomeInterFace in class BaseOne or BaseTwo. Look at main() on how it is done. This standard technique is most important for some decent OO programming and applies to certain areas of the gamingworld.
2a) Now look very closely to this code below:
private:
ISomeInterface& operator=(const ISomeInterface&){}
ISomeInterface(const ISomeInterface&){}
2b) Why is my copy-constructor 'private'(normal = public), and not even implemented?
2c) Why is the operator= method private and not even implemented?
Hint: look for "private copy constructor" or something like that, on the net. Or in a a VERY good book.
2d) I have at least one pointer in my BaseOne and BaseTwo classes, but I left the destructors empty. Why?
Hint: He who creates, destroys.
2e) Look at the code:
"void SetIface(ISomeInterface* iface) { delete IFace; IFace = iface;}"
What is the "delete" operator doing there? It deletes, I know. But why there, just before IFACE receives a new value?
Hint: Potantial leak somehow?
3) Your task (very important!)
- Derrive two classes from ISomeInterface.
- Make ISomeInterFace an 'abstract' class.
Hint: make this a PURE VIRTUAL FUNCTION:
void SetIface(ISomeInterface* iface) { delete IFace; IFace = iface;}
You know how to do that? You know what that means for your two derrived classes?
- In main() : Instead of 'plugging' an instance of ISomeInterFace in BaseOne (or BaseTwo), plug a derrived class from ISomeInterface in BaseOne or Base two.
4) Do you know what you were doing?
Hint:
- You made two machines (BaseOne and BaseTwo). They achieve the same thing but do it differently.
- You made two modules (the two derrived classes from ISomeInterface) for these machines. For example you can put DerrivedIFace_1 OR DerrivedIFace_2 in an instance of BaseOne. You can plug it in.
MORE HINTS:
- BaseOne is a vehicle in a game. (game, hint hint).
- BaseTwo is another vehicle in a game. Perhaps a vehicle with more weapons.
- "DerrivedIFace_1 : ISomeInterFace" ( our first derrived class) is a certain strategy. We can load it in one of or both the types of vehicles. For example, let a vehicle play cautiously. Or load "DerrivedIFace_2 : ISomeInterFace" in one or both the types of vehicles (BaseOne and BaseTwo, remember?) so they play more agressivly.
5) Do you realize that BaseOne and BaseTWo (our different fight-vehicles) only know they can receive modules of "ISomeInterface". The fight-vehicles don't know anything about possible strategies they gonna get (DerrivedIFace_2, ... ). Can you explain that to your self and others why?
6) Do you realize the Interface classes don't know anythihg at all? They are a completely "stand-alone" items. That is OO. Can you convine yourself?
7) You want 10 types of fight-vehicles instead of only two. Perhaps one is slow and weak and cheap. The best one is fast and powerfull and expensive. How you gonna solve this the OO-way?
Hint:
- Rename our BaseOne and BaseTwo to "DerrivedOne" and "DerrivedTwo".
- Make a baseclass called "Base". Make it an abstract base class for
DerrivedOne and DerrivedTwo. Or in other words, make sure DerrivedOne and DerrivedTwo are derrived from abstract class "Base".
- Now what you have to do is implement a typical "void Print()" method for DerrivedOne and DerrivedTwo, AND one for class "Base". So base hold the pure virtual method: "virtual void Print() = 0;"
And DerrivedOne holds "virtual void Print() { cout<<"Cheap Vehicle attacks!!!<<endl;}"
Don't forget to make another one for DerrivedTwo...

Now I want you to make a thing happen like this:
int main()
{
DerrivedIFace_1 IF_1; //get a strategy ready
DerrivedTwo DT; //get a fight-vehicle ready
Base* B = DT; //Load an abstract vehicle with a fight-vehicle (see line below)
B->Print( & IF_1 ) // Attaaack (Print) with strategy IF_1!
}

See what I am getting at? This is real OO. Not what is described in the beginner books or intermedate books.
Make sure you can do the task I given to you. It is the very very very basics of OO. But if you can do it with my code, then you rock and are ready to move on. Just find a way to test your code.

Good luck!
- Val -
__________________
Valmont is offline   Reply With Quote
Old 12-31-2003, 09:13 AM   #27 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Oh by the way, I just tested this code on Visual C++ 6 sp5.
It works great so good luck and watch the typos, etc.
__________________
Valmont is offline   Reply With Quote
Old 12-31-2003, 10:25 AM   #28 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Here, nock yourself out. Same idea, but with sorting algorithms.
Here are the analogies (comparisons):

- Class Sorter: an abstract vehicle. So you can also define medical and transport vehicles instead of only fight-vehicles.
- Class BubbleSorter (derrived): Cheap attack vehicle.
- Class CombSorter (derrived). Expenise but fast attack vehicle.

- Class SortHandle: All kinds of Strategies.
- Class ArraySortHandle (derrived) : Various Attack Strategies.
- Class DescendSortHandle(derrived from derrived): Our first attack strategy-> "Aim low when shooting".
- Class AscendSortHandle(derrived from derrived): Our second attack strategy-> "Aim high when shooting".


Analyze well and do the tasks with the previous codes I gave to you. Don't touch this one. Just run it and observe.
Code:
 
//**** StrategyPatternNeatSample.cpp : Entry point for this app.

#include"Sorter.h"
#include "BubbleSorter.h"
#include "CombSorter.h"
#include "AscendSortHandle.h"
#include "DescendSortHandle.h"

#include <iostream>
#include <string>

using namespace std;

string sLeaderTypes[7]={ "President", "Queen", "Warlord", "Ceasar",
                         "Minister", "Emperor", "Archduke"};

int elements = sizeof sLeaderTypes / sizeof *sLeaderTypes;

void Print(string* array, int size)
{
	for(int i=0 ; i< size ; ++i)
		cout<<array[i]<<endl;
}
void SortAndPrint(Sorter* sorter, SortHandle* handle)
{
	sorter->Sort(handle);
	Print(sLeaderTypes, elements);
	cout << endl;
}

int main()
{
    AscendSortHandle<string>  ascendHandle(sLeaderTypes, elements);
    DescendSortHandle<string> descendHandle(sLeaderTypes, elements);

    BubbleSorter bSort;
    CombSorter   cmbSort;

    cout << "*** Ascending Bubble Sort ***\n\n";
    SortAndPrint(&bSort, &ascendHandle);

    cout << "\n\n*** Descending Comb Sort ***\n" << endl;
    SortAndPrint(&cmbSort, &descendHandle);

    return EXIT_SUCCESS;
}

//**** Sorter.h ****

#include "SortHandle.h"

class Sorter
{
public:
	virtual void Sort(SortHandle*) = 0;
};

//**** BubbleSorter.h ****


class BubbleSorter : public Sorter
{
public:
	BubbleSorter() {}
	virtual ~BubbleSorter() {}

public:
	void Sort(SortHandle* sortHandle)
    {
		int size = sortHandle->GetSize();
		for(int i = size; i>=0; --i)
		{
			for(int j= 0 ; j<size-1 ; j++)
			{
				if( sortHandle->OutOfOrder(j, j+1) )
					sortHandle->Swap(j,j+1);
			}
		}
	}
};


//**** CombSorter.h ****

class CombSorter : public Sorter
{
public:
	CombSorter() {}
	virtual ~CombSorter() {}
	
	void Sort(SortHandle* sortHandle)
	{
		int size = sortHandle->GetSize();
		int gap = size;
		for (;;)
		{
			gap = NewGap(gap);
			bool swapped = false;
			for(int j= 0 ; j<size-gap ; j++)
				if( sortHandle->OutOfOrder(j, j+gap))
				{
					sortHandle->Swap(j,j+gap);
					swapped = true;
				}
				if(gap == 1 && !swapped)
					break;
		}
	}

	static int NewGap(int gap)
	{
		gap = (gap * 10) / 13;
		if (gap == 9 || gap == 10)
			gap = 11;
		if (gap < 1)
			gap = 1;
		return gap;
	}
};



// **** SortHandle.h ****

#ifndef SORTHANDLE_H
#define SORTHANDLE_H


class SortHandle
{
public:
	virtual void Swap(int i, int j) = 0;
	virtual bool OutOfOrder(int i, int j) = 0;
	virtual int  GetSize() = 0;
};

#endif // SORTHANDLE_H

//**** ArraySortHandle.h ****

#ifndef ARRAYSORTHANDLE_H
#define ARRAYSORTHANDLE_H


#include "SortHandle.h"

template<class T> class ArraySortHandle : public SortHandle
{
protected:
	ArraySortHandle(T* array, int elements) 
		: itsArray(array), itsElements(elements) {}
	virtual int GetSize(){ return itsElements; }
	virtual void Swap(int i, int j)
	{
		T tmp = itsArray[i];
		itsArray[i]=itsArray[j];
		itsArray[j]=tmp;
	}
	T* itsArray;
	int itsElements;
};

#endif //ARRAYSORTHANDLE_H

//**** DescendSortHandle.h ****

#include "ArraySortHandle.h"

template<class T> class DescendSortHandle : public ArraySortHandle<T>
{
public:
    DescendSortHandle(T* array, int elements)
			: ArraySortHandle<T>(array, elements) {}
		
public:
		virtual bool OutOfOrder(int i, int j) { return itsArray[i]<itsArray[j]; }
		
};

//**** AscendSortHandle.h ****

#include "ArraySortHandle.h"

template<class T> class AscendSortHandle : public ArraySortHandle<T>
{
public:
	AscendSortHandle(T* array, int elements)
		: ArraySortHandle<T>(array, elements) {}
	virtual bool OutOfOrder(int i, int j){ return itsArray[i]>itsArray[j]; }	
};
Remember, you don't need templates. I used templates so my code can sort any sortable type.
You only need to let your vehicles print out that they are attacking. Nothing more.

Now I am really tired and its time I go (party).

Good luck!

P.S.
This type of OO implementation is called the Strategy Pattern.
What a coincidence huh?
__________________
Valmont is offline   Reply With Quote
Old 12-31-2003, 11:07 AM   #29 (permalink)
L06@N
Registered User
 
L06@N's Avatar
 
Join Date: Dec 2003
Location: Nebraska, USA
Posts: 17
L06@N is on a distinguished road
I'll read through this more after I get time (am at work).
I just wanted to get on and atleast sneak a "thanks!" in there before you left for a while (hopefully before).
L06@N is offline   Reply With Quote
Old 01-04-2004, 10:43 PM   #30 (permalink)
Pizzaman
Registered User
 
Join Date: Sep 2003
Posts: 8
Pizzaman is on a distinguished road
Tricks of the 3D Game Programming Gurus-Advanced 3D Graphics and Rasterization

That book is really really hardcore. I wouldn't suggest it unless you are pretty good at doing the 2D rasterization and things in the other book I mentioned by the same author. But if you want to keep it around, go for it.


*edit* Whoa,... I just noticed the major amount of code that was posted previously.

Also this link would be useful

www.gamedev.net

-Pizzaman
Pizzaman is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Engine Submittions Eyelfixit Lounge 12 07-25-2003 08:09 PM
Patch Engine mozza Standard C, C++ 1 07-12-2003 11:52 PM
Please Review ZapMeta - New Search Engine khn Program Design and Methods 3 07-06-2003 09:15 AM


All times are GMT -8. The time now is 11:57 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting