bool Map::Generate(Geology* RegionGeology) { CellSizeX = 3; CellSizeY = 3; MapSizeX = CellSizeX * CELLEDGESIZE; MapSizeY = CellSizeY * CELLEDGESIZE; //MapSizeZ = CellSizeZ; // Create and add Cells with shape and material data for (uint16_t X = 0; X < CellSizeX; X++) { for (uint16_t Y = 0; Y < CellSizeX; Y++) { int Z = 0; //get From Geology CellCoordinates TargetCellCoordinates = CellCoordinates(X, Y, Z); Cell* NewCell = new Cell(); NewCell->setPosition(TargetCellCoordinates); addCell(NewCell, TargetCellCoordinates); NewCell->LoadCellData(MapGeology); } } // Initialize Faces for the cells for(std::map<uint64_t, Cell*>::iterator CellIterator = Cells.begin() ; CellIterator != Cells.end(); ++CellIterator ) { CellIterator->second->Init(); } return true; }
void Zone::addSelection(VolumeSelection* Selection) { MapCoordinates Origin = Selection->OriginLocation; MapCoordinates Terminal = Selection->TerminalLocation; for (int x = Origin.X; x < Terminal.X; x++) { for (int y = Origin.Y; y < Terminal.Y; y++) { for (int z = Origin.Z; z < Terminal.Z; z++) { MapCoordinates ZoneCube = MapCoordinates(x, y, z); CellCoordinates ZoneCell = CellCoordinates(ZoneCube); std::map< uint64_t, bitset <CUBESPERCELL>* >::iterator it = ZoneMap.find(ZoneCell.Key()); if (it != ZoneMap.end()) { bitset<CUBESPERCELL>* Bits = it->second; Bits->set(ZoneCube.Cube(), true); } else { bitset<CUBESPERCELL>* Bits = new bitset<CUBESPERCELL>; Bits->set(ZoneCube.Cube(), true); ZoneMap[ZoneCell.Key()] = Bits; } } } } }
void CSMWorld::RegionMap::updateSize() { std::pair<CellCoordinates, CellCoordinates> size = getSize(); if (int diff = size.first.getX() - mMin.getX()) { beginInsertColumns (QModelIndex(), 0, std::abs (diff)-1); mMin = CellCoordinates (size.first.getX(), mMin.getY()); endInsertColumns(); } if (int diff = size.first.getY() - mMin.getY()) { beginInsertRows (QModelIndex(), 0, std::abs (diff)-1); mMin = CellCoordinates (mMin.getX(), size.first.getY()); endInsertRows(); } if (int diff = size.second.getX() - mMax.getX()) { int columns = columnCount(); if (diff>0) beginInsertColumns (QModelIndex(), columns, columns+diff-1); else beginRemoveColumns (QModelIndex(), columns+diff, columns-1); mMax = CellCoordinates (size.second.getX(), mMax.getY()); endInsertColumns(); } if (int diff = size.second.getY() - mMax.getY()) { int rows = rowCount(); if (diff>0) beginInsertRows (QModelIndex(), rows, rows+diff-1); else beginRemoveRows (QModelIndex(), rows+diff, rows-1); mMax = CellCoordinates (mMax.getX(), size.second.getY()); endInsertRows(); } }
bool Zone::isCoordinateInZone(MapCoordinates TestCoordinates) { std::map< uint64_t, bitset <CUBESPERCELL>* >::iterator it = ZoneMap.find(CellCoordinates(TestCoordinates).Key()); if (it != ZoneMap.end()) { return it->second->test(TestCoordinates.Cube()); } else { return false; } }
CSMWorld::CellCoordinates CSMWorld::RegionMap::getIndex (const Cell& cell) const { std::istringstream stream (cell.mId); char ignore; int x = 0; int y = 0; stream >> ignore >> x >> y; return CellCoordinates (x, y); }
Cell* Map::getCubeOwner(MapCoordinates Coordinates) const { if ((Coordinates.X > MapSizeX) || (Coordinates.Y > MapSizeY) || (Coordinates.Z > MapSizeZ)) //TODO better more flexible limit check { return NULL; } CellCoordinates TargetCellCoordinates = CellCoordinates(Coordinates); return getCell(TargetCellCoordinates); }
std::pair<CSMWorld::CellCoordinates, CSMWorld::CellCoordinates> CSMWorld::RegionMap::getSize() const { const IdCollection<Cell>& cells = mData.getCells(); int size = cells.getSize(); CellCoordinates min (0, 0); CellCoordinates max (0, 0); for (int i=0; i<size; ++i) { const Record<Cell>& cell = cells.getRecord (i); const Cell& cell2 = cell.get(); if (cell2.isExterior()) { CellCoordinates index = getIndex (cell2); if (min==max) { min = index; max = min.move (1, 1); } else { if (index.getX()<min.getX()) min = CellCoordinates (index.getX(), min.getY()); else if (index.getX()>=max.getX()) max = CellCoordinates (index.getX()+1, max.getY()); if (index.getY()<min.getY()) min = CellCoordinates (min.getX(), index.getY()); else if (index.getY()>=max.getY()) max = CellCoordinates (max.getX(), index.getY() + 1); } } } return std::make_pair (min, max); }
bool Map::hasFace(MapCoordinates Coordinates, Direction DirectionType) const { MapCoordinates TargetMapCoordinates = Coordinates; Direction TargetFace = DirectionType; if (isDirectionPositive(DirectionType)) // East, South and Top Directions get translated to adjacent Cells avoiding a bounce back call { // Do something for edge of Map cases?? TargetMapCoordinates.TranslateMapCoordinates(DirectionType); TargetFace = OppositeDirection(TargetFace); } CellCoordinates TargetCellCoordinates = CellCoordinates(TargetMapCoordinates); Cell* TargetCell = getCell(TargetCellCoordinates); if (TargetCell != NULL) { return TargetCell->hasFace(CubeCoordinates(TargetMapCoordinates), TargetFace); } return false; }