コード例 #1
0
ファイル: graphics.cpp プロジェクト: strand/xoreos
void GraphicsManager::renderScene() {
	Common::enforceMainThread();

	cleanupAbandoned();

	if (_frameLock.load(boost::memory_order_acquire) > 0) {
		_frameEndSignal.store(true, boost::memory_order_release);

		return;
	}

	beginScene();

	if (playVideo()) {
		endScene();
		return;
	}

	renderGUIBack();
	renderWorld();
	renderGUIFront();
	renderCursor();

	endScene();

	_frameEndSignal.store(true, boost::memory_order_release);
}
コード例 #2
0
ファイル: scene.cpp プロジェクト: AlbanBedel/scummvm
void Scene::skipScene() {
	SceneQueueList::iterator queueIterator;

	if (!_sceneLoaded) {
		error("Scene::skip(): Error: Can't skip scene...no scene loaded");
	}

	if (_inGame) {
		error("Scene::skip(): Error: Can't skip scene...game already started");
	}

	// Walk down scene queue and try to find a skip target
	queueIterator = _sceneQueue.begin();
	if (queueIterator == _sceneQueue.end()) {
		error("Scene::skip(): Error: Can't skip scene...no scenes in queue");
	}

	++queueIterator;
	while (queueIterator != _sceneQueue.end()) {
		if (queueIterator->sceneSkipTarget) {
			// If skip target found, remove preceding scenes and load
			_sceneQueue.erase(_sceneQueue.begin(), queueIterator);

			endScene();

			loadScene(*_sceneQueue.begin());
			break;
		}
		++queueIterator;
	}

}
コード例 #3
0
ファイル: scene.cpp プロジェクト: AlbanBedel/scummvm
void Scene::nextScene() {
	SceneQueueList::iterator queueIterator;

	if (!_sceneLoaded) {
		error("Scene::next(): Error: Can't advance scene...no scene loaded");
	}

	if (_inGame) {
		error("Scene::next(): Error: Can't advance scene...game already started");
	}

	endScene();

	// Delete the current head in scene queue
	queueIterator = _sceneQueue.begin();
	if (queueIterator == _sceneQueue.end()) {
		return;
	}

	queueIterator = _sceneQueue.erase(queueIterator);

	if (queueIterator == _sceneQueue.end()) {
		return;
	}

	// Load the head in scene queue
	loadScene(*queueIterator);
}
コード例 #4
0
ファイル: BreadCore.cpp プロジェクト: prodongi/Bread
	void cCore::render2D(cApplication* application)
	{
		if (!beginScene(false))
			return ;

		beforeRender2D(application);
		if (getIsRender2D())
		{
			if (m_postProcessMgr && m_postProcessMgr->is())
			{
				m_postProcessMgr->render2D();
				m_postProcessMgr->renderDebugScreen();
			}
			m_gui->render();
			m_batchRenderMgr->render2D();
		}
		afterRender2D(application);

		if (_getIsRender(RENDER_DEBUG_INFO))
			renderDebugInfo(application);

		m_debugRenderMgr->render2D();

		if (_getIsRender(RENDER_FPS))
			application->renderFps();

		endScene();
	}
コード例 #5
0
ファイル: scene.cpp プロジェクト: AlbanBedel/scummvm
void Scene::changeScene(int16 sceneNumber, int actorsEntrance, SceneTransitionType transitionType, int chapter) {

	debug(5, "Scene::changeScene(%d, %d, %d, %d)", sceneNumber, actorsEntrance, transitionType, chapter);

	// This is used for latter ITE demos where all places on world map except
	// Tent Faire are substituted with IFF picture and short description
	if (_vm->_hasITESceneSubstitutes) {
		for (int i = 0; i < ARRAYSIZE(sceneSubstitutes); i++) {
			if (sceneSubstitutes[i].sceneId == sceneNumber) {
				const byte *pal;
				Common::File file;
				Rect rect;
				PalEntry cPal[PAL_ENTRIES];

				_vm->_interface->setMode(kPanelSceneSubstitute);

				if (file.open(sceneSubstitutes[i].image)) {
					Image::IFFDecoder decoder;
					decoder.loadStream(file);
					pal = decoder.getPalette();
					rect.setWidth(decoder.getSurface()->w);
					rect.setHeight(decoder.getSurface()->h);
					_vm->_gfx->drawRegion(rect, (const byte *)decoder.getSurface()->getPixels());
					for (int j = 0; j < PAL_ENTRIES; j++) {
						cPal[j].red = *pal++;
						cPal[j].green = *pal++;
						cPal[j].blue = *pal++;
					}
					_vm->_gfx->setPalette(cPal);

				}

				_vm->_interface->setStatusText("Click or Press Return to continue. Press Q to quit.", 96);
				_vm->_font->textDrawRect(kKnownFontMedium, sceneSubstitutes[i].title,
					 Common::Rect(0, 7, _vm->getDisplayInfo().width, 27), _vm->KnownColor2ColorId(kKnownColorBrightWhite), _vm->KnownColor2ColorId(kKnownColorBlack), kFontOutline);
				_vm->_font->textDrawRect(kKnownFontMedium, sceneSubstitutes[i].message,
					 Common::Rect(24, getHeight() - 33, _vm->getDisplayInfo().width - 11,
								  getHeight()), _vm->KnownColor2ColorId(kKnownColorBrightWhite), _vm->KnownColor2ColorId(kKnownColorBlack), kFontOutline);
				return;
			}
		}
	}

	LoadSceneParams sceneParams;

	sceneParams.actorsEntrance = actorsEntrance;
	sceneParams.loadFlag = kLoadBySceneNumber;
	sceneParams.sceneDescriptor = sceneNumber;
	sceneParams.transitionType = transitionType;
	sceneParams.sceneProc = NULL;
	sceneParams.sceneSkipTarget = false;
	sceneParams.chapter = chapter;

	if (sceneNumber != -2) {
		endScene();
	}

	loadScene(sceneParams);
}
コード例 #6
0
ファイル: graphics.cpp プロジェクト: mclark4386/xoreos
void GraphicsManager::renderScene() {
	Common::enforceMainThread();

	cleanupAbandoned();

	if (_frameLock > 0)
		return;

	beginScene();

	if (playVideo()) {
		endScene();
		return;
	}

	renderWorld();
	renderGUIFront();
	renderCursor();

	endScene();
}
コード例 #7
0
	void SceneManager::m_switchScene()
	{
		if (curScene != nullptr)
			endScene();
		Scene* newScene = makeActiveScene(m_nextScene);
		if (newScene)
			curScene = newScene;
		else
			curScene = new uth::DefaultScene();
		startScene();
		m_pendingSceneSwitch = false;
	}
コード例 #8
0
ファイル: graphics.cpp プロジェクト: Danice123/DungeonCrawler
//=============================================================================
// Return the number of pixels colliding between the two sprites.
// Pre: The device supports a stencil buffer and pOcclusionQuery points to
// a valid occlusionQuery object.
// Post: Returns the number of pixels of overlap
//=============================================================================
DWORD Graphics::pixelCollision(const SpriteData &sprite1, const SpriteData &sprite2)
{
    if(!stencilSupport)     // if no stencil buffer support
        return 0;

    beginScene();

    // Set up stencil buffer using current entity
    device3d->SetRenderState(D3DRS_STENCILENABLE,   true);
    device3d->SetRenderState(D3DRS_STENCILFUNC,     D3DCMP_ALWAYS);
    device3d->SetRenderState(D3DRS_STENCILREF,      0x1);
    device3d->SetRenderState(D3DRS_STENCILMASK,     0xffffffff);
    device3d->SetRenderState(D3DRS_STENCILWRITEMASK,0xffffffff);
    device3d->SetRenderState(D3DRS_STENCILFAIL,     D3DSTENCILOP_KEEP);
    device3d->SetRenderState(D3DRS_STENCILPASS,     D3DSTENCILOP_REPLACE);

    // Write a 1 into the stencil buffer for each non-transparent pixel in ent
    spriteBegin();
    // Enable stencil buffer (must be after spriteBegin)
    device3d->SetRenderState(D3DRS_STENCILENABLE,   true);
    drawSprite(sprite2);            // write 1s to stencil buffer
    spriteEnd();

    // Change stencil buffer to only allow writes where the stencil value is 1
    // (where the ent sprite is colliding with the current sprite)
    device3d->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL);
    device3d->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
    
    // Begin occlusion query to count pixels that are drawn
    pOcclusionQuery->Issue(D3DISSUE_BEGIN);

    spriteBegin();
    // Enable stencil buffer (must be after spriteBegin)
    device3d->SetRenderState(D3DRS_STENCILENABLE,   true);
    drawSprite(sprite1);            // draw current entity 
    spriteEnd();
    // End occlusion query
    pOcclusionQuery->Issue(D3DISSUE_END);

    // Wait until the GPU is finished.
    while(S_FALSE == pOcclusionQuery->GetData( &numberOfPixelsColliding, 
                                  sizeof(DWORD), D3DGETDATA_FLUSH ))
    {}

    // Turn off stencil
    device3d->SetRenderState(D3DRS_STENCILENABLE, false);

    endScene();
    return numberOfPixelsColliding;
}
コード例 #9
0
ファイル: BreadCore.cpp プロジェクト: prodongi/Bread
	void cCore::renderProfile()
	{
		if (!_getIsRender(RENDER_PROFILE))
			return ;

		if (!beginScene(false))
			return ;

		int x = _getIsRenderValue1(RENDER_PROFILE);
		int y = _getIsRenderValue2(RENDER_PROFILE);
		PROFILE_RENDER(x, y);

		endScene();
	}
コード例 #10
0
DWORD Graphics::pixelCollision(const SpriteData &sprite1, const SpriteData &sprite2)
{
    if(!stencilSupport)    
        return 0;

    beginScene();

 
    device3d->SetRenderState(D3DRS_STENCILENABLE,   true);
    device3d->SetRenderState(D3DRS_STENCILFUNC,     D3DCMP_ALWAYS);
    device3d->SetRenderState(D3DRS_STENCILREF,      0x1);
    device3d->SetRenderState(D3DRS_STENCILMASK,     0xffffffff);
    device3d->SetRenderState(D3DRS_STENCILWRITEMASK,0xffffffff);
    device3d->SetRenderState(D3DRS_STENCILFAIL,     D3DSTENCILOP_KEEP);
    device3d->SetRenderState(D3DRS_STENCILPASS,     D3DSTENCILOP_REPLACE);

    spriteBegin();
    device3d->SetRenderState(D3DRS_STENCILENABLE,   true);
    drawSprite(sprite2);           
    spriteEnd();

    device3d->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL);
    device3d->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
    
    pOcclusionQuery->Issue(D3DISSUE_BEGIN);

    spriteBegin();
    device3d->SetRenderState(D3DRS_STENCILENABLE,   true);
    drawSprite(sprite1);           
    spriteEnd();
    pOcclusionQuery->Issue(D3DISSUE_END);

    while(S_FALSE == pOcclusionQuery->GetData( &numberOfPixelsColliding, 
                                  sizeof(DWORD), D3DGETDATA_FLUSH ))
    {}
    device3d->SetRenderState(D3DRS_STENCILENABLE, false);

    endScene();
    return numberOfPixelsColliding;
}
コード例 #11
0
ファイル: clientlauncher.cpp プロジェクト: Mab879/freeminer
//freeminer:
void ClientLauncher::wait_data() {
	device->run();
	bool wait = false;
	std::vector<std::string> check_path { porting::path_share + DIR_DELIM + "builtin" + DIR_DELIM + "init.lua", g_settings->get("font_path") };
	for (auto p : check_path)
		if (!fs::PathExists(p)) {
			wait = true;
			break;
		}
	bool &kill = *porting::signal_handler_killstatus();
	for (int i = 0; i < 1000; ++i) { // 100s max
		if (i || wait) {
			auto driver = device->getVideoDriver();
			g_menuclouds->step(4);
			driver->beginScene(true, true, video::SColor(255, 140, 186, 250));
			g_menucloudsmgr->drawAll();
			guienv->drawAll();
			driver->endScene();
			device->run();
			device->sleep(100);
		}
		int no = 0;
		if (! (i % 10) ) { //every second
			for (auto p : check_path)
				if (!fs::PathExists(p)) {
					++no;
					break;
				}
			if (!no || kill || !device->run())
				break;
			infostream << "waiting assets i= " << i << " path="<< porting::path_share << std::endl;
		}
	}

	if (wait) {
		device->run();
		device->sleep(300);
	}
}
コード例 #12
0
ファイル: BreadCore.cpp プロジェクト: prodongi/Bread
	void cCore::render3D(cApplication* application)
	{
		bool clearScene = true;
		if (!beginScene(clearScene))
			return ;

		if (m_postProcessMgr && m_postProcessMgr->is())
		{
			m_postProcessMgr->beginRttScene(true);
			render3DScene(application);
			m_postProcessMgr->endRttScene();

			m_postProcessMgr->renderHelper();
		}
		else
		{
			render3DScene(application);
		}

		m_debugRenderMgr->render3D();

		endScene();
	}
コード例 #13
0
ファイル: gfxDevice.cpp プロジェクト: 1414648814/Torque3D
void GFXDevice::updateStates(bool forceSetAll /*=false*/)
{
   PROFILE_SCOPE(GFXDevice_updateStates);

   if(forceSetAll)
   {
      bool rememberToEndScene = false;
      if(!canCurrentlyRender())
      {
         if (!beginScene())
         {
            AssertFatal(false, "GFXDevice::updateStates:  Unable to beginScene!");
         }
         rememberToEndScene = true;
      }

      setMatrix( GFXMatrixProjection, mProjectionMatrix );
      setMatrix( GFXMatrixWorld, mWorldMatrix[mWorldStackSize] );
      setMatrix( GFXMatrixView, mViewMatrix );

      setVertexDecl( mCurrVertexDecl );

      for ( U32 i=0; i < VERTEX_STREAM_COUNT; i++ )
      {
         setVertexStream( i, mCurrentVertexBuffer[i] );
         setVertexStreamFrequency( i, mVertexBufferFrequency[i] );
      }

      if( mCurrentPrimitiveBuffer.isValid() ) // This could be NULL when the device is initalizing
         mCurrentPrimitiveBuffer->prepare();

      /// Stateblocks
      if ( mNewStateBlock )
         setStateBlockInternal(mNewStateBlock, true);
      mCurrentStateBlock = mNewStateBlock;

      for(U32 i = 0; i < getNumSamplers(); i++)
      {
         switch (mTexType[i])
         {
            case GFXTDT_Normal :
               {
                  mCurrentTexture[i] = mNewTexture[i];
                  setTextureInternal(i, mCurrentTexture[i]);
               }  
               break;
            case GFXTDT_Cube :
               {
                  mCurrentCubemap[i] = mNewCubemap[i];
                  if (mCurrentCubemap[i])
                     mCurrentCubemap[i]->setToTexUnit(i);
                  else
                     setTextureInternal(i, NULL);
               }
               break;
            default:
               AssertFatal(false, "Unknown texture type!");
               break;
         }
      }

      // Set our material
      setLightMaterialInternal(mCurrentLightMaterial);

      // Set our lights
      for(U32 i = 0; i < LIGHT_STAGE_COUNT; i++)
      {
         setLightInternal(i, mCurrentLight[i], mCurrentLightEnable[i]);
      }

       _updateRenderTargets();

      if(rememberToEndScene)
         endScene();

      return;
   }

   if (!mStateDirty)
      return;

   // Normal update logic begins here.
   mStateDirty = false;

   // Update Projection Matrix
   if( mProjectionMatrixDirty )
   {
      setMatrix( GFXMatrixProjection, mProjectionMatrix );
      mProjectionMatrixDirty = false;
   }
   
   // Update World Matrix
   if( mWorldMatrixDirty )
   {
      setMatrix( GFXMatrixWorld, mWorldMatrix[mWorldStackSize] );
      mWorldMatrixDirty = false;
   }
   
   // Update View Matrix
   if( mViewMatrixDirty )
   {
      setMatrix( GFXMatrixView, mViewMatrix );
      mViewMatrixDirty = false;
   }


   if( mTextureMatrixCheckDirty )
   {
      for( S32 i = 0; i < getNumSamplers(); i++ )
      {
         if( mTextureMatrixDirty[i] )
         {
            mTextureMatrixDirty[i] = false;
            setMatrix( (GFXMatrixType)(GFXMatrixTexture + i), mTextureMatrix[i] );
         }
      }

      mTextureMatrixCheckDirty = false;
   }

   // Update the vertex declaration.
   if ( mVertexDeclDirty )
   {
      setVertexDecl( mCurrVertexDecl );
      mVertexDeclDirty = false;
   }

   // Update the vertex buffers.
   for ( U32 i=0; i < VERTEX_STREAM_COUNT; i++ )
   {
      if ( mVertexBufferDirty[i] )
      {
         setVertexStream( i, mCurrentVertexBuffer[i] );
         mVertexBufferDirty[i] = false;
      }

      if ( mVertexBufferFrequencyDirty[i] )
      {
         setVertexStreamFrequency( i, mVertexBufferFrequency[i] );
         mVertexBufferFrequencyDirty[i] = false;
      }
   }

   // Update primitive buffer
   //
   // NOTE: It is very important to set the primitive buffer AFTER the vertex buffer
   // because in order to draw indexed primitives in DX8, the call to SetIndicies
   // needs to include the base vertex offset, and the DX8 GFXDevice relies on
   // having mCurrentVB properly assigned before the call to setIndices -patw
   if( mPrimitiveBufferDirty )
   {
      if( mCurrentPrimitiveBuffer.isValid() ) // This could be NULL when the device is initalizing
         mCurrentPrimitiveBuffer->prepare();
      mPrimitiveBufferDirty = false;
   }

   // NOTE: With state blocks, it's now important to update state before setting textures
   // some devices (e.g. OpenGL) set states on the texture and we need that information before
   // the texture is activated.
   if (mStateBlockDirty)
   {
      setStateBlockInternal(mNewStateBlock, false);
      mCurrentStateBlock = mNewStateBlock;
      mStateBlockDirty = false;
   }

   if( mTexturesDirty )
   {
      mTexturesDirty = false;
      for(U32 i = 0; i < getNumSamplers(); i++)
      {
         if(!mTextureDirty[i])
            continue;
         mTextureDirty[i] = false;

         switch (mTexType[i])
         {
         case GFXTDT_Normal :
            {
               mCurrentTexture[i] = mNewTexture[i];
               setTextureInternal(i, mCurrentTexture[i]);
            }  
            break;
         case GFXTDT_Cube :
            {
               mCurrentCubemap[i] = mNewCubemap[i];
               if (mCurrentCubemap[i])
                  mCurrentCubemap[i]->setToTexUnit(i);
               else
                  setTextureInternal(i, NULL);
            }
            break;
         default:
            AssertFatal(false, "Unknown texture type!");
            break;
         }
      }
   }
   
   // Set light material
   if(mLightMaterialDirty)
   {
      setLightMaterialInternal(mCurrentLightMaterial);
      mLightMaterialDirty = false;
   }

   // Set our lights
   if(mLightsDirty)
   {
      mLightsDirty = false;
      for(U32 i = 0; i < LIGHT_STAGE_COUNT; i++)
      {
         if(!mLightDirty[i])
            continue;

         mLightDirty[i] = false;
         setLightInternal(i, mCurrentLight[i], mCurrentLightEnable[i]);
      }
   }

   _updateRenderTargets();

#ifdef TORQUE_DEBUG_RENDER
   doParanoidStateCheck();
#endif
}
コード例 #14
0
void ClientApplication::run()
{
	int lastFPS = -1;
	auto driver = _device->getVideoDriver();

	sf::Clock c;
	while(_device->run())
	{
		float timeDelta = c.restart().asSeconds();
		scene::ICameraSceneNode* camera = getCamera();
		if(camera) {
			if(camera->isInputReceiverEnabled() && !_controller.isCameraFree())
				bindCameraToControlledEntity();
			if(!camera->isInputReceiverEnabled()) {
				vec3f cameraLookDir((_cameraElevation-PI_2)/PI*180,(_cameraYAngle+PI_2)/PI*180,0);
				cameraLookDir = cameraLookDir.rotationToDirection().normalize();
				camera->setTarget(camera->getAbsolutePosition()+cameraLookDir*10000);
				if(_sharedRegistry.hasKey("controlled_object_id")) {
					auto controlledCharSceneNode = _device->getSceneManager()->getSceneNodeFromId(_sharedRegistry.getValue<ID>("controlled_object_id"));
					if(controlledCharSceneNode) {
						controlledCharSceneNode->setVisible(false);
						camera->setPosition(controlledCharSceneNode->getPosition() + vec3f(0,1.6,0) + 0.23f*(cameraLookDir*vec3f(1,0,1)).normalize());
					}
				}
			}
		}

		while(receive());		
		//TODO fix frameLen spike after win inactivity (mind the physics)
		if(true)//if(_device->isWindowActive())
		{
			if(_device->isWindowActive())
				_device->getCursorControl()->setPosition(vec2f(0.5));
			driver->beginScene(/*true,true,video::SColor(255,255,255,255)*/);
			f32 ar = (float)driver->getScreenSize().Width/(float)driver->getScreenSize().Height;
			camera = getCamera();
			if(camera && ar != camera->getAspectRatio())
				camera->setAspectRatio(ar);
			//std::cout << "number of scene nodes: " << _device->getSceneManager()->getRootSceneNode()->getChildren().size() << std::endl;
				
			if(_yAngleSetCommandFilter.tick(timeDelta) && _yAngleSetCommandFilter.objUpdated()) {
				Command c(Command::Type::Y_ANGLE_SET);
				c._float = _yAngleSetCommandFilter.reset();
				sendCommand(c);
			}

			if(_physics)
				_physics->update(timeDelta);
			if(_vs)
				_vs->update(timeDelta);
			if(_gui)
				_gui->update(timeDelta);

			_device->getSceneManager()->drawAll();
			_device->getGUIEnvironment()->drawAll();

			driver->runAllOcclusionQueries(false);
			driver->updateAllOcclusionQueries();

			driver->endScene();

			// display frames per second in window title
			int fps = driver->getFPS();
			if (lastFPS != fps)
			{
				core::stringw str = L"MyGame [";
				str += driver->getName();
				str += "] FPS:";
				str += fps;

				_device->setWindowCaption(str.c_str());
				lastFPS = fps;
			}
		}
		sf::sleep(sf::milliseconds(1));
	}
}