}bool GameLayerMapBorder::isBorderCell(int x,int y,unsigned char type,BorderCell& cellOut) { static int vecs[][2]= { {-1,0},{1,0}, {0,1},{0,-1}, {-1,1},{-1,-1}, {1,1},{1,-1} }; bool bRet=false; if(_mapGrid->getValue(x,y)==GridType::None)return false; int mask = 0; /// Test Log bool masks[8]={false}; /// for (int i=0; i<8; i++) { if (_mapGrid->isOutMapGrid(x+vecs[i][0], y+vecs[i][1])) { continue; } if(_mapGrid->getValue(x+vecs[i][0], y+vecs[i][1]) == GridType::None) { mask |= (int)pow(2,i); bRet=true; masks[i] = true; } } if (bRet&&BorderCell::isValidBorderCell((BorderMaskType)mask)) { cellOut._cell=GridCell(x,y); cellOut._maskDir = (BorderMaskType)mask; } else if(bRet) { ///// Test Log undefine BorderCell static std::set<int> set; if(set.find(mask)==set.end()) { log("Border Mask %d%d%d%d%d%d%d%d",masks[0],masks[1], masks[2],masks[3],masks[4],masks[5],masks[6],masks[7]); set.insert(mask); } ///// cellOut._cell=GridCell(x,y); cellOut._maskDir = (BorderMaskType)mask; bRet=false; } return bRet; }
void GridDefinition::addColumnDefinition(qreal size) { _columns << GridCell(size, _columnSize); _columnSize += size; _invColumnSize = 1.0f / _columnSize; }
void GridDefinition::addRowDefinition(qreal size) { _rows << GridCell(size, _rowSize); _rowSize += size; _invRowSize = 1.0f / _rowSize; }
void GameLayerMapBorder::updateBorder(int x,int y, int width,int height) { //updateBorderCheckRemove(x,y,width,height); std::set<BorderCell> borderSet; for (int i = x; i < x+width; i++) { for (int j = y; j< y+height; j++) { GridCell gridCell = GridCell(i,j);//=_mapGrid->getGridCellByView(i, j); if (_mapGrid->isOutMapGrid(gridCell._x, gridCell._y)) { continue; } BorderCell cell; if (isNewBorderCell(gridCell._x, gridCell._y,(unsigned char)GridType::Dirt,cell)) { borderSet.insert(cell); } } } _isBox2DBorderLineDirt = true; std::list<GameBorderLine> list(std::move(getBorderlines(std::move(borderSet)))); if (list.size()<=0) { return; } for(auto& line :list) { addBorderLine(line); } // _isBox2DBorderLineDirt = true; }
void Grid::buildCells() { for(int i = 0; i<numRows; i++) { for(int j = 0; j<numColumns; j++) { Vector3D position = Vector3D(((float)(SCREEN_WIDTH)/numColumns)*(j),((float)SCREEN_HEIGHT/numRows)*(i)); cells[i][j] = GridCell(position, (float)SCREEN_HEIGHT/numRows, (float)(SCREEN_WIDTH)/numColumns, 4.0f, wallColor); } } }
void GameLayerMapBorder::updateBorderCheckRemove(int x,int y, int width,int height) { auto layerMap = GameLayerMap::getRunningLayer(); std::set<GridCell> cells; for (int i = x; i < x+width; i++) { for (int j = y; j< y+height; j++) { GridCell gridCell = GridCell(i,j); if (_mapGrid->isOutMapGrid(gridCell._x, gridCell._y)) { continue; } BorderCell cell; if (!isBorderCell(x,y,(unsigned char)GridType::Dirt,cell)&&cell._maskDir > 0) { static GridCell _vgrid[]= { GridCell(-1,0),GridCell(1,0),GridCell(0,1),GridCell(0,-1), GridCell(-1,1),GridCell(-1,-1),GridCell(1,1),GridCell(1,-1) }; for(int i = 0; i<(sizeof(_vgrid)/sizeof(GridCell));i++) { GridCell tcell =cell._cell+_vgrid[i]; if(_mapGrid->getValue(tcell._x,tcell._y)==GridType::None)continue; cells.insert(tcell); } layerMap->changeGridCell(cell._cell._x,cell._cell._y,GridType::None); } } } while (!cells.empty()) { auto ip = cells.begin(); BorderCell cell; if (!isBorderCell(ip->_x,ip->_x,(unsigned char)GridType::Dirt,cell)&&cell._maskDir > 0) { static GridCell _vgrid[]= { GridCell(-1,0),GridCell(1,0),GridCell(0,1),GridCell(0,-1), GridCell(-1,1),GridCell(-1,-1),GridCell(1,1),GridCell(1,-1) }; for(int i = 0; i<(sizeof(_vgrid)/sizeof(GridCell));i++) { GridCell tcell =cell._cell+_vgrid[i]; if(_mapGrid->getValue(tcell._x,tcell._y)==GridType::None)continue; cells.insert(tcell); } layerMap->changeGridCell(cell._cell._x,cell._cell._y,GridType::None); } cells.erase(ip); } }