/* Irrlicht Library Wrapper Created by: Nathan Adams Denzel Morris Copyright (C) 2007 This software is licensed under the GNU/GPL. This software may not be used for commerical purposes. */ #include #include #include #include #include #include "IrrLib.h" //Libraries we create go here //#include "IrrSphere.h" #include "IrrColor.h" //#include "Irr2D.h" using namespace irr; using namespace core; using namespace scene; using namespace video; using namespace io; using namespace gui; using namespace std; //TODO: Create own class for handling inputs! /*IrrLib::IrrLib(MastEventReceiver & receiver){ this->device = createDevice(EDT_SOFTWARE, dimension2d(640, 480), 16, false, false, false, &receiver); if (this->device == 0) exit(1); IrrLib::Init(); }*/ IrrLib::IrrLib(){ this->device = createDevice(EDT_SOFTWARE, dimension2d(640, 480), 16, false, false, false, &this->IrrEvent); if (this->device == 0) exit(1); IrrLib::Init(); } IrrLib::IrrLib(video::E_DRIVER_TYPE drivertype, core::dimension2d & res, u32 bits, bool fullscreen, bool stencilbuffer, bool vsync){ //MyEventReceiver receiver; this->device = createDevice(drivertype, res, bits, fullscreen, stencilbuffer, vsync, &this->IrrEvent); if (this->device == 0) exit(1); IrrLib::Init(); } IrrLib::IrrLib(int nDrivertype, int width, int height, int bits, bool fullscreen, bool stencilbuffer, bool vsync){ //MyEventReceiver receiver; video::E_DRIVER_TYPE drivertype; switch (nDrivertype){ case 0: //TODO: finish this switch case drivertype = EDT_NULL; break; case 1: drivertype = EDT_SOFTWARE; break; case 2: drivertype = EDT_BURNINGSVIDEO; break; case 3: drivertype = EDT_OPENGL; break; case 4: drivertype = EDT_DIRECT3D8; //*Note: It seems as Microsoft has stoped supporting DX 8.1, so you can not compile it into Irrlicht engine anymore //TODO: Find how to detect if DX is complied into Irrlicht //TODO: Find how to detecht for linux break; case 5: drivertype = EDT_DIRECT3D9; break; default: drivertype = EDT_SOFTWARE; break; } this->device = createDevice(drivertype, dimension2d(width, height), bits, fullscreen, stencilbuffer, vsync, &this->IrrEvent); if (this->device == 0) exit(1); IrrLib::Init(); } IrrLib::~IrrLib (){ //Our moms wont clean up after us! //Although I'm sure Irrlicht does this for us already, its always a good idea to check! /*if (this->device != NULL) delete this->device; if (this->driver != NULL) delete this->driver; if (this->smgr != NULL) delete this->smgr; if (this->mesh != NULL) delete this->mesh; if (this->node != NULL) delete this->node;*/ //it seems Irrlicht picks up after us... //however we created newNodes, now we need to delete it! } void IrrLib::Init(){ //this->numNodes = 0; //this->nodeNew = new ISceneNode[10]; //this->env->addStaticText(L"Transparent Control:", rect(20,30,300,80), true); this->env = this->device->getGUIEnvironment(); this->driver = this->device->getVideoDriver(); this->smgr = this->device->getSceneManager(); Irr3DLib.SetSmgr(this->smgr); Irr3DLib.SetDriver(this->driver); Irr2DLib.SetSmgr(this->smgr); Irr2DLib.SetDriver(this->driver); GUI.SetEnv(this->env); IrrEvent.SetDevice(this->device); this->timer = this->device->getTimer(); tick = this->timer->getRealTime(); } void IrrLib::ReadArchive(std::string file){ this->device->getFileSystem()->addZipFileArchive(file.c_str()); } void IrrLib::LoadQ3Level(std::string q3level){ this->mesh = this->smgr->getMesh(q3level.c_str()); this->node = 0; if (this->mesh) this->node = this->smgr->addOctTreeSceneNode(this->mesh->getMesh(0), 0, -1, 128); } void IrrLib::MapPos(int x, int y, int z){ if (this->node) this->node->setPosition(core::vector3df(x, y, z)); } void IrrLib::MapPos(){ if (this->node) this->node->setPosition(core::vector3df(0, 0, 0)); } void IrrLib::AddFPSCam(){ this->cam = this->smgr->addCameraSceneNodeFPS(); } void IrrLib::AddFPSCam(f32 x, f32 y, f32 z) { this->cam = this->smgr->addCameraSceneNodeFPS(); this->cam->setPosition(irr::core::vector3df(x, y, z)); } void IrrLib::VisibleCursor(bool tf){ if (tf == false) this->device->getCursorControl()->setVisible(false); else this->device->getCursorControl()->setVisible(true); } int IrrLib::GetFPSCount(){ return this->driver->getFPS(); } bool IrrLib::DeviceIsRunning(){ return this->device->run(); } bool IrrLib::IsActiveWindow(){ return this->device->isWindowActive(); } void IrrLib::BeginScene(){ this->driver->beginScene(true, true, video::SColor(0,200,200,200)); } void IrrLib::BeginScene(irr::video::SColor color){ this->driver->beginScene(true, true, color); } void IrrLib::BeginScene(bool usebackBuffer, bool usezBuffer, irr::video::SColor color){ this->driver->beginScene(usebackBuffer, usezBuffer, color); } void IrrLib::DrawAll(){ this->smgr->drawAll(); this->env->drawAll(); //this->device->getGUIEnvironment()->drawAll(); } void IrrLib::EndScene(){ this->driver->endScene(); } void IrrLib::SetWindowCaption(stringw str){ this->device->setWindowCaption(str.c_str()); } irr::core::stringw IrrLib::GetDriverName(){ return this->driver->getName(); } void IrrLib::EndIrrlicht(){ if(this->device != NULL){ this->device->drop(); this->device = NULL; } } void IrrLib::KeyPress(char key){ this->key = key; } char IrrLib::KeyPressed(){ return key; } irr::f32 IrrLib::getX(){ return this->smgr->getActiveCamera()->getPosition().X; } irr::f32 IrrLib::getY(){ return this->smgr->getActiveCamera()->getPosition().Y; } irr::f32 IrrLib::getZ(){ return this->smgr->getActiveCamera()->getPosition().Z; } bool IrrLib::CheckGameLoop(){ u32 now; now = this->timer->getRealTime(); if ((now - this->tick) >= 30){ //this->tick == time (NULL); return true; } else { return false; } } bool IrrLib::CheckGameLoop(u32 ms){ u32 now; now = this->timer->getRealTime(); if ((now - this->tick) >= ms){ this->tick = now; return true; } else { return false; } } void IrrLib::Exit() { this->device->closeDevice(); } //template std::string IrrLib::to_string (T t) /*std::string IrrLib::int_to_string (int t) { std::stringstream ss; ss << t; return ss.str(); }*/ // This is in the base class now, every class that decends from that class has this ability.