Ejemplo n.º 1
0
void BakedLightBaker::_add_mesh(const Ref<Mesh>& p_mesh,const Ref<Material>& p_mat_override,const Transform& p_xform) {


	for(int i=0;i<p_mesh->get_surface_count();i++) {

		if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
			continue;
		Ref<Material> mat = p_mat_override.is_valid()?p_mat_override:p_mesh->surface_get_material(i);

		int facecount=0;


		if (p_mesh->surface_get_format(i)&Mesh::ARRAY_FORMAT_INDEX) {

			facecount=p_mesh->surface_get_array_index_len(i);
		} else {

			facecount=p_mesh->surface_get_array_len(i);
		}

		ERR_CONTINUE((facecount==0 || (facecount%3)!=0));

		facecount/=3;

		int tbase=triangles.size();
		triangles.resize(facecount+tbase);


		Array a = p_mesh->surface_get_arrays(i);

		DVector<Vector3> vertices = a[Mesh::ARRAY_VERTEX];
		DVector<Vector3>::Read vr=vertices.read();

		if (p_mesh->surface_get_format(i)&Mesh::ARRAY_FORMAT_INDEX) {

			DVector<int> indices = a[Mesh::ARRAY_INDEX];
			DVector<int>::Read ir = indices.read();

			for(int i=0;i<facecount;i++) {
				Triangle &t=triangles[tbase+i];
				t.vertices[0]=p_xform.xform(vr[ ir[i*3+0] ]);
				t.vertices[1]=p_xform.xform(vr[ ir[i*3+1] ]);
				t.vertices[2]=p_xform.xform(vr[ ir[i*3+2] ]);
			}

		} else {

			for(int i=0;i<facecount;i++) {
				Triangle &t=triangles[tbase+i];
				t.vertices[0]=p_xform.xform(vr[ i*3+0 ]);
				t.vertices[1]=p_xform.xform(vr[ i*3+1 ]);
				t.vertices[2]=p_xform.xform(vr[ i*3+2 ]);
			}
		}
	}

}
Ejemplo n.º 2
0
void Particles2DEditorPlugin::_file_selected(const String& p_file) {

	print_line("file: "+p_file);

	int epc=epoints->get_val();

	Image img;
	Error err = ImageLoader::load_image(p_file,&img);
	ERR_EXPLAIN("Error loading image: "+p_file);
	ERR_FAIL_COND(err!=OK);

	img.convert(Image::FORMAT_GRAYSCALE_ALPHA);
	ERR_FAIL_COND(img.get_format()!=Image::FORMAT_GRAYSCALE_ALPHA);
	Size2i s = Size2(img.get_width(),img.get_height());
	ERR_FAIL_COND(s.width==0 || s.height==0);

	DVector<uint8_t> data = img.get_data();
	DVector<uint8_t>::Read r = data.read();

	Vector<Point2i> valid_positions;
	valid_positions.resize(s.width*s.height);
	int vpc=0;


	for(int i=0;i<s.width*s.height;i++) {

		uint8_t a = r[i*2+1];
		if (a>128) {
			valid_positions[vpc++]=Point2i(i%s.width,i/s.width);
		}
	}

	valid_positions.resize(vpc);

	ERR_EXPLAIN("No pixels with transparency > 128 in image..");
	ERR_FAIL_COND(valid_positions.size()==0);

	DVector<Point2> epoints;
	epoints.resize(epc);
	DVector<Point2>::Write w = epoints.write();

	Size2 extents = Size2(img.get_width()*0.5,img.get_height()*0.5);

	for(int i=0;i<epc;i++) {

		Point2 p = valid_positions[Math::rand()%vpc];
		p-=s/2;
		w[i]=p/extents;
	}

	w = DVector<Point2>::Write();

	undo_redo->create_action("Set Emission Mask");
	undo_redo->add_do_method(particles,"set_emission_points",epoints);
	undo_redo->add_do_method(particles,"set_emission_half_extents",extents);
	undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points());
	undo_redo->add_undo_method(particles,"set_emission_half_extents",particles->get_emission_half_extents());
	undo_redo->commit_action();

}
Ejemplo n.º 3
0
void AudioServer::sample_set_signed_data(RID p_sample, const DVector<float>& p_buffer) {

	int len = p_buffer.size();
	ERR_FAIL_COND( len == 0 );

	DVector<uint8_t> data;
	data.resize(len*2);
	DVector<uint8_t>::Write w=data.write();

	int16_t *samples = (int16_t*)w.ptr();

	DVector<float>::Read r = p_buffer.read();

	for(int i=0;i<len;i++) {

		float sample = r[i];
		sample = Math::floor( sample * (1<<16) );
		if (sample<-32768)
			sample=-32768;
		else if (sample>32767)
			sample=32767;
		samples[i]=sample;
	}

	w = DVector<uint8_t>::Write();

	sample_set_data(p_sample,data);


}
Ejemplo n.º 4
0
void TileMap::_set_tile_data(const DVector<int>& p_data) {

	int c=p_data.size();
	DVector<int>::Read r = p_data.read();


	for(int i=0;i<c;i+=2) {

		const uint8_t *ptr=(const uint8_t*)&r[i];
		uint8_t local[8];
		for(int j=0;j<8;j++)
			local[j]=ptr[j];

#ifdef BIG_ENDIAN_ENABLED


		SWAP(local[0],local[3]);
		SWAP(local[1],local[2]);
		SWAP(local[4],local[7]);
		SWAP(local[5],local[6]);
#endif
		int x = decode_uint16(&local[0]);
		int y = decode_uint16(&local[2]);
		uint32_t v = decode_uint32(&local[4]);
		bool flip_h = v&(1<<29);
		bool flip_v = v&(1<<30);
		v&=(1<<29)-1;

//		if (x<-20 || y <-20 || x>4000 || y>4000)
//			continue;
		set_cell(x,y,v,flip_h,flip_v);
	}

}
Ejemplo n.º 5
0
static int _get_number_from_token(DVector<uint8_t>& r_token) {

	int len = r_token.size();
	DVector<uint8_t>::Read r = r_token.read();
	return String::to_int((const char*)r.ptr(),len);

}
Ejemplo n.º 6
0
static Image _lossless_unpack_png(const DVector<uint8_t>& p_data) {

	DVector<uint8_t>::Read r = p_data.read();
	ERR_FAIL_COND_V(r[0]!='P' || r[1]!='N' || r[2]!='G' || r[3]!=' ',Image());
	return _load_mem_png(&r[4]);

}
Ejemplo n.º 7
0
Variant::Variant(const DVector<Face3>& p_face_array) {


	DVector<Vector3> vertices;
	int face_count=p_face_array.size();
	vertices.resize(face_count*3);

	if (face_count) {
		DVector<Face3>::Read r = p_face_array.read();
		DVector<Vector3>::Write w = vertices.write();

		for(int i=0;i<face_count;i++) {

			for(int j=0;j<3;j++)
				w[i*3+j]=r[i].vertex[j];
		}

		r=DVector<Face3>::Read();
		w=DVector<Vector3>::Write();

	}

	type = NIL;

	*this = vertices;
}
Ejemplo n.º 8
0
void NavigationMesh::create_from_mesh(const Ref<Mesh>& p_mesh) {


	vertices=DVector<Vector3>();
	clear_polygons();

	for(int i=0;i<p_mesh->get_surface_count();i++) {

		if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
			continue;
		Array arr = p_mesh->surface_get_arrays(i);
		DVector<Vector3> varr = arr[Mesh::ARRAY_VERTEX];
		DVector<int> iarr = arr[Mesh::ARRAY_INDEX];
		if (varr.size()==0 || iarr.size()==0)
			continue;

		int from = vertices.size();
		vertices.append_array(varr);
		int rlen = iarr.size();
		DVector<int>::Read r = iarr.read();

		for(int j=0;j<rlen;j+=3) {
			Vector<int> vi;
			vi.resize(3);
			vi[0]=r[j+0]+from;
			vi[1]=r[j+1]+from;
			vi[2]=r[j+2]+from;

			add_polygon(vi);
		}
	}
}
Ejemplo n.º 9
0
Ref<Texture> EditorPackedScenePreviewPlugin::_gen_from_imd(Ref<ResourceImportMetadata> p_imd) {

	if (p_imd.is_null()) {
		return Ref<Texture>();
	}

	if (!p_imd->has_option("thumbnail"))
		return Ref<Texture>();

	Variant tn = p_imd->get_option("thumbnail");
	//print_line(Variant::get_type_name(tn.get_type()));
	DVector<uint8_t> thumbnail = tn;

	int len = thumbnail.size();
	if (len==0)
		return Ref<Texture>();


	DVector<uint8_t>::Read r = thumbnail.read();

	Image img(r.ptr(),len);
	if (img.empty())
		return Ref<Texture>();

	Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture ));
	ptex->create_from_image(img,0);
	return ptex;

}
Ejemplo n.º 10
0
static void _decompress_etc(Image *p_img) {

	ERR_FAIL_COND(p_img->get_format() != Image::FORMAT_ETC);

	int imgw = p_img->get_width();
	int imgh = p_img->get_height();
	DVector<uint8_t> src = p_img->get_data();
	DVector<uint8_t> dst;

	DVector<uint8_t>::Read r = src.read();

	int mmc = p_img->get_mipmaps();

	for (int i = 0; i <= mmc; i++) {

		dst.resize(dst.size() + imgw * imgh * 3);
		const uint8_t *srcbr = &r[p_img->get_mipmap_offset(i)];
		DVector<uint8_t>::Write w = dst.write();

		uint8_t *wptr = &w[dst.size() - imgw * imgh * 3];

		int bw = MAX(imgw / 4, 1);
		int bh = MAX(imgh / 4, 1);

		for (int y = 0; y < bh; y++) {

			for (int x = 0; x < bw; x++) {

				uint8_t block[4 * 4 * 4];

				rg_etc1::unpack_etc1_block(srcbr, (unsigned int *)block);
				srcbr += 8;

				int maxx = MIN(imgw, 4);
				int maxy = MIN(imgh, 4);

				for (int yy = 0; yy < maxy; yy++) {

					for (int xx = 0; xx < maxx; xx++) {

						uint32_t src_ofs = (yy * 4 + xx) * 4;
						uint32_t dst_ofs = ((y * 4 + yy) * imgw + x * 4 + xx) * 3;
						wptr[dst_ofs + 0] = block[src_ofs + 0];
						wptr[dst_ofs + 1] = block[src_ofs + 1];
						wptr[dst_ofs + 2] = block[src_ofs + 2];
					}
				}
			}
		}

		imgw = MAX(1, imgw / 2);
		imgh = MAX(1, imgh / 2);
	}

	r = DVector<uint8_t>::Read();
	//print_line("Re Creating ETC into regular image: w "+itos(p_img->get_width())+" h "+itos(p_img->get_height())+" mm "+itos(p_img->get_mipmaps()));
	*p_img = Image(p_img->get_width(), p_img->get_height(), p_img->get_mipmaps(), Image::FORMAT_RGB, dst);
	if (p_img->get_mipmaps())
		p_img->generate_mipmaps(-1, true);
}
Ejemplo n.º 11
0
Error StreamPeer::_put_data(const DVector<uint8_t> &p_data) {

	int len = p_data.size();
	if (len == 0)
		return OK;
	DVector<uint8_t>::Read r = p_data.read();
	return put_data(&r[0], len);
}
Ejemplo n.º 12
0
void ConvexPolygonShape2DSW::set_data(const Variant& p_data) {

	ERR_FAIL_COND(p_data.get_type()!=Variant::VECTOR2_ARRAY && p_data.get_type()!=Variant::REAL_ARRAY);


	if (points)
		memdelete_arr(points);
	points=NULL;
	point_count=0;

	if (p_data.get_type()==Variant::VECTOR2_ARRAY) {
		DVector<Vector2> arr=p_data;
		ERR_FAIL_COND(arr.size()==0);
		point_count=arr.size();
		points = memnew_arr(Point,point_count);
		DVector<Vector2>::Read r = arr.read();

		for(int i=0;i<point_count;i++) {
			points[i].pos=r[i];
		}

		for(int i=0;i<point_count;i++) {

			Vector2 p = points[i].pos;
			Vector2 pn = points[(i+1)%point_count].pos;
			points[i].normal=(pn-p).tangent().normalized();
		}
	} else {

		DVector<real_t> dvr = p_data;
		point_count=dvr.size()/4;
		ERR_FAIL_COND(point_count==0);

		points = memnew_arr(Point,point_count);
		DVector<real_t>::Read r = dvr.read();

		for(int i=0;i<point_count;i++) {

			int idx=i<<2;
			points[i].pos.x=r[idx+0];
			points[i].pos.y=r[idx+1];
			points[i].normal.x=r[idx+2];
			points[i].normal.y=r[idx+3];

		}
	}


	ERR_FAIL_COND(point_count==0);
	Rect2 aabb;
	aabb.pos=points[0].pos;
	for(int i=1;i<point_count;i++)
		aabb.expand_to(points[i].pos);

	configure(aabb);
}
Ejemplo n.º 13
0
void TileMapEditor::_erase_points(const DVector<Vector2> p_points) {

	int len = p_points.size();
	DVector<Vector2>::Read pr = p_points.read();

	for (int i=0;i<len;i++) {

		_set_cell(pr[i], TileMap::INVALID_CELL);
	}
}
Ejemplo n.º 14
0
Error PacketPeer::put_packet_buffer(const DVector<uint8_t> &p_buffer) {

	int len = p_buffer.size();
	if (len==0)
		return OK;

	DVector<uint8_t>::Read r = p_buffer.read();
	return put_packet(&r[0],len);

}
Ejemplo n.º 15
0
void AudioServer::sample_set_signed_data(RID p_sample, const DVector<float>& p_buffer) {

	SampleFormat format = sample_get_format(p_sample);

	ERR_EXPLAIN("IMA ADPCM is not supported.");
	ERR_FAIL_COND(format==SAMPLE_FORMAT_IMA_ADPCM);

	int len = p_buffer.size();
	ERR_FAIL_COND( len == 0 );

	DVector<uint8_t> data;
	DVector<uint8_t>::Write w;
	DVector<float>::Read r = p_buffer.read();

	switch(format) {
		case SAMPLE_FORMAT_PCM8: {
			data.resize(len);
			w=data.write();

			int8_t *samples8 = (int8_t*)w.ptr();

			for(int i=0;i<len;i++) {

				float sample = Math::floor( r[i] * (1<<8) );
				if (sample<-128)
					sample=-128;
				else if (sample>127)
					sample=127;
				samples8[i]=sample;
			}
		} break;
		case SAMPLE_FORMAT_PCM16: {
			data.resize(len*2);
			w=data.write();

			int16_t *samples16 = (int16_t*)w.ptr();

			for(int i=0;i<len;i++) {

				float sample = Math::floor( r[i] * (1<<16) );
				if (sample<-32768)
					sample=-32768;
				else if (sample>32767)
					sample=32767;
				samples16[i]=sample;
			}
		} break;
	}

	w = DVector<uint8_t>::Write();

	sample_set_data(p_sample,data);


}
Ejemplo n.º 16
0
void SampleManagerMallocSW::sample_set_data(RID p_sample, const DVector<uint8_t>& p_buffer) {

	Sample *s = sample_owner.get(p_sample);
	ERR_FAIL_COND(!s);

	int buff_size=p_buffer.size();
	ERR_FAIL_COND(buff_size==0);


	ERR_EXPLAIN("Sample buffer size does not match sample size.");
	//print_line("len bytes: "+itos(s->length_bytes)+" bufsize: "+itos(buff_size));
	ERR_FAIL_COND(s->length_bytes!=buff_size);
	DVector<uint8_t>::Read buffer_r=p_buffer.read();
	const uint8_t *src = buffer_r.ptr();
	uint8_t *dst = (uint8_t*)s->data;
	//print_line("set data: "+itos(s->length_bytes));

	for(int i=0;i<s->length_bytes;i++) {

		dst[i]=src[i];
	}

	switch(s->format) {

		case AS::SAMPLE_FORMAT_PCM8: {

			if (s->stereo) {
				dst[s->length]=dst[s->length-2];
				dst[s->length+1]=dst[s->length-1];
			} else {

				dst[s->length]=dst[s->length-1];
			}

		} break;
		case AS::SAMPLE_FORMAT_PCM16: {

			if (s->stereo) {
				dst[s->length]=dst[s->length-4];
				dst[s->length+1]=dst[s->length-3];
				dst[s->length+2]=dst[s->length-2];
				dst[s->length+3]=dst[s->length-1];
			} else {

				dst[s->length]=dst[s->length-2];
				dst[s->length+1]=dst[s->length-1];
			}

		} break;

	}



}
Ejemplo n.º 17
0
Error HTTPClient::request_raw( Method p_method, const String& p_url, const Vector<String>& p_headers,const DVector<uint8_t>& p_body) {

	ERR_FAIL_INDEX_V(p_method,METHOD_MAX,ERR_INVALID_PARAMETER);
	ERR_FAIL_COND_V(status!=STATUS_CONNECTED,ERR_INVALID_PARAMETER);
	ERR_FAIL_COND_V(connection.is_null(),ERR_INVALID_DATA);


	static const char* _methods[METHOD_MAX]={
		"GET",
		"HEAD",
		"POST",
		"PUT",
		"DELETE",
		"OPTIONS",
		"TRACE",
		"CONNECT"};

	String request=String(_methods[p_method])+" "+p_url+" HTTP/1.1\r\n";
	request+="Host: "+conn_host+":"+itos(conn_port)+"\r\n";
	bool add_clen=p_body.size()>0;
	for(int i=0;i<p_headers.size();i++) {
		request+=p_headers[i]+"\r\n";
		if (add_clen && p_headers[i].find("Content-Length:")==0) {
			add_clen=false;
		}
	}
	if (add_clen) {
		request+="Content-Length: "+itos(p_body.size())+"\r\n";
		//should it add utf8 encoding? not sure
	}
	request+="\r\n";
	CharString cs=request.utf8();

	DVector<uint8_t> data;

	//Maybe this goes faster somehow?
	for(int i=0;i<cs.length();i++) {
		data.append( cs[i] );
	}
	data.append_array( p_body );

	DVector<uint8_t>::Read r = data.read();
	Error err = connection->put_data(&r[0], data.size());

	if (err) {
		close();
		status=STATUS_CONNECTION_ERROR;
		return err;
	}

	status=STATUS_REQUESTING;

	return OK;
}
Ejemplo n.º 18
0
void _File::store_buffer(const DVector<uint8_t>& p_buffer) {

    ERR_FAIL_COND(!f);

    int len = p_buffer.size();
    if (len==0)
        return;

    DVector<uint8_t>::Read r = p_buffer.read();

    f->store_buffer(&r[0],len);
}
Ejemplo n.º 19
0
void LightOccluder2D::_notification(int p_what) {

	if (p_what==NOTIFICATION_ENTER_CANVAS) {

		VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,get_canvas());
		VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform());
		VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible());

	}
	if (p_what==NOTIFICATION_TRANSFORM_CHANGED) {

		VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform());
	}
	if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {

		VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible());
	}

	if (p_what==NOTIFICATION_DRAW) {

		if (get_tree()->is_editor_hint()) {

			if (occluder_polygon.is_valid()) {

				DVector<Vector2> poly = occluder_polygon->get_polygon();

				if (poly.size()) {
					if (occluder_polygon->is_closed()) {
						Vector<Color> color;
						color.push_back(Color(0,0,0,0.6));
						draw_polygon(Variant(poly),color);
					} else {

						int ps=poly.size();
						DVector<Vector2>::Read r = poly.read();
						for(int i=0;i<ps-1;i++) {

							draw_line(r[i],r[i+1],Color(0,0,0,0.6),3);
						}
					}
				}
			}
		}
	}


	if (p_what==NOTIFICATION_EXIT_CANVAS) {

		VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,RID());
	}


}
Ejemplo n.º 20
0
void Translation::_set_messages(const DVector<String>& p_messages){

	int msg_count=p_messages.size();
	ERR_FAIL_COND(msg_count%2);

	DVector<String>::Read r = p_messages.read();

	for(int i=0;i<msg_count;i+=2) {

		add_message( r[i+0], r[i+1] );
	}

}
void ConcavePolygonShape2D::draw(const RID& p_to_rid,const Color& p_color) {


	DVector<Vector2> s = get_segments();
	int len=s.size();
	if (len==0 || (len%2)==1)
		return;

	DVector<Vector2>::Read r = s.read();
	for(int i=0;i<len;i+=2) {
		VisualServer::get_singleton()->canvas_item_add_line(p_to_rid,r[i],r[i+1],p_color,2);
	}

}
Ejemplo n.º 22
0
void Font::_set_kernings(const DVector<int>& p_kernings) {

	int len=p_kernings.size();
	ERR_FAIL_COND(len%3);
	if (!len)
		return;
	DVector<int>::Read r=p_kernings.read();

	for(int i=0;i<len/3;i++) {

		const int* data = &r[i*3];
		add_kerning_pair(data[0],data[1],data[2]);
	}
}
Ejemplo n.º 23
0
BooleanType GnuplotWindow::getMouseEvent( double &mouseX, double &mouseY )
{
    DVector tmp;
    if (tmp.read( "mouse.dat" ) != SUCCESSFUL_RETURN)
    	return BT_FALSE;

    mouseX = tmp( tmp.getDim()-2 );
    mouseY = tmp( tmp.getDim()-1 );

	if ( system("rm mouse.dat") )
		return BT_FALSE;

    return BT_TRUE;
}
Ejemplo n.º 24
0
void TileMapEditor::_fill_points(const DVector<Vector2> p_points, const Dictionary& p_op) {

	int len = p_points.size();
	DVector<Vector2>::Read pr = p_points.read();

	int id = p_op["id"];
	bool xf = p_op["flip_h"];
	bool yf = p_op["flip_v"];
	bool tr = p_op["transpose"];

	for (int i=0;i<len;i++) {

		_set_cell(pr[i], id, xf, yf, tr);
	}
}
Ejemplo n.º 25
0
Variant _File::get_var() const {

    ERR_FAIL_COND_V(!f,Variant());
    uint32_t len = get_32();
    DVector<uint8_t> buff = get_buffer(len);
    ERR_FAIL_COND_V(buff.size() != len, Variant());

    DVector<uint8_t>::Read r = buff.read();

    Variant v;
    Error err = decode_variant(v,&r[0],len);
    ERR_FAIL_COND_V( err!=OK, Variant() );

    return v;
}
Ejemplo n.º 26
0
void Font::_set_chars(const DVector<int>& p_chars) {

	int len = p_chars.size();
	//char 1 charsize 1 texture, 4 rect, 2 align, advance 1
	ERR_FAIL_COND(len%9);
	if (!len)
		return; //none to do
	int chars = len/9;


	DVector<int>::Read r=p_chars.read();
	for(int i=0;i<chars;i++) {

		const int* data = &r[i*9];
		add_char(data[0],data[1],Rect2(data[2],data[3],data[4],data[5]), Size2(data[6],data[7]),data[8]);
	}

}
Ejemplo n.º 27
0
void SampleManagerMallocSW::sample_set_data(RID p_sample, const DVector<uint8_t>& p_buffer) {

	Sample *s = sample_owner.get(p_sample);
	ERR_FAIL_COND(!s);

	int buff_size=p_buffer.size();
	ERR_FAIL_COND(buff_size==0);

	ERR_EXPLAIN("Sample buffer size does not match sample size.");
	ERR_FAIL_COND(s->length_bytes!=buff_size);
	DVector<uint8_t>::Read buffer_r=p_buffer.read();
	const uint8_t *src = buffer_r.ptr();
	uint8_t *dst = (uint8_t*)s->data;

	for(int i=0;i<s->length_bytes;i++) {

		dst[i]=src[i];
	}

}
Rect2 ConcavePolygonShape2D::get_rect() const {


	DVector<Vector2> s = get_segments();
	int len=s.size();
	if (len==0)
		return Rect2();

	Rect2 rect;

	DVector<Vector2>::Read r = s.read();
	for(int i=0;i<len;i++) {
		if (i==0)
			rect.pos=r[i];
		else
			rect.expand_to(r[i]);
	}

	return rect;

}
Ejemplo n.º 29
0
Array StreamPeer::_put_partial_data(const DVector<uint8_t> &p_data) {

	Array ret;

	int len = p_data.size();
	if (len == 0) {
		ret.push_back(OK);
		ret.push_back(0);
		return ret;
	}

	DVector<uint8_t>::Read r = p_data.read();
	int sent;
	Error err = put_partial_data(&r[0], len, sent);

	if (err != OK) {
		sent = 0;
	}
	ret.push_back(err);
	ret.push_back(sent);
	return ret;
}
Ejemplo n.º 30
0
	virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) {

		print_line("attempt to call "+String(p_method));

		r_error.error=Variant::CallError::CALL_OK;

		Map<StringName,MethodData >::Element *E=method_map.find(p_method);
		if (!E) {

			print_line("no exists");
			r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD;
			return Variant();
		}


		int ac = E->get().argtypes.size();
		if (ac<p_argcount) {

			print_line("fewargs");
			r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
			r_error.argument=ac;
			return Variant();
		}

		if (ac>p_argcount) {

			print_line("manyargs");
			r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
			r_error.argument=ac;
			return Variant();
		}



		for(int i=0;i<p_argcount;i++) {

			if (!Variant::can_convert(p_args[i]->get_type(),E->get().argtypes[i])) {

				r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
				r_error.argument=i;
				r_error.expected=E->get().argtypes[i];
			}
		}


		jvalue *v=NULL;

		if (p_argcount) {

			v=(jvalue*)alloca( sizeof(jvalue)*p_argcount );
		}

		for(int i=0;i<p_argcount;i++) {


			switch(E->get().argtypes[i]) {

				case Variant::BOOL: {

					v[i].z=*p_args[i];
				} break;
				case Variant::INT: {

					v[i].i=*p_args[i];
				} break;
				case Variant::REAL: {

					v[i].f=*p_args[i];
				} break;
				case Variant::STRING: {

					String s = *p_args[i];
					jstring jStr = env->NewStringUTF(s.utf8().get_data());
					v[i].l=jStr;
				} break;
				case Variant::STRING_ARRAY: {

					DVector<String> sarray = *p_args[i];
					jobjectArray arr = env->NewObjectArray(sarray.size(),env->FindClass("java/lang/String"),env->NewStringUTF(""));

					for(int j=0;j<sarray.size();j++) {

						env->SetObjectArrayElement(arr,j,env->NewStringUTF( sarray[i].utf8().get_data() ));
					}
					v[i].l=arr;

				} break;
				case Variant::INT_ARRAY: {

					DVector<int> array = *p_args[i];
					jintArray arr = env->NewIntArray(array.size());
					DVector<int>::Read r = array.read();
					env->SetIntArrayRegion(arr,0,array.size(),r.ptr());
					v[i].l=arr;

				} break;
				case Variant::REAL_ARRAY: {

					DVector<float> array = *p_args[i];
					jfloatArray arr = env->NewFloatArray(array.size());
					DVector<float>::Read r = array.read();
					env->SetFloatArrayRegion(arr,0,array.size(),r.ptr());
					v[i].l=arr;

				} break;
				default: {

					ERR_FAIL_V(Variant());
				} break;

			}
		}

		print_line("calling method!!");

		Variant ret;

		switch(E->get().ret_type) {

			case Variant::NIL: {


				print_line("call void");
				env->CallVoidMethodA(instance,E->get().method,v);
			} break;
			case Variant::BOOL: {

				ret = env->CallBooleanMethodA(instance,E->get().method,v);
				print_line("call bool");
			} break;
			case Variant::INT: {

				ret = env->CallIntMethodA(instance,E->get().method,v);
				print_line("call int");
			} break;
			case Variant::REAL: {

				ret = env->CallFloatMethodA(instance,E->get().method,v);
			} break;
			case Variant::STRING: {

				jobject o = env->CallObjectMethodA(instance,E->get().method,v);
				String singname = env->GetStringUTFChars((jstring)o, NULL );
			} break;
			case Variant::STRING_ARRAY: {

				jobjectArray arr = (jobjectArray)env->CallObjectMethodA(instance,E->get().method,v);

				int stringCount = env->GetArrayLength(arr);
				DVector<String> sarr;

				for (int i=0; i<stringCount; i++) {
					jstring string = (jstring) env->GetObjectArrayElement(arr, i);
					const char *rawString = env->GetStringUTFChars(string, 0);
					sarr.push_back(String(rawString));
				}

				ret=sarr;

			} break;
			case Variant::INT_ARRAY: {

				jintArray arr = (jintArray)env->CallObjectMethodA(instance,E->get().method,v);

				int fCount = env->GetArrayLength(arr);
				DVector<int> sarr;
				sarr.resize(fCount);

				DVector<int>::Write w = sarr.write();
				env->GetIntArrayRegion(arr,0,fCount,w.ptr());
				w = DVector<int>::Write();
				ret=sarr;
			} break;
			case Variant::REAL_ARRAY: {

				jfloatArray arr = (jfloatArray)env->CallObjectMethodA(instance,E->get().method,v);

				int fCount = env->GetArrayLength(arr);
				DVector<float> sarr;
				sarr.resize(fCount);

				DVector<float>::Write w = sarr.write();
				env->GetFloatArrayRegion(arr,0,fCount,w.ptr());
				w = DVector<float>::Write();
				ret=sarr;
			} break;
			default: {


				print_line("failure..");
				ERR_FAIL_V(Variant());
			} break;
		}

		print_line("success");

		return ret;
	}