当前位置: 首页>>代码示例>>C++>>正文


C++ ITimer::getTime方法代码示例

本文整理汇总了C++中ITimer::getTime方法的典型用法代码示例。如果您正苦于以下问题:C++ ITimer::getTime方法的具体用法?C++ ITimer::getTime怎么用?C++ ITimer::getTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITimer的用法示例。


在下文中一共展示了ITimer::getTime方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run

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;
}
开发者ID:PuKoren,项目名称:exploot-client,代码行数:25,代码来源:Application.cpp

示例2: dbLoopGDK

///@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;
}
开发者ID:benjaminhampe,项目名称:BenniSDK,代码行数:56,代码来源:libDarkGDK.cpp

示例3: main

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();
//.........这里部分代码省略.........
开发者ID:insanewarlock,项目名称:irrRTS-RTT,代码行数:101,代码来源:main.cpp

示例4: main


//.........这里部分代码省略.........

//-- 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;
}
开发者ID:cirosantilli,项目名称:computer_vision2d,代码行数:101,代码来源:main.cpp

示例5: run

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;
}
开发者ID:NHKChris,项目名称:hierarchical-fighting-boids,代码行数:95,代码来源:Application.cpp

示例6: main

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))
//.........这里部分代码省略.........
开发者ID:whztt07,项目名称:GameFinal,代码行数:101,代码来源:main.cpp

示例7: main

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++;
//.........这里部分代码省略.........
开发者ID:lheckemann,项目名称:licht-raiders,代码行数:101,代码来源:main.cpp


注:本文中的ITimer::getTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。