Пример #1
0
static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
		float start_off, float end_off, u32 needed_count, INodeDefManager *nodemgr)
{
	float d0 = (float)BS * p0.getDistanceFrom(p1);
	v3s16 u0 = p1 - p0;
	v3f uf = v3f(u0.X, u0.Y, u0.Z) * BS;
	uf.normalize();
	v3f p0f = v3f(p0.X, p0.Y, p0.Z) * BS;
	u32 count = 0;
	for(float s=start_off; s<d0+end_off; s+=step){
		v3f pf = p0f + uf * s;
		v3s16 p = floatToInt(pf, BS);
		MapNode n = map->getNodeNoEx(p);
		bool is_transparent = false;
		const ContentFeatures &f = nodemgr->get(n);
		if(f.solidness == 0)
			is_transparent = (f.visual_solidness != 2);
		else
			is_transparent = (f.solidness != 2);
		if(!is_transparent){
			count++;
			if(count >= needed_count)
				return true;
		}
		step *= stepfac;
	}
	return false;
}
Пример #2
0
static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
                       float start_off, float end_off, u32 needed_count, INodeDefManager *nodemgr,
                       std::unordered_map<v3POS, bool, v3POSHash, v3POSEqual> & occlude_cache)
{
    float d0 = (float)BS * p0.getDistanceFrom(p1);
    v3s16 u0 = p1 - p0;
    v3f uf = v3f(u0.X, u0.Y, u0.Z) * BS;
    uf.normalize();
    v3f p0f = v3f(p0.X, p0.Y, p0.Z) * BS;
    u32 count = 0;
    for(float s=start_off; s<d0+end_off; s+=step) {
        v3f pf = p0f + uf * s;
        v3s16 p = floatToInt(pf, BS);
        bool is_transparent = false;
        bool cache = true;
        if (occlude_cache.count(p)) {
            cache = false;
            is_transparent = occlude_cache[p];
        } else {
            MapNode n = map->getNodeTry(p);
            if (n.getContent() == CONTENT_IGNORE) {
                cache = false;
            }
            const ContentFeatures &f = nodemgr->get(n);
            if(f.solidness == 0)
                is_transparent = (f.visual_solidness != 2);
            else
                is_transparent = (f.solidness != 2);
        }
        if (cache)
            occlude_cache[p] = is_transparent;
        if(!is_transparent) {
            if(count == needed_count)
                return true;
            count++;
        }
        step *= stepfac;
    }
    return false;
}
Пример #3
0
//VERY BAD COPYPASTE FROM clientmap.cpp!
static bool isOccluded(Map *map, v3s16 p0, v3s16 p1, float step, float stepfac,
		float start_off, float end_off, u32 needed_count, INodeDefManager *nodemgr,
		unordered_map_v3POS<bool> & occlude_cache)
{
	float d0 = (float)1 * p0.getDistanceFrom(p1);
	v3s16 u0 = p1 - p0;
	v3f uf = v3f(u0.X, u0.Y, u0.Z);
	uf.normalize();
	v3f p0f = v3f(p0.X, p0.Y, p0.Z);
	u32 count = 0;
	for(float s=start_off; s<d0+end_off; s+=step){
		v3f pf = p0f + uf * s;
		v3s16 p = floatToInt(pf, 1);
		bool is_transparent = false;
		bool cache = true;
		if (occlude_cache.count(p)) {
			cache = false;
			is_transparent = occlude_cache[p];
		} else {
		MapNode n = map->getNodeTry(p);
		if (!n) {
			return true; // ONE DIFFERENCE FROM clientmap.cpp
		}
		const ContentFeatures &f = nodemgr->get(n);
		if(f.solidness == 0)
			is_transparent = (f.visual_solidness != 2);
		else
			is_transparent = (f.solidness != 2);
		}
		if (cache)
			occlude_cache[p] = is_transparent;
		if(!is_transparent){
			if(count == needed_count)
				return true;
			count++;
		}
		step *= stepfac;
	}
	return false;
}