当前位置: 首页>>代码示例>>C++>>正文


C++ DVector::resize方法代码示例

本文整理汇总了C++中DVector::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ DVector::resize方法的具体用法?C++ DVector::resize怎么用?C++ DVector::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DVector的用法示例。


在下文中一共展示了DVector::resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _get_partial_data

Array StreamPeer::_get_partial_data(int p_bytes) {

	Array ret;

	DVector<uint8_t> data;
	data.resize(p_bytes);
	if (data.size() != p_bytes) {

		ret.push_back(ERR_OUT_OF_MEMORY);
		ret.push_back(DVector<uint8_t>());
		return ret;
	}

	DVector<uint8_t>::Write w = data.write();
	int received;
	Error err = get_partial_data(&w[0], p_bytes, received);
	w = DVector<uint8_t>::Write();

	if (err != OK) {
		data.resize(0);
	} else if (received != data.size()) {

		data.resize(received);
	}

	ret.push_back(err);
	ret.push_back(data);
	return ret;
}
开发者ID:allkhor,项目名称:godot,代码行数:29,代码来源:stream_peer.cpp

示例2: sample_set_signed_data

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);


}
开发者ID:03050903,项目名称:godot,代码行数:55,代码来源:audio_server.cpp

示例3: _get_data

Dictionary PolygonPathFinder::_get_data() const{

	Dictionary d;
	DVector<Vector2> p;
	DVector<int> ind;
	Array connections;
	p.resize(points.size()-2);
	connections.resize(points.size()-2);
	ind.resize(edges.size()*2);
	DVector<float> penalties;
	penalties.resize(points.size()-2);
	{
		DVector<Vector2>::Write wp=p.write();
		DVector<float>::Write pw=penalties.write();

		for(int i=0;i<points.size()-2;i++) {
			wp[i]=points[i].pos;
			pw[i]=points[i].penalty;
			DVector<int> c;
			c.resize(points[i].connections.size());
			{
				DVector<int>::Write cw=c.write();
				int idx=0;
				for (Set<int>::Element *E=points[i].connections.front();E;E=E->next()) {
					cw[idx++]=E->get();
				}
			}
			connections[i]=c;
		}
	}
	{

		DVector<int>::Write iw=ind.write();
		int idx=0;
		for (Set<Edge>::Element *E=edges.front();E;E=E->next()) {
			iw[idx++]=E->get().points[0];
			iw[idx++]=E->get().points[1];
		}

	}

	d["bounds"]=bounds;
	d["points"]=p;
	d["penalties"]=penalties;
	d["connections"]=connections;
	d["segments"]=ind;

	return d;

}
开发者ID:AutonomicStudios,项目名称:godot,代码行数:50,代码来源:polygon_path_finder.cpp

示例4: _decompress_etc

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);
}
开发者ID:allkhor,项目名称:godot,代码行数:60,代码来源:image_etc.cpp

示例5: get_pending_frame_count

int VideoStreamTheoraplayer::get_pending_frame_count() const {

	if (!clip)
		return 0;

	if (!frame.empty())
		return 1;

	TheoraVideoFrame* f = clip->getNextFrame();
	if (!f)
		return 0;

	float w=clip->getWidth(),h=clip->getHeight();
    int imgsize = w * h * f->mBpp;

	int size = f->getStride() * f->getHeight() * f->mBpp;
	DVector<uint8_t> data;
	data.resize(imgsize);
	DVector<uint8_t>::Write wr = data.write();
    uint8_t* ptr = wr.ptr();
    copymem(ptr, f->getBuffer(), imgsize);
    /*
    for (int i=0; i<h; i++) {
        int dstofs = i * w * f->mBpp;
        int srcofs = i * f->getStride() * f->mBpp;
        copymem(ptr + dstofs, f->getBuffer() + dstofs, w * f->mBpp);
    };
     */
	frame = Image();
	frame.create(w, h, 0, f->mBpp == 3 ? Image::FORMAT_RGB : Image::FORMAT_RGBA, data);

	clip->popFrame();

	return 1;
};
开发者ID:HiddenDark,项目名称:godot,代码行数:35,代码来源:video_stream_theoraplayer.cpp

示例6:

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;
}
开发者ID:kyoconan,项目名称:godot,代码行数:26,代码来源:variant.cpp

示例7:

DVector<int> TileMap::_get_tile_data() const {

	DVector<int> data;
	data.resize(tile_map.size()*2);
	DVector<int>::Write w = data.write();

	int idx=0;
	for(const Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {

		uint8_t *ptr = (uint8_t*)&w[idx];
		encode_uint16(E->key().x,&ptr[0]);
		encode_uint16(E->key().y,&ptr[2]);
		uint32_t val = E->get().id;
		if (E->get().flip_h)
			val|=(1<<29);
		if (E->get().flip_v)
			val|=(1<<30);

		encode_uint32(val,&ptr[4]);
		idx+=2;
	}


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

	return data;

}
开发者ID:hbiblia,项目名称:godot,代码行数:28,代码来源:tile_map.cpp

示例8: _get_resources

Array ResourcePreloader::_get_resources() const {

	DVector<String> names;
	Array arr;
	arr.resize(resources.size());
	names.resize(resources.size());

	Set<String> sorted_names;

	for(Map<StringName,RES >::Element *E=resources.front();E;E=E->next()) {
		sorted_names.insert(E->key());
	}

	int i=0;
	for(Set<String>::Element *E=sorted_names.front();E;E=E->next()) {

		names.set(i,E->get());
		arr[i]=resources[E->get()];
		i++;
	}

	Array res;
	res.push_back(names);
	res.push_back(arr);
	return res;
}
开发者ID:0871087123,项目名称:godot,代码行数:26,代码来源:resource_preloader.cpp

示例9:

String _Marshalls::variant_to_base64(const Variant& p_var) {

    int len;
    Error err = encode_variant(p_var,NULL,len);
    ERR_FAIL_COND_V( err != OK, "" );

    DVector<uint8_t> buff;
    buff.resize(len);
    DVector<uint8_t>::Write w = buff.write();

    err = encode_variant(p_var,&w[0],len);
    ERR_FAIL_COND_V( err != OK, "" );

    int b64len = len / 3 * 4 + 4 + 1;
    DVector<uint8_t> b64buff;
    b64buff.resize(b64len);
    DVector<uint8_t>::Write w64 = b64buff.write();

    int strlen = base64_encode((char*)(&w64[0]), (char*)(&w[0]), len);
    //OS::get_singleton()->print("len is %i, vector size is %i\n", b64len, strlen);
    w64[strlen] = 0;
    String ret = (char*)&w64[0];

    return ret;
};
开发者ID:,项目名称:,代码行数:25,代码来源:

示例10: load

RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String& p_original_path, Error *r_error) {

	if (r_error)
		*r_error=ERR_FILE_CANT_OPEN;


	FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
	ERR_FAIL_COND_V(!f,RES());

	DVector<uint8_t> data;

	data.resize(f->get_len());

	ERR_FAIL_COND_V(data.size()==0,RES());

	{
		DVector<uint8_t>::Write w = data.write();
		f->get_buffer(w.ptr(),data.size());
	}

	Ref<DynamicFontData> dfd;
	dfd.instance();
	dfd->set_font_data(data);

	if (r_error)
		*r_error=OK;

	return dfd;
}
开发者ID:mrezai,项目名称:godot,代码行数:29,代码来源:dynamic_font.cpp

示例11:

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();

}
开发者ID:AMG194,项目名称:godot,代码行数:60,代码来源:particles_2d_editor_plugin.cpp

示例12: sample_set_signed_data

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);


}
开发者ID:0871087123,项目名称:godot,代码行数:30,代码来源:audio_server.cpp

示例13: jpeg_load_image_from_buffer

Error jpeg_load_image_from_buffer(Image *p_image,const uint8_t* p_buffer, int p_buffer_len) {

	jpgd::jpeg_decoder_mem_stream mem_stream(p_buffer,p_buffer_len);

	jpgd::jpeg_decoder decoder(&mem_stream);

	if (decoder.get_error_code() != jpgd::JPGD_SUCCESS) {
		return ERR_CANT_OPEN;
	}

	const int image_width = decoder.get_width();
	const int image_height = decoder.get_height();
	int comps = decoder.get_num_components();
	if (comps==3)
		comps=4; //weird

	if (decoder.begin_decoding() != jpgd::JPGD_SUCCESS)
		return ERR_FILE_CORRUPT;

	const int dst_bpl = image_width * comps;

	DVector<uint8_t> data;

	data.resize(dst_bpl * image_height);

	DVector<uint8_t>::Write dw = data.write();

	jpgd::uint8 *pImage_data = (jpgd::uint8*)dw.ptr();

	for (int y = 0; y < image_height; y++)
	{
		const jpgd::uint8* pScan_line;
		jpgd::uint scan_line_len;
		if (decoder.decode((const void**)&pScan_line, &scan_line_len) != jpgd::JPGD_SUCCESS)
		{
			return ERR_FILE_CORRUPT;
		}

		jpgd::uint8 *pDst = pImage_data + y * dst_bpl;
		memcpy(pDst, pScan_line, dst_bpl);


	}


	//all good

	Image::Format fmt;
	if (comps==1)
		fmt=Image::FORMAT_GRAYSCALE;
	else
		fmt=Image::FORMAT_RGBA;

	dw = DVector<uint8_t>::Write();
	p_image->create(image_width,image_height,0,fmt,data);

	return OK;

}
开发者ID:261117370,项目名称:godot,代码行数:59,代码来源:image_loader_jpegd.cpp

示例14:

void EditorExportPlatformWindows::store_16(DVector<uint8_t>& vector, uint16_t value) {
	const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&value);
	int size = vector.size();
	vector.resize( size + 2 );
	DVector<uint8_t>::Write w = vector.write();
	w[size]=bytes[0];
	w[size+1]=bytes[1];
}
开发者ID:Scrik,项目名称:godot,代码行数:8,代码来源:export.cpp

示例15: image_compress_squish

void image_compress_squish(Image *p_image) {

	int w=p_image->get_width();
	int h=p_image->get_height();

	if (p_image->get_mipmaps() == 0) {
		ERR_FAIL_COND( !w || w % 4 != 0);
		ERR_FAIL_COND( !h || h % 4 != 0);
	} else {
		ERR_FAIL_COND( !w || w !=nearest_power_of_2(w) );
		ERR_FAIL_COND( !h || h !=nearest_power_of_2(h) );
	};

	if (p_image->get_format()>=Image::FORMAT_BC1)
		return; //do not compress, already compressed


	Image::AlphaMode alpha = p_image->detect_alpha();
	Image::Format target_format;
	int shift=0;
	int squish_comp=squish::kColourRangeFit;
	switch(alpha) {

		case Image::ALPHA_NONE: target_format = Image::FORMAT_BC1; shift=1; squish_comp|=squish::kDxt1; break;
		case Image::ALPHA_BIT: target_format = Image::FORMAT_BC2; squish_comp|=squish::kDxt3; break;
		case Image::ALPHA_BLEND: target_format = Image::FORMAT_BC3; squish_comp|=squish::kDxt5; break;
	}


	p_image->convert(Image::FORMAT_RGBA); //always expects rgba

	int mm_count = p_image->get_mipmaps();

	DVector<uint8_t> data;
	int target_size = Image::get_image_data_size(w,h,target_format,mm_count);
	data.resize(target_size);

	DVector<uint8_t>::Read rb = p_image->get_data().read();
	DVector<uint8_t>::Write wb = data.write();

	int dst_ofs=0;

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

		int src_ofs = p_image->get_mipmap_offset(i);
		squish::CompressImage( &rb[src_ofs],w,h,&wb[dst_ofs],squish_comp);
		dst_ofs+=(MAX(4,w)*MAX(4,h))>>shift;
		w>>=1;
		h>>=1;
	}

	rb = DVector<uint8_t>::Read();
	wb = DVector<uint8_t>::Write();

	p_image->create(p_image->get_width(),p_image->get_height(),p_image->get_mipmaps(),target_format,data);

}
开发者ID:0871087123,项目名称:godot,代码行数:57,代码来源:image_compress_squish.cpp


注:本文中的DVector::resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。