OOp structure[Solved]
-
saltytaco1234
- Posts: 20
- Joined: Wed Dec 15, 2010 10:39 pm
OOp structure[Solved]
I tried searching this but couldn't find any good information. What I'm trying to do is make a class for each part. Like Player.h, Core.h, etc. But how would I allow the same device, scenemanger, GUiManager, etc. interact with each class. I'm kind of blind at this part. What I'm asking is, is how to make global pointers that can be used by different classes. Would Inherit each class from another?
Last edited by saltytaco1234 on Tue Jun 28, 2011 5:03 pm, edited 1 time in total.
Not trying to be rude, but:
*taken from old thread*
*And back on topic*
What I did in my framework was that I wrote a "Game" class or you can call it "Core" or w/e you like and stored the pointers to important stuff there. If other classes need to access any of those pointers it just takes the "Game" pointer to its constructor and stores it. Then it can get any of the important pointers and use them.
*taken from old thread*
What were you doing those 5 years??I am looking to join a game development team, to further progress my skills.
Primary Role: Porgrammer
Secondary Role: Modeling
Age:15
Game: Any game
Irrlicht experience: 1 1/2 years.
C++ Experience: 5 years
*And back on topic*
What I did in my framework was that I wrote a "Game" class or you can call it "Core" or w/e you like and stored the pointers to important stuff there. If other classes need to access any of those pointers it just takes the "Game" pointer to its constructor and stores it. Then it can get any of the important pointers and use them.
Working on game: Marrbles (Currently stopped).
-
saltytaco1234
- Posts: 20
- Joined: Wed Dec 15, 2010 10:39 pm
You should read these tutorials http://www.learncpp.com/ carefully and try to understand them - play around by modifying them, make something with the knowledge the tutorials gave you.
These tutorials however are only the basics to get you started. After that you will need to learn to design the stuff you're going to program as having no design proved to cause real headaches when you see that you're heading to a dead end.
These tutorials however are only the basics to get you started. After that you will need to learn to design the stuff you're going to program as having no design proved to cause real headaches when you see that you're heading to a dead end.
Working on game: Marrbles (Currently stopped).
-
saltytaco1234
- Posts: 20
- Joined: Wed Dec 15, 2010 10:39 pm
Would this work?
Code: Select all
class Game
{
public:
Game (IrrlichtDevice *device)
{
this->device = device;
this->driver = device->getVideoDriver();
this->env = device->getGUIEnvironment();
this->smgr = device->getSceneManager();
}
~Game ()
{}
protected:
IrrlichtDevice *device;
IGUIEnvironment *env;
IVideoDriver *driver;
ISceneManager *smgr;
}; Code: Select all
#include "Game.h" or "includes.h"
class MyClass : public Game
{
public:
MyClass(IrrlichtDevice *device) : Game(device)
{}
};
-
Radikalizm
- Posts: 1215
- Joined: Tue Jan 09, 2007 7:03 pm
- Location: Leuven, Belgium
Not how I mean't.
You should have something like:
And when you create MyClass you would pass the Game class pointer into constructor. Then you would be able to use m_Game in MyClass to access all the things you might need.
And again I must say that you have to read those tutorials or other sites that cover those topics to know how to deal with these kind of things.
Also I've heard that this book is good http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html but I still haven't found the time to take a look.
You should have something like:
Code: Select all
#include "Game.h" or "includes.h"
class MyClass
{
public:
MyClass(Game *game) : m_Game(game)
{}
protected:
Game * m_Game;
};
And again I must say that you have to read those tutorials or other sites that cover those topics to know how to deal with these kind of things.
Also I've heard that this book is good http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html but I still haven't found the time to take a look.
Working on game: Marrbles (Currently stopped).
-
Radikalizm
- Posts: 1215
- Joined: Tue Jan 09, 2007 7:03 pm
- Location: Leuven, Belgium
I have Bruce Eckel's Thinking in Java as a reference for my java work, and it's a very excellent book, so I assume that this one would be rather good tooserengeor wrote:Also I've heard that this book is good http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html but I still haven't found the time to take a look.
Well I've just read first few pages and I really liked it!Radikalizm wrote:I have Bruce Eckel's Thinking in Java as a reference for my java work, and it's a very excellent book, so I assume that this one would be rather good tooserengeor wrote:Also I've heard that this book is good http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html but I still haven't found the time to take a look.
At first I was afraid to look at it because I taught I might just see some hieroglyphs, but it turned out to be an easy to follow english text even though now its a bit late (01:30~)
Working on game: Marrbles (Currently stopped).
-
saltytaco1234
- Posts: 20
- Joined: Wed Dec 15, 2010 10:39 pm
My mom is ordering the book, as it looks really nice. ^^ Thanks, for the help and the book suggestion.serengeor wrote:Well I've just read first few pages and I really liked it!Radikalizm wrote:I have Bruce Eckel's Thinking in Java as a reference for my java work, and it's a very excellent book, so I assume that this one would be rather good tooserengeor wrote:Also I've heard that this book is good http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html but I still haven't found the time to take a look.
At first I was afraid to look at it because I taught I might just see some hieroglyphs, but it turned out to be an easy to follow english text even though now its a bit late (01:30~)
It's a good way to store all the stuff that's needed anywhere in your project and to make sure it's not instanced more than once. -> IrrlichtDevice and its frequently used chaps.serengeor wrote:My first attempts were using singleton pattern, but later on I got rid of it. It just didn't feel right for me
@saltytaco1234: Have you looked at online version(it's free)?
That way you get rid of passing IrrDev, SMgr and the like to every class' constructor and just take it wherever you'd need it.
beer->setMotivationCallback(this);
Re:
Well I was doing the "just take it wherever you'd need it" part and it looked a bit dirty for me, so I decided I should just pass the pointer to the main class that holds pointers to other classes (like device,physics manager and etc.) to whoever needs it.polylux wrote:It's a good way to store all the stuff that's needed anywhere in your project and to make sure it's not instanced more than once. -> IrrlichtDevice and its frequently used chaps.serengeor wrote:My first attempts were using singleton pattern, but later on I got rid of it. It just didn't feel right for me
@saltytaco1234: Have you looked at online version(it's free)?
That way you get rid of passing IrrDev, SMgr and the like to every class' constructor and just take it wherever you'd need it.
Though maybe using it for this purpose is not that bad
Working on game: Marrbles (Currently stopped).
