From 5dbf1809c6e3e905b94b8764e99491e608122261 Mon Sep 17 00:00:00 2001 From: RĂ©mi Verschelde Date: Sun, 5 Mar 2017 16:44:50 +0100 Subject: A Whole New World (clang-format edition) I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code --- servers/visual_server.cpp | 1161 ++++++++++++++++++++------------------------- 1 file changed, 523 insertions(+), 638 deletions(-) (limited to 'servers/visual_server.cpp') diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 5d231d208..a28c409b9 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -30,23 +30,20 @@ #include "global_config.h" #include "method_bind_ext.inc" -VisualServer *VisualServer::singleton=NULL; -VisualServer* (*VisualServer::create_func)()=NULL; +VisualServer *VisualServer::singleton = NULL; +VisualServer *(*VisualServer::create_func)() = NULL; VisualServer *VisualServer::get_singleton() { return singleton; } - - PoolVector VisualServer::_shader_get_param_list(RID p_shader) const { -//remove at some point + //remove at some point PoolVector pl; - #if 0 List params; shader_get_param_list(p_shader,¶ms); @@ -62,7 +59,7 @@ PoolVector VisualServer::_shader_get_param_list(RID p_shader) const { VisualServer *VisualServer::create() { - ERR_FAIL_COND_V(singleton,NULL); + ERR_FAIL_COND_V(singleton, NULL); if (create_func) return create_func(); @@ -70,13 +67,13 @@ VisualServer *VisualServer::create() { return NULL; } -RID VisualServer::texture_create_from_image(const Image& p_image,uint32_t p_flags) { +RID VisualServer::texture_create_from_image(const Image &p_image, uint32_t p_flags) { RID texture = texture_create(); - texture_allocate(texture,p_image.get_width(), p_image.get_height(), p_image.get_format(), p_flags); //if it has mipmaps, use, else generate - ERR_FAIL_COND_V(!texture.is_valid(),texture); + texture_allocate(texture, p_image.get_width(), p_image.get_height(), p_image.get_format(), p_flags); //if it has mipmaps, use, else generate + ERR_FAIL_COND_V(!texture.is_valid(), texture); - texture_set_data(texture, p_image ); + texture_set_data(texture, p_image); return texture; } @@ -89,41 +86,40 @@ RID VisualServer::get_test_texture() { #define TEST_TEXTURE_SIZE 256 - PoolVector test_data; - test_data.resize(TEST_TEXTURE_SIZE*TEST_TEXTURE_SIZE*3); + test_data.resize(TEST_TEXTURE_SIZE * TEST_TEXTURE_SIZE * 3); { - PoolVector::Write w=test_data.write(); + PoolVector::Write w = test_data.write(); - for (int x=0;x tangents; PoolVector uvs; - int vtx_idx=0; -#define ADD_VTX(m_idx) \ - vertices.push_back( face_points[m_idx] );\ - normals.push_back( normal_points[m_idx] );\ - tangents.push_back( normal_points[m_idx][1] );\ - tangents.push_back( normal_points[m_idx][2] );\ - tangents.push_back( normal_points[m_idx][0] );\ - tangents.push_back( 1.0 );\ - uvs.push_back( Vector3(uv_points[m_idx*2+0],uv_points[m_idx*2+1],0) );\ - vtx_idx++;\ - - for (int i=0;i<6;i++) { + int vtx_idx = 0; +#define ADD_VTX(m_idx) \ + vertices.push_back(face_points[m_idx]); \ + normals.push_back(normal_points[m_idx]); \ + tangents.push_back(normal_points[m_idx][1]); \ + tangents.push_back(normal_points[m_idx][2]); \ + tangents.push_back(normal_points[m_idx][0]); \ + tangents.push_back(1.0); \ + uvs.push_back(Vector3(uv_points[m_idx * 2 + 0], uv_points[m_idx * 2 + 1], 0)); \ + vtx_idx++; + for (int i = 0; i < 6; i++) { Vector3 face_points[4]; Vector3 normal_points[4]; - float uv_points[8]={0,0,0,1,1,1,1,0}; + float uv_points[8] = { 0, 0, 0, 1, 1, 1, 1, 0 }; - for (int j=0;j<4;j++) { + for (int j = 0; j < 4; j++) { float v[3]; - v[0]=1.0; - v[1]=1-2*((j>>1)&1); - v[2]=v[1]*(1-2*(j&1)); + v[0] = 1.0; + v[1] = 1 - 2 * ((j >> 1) & 1); + v[2] = v[1] * (1 - 2 * (j & 1)); - for (int k=0;k<3;k++) { + for (int k = 0; k < 3; k++) { - if (i<3) - face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1); + if (i < 3) + face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1); else - face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1); + face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1); } - normal_points[j]=Vector3(); - normal_points[j][i%3]=(i>=3?-1:1); + normal_points[j] = Vector3(); + normal_points[j][i % 3] = (i >= 3 ? -1 : 1); } - //tri 1 + //tri 1 ADD_VTX(0); ADD_VTX(1); ADD_VTX(2); - //tri 2 + //tri 2 ADD_VTX(2); ADD_VTX(3); ADD_VTX(0); - } RID test_cube = mesh_create(); Array d; d.resize(VS::ARRAY_MAX); - d[VisualServer::ARRAY_NORMAL]= normals ; - d[VisualServer::ARRAY_TANGENT]= tangents ; - d[VisualServer::ARRAY_TEX_UV]= uvs ; - d[VisualServer::ARRAY_VERTEX]= vertices ; + d[VisualServer::ARRAY_NORMAL] = normals; + d[VisualServer::ARRAY_TANGENT] = tangents; + d[VisualServer::ARRAY_TEX_UV] = uvs; + d[VisualServer::ARRAY_VERTEX] = vertices; PoolVector indices; indices.resize(vertices.size()); - for(int i=0;i vertices; PoolVector normals; - for(int i = 1; i <= p_lats; i++) { - double lat0 = Math_PI * (-0.5 + (double) (i - 1) / p_lats); - double z0 = Math::sin(lat0); - double zr0 = Math::cos(lat0); + for (int i = 1; i <= p_lats; i++) { + double lat0 = Math_PI * (-0.5 + (double)(i - 1) / p_lats); + double z0 = Math::sin(lat0); + double zr0 = Math::cos(lat0); - double lat1 = Math_PI * (-0.5 + (double) i / p_lats); + double lat1 = Math_PI * (-0.5 + (double)i / p_lats); double z1 = Math::sin(lat1); double zr1 = Math::cos(lat1); - for(int j = p_lons; j >= 1; j--) { + for (int j = p_lons; j >= 1; j--) { - double lng0 = 2 * Math_PI * (double) (j - 1) / p_lons; + double lng0 = 2 * Math_PI * (double)(j - 1) / p_lons; double x0 = Math::cos(lng0); double y0 = Math::sin(lng0); - double lng1 = 2 * Math_PI * (double) (j) / p_lons; + double lng1 = 2 * Math_PI * (double)(j) / p_lons; double x1 = Math::cos(lng1); double y1 = Math::sin(lng1); - - Vector3 v[4]={ - Vector3(x1 * zr0, z0, y1 *zr0), - Vector3(x1 * zr1, z1, y1 *zr1), - Vector3(x0 * zr1, z1, y0 *zr1), - Vector3(x0 * zr0, z0, y0 *zr0) + Vector3 v[4] = { + Vector3(x1 * zr0, z0, y1 * zr0), + Vector3(x1 * zr1, z1, y1 * zr1), + Vector3(x0 * zr1, z1, y0 * zr1), + Vector3(x0 * zr0, z0, y0 * zr0) }; -#define ADD_POINT(m_idx)\ - normals.push_back(v[m_idx]); \ - vertices.push_back(v[m_idx]*p_radius);\ +#define ADD_POINT(m_idx) \ + normals.push_back(v[m_idx]); \ + vertices.push_back(v[m_idx] * p_radius); ADD_POINT(0); ADD_POINT(1); @@ -286,32 +274,31 @@ RID VisualServer::make_sphere_mesh(int p_lats,int p_lons,float p_radius) { Array d; d.resize(VS::ARRAY_MAX); - d[ARRAY_VERTEX]=vertices; - d[ARRAY_NORMAL]=normals; + d[ARRAY_VERTEX] = vertices; + d[ARRAY_NORMAL] = normals; - mesh_add_surface_from_arrays(mesh,PRIMITIVE_TRIANGLES,d); + mesh_add_surface_from_arrays(mesh, PRIMITIVE_TRIANGLES, d); return mesh; } - RID VisualServer::material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_alpha, bool p_opaque_prepass) { - int version=0; + int version = 0; if (p_shaded) - version=1; + version = 1; if (p_transparent) - version|=2; + version |= 2; if (p_cut_alpha) - version|=4; + version |= 4; if (p_opaque_prepass) - version|=8; + version |= 8; if (material_2d[version].is_valid()) return material_2d[version]; //not valid, make -/* material_2d[version]=fixed_material_create(); + /* material_2d[version]=fixed_material_create(); fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_ALPHA,p_transparent); fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_DISCARD_ALPHA,p_cut_alpha); @@ -330,189 +317,167 @@ RID VisualServer::get_white_texture() { return white_texture; PoolVector wt; - wt.resize(16*3); + wt.resize(16 * 3); { - PoolVector::Write w =wt.write(); - for(int i=0;i<16*3;i++) - w[i]=255; + PoolVector::Write w = wt.write(); + for (int i = 0; i < 16 * 3; i++) + w[i] = 255; } - Image white(4,4,0,Image::FORMAT_RGB8,wt); - white_texture=texture_create(); - texture_allocate(white_texture,4,4,Image::FORMAT_RGB8); - texture_set_data(white_texture,white); + Image white(4, 4, 0, Image::FORMAT_RGB8, wt); + white_texture = texture_create(); + texture_allocate(white_texture, 4, 4, Image::FORMAT_RGB8); + texture_set_data(white_texture, white); return white_texture; - } - -Error VisualServer::_surface_set_data(Array p_arrays,uint32_t p_format,uint32_t *p_offsets,uint32_t p_stride,PoolVector &r_vertex_array,int p_vertex_array_len,PoolVector &r_index_array,int p_index_array_len,Rect3 &r_aabb,Vector r_bone_aabb) { +Error VisualServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint32_t *p_offsets, uint32_t p_stride, PoolVector &r_vertex_array, int p_vertex_array_len, PoolVector &r_index_array, int p_index_array_len, Rect3 &r_aabb, Vector r_bone_aabb) { PoolVector::Write vw = r_vertex_array.write(); PoolVector::Write iw; if (r_index_array.size()) { - print_line("elements: "+itos(r_index_array.size())); - - iw=r_index_array.write(); + print_line("elements: " + itos(r_index_array.size())); + iw = r_index_array.write(); } - int max_bone=0; - + int max_bone = 0; - for(int ai=0;ai array = p_arrays[ai]; - ERR_FAIL_COND_V( array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER ); - + ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER); PoolVector::Read read = array.read(); - const Vector2* src=read.ptr(); + const Vector2 *src = read.ptr(); // setting vertices means regenerating the AABB Rect2 aabb; + if (p_format & ARRAY_COMPRESS_VERTEX) { - if (p_format&ARRAY_COMPRESS_VERTEX) { + for (int i = 0; i < p_vertex_array_len; i++) { - for (int i=0;i array = p_arrays[ai]; - ERR_FAIL_COND_V( array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER ); - + ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER); PoolVector::Read read = array.read(); - const Vector3* src=read.ptr(); + const Vector3 *src = read.ptr(); // setting vertices means regenerating the AABB Rect3 aabb; + if (p_format & ARRAY_COMPRESS_VERTEX) { - if (p_format&ARRAY_COMPRESS_VERTEX) { - - for (int i=0;i array = p_arrays[ai]; - ERR_FAIL_COND_V( array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER ); - + ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER); PoolVector::Read read = array.read(); - const Vector3* src=read.ptr(); + const Vector3 *src = read.ptr(); // setting vertices means regenerating the AABB - if (p_format&ARRAY_COMPRESS_NORMAL) { + if (p_format & ARRAY_COMPRESS_NORMAL) { - for (int i=0;i array = p_arrays[ai]; - ERR_FAIL_COND_V( array.size() != p_vertex_array_len*4, ERR_INVALID_PARAMETER ); - + ERR_FAIL_COND_V(array.size() != p_vertex_array_len * 4, ERR_INVALID_PARAMETER); PoolVector::Read read = array.read(); - const real_t* src = read.ptr(); + const real_t *src = read.ptr(); - if (p_format&ARRAY_COMPRESS_TANGENT) { + if (p_format & ARRAY_COMPRESS_TANGENT) { - for (int i=0;i array = p_arrays[ai]; - ERR_FAIL_COND_V( array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER ); - + ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER); PoolVector::Read read = array.read(); - const Color* src = read.ptr(); + const Color *src = read.ptr(); - if (p_format&ARRAY_COMPRESS_COLOR) { - - for (int i=0;i array = p_arrays[ai]; - ERR_FAIL_COND_V( array.size() != p_vertex_array_len , ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER); PoolVector::Read read = array.read(); - const Vector2 * src=read.ptr(); - - + const Vector2 *src = read.ptr(); - if (p_format&ARRAY_COMPRESS_TEX_UV) { + if (p_format & ARRAY_COMPRESS_TEX_UV) { - for (int i=0;i array = p_arrays[ai]; - ERR_FAIL_COND_V( array.size() != p_vertex_array_len , ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(array.size() != p_vertex_array_len, ERR_INVALID_PARAMETER); PoolVector::Read read = array.read(); - const Vector2 * src=read.ptr(); + const Vector2 *src = read.ptr(); + if (p_format & ARRAY_COMPRESS_TEX_UV2) { + for (int i = 0; i < p_vertex_array_len; i++) { - if (p_format&ARRAY_COMPRESS_TEX_UV2) { - - for (int i=0;i array = p_arrays[ai]; - ERR_FAIL_COND_V( array.size() != p_vertex_array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER ); - + ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER); PoolVector::Read read = array.read(); - const real_t * src = read.ptr(); + const real_t *src = read.ptr(); - if (p_format&ARRAY_COMPRESS_WEIGHTS) { + if (p_format & ARRAY_COMPRESS_WEIGHTS) { - for (int i=0;i array = p_arrays[ai]; - ERR_FAIL_COND_V( array.size() != p_vertex_array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER ); - + ERR_FAIL_COND_V(array.size() != p_vertex_array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER); PoolVector::Read read = array.read(); - const int * src = read.ptr(); + const int *src = read.ptr(); + if (!(p_format & ARRAY_FLAG_USE_16_BIT_BONES)) { - if (!(p_format&ARRAY_FLAG_USE_16_BIT_BONES)) { - - for (int i=0;i indices = p_arrays[ai]; - ERR_FAIL_COND_V( indices.size() == 0, ERR_INVALID_PARAMETER ); - ERR_FAIL_COND_V( indices.size() != p_index_array_len, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(indices.size() == 0, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(indices.size() != p_index_array_len, ERR_INVALID_PARAMETER); /* determine wether using 16 or 32 bits indices */ PoolVector::Read read = indices.read(); - const int *src=read.ptr(); - - for (int i=0;i bones = p_arrays[VS::ARRAY_BONES]; PoolVector weights = p_arrays[VS::ARRAY_WEIGHTS]; - bool any_valid=false; + bool any_valid = false; - if (vertices.size() && bones.size()==vertices.size()*4 && weights.size()==bones.size()) { + if (vertices.size() && bones.size() == vertices.size() * 4 && weights.size() == bones.size()) { int vs = vertices.size(); - PoolVector::Read rv =vertices.read(); - PoolVector::Read rb=bones.read(); - PoolVector::Read rw=weights.read(); + PoolVector::Read rv = vertices.read(); + PoolVector::Read rb = bones.read(); + PoolVector::Read rw = weights.read(); Rect3 *bptr = r_bone_aabb.ptr(); - for(int i=0;isize.x<0) { + if (bptr->size.x < 0) { //first - bptr[idx]=Rect3(); - bptr[idx].pos=v; - any_valid=true; + bptr[idx] = Rect3(); + bptr[idx].pos = v; + any_valid = true; } else { bptr[idx].expand_to(v); } @@ -854,226 +785,217 @@ Error VisualServer::_surface_set_data(Array p_arrays,uint32_t p_format,uint32_t return OK; } +void VisualServer::mesh_add_surface_from_arrays(RID p_mesh, PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_compress_format) { -void VisualServer::mesh_add_surface_from_arrays(RID p_mesh,PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes,uint32_t p_compress_format) { - - ERR_FAIL_INDEX( p_primitive, VS::PRIMITIVE_MAX ); - ERR_FAIL_COND(p_arrays.size()!=VS::ARRAY_MAX); + ERR_FAIL_INDEX(p_primitive, VS::PRIMITIVE_MAX); + ERR_FAIL_COND(p_arrays.size() != VS::ARRAY_MAX); - uint32_t format=0; + uint32_t format = 0; // validation - int index_array_len=0; - int array_len=0; + int index_array_len = 0; + int array_len = 0; - for(int i=0;i v2 = var; - array_len=v2.size(); + array_len = v2.size(); } break; case Variant::POOL_VECTOR3_ARRAY: { PoolVector v3 = var; - array_len=v3.size(); + array_len = v3.size(); } break; default: { Array v = var; - array_len=v.size(); + array_len = v.size(); } break; } - array_len=PoolVector3Array(p_arrays[i]).size(); - ERR_FAIL_COND(array_len==0); - } else if (i==VS::ARRAY_INDEX) { + array_len = PoolVector3Array(p_arrays[i]).size(); + ERR_FAIL_COND(array_len == 0); + } else if (i == VS::ARRAY_INDEX) { - index_array_len=PoolIntArray(p_arrays[i]).size(); + index_array_len = PoolIntArray(p_arrays[i]).size(); } } - ERR_FAIL_COND((format&VS::ARRAY_FORMAT_VERTEX)==0); // mandatory - + ERR_FAIL_COND((format & VS::ARRAY_FORMAT_VERTEX) == 0); // mandatory if (p_blend_shapes.size()) { //validate format for morphs - for(int i=0;i bones = p_arrays[VS::ARRAY_BONES]; - int max_bone=0; + int max_bone = 0; { int bc = bones.size(); - PoolVector::Read r=bones.read(); - for(int j=0;j::Read r = bones.read(); + for (int j = 0; j < bc; j++) { + max_bone = MAX(r[j], max_bone); } } if (max_bone > 255) { - p_compress_format|=ARRAY_FLAG_USE_16_BIT_BONES; - elem_size=sizeof(uint16_t)*4; + p_compress_format |= ARRAY_FLAG_USE_16_BIT_BONES; + elem_size = sizeof(uint16_t) * 4; } else { - p_compress_format&=~ARRAY_FLAG_USE_16_BIT_BONES; - elem_size=sizeof(uint32_t); + p_compress_format &= ~ARRAY_FLAG_USE_16_BIT_BONES; + elem_size = sizeof(uint32_t); } - } break; case VS::ARRAY_INDEX: { - if (index_array_len<=0) { + if (index_array_len <= 0) { ERR_PRINT("index_array_len==NO_INDEX_ARRAY"); break; } /* determine wether using 16 or 32 bits indices */ - if (array_len>=(1<<16)) { + if (array_len >= (1 << 16)) { - elem_size=4; + elem_size = 4; } else { - elem_size=2; + elem_size = 2; } - offsets[i]=elem_size; + offsets[i] = elem_size; continue; } break; default: { - ERR_FAIL( ); + ERR_FAIL(); } } - offsets[i]=total_elem_size; - total_elem_size+=elem_size; - - + offsets[i] = total_elem_size; + total_elem_size += elem_size; } - uint32_t mask = (1< vertex_array; vertex_array.resize(array_size); - int index_array_size = offsets[VS::ARRAY_INDEX]*index_array_len; + int index_array_size = offsets[VS::ARRAY_INDEX] * index_array_len; PoolVector index_array; index_array.resize(index_array_size); @@ -1081,163 +1003,156 @@ void VisualServer::mesh_add_surface_from_arrays(RID p_mesh,PrimitiveType p_primi Rect3 aabb; Vector bone_aabb; - Error err = _surface_set_data(p_arrays,format,offsets,total_elem_size,vertex_array,array_len,index_array,index_array_len,aabb,bone_aabb); + Error err = _surface_set_data(p_arrays, format, offsets, total_elem_size, vertex_array, array_len, index_array, index_array_len, aabb, bone_aabb); if (err) { ERR_EXPLAIN("Invalid array format for surface"); - ERR_FAIL_COND(err!=OK); + ERR_FAIL_COND(err != OK); } Vector > blend_shape_data; - for(int i=0;i vertex_array_shape; vertex_array_shape.resize(array_size); PoolVector noindex; Rect3 laabb; - Error err = _surface_set_data(p_blend_shapes[i],format&~ARRAY_FORMAT_INDEX,offsets,total_elem_size,vertex_array_shape,array_len,noindex,0,laabb,bone_aabb); + Error err = _surface_set_data(p_blend_shapes[i], format & ~ARRAY_FORMAT_INDEX, offsets, total_elem_size, vertex_array_shape, array_len, noindex, 0, laabb, bone_aabb); aabb.merge_with(laabb); if (err) { ERR_EXPLAIN("Invalid blend shape array format for surface"); - ERR_FAIL_COND(err!=OK); + ERR_FAIL_COND(err != OK); } blend_shape_data.push_back(vertex_array_shape); } - mesh_add_surface(p_mesh,format,p_primitive,vertex_array,array_len,index_array,index_array_len,aabb,blend_shape_data,bone_aabb); - + mesh_add_surface(p_mesh, format, p_primitive, vertex_array, array_len, index_array, index_array_len, aabb, blend_shape_data, bone_aabb); } -Array VisualServer::_get_array_from_surface(uint32_t p_format,PoolVector p_vertex_data,int p_vertex_len,PoolVector p_index_data,int p_index_len) const { - +Array VisualServer::_get_array_from_surface(uint32_t p_format, PoolVector p_vertex_data, int p_vertex_len, PoolVector p_index_data, int p_index_len) const { uint32_t offsets[ARRAY_MAX]; - int total_elem_size=0; + int total_elem_size = 0; - for (int i=0;i=(1<<16)) { + if (p_vertex_len >= (1 << 16)) { - elem_size=4; + elem_size = 4; } else { - elem_size=2; + elem_size = 2; } - offsets[i]=elem_size; + offsets[i] = elem_size; continue; } break; default: { - ERR_FAIL_V( Array() ); + ERR_FAIL_V(Array()); } } - offsets[i]=total_elem_size; - total_elem_size+=elem_size; - - + offsets[i] = total_elem_size; + total_elem_size += elem_size; } Array ret; @@ -1245,127 +1160,123 @@ Array VisualServer::_get_array_from_surface(uint32_t p_format,PoolVector::Read r = p_vertex_data.read(); - for(int i=0;i arr_2d; arr_2d.resize(p_vertex_len); - if (p_format&ARRAY_COMPRESS_VERTEX) { + if (p_format & ARRAY_COMPRESS_VERTEX) { PoolVector::Write w = arr_2d.write(); - for(int j=0;j::Write w = arr_2d.write(); - for(int j=0;j arr_3d; arr_3d.resize(p_vertex_len); - if (p_format&ARRAY_COMPRESS_VERTEX) { + if (p_format & ARRAY_COMPRESS_VERTEX) { PoolVector::Write w = arr_3d.write(); - for(int j=0;j::Write w = arr_3d.write(); - for(int j=0;j arr; arr.resize(p_vertex_len); - if (p_format&ARRAY_COMPRESS_NORMAL) { + if (p_format & ARRAY_COMPRESS_NORMAL) { PoolVector::Write w = arr.write(); - for(int j=0;j::Write w = arr.write(); - for(int j=0;j arr; - arr.resize(p_vertex_len*4); - if (p_format&ARRAY_COMPRESS_TANGENT) { + arr.resize(p_vertex_len * 4); + if (p_format & ARRAY_COMPRESS_TANGENT) { PoolVector::Write w = arr.write(); - for(int j=0;j::Write w = arr.write(); - for(int j=0;j arr; arr.resize(p_vertex_len); - if (p_format&ARRAY_COMPRESS_COLOR) { + if (p_format & ARRAY_COMPRESS_COLOR) { PoolVector::Write w = arr.write(); - for(int j=0;j::Write w = arr.write(); - for(int j=0;j arr; arr.resize(p_vertex_len); - if (p_format&ARRAY_COMPRESS_TEX_UV) { + if (p_format & ARRAY_COMPRESS_TEX_UV) { PoolVector::Write w = arr.write(); - for(int j=0;j::Write w = arr.write(); - for(int j=0;j arr; arr.resize(p_vertex_len); - if (p_format&ARRAY_COMPRESS_TEX_UV2) { + if (p_format & ARRAY_COMPRESS_TEX_UV2) { PoolVector::Write w = arr.write(); - for(int j=0;j::Write w = arr.write(); - for(int j=0;j arr; - arr.resize(p_vertex_len*4); - if (p_format&ARRAY_COMPRESS_WEIGHTS) { + arr.resize(p_vertex_len * 4); + if (p_format & ARRAY_COMPRESS_WEIGHTS) { PoolVector::Write w = arr.write(); - for(int j=0;j::Write w = arr.write(); - for(int j=0;j arr; - arr.resize(p_vertex_len*4); - if (p_format&ARRAY_FLAG_USE_16_BIT_BONES) { + arr.resize(p_vertex_len * 4); + if (p_format & ARRAY_FLAG_USE_16_BIT_BONES) { PoolVector::Write w = arr.write(); - for(int j=0;j::Write w = arr.write(); - for(int j=0;j arr; arr.resize(p_index_len); - if (p_vertex_len<(1<<16)) { + if (p_vertex_len < (1 << 16)) { PoolVector::Write w = arr.write(); - for(int j=0;j::Write w = arr.write(); - for(int j=0;j vertex_data = mesh_surface_get_array(p_mesh,p_surface); - ERR_FAIL_COND_V(vertex_data.size()==0,Array()); - int vertex_len = mesh_surface_get_array_len(p_mesh,p_surface); - - PoolVector index_data = mesh_surface_get_index_array(p_mesh,p_surface); - int index_len = mesh_surface_get_array_index_len(p_mesh,p_surface); +Array VisualServer::mesh_surface_get_arrays(RID p_mesh, int p_surface) const { - uint32_t format = mesh_surface_get_format(p_mesh,p_surface); + PoolVector vertex_data = mesh_surface_get_array(p_mesh, p_surface); + ERR_FAIL_COND_V(vertex_data.size() == 0, Array()); + int vertex_len = mesh_surface_get_array_len(p_mesh, p_surface); + PoolVector index_data = mesh_surface_get_index_array(p_mesh, p_surface); + int index_len = mesh_surface_get_array_index_len(p_mesh, p_surface); - return _get_array_from_surface(format,vertex_data,vertex_len,index_data,index_len); + uint32_t format = mesh_surface_get_format(p_mesh, p_surface); + return _get_array_from_surface(format, vertex_data, vertex_len, index_data, index_len); } void VisualServer::_bind_methods() { - - ClassDB::bind_method(D_METHOD("texture_create"),&VisualServer::texture_create); - ClassDB::bind_method(D_METHOD("texture_create_from_image"),&VisualServer::texture_create_from_image,DEFVAL( TEXTURE_FLAGS_DEFAULT ) ); + ClassDB::bind_method(D_METHOD("texture_create"), &VisualServer::texture_create); + ClassDB::bind_method(D_METHOD("texture_create_from_image"), &VisualServer::texture_create_from_image, DEFVAL(TEXTURE_FLAGS_DEFAULT)); //ClassDB::bind_method(D_METHOD("texture_allocate"),&VisualServer::texture_allocate,DEFVAL( TEXTURE_FLAGS_DEFAULT ) ); //ClassDB::bind_method(D_METHOD("texture_set_data"),&VisualServer::texture_blit_rect,DEFVAL( CUBEMAP_LEFT ) ); //ClassDB::bind_method(D_METHOD("texture_get_rect"),&VisualServer::texture_get_rect ); - ClassDB::bind_method(D_METHOD("texture_set_flags"),&VisualServer::texture_set_flags ); - ClassDB::bind_method(D_METHOD("texture_get_flags"),&VisualServer::texture_get_flags ); - ClassDB::bind_method(D_METHOD("texture_get_width"),&VisualServer::texture_get_width ); - ClassDB::bind_method(D_METHOD("texture_get_height"),&VisualServer::texture_get_height ); - - ClassDB::bind_method(D_METHOD("texture_set_shrink_all_x2_on_set_data","shrink"),&VisualServer::texture_set_shrink_all_x2_on_set_data ); - - - + ClassDB::bind_method(D_METHOD("texture_set_flags"), &VisualServer::texture_set_flags); + ClassDB::bind_method(D_METHOD("texture_get_flags"), &VisualServer::texture_get_flags); + ClassDB::bind_method(D_METHOD("texture_get_width"), &VisualServer::texture_get_width); + ClassDB::bind_method(D_METHOD("texture_get_height"), &VisualServer::texture_get_height); + ClassDB::bind_method(D_METHOD("texture_set_shrink_all_x2_on_set_data", "shrink"), &VisualServer::texture_set_shrink_all_x2_on_set_data); } -void VisualServer::_canvas_item_add_style_box(RID p_item, const Rect2& p_rect, const Rect2& p_source, RID p_texture,const Vector& p_margins, const Color& p_modulate) { +void VisualServer::_canvas_item_add_style_box(RID p_item, const Rect2 &p_rect, const Rect2 &p_source, RID p_texture, const Vector &p_margins, const Color &p_modulate) { - ERR_FAIL_COND(p_margins.size()!=4); + ERR_FAIL_COND(p_margins.size() != 4); //canvas_item_add_style_box(p_item,p_rect,p_source,p_texture,Vector2(p_margins[0],p_margins[1]),Vector2(p_margins[2],p_margins[3]),true,p_modulate); } -void VisualServer::_camera_set_orthogonal(RID p_camera,float p_size,float p_z_near,float p_z_far) { +void VisualServer::_camera_set_orthogonal(RID p_camera, float p_size, float p_z_near, float p_z_far) { - camera_set_orthogonal(p_camera,p_size,p_z_near,p_z_far); + camera_set_orthogonal(p_camera, p_size, p_z_near, p_z_far); } - - - - -void VisualServer::mesh_add_surface_from_mesh_data( RID p_mesh, const Geometry::MeshData& p_mesh_data) { +void VisualServer::mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry::MeshData &p_mesh_data) { #if 1 PoolVector vertices; PoolVector normals; - for (int i=0;i vertices; + for (int i = 0; i < p_mesh_data.edges.size(); i++) { - - for (int i=0;i& p_planes) { - +void VisualServer::mesh_add_surface_from_planes(RID p_mesh, const PoolVector &p_planes) { Geometry::MeshData mdata = Geometry::build_convex_mesh(p_planes); - mesh_add_surface_from_mesh_data(p_mesh,mdata); - + mesh_add_surface_from_mesh_data(p_mesh, mdata); } -void VisualServer::immediate_vertex_2d(RID p_immediate,const Vector2& p_vertex) { - immediate_vertex(p_immediate,Vector3(p_vertex.x,p_vertex.y,0)); +void VisualServer::immediate_vertex_2d(RID p_immediate, const Vector2 &p_vertex) { + immediate_vertex(p_immediate, Vector3(p_vertex.x, p_vertex.y, 0)); } RID VisualServer::instance_create2(RID p_base, RID p_scenario) { RID instance = instance_create(); - instance_set_base(instance,p_base); - instance_set_scenario(instance,p_scenario); + instance_set_base(instance, p_base); + instance_set_scenario(instance, p_scenario); return instance; } - VisualServer::VisualServer() { //ERR_FAIL_COND(singleton); - singleton=this; - + singleton = this; } - VisualServer::~VisualServer() { - singleton=NULL; + singleton = NULL; } -- cgit v1.2.3-70-g09d2