bool MyDynamicManyRectsBase::Create(ID3D11Device* pD3DDevice, UINT rectCount, UINT strideInBytes, const void* pInitialData) { _ASSERTE(m_pVertexBuffer == nullptr); _ASSERTE(m_pIndexBuffer == nullptr); _ASSERTE(pD3DDevice != nullptr); _ASSERTE(pInitialData != nullptr); // 頂点バッファ初期化データに NULL 指定は不可。テクスチャの生成のときや、OpenGL とは違う。 _ASSERTE(rectCount > 0); _ASSERTE(strideInBytes > 0); HRESULT hr = E_FAIL; const UINT vertexCount = rectCount * 4; D3D11_BUFFER_DESC vbDesc = {}; vbDesc.ByteWidth = vertexCount * strideInBytes; vbDesc.Usage = D3D11_USAGE_DYNAMIC; vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; D3D11_SUBRESOURCE_DATA vbSubrData = {}; vbSubrData.pSysMem = pInitialData; hr = pD3DDevice->CreateBuffer(&vbDesc, &vbSubrData, m_pVertexBuffer.ReleaseAndGetAddressOf()); if (FAILED(hr)) { return false; } std::vector<TIndex> indexArray(rectCount * 6); for (size_t i = 0; i < rectCount; ++i) { // CCW indexArray[i * 6 + 0] = TIndex(0 + (i * 4)); indexArray[i * 6 + 1] = TIndex(2 + (i * 4)); indexArray[i * 6 + 2] = TIndex(1 + (i * 4)); indexArray[i * 6 + 3] = TIndex(1 + (i * 4)); indexArray[i * 6 + 4] = TIndex(2 + (i * 4)); indexArray[i * 6 + 5] = TIndex(3 + (i * 4)); } D3D11_BUFFER_DESC ibDesc = {}; ibDesc.ByteWidth = UINT(indexArray.size() * sizeof(TIndex)); ibDesc.Usage = D3D11_USAGE_DEFAULT; ibDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; D3D11_SUBRESOURCE_DATA ibSubrData = {}; ibSubrData.pSysMem = &indexArray[0]; hr = pD3DDevice->CreateBuffer(&ibDesc, &ibSubrData, m_pIndexBuffer.ReleaseAndGetAddressOf()); if (FAILED(hr)) { return false; } m_rectCount = rectCount; m_vertexBufferSizeInBytes = vbDesc.ByteWidth; return true; }
/** * Создает полностью детерминированную зависимость * Все недетерминированные выражения в индексах заменяются на * диапазон 0..размерность */ stringSet createActual(const stringSet &arg) { stringSet result; stringSet::const_iterator beg = arg.begin(); stringSet::const_iterator end = arg.end(); while (beg != end) { TParam cur = *--end; if (!cur. isArrayElement()) { result. push_back(cur); // fixme - remember arrayScalar continue; } // index case int dim = cur. getDimension(); TIndex *indexes = cur. getIndexes(); TDimensionList list = cur. getTypeInfo(). second; TDimensionList::iterator beg = list. begin(); for (int i = dim - 1; i >= 0; i--, beg++) { if (indexes[i]. isAtom()) { indexes[i] = TIndex(TRange(0, (*beg - 1))); continue; } } // этот элемент будет прозрачный в силу изначальной недетерминированности его индекса TParam res(cur. getName(), indexes, dim, cur.getTypeInfo(), true); //cout<<"Create Actual :"<<res<<endl; concat(result, toLocalMemoryUse(res)); delete[] indexes; } packUnifySet(result); return result; }
inline TIndex GetIndexChild(TIndex const & index, int i) { TIndex child(index); if (child.m_group == TIndex::INVALID) child.m_group = i; else if (child.m_country == TIndex::INVALID) child.m_country = i; else if (child.m_region == TIndex::INVALID) child.m_region = i; return child; } inline TIndex GetIndexParent(TIndex const & index) { ASSERT(index != TIndex(), ()); TIndex parent(index); if (parent.m_region != TIndex::INVALID) parent.m_region = TIndex::INVALID; else if (parent.m_country != TIndex::INVALID) parent.m_country = TIndex::INVALID; else parent.m_group = TIndex::INVALID; return parent; } CountryTree::CountryTree(Framework & framework) { m_layout.reset(new ActiveMapsLayout(framework)); ConnectToCoreStorage();
struct in_out elaborateArrayIndex(const Context &context, struct postfix_addon &arg, bool left, bool ifContext) { // Only [] allowed w/o . or -> struct postfix_addon *temp = &arg; // copy int size = 0; struct in_out result; // find sequence length while (temp->_arrayindex_ != NULL) { size++; if (temp->_main_. _addon_ != NULL) { // postfix-addon case temp = temp->_main_. _addon_; } else { break; } //if (temp->_main_. _primary_ != NULL) break; } // now we must have ref to primary else - semantic error if (temp->_main_. _primary_ == NULL) sserror("Only scalars and arrays are supported", temp->_main_.lt); string name; int dimension = size; if (temp->_main_. _primary_-> _name_ != NULL) { name = string(temp->_main_. _primary_-> _name_); } else { sserror("Name of array required", temp->_main_._primary_->lt); } // create storage TIndex *ref = new TIndex[size]; temp = &arg; while (temp->_arrayindex_ != NULL) { size--; concat(result, scanExpression(context, *temp->_arrayindex_, ifContext), options. get ("[]")); ref[size] = TIndex(temp->_arrayindex_); if (temp->_main_. _addon_ != NULL) { // postfix-addon case temp = temp->_main_. _addon_; } else { break; } } //cout<<"Getting name2 '"<<name<<"'"<<endl; TParam par(name, ref, dimension, context. getTypeInfo(name), ifContext); if (left == true) { result. insertOut(par); } else { result. insertIn(par); } delete[] ref; return result; }
void CMaterialEffects::LoadSpreadSheet() { m_bDataInitialized = true; Reset(false); CryComment("[MFX] Init"); IXmlTableReader* const pXmlTableReader = gEnv->pSystem->GetXmlUtils()->CreateXmlTableReader(); if (!pXmlTableReader) { GameWarning("[MFX] XML system failure"); return; } // The root node. XmlNodeRef root = gEnv->pSystem->LoadXmlFromFile( MATERIAL_EFFECTS_SPREADSHEET_FILE ); if (!root) { // The file wasn't found, or the wrong file format was used GameWarning("[MFX] File not found or wrong file type: %s", MATERIAL_EFFECTS_SPREADSHEET_FILE); pXmlTableReader->Release(); return; } CryComment("[MFX] Loaded: %s", MATERIAL_EFFECTS_SPREADSHEET_FILE); if (!pXmlTableReader->Begin(root)) { GameWarning("[MFX] Table not found"); pXmlTableReader->Release(); return; } // temporary multimap: we store effectstring -> [TIndexPairs]+ there typedef std::vector<TIndexPair> TIndexPairVec; typedef std::map<CConstCharArray, TIndexPairVec, less_CConstCharArray> TEffectStringToIndexPairVecMap; TEffectStringToIndexPairVecMap tmpEffectStringToIndexPairVecMap; int rowCount = 0; int warningCount = 0; CConstCharArray cell; string cellString; // temporary string // When we've gone down more rows than we have columns, we've entered special object space int maxCol = 0; std::vector<CConstCharArray> colOrder; std::vector<CConstCharArray> rowOrder; m_surfaceIdToMatrixEntry.resize(0); m_surfaceIdToMatrixEntry.resize(kMaxSurfaceCount, TIndex(0)); m_ptrToMatrixEntryMap.clear(); m_customConvert.clear(); // Iterate through the table's rows for (;;) { int nRowIndex = -1; if (!pXmlTableReader->ReadRow(nRowIndex)) break; // Iterate through the row's columns for (;;) { int colIndex = -1; if (!pXmlTableReader->ReadCell(colIndex, cell.ptr, cell.count)) break; if (cell.count <= 0) continue; cellString.assign(cell.ptr, cell.count); if (rowCount == 0 && colIndex > 0) { const int matId = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceTypeManager()->GetSurfaceTypeByName(cellString.c_str(), "MFX", true)->GetId(); if (matId != 0 || /* matId == 0 && */ stricmp(cellString.c_str(), "mat_default") == 0) // if matId != 0 or it's the mat_default name { // CryLogAlways("[MFX] Material found: %s [ID=%d] [mapping to row/col=%d]", cellString.c_str(), matId, colCount); if (m_surfaceIdToMatrixEntry.size() < matId) { m_surfaceIdToMatrixEntry.resize(matId+1); if (matId >= kMaxSurfaceCount) { assert (false && "MaterialEffects.cpp: SurfaceTypes exceeds 256. Reconsider implementation."); CryLogAlways("MaterialEffects.cpp: SurfaceTypes exceeds %d. Reconsider implementation.", kMaxSurfaceCount); } } m_surfaceIdToMatrixEntry[matId] = colIndex; } else { GameWarning("MFX WARNING: Material not found: %s", cellString.c_str()); ++warningCount; } colOrder.push_back(cell); } else if (rowCount > 0 && colIndex > 0) { //CryLog("[MFX] Event found: %s", cellString.c_str()); tmpEffectStringToIndexPairVecMap[cell].push_back(TIndexPair(rowCount, colIndex)); } else if (rowCount > maxCol && colIndex == 0) { IEntityClass *pEntityClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(cellString.c_str()); //CryLog("[MFX] Object class ID: %d", (int)pEntityClass); if (pEntityClass) { // CryComment("[MFX] Found EntityClass based entry: %s [mapping to row/col=%d]", cellString.c_str(), rowCount); m_ptrToMatrixEntryMap[pEntityClass] = rowCount; } else { // CryComment("[MFX] Found Custom entry: %s [mapping to row/col=%d]", cellString.c_str(), rowCount); cellString.MakeLower(); m_customConvert[cellString] = rowCount; ++warningCount; } } else if (rowCount > 0 && colIndex == 0) { rowOrder.push_back(cell); } // Heavy-duty debug info //CryLog("[MFX] celldata = %s at (%d, %d) rowCount=%d colIndex=%d maxCol=%d", curCellData->getContent(), i, j, rowCount, colIndex, maxCol); // Check if this is the furthest column we've seen thus far if (colIndex > maxCol) maxCol = colIndex; SLICE_AND_SLEEP(); } // Increment row counter ++rowCount; } // now postprocess the tmpEffectStringIndexPairVecMap and generate the m_matmatArray { // create the matmat array. // +1, because index pairs are in range [1..rowCount][1..maxCol] m_surfacesLookupTable.Create(rowCount+1,maxCol+1); TEffectStringToIndexPairVecMap::const_iterator iter = tmpEffectStringToIndexPairVecMap.begin(); TEffectStringToIndexPairVecMap::const_iterator iterEnd = tmpEffectStringToIndexPairVecMap.end(); string libName; string effectName; string tmpString; while (iter != iterEnd) { // lookup effect tmpString.assign(iter->first.ptr, iter->first.count); ToEffectString(tmpString, libName, effectName); TMFXContainerPtr pEffectContainer = InternalGetEffect(libName, effectName); TMFXEffectId effectId = pEffectContainer ? pEffectContainer->GetParams().effectId : InvalidEffectId; TIndexPairVec::const_iterator vecIter = iter->second.begin(); TIndexPairVec::const_iterator vecIterEnd = iter->second.end(); while (vecIter != vecIterEnd) { const TIndexPair& indexPair = *vecIter; // CryLogAlways("[%d,%d]->%d '%s'", indexPair.first, indexPair.second, effectId, tmpString.c_str()); m_surfacesLookupTable(indexPair.first,indexPair.second) = effectId; ++vecIter; } ++iter; } } if (CMaterialEffectsCVars::Get().mfx_Debug > 0) { CryLogAlways("[MFX] RowCount=%d MaxCol=%d (*=%d)", rowCount, maxCol,rowCount*maxCol); for (int y=0; y<m_surfacesLookupTable.m_nRows; ++y) { for (int x=0; x<m_surfacesLookupTable.m_nCols; ++x) { TMFXEffectId idRowCol = m_surfacesLookupTable.GetValue(y,x, USHRT_MAX); assert (idRowCol != USHRT_MAX); TMFXContainerPtr pEffectRowCol = InternalGetEffect(idRowCol); if (pEffectRowCol) { CryLogAlways("[%d,%d] -> %d '%s:%s'", y, x, idRowCol, pEffectRowCol->GetParams().libraryName.c_str(), pEffectRowCol->GetParams().name.c_str()); if (y<m_surfacesLookupTable.m_nCols) { TMFXEffectId idColRow = m_surfacesLookupTable.GetValue(x,y, USHRT_MAX); assert (idColRow != USHRT_MAX); TMFXContainerPtr pEffectColRow = InternalGetEffect(idColRow); if (idRowCol != idColRow) { if (pEffectColRow) { GameWarning("[MFX] Identity mismatch: ExcelRowCol %d:%d: %s:%s != %s:%s", y+1, x+1, pEffectRowCol->GetParams().libraryName.c_str(), pEffectRowCol->GetParams().name.c_str(), pEffectColRow->GetParams().libraryName.c_str(), pEffectColRow->GetParams().name.c_str()); } else { GameWarning("[MFX] Identity mismatch: ExcelRowCol %d:%d: %s:%s != [not found]", y+1, x+1, pEffectRowCol->GetParams().libraryName.c_str(), pEffectRowCol->GetParams().name.c_str()); } } } } } } } // check that we have the same number of columns and rows if (colOrder.size() > rowOrder.size()) { GameWarning("[MFX] Found %d Columns, but not enough rows specified (%d)", (int32)colOrder.size(), (int32)rowOrder.size()); } // check that column order matches row order if (CMaterialEffectsCVars::Get().mfx_Debug > 0) { string colName; string rowName; for (int i=0;i<colOrder.size(); ++i) { colName.assign(colOrder[i].ptr, colOrder[i].count); if (i < rowOrder.size()) { rowName.assign(rowOrder[i].ptr, rowOrder[i].count); } else { rowName.clear(); } // CryLogAlways("ExcelColRow=%d col=%s row=%s", i+2, colName.c_str(), rowName.c_str()); if (colName != rowName) { GameWarning("ExcelColRow=%d: %s != %s", i+2, colName.c_str(), rowName.c_str()); } } } pXmlTableReader->Release(); }