diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-01-07 18:25:37 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-01-07 18:26:38 -0300 |
commit | 2ab83e1abbf5ee6d00e16056a9e9394114026f28 (patch) | |
tree | 7efbb375cc4d00d8e8589fcf1b6a1303bec5df2d /drivers | |
parent | 2a38a5eaa844043b846e03d6655f84caf8a31e74 (diff) |
Memory pool vectors (DVector) have been enormously simplified in code, and renamed to PoolVector
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 90 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 4 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 110 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 24 | ||||
-rw-r--r-- | drivers/png/image_loader_png.cpp | 32 | ||||
-rw-r--r-- | drivers/png/resource_saver_png.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 7 | ||||
-rw-r--r-- | drivers/unix/rw_lock_posix.cpp | 76 | ||||
-rw-r--r-- | drivers/unix/rw_lock_posix.h | 37 |
9 files changed, 246 insertions, 136 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index b49f817188..2673c79232 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -998,7 +998,7 @@ void RasterizerGLES2::texture_set_data(RID p_texture,const Image& p_image,VS::Cu GLenum blit_target = (texture->target == GL_TEXTURE_CUBE_MAP)?_cube_side_enum[p_cube_side]:GL_TEXTURE_2D; texture->data_size=img.get_data().size(); - DVector<uint8_t>::Read read = img.get_data().read(); + PoolVector<uint8_t>::Read read = img.get_data().read(); glActiveTexture(GL_TEXTURE0); glBindTexture(texture->target, texture->tex_id); @@ -1133,7 +1133,7 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid ERR_FAIL_COND_V(!texture->active,Image()); ERR_FAIL_COND_V(texture->data_size==0,Image()); - DVector<uint8_t> data; + PoolVector<uint8_t> data; GLenum format,type=GL_UNSIGNED_BYTE; Image::Format fmt; int pixelsize=0; @@ -1235,7 +1235,7 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid } data.resize(texture->data_size); - DVector<uint8_t>::Write wb = data.write(); + PoolVector<uint8_t>::Write wb = data.write(); glActiveTexture(GL_TEXTURE0); int ofs=0; @@ -1264,7 +1264,7 @@ Image RasterizerGLES2::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_sid } - wb=DVector<uint8_t>::Write(); + wb=PoolVector<uint8_t>::Write(); Image img(texture->alloc_width,texture->alloc_height,texture->mipmaps,fmt,data); @@ -2103,10 +2103,10 @@ void RasterizerGLES2::mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive, uint8_t *array_ptr=NULL; uint8_t *index_array_ptr=NULL; - DVector<uint8_t> array_pre_vbo; - DVector<uint8_t>::Write vaw; - DVector<uint8_t> index_array_pre_vbo; - DVector<uint8_t>::Write iaw; + PoolVector<uint8_t> array_pre_vbo; + PoolVector<uint8_t>::Write vaw; + PoolVector<uint8_t> index_array_pre_vbo; + PoolVector<uint8_t>::Write iaw; /* create pointers */ if (use_VBO) { @@ -2191,11 +2191,11 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER ); - DVector<Vector3> array = p_arrays[ai]; + PoolVector<Vector3> array = p_arrays[ai]; ERR_FAIL_COND_V( array.size() != p_surface->array_len, ERR_INVALID_PARAMETER ); - DVector<Vector3>::Read read = array.read(); + PoolVector<Vector3>::Read read = array.read(); const Vector3* src=read.ptr(); // setting vertices means regenerating the AABB @@ -2252,11 +2252,11 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER ); - DVector<Vector3> array = p_arrays[ai]; + PoolVector<Vector3> array = p_arrays[ai]; ERR_FAIL_COND_V( array.size() != p_surface->array_len, ERR_INVALID_PARAMETER ); - DVector<Vector3>::Read read = array.read(); + PoolVector<Vector3>::Read read = array.read(); const Vector3* src=read.ptr(); // setting vertices means regenerating the AABB @@ -2292,12 +2292,12 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER ); - DVector<real_t> array = p_arrays[ai]; + PoolVector<real_t> array = p_arrays[ai]; ERR_FAIL_COND_V( array.size() != p_surface->array_len*4, ERR_INVALID_PARAMETER ); - DVector<real_t>::Read read = array.read(); + PoolVector<real_t>::Read read = array.read(); const real_t* src = read.ptr(); if (p_surface->array[VS::ARRAY_TANGENT].datatype==GL_BYTE) { @@ -2337,12 +2337,12 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::COLOR_ARRAY, ERR_INVALID_PARAMETER ); - DVector<Color> array = p_arrays[ai]; + PoolVector<Color> array = p_arrays[ai]; ERR_FAIL_COND_V( array.size() != p_surface->array_len, ERR_INVALID_PARAMETER ); - DVector<Color>::Read read = array.read(); + PoolVector<Color>::Read read = array.read(); const Color* src = read.ptr(); bool alpha=false; @@ -2371,11 +2371,11 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::VECTOR3_ARRAY && p_arrays[ai].get_type() != Variant::VECTOR2_ARRAY, ERR_INVALID_PARAMETER ); - DVector<Vector2> array = p_arrays[ai]; + PoolVector<Vector2> array = p_arrays[ai]; ERR_FAIL_COND_V( array.size() != p_surface->array_len , ERR_INVALID_PARAMETER); - DVector<Vector2>::Read read = array.read(); + PoolVector<Vector2>::Read read = array.read(); const Vector2 * src=read.ptr(); float scale=1.0; @@ -2417,12 +2417,12 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER ); - DVector<real_t> array = p_arrays[ai]; + PoolVector<real_t> array = p_arrays[ai]; ERR_FAIL_COND_V( array.size() != p_surface->array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER ); - DVector<real_t>::Read read = array.read(); + PoolVector<real_t>::Read read = array.read(); const real_t * src = read.ptr(); @@ -2460,12 +2460,12 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER ); - DVector<int> array = p_arrays[ai]; + PoolVector<int> array = p_arrays[ai]; ERR_FAIL_COND_V( array.size() != p_surface->array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER ); - DVector<int>::Read read = array.read(); + PoolVector<int>::Read read = array.read(); const int * src = read.ptr(); @@ -2511,13 +2511,13 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui ERR_FAIL_COND_V( p_surface->index_array_len<=0, ERR_INVALID_DATA ); ERR_FAIL_COND_V( p_arrays[ai].get_type() != Variant::INT_ARRAY, ERR_INVALID_PARAMETER ); - DVector<int> indices = p_arrays[ai]; + PoolVector<int> indices = p_arrays[ai]; ERR_FAIL_COND_V( indices.size() == 0, ERR_INVALID_PARAMETER ); ERR_FAIL_COND_V( indices.size() != p_surface->index_array_len, ERR_INVALID_PARAMETER ); /* determine wether using 16 or 32 bits indices */ - DVector<int>::Read read = indices.read(); + PoolVector<int>::Read read = indices.read(); const int *src=read.ptr(); for (int i=0;i<p_surface->index_array_len;i++) { @@ -2553,18 +2553,18 @@ Error RasterizerGLES2::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,ui for(int i=0;i<total_bones;i++) p_surface->skeleton_bone_used[i]=false; } - DVector<Vector3> vertices = p_arrays[VS::ARRAY_VERTEX]; - DVector<int> bones = p_arrays[VS::ARRAY_BONES]; - DVector<float> weights = p_arrays[VS::ARRAY_WEIGHTS]; + PoolVector<Vector3> vertices = p_arrays[VS::ARRAY_VERTEX]; + PoolVector<int> bones = p_arrays[VS::ARRAY_BONES]; + PoolVector<float> weights = p_arrays[VS::ARRAY_WEIGHTS]; bool any_valid=false; if (vertices.size() && bones.size()==vertices.size()*4 && weights.size()==bones.size()) { //print_line("MAKING SKELETHONG"); int vs = vertices.size(); - DVector<Vector3>::Read rv =vertices.read(); - DVector<int>::Read rb=bones.read(); - DVector<float>::Read rw=weights.read(); + PoolVector<Vector3>::Read rv =vertices.read(); + PoolVector<int>::Read rb=bones.read(); + PoolVector<float>::Read rw=weights.read(); Vector<bool> first; first.resize(total_bones); @@ -3310,7 +3310,7 @@ Vector3 RasterizerGLES2::particles_get_emission_base_velocity(RID p_particles) c } -void RasterizerGLES2::particles_set_emission_points(RID p_particles, const DVector<Vector3>& p_points) { +void RasterizerGLES2::particles_set_emission_points(RID p_particles, const PoolVector<Vector3>& p_points) { Particles* particles = particles_owner.get( p_particles ); ERR_FAIL_COND(!particles); @@ -3318,10 +3318,10 @@ void RasterizerGLES2::particles_set_emission_points(RID p_particles, const DVect particles->data.emission_points=p_points; } -DVector<Vector3> RasterizerGLES2::particles_get_emission_points(RID p_particles) const { +PoolVector<Vector3> RasterizerGLES2::particles_get_emission_points(RID p_particles) const { Particles* particles = particles_owner.get( p_particles ); - ERR_FAIL_COND_V(!particles,DVector<Vector3>()); + ERR_FAIL_COND_V(!particles,PoolVector<Vector3>()); return particles->data.emission_points; @@ -4304,9 +4304,9 @@ void RasterizerGLES2::begin_frame() { void RasterizerGLES2::capture_viewport(Image* r_capture) { #if 0 - DVector<uint8_t> pixels; + PoolVector<uint8_t> pixels; pixels.resize(viewport.width*viewport.height*3); - DVector<uint8_t>::Write w = pixels.write(); + PoolVector<uint8_t>::Write w = pixels.write(); #ifdef GLEW_ENABLED glReadBuffer(GL_COLOR_ATTACHMENT0); #endif @@ -4318,15 +4318,15 @@ void RasterizerGLES2::capture_viewport(Image* r_capture) { glPixelStorei(GL_PACK_ALIGNMENT, 4); - w=DVector<uint8_t>::Write(); + w=PoolVector<uint8_t>::Write(); r_capture->create(viewport.width,viewport.height,0,Image::FORMAT_RGB8,pixels); #else - DVector<uint8_t> pixels; + PoolVector<uint8_t> pixels; pixels.resize(viewport.width*viewport.height*4); - DVector<uint8_t>::Write w = pixels.write(); + PoolVector<uint8_t>::Write w = pixels.write(); glPixelStorei(GL_PACK_ALIGNMENT, 4); // uint64_t time = OS::get_singleton()->get_ticks_usec(); @@ -4359,7 +4359,7 @@ void RasterizerGLES2::capture_viewport(Image* r_capture) { } } - w=DVector<uint8_t>::Write(); + w=PoolVector<uint8_t>::Write(); r_capture->create(viewport.width,viewport.height,0,Image::FORMAT_RGBA8,pixels); //r_capture->flip_y(); @@ -8685,7 +8685,7 @@ RID RasterizerGLES2::canvas_light_occluder_create() { return canvas_occluder_owner.make_rid(co); } -void RasterizerGLES2::canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines) { +void RasterizerGLES2::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2>& p_lines) { CanvasOccluder *co = canvas_occluder_owner.get(p_occluder); ERR_FAIL_COND(!co); @@ -8709,18 +8709,18 @@ void RasterizerGLES2::canvas_light_occluder_set_polylines(RID p_occluder, const - DVector<float> geometry; - DVector<uint16_t> indices; + PoolVector<float> geometry; + PoolVector<uint16_t> indices; int lc = p_lines.size(); geometry.resize(lc*6); indices.resize(lc*3); - DVector<float>::Write vw=geometry.write(); - DVector<uint16_t>::Write iw=indices.write(); + PoolVector<float>::Write vw=geometry.write(); + PoolVector<uint16_t>::Write iw=indices.write(); - DVector<Vector2>::Read lr=p_lines.read(); + PoolVector<Vector2>::Read lr=p_lines.read(); const int POLY_HEIGHT = 16384; diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 5f82e1691b..b5904e09d0 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -4596,10 +4596,10 @@ void RasterizerSceneGLES3::_generate_brdf() { - DVector<uint8_t> brdf; + PoolVector<uint8_t> brdf; brdf.resize(brdf_size*brdf_size*2); - DVector<uint8_t>::Write w = brdf.write(); + PoolVector<uint8_t>::Write w = brdf.write(); for(int i=0;i<brdf_size;i++) { diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 689d7ab8c4..a3c5bf5577 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -670,7 +670,7 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture,const Image& p_image GLenum blit_target = (texture->target == GL_TEXTURE_CUBE_MAP)?_cube_side_enum[p_cube_side]:GL_TEXTURE_2D; texture->data_size=img.get_data().size(); - DVector<uint8_t>::Read read = img.get_data().read(); + PoolVector<uint8_t>::Read read = img.get_data().read(); glActiveTexture(GL_TEXTURE0); glBindTexture(texture->target, texture->tex_id); @@ -831,12 +831,12 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c #ifdef GLES_OVER_GL - DVector<uint8_t> data; + PoolVector<uint8_t> data; int data_size = Image::get_image_data_size(texture->alloc_width,texture->alloc_height,texture->format,texture->mipmaps>1?-1:0); data.resize(data_size*2); //add some memory at the end, just in case for buggy drivers - DVector<uint8_t>::Write wb = data.write(); + PoolVector<uint8_t>::Write wb = data.write(); glActiveTexture(GL_TEXTURE0); @@ -868,7 +868,7 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c } - wb=DVector<uint8_t>::Write(); + wb=PoolVector<uint8_t>::Write(); data.resize(data_size); @@ -1848,11 +1848,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } break; case ShaderLanguage::TYPE_IVEC2: { - DVector<int> iv = value; + PoolVector<int> iv = value; int s = iv.size(); GLint *gui = (GLint*)data; - DVector<int>::Read r = iv.read(); + PoolVector<int>::Read r = iv.read(); for(int i=0;i<2;i++) { if (i<s) @@ -1865,11 +1865,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } break; case ShaderLanguage::TYPE_IVEC3: { - DVector<int> iv = value; + PoolVector<int> iv = value; int s = iv.size(); GLint *gui = (GLint*)data; - DVector<int>::Read r = iv.read(); + PoolVector<int>::Read r = iv.read(); for(int i=0;i<3;i++) { if (i<s) @@ -1882,11 +1882,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy case ShaderLanguage::TYPE_IVEC4: { - DVector<int> iv = value; + PoolVector<int> iv = value; int s = iv.size(); GLint *gui = (GLint*)data; - DVector<int>::Read r = iv.read(); + PoolVector<int>::Read r = iv.read(); for(int i=0;i<4;i++) { if (i<s) @@ -1905,11 +1905,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } break; case ShaderLanguage::TYPE_UVEC2: { - DVector<int> iv = value; + PoolVector<int> iv = value; int s = iv.size(); GLuint *gui = (GLuint*)data; - DVector<int>::Read r = iv.read(); + PoolVector<int>::Read r = iv.read(); for(int i=0;i<2;i++) { if (i<s) @@ -1920,11 +1920,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } } break; case ShaderLanguage::TYPE_UVEC3: { - DVector<int> iv = value; + PoolVector<int> iv = value; int s = iv.size(); GLuint *gui = (GLuint*)data; - DVector<int>::Read r = iv.read(); + PoolVector<int>::Read r = iv.read(); for(int i=0;i<3;i++) { if (i<s) @@ -1935,11 +1935,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy } break; case ShaderLanguage::TYPE_UVEC4: { - DVector<int> iv = value; + PoolVector<int> iv = value; int s = iv.size(); GLuint *gui = (GLuint*)data; - DVector<int>::Read r = iv.read(); + PoolVector<int>::Read r = iv.read(); for(int i=0;i<4;i++) { if (i<s) @@ -2463,9 +2463,9 @@ RID RasterizerStorageGLES3::mesh_create(){ } -void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const AABB& p_aabb,const Vector<DVector<uint8_t> >& p_blend_shapes,const Vector<AABB>& p_bone_aabbs){ +void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const PoolVector<uint8_t>& p_array,int p_vertex_count,const PoolVector<uint8_t>& p_index_array,int p_index_count,const AABB& p_aabb,const Vector<PoolVector<uint8_t> >& p_blend_shapes,const Vector<AABB>& p_bone_aabbs){ - DVector<uint8_t> array = p_array; + PoolVector<uint8_t> array = p_array; Mesh *mesh = mesh_owner.getornull(p_mesh); ERR_FAIL_COND(!mesh); @@ -2667,12 +2667,12 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::P print_line("desired size: "+itos(array_size)+" vcount "+itos(p_vertex_count)+" should be: "+itos(array.size()+p_vertex_count*2)+" but is "+itos(array.size())); if (array.size()!=array_size && array.size()+p_vertex_count*2 == array_size) { //old format, convert - array = DVector<uint8_t>(); + array = PoolVector<uint8_t>(); array.resize( p_array.size()+p_vertex_count*2 ); - DVector<uint8_t>::Write w = array.write(); - DVector<uint8_t>::Read r = p_array.read(); + PoolVector<uint8_t>::Write w = array.write(); + PoolVector<uint8_t>::Read r = p_array.read(); uint16_t *w16 = (uint16_t*)w.ptr(); const uint16_t *r16 = (uint16_t*)r.ptr(); @@ -2739,7 +2739,7 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::P { - DVector<uint8_t>::Read vr = array.read(); + PoolVector<uint8_t>::Read vr = array.read(); glGenBuffers(1,&surface->vertex_id); glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id); @@ -2749,7 +2749,7 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::P if (p_format&VS::ARRAY_FORMAT_INDEX) { - DVector<uint8_t>::Read ir = p_index_array.read(); + PoolVector<uint8_t>::Read ir = p_index_array.read(); glGenBuffers(1,&surface->index_id); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id); @@ -2809,7 +2809,7 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh,uint32_t p_format,VS::P Surface::MorphTarget mt; - DVector<uint8_t>::Read vr = p_blend_shapes[i].read(); + PoolVector<uint8_t>::Read vr = p_blend_shapes[i].read(); glGenBuffers(1,&mt.vertex_id); glBindBuffer(GL_ARRAY_BUFFER,mt.vertex_id); @@ -2933,25 +2933,25 @@ int RasterizerStorageGLES3::mesh_surface_get_array_index_len(RID p_mesh, int p_s return mesh->surfaces[p_surface]->index_array_len; } -DVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_array(RID p_mesh, int p_surface) const{ +PoolVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_array(RID p_mesh, int p_surface) const{ const Mesh *mesh = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!mesh,DVector<uint8_t>()); - ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),DVector<uint8_t>()); + ERR_FAIL_COND_V(!mesh,PoolVector<uint8_t>()); + ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),PoolVector<uint8_t>()); Surface *surface = mesh->surfaces[p_surface]; glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id); void * data = glMapBufferRange(GL_ARRAY_BUFFER,0,surface->array_byte_size,GL_MAP_READ_BIT); - ERR_FAIL_COND_V(!data,DVector<uint8_t>()); + ERR_FAIL_COND_V(!data,PoolVector<uint8_t>()); - DVector<uint8_t> ret; + PoolVector<uint8_t> ret; ret.resize(surface->array_byte_size); { - DVector<uint8_t>::Write w = ret.write(); + PoolVector<uint8_t>::Write w = ret.write(); copymem(w.ptr(),data,surface->array_byte_size); } glUnmapBuffer(GL_ARRAY_BUFFER); @@ -2960,26 +2960,26 @@ DVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_array(RID p_mesh, int return ret; } -DVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_index_array(RID p_mesh, int p_surface) const { +PoolVector<uint8_t> RasterizerStorageGLES3::mesh_surface_get_index_array(RID p_mesh, int p_surface) const { const Mesh *mesh = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!mesh,DVector<uint8_t>()); - ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),DVector<uint8_t>()); + ERR_FAIL_COND_V(!mesh,PoolVector<uint8_t>()); + ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),PoolVector<uint8_t>()); Surface *surface = mesh->surfaces[p_surface]; - ERR_FAIL_COND_V(surface->index_array_len==0,DVector<uint8_t>()); + ERR_FAIL_COND_V(surface->index_array_len==0,PoolVector<uint8_t>()); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id); void * data = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER,0,surface->index_array_byte_size,GL_MAP_READ_BIT); - ERR_FAIL_COND_V(!data,DVector<uint8_t>()); + ERR_FAIL_COND_V(!data,PoolVector<uint8_t>()); - DVector<uint8_t> ret; + PoolVector<uint8_t> ret; ret.resize(surface->index_array_byte_size); { - DVector<uint8_t>::Write w = ret.write(); + PoolVector<uint8_t>::Write w = ret.write(); copymem(w.ptr(),data,surface->index_array_byte_size); } @@ -3019,27 +3019,27 @@ AABB RasterizerStorageGLES3::mesh_surface_get_aabb(RID p_mesh, int p_surface) co } -Vector<DVector<uint8_t> > RasterizerStorageGLES3::mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const{ +Vector<PoolVector<uint8_t> > RasterizerStorageGLES3::mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const{ const Mesh *mesh = mesh_owner.getornull(p_mesh); - ERR_FAIL_COND_V(!mesh,Vector<DVector<uint8_t> >()); - ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),Vector<DVector<uint8_t> >()); + ERR_FAIL_COND_V(!mesh,Vector<PoolVector<uint8_t> >()); + ERR_FAIL_INDEX_V(p_surface,mesh->surfaces.size(),Vector<PoolVector<uint8_t> >()); - Vector<DVector<uint8_t> > bsarr; + Vector<PoolVector<uint8_t> > bsarr; for(int i=0;i<mesh->surfaces[p_surface]->morph_targets.size();i++) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,mesh->surfaces[p_surface]->morph_targets[i].vertex_id); void * data = glMapBufferRange(GL_ELEMENT_ARRAY_BUFFER,0,mesh->surfaces[p_surface]->array_byte_size,GL_MAP_READ_BIT); - ERR_FAIL_COND_V(!data,Vector<DVector<uint8_t> >()); + ERR_FAIL_COND_V(!data,Vector<PoolVector<uint8_t> >()); - DVector<uint8_t> ret; + PoolVector<uint8_t> ret; ret.resize(mesh->surfaces[p_surface]->array_byte_size); { - DVector<uint8_t>::Write w = ret.write(); + PoolVector<uint8_t>::Write w = ret.write(); copymem(w.ptr(),data,mesh->surfaces[p_surface]->array_byte_size); } @@ -4705,7 +4705,7 @@ RID RasterizerStorageGLES3::room_create(){ return RID(); } -void RasterizerStorageGLES3::room_add_bounds(RID p_room, const DVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform){ +void RasterizerStorageGLES3::room_add_bounds(RID p_room, const PoolVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform){ } @@ -4810,7 +4810,7 @@ Transform RasterizerStorageGLES3::gi_probe_get_to_cell_xform(RID p_probe) const -void RasterizerStorageGLES3::gi_probe_set_dynamic_data(RID p_probe,const DVector<int>& p_data){ +void RasterizerStorageGLES3::gi_probe_set_dynamic_data(RID p_probe,const PoolVector<int>& p_data){ GIProbe *gip = gi_probe_owner.getornull(p_probe); ERR_FAIL_COND(!gip); @@ -4819,10 +4819,10 @@ void RasterizerStorageGLES3::gi_probe_set_dynamic_data(RID p_probe,const DVector gip->instance_change_notify(); } -DVector<int> RasterizerStorageGLES3::gi_probe_get_dynamic_data(RID p_probe) const{ +PoolVector<int> RasterizerStorageGLES3::gi_probe_get_dynamic_data(RID p_probe) const{ const GIProbe *gip = gi_probe_owner.getornull(p_probe); - ERR_FAIL_COND_V(!gip,DVector<int>()); + ERR_FAIL_COND_V(!gip,PoolVector<int>()); return gip->dynamic_data; } @@ -5125,7 +5125,7 @@ void RasterizerStorageGLES3::particles_set_emission_box_extents(RID p_particles, particles->emission_box_extents=p_extents; } -void RasterizerStorageGLES3::particles_set_emission_points(RID p_particles,const DVector<Vector3>& p_points) { +void RasterizerStorageGLES3::particles_set_emission_points(RID p_particles,const PoolVector<Vector3>& p_points) { Particles *particles = particles_owner.getornull(p_particles); ERR_FAIL_COND(!particles); @@ -5961,7 +5961,7 @@ RID RasterizerStorageGLES3::canvas_light_occluder_create() { return canvas_occluder_owner.make_rid(co); } -void RasterizerStorageGLES3::canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines) { +void RasterizerStorageGLES3::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2>& p_lines) { CanvasOccluder *co = canvas_occluder_owner.get(p_occluder); ERR_FAIL_COND(!co); @@ -5985,18 +5985,18 @@ void RasterizerStorageGLES3::canvas_light_occluder_set_polylines(RID p_occluder, - DVector<float> geometry; - DVector<uint16_t> indices; + PoolVector<float> geometry; + PoolVector<uint16_t> indices; int lc = p_lines.size(); geometry.resize(lc*6); indices.resize(lc*3); - DVector<float>::Write vw=geometry.write(); - DVector<uint16_t>::Write iw=indices.write(); + PoolVector<float>::Write vw=geometry.write(); + PoolVector<uint16_t>::Write iw=indices.write(); - DVector<Vector2>::Read lr=p_lines.read(); + PoolVector<Vector2>::Read lr=p_lines.read(); const int POLY_HEIGHT = 16384; diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index 357b69183e..32581e860d 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -599,7 +599,7 @@ public: virtual RID mesh_create(); - virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const AABB& p_aabb,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >(),const Vector<AABB>& p_bone_aabbs=Vector<AABB>()); + virtual void mesh_add_surface(RID p_mesh,uint32_t p_format,VS::PrimitiveType p_primitive,const PoolVector<uint8_t>& p_array,int p_vertex_count,const PoolVector<uint8_t>& p_index_array,int p_index_count,const AABB& p_aabb,const Vector<PoolVector<uint8_t> >& p_blend_shapes=Vector<PoolVector<uint8_t> >(),const Vector<AABB>& p_bone_aabbs=Vector<AABB>()); virtual void mesh_set_morph_target_count(RID p_mesh,int p_amount); virtual int mesh_get_morph_target_count(RID p_mesh) const; @@ -614,15 +614,15 @@ public: virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const; virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const; - virtual DVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const; - virtual DVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const; + virtual PoolVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const; + virtual PoolVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const; virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const; virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const; virtual AABB mesh_surface_get_aabb(RID p_mesh, int p_surface) const; - virtual Vector<DVector<uint8_t> > mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const; + virtual Vector<PoolVector<uint8_t> > mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const; virtual Vector<AABB> mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const; virtual void mesh_remove_surface(RID p_mesh, int p_surface); @@ -877,7 +877,7 @@ public: /* ROOM API */ virtual RID room_create(); - virtual void room_add_bounds(RID p_room, const DVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform); + virtual void room_add_bounds(RID p_room, const PoolVector<Vector2>& p_convex_polygon,float p_height,const Transform& p_transform); virtual void room_clear_bounds(RID p_room); /* PORTAL API */ @@ -913,7 +913,7 @@ public: uint32_t version; - DVector<int> dynamic_data; + PoolVector<int> dynamic_data; }; @@ -931,8 +931,8 @@ public: virtual void gi_probe_set_to_cell_xform(RID p_probe,const Transform& p_xform); virtual Transform gi_probe_get_to_cell_xform(RID p_probe) const; - virtual void gi_probe_set_dynamic_data(RID p_probe,const DVector<int>& p_data); - virtual DVector<int> gi_probe_get_dynamic_data(RID p_probe) const; + virtual void gi_probe_set_dynamic_data(RID p_probe,const PoolVector<int>& p_data); + virtual PoolVector<int> gi_probe_get_dynamic_data(RID p_probe) const; virtual void gi_probe_set_dynamic_range(RID p_probe,int p_range); virtual int gi_probe_get_dynamic_range(RID p_probe) const; @@ -985,7 +985,7 @@ public: VS::ParticlesEmissionShape emission_shape; float emission_sphere_radius; Vector3 emission_box_extents; - DVector<Vector3> emission_points; + PoolVector<Vector3> emission_points; GLuint emission_point_texture; VS::ParticlesDrawOrder draw_order; @@ -1061,7 +1061,7 @@ public: virtual void particles_set_emission_shape(RID p_particles,VS::ParticlesEmissionShape p_shape); virtual void particles_set_emission_sphere_radius(RID p_particles,float p_radius); virtual void particles_set_emission_box_extents(RID p_particles,const Vector3& p_extents); - virtual void particles_set_emission_points(RID p_particles,const DVector<Vector3>& p_points); + virtual void particles_set_emission_points(RID p_particles,const PoolVector<Vector3>& p_points); virtual void particles_set_draw_order(RID p_particles,VS::ParticlesDrawOrder p_order); @@ -1208,14 +1208,14 @@ public: GLuint vertex_id; // 0 means, unconfigured GLuint index_id; // 0 means, unconfigured - DVector<Vector2> lines; + PoolVector<Vector2> lines; int len; }; RID_Owner<CanvasOccluder> canvas_occluder_owner; virtual RID canvas_light_occluder_create(); - virtual void canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2>& p_lines); + virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2>& p_lines); virtual VS::InstanceType get_base_type(RID p_rid) const; diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp index d74a12ba93..de095c20ac 100644 --- a/drivers/png/image_loader_png.cpp +++ b/drivers/png/image_loader_png.cpp @@ -181,11 +181,11 @@ Error ImageLoaderPNG::_load_image(void *rf_up,png_rw_ptr p_func,Image *p_image) //int rowsize = png_get_rowbytes(png, info); int rowsize = components * width; - DVector<uint8_t> dstbuff; + PoolVector<uint8_t> dstbuff; dstbuff.resize( rowsize * height ); - DVector<uint8_t>::Write dstbuff_write = dstbuff.write(); + PoolVector<uint8_t>::Write dstbuff_write = dstbuff.write(); uint8_t* data = dstbuff_write.ptr(); @@ -265,10 +265,10 @@ static Image _load_mem_png(const uint8_t* p_png,int p_size) { } -static Image _lossless_unpack_png(const DVector<uint8_t>& p_data) { +static Image _lossless_unpack_png(const PoolVector<uint8_t>& p_data) { int len = p_data.size(); - DVector<uint8_t>::Read r = p_data.read(); + PoolVector<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],len-4); @@ -276,17 +276,17 @@ static Image _lossless_unpack_png(const DVector<uint8_t>& p_data) { static void _write_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length) { - DVector<uint8_t> &v = *(DVector<uint8_t>*)png_get_io_ptr(png_ptr); + PoolVector<uint8_t> &v = *(PoolVector<uint8_t>*)png_get_io_ptr(png_ptr); int vs = v.size(); v.resize(vs+p_length); - DVector<uint8_t>::Write w = v.write(); + PoolVector<uint8_t>::Write w = v.write(); copymem(&w[vs],data,p_length); //print_line("png write: "+itos(p_length)); } -static DVector<uint8_t> _lossless_pack_png(const Image& p_image) { +static PoolVector<uint8_t> _lossless_pack_png(const Image& p_image) { Image img = p_image; @@ -294,7 +294,7 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) { img.decompress(); - ERR_FAIL_COND_V(img.is_compressed(), DVector<uint8_t>()); + ERR_FAIL_COND_V(img.is_compressed(), PoolVector<uint8_t>()); png_structp png_ptr; png_infop info_ptr; @@ -304,16 +304,16 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) { /* initialize stuff */ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - ERR_FAIL_COND_V(!png_ptr,DVector<uint8_t>()); + ERR_FAIL_COND_V(!png_ptr,PoolVector<uint8_t>()); info_ptr = png_create_info_struct(png_ptr); - ERR_FAIL_COND_V(!info_ptr,DVector<uint8_t>()); + ERR_FAIL_COND_V(!info_ptr,PoolVector<uint8_t>()); if (setjmp(png_jmpbuf(png_ptr))) { - ERR_FAIL_V(DVector<uint8_t>()); + ERR_FAIL_V(PoolVector<uint8_t>()); } - DVector<uint8_t> ret; + PoolVector<uint8_t> ret; ret.push_back('P'); ret.push_back('N'); ret.push_back('G'); @@ -323,7 +323,7 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) { /* write header */ if (setjmp(png_jmpbuf(png_ptr))) { - ERR_FAIL_V(DVector<uint8_t>()); + ERR_FAIL_V(PoolVector<uint8_t>()); } int pngf=0; @@ -379,11 +379,11 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) { /* write bytes */ if (setjmp(png_jmpbuf(png_ptr))) { - ERR_FAIL_V(DVector<uint8_t>()); + ERR_FAIL_V(PoolVector<uint8_t>()); } - DVector<uint8_t>::Read r = img.get_data().read(); + PoolVector<uint8_t>::Read r = img.get_data().read(); row_pointers = (png_bytep*)memalloc(sizeof(png_bytep)*h); for(int i=0;i<h;i++) { @@ -397,7 +397,7 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) { /* end write */ if (setjmp(png_jmpbuf(png_ptr))) { - ERR_FAIL_V(DVector<uint8_t>()); + ERR_FAIL_V(PoolVector<uint8_t>()); } png_write_end(png_ptr, NULL); diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index b06b02b200..a9a199bb59 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -193,7 +193,7 @@ Error ResourceSaverPNG::save_image(const String &p_path, Image &p_img) { } - DVector<uint8_t>::Read r = p_img.get_data().read(); + PoolVector<uint8_t>::Read r = p_img.get_data().read(); row_pointers = (png_bytep*)memalloc(sizeof(png_bytep)*h); for(int i=0;i<h;i++) { diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 1e8b76f505..283cff0486 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -31,10 +31,10 @@ #ifdef UNIX_ENABLED -#include "os/memory_pool_dynamic_static.h" #include "thread_posix.h" #include "semaphore_posix.h" #include "mutex_posix.h" +#include "rw_lock_posix.h" #include "core/os/thread_dummy.h" //#include "core/io/file_access_buffered_fa.h" @@ -116,7 +116,6 @@ int OS_Unix::unix_initialize_audio(int p_audio_driver) { return 0; } -static MemoryPoolDynamicStatic *mempool_dynamic=NULL; void OS_Unix::initialize_core() { @@ -129,6 +128,7 @@ void OS_Unix::initialize_core() { ThreadPosix::make_default(); SemaphorePosix::make_default(); MutexPosix::make_default(); + RWLockPosix::make_default(); #endif FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES); FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA); @@ -144,7 +144,6 @@ void OS_Unix::initialize_core() { PacketPeerUDPPosix::make_default(); IP_Unix::make_default(); #endif - mempool_dynamic = memnew( MemoryPoolDynamicStatic ); ticks_start=0; ticks_start=get_ticks_usec(); @@ -153,8 +152,6 @@ void OS_Unix::initialize_core() { void OS_Unix::finalize_core() { - if (mempool_dynamic) - memdelete( mempool_dynamic ); } diff --git a/drivers/unix/rw_lock_posix.cpp b/drivers/unix/rw_lock_posix.cpp new file mode 100644 index 0000000000..772a7b812a --- /dev/null +++ b/drivers/unix/rw_lock_posix.cpp @@ -0,0 +1,76 @@ + +#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED) + +#include "os/memory.h" +#include "rw_lock_posix.h" +#include "error_macros.h" +#include <stdio.h> + +void RWLockPosix::read_lock() { + + int err =pthread_rwlock_rdlock(&rwlock); + if (err!=0) { + perror("wtf: "); + } + ERR_FAIL_COND(err!=0); +} + +void RWLockPosix::read_unlock() { + + pthread_rwlock_unlock(&rwlock); +} + +Error RWLockPosix::read_try_lock() { + + if (pthread_rwlock_tryrdlock(&rwlock)!=0) { + return ERR_BUSY; + } else { + return OK; + } + +} + +void RWLockPosix::write_lock() { + + int err = pthread_rwlock_wrlock(&rwlock); + ERR_FAIL_COND(err!=0); +} + +void RWLockPosix::write_unlock() { + + pthread_rwlock_unlock(&rwlock); +} + +Error RWLockPosix::write_try_lock() { + if (pthread_rwlock_trywrlock(&rwlock)!=0) { + return ERR_BUSY; + } else { + return OK; + } +} + + +RWLock *RWLockPosix::create_func_posix() { + + return memnew( RWLockPosix ); +} + +void RWLockPosix::make_default() { + + create_func=create_func_posix; +} + + +RWLockPosix::RWLockPosix() { + + rwlock=PTHREAD_RWLOCK_INITIALIZER; +} + + +RWLockPosix::~RWLockPosix() { + + pthread_rwlock_destroy(&rwlock); + +} + +#endif diff --git a/drivers/unix/rw_lock_posix.h b/drivers/unix/rw_lock_posix.h new file mode 100644 index 0000000000..bcc102f6a6 --- /dev/null +++ b/drivers/unix/rw_lock_posix.h @@ -0,0 +1,37 @@ +#ifndef RWLOCKPOSIX_H +#define RWLOCKPOSIX_H + +#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED) + +#include <pthread.h> +#include "os/rw_lock.h" + +class RWLockPosix : public RWLock { + + + pthread_rwlock_t rwlock; + + static RWLock *create_func_posix(); + +public: + + virtual void read_lock(); + virtual void read_unlock(); + virtual Error read_try_lock(); + + virtual void write_lock(); + virtual void write_unlock(); + virtual Error write_try_lock(); + + static void make_default(); + + RWLockPosix(); + + ~RWLockPosix(); + +}; + +#endif + + +#endif // RWLOCKPOSIX_H |