void BiomeView::regionAvailable(int a_RegionX, int a_RegionZ) { for (int z = 0; z < 32; z++) { for (int x = 0; x < 32; x++) { drawChunk(a_RegionX * 32 + x, a_RegionZ * 32 + z); } } update(); }
void BiomeView::redraw() { if (!hasData()) { // No data means no image is displayed, no need to compose: update(); return; } int chunksize = 16 * m_Zoom; // first find the center block position int centerchunkx = floor(m_X / 16); int centerchunkz = floor(m_Z / 16); // and the center of the screen int centerx = m_Image.width() / 2; int centery = m_Image.height() / 2; // and align for panning centerx -= (m_X - centerchunkx * 16) * m_Zoom; centery -= (m_Z - centerchunkz * 16) * m_Zoom; // now calculate the topleft block on the screen int startx = centerchunkx - centerx / chunksize - 1; int startz = centerchunkz - centery / chunksize - 1; // and the dimensions of the screen in blocks int blockswide = m_Image.width() / chunksize + 3; int blockstall = m_Image.height() / chunksize + 3; for (int z = startz; z < startz + blockstall; z++) { for (int x = startx; x < startx + blockswide; x++) { drawChunk(x, z); } } update(); }
void MapView::chunkUpdated(int x, int z) { drawChunk(x, z); update(); }
void MapView::redraw() { if (!this->isEnabled()) { // blank uchar *bits = image.bits(); int imgstride = image.bytesPerLine(); int imgoffset = 0; for (int y = 0; y < image.height(); y++, imgoffset += imgstride) memset(bits + imgoffset, 0xee, imgstride); update(); return; } double chunksize = 16 * zoom; // first find the center block position int centerchunkx = floor(x / 16); int centerchunkz = floor(z / 16); // and the center of the screen int centerx = image.width() / 2; int centery = image.height() / 2; // and align for panning centerx -= (x - centerchunkx * 16) * zoom; centery -= (z - centerchunkz * 16) * zoom; // now calculate the topleft block on the screen int startx = centerchunkx - floor(centerx / chunksize) - 1; int startz = centerchunkz - floor(centery / chunksize) - 1; // and the dimensions of the screen in blocks int blockswide = image.width() / chunksize + 3; int blockstall = image.height() / chunksize + 3; for (int cz = startz; cz < startz + blockstall; cz++) for (int cx = startx; cx < startx + blockswide; cx++) drawChunk(cx, cz); // add on the entity layer QPainter canvas(&image); double halfviewwidth = image.width() / 2 / zoom; double halvviewheight = image.height() / 2 / zoom; double x1 = x - halfviewwidth; double z1 = z - halvviewheight; double x2 = x + halfviewwidth; double z2 = z + halvviewheight; // draw the entities for (int cz = startz; cz < startz + blockstall; cz++) { for (int cx = startx; cx < startx + blockswide; cx++) { for (auto &type : overlayItemTypes) { Chunk *chunk = cache.fetch(cx, cz); if (chunk) { auto range = chunk->entities.equal_range(type); for (auto it = range.first; it != range.second; ++it) { // don't show entities above our depth int entityY = (*it)->midpoint().y; // everything below the current block, // but also inside the current block if (entityY < depth + 1) { int entityX = static_cast<int>((*it)->midpoint().x) & 0x0f; int entityZ = static_cast<int>((*it)->midpoint().z) & 0x0f; int index = entityX + (entityZ << 4); int highY = chunk->depth[index]; if ( (entityY+10 >= highY) || (entityY+10 >= depth) ) (*it)->draw(x1, z1, zoom, &canvas); } } } } } } // draw the generated structures for (auto &type : overlayItemTypes) { for (auto &item : overlayItems[type]) { if (item->intersects(OverlayItem::Point(x1 - 1, 0, z1 - 1), OverlayItem::Point(x2 + 1, depth, z2 + 1))) { item->draw(x1, z1, zoom, &canvas); } } } emit(coordinatesChanged(x, depth, z)); update(); }