Beispiel #1
0
MinimapPixel *MinimapUpdateThread::getMinimapPixel(v3s16 pos,
	s16 scan_height, s16 *pixel_height)
{
	s16 height = scan_height - MAP_BLOCKSIZE;
	v3s16 blockpos_max, blockpos_min, relpos;

	getNodeBlockPosWithOffset(
		v3s16(pos.X, pos.Y - scan_height / 2, pos.Z),
		blockpos_min, relpos);
	getNodeBlockPosWithOffset(
		v3s16(pos.X, pos.Y + scan_height / 2, pos.Z),
		blockpos_max, relpos);

	for (s16 i = blockpos_max.Y; i > blockpos_min.Y - 1; i--) {
		std::map<v3s16, MinimapMapblock *>::iterator it =
			m_blocks_cache.find(v3s16(blockpos_max.X, i, blockpos_max.Z));
		if (it != m_blocks_cache.end()) {
			MinimapMapblock *mmblock = it->second;
			MinimapPixel *pixel = &mmblock->data[relpos.Z * MAP_BLOCKSIZE + relpos.X];
			if (pixel->id != CONTENT_AIR) {
				*pixel_height = height + pixel->height;
				return pixel;
			}
		}

		height -= MAP_BLOCKSIZE;
	}

	return NULL;
}
Beispiel #2
0
s16 MinimapUpdateThread::getAirCount(v3s16 pos, s16 height)
{
	s16 air_count = 0;
	v3s16 blockpos_max, blockpos_min, relpos;

	getNodeBlockPosWithOffset(
		v3s16(pos.X, pos.Y - height / 2, pos.Z),
		blockpos_min, relpos);
	getNodeBlockPosWithOffset(
		v3s16(pos.X, pos.Y + height / 2, pos.Z),
		blockpos_max, relpos);

	for (s16 i = blockpos_max.Y; i > blockpos_min.Y - 1; i--) {
		std::map<v3s16, MinimapMapblock *>::iterator it =
			m_blocks_cache.find(v3s16(blockpos_max.X, i, blockpos_max.Z));
		if (it != m_blocks_cache.end()) {
			MinimapMapblock *mmblock = it->second;
			MinimapPixel *pixel = &mmblock->data[relpos.Z * MAP_BLOCKSIZE + relpos.X];
			air_count += pixel->air_count;
		}
	}

	return air_count;
}
Beispiel #3
0
void MinimapUpdateThread::getMap(v3POS pos, s16 size, s16 scan_height, bool is_radar) {
	v3POS p(pos.X - size / 2, pos.Y, pos.Z - size / 2);

	v3POS blockpos_player, relpos;
	getNodeBlockPosWithOffset(pos, blockpos_player, relpos);

	for (s16 x = 0; x < size; x++)
		for (s16 z = 0; z < size; z++) {
			auto mmpixel = &data->minimap_scan[x + z * size];
			mmpixel->air_count = 0;
			mmpixel->id = CONTENT_AIR;

			v3POS pos(p.X + x, p.Y, p.Z + z);
			v3POS blockpos_max, blockpos_min;
			getNodeBlockPosWithOffset(v3POS(pos.X, pos.Y - scan_height / 2, pos.Z), blockpos_min, relpos);
			getNodeBlockPosWithOffset(v3POS(pos.X, pos.Y + scan_height / 2, pos.Z), blockpos_max, relpos);

			s16 pixel_height = 0;
			s16 height = scan_height - MAP_BLOCKSIZE;

			v2POS top_block_xz(blockpos_max.X, blockpos_max.Z);

			if (!getmap_cache.count(top_block_xz)) {
				getmap_cache.emplace(std::piecewise_construct, std::forward_as_tuple(top_block_xz), std::forward_as_tuple());
				auto & vec = getmap_cache[top_block_xz];

/* simple:
				for (auto i = blockpos_max.Y; i > blockpos_min.Y - 1; --i) {
					auto it = m_blocks_cache.find(v3POS(blockpos_max.X, i, blockpos_max.Z));
					if (it == m_blocks_cache.end())
						continue;
					vec.emplace(i, it->second);
				}
*/
				int c = 0;
				for (auto i = blockpos_player.Y; i > blockpos_min.Y - 1; --i) {
					auto it = m_blocks_cache.find(v3POS(blockpos_max.X, i, blockpos_max.Z));
					if (it == m_blocks_cache.end())
						continue;
					vec.emplace(c++, it->second);
				}
				for (auto i = blockpos_max.Y; i > blockpos_player.Y; --i) {
					auto it = m_blocks_cache.find(v3POS(blockpos_max.X, i, blockpos_max.Z));
					if (it == m_blocks_cache.end())
						continue;
					vec.emplace(c++, it->second);
				}
			}

			//simple: for (auto & mmblock : getmap_cache[top_block_xz]) {
			for (auto & it : getmap_cache[top_block_xz]) {
				auto & mmblock = it.second;
				auto pixel = &mmblock->data[relpos.Z * MAP_BLOCKSIZE + relpos.X];
				mmpixel->air_count += pixel->air_count;
				if (pixel->id != CONTENT_AIR) {
					pixel_height = height + pixel->height;
					mmpixel->id = pixel->id;
					mmpixel->height = pixel_height;
					if (!is_radar)
						break;
				}
				height -= MAP_BLOCKSIZE;
			}
		}
}