/// @brief Initialize the vertex buffer. /// /// @param _nNbElements Number of elements. /// @param _nNbVertices Number of vertex. /// /// @return True if initialized successfully. bool CVertexBuffer::Initialize(const SVertexDeclaration *_pVertexDeclarations, uint32 _nNbElements, uint32 _nNbVertices) { SAM_ASSERT(m_pBuffer == NULL, "Vertex buffer already allocated"); SAM_ASSERT(_pVertexDeclarations != NULL, "Vertex declaration is null"); m_nNbVertices = _nNbVertices; m_nNbElements = _nNbElements; // Compute the stride. m_nStride = _pVertexDeclarations[m_nNbElements - 1].m_nOffset; m_nStride += GetSizeByType(_pVertexDeclarations[m_nNbElements - 1].m_eType) * _pVertexDeclarations[m_nNbElements - 1].m_nNbComponents; // Setup the vertex buffer. D3D11_BUFFER_DESC bufferDesc; ZeroMemory(&bufferDesc, sizeof(D3D11_BUFFER_DESC)); bufferDesc.Usage = D3D11_USAGE_DYNAMIC; bufferDesc.ByteWidth = m_nStride * m_nNbVertices; bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; HRESULT hResult = g_Env->pRenderWindow->GetD3DDevice()->CreateBuffer(&bufferDesc, NULL, &m_pBuffer); if(hResult != S_OK) { g_Env->pRenderWindow->LogError(hResult); return false; } // Memorize the configuration. m_pVertexDeclaration = SAM_ALLOC_ARRAY(SVertexDeclaration, m_nNbElements); memcpy(m_pVertexDeclaration, _pVertexDeclarations, sizeof(SVertexDeclaration) * m_nNbElements); return true; }
// Delete focused folder in the file tree (archetype, package, world). void CMainWindow::DeleteFolder() { QTreeWidgetItem *pCurrentItem = ui->projectsTreeWidget->currentItem(); CFolder *pFolder = pCurrentItem->data(0, Qt::UserRole).value<CFolder*>(); SAM_ASSERT(pFolder && pFolder->GetDir().exists(), "Current directory doesn't exist!"); QString sMessage = "Are you sure you want to delete "; if(pCurrentItem->parent() == m_pTreePackages) { sMessage += "the package '"; } else { sMessage += "the folder '"; } // Ask the user to be sure. switch(CSamBox::Message(sMessage + pFolder->GetDir().dirName() + "' ?")) { case QMessageBox::No: case QMessageBox::Cancel: return; } // Delete the content. pFolder->GetDir().removeRecursively(); delete pCurrentItem; SAM_DELETE pFolder; }
// Create entity system. CEntitySystem *CreateEntitySystem(Env *p_pEnv) { SAM_ASSERT(p_pEnv->m_pEntitySystem == NULL, "Entity System was already created."); ModuleInit(p_pEnv); // TODO: creer le module. return NULL; }
/// @brief Lock vertex buffer. /// /// @param _nIndex Index of the vertex buffer. /// @param _pBuffer Vertex buffer. /// @param _nSize Size to read. /// /// @return True if it mapped successfully. bool CVertexBuffer::MapRead(uint32 _nIndex, void *_pBuffer, uint32 _nSize) { SAM_ASSERT(_pBuffer != NULL, "Buffer is null"); SAM_ASSERT(_nIndex < m_nNbVertices, "Index is out of range"); // Lock the vertex buffer. D3D11_MAPPED_SUBRESOURCE subressource; ZeroMemory(&subressource, sizeof(D3D11_MAPPED_SUBRESOURCE)); HRESULT hResult = g_Env->pRenderWindow->GetD3DContext()->Map(m_pBuffer, _nIndex, GetDX11Map(VU_Read_Only), 0, &subressource); if(hResult != S_OK) { g_Env->pRenderWindow->LogError(hResult); return false; } _pBuffer = subressource.pData; return true; }
/// @brief Initialize the device. /// /// @return true if no error occurred. bool CKeyboard::Init() { SAM_ASSERT(m_pKeyboard == NULL, "Keyboard is already initialized"); // create device HRESULT hResult = g_Env->pInputManager->GetInputSystem()->CreateDevice(GUID_SysKeyboard, &m_pKeyboard, NULL); if(FAILED(hResult)) { SamLogWarning("Unable to create keyboard device, error code: %d\n", hResult); return false; } hResult = m_pKeyboard->SetDataFormat(&c_dfDIKeyboard); if(FAILED(hResult)) { SamLogError("Unable to set data format for keyboard device, error code: %d\n", hResult); return false; } #ifdef ENABLE_BUFFER_MODE // Enable buffered mode. DIPROPDWORD oProperty; oProperty.diph.dwSize = sizeof(DIPROPDWORD); oProperty.diph.dwHeaderSize = sizeof(DIPROPHEADER); oProperty.diph.dwObj = 0; oProperty.diph.dwHow = DIPH_DEVICE; oProperty.dwData = KEY_BUFFERSIZE; hResult = m_pKeyboard->SetProperty(DIPROP_BUFFERSIZE, &oProperty.diph); if(FAILED(hResult)) { SamLogError("Unable to set buffered mode for keyboard device, error code: %d\n", hResult); return false; } #endif // Exclusive by default. if(!SetExclusiveMode(false)) return false; // Enable the device. if(!Enable(true)) return false; return true; }
/// @brief Exclusive mode. /// /// @param _bExclusive True to active exclusive mode. /// /// @return True if no error occurred. bool CKeyboard::SetExclusiveMode(bool _bExclusive) { SAM_ASSERT(m_pKeyboard != NULL, "Keyboard was not initialized"); int nFlags = DISCL_FOREGROUND; if(_bExclusive) nFlags |= DISCL_EXCLUSIVE; else nFlags |= DISCL_NONEXCLUSIVE | DISCL_NOWINKEY; HRESULT hResult = m_pKeyboard->SetCooperativeLevel(g_Env->pInputManager->GetHWND(), nFlags); if(FAILED(hResult)) { SamLogWarning("Unable to set exclusive mode for keyboard device, error code: %d", hResult); return false; } return true; }
/// @brief Enable the device. /// /// @param _bEnable True to enable the device. /// /// @return True if no error occurred. bool CKeyboard::Enable(bool _bEnable) { SAM_ASSERT(m_pKeyboard != NULL, "Keyboard was not initialized"); m_bEnabled = _bEnable; HRESULT hResult = S_OK; if(_bEnable) hResult = m_pKeyboard->Acquire(); else hResult = m_pKeyboard->Unacquire(); if(FAILED(hResult)) { SamLogWarning("Unable to enable the keyboard device, error code: %d", hResult); return false; } return true; }
// Destroy entity system. void DestroyEntitySystem() { SAM_ASSERT(g_Env->m_pEntitySystem != NULL, "Entity System was already freed"); // TODO: supprimer le module. }
/// @brief Retrieves the number of component. /// /// @param _nIndex Index of the element. /// /// @return The number of component. uint32 CVertexBuffer::GetNbComponent(uint32 _nIndex) const { SAM_ASSERT(_nIndex < m_nNbElements, "Index is out of range"); return m_pVertexDeclaration[_nIndex].m_nNbComponents; }
/// @brief Retrieves type id. /// /// @param _nIndex Index of the element. /// /// @return Type ID. ETypeID CVertexBuffer::GetTypeID(uint32 _nIndex) const { SAM_ASSERT(_nIndex < m_nNbElements, "Index is out of range"); return m_pVertexDeclaration[_nIndex].m_eType; }
/// @brief Retrieves the semantic by index. /// /// @param _nIndex Index of the element. /// /// @return The semantic or VS_Nb if not found. EVertexSemantic CVertexBuffer::GetSemantic(uint32 _nIndex) const { SAM_ASSERT(_nIndex < m_nNbElements, "Index is out of range"); return m_pVertexDeclaration[_nIndex].m_eSemantic; }