Esempio n. 1
0
status_t
Inode::Create(const char* name, int mode, int perms, OpenFileCookie* cookie,
	OpenDelegationData* data, ino_t* id)
{
	ASSERT(name != NULL);
	ASSERT(cookie != NULL);
	ASSERT(data != NULL);

	cookie->fMode = mode;
	cookie->fLocks = NULL;

	OpenState* state = new(std::nothrow) OpenState;
	if (state == NULL)
		return B_NO_MEMORY;

	status_t result = CreateState(name, mode, perms, state, data);
	if (result != B_OK) {
		delete state;
		return result;
	}

	cookie->fOpenState = state;
	cookie->fFileSystem = fFileSystem;

	*id = FileIdToInoT(state->fInfo.fFileId);

	fFileSystem->AddOpenFile(state);
	fFileSystem->Root()->MakeInfoInvalid();

	notify_entry_created(fFileSystem->DevId(), ID(), name, *id);

	return B_OK;
}
Esempio n. 2
0
void StateStack::ApplyPendingChanges()
{
	for( Impl::PendingChange change : pImpl->mPendingList )
	{
		switch( change.action )
		{
			case StateStack::Action::Push:
				pImpl->mStack.push_back( CreateState( change.stateID ) );
				break;

			case StateStack::Action::Pop:
				pImpl->mStack.back()->OnDestroy();
				pImpl->mStack.pop_back();

				if ( !pImpl->mStack.empty() )
				{
					pImpl->mStack.back()->OnActivate();
				}
				break;

			case StateStack::Action::Clear:
				for ( State::StatePtr & state : pImpl->mStack )
				{
					state->OnDestroy();
				}

				pImpl->mStack.clear();
				break;
		}
	}

	pImpl->mPendingList.clear();
}
void StateManager::SwitchTo(const StateType& l_type){
	m_shared->m_eventManager->SetCurrentState(l_type);
	m_shared->m_guiManager->SetCurrentState(l_type);
	m_shared->m_soundManager->ChangeState(l_type); // new
	for (auto itr = m_states.begin();
		itr != m_states.end(); ++itr)
	{
		if (itr->first == l_type){
			m_states.back().second->Deactivate();
			StateType tmp_type = itr->first;
			BaseState* tmp_state = itr->second;
			m_states.erase(itr);
			m_states.emplace_back(tmp_type, tmp_state);
			tmp_state->Activate();
			m_shared->m_wind->GetRenderWindow()->setView(tmp_state->GetView());
			return;
		}
	}

	// State with l_type wasn't found.
	if (!m_states.empty()){ m_states.back().second->Deactivate(); }
	CreateState(l_type);
	m_states.back().second->Activate();
	m_shared->m_wind->GetRenderWindow()->setView(m_states.back().second->GetView());
}
Esempio n. 4
0
void Queen(int * board, int n)
{
	Stack * StateStack;
	if ( CreateStack(&StateStack, sizeof(State), n * n) == false )
	{
		printf("Loi: Khong du bo nho!\n");
		exit(0);
	}
	
	int i, k;
	
	i = 0;
	k = 0;
	
	State * state;
	
	do
	{
		if (k < n)
		{
			for (i = 0; i < n; ++i)
			{
				state = CreateState(k, i);
				push(StateStack, state);
			}
		}
		
		state = pop(StateStack);
		k = state->k;
		i = state->i;
		board[k] = i;
		
		free(state);
		
		if (k == n - 1)
		{
			do
			{
				if (CheckBoard(board, n) == true)
				{
					Mark(board, n);
				}
				
				state = pop(StateStack);
				k = state->k;
				i = state->i;
				board[k] = i;
				
				free(state);
				
			} while (k == n-1);
		}
		
		++k;
		
	} while (CheckEmpty(StateStack) != true);
	
	DestroyStack(StateStack);
}
dAutomataState* dDeterministicFiniteAutonata::CreateTargetState (dTree<dAutomataState*,dAutomataState*>& subSet, int id)
{
	dAutomataState* const state = CreateState (id);
	dTree<dAutomataState*,dAutomataState*>::Iterator iter (subSet);
	for (iter.Begin(); iter; iter ++) {
		dAutomataState* const subSetState = iter.GetNode()->GetInfo();
		state->m_myNFANullStates.Append(subSetState);
		if (subSetState->m_exitState) {
			state->m_exitState = true;
		}
	}
	return state;
}
Esempio n. 6
0
CMDPSTATE* ADPlanner::GetState(int stateID, ADSearchStateSpace_t* pSearchStateSpace)
{	

	if(stateID >= (int)environment_->StateID2IndexMapping.size())
	{
		printf("ERROR int GetState: stateID is invalid\n");
		exit(1);
	}

	if(environment_->StateID2IndexMapping[stateID][ADMDP_STATEID2IND] == -1)
		return CreateState(stateID, pSearchStateSpace);
	else
		return pSearchStateSpace->searchMDP.StateArray[environment_->StateID2IndexMapping[stateID][ADMDP_STATEID2IND]];

}
Esempio n. 7
0
void StateStack::ApplyPendingChanges()
{
	for ( PendingChange_t& change : m_pendingList )
	{
		switch (change.action)
		{
			case Push:
				m_stack.push_back(CreateState(change.stateID));
				break;

			case Pop:
				m_stack.pop_back();
				break;

			case Clear:
				m_stack.clear();
				break;
		}
	}

	m_pendingList.clear();
}
void Tokenizer<TokenEnumType, InputType>::LoadSymbols(const SymbolTable &symbols)
{
    for (auto &symbol : symbols)
    {
        auto currentState = m_rootState;

        auto &value = symbol.first;
        auto length = value.size( );

        for (size_t i = 0; i < length; ++i)
        {
            auto character = value[ i ];
            typename StateType::Handle nextState;

            auto isLastCharacter = i == length - 1;

            auto search = currentState->m_edges.find( character );

            // doesn't already exist
            if (search == currentState->m_edges.end( ))
            {
                nextState = CreateState( );

                currentState->AddEdge( nextState, character );
            } 
            else
            {
                nextState = search->second;
            }

            if (isLastCharacter)
                nextState->m_acceptingType = symbol.second;

            currentState = nextState;
        }
    }
}
Esempio n. 9
0
void StateStack::ApplyPendingStackChanges() {
    for (auto itr = pendingStackChanges.begin();
         itr != pendingStackChanges.end(); itr++) {
        PendingStackChange change = (*itr);
        switch (change.action) {
            case PUSH:
                stack.push_back(CreateState(change.stateID));
                break;
            
            case POP:
                stack.pop_back();
                if (stack.size()) {
                    stack.back()->SetActive(true);
                }
                break;
                
            case CLEAR:
                stack.clear();
                break;
        }
    }
    
    pendingStackChanges.clear();
}
Esempio n. 10
0
int main(){
	auto pLogger = CB::Log::CLogger::GetInstance();
	pLogger->AddStream(CB::IO::File::Open(L"main.log", CB::IO::File::AccessType::WriteOnly, CB::IO::File::OpenAction::AlwaysCreate).Cast<CB::IO::IStream>());
	pLogger->AddStream(CB::IO::Console::Create().Cast<CB::IO::IStream>(), CB::Log::CTextFormatter::Create(CB::String::Encoding::ANSI).Cast<CB::Log::IEntryFormatter>());
	pLogger->SetDebugMode(true);

	try{
		auto pWinDriver = CB::Window::LoadDriver(L"MSWindowDriver");
		auto pGraphicDriver = CB::Graphic::LoadDriver(L"OGLGraphicDriver");
		{
			auto pWinManager = pWinDriver->CreateManager();
			auto pGraphicManager = pGraphicDriver->CreateManager(pWinManager);
			
			CB::Math::CSize outSize(640, 480);
			auto pWindow = pWinManager->CreateWindow(L"GraphicTest", CB::Window::Style::Single, outSize);

			auto pGraphicAdapter = pGraphicManager->GetDefaultAdapter();

			CB::Graphic::CDisplayMode dispMode(pWindow->GetSize(), 0, CB::Graphic::BufferFormat::B8G8R8X8);
			CB::Graphic::CDeviceDesc devDesc(pWindow, dispMode, CB::Graphic::BufferFormat::D24S8, false);

			CB::Collection::CList<CB::Graphic::FeatureLevel> featureLevels;
			featureLevels.Add(CB::Graphic::FeatureLevel::Level_1);

			auto pGraphicDevice = pGraphicAdapter->CreateDevice(pWindow, devDesc, featureLevels);

			pWindow->OnClose += CB::Signals::CFunc<const bool, CB::CRefPtr<CB::Window::IWindow>>(CloseEvent);

			pWindow->SetVisible(true);

			CB::Graphic::CDepthStencilStateDesc depthDesc;
			depthDesc.bDepthTestEnabled = true;
			depthDesc.uDepthFunction = CB::Graphic::CompareFunc::LessEqual;
			auto pDepthState = pGraphicDevice->CreateState(depthDesc);
			pGraphicDevice->SetState(pDepthState.Cast<CB::Graphic::IDeviceState>());

			CB::Graphic::CRasterizerStateDesc rastDesc;
			rastDesc.uCullMode = CB::Graphic::CullMode::None;
			auto pRastState = pGraphicDevice->CreateState(rastDesc);
			pGraphicDevice->SetState(pRastState.Cast<CB::Graphic::IDeviceState>());

			CB::Graphic::CBlendStateDesc blendDesc;
			blendDesc.ColorBlend.uDestOperand = CB::Graphic::BlendOption::OneMinusSourceAlpha;
			blendDesc.ColorBlend.uSourceOperand = CB::Graphic::BlendOption::SourceAlpha;
			blendDesc.ColorBlend.uOperation = CB::Graphic::BlendOperation::Add;
			blendDesc.AlphaBlend.uDestOperand = CB::Graphic::BlendOption::OneMinusSourceAlpha;
			blendDesc.AlphaBlend.uSourceOperand = CB::Graphic::BlendOption::SourceAlpha;
			blendDesc.AlphaBlend.uOperation = CB::Graphic::BlendOperation::Add;
			blendDesc.bEnabled[0] = true;
			auto pBlendState = pGraphicDevice->CreateState(blendDesc);
			pGraphicDevice->SetState(pBlendState.Cast<CB::Graphic::IDeviceState>());

			auto pFontManager = CB::Font::CManager::Create();

			auto pFontStream = CB::IO::File::Open(L"Assets/font.ttf").Cast<CB::IO::IStream>();
			auto pFont = pFontManager->Load(pFontStream);
			
			pFont->SelectFace(0);
			pFont->SetSize(24);

			CB::Collection::CList<CB::Tools::CFontCharDesc> charDescs;
			CB::Tools::CFontTextureGenerator fontGen(pGraphicDevice);

			fontGen.MaxTextureSize.Set(512, 512);
			auto pTexture = fontGen.Generate(pFont, charDescs);

			CB::Tools::CTextMeshGenerator textGen(charDescs);
			CB::Tools::CMeshRawIVT textMesh;

			textGen.Generate(L"Marek	M³ynarski!", textMesh);

			CB::Collection::CList<CB::Graphic::CVertexElement> vEls;
			vEls.Add(CB::Graphic::CVertexElement(0, L"vinput.vPosition", CB::Graphic::VertexType::Float, 3, 0));
			vEls.Add(CB::Graphic::CVertexElement(1, L"vinput.vTexCoord", CB::Graphic::VertexType::Float, 2, 0));

			GraphicTest::CShaderLoader shaders(pGraphicDevice, L"Shaders/TextureShader.cg");

			auto pTextDecl = pGraphicDevice->CreateVertexDeclaration(shaders.pVertexShader, vEls);

			auto pTextVertexBuffer = pGraphicDevice->CreateBuffer(CB::Graphic::BufferType::Vertex, CB::Graphic::BufferUsage::Dynamic, CB::Graphic::BufferAccess::Write, textMesh.Vertices);
			auto pTextTCoordBuffer = pGraphicDevice->CreateBuffer(CB::Graphic::BufferType::Vertex, CB::Graphic::BufferUsage::Dynamic, CB::Graphic::BufferAccess::Write, textMesh.TexCoords);
			auto pTextIndexBuffer = pGraphicDevice->CreateBuffer(CB::Graphic::BufferType::Index, CB::Graphic::BufferUsage::Dynamic, CB::Graphic::BufferAccess::Write, textMesh.Indices);

			float32 fAspect = (float32)outSize.Width / (float32)outSize.Height;
			CB::Math::CMatrix mProj = CB::Math::CMatrix::GetPerspective(fAspect, 60.0f, 1.0f, 100.0f);
			CB::Math::CMatrix mView = CB::Math::CMatrix::GetTranslation(-4.0f, 0.0f, -3.4f);
			CB::Math::CMatrix mModel = CB::Math::CMatrix::GetIdentity();

			shaders.pFragmentShader->SetSampler(L"texDiffuse", pTexture.Cast<CB::Graphic::IBaseTexture>());
			pTexture->SetFilters(CB::Graphic::TextureFilter::Linear, CB::Graphic::TextureFilter::Linear, CB::Graphic::TextureFilter::Linear);
			pTexture->SetAnisotropy(8);
			//g_pTexture = texture.pTexture;			

			while(g_bRun){
				pGraphicDevice->Clear(1.0f, 1);
				pGraphicDevice->Clear(CB::Math::CColor(1.0f, 0.5f, 0.0f, 1.0f));

				pGraphicDevice->BeginRender();

				pGraphicDevice->SetShader(shaders.pVertexShader);
				pGraphicDevice->SetShader(shaders.pFragmentShader);

				static float32 fV = 0.0f;
				fV += 20 * g_Timer.GetTimeDelta();
				mModel = CB::Math::CMatrix::GetRotation(CB::Math::AxisOrientation::AxisX, fV);

				shaders.pVertexShader->SetUniform(L"vinput.mProj", mProj);
				shaders.pVertexShader->SetUniform(L"vinput.mView", mView);
				shaders.pVertexShader->SetUniform(L"vinput.mModel", mModel);

				pGraphicDevice->SetVertexDeclaration(pTextDecl);
				pGraphicDevice->SetVertexBuffer(0, pTextVertexBuffer);
				pGraphicDevice->SetVertexBuffer(1, pTextTCoordBuffer);
				pGraphicDevice->SetIndexBuffer(pTextIndexBuffer);

				pGraphicDevice->RenderIndexed(textMesh.uNumberOfPolygons);

				pGraphicDevice->EndRender();

				g_Timer.Update();
				pWinManager->ProcessEvents();

				float fFPS = 1.0f / (g_Timer.GetTimeDelta() == 0.0f ? 1.0f : g_Timer.GetTimeDelta());
				uint32 uFPS = (uint32)fFPS;

				textMesh.Clear();
				textGen.Generate(L"FPS: " + CB::String::ToString(uFPS), textMesh);

				pTextVertexBuffer->LoadData(textMesh.Vertices);
				pTextTCoordBuffer->LoadData(textMesh.TexCoords);
				pTextIndexBuffer->LoadData(textMesh.Indices);

				pGraphicDevice->Swap();
			}

			g_pTexture.Release();
		}
	}
	catch(CB::Exception::CException& Exception){
		CB::Log::Write(Exception, CB::Log::LogLevel::Fatal);
		CB::Message::Show(Exception, CB::Message::Icon::Error);
	}
	return 0;
}
Tokenizer<TokenEnumType, InputType>::Tokenizer(void)
    : m_rootState( CreateState( ) )
{
    
}