bool Application::run(){ if(!device) return false; ITimer* irrTimer = device->getTimer(); u32 TimeStamp = irrTimer->getTime(), DeltaTime = 0; while(device->run() && driver){ DeltaTime = irrTimer->getTime() - TimeStamp; TimeStamp = irrTimer->getTime(); this->updateTitle(); if(device->isWindowActive()){ driver->beginScene(true, true, video::SColor(255,100,100,100)); smgr->drawAll(); device->getGUIEnvironment()->drawAll(); driver->endScene(); } if(scene) scene->update(DeltaTime, state); if(state != oldState) loadLevel(); } return true; }
///@brief bool dbLoopGDK() { dbPRINT("dbLoopGDK()\n"); DarkGDK_SGlobalStruct& app = DarkGDK_SGlobalStruct::getInstance(); IrrlichtDevice* device = app.Device; if (!device) return false; /// empty irrlicht message loop if (!device->run()) return false; ITimer* timer = device->getTimer(); /// get current time app.Time_Now = timer->getTime(); if (app.Time_Now >= app.Time_Last + 1000 ) { app.FPS_Now = app.FPS_Count; app.FPS_Count = 0; if (app.FPS_Min > app.FPS_Now) app.FPS_Min = app.FPS_Now; if (app.FPS_Max < app.FPS_Now) app.FPS_Max = app.FPS_Now; app.Time_Last = timer->getTime(); } video::IVideoDriver* driver = device->getVideoDriver(); /// check resize-event if ( app.ScreenSize != driver->getScreenSize() ) { app.ScreenSize = driver->getScreenSize(); app.ScreenRect = core::recti( 0, 0, app.ScreenSize.Width-1, app.ScreenSize.Height-1); driver->OnResize( app.ScreenSize ); /// resize aspect ratio of current active camera scene::ISceneManager* smgr = device->getSceneManager(); scene::ICameraSceneNode* camera = smgr->getActiveCamera(); if ( camera ) { app.CurrentCamera = camera; camera->setAspectRatio( (f32)app.ScreenSize.Width / (f32)app.ScreenSize.Width ); } } return true; }
int main() { // Event Receiver // ====================================================== MyEventReceiver receiver; // get Screen resolution // =============================================== //create a NULL device to detect screen resolution IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL); core::dimension2d<u32> deskRes = nulldevice->getVideoModeList()->getDesktopResolution(); nulldevice->drop(); // Create device // ======================================================= IrrlichtDevice *device; //1366, 768 //1024, 600 int FullScreen = 1; if (FullScreen == 1) { device = createDevice(video::EDT_DIRECT3D9, deskRes, 32, true, false, true, &receiver); } else { device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<u32>(800, 600), 32, false, false, true, &receiver); } // Get a pointers // ====================================================== video::IVideoDriver* driver = device->getVideoDriver(); scene::ISceneManager* smgr = device->getSceneManager(); gui::IGUIEnvironment* guienv = device->getGUIEnvironment(); // Disable mip maps // ===================================================== //driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); // Image // ================================================================ video::ITexture* controlsPic = driver->getTexture("./media/Controls.png"); video::ITexture* irrlichtLogo = driver->getTexture("./media/irrlichtlogo2.png"); // Terrain // ============================================================== scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("./media/heightmap3.jpg", 0, -1, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0), core::vector3df(1, 1, 1)); if (terrain) { terrain->setID(NotPickable); terrain->setScale(core::vector3df(1.0f, 0.5f, 1.0f)); //terrain->setPosition(core::vector3df(0, 0, 0)); terrain->setMaterialFlag(video::EMF_LIGHTING, false); terrain->setMaterialTexture(0, driver->getTexture("./media/terrainTexture2.jpg")); } // Box // ================================================================== scene::ISceneNode* box = smgr->addCubeSceneNode(); box->setMaterialTexture(0, driver->getTexture("./media/redPixel.bmp")); box->setMaterialFlag(video::EMF_LIGHTING, false); box->setScale(core::vector3df(5, 5, 5)); box->setPosition(core::vector3df(-500, 1000, -500)); //box->setScale(core::vector3df(1, 2, 1)); // light // ================================================================ scene::ILightSceneNode* lightSun1 = smgr->addLightSceneNode(0, core::vector3df(812, terrain->getHeight(812, 812) + 812, 812), video::SColorf(1, 1, 0.94f, 1), 5000.0f); // ========================================================================= device->getCursorControl()->setVisible(false); // display frames per second // ============================================ int fps; int lastFPS = -1; gui::IGUIStaticText* guiText = guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!", core::rect<s32>(10, 200, 100, 222), true); core::stringw str; // Frame rate independence // ============================================== u32 then = device->getTimer()->getTime(); u32 now; f32 tempT; f32 deltaTime; ITimer* Timer = device->getTimer(); // Action // =============================================================== Action Act(&receiver, device, terrain, &deltaTime); while (device->run()) { if (device->isWindowActive()) { // Frame rate independence // ========================================== now = Timer->getTime(); tempT = (f32)(now - then); deltaTime = (f32)(((tempT) < 60) ? tempT : 60); then = now; // ===================================================================== Act.update(); // Draw Scene // ======================================================= driver->beginScene(true, true, video::SColor(255, 100, 101, 140)); smgr->drawAll(); guienv->drawAll(); driver->draw2DImage(controlsPic, core::rect<s32>(10, 10, 200, 200), core::rect<s32>(0, 0, 256, 256), 0, 0, true); driver->draw2DImage(irrlichtLogo, core::rect<s32>(1100, 10, 1250, 150), core::rect<s32>(0, 0, 128, 128), 0, 0, true); // Selection box (must be implemented elsewhere of course /*driver->draw2DRectangle(video::SColor(50, 3, 67, 67), core::rect<s32>(512, 512, 680, 680)); driver->draw2DLine(core::position2d<s32>(512, 512), core::position2d<s32>(512, 680), video::SColor(255, 11, 208, 194)); driver->draw2DLine(core::position2d<s32>(512, 680), core::position2d<s32>(680, 680), video::SColor(255, 11, 208, 194)); driver->draw2DLine(core::position2d<s32>(680, 680), core::position2d<s32>(680, 512), video::SColor(255, 11, 208, 194)); driver->draw2DLine(core::position2d<s32>(680, 512), core::position2d<s32>(512, 512), video::SColor(255, 11, 208, 194));*/ Act.DrawCursor(); driver->endScene(); // Type FPS //========================================================== fps = driver->getFPS(); if (lastFPS != fps) { str = L"["; str += driver->getName(); str += "] FPS:"; str += fps; guiText->setText(str.c_str()); lastFPS = fps; } } else device->yield(); } // Drop Device //=========================================================== device->drop(); return 0; }
int main() { const int nRobots = 2; //given robot numbers will be controlled by humans vector<int> humanBrainIds; //humanBrainIds.push_back(1); //humanBrainIds.push_back(0); //-- device ------------------------------------------------------------// IrrlichtDevice* device; device = createDevice( EDT_OPENGL, //driverType windowSize, 16, //bits false, false, //stencilbuffer false, //vsync NULL //receiver ); //advanced device params //SIrrlichtCreationParameters params; //params.DeviceType = EIDT_CONSOLE; //params.DriverType = EDT_OPENGL; //params.WindowSize = windowSize; //device = createDeviceEx(params); if (device == 0) return EXIT_FAILURE; // could not create selected driver. IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->getSceneManager(); //-- lights ------------------------------------------------------------// //ambient light //smgr->setAmbientLight( SColorf(1.0f,1.0f,1.0f,1.0f) ); //smgr->setAmbientLight( SColorf(.3f,.3f,.3f,1.0f) ); //diffusive light SLight light_data; light_data.AmbientColor = SColorf(.3,.3,.3); //light_data.Attenuation = vector3df(.3,.3,.3); //Attenuation cte, linear quadratic TODO ?? light_data.DiffuseColor = SColorf(.0,.0,.0); light_data.SpecularColor = SColorf(.0,.0,.0); light_data.CastShadows = true; light_data.Radius = 100.0f; light_data.Type = ELT_DIRECTIONAL; //ELT_POINT point light, it has a position in space and radiates light in all directions //ELT_SPOT spot light, it has a position in space, a direction, and a limited cone of influence //ELT_DIRECTIONAL directional light, coming from a direction from an infinite distance ILightSceneNode* light = smgr->addLightSceneNode(0, core::vector3df(.5f,.0f,.5f)); light->setLightData(light_data); //-- objects ------------------------------------------------------------// IMesh* mesh; ISceneNode * node; float HEIGHT=1000.f, WIDTH=1.f; //height between center/sky == height bottom/center //large so that scene looks 2d on interactive test mode. //on automatic mode, only middle pixel row is taken, so this does not matter //outter boundary //square node = smgr->addCubeSceneNode( 2.f*WIDTH, // width 0, // parent -1, // id vector3df(0, 0, 0), // center vector3df(0, 0, 0), // rotation vector3df(1.0f, HEIGHT, 1.0f)*-1.f // scale. *-1 turns it inside out. to use both faces make two cubes. ); //circle //mesh = smgr->getGeometryCreator()->createCylinderMesh( //1.f, //radius //1., //length //50, //tesselation //SColor(0,0,0,255), //color //false, //closeTop //0.f //oblique //); //node = smgr->addMeshSceneNode( //mesh, //0, //ISceneNode * parent //-1, //s32 id //vector3df(0, -HEIGHT, 0), //const core::vector3df & position //vector3df(0, 0, 0), //const core::vector3df & rotation //vector3df(1.0f, 2.f*HEIGHT, 1.0f) //const core::vector3df & scale //); node->getMaterial(0).AmbientColor.set(0,0,0,0); node->getMaterial(0).DiffuseColor.set(0,0,0,0); //node->getMaterial(0).SpecularColor.set(255,255,255,255); //node->getMaterial(0).Shininess = 20.0f; //node->getMaterial(0).EmissiveColor.set(0,0,0,0); //node->setMaterialFlag(EMF_WIREFRAME,true); //wireframe only //left cube node = smgr->addCubeSceneNode( 0.2, // width 0, // parent -1, // id vector3df(-.3, 0, 0), // center vector3df(0, 0, 0), // rotation vector3df(1.0f, HEIGHT, 1.0f) // scale ); node->getMaterial(0).AmbientColor.set(0,255,0,0); node->getMaterial(0).DiffuseColor.set(0,255,0,0); //right cube node = smgr->addCubeSceneNode( .2f, // width 0, // parent -1, // id vector3df(.3, 0, 0), // center vector3df(0, 0, 0), // rotation vector3df(1.0f, HEIGHT, 1.0f) // scale ); node->getMaterial(0).AmbientColor.set(0,0,255,0); node->getMaterial(0).DiffuseColor.set(0,0,255,0); //cylinder //mesh = smgr->getGeometryCreator()->createCylinderMesh( //.1f, //radius //1., //length //50, //tesselation //SColor(), //color //false, //closeTop //0.f //oblique //); //node = smgr->addMeshSceneNode( //mesh, //0, //ISceneNode * parent //-1, //s32 id //vector3df(0, -HEIGHT, 0), //const core::vector3df & position //vector3df(0, 0, 0), //const core::vector3df & rotation //vector3df(1.0f, 2.*HEIGHT, 1.0f) //const core::vector3df & scale //); //node->getMaterial(0).AmbientColor.set(0,0,0,255); //node->getMaterial(0).DiffuseColor.set(0,0,0,255); //sphere //node = smgr->addSphereSceneNode( //0.1, // radius //50, // poly count //0, // parent //FruitID, // id //vector3df(0, 0, 0), // center //vector3df(0, 0, 0), // rotation //vector3df(1.0f, 1.0f, 1.0f) // scale //); //node->getMaterial(0).AmbientColor.set(0,0,0,255); //node->getMaterial(0).DiffuseColor.set(0,0,0,255); //node->getMaterial(0).Lighting = true; //-- collision ------------------------------------------------------------// /* Put everything we want to do collision checking with inside the meta selector. */ IMetaTriangleSelector * meta = smgr->createMetaTriangleSelector(); array<ISceneNode *> nodes; smgr->getSceneNodesFromType(ESNT_ANY, nodes); // Find all nodes for (u32 i=0; i < nodes.size(); ++i) { ISceneNode * node = nodes[i]; ITriangleSelector * selector = 0; switch(node->getType()) { case ESNT_CUBE: case ESNT_ANIMATED_MESH: // Because the selector won't animate with the mesh, // and is only being used for camera collision, we'll just use an approximate // bounding box instead of ((IAnimatedMeshSceneNode*)node)->getMesh(0) selector = smgr->createTriangleSelectorFromBoundingBox(node); break; case ESNT_MESH: case ESNT_SPHERE: // Derived from IMeshSceneNode selector = smgr->createTriangleSelector(((IMeshSceneNode*)node)->getMesh(), node); break; case ESNT_TERRAIN: selector = smgr->createTerrainTriangleSelector((ITerrainSceneNode*)node); break; case ESNT_OCTREE: selector = smgr->createOctreeTriangleSelector(((IMeshSceneNode*)node)->getMesh(), node); break; default: // Don't create a selector for this node type break; } if(selector) { // Add it to the meta selector, which will take a reference to it meta->addTriangleSelector(selector); // And drop my reference to it, so that the meta selector owns it. selector->drop(); } } //-- robots ------------------------------------------------------------// //create robots Fly2D::Brain* brains[nRobots]; //all to a default type //for ( int i=0; i<nRobots; i++ ) //{ //brains[i] = new Fly2D::BrainForward; ////brains[i] = new Fly2D::BrainCircle(); //} brains[0] = new Fly2D::BrainForward; brains[1] = new Fly2D::BrainForward; //decide human control vector<Fly2D::BrainHuman*> hBrains; for ( vector<int>::iterator i = humanBrainIds.begin(); i != humanBrainIds.end(); ++i ) { if ( *i > nRobots ) { cerr << "no such robot: " << *i << endl; exit(EXIT_FAILURE); } delete brains[*i]; Fly2D::BrainHuman* hBrain = new Fly2D::BrainHuman; brains[*i] = hBrain; hBrains.push_back(hBrain); } Fly2D::ReceiverHuman hReceiver = Fly2D::ReceiverHuman( hBrains ); device->setEventReceiver( &hReceiver ); Robot* robots[nRobots]; robots[0] = new Fly2D::Robot( *device, *meta, *brains[0], vector3df(0,0,-0.5f), vector3df(0,0, 0.5f), 0.01 ); robots[1] = new Fly2D::Robot( *device, *meta, *brains[1], vector3df(0,0,0.5f), vector3df(0,0, -0.5f), 0.01 ); meta->drop(); // As soon as we're done with the selector, drop it. //-- run ------------------------------------------------------------// //TEST vector3df oldpos, oldtarget; //END TEST int nFrames = 0; ITimer* timer = device->getTimer(); int t0 = timer->getTime(); int w = driver->getScreenSize().Width; int h = driver->getScreenSize().Height; int dh = h/nRobots; int observeRobot = 0; while(device->run()) { //if (device->isWindowActive()) //only work if window has focus. //draw driver->setViewPort(rect<s32>(0,0,w,h)); driver->beginScene(true,true,0); for(int i=0; i<nRobots; i++) { driver->setViewPort(rect<s32>(0,dh*i,w,dh*(i+1))); //only part of window gets drawn into smgr->setActiveCamera(robots[i]->camera); smgr->drawAll(); //draws on window scene of active camera robots[i]->update(); } driver->endScene(); //TEST //if //( //robots[observeRobot].getPosition() != oldpos //|| robots[observeRobot].getTarget() != oldtarget //) //oldpos = robots[observeRobot].getPosition(); //oldtarget = robots[observeRobot].getTarget(); cout << robots[observeRobot]->str(); //FPS info //cout << "frame no:" << endl << nFrames << endl;; //cout << "average fps:" << endl << 1000*nFrames/(float)(timer->getTime()-t0) << endl; //nFrames++; cout << "fps:" << endl << driver->getFPS() << endl; //END TEST } device->drop(); return 0; }
bool Application::run(){ if(!device){ return false; } Simulation sim; sim.Init(); //std::vector<Boid*> boids; int nbLead = 3; int nbUnit = 20; this->CreateBoids(nbLead, nbUnit, 10, sim, NULL,0,0,0); //this->SetCameraTarget(boids[0]); /*this->CreateBoids(150, &boids, &sim, Vector3(0.f, 0.f, 0.f)); this->CreateBoids(50, &boids, &sim, Vector3(40.f, 0.f, 0.f));*/ ITimer* irrTimer = device->getTimer(); u32 TimeStamp = irrTimer->getTime(); irr::u32 DeltaTime = 0; while(device->run()){ DeltaTime = irrTimer->getTime() - TimeStamp; TimeStamp = irrTimer->getTime(); sim.Update((float)DeltaTime); vector<Unit*> list = sim.GetAllUnits(); for(unsigned int i = 0; i < list.size(); i++){ Vector3 pos = list[i]->m_position; ((Boid*)list[i]->GetData())->setOrientation(core::vector3df(pos.X, pos.Y, pos.Z)); ((Boid*)list[i]->GetData())->setPosition(core::vector3df(pos.X, pos.Y, pos.Z)); } driver->beginScene(); smgr->drawAll(); irr::video::SMaterial m; m.Lighting=false; driver->setMaterial(m); driver->setTransform(video::ETS_WORLD, core::matrix4()); m_currentTime += DeltaTime; if(m_currentTime >= m_lastTime) { m_lastTime = TimeStamp + 10000 / (nbUnit * nbLead); if(list.size() > nbLead) { int r = rand()%list.size(); ps->setPosition(irr::core::vector3df(list[r]->m_position.X, list[r]->m_position.Y, list[r]->m_position.Z)); } else { ps->setEmitter(0); } } for(unsigned int i = 0; i < list.size(); i++){ if(list[i]->m_lead == NULL && list[i]->m_target != NULL) { Vector3 pos = list[i]->m_position; Vector3 posTarget = list[i]->m_target->m_position; driver->draw3DLine(irr::core::vector3df(pos.X,pos.Y,pos.Z),irr::core::vector3df(posTarget.X,posTarget.Y,posTarget.Z), ((Boid*)list[i]->GetData())->getColor()); } auto projectiles = list[i]->GetProjectileList(); for(unsigned int j = 0; j < projectiles.size(); j++){ Vector3 pos = projectiles[j].m_position; Vector3 posTarget = projectiles[j].m_position + (projectiles[j].m_velocity * projectiles[j].m_speed * 20.f); driver->draw3DLine(irr::core::vector3df(pos.X,pos.Y,pos.Z),irr::core::vector3df(posTarget.X,posTarget.Y,posTarget.Z), ((Boid*)list[i]->GetData())->getColor()); } } if(font) { std::vector<Unit*> rootUnits = sim.GetRootUnits(); for(unsigned int i = 0; i < rootUnits.size(); i++) { wchar_t str[1000]; swprintf(str, L"LEADER %d", i + 1); video::SColor color = ((Boid*)rootUnits.at(i)->GetData())->getColor(); font->draw(str, core::rect<s32>(20, (20 + 40)*i + 20,200,50), color); swprintf(str, L"Units: %d", rootUnits.at(i)->m_units.size() + 1); font->draw(str, core::rect<s32>(45, (20 + 40)*i + 40,200,50), color); } } driver->endScene(); } /*for(unsigned int i = 0; i < boids.size(); i++){ delete boids[i]; }*/ sim.Clear(); return true; }
int main() { IDevice* device = gf::createDevice(EDT_DIRECT3D11, 800, 600); IVideoDriver* driver = device->getVideoDriver(); ISceneManager* smgr = device->createSceneManager(); IResourceGroupManager* resourceGroupManager = driver->getResourceGroupManager(); resourceGroupManager->init("Resources.cfg"); ITimer* timer = device->getTimer(); timer->reset(); ITextureManager* textureManager = ITextureManager::getInstance(); IShaderManager* shaderMgr = driver->getShaderManager(); IShader* shader = shaderMgr->load(EST_COMPUTE_SHADER, "matmul.hlsl", "cs_main"); const u32 dimension = 512; const u32 sq_dimension = dimension * dimension; std::vector<f32> A(sq_dimension); std::vector<f32> B(sq_dimension); std::vector<f32> C(sq_dimension); std::vector<f32> D(sq_dimension); // init data for (u32 i = 0; i < sq_dimension; i++) { A[i] = math::RandomFloat(0, 10.0f); B[i] = math::RandomFloat(0, 10.0f); } f32 start_time, end_time; start_time = timer->getTime(); // store the right answers to D for (u32 i = 0; i < dimension; i++) { for (u32 j = 0; j < dimension; j++) { f32 sum = 0; for (u32 k = 0; k < dimension; k++) { sum += A[i * dimension + k] * B[k * dimension + j]; } D[i * dimension + j] = sum; } } end_time = timer->getTime(); printf("The computation time by CPU: %fs\n", end_time - start_time); start_time = timer->getTime(); ITexture* inputTexture1 = textureManager->createTexture2D("input1", dimension, dimension, ETBT_SHADER_RESOURCE, &A[0], 1, EGF_R32_FLOAT, 0); ITexture* inputTexture2 = textureManager->createTexture2D("input2", dimension, dimension, ETBT_SHADER_RESOURCE, &B[0], 1, EGF_R32_FLOAT, 0); ITexture* outputTexture = textureManager->createTexture2D("output", dimension, dimension, ETBT_UNORDERED_ACCESS, nullptr, 1, EGF_R32_FLOAT, 0); ITexture* copyTexture = textureManager->createTexture2D("copy", dimension, dimension, ETBT_CPU_ACCESS_READ, nullptr, 1, EGF_R32_FLOAT, 0); shader->setTexture("gInputA", inputTexture1); shader->setTexture("gInputB", inputTexture2); shader->setTexture("gOutput", outputTexture); u32 blockNum = dimension / 8; if (blockNum * 8 != dimension) blockNum++; driver->runComputeShader(shader, blockNum, blockNum, 1); //driver->resetRWTextures(); //driver->resetTextures(); outputTexture->copyDataToAnotherTexture(copyTexture); STextureData outputData; copyTexture->lock(ETLT_READ, &outputData); u8* data = (u8*)outputData.Data; for (u32 i = 0; i < dimension; i++) { // copy each row. memcpy(&C[i * dimension], data + outputData.RowPitch * i, dimension * sizeof(f32)); } copyTexture->unlock(); end_time = timer->getTime(); printf("The computation time by GPU: %fs\n", end_time - start_time); for (u32 i = 0; i < sq_dimension; i++) { assert(math::FloatEqual(C[i], D[i])); } // destory textures. if (!textureManager->destroy(inputTexture1)) printf("Destory texture failed!"); if (!textureManager->destroy(inputTexture2)) printf("Destory texture failed!"); if (!textureManager->destroy(outputTexture)) printf("Destory texture failed!"); if (!textureManager->destroy(copyTexture)) printf("Destory texture failed!"); //sphereMaterial.drop(); smgr->destroy(); device->drop(); system("pause"); return 0; }
int main() { state.phase = GameState::PHASE_ENTERING; state.state = GameState::STATE_INGAME; // asdf try { UserConfig = ConfigFile(get_userdata_path() + "user.cfg"); } catch (ConfigFile::file_not_found) { printf("No user config file found, creating...\n"); boost::filesystem::create_directories(get_userdata_path()); FILE *f; f = fopen((get_userdata_path() + "user.cfg").c_str(), "w"); if (f == NULL) { printf("Could not create user config file. Aborting. Please check that the path to the user config file is available: %s", (get_userdata_path() + "user.cfg").c_str()); exit(-1); } fclose(f); UserConfig = ConfigFile(get_userdata_path() + "user.cfg"); } IrrlichtDevice *device = setupDevice(receiver, &UserConfig); if (!device) { printf("Could not create device.\n"); } device->setWindowCaption(L"Licht Raiders"); device->setResizable(false); driver = device->getVideoDriver(); smgr = device->getSceneManager(); guienv = device->getGUIEnvironment(); collMan = smgr->getSceneCollisionManager(); /* Set up GUI */ // gui::IGUISkin* skin = env->getSkin(); setup_GUI(); /* Set up camera */ scene::ISceneNode *cam_base = smgr->addEmptySceneNode(0, DEFAULT_ID); scene::ICameraSceneNode *cam = smgr->addCameraSceneNode(cam_base, vector3df(0, 20, -2), vector3df(0, 0, 0), DEFAULT_ID); cam->setTarget(core::vector3df(0,0,0)); cam->setFarValue(42000.0f); cam->setNearValue(0.0625f); vector3df rotatedCamMove; vector3df camPos = cam->getPosition(); vector3df camTarget = cam->getTarget(); vector3df tempVec; // Used for miscellaneous things, just as a temporary vec3df storage /* Map */ FILE *mapfile; mapfile = fopen("data/maps/test.map", "rb"); if (mapfile == NULL) { bork("Could not open test map"); } map = new Map; map->load(mapfile); fclose(mapfile); /* Set up lighting */ smgr->setAmbientLight(SColor(0x404040)); scene::ILightSceneNode *light = smgr->addLightSceneNode(0, vector3df(0,30,0), SColor(0xffffff), 160.0f, DEFAULT_ID); scene::ILightSceneNode *light2 = smgr->addLightSceneNode(0, vector3df(0,30,0), SColor(0xffffff), 160.0f, DEFAULT_ID); /* Set up skybox */ const io::path skyboxFilename ("data/textures/skybox/top.png"); video::ITexture *sb_tex = driver->getTexture(skyboxFilename); smgr->addSkyBoxSceneNode(sb_tex, sb_tex, sb_tex, sb_tex, sb_tex, sb_tex, 0, DEFAULT_ID); /* T-Minus ten! */ ITimer* timer = device->getTimer(); timer->setTime(0); unsigned int now = 0; unsigned int lastUpdate = 0; int frame = 0; vector3df mousething; core::line3df ray; core::triangle3df dummyTri; int skips = 0; #ifdef DETAILED_PERFORMANCE float average_skips = -1; int max_skips = 0; #endif int slowness_count = 0; Entity randomEntity(vector2df(1, 1)); /* We have liftoff! */ while (device->run()) { now = timer->getTime(); if (now >= lastUpdate + 1000.0/MAX_FPS) { // Performance data collection #ifdef DETAILED_PERFORMANCE average_skips = (average_skips*frame + skips) / (frame+1); if (skips > max_skips) max_skips = skips; #endif if (skips == 0) slowness_count++; skips = 0; frame++; lastUpdate = now; driver->beginScene(true, true, SColor(255, 255, 0, 255)); smgr->drawAll(); guienv->drawAll(); driver->endScene(); rotatedCamMove = camMove; rotatedCamMove.rotateXZBy(camRot); camPos = cam_base->getPosition(); camTarget = cam->getTarget(); camPos += camMove; camTarget += camMove; cam_base->setPosition(camPos); cam->setTarget(camTarget); camPos = cam->getAbsolutePosition(); // Does reusing this variable for this count as bad? Does mah face look bovvered? camPos.Y = light->getPosition().Y; light->setPosition(camPos); light2->setPosition(camTarget); camHeight += camHeightChange; tempVec = vector3df(50,camHeight,0); tempVec.rotateXZBy(camRot); cam->setPosition(tempVec); if (frame % 400 == 0) printf("%i FPS\n", driver->getFPS()); if (state.state == GameState::STATE_NONE) break; } else { device->yield(); skips++; } } device->drop(); printf("Slowness: %i%%\n", (int) (((float) slowness_count / frame) * 100)); // Cast to get an integer percentage without annoying decimal places #ifdef DETAILED_PERFORMANCE printf("Average skips: %f\tMax skips (the higher the better): %i\n", average_skips, max_skips); #endif return 0; }