本文整理汇总了C++中PoolVector::write方法的典型用法代码示例。如果您正苦于以下问题:C++ PoolVector::write方法的具体用法?C++ PoolVector::write怎么用?C++ PoolVector::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PoolVector
的用法示例。
在下文中一共展示了PoolVector::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _get_data
Dictionary PolygonPathFinder::_get_data() const {
Dictionary d;
PoolVector<Vector2> p;
PoolVector<int> ind;
Array connections;
p.resize(points.size() - 2);
connections.resize(points.size() - 2);
ind.resize(edges.size() * 2);
PoolVector<float> penalties;
penalties.resize(points.size() - 2);
{
PoolVector<Vector2>::Write wp = p.write();
PoolVector<float>::Write pw = penalties.write();
for (int i = 0; i < points.size() - 2; i++) {
wp[i] = points[i].pos;
pw[i] = points[i].penalty;
PoolVector<int> c;
c.resize(points[i].connections.size());
{
PoolVector<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;
}
}
{
PoolVector<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;
}
示例2: 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());
PoolVector<uint8_t> data;
data.resize(f->get_len());
ERR_FAIL_COND_V(data.size() == 0, RES());
{
PoolVector<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;
}
示例3: import
Error ResourceImporterOGGVorbis::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) {
bool loop = p_options["loop"];
FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ);
if (!f) {
ERR_FAIL_COND_V(!f, ERR_CANT_OPEN);
}
size_t len = f->get_len();
PoolVector<uint8_t> data;
data.resize(len);
PoolVector<uint8_t>::Write w = data.write();
f->get_buffer(w.ptr(), len);
memdelete(f);
Ref<AudioStreamOGGVorbis> ogg_stream;
ogg_stream.instance();
ogg_stream->set_data(data);
ogg_stream->set_loop(loop);
return ResourceSaver::save(p_save_path + ".asogg", ogg_stream);
}
示例4: _update_presets
void ColorPicker::_update_presets() {
Size2 size = bt_add_preset->get_size();
preset->set_custom_minimum_size(Size2(size.width * presets.size(), size.height));
PoolVector<uint8_t> img;
img.resize(size.x * presets.size() * size.y * 3);
{
PoolVector<uint8_t>::Write w = img.write();
for (int y = 0; y < size.y; y++) {
for (int x = 0; x < size.x * presets.size(); x++) {
int ofs = (y * (size.x * presets.size()) + x) * 3;
w[ofs + 0] = uint8_t(CLAMP(presets[(int)x / size.x].r * 255.0, 0, 255));
w[ofs + 1] = uint8_t(CLAMP(presets[(int)x / size.x].g * 255.0, 0, 255));
w[ofs + 2] = uint8_t(CLAMP(presets[(int)x / size.x].b * 255.0, 0, 255));
}
}
}
Ref<Image> i = memnew(Image(size.x * presets.size(), size.y, false, Image::FORMAT_RGB8, img));
Ref<ImageTexture> t;
t.instance();
t->create_from_image(i);
preset->set_texture(t);
}
示例5: _get_partial_data
Array StreamPeer::_get_partial_data(int p_bytes) {
Array ret;
PoolVector<uint8_t> data;
data.resize(p_bytes);
if (data.size() != p_bytes) {
ret.push_back(ERR_OUT_OF_MEMORY);
ret.push_back(PoolVector<uint8_t>());
return ret;
}
PoolVector<uint8_t>::Write w = data.write();
int received;
Error err = get_partial_data(&w[0], p_bytes, received);
w = PoolVector<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;
}
示例6: canvas_occluder_polygon_set_shape
void VisualServerCanvas::canvas_occluder_polygon_set_shape(RID p_occluder_polygon, const PoolVector<Vector2> &p_shape, bool p_closed) {
if (p_shape.size() < 3) {
canvas_occluder_polygon_set_shape_as_lines(p_occluder_polygon, p_shape);
return;
}
PoolVector<Vector2> lines;
int lc = p_shape.size() * 2;
lines.resize(lc - (p_closed ? 0 : 2));
{
PoolVector<Vector2>::Write w = lines.write();
PoolVector<Vector2>::Read r = p_shape.read();
int max = lc / 2;
if (!p_closed) {
max--;
}
for (int i = 0; i < max; i++) {
Vector2 a = r[i];
Vector2 b = r[(i + 1) % (lc / 2)];
w[i * 2 + 0] = a;
w[i * 2 + 1] = b;
}
}
canvas_occluder_polygon_set_shape_as_lines(p_occluder_polygon, lines);
}
示例7: if
Ref<TriangleMesh> SpriteBase3D::generate_triangle_mesh() const {
if (triangle_mesh.is_valid())
return triangle_mesh;
PoolVector<Vector3> faces;
faces.resize(6);
PoolVector<Vector3>::Write facesw = faces.write();
Rect2 final_rect = get_item_rect();
if (final_rect.size.x == 0 || final_rect.size.y == 0)
return Ref<TriangleMesh>();
float pixel_size = get_pixel_size();
Vector2 vertices[4] = {
(final_rect.position + Vector2(0, final_rect.size.y)) * pixel_size,
(final_rect.position + final_rect.size) * pixel_size,
(final_rect.position + Vector2(final_rect.size.x, 0)) * pixel_size,
final_rect.position * pixel_size,
};
int x_axis = ((axis + 1) % 3);
int y_axis = ((axis + 2) % 3);
if (axis != Vector3::AXIS_Z) {
SWAP(x_axis, y_axis);
for (int i = 0; i < 4; i++) {
if (axis == Vector3::AXIS_Y) {
vertices[i].y = -vertices[i].y;
} else if (axis == Vector3::AXIS_X) {
vertices[i].x = -vertices[i].x;
}
}
}
static const int indices[6] = {
0, 1, 2,
0, 2, 3
};
for (int j = 0; j < 6; j++) {
int i = indices[j];
Vector3 vtx;
vtx[x_axis] = vertices[i][0];
vtx[y_axis] = vertices[i][1];
facesw[j] = vtx;
}
facesw = PoolVector<Vector3>::Write();
triangle_mesh = Ref<TriangleMesh>(memnew(TriangleMesh));
triangle_mesh->create(faces);
return triangle_mesh;
}
示例8: memnew
void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
if (unparenting || !can_update_body)
return;
CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>();
ERR_FAIL_COND(!co);
if (polygon.size() == 0)
return;
bool solids = build_mode == BUILD_SOLIDS;
if (solids) {
//here comes the sun, lalalala
//decompose concave into multiple convex polygons and add them
Vector<Vector<Vector2> > decomp = _decompose_in_convex();
shape_from = co->get_shape_count();
for (int i = 0; i < decomp.size(); i++) {
Ref<ConvexPolygonShape2D> convex = memnew(ConvexPolygonShape2D);
convex->set_points(decomp[i]);
co->add_shape(convex, get_transform());
if (trigger)
co->set_shape_as_trigger(co->get_shape_count() - 1, true);
}
shape_to = co->get_shape_count() - 1;
if (shape_to < shape_from) {
shape_from = -1;
shape_to = -1;
}
} else {
Ref<ConcavePolygonShape2D> concave = memnew(ConcavePolygonShape2D);
PoolVector<Vector2> segments;
segments.resize(polygon.size() * 2);
PoolVector<Vector2>::Write w = segments.write();
for (int i = 0; i < polygon.size(); i++) {
w[(i << 1) + 0] = polygon[i];
w[(i << 1) + 1] = polygon[(i + 1) % polygon.size()];
}
w = PoolVector<Vector2>::Write();
concave->set_segments(segments);
co->add_shape(concave, get_transform());
if (trigger)
co->set_shape_as_trigger(co->get_shape_count() - 1, true);
shape_from = co->get_shape_count() - 1;
shape_to = co->get_shape_count() - 1;
}
//co->add_shape(shape,get_transform());
}
示例9: _get
bool GridMap::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name;
if (name == "theme") {
r_ret = get_theme();
} else if (name == "cell_size") {
r_ret = get_cell_size();
} else if (name == "cell_octant_size") {
r_ret = get_octant_size();
} else if (name == "cell_center_x") {
r_ret = get_center_x();
} else if (name == "cell_center_y") {
r_ret = get_center_y();
} else if (name == "cell_center_z") {
r_ret = get_center_z();
} else if (name == "cell_scale") {
r_ret = cell_scale;
} else if (name == "data") {
Dictionary d;
PoolVector<int> cells;
cells.resize(cell_map.size() * 3);
{
PoolVector<int>::Write w = cells.write();
int i = 0;
for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) {
encode_uint64(E->key().key, (uint8_t *)&w[i * 3]);
encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]);
}
}
d["cells"] = cells;
r_ret = d;
} else if (name.begins_with("areas/")) {
int which = name.get_slicec('/', 1).to_int();
String what = name.get_slicec('/', 2);
if (what == "bounds")
r_ret = area_get_bounds(which);
else if (what == "name")
r_ret = area_get_name(which);
else if (what == "disable_distance")
r_ret = area_get_portal_disable_distance(which);
else if (what == "exterior_portal")
r_ret = area_is_exterior_portal(which);
else
return false;
} else
return false;
return true;
}
示例10:
PoolVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
ERR_FAIL_COND_V(!points.has(p_from_id),PoolVector<Vector3>());
ERR_FAIL_COND_V(!points.has(p_to_id),PoolVector<Vector3>());
pass++;
Point* a = points[p_from_id];
Point* b = points[p_to_id];
if (a==b) {
PoolVector<Vector3> ret;
ret.push_back(a->pos);
return ret;
}
Point *begin_point=a;
Point *end_point=b;
bool found_route=_solve(begin_point,end_point);
if (!found_route)
return PoolVector<Vector3>();
//midpoints
Point *p=end_point;
int pc=1; //begin point
while(p!=begin_point) {
pc++;
p=p->prev_point;
}
PoolVector<Vector3> path;
path.resize(pc);
{
PoolVector<Vector3>::Write w = path.write();
Point *p=end_point;
int idx=pc-1;
while(p!=begin_point) {
w[idx--]=p->pos;
p=p->prev_point;
}
w[0]=p->pos; //assign first
}
return path;
}
示例11: _process_raw
void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) {
ERR_FAIL_COND(p_packet_len < 2);
PoolVector<uint8_t> out;
int len = p_packet_len - 1;
out.resize(len);
{
PoolVector<uint8_t>::Write w = out.write();
memcpy(&w[0], &p_packet[1], len);
}
emit_signal("network_peer_packet", p_from, out);
}
示例12: add_vertices_to_array
void Shape::add_vertices_to_array(PoolVector<Vector3> &array, const Transform &p_xform) {
Vector<Vector3> toadd = _gen_debug_mesh_lines();
if (toadd.size()) {
int base = array.size();
array.resize(base + toadd.size());
PoolVector<Vector3>::Write w = array.write();
for (int i = 0; i < toadd.size(); i++) {
w[i + base] = p_xform.xform(toadd[i]);
}
}
}
示例13: get_packet_buffer
Error PacketPeer::get_packet_buffer(PoolVector<uint8_t> &r_buffer) const {
const uint8_t *buffer;
int buffer_size;
Error err = get_packet(&buffer, buffer_size);
if (err)
return err;
r_buffer.resize(buffer_size);
if (buffer_size == 0)
return OK;
PoolVector<uint8_t>::Write w = r_buffer.write();
for (int i = 0; i < buffer_size; i++)
w[i] = buffer[i];
return OK;
}
示例14: _get
bool GridMap::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name;
if (name == "theme") {
r_ret = get_theme();
} else if (name == "cell_size") {
r_ret = get_cell_size();
} else if (name == "cell_octant_size") {
r_ret = get_octant_size();
} else if (name == "cell_center_x") {
r_ret = get_center_x();
} else if (name == "cell_center_y") {
r_ret = get_center_y();
} else if (name == "cell_center_z") {
r_ret = get_center_z();
} else if (name == "cell_scale") {
r_ret = cell_scale;
} else if (name == "data") {
Dictionary d;
PoolVector<int> cells;
cells.resize(cell_map.size() * 3);
{
PoolVector<int>::Write w = cells.write();
int i = 0;
for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) {
encode_uint64(E->key().key, (uint8_t *)&w[i * 3]);
encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]);
}
}
d["cells"] = cells;
r_ret = d;
} else
return false;
return true;
}
示例15: _get_data
Array StreamPeer::_get_data(int p_bytes) {
Array ret;
PoolVector<uint8_t> data;
data.resize(p_bytes);
if (data.size() != p_bytes) {
ret.push_back(ERR_OUT_OF_MEMORY);
ret.push_back(PoolVector<uint8_t>());
return ret;
}
PoolVector<uint8_t>::Write w = data.write();
Error err = get_data(&w[0], p_bytes);
w = PoolVector<uint8_t>::Write();
ret.push_back(err);
ret.push_back(data);
return ret;
}