is it possable to make say
smgr = device->getSceneManager();
a global variable so that it can be declared once like say in your main.cpp and called from any other class or node or source file simply by doing something like:
smgr->addWhatEverNode(
stuff->getThis(..//stuff to get),
thing->doThis(..//Thingtodo);
or is this a RTFM on my part?
can this be done?
-
- Posts: 156
- Joined: Wed Jul 21, 2004 4:29 am
- Location: Mishawaka, In
-
- Posts: 156
- Joined: Wed Jul 21, 2004 4:29 am
- Location: Mishawaka, In
yep ...brain left me again on that one.
i think i suffered a minor malfunction of the cerebral cortex on that one.....
or perhaps it was just a dumb attack!
anyhow i knew that but thanks,,, just goes to show kids,,,,,,dont code when ur high lol....
or perhaps it was just a dumb attack!
anyhow i knew that but thanks,,, just goes to show kids,,,,,,dont code when ur high lol....
-
- Posts: 63
- Joined: Thu Aug 05, 2004 9:40 am
- Location: Germany
Hi,
I use this base class:
Has someone tried another approach?
I use this base class:
Code: Select all
class Constants
{
public:
Constants(irr::IrrlichtDevice* Device) : device(Device)
{
drvr = device->getVideoDriver();
smgr = device->getSceneManager();
};
irr::IrrlichtDevice* device;
irr::video::IVideoDriver* drvr;
irr::scene::ISceneManager* smgr;
};
That's pretty much what I do.
I have a class called CHub that holds references to all the parts of my game, the Irrlicht device + other parts, the Raknet device, the Audiere device, the inventory handler, the player handler, the game states, etc...
However, I use it as a single instance...
(excess code removed)
Hub.h:
Hub.cpp
Then, all I need in any other class to have access to the hub is to:
CHub* hub = CHub::getInstance();
The class will instantiate once and every class in your application can share it.
I have a class called CHub that holds references to all the parts of my game, the Irrlicht device + other parts, the Raknet device, the Audiere device, the inventory handler, the player handler, the game states, etc...
However, I use it as a single instance...
(excess code removed)
Hub.h:
Code: Select all
#pragma once
class CHub
{
private:
static bool instanceFlag;
static CHub *hub_mgr;
public:
static CHub* getInstance();
//!Global Variables
irr::IrrlichtDevice* irr_device;
irr::video::IVideoDriver* video_driver;
//!Scene Management
irr::gui::IGUIEnvironment* gui_env;
irr::scene::ISceneManager* scene_mgr;
StateManager* state_mgr;
};
Code: Select all
#include "Hub.h"
bool CHub::instanceFlag = false;
CHub* CHub::hub_mgr = NULL;
/*******************************************************************************
Constructor
*******************************************************************************/
CHub::CHub(void)
{
//!Initialize Irrlicht
device = irr::createDevice(irr::video::EDT_DIRECTX8, irr::core::dimension2d<irr::s32>(1024, 768), 32, false, false, this);
video_driver = device->getVideoDriver();
scene_mgr = device->getSceneManager();
gui_env = device->getGUIEnvironment();
}
/*******************************************************************************
Get an Instance
*******************************************************************************/
CHub* CHub::getInstance()
{
if(! instanceFlag)
{
hub_mgr = new CHub();
instanceFlag = true;
return hub_mgr;
}
else
{
return hub_mgr;
}
}
/*******************************************************************************
Destructor
*******************************************************************************/
CHub::~CHub(void)
{
instanceFlag = false;
device->drop();
}
CHub* hub = CHub::getInstance();
The class will instantiate once and every class in your application can share it.
Last edited by saigumi on Thu Aug 05, 2004 5:16 pm, edited 1 time in total.
Crud, how do I do this again?
-
- Posts: 63
- Joined: Thu Aug 05, 2004 9:40 am
- Location: Germany