Esempio n. 1
0
std::shared_ptr<Actor> AIFactory::create()
{
	irr::scene::ISceneManager* smgr = GameApp::getSingleton().getSceneManager();

	std::string animDataPath = "../../../art/"
	+ aiName
	+ ".xml";

	auto sprData = animationEngine.load(animDataPath.c_str());

	assert(sprData);

	auto spr = std::make_shared<AnimatedSprite>(sprData, smgr->getRootSceneNode(), smgr);
	spr->setAnchor(irr::core::vector3df(spr->getSize().Width/2, 0.f, spr->getSize().Height));
	animationEngine.addSprite(spr);

	std::shared_ptr<Actor> ai = std::make_shared<Actor>();

	// initialize state machine
	auto stateMachine = std::make_shared<AIStateMachine>(ai, HashedString("idle"));
	stateMachine->setTeamMembership(membershipSupplier->requestMembership());
	stateMachine->initStates();

	ai->setStateMachine(stateMachine);
	ai->setSprite(spr);
	aiEventSource->addListener(ai);

	ai->start();

	return ai;
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
// Reset D3D device
//-----------------------------------------------------------------------------
void GFXPCD3D9Device::reset( D3DPRESENT_PARAMETERS &d3dpp )
{
   if(!mD3DDevice)
      return;

   mInitialized = false;

   mMultisampleType = d3dpp.MultiSampleType;
   mMultisampleLevel = d3dpp.MultiSampleQuality;
   _validateMultisampleParams(d3dpp.BackBufferFormat, mMultisampleType, mMultisampleLevel);

   // Clean up some commonly dangling state. This helps prevents issues with
   // items that are destroyed by the texture manager callbacks and recreated
   // later, but still left bound.
   setVertexBuffer(NULL);
   setPrimitiveBuffer(NULL);
   for(S32 i=0; i<getNumSamplers(); i++)
      setTexture(i, NULL);

   // Deal with the depth/stencil buffer.
   if(mDeviceDepthStencil)
   {
      Con::printf("GFXPCD3D9Device::reset - depthstencil %x has %d ref's", mDeviceDepthStencil, mDeviceDepthStencil->AddRef()-1);
      mDeviceDepthStencil->Release();
   }

   // First release all the stuff we allocated from D3DPOOL_DEFAULT
   releaseDefaultPoolResources();

   // reset device
   Con::printf( "--- Resetting D3D Device ---" );
   HRESULT hres = S_OK;
   hres = mD3DDevice->Reset( &d3dpp );

   if( FAILED( hres ) )
   {
      while( mD3DDevice->TestCooperativeLevel() == D3DERR_DEVICELOST )
      {
         Sleep( 100 );
      }

      hres = mD3DDevice->Reset( &d3dpp );
   }

   D3D9Assert( hres, "GFXD3D9Device::reset - Failed to create D3D Device!" );
   mInitialized = true;

   // Setup default states
   initStates();

   // Now re aquire all the resources we trashed earlier
   reacquireDefaultPoolResources();

   // Mark everything dirty and flush to card, for sanity.
   updateStates(true);
}
Esempio n. 3
0
uiDrawContext *newContext(ID2D1RenderTarget *rt)
{
	uiDrawContext *c;

	c = uiNew(uiDrawContext);
	c->rt = rt;
	initStates(c);
	resetTarget(c->rt);
	return c;
}
Esempio n. 4
0
		void StateBasedGame::init(GameContainer* container) {
			m_container = container;

			initStates(container);

			for (unsigned int i = 0; i < m_states.size(); i++) {
				GameState* s = m_states.at(i);
				ARK2D::getLog()->i(StringUtil::append("initialising state: ", s->id()));
				s->init(container, this);
			}

			m_initialised = true;
		}
Esempio n. 5
0
BlockStates DataFlowPass::runOnBlocks(const BlockVector& blocks) {
  BlockStates states;
  // First pass: precompute generate and kill sets.
  initStates(blocks, states);
  // iterate for a forwards pass
  if (_direction == FORWARDS) {
    const BasicBlock* start = blocks.front();
    traverseForwards(start, states);
  }
  // iterate for a backwards pass
  else if (_direction == BACKWARDS) {
    const BasicBlock* start = blocks.back();
    traverseBackwards(start, states);
  }
  return states;
}
Esempio n. 6
0
MainWindow::MainWindow() : QMainWindow(),
    m_ParticleFilter(250, &m_ObservationModel, &m_MovementModel),
    m_RunFilter(true)
{
    setupUi(this);

    this->grabKeyboard();

    m_frontDown = m_backDown = m_rightDown = m_leftDown = 0;
    m_RenderWidget->setParticleFilter(&m_ParticleFilter);

    connect(m_ParticleWeightPlotCheckBox, SIGNAL(stateChanged(int)), this, SLOT(changeDisplaySettings()));
    connect(m_LoopModeRadioButton, SIGNAL(toggled(bool)), this, SLOT(changeRunMode()));
    connect(m_ResampleButton, SIGNAL(clicked()), this, SLOT(resample()));
    connect(m_DriftButton, SIGNAL(clicked()), this, SLOT(drift()));
    connect(m_DiffuseButton, SIGNAL(clicked()), this, SLOT(diffuse()));
    connect(m_MeasureButton, SIGNAL(clicked()), this, SLOT(measure()));
    connect(m_RedrawParticlesButton, SIGNAL(clicked()), this, SLOT(redrawParticles()));
    connect(m_ResamplingModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setResamplingMode()));

    // read standard values into spin boxes
    m_XSpinBox->setValue(m_MovementModel.getXStdDev());
    m_YSpinBox->setValue(m_MovementModel.getYStdDev());
    m_ThetaSpinBox->setValue(m_MovementModel.getThetaStdDev() / M_PI * 180.0);
    m_SpeedSpinBox->setValue(m_MovementModel.getSpeedStdDev());
    m_RotationSpeedSpinBox->setValue(m_MovementModel.getRotationSpeedStdDev() / M_PI * 180.0);

    // connect spin boxes
    connect(m_XSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setMovementModelParameters()));
    connect(m_YSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setMovementModelParameters()));
    connect(m_ThetaSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setMovementModelParameters()));
    connect(m_SpeedSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setMovementModelParameters()));
    connect(m_RotationSpeedSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setMovementModelParameters()));

    QTimer::singleShot(50, this, SLOT(initStates()));
    // start the loop
    QTimer::singleShot(100, this, SLOT(gameLoop()));
}
Esempio n. 7
0
//-----------------------------------------------------------------------------
// Initialize - create window, device, etc
//-----------------------------------------------------------------------------
void GFXPCD3D9Device::init( const GFXVideoMode &mode, PlatformWindow *window /* = NULL */ )
{
   AssertFatal(window, "GFXPCD3D9Device::init - must specify a window!");

   initD3DXFnTable();

   HWND winHwnd = (HWND)window->getSystemWindow( PlatformWindow::WindowSystem_Windows );
   AssertISV(winHwnd, "GFXPCD3D9WindowTarget::initPresentationParams() - no HWND");

   // Create D3D Presentation params
   D3DPRESENT_PARAMETERS d3dpp = setupPresentParams( mode, winHwnd );
   mMultisampleType = d3dpp.MultiSampleType;
   mMultisampleLevel = d3dpp.MultiSampleQuality;
      
#ifndef TORQUE_SHIPPING
   bool usePerfHud = GFXPCD3D9Device::mEnableNVPerfHUD || Con::getBoolVariable("$Video::useNVPerfHud", false);   
#else
   bool usePerfHud = false;
#endif

   HRESULT hres = E_FAIL;
   if ( usePerfHud )
   {  
      hres = createDevice(  mD3D->GetAdapterCount() - 1, D3DDEVTYPE_REF, winHwnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp);
   }
   else 
   {
      // Vertex processing was changed from MIXED to HARDWARE because of the switch to a pure D3D device.

      // Set up device flags from our compile flags.
      U32 deviceFlags = 0;
      deviceFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;

      // Currently, offscreen rendering is only used by WPF apps and we need to create with D3DCREATE_MULTITHREAD for it
      // In all other cases, you can do better by locking/creating resources in the primary thread
      // and passing them to worker threads.
      if (window->getOffscreenRender())
      {
         deviceFlags |= D3DCREATE_MULTITHREADED;
         d3dpp.Windowed = TRUE;
         d3dpp.BackBufferHeight = 1;
         d3dpp.BackBufferWidth = 1;
         d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
         d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
         d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
      }

      // DirectX will switch the floating poing control word to single precision
      // and disable exceptions by default.  There are a few issues with this...
      //
      // 1. It can cause rendering problems when running in WPF.
      // 2. Firefox embedding issues.
      // 3. Physics engines depend on the higher precision.
      //
      // Interestingly enough... DirectX 10 and 11 do not modifiy the floating point
      // settings and are always in full precision.
      //
      // The down side is we supposedly loose some performance, but so far i've not
      // seen a measurable impact.
      // 
      deviceFlags |= D3DCREATE_FPU_PRESERVE;

      // Try to do pure, unless we're doing debug (and thus doing more paranoid checking).
#ifndef TORQUE_DEBUG_RENDER
      deviceFlags |= D3DCREATE_PUREDEVICE;
#endif

      hres = createDevice( mAdapterIndex, D3DDEVTYPE_HAL, winHwnd, deviceFlags, &d3dpp);

      if (FAILED(hres) && hres != D3DERR_OUTOFVIDEOMEMORY)
      {
         Con::errorf("   Failed to create hardware device, trying mixed device");
         // turn off pure
         deviceFlags &= (~D3DCREATE_PUREDEVICE);

         // try mixed mode
         deviceFlags &= (~D3DCREATE_HARDWARE_VERTEXPROCESSING);
         deviceFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
         hres = createDevice( mAdapterIndex, D3DDEVTYPE_HAL, 
            winHwnd, deviceFlags, 
            &d3dpp);

         // try software 
         if (FAILED(hres) && hres != D3DERR_OUTOFVIDEOMEMORY)
         {
            Con::errorf("   Failed to create mixed mode device, trying software device");
            deviceFlags &= (~D3DCREATE_MIXED_VERTEXPROCESSING);
            deviceFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
            hres = createDevice( mAdapterIndex, D3DDEVTYPE_HAL, 
               winHwnd, deviceFlags,
               &d3dpp);

            if (FAILED(hres) && hres != D3DERR_OUTOFVIDEOMEMORY)
               Con::errorf("   Failed to create software device, giving up");
            D3D9Assert(hres, "GFXPCD3D9Device::init - CreateDevice failed!");
         }
      }
   }

   // Gracefully die if they can't give us a device.
   if(!mD3DDevice)
   {
      if (hres == D3DERR_OUTOFVIDEOMEMORY)
      {
         char errorMsg[4096];
         dSprintf(errorMsg, sizeof(errorMsg),
            "Out of video memory. Close other windows, reboot, and/or upgrade your video card drivers. Your video card is: %s", getAdapter().getName());
         Platform::AlertOK("DirectX Error", errorMsg);
      }
      else
      {
         Platform::AlertOK("DirectX Error!", "Failed to initialize Direct3D! Make sure you have DirectX 9 installed, and "
            "are running a graphics card that supports Pixel Shader 1.1.");
      }
      Platform::forceShutdown(1);
   }

   // Check up on things
   Con::printf("   Cur. D3DDevice ref count=%d", mD3DDevice->AddRef() - 1);
   mD3DDevice->Release();
   
   mTextureManager = new GFXD3D9TextureManager( mD3DDevice, mAdapterIndex );

   // Now reacquire all the resources we trashed earlier
   reacquireDefaultPoolResources();
      
   // Setup default states
   initStates();

   //-------- Output init info ---------   
   D3DCAPS9 caps;
   mD3DDevice->GetDeviceCaps( &caps );

   U8 *pxPtr = (U8*) &caps.PixelShaderVersion;
   mPixVersion = pxPtr[1] + pxPtr[0] * 0.1;
   if (mPixVersion >= 2.0f && mPixVersion < 3.0f && caps.PS20Caps.NumTemps >= 32)
      mPixVersion += 0.2f;
   else if (mPixVersion >= 2.0f && mPixVersion < 3.0f && caps.PS20Caps.NumTemps >= 22)
      mPixVersion += 0.1f;
   Con::printf( "   Pix version detected: %f", mPixVersion );

   if ( smForcedPixVersion >= 0.0f && smForcedPixVersion < mPixVersion )
   {
      mPixVersion = smForcedPixVersion;
      Con::errorf( "   Forced pix version: %f", mPixVersion );
   }

   U8 *vertPtr = (U8*) &caps.VertexShaderVersion;
   F32 vertVersion = vertPtr[1] + vertPtr[0] * 0.1;
   Con::printf( "   Vert version detected: %f", vertVersion );

   // The sampler count is based on the shader model and
   // not found in the caps.
   //
   // MaxSimultaneousTextures is only valid for fixed
   // function rendering.
   //
   if ( mPixVersion >= 2.0f )
      mNumSamplers = 16;
   else if ( mPixVersion >= 1.4f )
      mNumSamplers = 6;
   else if ( mPixVersion > 0.0f )
      mNumSamplers = 4;
   else
      mNumSamplers = caps.MaxSimultaneousTextures;      

   // This shouldn't happen until SM5 or some other
   // radical change in GPU hardware occurs.
   AssertFatal( mNumSamplers <= TEXTURE_STAGE_COUNT, 
      "GFXPCD3D9Device::init - Sampler count greater than TEXTURE_STAGE_COUNT!" );
            
   Con::printf( "   Maximum number of simultaneous samplers: %d", mNumSamplers );

   // detect max number of simultaneous render targets
   mNumRenderTargets = caps.NumSimultaneousRTs;
   Con::printf( "   Number of simultaneous render targets: %d", mNumRenderTargets );
   
   // detect occlusion query support
   if (SUCCEEDED(mD3DDevice->CreateQuery( D3DQUERYTYPE_OCCLUSION, NULL )))
	   mOcclusionQuerySupported = true;
      
   Con::printf( "   Hardware occlusion query detected: %s", mOcclusionQuerySupported ? "Yes" : "No" );      

   Con::printf( "   Using Direct3D9Ex: %s", isD3D9Ex() ? "Yes" : "No" );
   
   mCardProfiler = new GFXD3D9CardProfiler(mAdapterIndex);
   mCardProfiler->init();

   gScreenShot = new ScreenShotD3D;

   // Set the video capture frame grabber.
   mVideoFrameGrabber = new VideoFrameGrabberD3D9();
   VIDCAP->setFrameGrabber( mVideoFrameGrabber );

   // Grab the depth-stencil...
   SAFE_RELEASE(mDeviceDepthStencil);
   D3D9Assert(mD3DDevice->GetDepthStencilSurface(&mDeviceDepthStencil), "GFXD3D9Device::init - couldn't grab reference to device's depth-stencil surface.");  

   mInitialized = true;

   deviceInited();

   // Uncomment to dump out code needed in initStates, you may also need to enable the reference device (get rid of code in initStates first as well)
   // regenStates();
}
Esempio n. 8
0
SVGPathRunner::SVGPathRunner()
{
	if (pathCommands.size() == 0) {
		initStates();
	}
}
Esempio n. 9
0
bool RenderDevice::init()
{
	bool failed = false;

	char *vendor = (char *)glGetString( GL_VENDOR );
	char *renderer = (char *)glGetString( GL_RENDERER );
	char *version = (char *)glGetString( GL_VERSION );
	
	Modules::log().writeInfo( "Initializing GL2 backend using OpenGL driver '%s' by '%s' on '%s'",
	                          version, vendor, renderer );
	
	// Init extensions
	if( !initOpenGLExtensions() )
	{	
		Modules::log().writeError( "Could not find all required OpenGL function entry points" );
		failed = true;
	}

	// Check that OpenGL 2.0 is available
	if( glExt::majorVersion * 10 + glExt::minorVersion < 20 )
	{
		Modules::log().writeError( "OpenGL 2.0 not available" );
		failed = true;
	}
	
	// Check that required extensions are supported
	if( !glExt::EXT_framebuffer_object )
	{
		Modules::log().writeError( "Extension EXT_framebuffer_object not supported" );
		failed = true;
	}
	if( !glExt::EXT_texture_filter_anisotropic )
	{
		Modules::log().writeError( "Extension EXT_texture_filter_anisotropic not supported" );
		failed = true;
	}
	if( !glExt::EXT_texture_compression_s3tc )
	{
		Modules::log().writeError( "Extension EXT_texture_compression_s3tc not supported" );
		failed = true;
	}
	if( !glExt::EXT_texture_sRGB )
	{
		Modules::log().writeError( "Extension EXT_texture_sRGB not supported" );
		failed = true;
	}
	
	if( failed )
	{
		Modules::log().writeError( "Failed to init renderer backend, debug info following" );
		char *exts = (char *)glGetString( GL_EXTENSIONS );
		Modules::log().writeInfo( "Supported extensions: '%s'", exts );

		return false;
	}
	
	// Get capabilities
	_caps.texFloat = glExt::ARB_texture_float ? 1 : 0;
	_caps.texNPOT = glExt::ARB_texture_non_power_of_two ? 1 : 0;
	_caps.rtMultisampling = glExt::EXT_framebuffer_multisample ? 1 : 0;

	// Find supported depth format (some old ATI cards only support 16 bit depth for FBOs)
	_depthFormat = GL_DEPTH_COMPONENT24;
	uint32 testBuf = createRenderBuffer( 32, 32, TextureFormats::BGRA8, true, 1, 0 ); 
	if( testBuf == 0 )
	{	
		_depthFormat = GL_DEPTH_COMPONENT16;
		Modules::log().writeWarning( "Render target depth precision limited to 16 bit" );
	}
	else
		destroyRenderBuffer( testBuf );
	
	initStates();
	resetStates();

	return true;
}
Esempio n. 10
0
/* Goes through the list of circuit objects and runs its initTR()
   function. */
void e_trsolver::initETR (nr_double_t start, nr_double_t firstdelta, int mode)
{
    const char * const IMethod = getPropertyString ("IntegrationMethod");
    //nr_double_t start = getPropertyDouble ("Start");
    //nr_double_t stop = start + firstdelta;
    //nr_double_t points = 1.0;

    // fetch corrector integration method and determine predicor method
    corrMaxOrder = getPropertyInteger ("Order");
    corrType = CMethod = correctorType (IMethod, corrMaxOrder);
    predType = PMethod = predictorType (CMethod, corrMaxOrder, predMaxOrder);
    corrOrder = corrMaxOrder;
    predOrder = predMaxOrder;

    // initialize step values
    if (mode == ETR_MODE_ASYNC){
        delta = getPropertyDouble ("InitialStep");
        deltaMin = getPropertyDouble ("MinStep");
        deltaMax = getPropertyDouble ("MaxStep");
        if (deltaMax == 0.0)
            deltaMax = firstdelta; // MIN ((stop - start) / (points - 1), stop / 200);
        if (deltaMin == 0.0)
            deltaMin = NR_TINY * 10 * deltaMax;
        if (delta == 0.0)
            delta = firstdelta; // MIN (stop / 200, deltaMax) / 10;
        if (delta < deltaMin) delta = deltaMin;
        if (delta > deltaMax) delta = deltaMax;
    }
    else if (mode == ETR_MODE_SYNC)
    {
        delta = firstdelta;
        deltaMin = NR_TINY * 10;
        deltaMax =  std::numeric_limits<nr_double_t>::max() / 10;
    }

    // initialize step history
    setStates (2);
    initStates ();
    // initialise the history of states, setting them all to 'delta'
    fillState (dState, delta);

    // copy the initialised states to the 'deltas' array
    saveState (dState, deltas);
    // copy the deltas to all the circuits
    setDelta ();
    // set the initial corrector and predictor coefficients
    calcCorrectorCoeff (corrType, corrOrder, corrCoeff, deltas);
    calcPredictorCoeff (predType, predOrder, predCoeff, deltas);

    // initialize history of solution vectors (solutions)
    for (int i = 0; i < 8; i++)
    {
        // solution contains the last sets of node voltages and branch
        // currents at each of the last 8 'deltas'.
        // Note for convenience the definition:
        //   #define SOL(state) (solution[(int) getState (sState, (state))])
        // is provided and used elsewhere to update the solutions
        solution[i] = new tvector<nr_double_t>;
        setState (sState, (nr_double_t) i, i);
        lastsolution[i] = new tvector<nr_double_t>;
    }

    // Initialise history tracking for asynchronous solvers
    // See acceptstep_async and rejectstep_async for more
    // information
    lastasynctime = start;
    saveState (dState, lastdeltas);
    lastdelta = delta;

    // tell circuit elements about the transient analysis
    circuit *c, * root = subnet->getRoot ();
    for (c = root; c != NULL; c = (circuit *) c->getNext ())
        initCircuitTR (c);
    // also initialize the created circuit elements
    for (c = root; c != NULL; c = (circuit *) c->getPrev ())
        initCircuitTR (c);
}
Esempio n. 11
0
map<NFAVertex, NFAStateSet> findSquashers(const NGHolder &g, som_type som) {
    map<NFAVertex, NFAStateSet> squash;

    // Number of bits to use for all our masks. If we're a triggered graph,
    // tops have already been assigned, so we don't have to account for them.
    const u32 numStates = num_vertices(g);

    // Build post-dominator tree.
    PostDomTree pdom_tree;
    buildPDomTree(g, pdom_tree);

    // Build list of vertices by state ID and a set of init states.
    vector<NFAVertex> vByIndex(numStates, NFAGraph::null_vertex());
    NFAStateSet initStates(numStates);
    smgb_cache cache(g);

    // Mappings used for SOM mode calculations, otherwise left empty.
    unordered_map<NFAVertex, u32> region_map;
    vector<DepthMinMax> som_depths;
    if (som) {
        region_map = assignRegions(g);
        som_depths = getDistancesFromSOM(g);
    }

    for (auto v : vertices_range(g)) {
        const u32 vert_id = g[v].index;
        DEBUG_PRINTF("vertex %u/%u\n", vert_id, numStates);
        assert(vert_id < numStates);
        vByIndex[vert_id] = v;

        if (is_any_start(v, g) || !in_degree(v, g)) {
            initStates.set(vert_id);
        }
    }

    for (u32 i = 0; i < numStates; i++) {
        NFAVertex v = vByIndex[i];
        assert(v != NFAGraph::null_vertex());
        const CharReach &cr = g[v].char_reach;

        /* only non-init cyclics can be squashers */
        if (!hasSelfLoop(v, g) || initStates.test(i)) {
            continue;
        }

        DEBUG_PRINTF("state %u is cyclic\n", i);

        NFAStateSet mask(numStates), succ(numStates), pred(numStates);
        buildSquashMask(mask, g, v, cr, initStates, vByIndex, pdom_tree, som,
                        som_depths, region_map, cache);
        buildSucc(succ, g, v);
        buildPred(pred, g, v);
        const auto &reports = g[v].reports;

        for (size_t j = succ.find_first(); j != succ.npos;
             j = succ.find_next(j)) {
            NFAVertex vj = vByIndex[j];
            NFAStateSet pred2(numStates);
            buildPred(pred2, g, vj);
            if (pred2 == pred) {
                DEBUG_PRINTF("adding the sm from %zu to %u's sm\n", j, i);
                NFAStateSet tmp(numStates);
                buildSquashMask(tmp, g, vj, cr, initStates, vByIndex, pdom_tree,
                                som, som_depths, region_map, cache);
                mask &= tmp;
            }
        }

        for (size_t j = pred.find_first(); j != pred.npos;
             j = pred.find_next(j)) {
            NFAVertex vj = vByIndex[j];
            NFAStateSet succ2(numStates);
            buildSucc(succ2, g, vj);
            /* we can use j as a basis for squashing if its succs are a subset
             * of ours */
            if ((succ2 & ~succ).any()) {
                continue;
            }

            if (som) {
                /* We cannot use j to add to the squash mask of v if it may
                 * have an earlier start of match offset. ie for us j as a
                 * basis for the squash mask of v we require:
                 * maxSomDist(j) <= minSomDist(v)
                 */

                /* ** TODO ** */

                const depth &max_som_dist_j =
                    som_depths[g[vj].index].max;
                const depth &min_som_dist_v =
                    som_depths[g[v].index].min;
                if (max_som_dist_j > min_som_dist_v ||
                    max_som_dist_j.is_infinite()) {
                    /* j can't be used as it may be storing an earlier SOM */
                    continue;
                }
            }

            const CharReach &crv = g[vj].char_reach;

            /* we also require that j's report information be a subset of ours
             */
            bool seen_special = false;
            for (auto w : adjacent_vertices_range(vj, g)) {
                if (is_special(w, g)) {
                    if (!edge(v, w, g).second) {
                        goto next_j;
                    }
                    seen_special = true;
                }
            }

            // FIXME: should be subset check?
            if (seen_special && g[vj].reports != reports) {
                continue;
            }

            /* ok we can use j */
            if ((crv & ~cr).none()) {
                NFAStateSet tmp(numStates);
                buildSquashMask(tmp, g, vj, cr, initStates, vByIndex, pdom_tree,
                                som, som_depths, region_map, cache);
                mask &= tmp;
                mask.reset(j);
            }

        next_j:;
        }

        mask.set(i); /* never clear ourselves */

        if ((~mask).any()) { // i.e. some bits unset in mask
            DEBUG_PRINTF("%u squashes %zu other states\n", i, (~mask).count());
            squash.emplace(v, mask);
        }
    }

    findDerivedSquashers(g, vByIndex, pdom_tree, initStates, &squash, som,
                         som_depths, region_map, cache);

    clearMutualSquashers(g, vByIndex, squash);

    return squash;
}
Esempio n. 12
0
f2dInputJoystickImpl::f2dInputJoystickImpl(f2dInputSysImpl* pSys, HWND Win, const GUID& pGUID, bool bGlobalFocus)
	: m_pSys(pSys), m_pDev(NULL), m_DefaultListener(pSys), m_pListener(&m_DefaultListener),
	m_lXHalf(0), m_lXHalfLen(0), m_lYHalf(0), m_lYHalfLen(0), m_lZHalf(0), m_lZHalfLen(0), 
	m_lRxHalf(0), m_lRxHalfLen(0), m_lRyHalf(0), m_lRyHalfLen(0), m_lRzHalf(0), m_lRzHalfLen(0),
	m_lX(0.f), m_lY(0.f), m_lZ(0.f), m_lRx(0.f), m_lRy(0.f), m_lRz(0.f)
{
	IDirectInput8* pDev = pSys->GetHandle();

	memset(m_ButtonDown, 0, sizeof(m_ButtonDown));
	memset(m_Slider, 0, sizeof(m_Slider));
	memset(m_POV, 0, sizeof(m_POV));

	HRESULT tHR = pDev->CreateDevice(pGUID, &m_pDev, NULL);
	if(FAILED(tHR))
		throw fcyWin32COMException("f2dInputJoystickImpl::f2dInputJoystickImpl", "CreateDevice Failed.", tHR);
	
	// ÉèÖÃЭ×÷ģʽ
	fuInt tFlag = DISCL_NONEXCLUSIVE;
	if(bGlobalFocus)
		tFlag |= DISCL_BACKGROUND;
	else
		tFlag |= DISCL_FOREGROUND;
	tHR = m_pDev->SetCooperativeLevel(Win, tFlag);
	if(FAILED(tHR))
	{
		FCYSAFEKILL(m_pDev);
		throw fcyWin32COMException("f2dInputJoystickImpl::f2dInputJoystickImpl", "SetCooperativeLevel Failed.", tHR);
	}

    // ÉèÖÃÊý¾Ý¸ñʽ
	tHR = m_pDev->SetDataFormat(&DIDF_Joystick);
	if(FAILED(tHR))
	{
		FCYSAFEKILL(m_pDev);
		throw fcyWin32COMException("f2dInputJoystickImpl::f2dInputJoystickImpl", "SetDataFormat Failed.", tHR);
	}
	
	// ÉèÖûº³åÇø
	DIPROPDWORD tBufferProperty;

    tBufferProperty.diph.dwSize = sizeof(DIPROPDWORD);
    tBufferProperty.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    tBufferProperty.diph.dwObj = 0;
    tBufferProperty.diph.dwHow = DIPH_DEVICE;
    tBufferProperty.dwData = BufferSize;

    tHR = m_pDev->SetProperty(DIPROP_BUFFERSIZE, &tBufferProperty.diph);
	if(FAILED(tHR))
	{
		FCYSAFEKILL(m_pDev);
		throw fcyWin32COMException("f2dInputJoystickImpl::f2dInputJoystickImpl", "SetProperty Failed.", tHR);
	}

	initStates();

	// »ñµÃÉ豸
	tHR = m_pDev->Acquire();

	// ×¢²á
	m_pSys->RegisterDevice(this);
}