00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <iostream>
00013 #include <irrlicht.h>
00014 #include <strings.h>
00015 #include <sstream>
00016 #include <time.h>
00017
00018 #include "IrrLib.h"
00019
00020
00021 #include "IrrColor.h"
00022
00023
00024 using namespace irr;
00025 using namespace core;
00026 using namespace scene;
00027 using namespace video;
00028 using namespace io;
00029 using namespace gui;
00030
00031 using namespace std;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 IrrLib::IrrLib(){
00042 this->device = createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16, false, false, false, &this->IrrEvent);
00043 if (this->device == 0)
00044 exit(1);
00045 IrrLib::Init();
00046 }
00047
00048 IrrLib::IrrLib(video::E_DRIVER_TYPE drivertype, core::dimension2d<s32> & res, u32 bits, bool fullscreen, bool stencilbuffer, bool vsync){
00049
00050 this->device = createDevice(drivertype, res, bits, fullscreen, stencilbuffer, vsync, &this->IrrEvent);
00051 if (this->device == 0)
00052 exit(1);
00053 IrrLib::Init();
00054 }
00055
00056 IrrLib::IrrLib(int nDrivertype, int width, int height, int bits, bool fullscreen, bool stencilbuffer, bool vsync){
00057
00058 video::E_DRIVER_TYPE drivertype;
00059 switch (nDrivertype){
00060 case 0:
00061 drivertype = EDT_NULL;
00062 break;
00063 case 1:
00064 drivertype = EDT_SOFTWARE;
00065 break;
00066 case 2:
00067 drivertype = EDT_BURNINGSVIDEO;
00068 break;
00069 case 3:
00070 drivertype = EDT_OPENGL;
00071 break;
00072 case 4:
00073 drivertype = EDT_DIRECT3D8;
00074
00075
00076
00077 break;
00078 case 5:
00079 drivertype = EDT_DIRECT3D9;
00080 break;
00081 default:
00082 drivertype = EDT_SOFTWARE;
00083 break;
00084 }
00085 this->device = createDevice(drivertype, dimension2d<s32>(width, height), bits, fullscreen, stencilbuffer, vsync, &this->IrrEvent);
00086 if (this->device == 0)
00087 exit(1);
00088 IrrLib::Init();
00089 }
00090
00091 IrrLib::~IrrLib (){
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 }
00105
00106 void IrrLib::Init(){
00107
00108
00109
00110 this->env = this->device->getGUIEnvironment();
00111 this->driver = this->device->getVideoDriver();
00112 this->smgr = this->device->getSceneManager();
00113 Irr3DLib.SetSmgr(this->smgr);
00114 Irr3DLib.SetDriver(this->driver);
00115 Irr2DLib.SetSmgr(this->smgr);
00116 Irr2DLib.SetDriver(this->driver);
00117 GUI.SetEnv(this->env);
00118 IrrEvent.SetDevice(this->device);
00119 this->timer = this->device->getTimer();
00120 tick = this->timer->getRealTime();
00121 }
00122
00123 void IrrLib::ReadArchive(stringc file){
00124 this->device->getFileSystem()->addZipFileArchive(file.c_str());
00125 }
00126
00127 void IrrLib::LoadQ3Level(stringc q3level){
00128 this->mesh = this->smgr->getMesh(q3level.c_str());
00129 this->node = 0;
00130 if (this->mesh)
00131 this->node = this->smgr->addOctTreeSceneNode(this->mesh->getMesh(0), 0, -1, 128);
00132 }
00133
00134 void IrrLib::MapPos(int x, int y, int z){
00135 if (this->node)
00136 this->node->setPosition(core::vector3df(x, y, z));
00137 }
00138
00139 void IrrLib::MapPos(){
00140 if (this->node)
00141 this->node->setPosition(core::vector3df(0, 0, 0));
00142 }
00143
00144 void IrrLib::AddFPSCam(){
00145 this->cam = this->smgr->addCameraSceneNodeFPS();
00146 }
00147
00148 void IrrLib::AddFPSCam(f32 x, f32 y, f32 z)
00149 {
00150 this->cam = this->smgr->addCameraSceneNodeFPS();
00151 this->cam->setPosition(irr::core::vector3df(x, y, z));
00152 }
00153
00154 void IrrLib::VisibleCursor(bool tf){
00155 if (tf == false)
00156 this->device->getCursorControl()->setVisible(false);
00157 else
00158 this->device->getCursorControl()->setVisible(true);
00159 }
00160
00161 int IrrLib::GetFPSCount(){
00162 return this->driver->getFPS();
00163 }
00164
00165 bool IrrLib::DeviceIsRunning(){
00166 return this->device->run();
00167 }
00168
00169 bool IrrLib::IsActiveWindow(){
00170 return this->device->isWindowActive();
00171 }
00172
00173 void IrrLib::BeginScene(){
00174 this->driver->beginScene(true, true, video::SColor(0,200,200,200));
00175 }
00176
00177 void IrrLib::BeginScene(const irr::video::SColor& color){
00178 this->driver->beginScene(true, true, color);
00179 }
00180
00181 void IrrLib::BeginScene(bool usebackBuffer, bool usezBuffer, irr::video::SColor color){
00182 this->driver->beginScene(usebackBuffer, usezBuffer, color);
00183 }
00184
00185 void IrrLib::DrawAll(){
00186
00187
00188
00189
00190 this->smgr->drawAll();
00191 this->env->drawAll();
00192
00193 }
00194
00195 void IrrLib::EndScene(){
00196 this->driver->endScene();
00197 }
00198
00199 void IrrLib::SetWindowCaption(stringw str){
00200 this->device->setWindowCaption(str.c_str());
00201 }
00202
00203 irr::core::stringw IrrLib::GetDriverName(){
00204 return this->driver->getName();
00205 }
00206
00207 void IrrLib::EndIrrlicht(){
00208 if(this->device != NULL){
00209 this->device->drop();
00210 this->device = NULL;
00211 }
00212 }
00213
00214 void IrrLib::KeyPress(char key){
00215 this->key = key;
00216 }
00217
00218 char IrrLib::KeyPressed(){
00219 return key;
00220 }
00221
00222 irr::f32 IrrLib::getX(){
00223 return this->smgr->getActiveCamera()->getPosition().X;
00224 }
00225
00226 irr::f32 IrrLib::getY(){
00227 return this->smgr->getActiveCamera()->getPosition().Y;
00228 }
00229
00230 irr::f32 IrrLib::getZ(){
00231 return this->smgr->getActiveCamera()->getPosition().Z;
00232 }
00233
00234 bool IrrLib::CheckGameLoop(){
00235 u32 now;
00236 now = this->timer->getRealTime();
00237 if ((now - this->tick) >= 30){
00238
00239 return true;
00240 } else {
00241 return false;
00242 }
00243 }
00244
00245 bool IrrLib::CheckGameLoop(u32 ms){
00246 u32 now;
00247 now = this->timer->getRealTime();
00248 if ((now - this->tick) >= ms){
00249 this->tick = now;
00250 return true;
00251 } else {
00252 return false;
00253 }
00254 }
00255
00256 void IrrLib::Exit()
00257 {
00258 this->device->closeDevice();
00259 }
00260
00261 PixelSize IrrLib::GetScreenSize()
00262 {
00263 return this->driver->getScreenSize();
00264
00265
00266
00267
00268
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278