Ejemplo n.º 1
0
void Grid::findAll(vector<int> &out, const FBox &box, int ignored_id, int flags) const {
	IRect grid_box = nodeCoords(box);

	for(int y = grid_box.min.y; y <= grid_box.max.y; y++)
		for(int x = grid_box.min.x; x <= grid_box.max.x; x++) {
			int node_id = nodeAt(int2(x, y));
			const Node &node = m_nodes[node_id];

			if(!flagTest(node.obj_flags, flags) || !areOverlapping(box, node.bbox))
				continue;
			bool anything_found = false;

			const Object *objects[node.size];
			int count = extractObjects(node_id, objects, ignored_id, flags);

			for(int n = 0; n < count; n++)
				if(areOverlapping(box, objects[n]->bbox)) {
					if(objects[n]->node_id == -1)
						disableOverlap(objects[n]);
					out.push_back(objects[n] - &m_objects[0]);
					anything_found = true;
				}

			if(!anything_found && node.is_dirty)
				updateNode(node_id);	
		}

	clearDisables();
}
Ejemplo n.º 2
0
void Grid::findAll(vector<int> &out, const IRect &view_rect, int flags) const {
	IRect grid_box(0, 0, m_size.x, m_size.y);

	for(int y = grid_box.min.y; y < grid_box.max.y; y++) {
		const int2 &row_rect = m_row_rects[y];
		if(row_rect.x >= view_rect.max.y || row_rect.y <= view_rect.min.y)
			continue;
		
		for(int x = grid_box.min.x; x < grid_box.max.x; x++) {
			int node_id = nodeAt(int2(x, y));
			const Node &node = m_nodes[node_id];
	
			if(!flagTest(node.obj_flags, flags) || !areOverlapping(view_rect, node.rect))
				continue;

			bool anything_found = false;
			const Object *objects[node.size];
			int count = extractObjects(node_id, objects, -1, flags);

			for(int n = 0; n < count; n++) {
				if(areOverlapping(view_rect, objects[n]->rect())) {
					if(objects[n]->node_id == -1)
						disableOverlap(objects[n]);
					out.push_back(objects[n] - &m_objects[0]);
					anything_found = true;
				}
			}

			if(!anything_found && node.is_dirty)
				updateNode(node_id);	
		}
	}

	clearDisables();
}
Ejemplo n.º 3
0
bool OccluderMap::isUnder(int lower_id, int upper_id) const {
	DASSERT(upper_id >= 0 && upper_id < size());
	DASSERT(lower_id >= 0 && lower_id < size());

	const Occluder &lower = m_occluders[lower_id];
	const Occluder &upper = m_occluders[upper_id];

	if(lower.bbox.min.y >= upper.bbox.max.y)
		return false;
	if(!areOverlapping(	FRect(lower.bbox.min.xz(), lower.bbox.max.xz()),
						FRect(upper.bbox.min.xz(), upper.bbox.max.xz())))
		return false;
	if(lower_id == upper_id)
		return false;

	vector<int> temp;
	temp.reserve(1024);
	
	FBox bbox = upper.bbox;
	bbox.max.y = bbox.min.y;
	bbox.min.y = 0;
	m_grid.findAll(temp, bbox);

	for(int n = 0; n < (int)temp.size(); n++)
		if(m_grid[temp[n]].occluder_id == lower_id)
			return true;
	return false;
}
Ejemplo n.º 4
0
	void Entity::addToRender(SceneRenderer &out, Color color) const {
		//PROFILE("Entity::addToRender");
		IRect rect = m_sprite.getRect(m_seq_idx, m_frame_idx, m_dir_idx);
		if(!areOverlapping(out.targetRect(), rect + (int2)worldToScreen(m_pos)))
			return;

		FBox bbox = boundingBox() - pos();
		if(shrinkRenderedBBox() && bbox.height() >= 2.0f)
			bbox = {float3(bbox.x(), min(bbox.y() + 1.0f, bbox.ey() - 0.5f), bbox.z()), bbox.max()};

		bool as_overlay = renderAsOverlay();

		FRect tex_rect;
		auto tex = m_sprite.getFrame(m_seq_idx, m_frame_idx, m_dir_idx, tex_rect);
		bool added = out.add(tex, rect, m_pos, bbox, color, tex_rect, as_overlay);
	
	 	if(added && m_oseq_idx != -1 && m_oframe_idx != -1) {
			//TODO: overlay may be visible, while normal sprite is not!
			rect = m_sprite.getRect(m_oseq_idx, m_oframe_idx, m_dir_idx);
			auto ov_tex = m_sprite.getFrame(m_oseq_idx, m_oframe_idx, m_dir_idx, tex_rect);
			out.add(ov_tex, rect, m_pos, bbox, color, tex_rect, true);
		}

//		if(findAny(boundingBox(), {Flags::all | Flags::colliding, ref()}))
//			out.addBox(bbox + pos(), ColorId::red);
	}
Ejemplo n.º 5
0
void testOverlappingBlobs()
{
    printf("\nTEST BLOB OVERLAPPING\n");
    
    Blob b1, b2;
    
    b1.box.x = 1; b1.box.y = 1;
    b1.box.width = 3; b1.box.height = 3;
    b2.box.x = 2; b2.box.y = 3;
    b2.box.width = 3; b2.box.height = 2;
    
    int overlap = areOverlapping(&b1, &b2);
    printf("Expected: 1, Actual: %d\n", overlap);
    
    b1.box.x = 1; b1.box.y = 1;
    b1.box.width = 3; b1.box.height = 3;
    b2.box.x = 3; b2.box.y = 1;
    b2.box.width = 1; b2.box.height = 3;
    
    overlap = areOverlapping(&b1, &b2);
    printf("Expected: 1, Actual: %d\n", overlap);
    
    b1.box.x = 1; b1.box.y = 1;
    b1.box.width = 3; b1.box.height = 3;
    b2.box.x = 4; b2.box.y = 1;
    b2.box.width = 1; b2.box.height = 3;
    
    overlap = areOverlapping(&b1, &b2);
    printf("Expected: 0, Actual: %d\n", overlap);
    
    b1.box.x = 1; b1.box.y = 1;
    b1.box.width = 3; b1.box.height = 3;
    b2.box.x = 2; b2.box.y = 5;
    b2.box.width = 1; b2.box.height = 3;
    
    overlap = areOverlapping(&b1, &b2);
    printf("Expected: 0, Actual: %d\n", overlap);
}
Ejemplo n.º 6
0
int Grid::findAny(const FBox &box, int ignored_id, int flags) const {
	IRect grid_box = nodeCoords(box);

	for(int y = grid_box.min.y; y <= grid_box.max.y; y++)
		for(int x = grid_box.min.x; x <= grid_box.max.x; x++) {
			int node_id = nodeAt(int2(x, y));
			const Node &node = m_nodes[node_id];

			if(!node.size || !flagTest(node.obj_flags, flags) || !areOverlapping(box, node.bbox))
				continue;

			const Object *objects[node.size];
			int count = extractObjects(node_id, objects, ignored_id, flags);

			for(int n = 0; n < count; n++)
				if(areOverlapping(box, objects[n]->bbox))
					return objects[n] - &m_objects[0];

			if(node.is_dirty)
				updateNode(node_id);	
		}

	return -1;
}
Ejemplo n.º 7
0
	void TileSelector::drawContents(Renderer2D &out) const {
		int2 offset = innerOffset();
		IRect clip_rect(int2(0, 0), clippedRect().size());

		for(int n = 0; n < (int)m_tile_list.size(); n++) {
			const Tile *tile = m_tile_list[n].tile;
			IRect tile_rect = tile->rect();
			int2 pos = m_tile_list[n].pos - tile_rect.min - offset;

			if(areOverlapping(clip_rect, tile_rect + pos))
				tile->draw(out, pos);
		}
		
		if(m_selection) {
			int2 pos = m_selection->pos - offset;

			out.setViewPos(-clippedRect().min - pos + m_selection->tile->rect().min);
			IBox box(int3(0, 0, 0), m_selection->tile->bboxSize());
			drawBBox(out, box);
		//	out.addFilledRect(IRect(pos, pos + m_selection->size));
		}
	}
Ejemplo n.º 8
0
	void GroupEditor::drawContents(Renderer2D &out) const {
		int2 offset = innerOffset();

		for(int n = 0; n < m_tile_group->entryCount(); n++)
		   m_tile_group->entryTile(n)->m_temp = n;

		IRect clip_rect(int2(0, 0), clippedRect().size());

		for(int n = 0; n < (int)m_tile_list.size(); n++) {
			const ui::TileList::Entry &entry = m_tile_list[n];
			entry.is_selected = m_mode == mAddRemove?
				m_tile_group->isValidEntryId(entry.tile->m_temp, entry.tile) :
				entry.group_id == m_selected_group_id;

			IRect tile_rect = entry.tile->rect();
			int2 pos = entry.pos - tile_rect.min - offset;

			if(areOverlapping(clip_rect, tile_rect + pos))
				entry.tile->draw(out, pos);
		}
		
		DTexture::unbind();
		for(int n = 0; n < (int)m_tile_list.size(); n++) {
			const ui::TileList::Entry &entry = m_tile_list[n];
			if(!entry.is_selected)
				continue;
		
			Color col = m_tile_group->isEntryDirty(entry.tile->m_temp)? ColorId::red : ColorId::white;	
			int2 pos = entry.pos - offset;
			out.addRect(IRect(pos, pos + entry.size), col);
		}

		if(m_mode == mModify && m_selected_group_id != -1) {	
			IRect edit_rect(clippedRect().max - int2(280, 250), clippedRect().max - int2(5, 0));
			int2 center = edit_rect.center();

			out.setViewPos(-center);
			int2 half_size = edit_rect.size() / 2;
			out.addFilledRect(IRect(-half_size, half_size), FColor(0.3f, 0.3f, 0.3f));
			drawBBox(out, IBox({-9, 0, -9}, {9, 1, 9}), ColorId::white);

			auto font = res::getFont(WindowStyle::fonts[0]);

			for(int n = 0; n < TileGroup::Group::side_count; n++) {
				out.setViewPos(-center - worldToScreen(TileGroup::Group::s_side_offsets[n] * 9));
				font->draw(out, float2(0, 0), {ColorId::white}, format("%d", m_tile_group->groupSurface(m_selected_group_id, n)));
			}
				
			out.setViewPos(-center +edit_rect.size() / 2);
			font->draw(out, float2(0, 0), {ColorId::white}, format("setting surface: %d", m_selected_surface_id));

			/*
			const char *names[] = {
				"",
				"snow",
				"gravel",
				"dirt",
				"grass",
				"mud",
				"mud_cracked",
				"sand",
				"green goo",
			};

			out.setViewPos(-int2(bottom_rect.max.x - 200, bottom_rect.min.y));
			for(int n = 0; n < arraySize(names); n++)
				font->draw(int2(0, 10), ColorId::white,
						m_selected_surface_id == n? "%d: [%s]\n" : "%d: %s\n", n, names[n]); */
			out.setViewPos(-clippedRect().min);
		}

		if(m_current_entry)
			m_font->draw(out, float2(5, height() - 20), {ColorId::white, ColorId::black},
					format("%s", m_current_entry->tile->resourceName().c_str()));
	}