From 4f163972bbd9c7379b01a1f9aa5310646ca7865e Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 10 Jun 2019 12:38:51 -0300 Subject: [PATCH] Refactored RID/RID_Owner to always use O(1) allocation. * Implements a growing chunked allocator * Removed redudant methods get and getptr, only getornull is supported now. --- core/rid.cpp | 41 -- core/rid.h | 151 +------ core/rid_owner.cpp | 3 + core/rid_owner.h | 266 +++++++++++++ drivers/dummy/rasterizer_dummy.h | 17 +- drivers/gles2/rasterizer_canvas_gles2.cpp | 6 +- drivers/gles2/rasterizer_gles2.cpp | 2 +- drivers/gles2/rasterizer_scene_gles2.cpp | 26 +- drivers/gles2/rasterizer_scene_gles2.h | 16 +- drivers/gles2/rasterizer_storage_gles2.cpp | 100 ++--- drivers/gles2/rasterizer_storage_gles2.h | 47 +-- drivers/gles3/rasterizer_canvas_gles3.cpp | 12 +- drivers/gles3/rasterizer_canvas_gles3.h | 4 +- drivers/gles3/rasterizer_gles3.cpp | 2 +- drivers/gles3/rasterizer_scene_gles3.cpp | 78 ++-- drivers/gles3/rasterizer_scene_gles3.h | 24 +- drivers/gles3/rasterizer_storage_gles3.cpp | 154 ++++---- drivers/gles3/rasterizer_storage_gles3.h | 56 +-- main/main.cpp | 1 - modules/bullet/bullet_physics_server.cpp | 370 +++++++++--------- modules/bullet/bullet_physics_server.h | 26 +- modules/bullet/rid_bullet.h | 2 +- modules/bullet/space_bullet.cpp | 8 +- modules/gdnavigation/gd_navigation_server.cpp | 58 +-- modules/gdnavigation/gd_navigation_server.h | 8 +- modules/gdnavigation/nav_rid.h | 2 +- scene/animation/skeleton_ik.h | 2 +- servers/physics/constraint_sw.h | 2 +- servers/physics/physics_server_sw.cpp | 294 +++++++------- servers/physics/physics_server_sw.h | 11 +- servers/physics/shape_sw.h | 4 +- servers/physics/space_sw.cpp | 8 +- servers/physics/space_sw.h | 2 +- servers/physics_2d/body_2d_sw.cpp | 2 +- servers/physics_2d/constraint_2d_sw.h | 2 +- servers/physics_2d/physics_2d_server_sw.cpp | 262 ++++++------- servers/physics_2d/physics_2d_server_sw.h | 11 +- servers/physics_2d/shape_2d_sw.h | 4 +- servers/physics_2d/space_2d_sw.cpp | 8 +- servers/physics_2d/space_2d_sw.h | 2 +- servers/visual/rasterizer.h | 8 +- servers/visual/visual_server_canvas.cpp | 104 ++--- servers/visual/visual_server_canvas.h | 12 +- servers/visual/visual_server_scene.cpp | 68 ++-- servers/visual/visual_server_scene.h | 11 +- servers/visual/visual_server_viewport.cpp | 2 +- servers/visual/visual_server_viewport.h | 7 +- 47 files changed, 1209 insertions(+), 1097 deletions(-) delete mode 100644 core/rid.cpp create mode 100644 core/rid_owner.cpp create mode 100644 core/rid_owner.h diff --git a/core/rid.cpp b/core/rid.cpp deleted file mode 100644 index 727658314ff5..000000000000 --- a/core/rid.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************/ -/* rid.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "rid.h" - -RID_Data::~RID_Data() { -} - -SafeRefCount RID_OwnerBase::refcount; - -void RID_OwnerBase::init_rid() { - - refcount.init(); -} diff --git a/core/rid.h b/core/rid.h index 7e1240918194..583d62a5b1e1 100644 --- a/core/rid.h +++ b/core/rid.h @@ -32,172 +32,45 @@ #define RID_H #include "core/list.h" +#include "core/oa_hash_map.h" #include "core/os/memory.h" #include "core/safe_refcount.h" #include "core/set.h" #include "core/typedefs.h" -class RID_OwnerBase; - -class RID_Data { - - friend class RID_OwnerBase; - -#ifndef DEBUG_ENABLED - RID_OwnerBase *_owner; -#endif - uint32_t _id; - -public: - _FORCE_INLINE_ uint32_t get_id() const { return _id; } - - virtual ~RID_Data(); -}; +class RID_AllocBase; class RID { - friend class RID_OwnerBase; - - mutable RID_Data *_data; + friend class RID_AllocBase; + uint64_t _id; public: - _FORCE_INLINE_ RID_Data *get_data() const { return _data; } - _FORCE_INLINE_ bool operator==(const RID &p_rid) const { - return _data == p_rid._data; + return _id == p_rid._id; } _FORCE_INLINE_ bool operator<(const RID &p_rid) const { - return _data < p_rid._data; + return _id < p_rid._id; } _FORCE_INLINE_ bool operator<=(const RID &p_rid) const { - return _data <= p_rid._data; + return _id <= p_rid._id; } _FORCE_INLINE_ bool operator>(const RID &p_rid) const { - return _data > p_rid._data; + return _id > p_rid._id; } _FORCE_INLINE_ bool operator!=(const RID &p_rid) const { - return _data != p_rid._data; + return _id != p_rid._id; } - _FORCE_INLINE_ bool is_valid() const { return _data != NULL; } + _FORCE_INLINE_ bool is_valid() const { return _id != 0; } - _FORCE_INLINE_ uint32_t get_id() const { return _data ? _data->get_id() : 0; } + _FORCE_INLINE_ uint64_t get_id() const { return _id; } _FORCE_INLINE_ RID() { - _data = NULL; - } -}; - -class RID_OwnerBase { -protected: - static SafeRefCount refcount; - _FORCE_INLINE_ void _set_data(RID &p_rid, RID_Data *p_data) { - p_rid._data = p_data; - refcount.ref(); - p_data->_id = refcount.get(); -#ifndef DEBUG_ENABLED - p_data->_owner = this; -#endif - } - -#ifndef DEBUG_ENABLED - - _FORCE_INLINE_ bool _is_owner(const RID &p_rid) const { - - return this == p_rid._data->_owner; - } - - _FORCE_INLINE_ void _remove_owner(RID &p_rid) { - - p_rid._data->_owner = NULL; - } -#endif - -public: - virtual void get_owned_list(List *p_owned) = 0; - - static void init_rid(); - virtual ~RID_OwnerBase() {} -}; - -template -class RID_Owner : public RID_OwnerBase { -public: -#ifdef DEBUG_ENABLED - mutable Set id_map; -#endif -public: - _FORCE_INLINE_ RID make_rid(T *p_data) { - - RID rid; - _set_data(rid, p_data); - -#ifdef DEBUG_ENABLED - id_map.insert(p_data); -#endif - - return rid; - } - - _FORCE_INLINE_ T *get(const RID &p_rid) { - -#ifdef DEBUG_ENABLED - - ERR_FAIL_COND_V(!p_rid.is_valid(), NULL); - ERR_FAIL_COND_V(!id_map.has(p_rid.get_data()), NULL); -#endif - return static_cast(p_rid.get_data()); - } - - _FORCE_INLINE_ T *getornull(const RID &p_rid) { - -#ifdef DEBUG_ENABLED - - if (p_rid.get_data()) { - ERR_FAIL_COND_V(!id_map.has(p_rid.get_data()), NULL); - } -#endif - return static_cast(p_rid.get_data()); - } - - _FORCE_INLINE_ T *getptr(const RID &p_rid) { - - return static_cast(p_rid.get_data()); - } - - _FORCE_INLINE_ bool owns(const RID &p_rid) const { - - if (p_rid.get_data() == NULL) - return false; -#ifdef DEBUG_ENABLED - return id_map.has(p_rid.get_data()); -#else - return _is_owner(p_rid); -#endif - } - - void free(RID p_rid) { - -#ifdef DEBUG_ENABLED - id_map.erase(p_rid.get_data()); -#else - _remove_owner(p_rid); -#endif - } - - void get_owned_list(List *p_owned) { - -#ifdef DEBUG_ENABLED - - for (typename Set::Element *E = id_map.front(); E; E = E->next()) { - RID r; - _set_data(r, static_cast(E->get())); - p_owned->push_back(r); - } -#endif + _id = 0; } }; diff --git a/core/rid_owner.cpp b/core/rid_owner.cpp new file mode 100644 index 000000000000..6ebb5ceecc1d --- /dev/null +++ b/core/rid_owner.cpp @@ -0,0 +1,3 @@ +#include "rid_owner.h" + +volatile uint64_t RID_AllocBase::base_id = 1; diff --git a/core/rid_owner.h b/core/rid_owner.h new file mode 100644 index 000000000000..2443aac0a40b --- /dev/null +++ b/core/rid_owner.h @@ -0,0 +1,266 @@ +#ifndef RID_OWNER_H +#define RID_OWNER_H + +#include "core/print_string.h" +#include "core/rid.h" + +class RID_AllocBase { + + static volatile uint64_t base_id; + +protected: + static RID _make_from_id(uint64_t p_id) { + RID rid; + rid._id = p_id; + return rid; + } + + static uint64_t _gen_id() { + return atomic_increment(&base_id); + } + + static RID _gen_rid() { + return _make_from_id(_gen_id()); + } + +public: + virtual ~RID_AllocBase() {} +}; + +template +class RID_Alloc : public RID_AllocBase { + + T **chunks; + uint32_t **free_list_chunks; + uint32_t **validator_chunks; + + uint32_t elements_in_chunk; + uint32_t max_alloc; + uint32_t alloc_count; + + const char *description; + +public: + RID make_rid(const T &p_value) { + + if (alloc_count == max_alloc) { + //allocate a new chunk + uint32_t chunk_count = alloc_count == 0 ? 0 : (max_alloc / elements_in_chunk + 1); + + //grow chunks + chunks = (T **)memrealloc(chunks, sizeof(T *) * (chunk_count + 1)); + chunks[chunk_count] = (T *)memalloc(sizeof(T) * elements_in_chunk); //but don't initialize + + //grow validators + validator_chunks = (uint32_t **)memrealloc(validator_chunks, sizeof(uint32_t *) * (chunk_count + 1)); + validator_chunks[chunk_count] = (uint32_t *)memalloc(sizeof(uint32_t) * elements_in_chunk); + //grow free lists + free_list_chunks = (uint32_t **)memrealloc(free_list_chunks, sizeof(uint32_t *) * (chunk_count + 1)); + free_list_chunks[chunk_count] = (uint32_t *)memalloc(sizeof(uint32_t) * elements_in_chunk); + + //initialize + for (uint32_t i = 0; i < elements_in_chunk; i++) { + //dont initialize chunk + validator_chunks[chunk_count][i] = 0xFFFFFFFF; + free_list_chunks[chunk_count][i] = alloc_count + i; + } + + max_alloc += elements_in_chunk; + } + + uint32_t free_index = free_list_chunks[alloc_count / elements_in_chunk][alloc_count % elements_in_chunk]; + + uint32_t free_chunk = free_index / elements_in_chunk; + uint32_t free_element = free_index % elements_in_chunk; + + T *ptr = &chunks[free_chunk][free_element]; + memnew_placement(ptr, T(p_value)); + + uint32_t validator = (uint32_t)(_gen_id() % 0xFFFFFFFF); + uint64_t id = validator; + id <<= 32; + id |= free_index; + + validator_chunks[free_chunk][free_element] = validator; + alloc_count++; + + return _make_from_id(id); + } + + _FORCE_INLINE_ T *getornull(const RID &p_rid) { + + uint64_t id = p_rid.get_id(); + uint32_t idx = uint32_t(id & 0xFFFFFFFF); + if (unlikely(idx >= alloc_count)) { + return NULL; + } + + uint32_t idx_chunk = idx / elements_in_chunk; + uint32_t idx_element = idx % elements_in_chunk; + + uint32_t validator = uint32_t(id >> 32); + if (validator_chunks[idx_chunk][idx_element] != validator) { + return NULL; + } + + return &chunks[idx_chunk][idx_element]; + } + + _FORCE_INLINE_ bool owns(const RID &p_rid) { + + uint64_t id = p_rid.get_id(); + uint32_t idx = uint32_t(id & 0xFFFFFFFF); + if (unlikely(idx >= alloc_count)) { + return false; + } + + uint32_t idx_chunk = idx / elements_in_chunk; + uint32_t idx_element = idx % elements_in_chunk; + + uint32_t validator = uint32_t(id >> 32); + return validator_chunks[idx_chunk][idx_element] == validator; + } + + _FORCE_INLINE_ void free(const RID &p_rid) { + + uint64_t id = p_rid.get_id(); + uint32_t idx = uint32_t(id & 0xFFFFFFFF); + if (unlikely(idx >= alloc_count)) { + return; + } + + uint32_t idx_chunk = idx / elements_in_chunk; + uint32_t idx_element = idx % elements_in_chunk; + + uint32_t validator = uint32_t(id >> 32); + if (validator_chunks[idx_chunk][idx_element] != validator) { + return; + } + + chunks[idx_chunk][idx_element].~T(); + validator_chunks[idx_chunk][idx_element] = 0xFFFFFFFF; // go invalid + + free_list_chunks[alloc_count / elements_in_chunk][alloc_count % elements_in_chunk] = idx; + alloc_count--; + } + + void get_owned_list(List *p_owned) { + for (size_t i = 0; i < alloc_count; i++) { + uint64_t idx = free_list_chunks[i / elements_in_chunk][i % elements_in_chunk]; + uint64_t validator = validator_chunks[idx / elements_in_chunk][idx % elements_in_chunk]; + p_owned->push_back(_make_from_id((validator << 32) & idx)); + } + } + + void set_description(const char *p_descrption) { + description = p_descrption; + } + + RID_Alloc(uint32_t p_target_chunk_byte_size = 4096) { + chunks = NULL; + free_list_chunks = NULL; + validator_chunks = NULL; + + elements_in_chunk = sizeof(T) > p_target_chunk_byte_size ? 1 : (p_target_chunk_byte_size / sizeof(T)); + max_alloc = 0; + alloc_count = 0; + description = NULL; + } + + ~RID_Alloc() { + if (alloc_count) { + if (description) { + print_error("ERROR: " + itos(alloc_count) + " RID allocations of type " + description + " were leaked at exit."); + } else { + print_error("ERROR: " + itos(alloc_count) + " RID allocations of unspecified type were leaked at exit."); + } + + for (uint32_t i = 0; i < alloc_count; i++) { + uint64_t idx = free_list_chunks[i / elements_in_chunk][i % elements_in_chunk]; + chunks[idx / elements_in_chunk][idx % elements_in_chunk].~T(); + } + } + + uint32_t chunk_count = alloc_count == 0 ? 0 : (max_alloc / elements_in_chunk + 1); + for (uint32_t i = 0; i < chunk_count; i++) { + memfree(chunks[i]); + memfree(validator_chunks[i]); + memfree(free_list_chunks[i]); + } + + if (chunks) { + memfree(chunks); + memfree(free_list_chunks); + memfree(validator_chunks); + } + } +}; + +template +class RID_PtrOwner { + RID_Alloc alloc; + +public: + _FORCE_INLINE_ RID make_rid(T *p_ptr) { + return alloc.make_rid(p_ptr); + } + + _FORCE_INLINE_ T *getornull(const RID &p_rid) { + T **ptr = alloc.getornull(p_rid); + if (unlikely(!ptr)) { + return NULL; + } + return *ptr; + } + + _FORCE_INLINE_ bool owns(const RID &p_rid) { + return alloc.owns(p_rid); + } + + _FORCE_INLINE_ void free(const RID &p_rid) { + alloc.free(p_rid); + } + + _FORCE_INLINE_ void get_owned_list(List *p_owned) { + return alloc.get_owned_list(p_owned); + } + + void set_description(const char *p_descrption) { + alloc.set_description(p_descrption); + } + RID_PtrOwner(uint32_t p_target_chunk_byte_size = 4096) : + alloc(p_target_chunk_byte_size) {} +}; + +template +class RID_Owner { + RID_Alloc alloc; + +public: + _FORCE_INLINE_ RID make_rid(const T &p_ptr) { + return alloc.make_rid(p_ptr); + } + + _FORCE_INLINE_ T *getornull(const RID &p_rid) { + return alloc.getornull(p_rid); + } + + _FORCE_INLINE_ bool owns(const RID &p_rid) { + return alloc.owns(p_rid); + } + + _FORCE_INLINE_ void free(const RID &p_rid) { + alloc.free(p_rid); + } + + _FORCE_INLINE_ void get_owned_list(List *p_owned) { + return alloc.get_owned_list(p_owned); + } + + void set_description(const char *p_descrption) { + alloc.set_description(p_descrption); + } + RID_Owner(uint32_t p_target_chunk_byte_size = 4096) : + alloc(p_target_chunk_byte_size) {} +}; +#endif // RID_OWNER_H diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h index 418e18cb7825..4521b9208d36 100644 --- a/drivers/dummy/rasterizer_dummy.h +++ b/drivers/dummy/rasterizer_dummy.h @@ -32,6 +32,7 @@ #define RASTERIZER_DUMMY_H #include "core/math/camera_matrix.h" +#include "core/rid_owner.h" #include "core/self_list.h" #include "scene/resources/mesh.h" #include "servers/visual/rasterizer.h" @@ -121,7 +122,7 @@ class RasterizerSceneDummy : public RasterizerScene { class RasterizerStorageDummy : public RasterizerStorage { public: /* TEXTURE API */ - struct DummyTexture : public RID_Data { + struct DummyTexture { int width; int height; uint32_t flags; @@ -142,14 +143,14 @@ class RasterizerStorageDummy : public RasterizerStorage { Vector bone_aabbs; }; - struct DummyMesh : public RID_Data { + struct DummyMesh { Vector surfaces; int blend_shape_count; VS::BlendShapeMode blend_shape_mode; }; - mutable RID_Owner texture_owner; - mutable RID_Owner mesh_owner; + mutable RID_PtrOwner texture_owner; + mutable RID_PtrOwner mesh_owner; RID texture_create() { @@ -178,7 +179,7 @@ class RasterizerStorageDummy : public RasterizerStorage { } void texture_set_data_partial(RID p_texture, const Ref &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_level) { - DummyTexture *t = texture_owner.get(p_texture); + DummyTexture *t = texture_owner.getornull(p_texture); ERR_FAIL_COND(!t); ERR_FAIL_COND_MSG(p_image.is_null(), "It's not a reference to a valid Image object."); @@ -588,7 +589,7 @@ class RasterizerStorageDummy : public RasterizerStorage { void gi_probe_dynamic_data_update(RID p_gi_probe_data, int p_depth_slice, int p_slice_count, int p_mipmap, const void *p_data) {} /* LIGHTMAP CAPTURE */ - struct Instantiable : public RID_Data { + struct Instantiable { SelfList::List instance_list; @@ -630,7 +631,7 @@ class RasterizerStorageDummy : public RasterizerStorage { } }; - mutable RID_Owner lightmap_capture_data_owner; + mutable RID_PtrOwner lightmap_capture_data_owner; void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds) {} AABB lightmap_capture_get_bounds(RID p_capture) const { return AABB(); } void lightmap_capture_set_octree(RID p_capture, const PoolVector &p_octree) {} @@ -724,7 +725,7 @@ class RasterizerStorageDummy : public RasterizerStorage { if (texture_owner.owns(p_rid)) { // delete the texture - DummyTexture *texture = texture_owner.get(p_rid); + DummyTexture *texture = texture_owner.getornull(p_rid); texture_owner.free(p_rid); memdelete(texture); } diff --git a/drivers/gles2/rasterizer_canvas_gles2.cpp b/drivers/gles2/rasterizer_canvas_gles2.cpp index 373d3989ce45..bdbe24524d21 100644 --- a/drivers/gles2/rasterizer_canvas_gles2.cpp +++ b/drivers/gles2/rasterizer_canvas_gles2.cpp @@ -88,7 +88,7 @@ void RasterizerCanvasGLES2::_set_uniforms() { state.canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_OUTSIDE_ALPHA, light->mode == VS::CANVAS_LIGHT_MODE_MASK ? 1.0 : 0.0); if (state.using_shadow) { - RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer); + RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.getornull(light->shadow_buffer); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 5); glBindTexture(GL_TEXTURE_2D, cls->distance); state.canvas_shader.set_uniform(CanvasShaderGLES2::SHADOW_MATRIX, light->shadow_matrix_cache); @@ -1480,7 +1480,7 @@ void RasterizerCanvasGLES2::canvas_render_items(Item *p_item_list, int p_z, cons { //skeleton handling if (ci->skeleton.is_valid() && storage->skeleton_owner.owns(ci->skeleton)) { - skeleton = storage->skeleton_owner.get(ci->skeleton); + skeleton = storage->skeleton_owner.getornull(ci->skeleton); if (!skeleton->use_2d) { skeleton = NULL; } else { @@ -1825,7 +1825,7 @@ void RasterizerCanvasGLES2::canvas_debug_viewport_shadows(Light *p_lights_with_s void RasterizerCanvasGLES2::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) { - RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer); + RasterizerStorageGLES2::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.getornull(p_buffer); ERR_FAIL_COND(!cls); glDisable(GL_BLEND); diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 140617246c5b..02b956fd44dc 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -384,7 +384,7 @@ void RasterizerGLES2::set_boot_image(const Ref &p_image, const Color &p_c screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor(); } - RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(texture); + RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(texture); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1); glBindTexture(GL_TEXTURE_2D, t->tex_id); canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1)); diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp index bb6a45e24086..0be8503dd138 100644 --- a/drivers/gles2/rasterizer_scene_gles2.cpp +++ b/drivers/gles2/rasterizer_scene_gles2.cpp @@ -370,7 +370,7 @@ bool RasterizerSceneGLES2::shadow_atlas_update_light(RID p_atlas, RID p_light_in // it is take but invalid, so we can take it shadow_atlas->shadow_owners.erase(sh->owner); - LightInstance *sli = light_instance_owner.get(sh->owner); + LightInstance *sli = light_instance_owner.getornull(sh->owner); sli->shadow_atlases.erase(p_atlas); } @@ -412,7 +412,7 @@ bool RasterizerSceneGLES2::shadow_atlas_update_light(RID p_atlas, RID p_light_in // it is take but invalid, so we can take it shadow_atlas->shadow_owners.erase(sh->owner); - LightInstance *sli = light_instance_owner.get(sh->owner); + LightInstance *sli = light_instance_owner.getornull(sh->owner); sli->shadow_atlases.erase(p_atlas); } @@ -976,7 +976,7 @@ void RasterizerSceneGLES2::_add_geometry(RasterizerStorageGLES2::Geometry *p_geo } if (!material) { - material = storage->material_owner.getptr(default_material); + material = storage->material_owner.getornull(default_material); } ERR_FAIL_COND(!material); @@ -1023,10 +1023,10 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G if (!p_material->shader->spatial.uses_alpha_scissor && !p_material->shader->spatial.writes_modelview_or_projection && !p_material->shader->spatial.uses_vertex && !p_material->shader->spatial.uses_discard && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) { //shader does not use discard and does not write a vertex position, use generic material if (p_instance->cast_shadows == VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED) { - p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided); + p_material = storage->material_owner.getornull(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided); mirror = false; } else { - p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material); + p_material = storage->material_owner.getornull(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material); } } @@ -1242,13 +1242,13 @@ void RasterizerSceneGLES2::_fill_render_list(InstanceBase **p_cull_result, int p } break; case VS::INSTANCE_MULTIMESH: { - RasterizerStorageGLES2::MultiMesh *multi_mesh = storage->multimesh_owner.getptr(instance->base); + RasterizerStorageGLES2::MultiMesh *multi_mesh = storage->multimesh_owner.getornull(instance->base); ERR_CONTINUE(!multi_mesh); if (multi_mesh->size == 0 || multi_mesh->visible_instances == 0) continue; - RasterizerStorageGLES2::Mesh *mesh = storage->mesh_owner.getptr(multi_mesh->mesh); + RasterizerStorageGLES2::Mesh *mesh = storage->mesh_owner.getornull(multi_mesh->mesh); if (!mesh) continue; @@ -1261,7 +1261,7 @@ void RasterizerSceneGLES2::_fill_render_list(InstanceBase **p_cull_result, int p } break; case VS::INSTANCE_IMMEDIATE: { - RasterizerStorageGLES2::Immediate *im = storage->immediate_owner.getptr(instance->base); + RasterizerStorageGLES2::Immediate *im = storage->immediate_owner.getornull(instance->base); ERR_CONTINUE(!im); _add_geometry(im, instance, NULL, -1, p_depth_pass, p_shadow_pass); @@ -1789,7 +1789,7 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) { storage->info.render.vertices_count += vertices; if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) { - RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(c.texture); + RasterizerStorageGLES2::Texture *t = storage->texture_owner.getornull(c.texture); if (t->redraw_if_visible) { VisualServerRaster::redraw_request(); @@ -3874,11 +3874,11 @@ bool RasterizerSceneGLES2::free(RID p_rid) { if (light_instance_owner.owns(p_rid)) { - LightInstance *light_instance = light_instance_owner.getptr(p_rid); + LightInstance *light_instance = light_instance_owner.getornull(p_rid); //remove from shadow atlases.. for (Set::Element *E = light_instance->shadow_atlases.front(); E; E = E->next()) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(E->get()); + ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(E->get()); ERR_CONTINUE(!shadow_atlas->shadow_owners.has(p_rid)); uint32_t key = shadow_atlas->shadow_owners[p_rid]; uint32_t q = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3; @@ -3893,13 +3893,13 @@ bool RasterizerSceneGLES2::free(RID p_rid) { } else if (shadow_atlas_owner.owns(p_rid)) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(p_rid); + ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_rid); shadow_atlas_set_size(p_rid, 0); shadow_atlas_owner.free(p_rid); memdelete(shadow_atlas); } else if (reflection_probe_instance_owner.owns(p_rid)) { - ReflectionProbeInstance *reflection_instance = reflection_probe_instance_owner.get(p_rid); + ReflectionProbeInstance *reflection_instance = reflection_probe_instance_owner.getornull(p_rid); for (int i = 0; i < 6; i++) { glDeleteFramebuffers(1, &reflection_instance->fbo[i]); diff --git a/drivers/gles2/rasterizer_scene_gles2.h b/drivers/gles2/rasterizer_scene_gles2.h index 74adae05aabc..96e520aa929d 100644 --- a/drivers/gles2/rasterizer_scene_gles2.h +++ b/drivers/gles2/rasterizer_scene_gles2.h @@ -225,7 +225,7 @@ class RasterizerSceneGLES2 : public RasterizerScene { uint64_t shadow_atlas_realloc_tolerance_msec; - struct ShadowAtlas : public RID_Data { + struct ShadowAtlas { enum { QUADRANT_SHIFT = 27, SHADOW_INDEX_MASK = (1 << QUADRANT_SHIFT) - 1, @@ -273,7 +273,7 @@ class RasterizerSceneGLES2 : public RasterizerScene { Vector shadow_cubemaps; - RID_Owner shadow_atlas_owner; + RID_PtrOwner shadow_atlas_owner; RID shadow_atlas_create(); void shadow_atlas_set_size(RID p_atlas, int p_size); @@ -304,7 +304,7 @@ class RasterizerSceneGLES2 : public RasterizerScene { /* REFLECTION PROBE INSTANCE */ - struct ReflectionProbeInstance : public RID_Data { + struct ReflectionProbeInstance { RasterizerStorageGLES2::ReflectionProbe *probe_ptr; RID probe; @@ -330,7 +330,7 @@ class RasterizerSceneGLES2 : public RasterizerScene { Transform transform; }; - mutable RID_Owner reflection_probe_instance_owner; + mutable RID_PtrOwner reflection_probe_instance_owner; ReflectionProbeInstance **reflection_probe_instances; int reflection_probe_count; @@ -345,7 +345,7 @@ class RasterizerSceneGLES2 : public RasterizerScene { /* ENVIRONMENT API */ - struct Environment : public RID_Data { + struct Environment { VS::EnvironmentBG bg_mode; RID sky; @@ -459,7 +459,7 @@ class RasterizerSceneGLES2 : public RasterizerScene { } }; - mutable RID_Owner environment_owner; + mutable RID_PtrOwner environment_owner; virtual RID environment_create(); @@ -496,7 +496,7 @@ class RasterizerSceneGLES2 : public RasterizerScene { /* LIGHT INSTANCE */ - struct LightInstance : public RID_Data { + struct LightInstance { struct ShadowTransform { CameraMatrix camera; @@ -530,7 +530,7 @@ class RasterizerSceneGLES2 : public RasterizerScene { Set shadow_atlases; // atlases where this light is registered }; - mutable RID_Owner light_instance_owner; + mutable RID_PtrOwner light_instance_owner; virtual RID light_instance_create(RID p_light); virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform); diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index a1c5d20a1412..f929771c8643 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -1184,7 +1184,7 @@ void RasterizerStorageGLES2::texture_set_proxy(RID p_texture, RID p_proxy) { } if (p_proxy.is_valid()) { - Texture *proxy = texture_owner.get(p_proxy); + Texture *proxy = texture_owner.getornull(p_proxy); ERR_FAIL_COND(!proxy); ERR_FAIL_COND(proxy == texture); proxy->proxy_owners.insert(texture); @@ -1201,7 +1201,7 @@ void RasterizerStorageGLES2::texture_set_force_redraw_if_visible(RID p_texture, } void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); texture->detect_3d = p_callback; @@ -1209,7 +1209,7 @@ void RasterizerStorageGLES2::texture_set_detect_3d_callback(RID p_texture, Visua } void RasterizerStorageGLES2::texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); texture->detect_srgb = p_callback; @@ -1217,7 +1217,7 @@ void RasterizerStorageGLES2::texture_set_detect_srgb_callback(RID p_texture, Vis } void RasterizerStorageGLES2::texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); texture->detect_normal = p_callback; @@ -1456,7 +1456,7 @@ void RasterizerStorageGLES2::shader_set_code(RID p_shader, const String &p_code) String RasterizerStorageGLES2::shader_get_code(RID p_shader) const { - const Shader *shader = shader_owner.get(p_shader); + const Shader *shader = shader_owner.getornull(p_shader); ERR_FAIL_COND_V(!shader, ""); return shader->code; @@ -1610,7 +1610,7 @@ void RasterizerStorageGLES2::update_dirty_shaders() { void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List *p_param_list) const { - Shader *shader = shader_owner.get(p_shader); + Shader *shader = shader_owner.getornull(p_shader); ERR_FAIL_COND(!shader); if (shader->dirty_list.in_list()) { @@ -1754,7 +1754,7 @@ void RasterizerStorageGLES2::shader_get_param_list(RID p_shader, List::Element *E = shader->default_textures.find(p_name); @@ -1800,7 +1800,7 @@ RID RasterizerStorageGLES2::material_create() { void RasterizerStorageGLES2::material_set_shader(RID p_material, RID p_shader) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); Shader *shader = shader_owner.getornull(p_shader); @@ -1821,7 +1821,7 @@ void RasterizerStorageGLES2::material_set_shader(RID p_material, RID p_shader) { RID RasterizerStorageGLES2::material_get_shader(RID p_material) const { - const Material *material = material_owner.get(p_material); + const Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, RID()); if (material->shader) { @@ -1833,7 +1833,7 @@ RID RasterizerStorageGLES2::material_get_shader(RID p_material) const { void RasterizerStorageGLES2::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); if (p_value.get_type() == Variant::NIL) { @@ -1847,7 +1847,7 @@ void RasterizerStorageGLES2::material_set_param(RID p_material, const StringName Variant RasterizerStorageGLES2::material_get_param(RID p_material, const StringName &p_param) const { - const Material *material = material_owner.get(p_material); + const Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, RID()); if (material->params.has(p_param)) { @@ -1858,7 +1858,7 @@ Variant RasterizerStorageGLES2::material_get_param(RID p_material, const StringN } Variant RasterizerStorageGLES2::material_get_param_default(RID p_material, const StringName &p_param) const { - const Material *material = material_owner.get(p_material); + const Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, Variant()); if (material->shader) { @@ -1879,14 +1879,14 @@ void RasterizerStorageGLES2::material_set_line_width(RID p_material, float p_wid } void RasterizerStorageGLES2::material_set_next_pass(RID p_material, RID p_next_material) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); material->next_pass = p_next_material; } bool RasterizerStorageGLES2::material_is_animated(RID p_material) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, false); if (material->dirty_list.in_list()) { _update_material(material); @@ -1900,7 +1900,7 @@ bool RasterizerStorageGLES2::material_is_animated(RID p_material) { } bool RasterizerStorageGLES2::material_casts_shadows(RID p_material) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, false); if (material->dirty_list.in_list()) { _update_material(material); @@ -1947,7 +1947,7 @@ void RasterizerStorageGLES2::material_set_render_priority(RID p_material, int pr ERR_FAIL_COND(priority < VS::MATERIAL_RENDER_PRIORITY_MIN); ERR_FAIL_COND(priority > VS::MATERIAL_RENDER_PRIORITY_MAX); - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); material->render_priority = priority; @@ -2804,7 +2804,7 @@ AABB RasterizerStorageGLES2::mesh_get_custom_aabb(RID p_mesh) const { } AABB RasterizerStorageGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { - Mesh *mesh = mesh_owner.get(p_mesh); + Mesh *mesh = mesh_owner.getornull(p_mesh); ERR_FAIL_COND_V(!mesh, AABB()); if (mesh->custom_aabb != AABB()) @@ -2812,7 +2812,7 @@ AABB RasterizerStorageGLES2::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { Skeleton *sk = NULL; if (p_skeleton.is_valid()) { - sk = skeleton_owner.get(p_skeleton); + sk = skeleton_owner.getornull(p_skeleton); } AABB aabb; @@ -3468,7 +3468,7 @@ RID RasterizerStorageGLES2::immediate_create() { } void RasterizerStorageGLES2::immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(im->building); @@ -3481,7 +3481,7 @@ void RasterizerStorageGLES2::immediate_begin(RID p_immediate, VS::PrimitiveType } void RasterizerStorageGLES2::immediate_vertex(RID p_immediate, const Vector3 &p_vertex) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -3509,7 +3509,7 @@ void RasterizerStorageGLES2::immediate_vertex(RID p_immediate, const Vector3 &p_ } void RasterizerStorageGLES2::immediate_normal(RID p_immediate, const Vector3 &p_normal) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -3518,7 +3518,7 @@ void RasterizerStorageGLES2::immediate_normal(RID p_immediate, const Vector3 &p_ } void RasterizerStorageGLES2::immediate_tangent(RID p_immediate, const Plane &p_tangent) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -3527,7 +3527,7 @@ void RasterizerStorageGLES2::immediate_tangent(RID p_immediate, const Plane &p_t } void RasterizerStorageGLES2::immediate_color(RID p_immediate, const Color &p_color) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -3536,7 +3536,7 @@ void RasterizerStorageGLES2::immediate_color(RID p_immediate, const Color &p_col } void RasterizerStorageGLES2::immediate_uv(RID p_immediate, const Vector2 &tex_uv) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -3545,7 +3545,7 @@ void RasterizerStorageGLES2::immediate_uv(RID p_immediate, const Vector2 &tex_uv } void RasterizerStorageGLES2::immediate_uv2(RID p_immediate, const Vector2 &tex_uv) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -3554,7 +3554,7 @@ void RasterizerStorageGLES2::immediate_uv2(RID p_immediate, const Vector2 &tex_u } void RasterizerStorageGLES2::immediate_end(RID p_immediate) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -3563,7 +3563,7 @@ void RasterizerStorageGLES2::immediate_end(RID p_immediate) { } void RasterizerStorageGLES2::immediate_clear(RID p_immediate) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(im->building); @@ -3572,13 +3572,13 @@ void RasterizerStorageGLES2::immediate_clear(RID p_immediate) { } AABB RasterizerStorageGLES2::immediate_get_aabb(RID p_immediate) const { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND_V(!im, AABB()); return im->aabb; } void RasterizerStorageGLES2::immediate_set_material(RID p_immediate, RID p_material) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); im->material = p_material; @@ -3586,7 +3586,7 @@ void RasterizerStorageGLES2::immediate_set_material(RID p_immediate, RID p_mater } RID RasterizerStorageGLES2::immediate_get_material(RID p_immediate) const { - const Immediate *im = immediate_owner.get(p_immediate); + const Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND_V(!im, RID()); return im->material; } @@ -5057,7 +5057,7 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) { glDeleteFramebuffers(1, &rt->external.fbo); // clean up our texture - Texture *t = texture_owner.get(rt->external.texture); + Texture *t = texture_owner.getornull(rt->external.texture); t->alloc_height = 0; t->alloc_width = 0; t->width = 0; @@ -5079,7 +5079,7 @@ void RasterizerStorageGLES2::_render_target_clear(RenderTarget *rt) { rt->depth = 0; } - Texture *tex = texture_owner.get(rt->texture); + Texture *tex = texture_owner.getornull(rt->texture); tex->alloc_height = 0; tex->alloc_width = 0; tex->width = 0; @@ -5206,7 +5206,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar } // clean up our texture - Texture *t = texture_owner.get(rt->external.texture); + Texture *t = texture_owner.getornull(rt->external.texture); t->alloc_height = 0; t->alloc_width = 0; t->width = 0; @@ -5258,7 +5258,7 @@ void RasterizerStorageGLES2::render_target_set_external_texture(RID p_render_tar glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); // find our texture - t = texture_owner.get(rt->external.texture); + t = texture_owner.getornull(rt->external.texture); } // set our texture @@ -5448,7 +5448,7 @@ RID RasterizerStorageGLES2::canvas_light_occluder_create() { void RasterizerStorageGLES2::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector &p_lines) { - CanvasOccluder *co = canvas_occluder_owner.get(p_occluder); + CanvasOccluder *co = canvas_occluder_owner.getornull(p_occluder); ERR_FAIL_COND(!co); co->lines = p_lines; @@ -5565,7 +5565,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { RenderTarget *rt = render_target_owner.getornull(p_rid); _render_target_clear(rt); - Texture *t = texture_owner.get(rt->texture); + Texture *t = texture_owner.getornull(rt->texture); texture_owner.free(rt->texture); memdelete(t); render_target_owner.free(p_rid); @@ -5574,7 +5574,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (texture_owner.owns(p_rid)) { - Texture *t = texture_owner.get(p_rid); + Texture *t = texture_owner.getornull(p_rid); // can't free a render target texture ERR_FAIL_COND_V(t->render_target, true); @@ -5585,7 +5585,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (sky_owner.owns(p_rid)) { - Sky *sky = sky_owner.get(p_rid); + Sky *sky = sky_owner.getornull(p_rid); sky_set_texture(p_rid, RID(), 256); sky_owner.free(p_rid); memdelete(sky); @@ -5593,7 +5593,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (shader_owner.owns(p_rid)) { - Shader *shader = shader_owner.get(p_rid); + Shader *shader = shader_owner.getornull(p_rid); if (shader->shader && shader->custom_code_id) { shader->shader->free_custom_shader(shader->custom_code_id); @@ -5618,7 +5618,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (material_owner.owns(p_rid)) { - Material *m = material_owner.get(p_rid); + Material *m = material_owner.getornull(p_rid); if (m->shader) { m->shader->materials.remove(&m->list); @@ -5650,7 +5650,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (skeleton_owner.owns(p_rid)) { - Skeleton *s = skeleton_owner.get(p_rid); + Skeleton *s = skeleton_owner.getornull(p_rid); if (s->update_list.in_list()) { skeleton_update_list.remove(&s->update_list); @@ -5672,7 +5672,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (mesh_owner.owns(p_rid)) { - Mesh *mesh = mesh_owner.get(p_rid); + Mesh *mesh = mesh_owner.getornull(p_rid); mesh->instance_remove_deps(); mesh_clear(p_rid); @@ -5695,7 +5695,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (multimesh_owner.owns(p_rid)) { - MultiMesh *multimesh = multimesh_owner.get(p_rid); + MultiMesh *multimesh = multimesh_owner.getornull(p_rid); multimesh->instance_remove_deps(); if (multimesh->mesh.is_valid()) { @@ -5714,7 +5714,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (immediate_owner.owns(p_rid)) { - Immediate *im = immediate_owner.get(p_rid); + Immediate *im = immediate_owner.getornull(p_rid); im->instance_remove_deps(); immediate_owner.free(p_rid); @@ -5723,7 +5723,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { return true; } else if (light_owner.owns(p_rid)) { - Light *light = light_owner.get(p_rid); + Light *light = light_owner.getornull(p_rid); light->instance_remove_deps(); light_owner.free(p_rid); @@ -5733,7 +5733,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { } else if (reflection_probe_owner.owns(p_rid)) { // delete the texture - ReflectionProbe *reflection_probe = reflection_probe_owner.get(p_rid); + ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_rid); reflection_probe->instance_remove_deps(); reflection_probe_owner.free(p_rid); @@ -5743,7 +5743,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { } else if (lightmap_capture_data_owner.owns(p_rid)) { // delete the texture - LightmapCapture *lightmap_capture = lightmap_capture_data_owner.get(p_rid); + LightmapCapture *lightmap_capture = lightmap_capture_data_owner.getornull(p_rid); lightmap_capture->instance_remove_deps(); lightmap_capture_data_owner.free(p_rid); @@ -5752,7 +5752,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { } else if (canvas_occluder_owner.owns(p_rid)) { - CanvasOccluder *co = canvas_occluder_owner.get(p_rid); + CanvasOccluder *co = canvas_occluder_owner.getornull(p_rid); if (co->index_id) glDeleteBuffers(1, &co->index_id); if (co->vertex_id) @@ -5765,7 +5765,7 @@ bool RasterizerStorageGLES2::free(RID p_rid) { } else if (canvas_light_shadow_owner.owns(p_rid)) { - CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid); + CanvasLightShadow *cls = canvas_light_shadow_owner.getornull(p_rid); glDeleteFramebuffers(1, &cls->fbo); glDeleteRenderbuffers(1, &cls->depth); glDeleteTextures(1, &cls->distance); diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index d006d2e7f444..a5f8f1972cfa 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -38,6 +38,7 @@ #include "shader_compiler_gles2.h" #include "shader_gles2.h" +#include "core/rid_owner.h" #include "shaders/copy.glsl.gen.h" #include "shaders/cubemap_filter.glsl.gen.h" /* @@ -179,7 +180,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { //////////////////////////////////DATA/////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// - struct Instantiable : public RID_Data { + struct Instantiable { SelfList::List instance_list; _FORCE_INLINE_ void instance_change_notify(bool p_aabb, bool p_materials) { @@ -239,7 +240,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { struct RenderTarget; - struct Texture : RID_Data { + struct Texture { Texture *proxy; Set proxy_owners; @@ -340,7 +341,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { } }; - mutable RID_Owner texture_owner; + mutable RID_PtrOwner texture_owner; Ref _get_gl_image_and_format(const Ref &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool p_force_decompress) const; @@ -382,14 +383,14 @@ class RasterizerStorageGLES2 : public RasterizerStorage { /* SKY API */ - struct Sky : public RID_Data { + struct Sky { RID panorama; GLuint radiance; int radiance_size; }; - mutable RID_Owner sky_owner; + mutable RID_PtrOwner sky_owner; virtual RID sky_create(); virtual void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size); @@ -398,7 +399,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { struct Material; - struct Shader : public RID_Data { + struct Shader { RID self; @@ -516,7 +517,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { } }; - mutable RID_Owner shader_owner; + mutable RID_PtrOwner shader_owner; mutable SelfList::List _shader_dirty_list; void _shader_make_dirty(Shader *p_shader); @@ -535,7 +536,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { /* COMMON MATERIAL API */ - struct Material : public RID_Data { + struct Material { Shader *shader; Map params; @@ -576,7 +577,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { void _update_material(Material *p_material); - mutable RID_Owner material_owner; + mutable RID_PtrOwner material_owner; virtual RID material_create(); @@ -698,7 +699,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { } }; - mutable RID_Owner mesh_owner; + mutable RID_PtrOwner mesh_owner; virtual RID mesh_create(); @@ -780,7 +781,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { } }; - mutable RID_Owner multimesh_owner; + mutable RID_PtrOwner multimesh_owner; SelfList::List multimesh_update_list; @@ -843,7 +844,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { Vector2 chunk_uv; Vector2 chunk_uv2; - mutable RID_Owner immediate_owner; + mutable RID_PtrOwner immediate_owner; virtual RID immediate_create(); virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture = RID()); @@ -861,7 +862,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { /* SKELETON API */ - struct Skeleton : RID_Data { + struct Skeleton { bool use_2d; @@ -886,7 +887,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { } }; - mutable RID_Owner skeleton_owner; + mutable RID_PtrOwner skeleton_owner; SelfList::List skeleton_update_list; @@ -932,7 +933,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { uint64_t version; }; - mutable RID_Owner light_owner; + mutable RID_PtrOwner light_owner; virtual RID light_create(VS::LightType p_type); @@ -988,7 +989,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { int resolution; }; - mutable RID_Owner reflection_probe_owner; + mutable RID_PtrOwner reflection_probe_owner; virtual RID reflection_probe_create(); @@ -1074,7 +1075,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { } }; - mutable RID_Owner lightmap_capture_data_owner; + mutable RID_PtrOwner lightmap_capture_data_owner; virtual RID lightmap_capture_create(); virtual void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds); @@ -1137,7 +1138,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { /* RENDER TARGET */ - struct RenderTarget : public RID_Data { + struct RenderTarget { GLuint fbo; GLuint color; GLuint depth; @@ -1233,7 +1234,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { } }; - mutable RID_Owner render_target_owner; + mutable RID_PtrOwner render_target_owner; void _render_target_clear(RenderTarget *rt); void _render_target_allocate(RenderTarget *rt); @@ -1251,7 +1252,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { /* CANVAS SHADOW */ - struct CanvasLightShadow : public RID_Data { + struct CanvasLightShadow { int size; int height; @@ -1260,13 +1261,13 @@ class RasterizerStorageGLES2 : public RasterizerStorage { GLuint distance; //for older devices }; - RID_Owner canvas_light_shadow_owner; + RID_PtrOwner canvas_light_shadow_owner; virtual RID canvas_light_shadow_buffer_create(int p_width); /* LIGHT SHADOW MAPPING */ - struct CanvasOccluder : public RID_Data { + struct CanvasOccluder { GLuint vertex_id; // 0 means, unconfigured GLuint index_id; // 0 means, unconfigured @@ -1274,7 +1275,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage { int len; }; - RID_Owner canvas_occluder_owner; + RID_PtrOwner canvas_occluder_owner; virtual RID canvas_light_occluder_create(); virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector &p_lines); diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index b7b31c66aa31..9e1b302a03bf 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -1402,7 +1402,7 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons { //skeleton handling if (ci->skeleton.is_valid() && storage->skeleton_owner.owns(ci->skeleton)) { - skeleton = storage->skeleton_owner.get(ci->skeleton); + skeleton = storage->skeleton_owner.getornull(ci->skeleton); if (!skeleton->use_2d) { skeleton = NULL; } else { @@ -1697,11 +1697,13 @@ void RasterizerCanvasGLES3::canvas_render_items(Item *p_item_list, int p_z, cons } } - glBindBufferBase(GL_UNIFORM_BUFFER, 1, static_cast(light->light_internal.get_data())->ubo); + LightInternal *light_internal = light_internal_owner.getornull(light->light_internal); + + glBindBufferBase(GL_UNIFORM_BUFFER, 1, light_internal->ubo); if (has_shadow) { - RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(light->shadow_buffer); + RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.getornull(light->shadow_buffer); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2); glBindTexture(GL_TEXTURE_2D, cls->distance); @@ -1807,7 +1809,7 @@ void RasterizerCanvasGLES3::canvas_debug_viewport_shadows(Light *p_lights_with_s while (light) { if (light->shadow_buffer.is_valid()) { - RasterizerStorageGLES3::CanvasLightShadow *sb = storage->canvas_light_shadow_owner.get(light->shadow_buffer); + RasterizerStorageGLES3::CanvasLightShadow *sb = storage->canvas_light_shadow_owner.getornull(light->shadow_buffer); if (sb) { glBindTexture(GL_TEXTURE_2D, sb->distance); draw_generic_textured_rect(Rect2(h, ofs, w - h * 2, h), Rect2(0, 0, 1, 1)); @@ -1823,7 +1825,7 @@ void RasterizerCanvasGLES3::canvas_debug_viewport_shadows(Light *p_lights_with_s void RasterizerCanvasGLES3::canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) { - RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.get(p_buffer); + RasterizerStorageGLES3::CanvasLightShadow *cls = storage->canvas_light_shadow_owner.getornull(p_buffer); ERR_FAIL_COND(!cls); glDisable(GL_BLEND); diff --git a/drivers/gles3/rasterizer_canvas_gles3.h b/drivers/gles3/rasterizer_canvas_gles3.h index 929867337dc2..8e7a3ae873ba 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.h +++ b/drivers/gles3/rasterizer_canvas_gles3.h @@ -96,7 +96,7 @@ class RasterizerCanvasGLES3 : public RasterizerCanvas { RasterizerStorageGLES3 *storage; - struct LightInternal : public RID_Data { + struct LightInternal { struct UBOData { @@ -117,7 +117,7 @@ class RasterizerCanvasGLES3 : public RasterizerCanvas { GLuint ubo; }; - RID_Owner light_internal_owner; + RID_PtrOwner light_internal_owner; virtual RID light_internal_create(); virtual void light_internal_update(RID p_rid, Light *p_light); diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index e06cc5542383..ef6f2854bcc2 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -320,7 +320,7 @@ void RasterizerGLES3::set_boot_image(const Ref &p_image, const Color &p_c screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor(); } - RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(texture); + RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(texture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, t->tex_id); canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1)); diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 27173d317b80..27992ea5b90f 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -351,7 +351,7 @@ bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_in if (sh->owner.is_valid()) { //is taken, but is invalid, erasing it shadow_atlas->shadow_owners.erase(sh->owner); - LightInstance *sli = light_instance_owner.get(sh->owner); + LightInstance *sli = light_instance_owner.getornull(sh->owner); sli->shadow_atlases.erase(p_atlas); } @@ -391,7 +391,7 @@ bool RasterizerSceneGLES3::shadow_atlas_update_light(RID p_atlas, RID p_light_in if (sh->owner.is_valid()) { //is taken, but is invalid, erasing it shadow_atlas->shadow_owners.erase(sh->owner); - LightInstance *sli = light_instance_owner.get(sh->owner); + LightInstance *sli = light_instance_owner.getornull(sh->owner); sli->shadow_atlases.erase(p_atlas); } @@ -1170,7 +1170,7 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material *p_m GLenum target = GL_TEXTURE_2D; GLuint tex = 0; - RasterizerStorageGLES3::Texture *t = storage->texture_owner.getptr(textures[i]); + RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(textures[i]); if (t) { @@ -1606,7 +1606,7 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) { - RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(c.texture); + RasterizerStorageGLES3::Texture *t = storage->texture_owner.getornull(c.texture); if (t->redraw_if_visible) { VisualServerRaster::redraw_request(); @@ -1884,7 +1884,7 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform const RID *reflections = e->instance->reflection_probe_instances.ptr(); for (int i = 0; i < rc; i++) { - ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getptr(reflections[i]); + ReflectionProbeInstance *rpi = reflection_probe_instance_owner.getornull(reflections[i]); if (rpi->last_pass != render_pass) //not visible continue; @@ -1903,7 +1903,7 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform if (gi_probe_count) { const RID *ridp = e->instance->gi_probe_instances.ptr(); - GIProbeInstance *gipi = gi_probe_instance_owner.getptr(ridp[0]); + GIProbeInstance *gipi = gi_probe_instance_owner.getornull(ridp[0]); float bias_scale = e->instance->baked_light ? 1 : 0; glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 9); @@ -1917,7 +1917,7 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_CELL_SIZE1, gipi->cell_size_cache); if (gi_probe_count > 1) { - GIProbeInstance *gipi2 = gi_probe_instance_owner.getptr(ridp[1]); + GIProbeInstance *gipi2 = gi_probe_instance_owner.getornull(ridp[1]); glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 10); glBindTexture(GL_TEXTURE_3D, gipi2->tex_cache); @@ -2286,7 +2286,7 @@ void RasterizerSceneGLES3::_add_geometry(RasterizerStorageGLES3::Geometry *p_geo } if (!m) { - m = storage->material_owner.getptr(default_material); + m = storage->material_owner.getornull(default_material); } ERR_FAIL_COND(!m); @@ -2337,11 +2337,11 @@ void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::G if (!p_material->shader->spatial.uses_alpha_scissor && !p_material->shader->spatial.writes_modelview_or_projection && !p_material->shader->spatial.uses_vertex && !p_material->shader->spatial.uses_discard && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES3::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) { //shader does not use discard and does not write a vertex position, use generic material if (p_instance->cast_shadows == VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED) { - p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided); + p_material = storage->material_owner.getornull(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided); no_cull = true; mirror = false; } else { - p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material); + p_material = storage->material_owner.getornull(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material); } } @@ -2792,7 +2792,7 @@ void RasterizerSceneGLES3::_setup_lights(RID *p_light_cull_result, int p_light_c ERR_BREAK(i >= render_list.max_lights); - LightInstance *li = light_instance_owner.getptr(p_light_cull_result[i]); + LightInstance *li = light_instance_owner.getornull(p_light_cull_result[i]); LightDataUBO ubo_data; //used for filling @@ -3142,7 +3142,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p case VS::INSTANCE_MESH: { - RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getptr(inst->base); + RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getornull(inst->base); ERR_CONTINUE(!mesh); int ssize = mesh->surfaces.size(); @@ -3159,13 +3159,13 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p } break; case VS::INSTANCE_MULTIMESH: { - RasterizerStorageGLES3::MultiMesh *multi_mesh = storage->multimesh_owner.getptr(inst->base); + RasterizerStorageGLES3::MultiMesh *multi_mesh = storage->multimesh_owner.getornull(inst->base); ERR_CONTINUE(!multi_mesh); if (multi_mesh->size == 0 || multi_mesh->visible_instances == 0) continue; - RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getptr(multi_mesh->mesh); + RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getornull(multi_mesh->mesh); if (!mesh) continue; //mesh not assigned @@ -3180,7 +3180,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p } break; case VS::INSTANCE_IMMEDIATE: { - RasterizerStorageGLES3::Immediate *immediate = storage->immediate_owner.getptr(inst->base); + RasterizerStorageGLES3::Immediate *immediate = storage->immediate_owner.getornull(inst->base); ERR_CONTINUE(!immediate); _add_geometry(immediate, inst, NULL, -1, p_depth_pass, p_shadow_pass); @@ -3188,7 +3188,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p } break; case VS::INSTANCE_PARTICLES: { - RasterizerStorageGLES3::Particles *particles = storage->particles_owner.getptr(inst->base); + RasterizerStorageGLES3::Particles *particles = storage->particles_owner.getornull(inst->base); ERR_CONTINUE(!particles); for (int j = 0; j < particles->draw_passes.size(); j++) { @@ -3196,7 +3196,7 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p RID pmesh = particles->draw_passes[j]; if (!pmesh.is_valid()) continue; - RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.get(pmesh); + RasterizerStorageGLES3::Mesh *mesh = storage->mesh_owner.getornull(pmesh); if (!mesh) continue; //mesh not assigned @@ -4155,7 +4155,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const ERR_BREAK(i >= render_list.max_lights); - LightInstance *li = light_instance_owner.getptr(p_light_cull_result[i]); + LightInstance *li = light_instance_owner.getornull(p_light_cull_result[i]); if (li->light_ptr->param[VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE] > CMP_EPSILON) { state.used_contact_shadows = true; } @@ -4229,7 +4229,7 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const if (probe) { - ReflectionAtlas *ref_atlas = reflection_atlas_owner.getptr(probe->atlas); + ReflectionAtlas *ref_atlas = reflection_atlas_owner.getornull(probe->atlas); ERR_FAIL_COND(!ref_atlas); int target_size = ref_atlas->size / ref_atlas->subdiv; @@ -4914,11 +4914,11 @@ bool RasterizerSceneGLES3::free(RID p_rid) { if (light_instance_owner.owns(p_rid)) { - LightInstance *light_instance = light_instance_owner.getptr(p_rid); + LightInstance *light_instance = light_instance_owner.getornull(p_rid); //remove from shadow atlases.. for (Set::Element *E = light_instance->shadow_atlases.front(); E; E = E->next()) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(E->get()); + ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(E->get()); ERR_CONTINUE(!shadow_atlas->shadow_owners.has(p_rid)); uint32_t key = shadow_atlas->shadow_owners[p_rid]; uint32_t q = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x3; @@ -4933,19 +4933,19 @@ bool RasterizerSceneGLES3::free(RID p_rid) { } else if (shadow_atlas_owner.owns(p_rid)) { - ShadowAtlas *shadow_atlas = shadow_atlas_owner.get(p_rid); + ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_rid); shadow_atlas_set_size(p_rid, 0); shadow_atlas_owner.free(p_rid); memdelete(shadow_atlas); } else if (reflection_atlas_owner.owns(p_rid)) { - ReflectionAtlas *reflection_atlas = reflection_atlas_owner.get(p_rid); + ReflectionAtlas *reflection_atlas = reflection_atlas_owner.getornull(p_rid); reflection_atlas_set_size(p_rid, 0); reflection_atlas_owner.free(p_rid); memdelete(reflection_atlas); } else if (reflection_probe_instance_owner.owns(p_rid)) { - ReflectionProbeInstance *reflection_instance = reflection_probe_instance_owner.get(p_rid); + ReflectionProbeInstance *reflection_instance = reflection_probe_instance_owner.getornull(p_rid); reflection_probe_release_atlas_index(p_rid); reflection_probe_instance_owner.free(p_rid); @@ -4953,14 +4953,14 @@ bool RasterizerSceneGLES3::free(RID p_rid) { } else if (environment_owner.owns(p_rid)) { - Environment *environment = environment_owner.get(p_rid); + Environment *environment = environment_owner.getornull(p_rid); environment_owner.free(p_rid); memdelete(environment); } else if (gi_probe_instance_owner.owns(p_rid)) { - GIProbeInstance *gi_probe_instance = gi_probe_instance_owner.get(p_rid); + GIProbeInstance *gi_probe_instance = gi_probe_instance_owner.getornull(p_rid); gi_probe_instance_owner.free(p_rid); memdelete(gi_probe_instance); @@ -5320,6 +5320,19 @@ void RasterizerSceneGLES3::iteration() { } void RasterizerSceneGLES3::finalize() { + + storage->free(default_material); + storage->free(default_material_twosided); + storage->free(default_shader); + storage->free(default_shader_twosided); + + storage->free(default_worldcoord_material); + storage->free(default_worldcoord_material_twosided); + storage->free(default_worldcoord_shader); + storage->free(default_worldcoord_shader_twosided); + + storage->free(default_overdraw_material); + storage->free(default_overdraw_shader); } RasterizerSceneGLES3::RasterizerSceneGLES3() { @@ -5327,19 +5340,6 @@ RasterizerSceneGLES3::RasterizerSceneGLES3() { RasterizerSceneGLES3::~RasterizerSceneGLES3() { - memdelete(default_material.get_data()); - memdelete(default_material_twosided.get_data()); - memdelete(default_shader.get_data()); - memdelete(default_shader_twosided.get_data()); - - memdelete(default_worldcoord_material.get_data()); - memdelete(default_worldcoord_material_twosided.get_data()); - memdelete(default_worldcoord_shader.get_data()); - memdelete(default_worldcoord_shader_twosided.get_data()); - - memdelete(default_overdraw_material.get_data()); - memdelete(default_overdraw_shader.get_data()); - memfree(state.spot_array_tmp); memfree(state.omni_array_tmp); memfree(state.reflection_array_tmp); diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index 7885d7c1b7c6..474bbce1d652 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -216,7 +216,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { /* SHADOW ATLAS API */ - struct ShadowAtlas : public RID_Data { + struct ShadowAtlas { enum { QUADRANT_SHIFT = 27, @@ -267,7 +267,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { Vector shadow_cubemaps; - RID_Owner shadow_atlas_owner; + RID_PtrOwner shadow_atlas_owner; RID shadow_atlas_create(); void shadow_atlas_set_size(RID p_atlas, int p_size); @@ -288,7 +288,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { /* REFLECTION PROBE ATLAS API */ - struct ReflectionAtlas : public RID_Data { + struct ReflectionAtlas { int subdiv; int size; @@ -304,7 +304,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { Vector reflections; }; - mutable RID_Owner reflection_atlas_owner; + mutable RID_PtrOwner reflection_atlas_owner; virtual RID reflection_atlas_create(); virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_size); @@ -324,7 +324,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { /* REFLECTION PROBE INSTANCE */ - struct ReflectionProbeInstance : public RID_Data { + struct ReflectionProbeInstance { RasterizerStorageGLES3::ReflectionProbe *probe_ptr; RID probe; @@ -352,7 +352,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { //notes: for ambientblend, use distance to edge to blend between already existing global environment }; - mutable RID_Owner reflection_probe_instance_owner; + mutable RID_PtrOwner reflection_probe_instance_owner; virtual RID reflection_probe_instance_create(RID p_probe); virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform); @@ -364,7 +364,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { /* ENVIRONMENT API */ - struct Environment : public RID_Data { + struct Environment { VS::EnvironmentBG bg_mode; @@ -533,7 +533,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { } }; - RID_Owner environment_owner; + RID_PtrOwner environment_owner; virtual RID environment_create(); @@ -590,7 +590,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { float shadow_split_offsets[4]; }; - struct LightInstance : public RID_Data { + struct LightInstance { struct ShadowTransform { @@ -630,7 +630,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { LightInstance() {} }; - mutable RID_Owner light_instance_owner; + mutable RID_PtrOwner light_instance_owner; virtual RID light_instance_create(RID p_light); virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform); @@ -639,7 +639,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { /* REFLECTION INSTANCE */ - struct GIProbeInstance : public RID_Data { + struct GIProbeInstance { RID data; RasterizerStorageGLES3::GIProbe *probe; GLuint tex_cache; @@ -653,7 +653,7 @@ class RasterizerSceneGLES3 : public RasterizerScene { } }; - mutable RID_Owner gi_probe_instance_owner; + mutable RID_PtrOwner gi_probe_instance_owner; virtual RID gi_probe_instance_create(); virtual void gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data); diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index e5a7fcce0794..2a25c1d6cc34 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -647,7 +647,7 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_ } #endif - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); texture->width = p_width; texture->height = p_height; @@ -750,7 +750,7 @@ void RasterizerStorageGLES3::texture_allocate(RID p_texture, int p_width, int p_ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref &p_image, int p_layer) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); ERR_FAIL_COND(!texture->active); @@ -978,7 +978,7 @@ void RasterizerStorageGLES3::texture_set_data(RID p_texture, const Ref &p // TODO If we want this to be usable without pre-filling pixels with a full image, we have to call glTexImage2D() with null data. void RasterizerStorageGLES3::texture_set_data_partial(RID p_texture, const Ref &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, int p_layer) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); ERR_FAIL_COND(!texture->active); @@ -1064,7 +1064,7 @@ void RasterizerStorageGLES3::texture_set_data_partial(RID p_texture, const Ref RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer) const { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, Ref()); ERR_FAIL_COND_V(!texture->active, Ref()); @@ -1347,7 +1347,7 @@ Ref RasterizerStorageGLES3::texture_get_data(RID p_texture, int p_layer) void RasterizerStorageGLES3::texture_set_flags(RID p_texture, uint32_t p_flags) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); if (texture->render_target) { @@ -1423,7 +1423,7 @@ void RasterizerStorageGLES3::texture_set_flags(RID p_texture, uint32_t p_flags) } uint32_t RasterizerStorageGLES3::texture_get_flags(RID p_texture) const { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, 0); @@ -1431,7 +1431,7 @@ uint32_t RasterizerStorageGLES3::texture_get_flags(RID p_texture) const { } Image::Format RasterizerStorageGLES3::texture_get_format(RID p_texture) const { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, Image::FORMAT_L8); @@ -1439,7 +1439,7 @@ Image::Format RasterizerStorageGLES3::texture_get_format(RID p_texture) const { } VisualServer::TextureType RasterizerStorageGLES3::texture_get_type(RID p_texture) const { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, VS::TEXTURE_TYPE_2D); @@ -1447,7 +1447,7 @@ VisualServer::TextureType RasterizerStorageGLES3::texture_get_type(RID p_texture } uint32_t RasterizerStorageGLES3::texture_get_texid(RID p_texture) const { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, 0); @@ -1464,7 +1464,7 @@ void RasterizerStorageGLES3::texture_bind(RID p_texture, uint32_t p_texture_no) } uint32_t RasterizerStorageGLES3::texture_get_width(RID p_texture) const { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, 0); @@ -1472,7 +1472,7 @@ uint32_t RasterizerStorageGLES3::texture_get_width(RID p_texture) const { } uint32_t RasterizerStorageGLES3::texture_get_height(RID p_texture) const { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, 0); @@ -1481,7 +1481,7 @@ uint32_t RasterizerStorageGLES3::texture_get_height(RID p_texture) const { uint32_t RasterizerStorageGLES3::texture_get_depth(RID p_texture) const { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, 0); @@ -1490,7 +1490,7 @@ uint32_t RasterizerStorageGLES3::texture_get_depth(RID p_texture) const { void RasterizerStorageGLES3::texture_set_size_override(RID p_texture, int p_width, int p_height, int p_depth) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); ERR_FAIL_COND(texture->render_target); @@ -1503,7 +1503,7 @@ void RasterizerStorageGLES3::texture_set_size_override(RID p_texture, int p_widt } void RasterizerStorageGLES3::texture_set_path(RID p_texture, const String &p_path) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); texture->path = p_path; @@ -1511,7 +1511,7 @@ void RasterizerStorageGLES3::texture_set_path(RID p_texture, const String &p_pat String RasterizerStorageGLES3::texture_get_path(RID p_texture) const { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND_V(!texture, String()); return texture->path; } @@ -1522,7 +1522,7 @@ void RasterizerStorageGLES3::texture_debug_usage(List *r_info) for (List::Element *E = textures.front(); E; E = E->next()) { - Texture *t = texture_owner.get(E->get()); + Texture *t = texture_owner.getornull(E->get()); if (!t) continue; VS::TextureInfo tinfo; @@ -1548,7 +1548,7 @@ void RasterizerStorageGLES3::textures_keep_original(bool p_enable) { void RasterizerStorageGLES3::texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); texture->detect_3d = p_callback; @@ -1556,7 +1556,7 @@ void RasterizerStorageGLES3::texture_set_detect_3d_callback(RID p_texture, Visua } void RasterizerStorageGLES3::texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); texture->detect_srgb = p_callback; @@ -1564,7 +1564,7 @@ void RasterizerStorageGLES3::texture_set_detect_srgb_callback(RID p_texture, Vis } void RasterizerStorageGLES3::texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); texture->detect_normal = p_callback; @@ -1573,7 +1573,7 @@ void RasterizerStorageGLES3::texture_set_detect_normal_callback(RID p_texture, V RID RasterizerStorageGLES3::texture_create_radiance_cubemap(RID p_source, int p_resolution) const { - Texture *texture = texture_owner.get(p_source); + Texture *texture = texture_owner.getornull(p_source); ERR_FAIL_COND_V(!texture, RID()); ERR_FAIL_COND_V(texture->type != VS::TEXTURE_TYPE_CUBEMAP, RID()); @@ -1729,7 +1729,7 @@ Size2 RasterizerStorageGLES3::texture_size_with_proxy(RID p_texture) const { void RasterizerStorageGLES3::texture_set_proxy(RID p_texture, RID p_proxy) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); if (texture->proxy) { @@ -1738,7 +1738,7 @@ void RasterizerStorageGLES3::texture_set_proxy(RID p_texture, RID p_proxy) { } if (p_proxy.is_valid()) { - Texture *proxy = texture_owner.get(p_proxy); + Texture *proxy = texture_owner.getornull(p_proxy); ERR_FAIL_COND(!proxy); ERR_FAIL_COND(proxy == texture); proxy->proxy_owners.insert(texture); @@ -1748,7 +1748,7 @@ void RasterizerStorageGLES3::texture_set_proxy(RID p_texture, RID p_proxy) { void RasterizerStorageGLES3::texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) { - Texture *texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.getornull(p_texture); ERR_FAIL_COND(!texture); texture->redraw_if_visible = p_enable; } @@ -2194,7 +2194,7 @@ void RasterizerStorageGLES3::_shader_make_dirty(Shader *p_shader) { void RasterizerStorageGLES3::shader_set_code(RID p_shader, const String &p_code) { - Shader *shader = shader_owner.get(p_shader); + Shader *shader = shader_owner.getornull(p_shader); ERR_FAIL_COND(!shader); shader->code = p_code; @@ -2234,7 +2234,7 @@ void RasterizerStorageGLES3::shader_set_code(RID p_shader, const String &p_code) } String RasterizerStorageGLES3::shader_get_code(RID p_shader) const { - const Shader *shader = shader_owner.get(p_shader); + const Shader *shader = shader_owner.getornull(p_shader); ERR_FAIL_COND_V(!shader, String()); return shader->code; @@ -2387,7 +2387,7 @@ void RasterizerStorageGLES3::update_dirty_shaders() { void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List *p_param_list) const { - Shader *shader = shader_owner.get(p_shader); + Shader *shader = shader_owner.getornull(p_shader); ERR_FAIL_COND(!shader); if (shader->dirty_list.in_list()) @@ -2502,7 +2502,7 @@ void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List::Element *E = shader->default_textures.find(p_name); @@ -2543,7 +2543,7 @@ RID RasterizerStorageGLES3::material_create() { void RasterizerStorageGLES3::material_set_shader(RID p_material, RID p_shader) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); Shader *shader = shader_owner.getornull(p_shader); @@ -2563,7 +2563,7 @@ void RasterizerStorageGLES3::material_set_shader(RID p_material, RID p_shader) { RID RasterizerStorageGLES3::material_get_shader(RID p_material) const { - const Material *material = material_owner.get(p_material); + const Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, RID()); if (material->shader) @@ -2574,7 +2574,7 @@ RID RasterizerStorageGLES3::material_get_shader(RID p_material) const { void RasterizerStorageGLES3::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); if (p_value.get_type() == Variant::NIL) @@ -2586,7 +2586,7 @@ void RasterizerStorageGLES3::material_set_param(RID p_material, const StringName } Variant RasterizerStorageGLES3::material_get_param(RID p_material, const StringName &p_param) const { - const Material *material = material_owner.get(p_material); + const Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, Variant()); if (material->params.has(p_param)) @@ -2596,7 +2596,7 @@ Variant RasterizerStorageGLES3::material_get_param(RID p_material, const StringN } Variant RasterizerStorageGLES3::material_get_param_default(RID p_material, const StringName &p_param) const { - const Material *material = material_owner.get(p_material); + const Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, Variant()); if (material->shader) { @@ -2611,7 +2611,7 @@ Variant RasterizerStorageGLES3::material_get_param_default(RID p_material, const void RasterizerStorageGLES3::material_set_line_width(RID p_material, float p_width) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); material->line_width = p_width; @@ -2619,7 +2619,7 @@ void RasterizerStorageGLES3::material_set_line_width(RID p_material, float p_wid void RasterizerStorageGLES3::material_set_next_pass(RID p_material, RID p_next_material) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); material->next_pass = p_next_material; @@ -2627,7 +2627,7 @@ void RasterizerStorageGLES3::material_set_next_pass(RID p_material, RID p_next_m bool RasterizerStorageGLES3::material_is_animated(RID p_material) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, false); if (material->dirty_list.in_list()) { _update_material(material); @@ -2641,7 +2641,7 @@ bool RasterizerStorageGLES3::material_is_animated(RID p_material) { } bool RasterizerStorageGLES3::material_casts_shadows(RID p_material) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND_V(!material, false); if (material->dirty_list.in_list()) { _update_material(material); @@ -2658,7 +2658,7 @@ bool RasterizerStorageGLES3::material_casts_shadows(RID p_material) { void RasterizerStorageGLES3::material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); Map::Element *E = material->instance_owners.find(p_instance); @@ -2671,7 +2671,7 @@ void RasterizerStorageGLES3::material_add_instance_owner(RID p_material, Rasteri void RasterizerStorageGLES3::material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) { - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); Map::Element *E = material->instance_owners.find(p_instance); @@ -2688,7 +2688,7 @@ void RasterizerStorageGLES3::material_set_render_priority(RID p_material, int pr ERR_FAIL_COND(priority < VS::MATERIAL_RENDER_PRIORITY_MIN); ERR_FAIL_COND(priority > VS::MATERIAL_RENDER_PRIORITY_MAX); - Material *material = material_owner.get(p_material); + Material *material = material_owner.getornull(p_material); ERR_FAIL_COND(!material); material->render_priority = priority; @@ -4136,7 +4136,7 @@ AABB RasterizerStorageGLES3::mesh_get_custom_aabb(RID p_mesh) const { AABB RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { - Mesh *mesh = mesh_owner.get(p_mesh); + Mesh *mesh = mesh_owner.getornull(p_mesh); ERR_FAIL_COND_V(!mesh, AABB()); if (mesh->custom_aabb != AABB()) { @@ -4145,7 +4145,7 @@ AABB RasterizerStorageGLES3::mesh_get_aabb(RID p_mesh, RID p_skeleton) const { Skeleton *sk = NULL; if (p_skeleton.is_valid()) { - sk = skeleton_owner.get(p_skeleton); + sk = skeleton_owner.getornull(p_skeleton); } AABB aabb; @@ -5047,7 +5047,7 @@ RID RasterizerStorageGLES3::immediate_create() { void RasterizerStorageGLES3::immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture) { ERR_FAIL_INDEX(p_primitive, (int)VS::PRIMITIVE_MAX); - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(im->building); @@ -5060,7 +5060,7 @@ void RasterizerStorageGLES3::immediate_begin(RID p_immediate, VS::PrimitiveType } void RasterizerStorageGLES3::immediate_vertex(RID p_immediate, const Vector3 &p_vertex) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -5090,7 +5090,7 @@ void RasterizerStorageGLES3::immediate_vertex(RID p_immediate, const Vector3 &p_ void RasterizerStorageGLES3::immediate_normal(RID p_immediate, const Vector3 &p_normal) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -5099,7 +5099,7 @@ void RasterizerStorageGLES3::immediate_normal(RID p_immediate, const Vector3 &p_ } void RasterizerStorageGLES3::immediate_tangent(RID p_immediate, const Plane &p_tangent) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -5108,7 +5108,7 @@ void RasterizerStorageGLES3::immediate_tangent(RID p_immediate, const Plane &p_t } void RasterizerStorageGLES3::immediate_color(RID p_immediate, const Color &p_color) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -5117,7 +5117,7 @@ void RasterizerStorageGLES3::immediate_color(RID p_immediate, const Color &p_col } void RasterizerStorageGLES3::immediate_uv(RID p_immediate, const Vector2 &tex_uv) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -5126,7 +5126,7 @@ void RasterizerStorageGLES3::immediate_uv(RID p_immediate, const Vector2 &tex_uv } void RasterizerStorageGLES3::immediate_uv2(RID p_immediate, const Vector2 &tex_uv) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -5136,7 +5136,7 @@ void RasterizerStorageGLES3::immediate_uv2(RID p_immediate, const Vector2 &tex_u void RasterizerStorageGLES3::immediate_end(RID p_immediate) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(!im->building); @@ -5146,7 +5146,7 @@ void RasterizerStorageGLES3::immediate_end(RID p_immediate) { } void RasterizerStorageGLES3::immediate_clear(RID p_immediate) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); ERR_FAIL_COND(im->building); @@ -5156,14 +5156,14 @@ void RasterizerStorageGLES3::immediate_clear(RID p_immediate) { AABB RasterizerStorageGLES3::immediate_get_aabb(RID p_immediate) const { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND_V(!im, AABB()); return im->aabb; } void RasterizerStorageGLES3::immediate_set_material(RID p_immediate, RID p_material) { - Immediate *im = immediate_owner.get(p_immediate); + Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND(!im); im->material = p_material; im->instance_change_notify(false, true); @@ -5171,7 +5171,7 @@ void RasterizerStorageGLES3::immediate_set_material(RID p_immediate, RID p_mater RID RasterizerStorageGLES3::immediate_get_material(RID p_immediate) const { - const Immediate *im = immediate_owner.get(p_immediate); + const Immediate *im = immediate_owner.getornull(p_immediate); ERR_FAIL_COND_V(!im, RID()); return im->material; } @@ -6999,7 +6999,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { glDeleteFramebuffers(1, &rt->external.fbo); // clean up our texture - Texture *t = texture_owner.get(rt->external.texture); + Texture *t = texture_owner.getornull(rt->external.texture); t->alloc_height = 0; t->alloc_width = 0; t->width = 0; @@ -7011,7 +7011,7 @@ void RasterizerStorageGLES3::_render_target_clear(RenderTarget *rt) { rt->external.fbo = 0; } - Texture *tex = texture_owner.get(rt->texture); + Texture *tex = texture_owner.getornull(rt->texture); tex->alloc_height = 0; tex->alloc_width = 0; tex->width = 0; @@ -7117,7 +7117,7 @@ void RasterizerStorageGLES3::_render_target_allocate(RenderTarget *rt) { ERR_FAIL_COND(status != GL_FRAMEBUFFER_COMPLETE); - Texture *tex = texture_owner.get(rt->texture); + Texture *tex = texture_owner.getornull(rt->texture); tex->format = image_format; tex->gl_format_cache = color_format; tex->gl_type_cache = color_type; @@ -7487,7 +7487,7 @@ void RasterizerStorageGLES3::render_target_set_external_texture(RID p_render_tar glDeleteFramebuffers(1, &rt->external.fbo); // clean up our texture - Texture *t = texture_owner.get(rt->external.texture); + Texture *t = texture_owner.getornull(rt->external.texture); t->alloc_height = 0; t->alloc_width = 0; t->width = 0; @@ -7536,7 +7536,7 @@ void RasterizerStorageGLES3::render_target_set_external_texture(RID p_render_tar glBindFramebuffer(GL_FRAMEBUFFER, rt->external.fbo); // find our texture - t = texture_owner.get(rt->external.texture); + t = texture_owner.getornull(rt->external.texture); } // set our texture @@ -7678,7 +7678,7 @@ RID RasterizerStorageGLES3::canvas_light_occluder_create() { void RasterizerStorageGLES3::canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector &p_lines) { - CanvasOccluder *co = canvas_occluder_owner.get(p_occluder); + CanvasOccluder *co = canvas_occluder_owner.getornull(p_occluder); ERR_FAIL_COND(!co); co->lines = p_lines; @@ -7818,7 +7818,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { RenderTarget *rt = render_target_owner.getornull(p_rid); _render_target_clear(rt); - Texture *t = texture_owner.get(rt->texture); + Texture *t = texture_owner.getornull(rt->texture); texture_owner.free(rt->texture); memdelete(t); render_target_owner.free(p_rid); @@ -7826,7 +7826,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (texture_owner.owns(p_rid)) { // delete the texture - Texture *texture = texture_owner.get(p_rid); + Texture *texture = texture_owner.getornull(p_rid); ERR_FAIL_COND_V(texture->render_target, true); //can't free the render target texture, dude info.texture_mem -= texture->total_data_size; texture_owner.free(p_rid); @@ -7834,7 +7834,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (sky_owner.owns(p_rid)) { // delete the sky - Sky *sky = sky_owner.get(p_rid); + Sky *sky = sky_owner.getornull(p_rid); sky_set_texture(p_rid, RID(), 256); sky_owner.free(p_rid); memdelete(sky); @@ -7842,7 +7842,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (shader_owner.owns(p_rid)) { // delete the texture - Shader *shader = shader_owner.get(p_rid); + Shader *shader = shader_owner.getornull(p_rid); if (shader->shader && shader->custom_code_id) shader->shader->free_custom_shader(shader->custom_code_id); @@ -7867,7 +7867,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (material_owner.owns(p_rid)) { // delete the texture - Material *material = material_owner.get(p_rid); + Material *material = material_owner.getornull(p_rid); if (material->shader) { material->shader->materials.remove(&material->list); @@ -7902,7 +7902,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (skeleton_owner.owns(p_rid)) { // delete the texture - Skeleton *skeleton = skeleton_owner.get(p_rid); + Skeleton *skeleton = skeleton_owner.getornull(p_rid); if (skeleton->update_list.in_list()) { skeleton_update_list.remove(&skeleton->update_list); } @@ -7920,7 +7920,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (mesh_owner.owns(p_rid)) { // delete the texture - Mesh *mesh = mesh_owner.get(p_rid); + Mesh *mesh = mesh_owner.getornull(p_rid); mesh->instance_remove_deps(); mesh_clear(p_rid); @@ -7941,7 +7941,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (multimesh_owner.owns(p_rid)) { // delete the texture - MultiMesh *multimesh = multimesh_owner.get(p_rid); + MultiMesh *multimesh = multimesh_owner.getornull(p_rid); multimesh->instance_remove_deps(); if (multimesh->mesh.is_valid()) { @@ -7958,7 +7958,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { memdelete(multimesh); } else if (immediate_owner.owns(p_rid)) { - Immediate *immediate = immediate_owner.get(p_rid); + Immediate *immediate = immediate_owner.getornull(p_rid); immediate->instance_remove_deps(); immediate_owner.free(p_rid); @@ -7966,7 +7966,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (light_owner.owns(p_rid)) { // delete the texture - Light *light = light_owner.get(p_rid); + Light *light = light_owner.getornull(p_rid); light->instance_remove_deps(); light_owner.free(p_rid); @@ -7975,7 +7975,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (reflection_probe_owner.owns(p_rid)) { // delete the texture - ReflectionProbe *reflection_probe = reflection_probe_owner.get(p_rid); + ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_rid); reflection_probe->instance_remove_deps(); reflection_probe_owner.free(p_rid); @@ -7984,7 +7984,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (gi_probe_owner.owns(p_rid)) { // delete the texture - GIProbe *gi_probe = gi_probe_owner.get(p_rid); + GIProbe *gi_probe = gi_probe_owner.getornull(p_rid); gi_probe->instance_remove_deps(); gi_probe_owner.free(p_rid); @@ -7992,7 +7992,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (gi_probe_data_owner.owns(p_rid)) { // delete the texture - GIProbeData *gi_probe_data = gi_probe_data_owner.get(p_rid); + GIProbeData *gi_probe_data = gi_probe_data_owner.getornull(p_rid); glDeleteTextures(1, &gi_probe_data->tex_id); gi_probe_data_owner.free(p_rid); @@ -8000,7 +8000,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (lightmap_capture_data_owner.owns(p_rid)) { // delete the texture - LightmapCapture *lightmap_capture = lightmap_capture_data_owner.get(p_rid); + LightmapCapture *lightmap_capture = lightmap_capture_data_owner.getornull(p_rid); lightmap_capture->instance_remove_deps(); lightmap_capture_data_owner.free(p_rid); @@ -8008,7 +8008,7 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (canvas_occluder_owner.owns(p_rid)) { - CanvasOccluder *co = canvas_occluder_owner.get(p_rid); + CanvasOccluder *co = canvas_occluder_owner.getornull(p_rid); if (co->index_id) glDeleteBuffers(1, &co->index_id); if (co->vertex_id) @@ -8021,14 +8021,14 @@ bool RasterizerStorageGLES3::free(RID p_rid) { } else if (canvas_light_shadow_owner.owns(p_rid)) { - CanvasLightShadow *cls = canvas_light_shadow_owner.get(p_rid); + CanvasLightShadow *cls = canvas_light_shadow_owner.getornull(p_rid); glDeleteFramebuffers(1, &cls->fbo); glDeleteRenderbuffers(1, &cls->depth); glDeleteTextures(1, &cls->distance); canvas_light_shadow_owner.free(p_rid); memdelete(cls); } else if (particles_owner.owns(p_rid)) { - Particles *particles = particles_owner.get(p_rid); + Particles *particles = particles_owner.getornull(p_rid); particles->instance_remove_deps(); particles_owner.free(p_rid); memdelete(particles); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index bd853852fea4..1953a2e8093c 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -43,6 +43,8 @@ #include "shaders/cubemap_filter.glsl.gen.h" #include "shaders/particles.glsl.gen.h" +#include "core/rid_owner.h" + // WebGL 2.0 has no MapBufferRange/UnmapBuffer, but offers a non-ES style BufferSubData API instead. #ifdef __EMSCRIPTEN__ void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data); @@ -179,7 +181,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { //////////////////////////////////DATA/////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// - struct Instantiable : public RID_Data { + struct Instantiable { SelfList::List instance_list; @@ -242,7 +244,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { struct RenderTarget; - struct Texture : public RID_Data { + struct Texture { Texture *proxy; Set proxy_owners; @@ -342,7 +344,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { } }; - mutable RID_Owner texture_owner; + mutable RID_PtrOwner texture_owner; Ref _get_gl_image_and_format(const Ref &p_image, Image::Format p_format, uint32_t p_flags, Image::Format &r_real_format, GLenum &r_gl_format, GLenum &r_gl_internal_format, GLenum &r_gl_type, bool &r_compressed, bool &r_srgb, bool p_force_decompress) const; @@ -384,7 +386,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { /* SKY API */ - struct Sky : public RID_Data { + struct Sky { RID panorama; GLuint radiance; @@ -392,7 +394,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { int radiance_size; }; - mutable RID_Owner sky_owner; + mutable RID_PtrOwner sky_owner; virtual RID sky_create(); virtual void sky_set_texture(RID p_sky, RID p_panorama, int p_radiance_size); @@ -401,7 +403,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { struct Material; - struct Shader : public RID_Data { + struct Shader { RID self; @@ -522,7 +524,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { mutable SelfList::List _shader_dirty_list; void _shader_make_dirty(Shader *p_shader); - mutable RID_Owner shader_owner; + mutable RID_PtrOwner shader_owner; virtual RID shader_create(); @@ -539,7 +541,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { /* COMMON MATERIAL API */ - struct Material : public RID_Data { + struct Material { Shader *shader; GLuint ubo_id; @@ -582,7 +584,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { void _material_add_geometry(RID p_material, Geometry *p_geometry); void _material_remove_geometry(RID p_material, Geometry *p_geometry); - mutable RID_Owner material_owner; + mutable RID_PtrOwner material_owner; virtual RID material_create(); @@ -724,7 +726,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { } }; - mutable RID_Owner mesh_owner; + mutable RID_PtrOwner mesh_owner; virtual RID mesh_create(); @@ -804,7 +806,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { } }; - mutable RID_Owner multimesh_owner; + mutable RID_PtrOwner multimesh_owner; SelfList::List multimesh_update_list; @@ -869,7 +871,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { Vector2 chunk_uv; Vector2 chunk_uv2; - mutable RID_Owner immediate_owner; + mutable RID_PtrOwner immediate_owner; virtual RID immediate_create(); virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_primitive, RID p_texture = RID()); @@ -887,7 +889,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { /* SKELETON API */ - struct Skeleton : RID_Data { + struct Skeleton { bool use_2d; int size; Vector skel_texture; @@ -904,7 +906,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { } }; - mutable RID_Owner skeleton_owner; + mutable RID_PtrOwner skeleton_owner; SelfList::List skeleton_update_list; @@ -941,7 +943,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { uint64_t version; }; - mutable RID_Owner light_owner; + mutable RID_PtrOwner light_owner; virtual RID light_create(VS::LightType p_type); @@ -996,7 +998,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { uint32_t cull_mask; }; - mutable RID_Owner reflection_probe_owner; + mutable RID_PtrOwner reflection_probe_owner; virtual RID reflection_probe_create(); @@ -1044,7 +1046,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { PoolVector dynamic_data; }; - mutable RID_Owner gi_probe_owner; + mutable RID_PtrOwner gi_probe_owner; virtual RID gi_probe_create(); @@ -1083,7 +1085,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { virtual uint32_t gi_probe_get_version(RID p_probe); - struct GIProbeData : public RID_Data { + struct GIProbeData { int width; int height; @@ -1096,7 +1098,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { } }; - mutable RID_Owner gi_probe_data_owner; + mutable RID_PtrOwner gi_probe_data_owner; virtual GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const; virtual RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression); @@ -1132,7 +1134,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { } }; - mutable RID_Owner lightmap_capture_data_owner; + mutable RID_PtrOwner lightmap_capture_data_owner; /* PARTICLES */ @@ -1228,7 +1230,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { void update_particles(); - mutable RID_Owner particles_owner; + mutable RID_PtrOwner particles_owner; virtual RID particles_create(); @@ -1277,7 +1279,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { /* RENDER TARGET */ - struct RenderTarget : public RID_Data { + struct RenderTarget { GLuint fbo; GLuint color; @@ -1389,7 +1391,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { } }; - mutable RID_Owner render_target_owner; + mutable RID_PtrOwner render_target_owner; void _render_target_clear(RenderTarget *rt); void _render_target_allocate(RenderTarget *rt); @@ -1407,7 +1409,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { /* CANVAS SHADOW */ - struct CanvasLightShadow : public RID_Data { + struct CanvasLightShadow { int size; int height; @@ -1416,13 +1418,13 @@ class RasterizerStorageGLES3 : public RasterizerStorage { GLuint distance; //for older devices }; - RID_Owner canvas_light_shadow_owner; + RID_PtrOwner canvas_light_shadow_owner; virtual RID canvas_light_shadow_buffer_create(int p_width); /* LIGHT SHADOW MAPPING */ - struct CanvasOccluder : public RID_Data { + struct CanvasOccluder { GLuint array_id; // 0 means, unconfigured GLuint vertex_id; // 0 means, unconfigured @@ -1431,7 +1433,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage { int len; }; - RID_Owner canvas_occluder_owner; + RID_PtrOwner canvas_occluder_owner; virtual RID canvas_light_occluder_create(); virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector &p_lines); diff --git a/main/main.cpp b/main/main.cpp index 162d5568d4d0..b74ae3643424 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -352,7 +352,6 @@ void Main::print_help(const char *p_binary) { */ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_phase) { - RID_OwnerBase::init_rid(); OS::get_singleton()->initialize_core(); diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index e50798729747..fceb5d2b4b84 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -134,7 +134,7 @@ RID BulletPhysicsServer::shape_create(ShapeType p_shape) { } void BulletPhysicsServer::shape_set_data(RID p_shape, const Variant &p_data) { - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); shape->set_data(p_data); } @@ -144,25 +144,25 @@ void BulletPhysicsServer::shape_set_custom_solver_bias(RID p_shape, real_t p_bia } PhysicsServer::ShapeType BulletPhysicsServer::shape_get_type(RID p_shape) const { - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, PhysicsServer::SHAPE_CUSTOM); return shape->get_type(); } Variant BulletPhysicsServer::shape_get_data(RID p_shape) const { - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, Variant()); return shape->get_data(); } void BulletPhysicsServer::shape_set_margin(RID p_shape, real_t p_margin) { - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); shape->set_margin(p_margin); } real_t BulletPhysicsServer::shape_get_margin(RID p_shape) const { - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0.0); return shape->get_margin(); } @@ -179,7 +179,7 @@ RID BulletPhysicsServer::space_create() { void BulletPhysicsServer::space_set_active(RID p_space, bool p_active) { - SpaceBullet *space = space_owner.get(p_space); + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); if (space_is_active(p_space) == p_active) { @@ -196,47 +196,47 @@ void BulletPhysicsServer::space_set_active(RID p_space, bool p_active) { } bool BulletPhysicsServer::space_is_active(RID p_space) const { - SpaceBullet *space = space_owner.get(p_space); + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, false); return -1 != active_spaces.find(space); } void BulletPhysicsServer::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) { - SpaceBullet *space = space_owner.get(p_space); + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); space->set_param(p_param, p_value); } real_t BulletPhysicsServer::space_get_param(RID p_space, SpaceParameter p_param) const { - SpaceBullet *space = space_owner.get(p_space); + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_param(p_param); } PhysicsDirectSpaceState *BulletPhysicsServer::space_get_direct_state(RID p_space) { - SpaceBullet *space = space_owner.get(p_space); + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, NULL); return space->get_direct_state(); } void BulletPhysicsServer::space_set_debug_contacts(RID p_space, int p_max_contacts) { - SpaceBullet *space = space_owner.get(p_space); + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); space->set_debug_contacts(p_max_contacts); } Vector BulletPhysicsServer::space_get_contacts(RID p_space) const { - SpaceBullet *space = space_owner.get(p_space); + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, Vector()); return space->get_debug_contacts(); } int BulletPhysicsServer::space_get_contact_count(RID p_space) const { - SpaceBullet *space = space_owner.get(p_space); + SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_debug_contact_count(); @@ -250,91 +250,91 @@ RID BulletPhysicsServer::area_create() { } void BulletPhysicsServer::area_set_space(RID p_area, RID p_space) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); SpaceBullet *space = NULL; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } area->set_space(space); } RID BulletPhysicsServer::area_get_space(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); return area->get_space()->get_self(); } void BulletPhysicsServer::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_spOv_mode(p_mode); } PhysicsServer::AreaSpaceOverrideMode BulletPhysicsServer::area_get_space_override_mode(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED); return area->get_spOv_mode(); } void BulletPhysicsServer::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform, bool p_disabled) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); area->add_shape(shape, p_transform, p_disabled); } void BulletPhysicsServer::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); area->set_shape(p_shape_idx, shape); } void BulletPhysicsServer::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_shape_transform(p_shape_idx, p_transform); } int BulletPhysicsServer::area_get_shape_count(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, 0); return area->get_shape_count(); } RID BulletPhysicsServer::area_get_shape(RID p_area, int p_shape_idx) const { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, RID()); return area->get_shape(p_shape_idx)->get_self(); } Transform BulletPhysicsServer::area_get_shape_transform(RID p_area, int p_shape_idx) const { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Transform()); return area->get_shape_transform(p_shape_idx); } void BulletPhysicsServer::area_remove_shape(RID p_area, int p_shape_idx) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); return area->remove_shape_full(p_shape_idx); } void BulletPhysicsServer::area_clear_shapes(RID p_area) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); for (int i = area->get_shape_count(); 0 < i; --i) @@ -342,7 +342,7 @@ void BulletPhysicsServer::area_clear_shapes(RID p_area) { } void BulletPhysicsServer::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_shape_disabled(p_shape_idx, p_disabled); @@ -352,7 +352,7 @@ void BulletPhysicsServer::area_attach_object_instance_id(RID p_area, ObjectID p_ if (space_owner.owns(p_area)) { return; } - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_instance_id(p_id); } @@ -361,20 +361,20 @@ ObjectID BulletPhysicsServer::area_get_object_instance_id(RID p_area) const { if (space_owner.owns(p_area)) { return 0; } - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, ObjectID()); return area->get_instance_id(); } void BulletPhysicsServer::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) { if (space_owner.owns(p_area)) { - SpaceBullet *space = space_owner.get(p_area); + SpaceBullet *space = space_owner.getornull(p_area); if (space) { space->set_param(p_param, p_value); } } else { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_param(p_param, p_value); @@ -383,10 +383,10 @@ void BulletPhysicsServer::area_set_param(RID p_area, AreaParameter p_param, cons Variant BulletPhysicsServer::area_get_param(RID p_area, AreaParameter p_param) const { if (space_owner.owns(p_area)) { - SpaceBullet *space = space_owner.get(p_area); + SpaceBullet *space = space_owner.getornull(p_area); return space->get_param(p_param); } else { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Variant()); return area->get_param(p_param); @@ -394,58 +394,58 @@ Variant BulletPhysicsServer::area_get_param(RID p_area, AreaParameter p_param) c } void BulletPhysicsServer::area_set_transform(RID p_area, const Transform &p_transform) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_transform(p_transform); } Transform BulletPhysicsServer::area_get_transform(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Transform()); return area->get_transform(); } void BulletPhysicsServer::area_set_collision_mask(RID p_area, uint32_t p_mask) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_collision_mask(p_mask); } void BulletPhysicsServer::area_set_collision_layer(RID p_area, uint32_t p_layer) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_collision_layer(p_layer); } void BulletPhysicsServer::area_set_monitorable(RID p_area, bool p_monitorable) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_monitorable(p_monitorable); } void BulletPhysicsServer::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_event_callback(CollisionObjectBullet::TYPE_RIGID_BODY, p_receiver ? p_receiver->get_instance_id() : 0, p_method); } void BulletPhysicsServer::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_event_callback(CollisionObjectBullet::TYPE_AREA, p_receiver ? p_receiver->get_instance_id() : 0, p_method); } void BulletPhysicsServer::area_set_ray_pickable(RID p_area, bool p_enable) { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_ray_pickable(p_enable); } bool BulletPhysicsServer::area_is_ray_pickable(RID p_area) const { - AreaBullet *area = area_owner.get(p_area); + AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, false); return area->is_ray_pickable(); } @@ -461,12 +461,12 @@ RID BulletPhysicsServer::body_create(BodyMode p_mode, bool p_init_sleeping) { } void BulletPhysicsServer::body_set_space(RID p_body, RID p_space) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); SpaceBullet *space = NULL; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } @@ -477,7 +477,7 @@ void BulletPhysicsServer::body_set_space(RID p_body, RID p_space) { } RID BulletPhysicsServer::body_get_space(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); SpaceBullet *space = body->get_space(); @@ -487,53 +487,53 @@ RID BulletPhysicsServer::body_get_space(RID p_body) const { } void BulletPhysicsServer::body_set_mode(RID p_body, PhysicsServer::BodyMode p_mode) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_mode(p_mode); } PhysicsServer::BodyMode BulletPhysicsServer::body_get_mode(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, BODY_MODE_STATIC); return body->get_mode(); } void BulletPhysicsServer::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform, bool p_disabled) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); body->add_shape(shape, p_transform, p_disabled); } void BulletPhysicsServer::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - ShapeBullet *shape = shape_owner.get(p_shape); + ShapeBullet *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); body->set_shape(p_shape_idx, shape); } void BulletPhysicsServer::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_shape_transform(p_shape_idx, p_transform); } int BulletPhysicsServer::body_get_shape_count(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_shape_count(); } RID BulletPhysicsServer::body_get_shape(RID p_body, int p_shape_idx) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); ShapeBullet *shape = body->get_shape(p_shape_idx); @@ -543,27 +543,27 @@ RID BulletPhysicsServer::body_get_shape(RID p_body, int p_shape_idx) const { } Transform BulletPhysicsServer::body_get_shape_transform(RID p_body, int p_shape_idx) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Transform()); return body->get_shape_transform(p_shape_idx); } void BulletPhysicsServer::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_shape_disabled(p_shape_idx, p_disabled); } void BulletPhysicsServer::body_remove_shape(RID p_body, int p_shape_idx) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->remove_shape_full(p_shape_idx); } void BulletPhysicsServer::body_clear_shapes(RID p_body) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->remove_all_shapes(); @@ -584,42 +584,42 @@ uint32_t BulletPhysicsServer::body_get_object_instance_id(RID p_body) const { } void BulletPhysicsServer::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_continuous_collision_detection(p_enable); } bool BulletPhysicsServer::body_is_continuous_collision_detection_enabled(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->is_continuous_collision_detection_enabled(); } void BulletPhysicsServer::body_set_collision_layer(RID p_body, uint32_t p_layer) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_layer(p_layer); } uint32_t BulletPhysicsServer::body_get_collision_layer(RID p_body) const { - const RigidBodyBullet *body = rigid_body_owner.get(p_body); + const RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_layer(); } void BulletPhysicsServer::body_set_collision_mask(RID p_body, uint32_t p_mask) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_mask(p_mask); } uint32_t BulletPhysicsServer::body_get_collision_mask(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_mask(); @@ -635,21 +635,21 @@ uint32_t BulletPhysicsServer::body_get_user_flags(RID p_body) const { } void BulletPhysicsServer::body_set_param(RID p_body, BodyParameter p_param, float p_value) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_param(p_param, p_value); } float BulletPhysicsServer::body_get_param(RID p_body, BodyParameter p_param) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_param(p_param); } void BulletPhysicsServer::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); if (body->get_kinematic_utilities()) { @@ -659,7 +659,7 @@ void BulletPhysicsServer::body_set_kinematic_safe_margin(RID p_body, real_t p_ma } real_t BulletPhysicsServer::body_get_kinematic_safe_margin(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); if (body->get_kinematic_utilities()) { @@ -671,90 +671,90 @@ real_t BulletPhysicsServer::body_get_kinematic_safe_margin(RID p_body) const { } void BulletPhysicsServer::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_state(p_state, p_variant); } Variant BulletPhysicsServer::body_get_state(RID p_body, BodyState p_state) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Variant()); return body->get_state(p_state); } void BulletPhysicsServer::body_set_applied_force(RID p_body, const Vector3 &p_force) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_applied_force(p_force); } Vector3 BulletPhysicsServer::body_get_applied_force(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3()); return body->get_applied_force(); } void BulletPhysicsServer::body_set_applied_torque(RID p_body, const Vector3 &p_torque) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_applied_torque(p_torque); } Vector3 BulletPhysicsServer::body_get_applied_torque(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3()); return body->get_applied_torque(); } void BulletPhysicsServer::body_add_central_force(RID p_body, const Vector3 &p_force) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_central_force(p_force); } void BulletPhysicsServer::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_force(p_force, p_pos); } void BulletPhysicsServer::body_add_torque(RID p_body, const Vector3 &p_torque) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_torque(p_torque); } void BulletPhysicsServer::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_central_impulse(p_impulse); } void BulletPhysicsServer::body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_impulse(p_pos, p_impulse); } void BulletPhysicsServer::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_torque_impulse(p_impulse); } void BulletPhysicsServer::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); Vector3 v = body->get_linear_velocity(); @@ -765,39 +765,39 @@ void BulletPhysicsServer::body_set_axis_velocity(RID p_body, const Vector3 &p_ax } void BulletPhysicsServer::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_axis_lock(p_axis, p_lock); } bool BulletPhysicsServer::body_is_axis_locked(RID p_body, BodyAxis p_axis) const { - const RigidBodyBullet *body = rigid_body_owner.get(p_body); + const RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->is_axis_locked(p_axis); } void BulletPhysicsServer::body_add_collision_exception(RID p_body, RID p_body_b) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - RigidBodyBullet *other_body = rigid_body_owner.get(p_body_b); + RigidBodyBullet *other_body = rigid_body_owner.getornull(p_body_b); ERR_FAIL_COND(!other_body); body->add_collision_exception(other_body); } void BulletPhysicsServer::body_remove_collision_exception(RID p_body, RID p_body_b) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - RigidBodyBullet *other_body = rigid_body_owner.get(p_body_b); + RigidBodyBullet *other_body = rigid_body_owner.getornull(p_body_b); ERR_FAIL_COND(!other_body); body->remove_collision_exception(other_body); } void BulletPhysicsServer::body_get_collision_exceptions(RID p_body, List *p_exceptions) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); for (int i = 0; i < body->get_exceptions().size(); i++) { p_exceptions->push_back(body->get_exceptions()[i]); @@ -805,14 +805,14 @@ void BulletPhysicsServer::body_get_collision_exceptions(RID p_body, List *p } void BulletPhysicsServer::body_set_max_contacts_reported(RID p_body, int p_contacts) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_max_collisions_detection(p_contacts); } int BulletPhysicsServer::body_get_max_contacts_reported(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_max_collisions_detection(); @@ -828,45 +828,45 @@ float BulletPhysicsServer::body_get_contacts_reported_depth_threshold(RID p_body } void BulletPhysicsServer::body_set_omit_force_integration(RID p_body, bool p_omit) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_omit_forces_integration(p_omit); } bool BulletPhysicsServer::body_is_omitting_force_integration(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->get_omit_forces_integration(); } void BulletPhysicsServer::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(0), p_method, p_udata); } void BulletPhysicsServer::body_set_ray_pickable(RID p_body, bool p_enable) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_ray_pickable(p_enable); } bool BulletPhysicsServer::body_is_ray_pickable(RID p_body) const { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->is_ray_pickable(); } PhysicsDirectBodyState *BulletPhysicsServer::body_get_direct_state(RID p_body) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, NULL); return BulletPhysicsDirectBodyState::get_singleton(body); } bool BulletPhysicsServer::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); @@ -874,7 +874,7 @@ bool BulletPhysicsServer::body_test_motion(RID p_body, const Transform &p_from, } int BulletPhysicsServer::body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) { - RigidBodyBullet *body = rigid_body_owner.get(p_body); + RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); ERR_FAIL_COND_V(!body->get_space(), 0); @@ -891,19 +891,19 @@ RID BulletPhysicsServer::soft_body_create(bool p_init_sleeping) { } void BulletPhysicsServer::soft_body_update_visual_server(RID p_body, class SoftBodyVisualServerHandler *p_visual_server_handler) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->update_visual_server(p_visual_server_handler); } void BulletPhysicsServer::soft_body_set_space(RID p_body, RID p_space) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); SpaceBullet *space = NULL; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } @@ -914,7 +914,7 @@ void BulletPhysicsServer::soft_body_set_space(RID p_body, RID p_space) { } RID BulletPhysicsServer::soft_body_get_space(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); SpaceBullet *space = body->get_space(); @@ -924,47 +924,47 @@ RID BulletPhysicsServer::soft_body_get_space(RID p_body) const { } void BulletPhysicsServer::soft_body_set_mesh(RID p_body, const REF &p_mesh) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_soft_mesh(p_mesh); } void BulletPhysicsServer::soft_body_set_collision_layer(RID p_body, uint32_t p_layer) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_layer(p_layer); } uint32_t BulletPhysicsServer::soft_body_get_collision_layer(RID p_body) const { - const SoftBodyBullet *body = soft_body_owner.get(p_body); + const SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_layer(); } void BulletPhysicsServer::soft_body_set_collision_mask(RID p_body, uint32_t p_mask) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_mask(p_mask); } uint32_t BulletPhysicsServer::soft_body_get_collision_mask(RID p_body) const { - const SoftBodyBullet *body = soft_body_owner.get(p_body); + const SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_mask(); } void BulletPhysicsServer::soft_body_add_collision_exception(RID p_body, RID p_body_b) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b); + CollisionObjectBullet *other_body = rigid_body_owner.getornull(p_body_b); if (!other_body) { - other_body = soft_body_owner.get(p_body_b); + other_body = soft_body_owner.getornull(p_body_b); } ERR_FAIL_COND(!other_body); @@ -972,12 +972,12 @@ void BulletPhysicsServer::soft_body_add_collision_exception(RID p_body, RID p_bo } void BulletPhysicsServer::soft_body_remove_collision_exception(RID p_body, RID p_body_b) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); - CollisionObjectBullet *other_body = rigid_body_owner.get(p_body_b); + CollisionObjectBullet *other_body = rigid_body_owner.getornull(p_body_b); if (!other_body) { - other_body = soft_body_owner.get(p_body_b); + other_body = soft_body_owner.getornull(p_body_b); } ERR_FAIL_COND(!other_body); @@ -985,7 +985,7 @@ void BulletPhysicsServer::soft_body_remove_collision_exception(RID p_body, RID p } void BulletPhysicsServer::soft_body_get_collision_exceptions(RID p_body, List *p_exceptions) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); for (int i = 0; i < body->get_exceptions().size(); i++) { p_exceptions->push_back(body->get_exceptions()[i]); @@ -1004,14 +1004,14 @@ Variant BulletPhysicsServer::soft_body_get_state(RID p_body, BodyState p_state) } void BulletPhysicsServer::soft_body_set_transform(RID p_body, const Transform &p_transform) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_soft_transform(p_transform); } Vector3 BulletPhysicsServer::soft_body_get_vertex_position(RID p_body, int vertex_index) const { - const SoftBodyBullet *body = soft_body_owner.get(p_body); + const SoftBodyBullet *body = soft_body_owner.getornull(p_body); Vector3 pos; ERR_FAIL_COND_V(!body, pos); @@ -1020,133 +1020,133 @@ Vector3 BulletPhysicsServer::soft_body_get_vertex_position(RID p_body, int verte } void BulletPhysicsServer::soft_body_set_ray_pickable(RID p_body, bool p_enable) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_ray_pickable(p_enable); } bool BulletPhysicsServer::soft_body_is_ray_pickable(RID p_body) const { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->is_ray_pickable(); } void BulletPhysicsServer::soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_simulation_precision(p_simulation_precision); } int BulletPhysicsServer::soft_body_get_simulation_precision(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_simulation_precision(); } void BulletPhysicsServer::soft_body_set_total_mass(RID p_body, real_t p_total_mass) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_total_mass(p_total_mass); } real_t BulletPhysicsServer::soft_body_get_total_mass(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_total_mass(); } void BulletPhysicsServer::soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_linear_stiffness(p_stiffness); } real_t BulletPhysicsServer::soft_body_get_linear_stiffness(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_linear_stiffness(); } void BulletPhysicsServer::soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_areaAngular_stiffness(p_stiffness); } real_t BulletPhysicsServer::soft_body_get_areaAngular_stiffness(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_areaAngular_stiffness(); } void BulletPhysicsServer::soft_body_set_volume_stiffness(RID p_body, real_t p_stiffness) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_volume_stiffness(p_stiffness); } real_t BulletPhysicsServer::soft_body_get_volume_stiffness(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_volume_stiffness(); } void BulletPhysicsServer::soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_pressure_coefficient(p_pressure_coefficient); } real_t BulletPhysicsServer::soft_body_get_pressure_coefficient(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_pressure_coefficient(); } void BulletPhysicsServer::soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); return body->set_pose_matching_coefficient(p_pose_matching_coefficient); } real_t BulletPhysicsServer::soft_body_get_pose_matching_coefficient(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_pose_matching_coefficient(); } void BulletPhysicsServer::soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_damping_coefficient(p_damping_coefficient); } real_t BulletPhysicsServer::soft_body_get_damping_coefficient(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_damping_coefficient(); } void BulletPhysicsServer::soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_drag_coefficient(p_drag_coefficient); } real_t BulletPhysicsServer::soft_body_get_drag_coefficient(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_drag_coefficient(); } void BulletPhysicsServer::soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_node_position(p_point_index, p_global_position); } Vector3 BulletPhysicsServer::soft_body_get_point_global_position(RID p_body, int p_point_index) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3(0., 0., 0.)); Vector3 pos; body->get_node_position(p_point_index, pos); @@ -1154,7 +1154,7 @@ Vector3 BulletPhysicsServer::soft_body_get_point_global_position(RID p_body, int } Vector3 BulletPhysicsServer::soft_body_get_point_offset(RID p_body, int p_point_index) const { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3()); Vector3 res; body->get_node_offset(p_point_index, res); @@ -1162,25 +1162,25 @@ Vector3 BulletPhysicsServer::soft_body_get_point_offset(RID p_body, int p_point_ } void BulletPhysicsServer::soft_body_remove_all_pinned_points(RID p_body) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->reset_all_node_mass(); } void BulletPhysicsServer::soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_node_mass(p_point_index, p_pin ? 0 : 1); } bool BulletPhysicsServer::soft_body_is_point_pinned(RID p_body, int p_point_index) { - SoftBodyBullet *body = soft_body_owner.get(p_body); + SoftBodyBullet *body = soft_body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0.f); return body->get_node_mass(p_point_index); } PhysicsServer::JointType BulletPhysicsServer::joint_get_type(RID p_joint) const { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, JOINT_PIN); return joint->get_type(); } @@ -1195,28 +1195,28 @@ int BulletPhysicsServer::joint_get_solver_priority(RID p_joint) const { } void BulletPhysicsServer::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); joint->disable_collisions_between_bodies(p_disable); } bool BulletPhysicsServer::joint_is_disabled_collisions_between_bodies(RID p_joint) const { - JointBullet *joint(joint_owner.get(p_joint)); + JointBullet *joint(joint_owner.getornull(p_joint)); ERR_FAIL_COND_V(!joint, false); return joint->is_disabled_collisions_between_bodies(); } RID BulletPhysicsServer::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = NULL; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1230,7 +1230,7 @@ RID BulletPhysicsServer::joint_create_pin(RID p_body_A, const Vector3 &p_local_A } void BulletPhysicsServer::pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointBullet *pin_joint = static_cast(joint); @@ -1238,7 +1238,7 @@ void BulletPhysicsServer::pin_joint_set_param(RID p_joint, PinJointParam p_param } float BulletPhysicsServer::pin_joint_get_param(RID p_joint, PinJointParam p_param) const { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, 0); PinJointBullet *pin_joint = static_cast(joint); @@ -1246,7 +1246,7 @@ float BulletPhysicsServer::pin_joint_get_param(RID p_joint, PinJointParam p_para } void BulletPhysicsServer::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointBullet *pin_joint = static_cast(joint); @@ -1254,7 +1254,7 @@ void BulletPhysicsServer::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) } Vector3 BulletPhysicsServer::pin_joint_get_local_a(RID p_joint) const { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointBullet *pin_joint = static_cast(joint); @@ -1262,7 +1262,7 @@ Vector3 BulletPhysicsServer::pin_joint_get_local_a(RID p_joint) const { } void BulletPhysicsServer::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointBullet *pin_joint = static_cast(joint); @@ -1270,7 +1270,7 @@ void BulletPhysicsServer::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) } Vector3 BulletPhysicsServer::pin_joint_get_local_b(RID p_joint) const { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointBullet *pin_joint = static_cast(joint); @@ -1278,13 +1278,13 @@ Vector3 BulletPhysicsServer::pin_joint_get_local_b(RID p_joint) const { } RID BulletPhysicsServer::joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = NULL; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1298,13 +1298,13 @@ RID BulletPhysicsServer::joint_create_hinge(RID p_body_A, const Transform &p_hin } RID BulletPhysicsServer::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = NULL; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1318,7 +1318,7 @@ RID BulletPhysicsServer::joint_create_hinge_simple(RID p_body_A, const Vector3 & } void BulletPhysicsServer::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_HINGE); HingeJointBullet *hinge_joint = static_cast(joint); @@ -1326,7 +1326,7 @@ void BulletPhysicsServer::hinge_joint_set_param(RID p_joint, HingeJointParam p_p } float BulletPhysicsServer::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, 0); HingeJointBullet *hinge_joint = static_cast(joint); @@ -1334,7 +1334,7 @@ float BulletPhysicsServer::hinge_joint_get_param(RID p_joint, HingeJointParam p_ } void BulletPhysicsServer::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_HINGE); HingeJointBullet *hinge_joint = static_cast(joint); @@ -1342,7 +1342,7 @@ void BulletPhysicsServer::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_fla } bool BulletPhysicsServer::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, false); ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, false); HingeJointBullet *hinge_joint = static_cast(joint); @@ -1350,13 +1350,13 @@ bool BulletPhysicsServer::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_fla } RID BulletPhysicsServer::joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = NULL; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1370,7 +1370,7 @@ RID BulletPhysicsServer::joint_create_slider(RID p_body_A, const Transform &p_lo } void BulletPhysicsServer::slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_SLIDER); SliderJointBullet *slider_joint = static_cast(joint); @@ -1378,7 +1378,7 @@ void BulletPhysicsServer::slider_joint_set_param(RID p_joint, SliderJointParam p } float BulletPhysicsServer::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_SLIDER, 0); SliderJointBullet *slider_joint = static_cast(joint); @@ -1386,13 +1386,13 @@ float BulletPhysicsServer::slider_joint_get_param(RID p_joint, SliderJointParam } RID BulletPhysicsServer::joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = NULL; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1404,7 +1404,7 @@ RID BulletPhysicsServer::joint_create_cone_twist(RID p_body_A, const Transform & } void BulletPhysicsServer::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_CONE_TWIST); ConeTwistJointBullet *coneTwist_joint = static_cast(joint); @@ -1412,7 +1412,7 @@ void BulletPhysicsServer::cone_twist_joint_set_param(RID p_joint, ConeTwistJoint } float BulletPhysicsServer::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0.); ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0.); ConeTwistJointBullet *coneTwist_joint = static_cast(joint); @@ -1420,13 +1420,13 @@ float BulletPhysicsServer::cone_twist_joint_get_param(RID p_joint, ConeTwistJoin } RID BulletPhysicsServer::joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { - RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A); + RigidBodyBullet *body_A = rigid_body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); JointAssertSpace(body_A, "A", RID()); RigidBodyBullet *body_B = NULL; if (p_body_B.is_valid()) { - body_B = rigid_body_owner.get(p_body_B); + body_B = rigid_body_owner.getornull(p_body_B); JointAssertSpace(body_B, "B", RID()); JointAssertSameSpace(body_A, body_B, RID()); } @@ -1440,7 +1440,7 @@ RID BulletPhysicsServer::joint_create_generic_6dof(RID p_body_A, const Transform } void BulletPhysicsServer::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointBullet *generic_6dof_joint = static_cast(joint); @@ -1448,7 +1448,7 @@ void BulletPhysicsServer::generic_6dof_joint_set_param(RID p_joint, Vector3::Axi } float BulletPhysicsServer::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0); Generic6DOFJointBullet *generic_6dof_joint = static_cast(joint); @@ -1456,7 +1456,7 @@ float BulletPhysicsServer::generic_6dof_joint_get_param(RID p_joint, Vector3::Ax } void BulletPhysicsServer::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointBullet *generic_6dof_joint = static_cast(joint); @@ -1464,7 +1464,7 @@ void BulletPhysicsServer::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis } bool BulletPhysicsServer::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, false); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, false); Generic6DOFJointBullet *generic_6dof_joint = static_cast(joint); @@ -1472,7 +1472,7 @@ bool BulletPhysicsServer::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis } void BulletPhysicsServer::generic_6dof_joint_set_precision(RID p_joint, int p_precision) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointBullet *generic_6dof_joint = static_cast(joint); @@ -1480,7 +1480,7 @@ void BulletPhysicsServer::generic_6dof_joint_set_precision(RID p_joint, int p_pr } int BulletPhysicsServer::generic_6dof_joint_get_precision(RID p_joint) { - JointBullet *joint = joint_owner.get(p_joint); + JointBullet *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0); Generic6DOFJointBullet *generic_6dof_joint = static_cast(joint); @@ -1490,7 +1490,7 @@ int BulletPhysicsServer::generic_6dof_joint_get_precision(RID p_joint) { void BulletPhysicsServer::free(RID p_rid) { if (shape_owner.owns(p_rid)) { - ShapeBullet *shape = shape_owner.get(p_rid); + ShapeBullet *shape = shape_owner.getornull(p_rid); // Notify the shape is configured for (Map::Element *element = shape->get_owners().front(); element; element = element->next()) { @@ -1501,7 +1501,7 @@ void BulletPhysicsServer::free(RID p_rid) { bulletdelete(shape); } else if (rigid_body_owner.owns(p_rid)) { - RigidBodyBullet *body = rigid_body_owner.get(p_rid); + RigidBodyBullet *body = rigid_body_owner.getornull(p_rid); body->set_space(NULL); @@ -1512,7 +1512,7 @@ void BulletPhysicsServer::free(RID p_rid) { } else if (soft_body_owner.owns(p_rid)) { - SoftBodyBullet *body = soft_body_owner.get(p_rid); + SoftBodyBullet *body = soft_body_owner.getornull(p_rid); body->set_space(NULL); @@ -1521,7 +1521,7 @@ void BulletPhysicsServer::free(RID p_rid) { } else if (area_owner.owns(p_rid)) { - AreaBullet *area = area_owner.get(p_rid); + AreaBullet *area = area_owner.getornull(p_rid); area->set_space(NULL); @@ -1532,14 +1532,14 @@ void BulletPhysicsServer::free(RID p_rid) { } else if (joint_owner.owns(p_rid)) { - JointBullet *joint = joint_owner.get(p_rid); + JointBullet *joint = joint_owner.getornull(p_rid); joint->destroy_internal_constraint(); joint_owner.free(p_rid); bulletdelete(joint); } else if (space_owner.owns(p_rid)) { - SpaceBullet *space = space_owner.get(p_rid); + SpaceBullet *space = space_owner.getornull(p_rid); space->remove_all_collision_objects(); diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h index 4a3b4a2edc6c..22032d32e3bf 100644 --- a/modules/bullet/bullet_physics_server.h +++ b/modules/bullet/bullet_physics_server.h @@ -33,13 +33,13 @@ #include "area_bullet.h" #include "core/rid.h" +#include "core/rid_owner.h" #include "joint_bullet.h" #include "rigid_body_bullet.h" #include "servers/physics_server.h" #include "shape_bullet.h" #include "soft_body_bullet.h" #include "space_bullet.h" - /** @author AndreaCatania */ @@ -53,12 +53,12 @@ class BulletPhysicsServer : public PhysicsServer { char active_spaces_count; Vector active_spaces; - mutable RID_Owner space_owner; - mutable RID_Owner shape_owner; - mutable RID_Owner area_owner; - mutable RID_Owner rigid_body_owner; - mutable RID_Owner soft_body_owner; - mutable RID_Owner joint_owner; + mutable RID_PtrOwner space_owner; + mutable RID_PtrOwner shape_owner; + mutable RID_PtrOwner area_owner; + mutable RID_PtrOwner rigid_body_owner; + mutable RID_PtrOwner soft_body_owner; + mutable RID_PtrOwner joint_owner; protected: static void _bind_methods(); @@ -67,22 +67,22 @@ class BulletPhysicsServer : public PhysicsServer { BulletPhysicsServer(); ~BulletPhysicsServer(); - _FORCE_INLINE_ RID_Owner *get_space_owner() { + _FORCE_INLINE_ RID_PtrOwner *get_space_owner() { return &space_owner; } - _FORCE_INLINE_ RID_Owner *get_shape_owner() { + _FORCE_INLINE_ RID_PtrOwner *get_shape_owner() { return &shape_owner; } - _FORCE_INLINE_ RID_Owner *get_area_owner() { + _FORCE_INLINE_ RID_PtrOwner *get_area_owner() { return &area_owner; } - _FORCE_INLINE_ RID_Owner *get_rigid_body_owner() { + _FORCE_INLINE_ RID_PtrOwner *get_rigid_body_owner() { return &rigid_body_owner; } - _FORCE_INLINE_ RID_Owner *get_soft_body_owner() { + _FORCE_INLINE_ RID_PtrOwner *get_soft_body_owner() { return &soft_body_owner; } - _FORCE_INLINE_ RID_Owner *get_joint_owner() { + _FORCE_INLINE_ RID_PtrOwner *get_joint_owner() { return &joint_owner; } diff --git a/modules/bullet/rid_bullet.h b/modules/bullet/rid_bullet.h index 28bcedb01a08..d073e209cd9c 100644 --- a/modules/bullet/rid_bullet.h +++ b/modules/bullet/rid_bullet.h @@ -39,7 +39,7 @@ class BulletPhysicsServer; -class RIDBullet : public RID_Data { +class RIDBullet { RID self; BulletPhysicsServer *physicsServer; diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index 762637ce75ed..dae1719aa9cf 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -122,7 +122,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra if (p_result_max <= 0) return 0; - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale_abs(), p_margin); if (!btShape->isConvex()) { @@ -152,7 +152,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra } bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &r_closest_safe, float &r_closest_unsafe, const Set &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, ShapeRestInfo *r_info) { - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale(), p_margin); if (!btShape->isConvex()) { @@ -207,7 +207,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & if (p_result_max <= 0) return 0; - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale_abs(), p_margin); if (!btShape->isConvex()) { @@ -239,7 +239,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); + ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale_abs(), p_margin); if (!btShape->isConvex()) { diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp index f3ffd93c9c52..06862300720a 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/gdnavigation/gd_navigation_server.cpp @@ -140,7 +140,7 @@ RID GdNavigationServer::map_create() const { } COMMAND_2(map_set_active, RID, p_map, bool, p_active) { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND(map == NULL); if (p_active) { @@ -153,56 +153,56 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) { } bool GdNavigationServer::map_is_active(RID p_map) const { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == NULL, false); return active_maps.find(map) >= 0; } COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND(map == NULL); map->set_up(p_up); } Vector3 GdNavigationServer::map_get_up(RID p_map) const { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == NULL, Vector3()); return map->get_up(); } COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size) { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND(map == NULL); map->set_cell_size(p_cell_size); } real_t GdNavigationServer::map_get_cell_size(RID p_map) const { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == NULL, 0); return map->get_cell_size(); } COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margin) { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND(map == NULL); map->set_edge_connection_margin(p_connection_margin); } real_t GdNavigationServer::map_get_edge_connection_margin(RID p_map) const { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == NULL, 0); return map->get_edge_connection_margin(); } Vector GdNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == NULL, Vector()); return map->get_path(p_origin, p_destination, p_optimize); @@ -219,7 +219,7 @@ RID GdNavigationServer::region_create() const { } COMMAND_2(region_set_map, RID, p_region, RID, p_map) { - NavRegion *region = region_owner.get(p_region); + NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND(region == NULL); if (region->get_map() != NULL) { @@ -232,7 +232,7 @@ COMMAND_2(region_set_map, RID, p_region, RID, p_map) { } if (p_map.is_valid()) { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND(map == NULL); map->add_region(region); @@ -241,14 +241,14 @@ COMMAND_2(region_set_map, RID, p_region, RID, p_map) { } COMMAND_2(region_set_transform, RID, p_region, Transform, p_transform) { - NavRegion *region = region_owner.get(p_region); + NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND(region == NULL); region->set_transform(p_transform); } COMMAND_2(region_set_navmesh, RID, p_region, Ref, p_nav_mesh) { - NavRegion *region = region_owner.get(p_region); + NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND(region == NULL); region->set_mesh(p_nav_mesh); @@ -275,7 +275,7 @@ RID GdNavigationServer::agent_create() const { } COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); if (agent->get_map()) { @@ -288,7 +288,7 @@ COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) { agent->set_map(NULL); if (p_map.is_valid()) { - NavMap *map = map_owner.get(p_map); + NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND(map == NULL); agent->set_map(map); @@ -301,77 +301,77 @@ COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) { } COMMAND_2(agent_set_neighbor_dist, RID, p_agent, real_t, p_dist) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->get_agent()->neighborDist_ = p_dist; } COMMAND_2(agent_set_max_neighbors, RID, p_agent, int, p_count) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->get_agent()->maxNeighbors_ = p_count; } COMMAND_2(agent_set_time_horizon, RID, p_agent, real_t, p_time) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->get_agent()->timeHorizon_ = p_time; } COMMAND_2(agent_set_radius, RID, p_agent, real_t, p_radius) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->get_agent()->radius_ = p_radius; } COMMAND_2(agent_set_max_speed, RID, p_agent, real_t, p_max_speed) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->get_agent()->maxSpeed_ = p_max_speed; } COMMAND_2(agent_set_velocity, RID, p_agent, Vector3, p_velocity) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->get_agent()->velocity_ = RVO::Vector3(p_velocity.x, p_velocity.y, p_velocity.z); } COMMAND_2(agent_set_target_velocity, RID, p_agent, Vector3, p_velocity) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->get_agent()->prefVelocity_ = RVO::Vector3(p_velocity.x, p_velocity.y, p_velocity.z); } COMMAND_2(agent_set_position, RID, p_agent, Vector3, p_position) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->get_agent()->position_ = RVO::Vector3(p_position.x, p_position.y, p_position.z); } COMMAND_2(agent_set_ignore_y, RID, p_agent, bool, p_ignore) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->get_agent()->ignore_y_ = p_ignore; } bool GdNavigationServer::agent_is_map_changed(RID p_agent) const { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND_V(agent == NULL, false); return agent->is_map_changed(); } COMMAND_4(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_method, Variant, p_udata) { - RvoAgent *agent = agent_owner.get(p_agent); + RvoAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == NULL); agent->set_callback(p_receiver == NULL ? 0 : p_receiver->get_instance_id(), p_method, p_udata); @@ -387,7 +387,7 @@ COMMAND_4(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_ COMMAND_1(free, RID, p_object) { if (map_owner.owns(p_object)) { - NavMap *map = map_owner.get(p_object); + NavMap *map = map_owner.getornull(p_object); // Removes any assigned region std::vector regions = map->get_regions(); @@ -408,7 +408,7 @@ COMMAND_1(free, RID, p_object) { memdelete(map); } else if (region_owner.owns(p_object)) { - NavRegion *region = region_owner.get(p_object); + NavRegion *region = region_owner.getornull(p_object); // Removes this region from the map if assigned if (region->get_map() != NULL) { @@ -420,7 +420,7 @@ COMMAND_1(free, RID, p_object) { memdelete(region); } else if (agent_owner.owns(p_object)) { - RvoAgent *agent = agent_owner.get(p_object); + RvoAgent *agent = agent_owner.getornull(p_object); // Removes this agent from the map if assigned if (agent->get_map() != NULL) { diff --git a/modules/gdnavigation/gd_navigation_server.h b/modules/gdnavigation/gd_navigation_server.h index 80ba06880c31..b0fcdaf8342d 100644 --- a/modules/gdnavigation/gd_navigation_server.h +++ b/modules/gdnavigation/gd_navigation_server.h @@ -31,6 +31,8 @@ #ifndef GD_NAVIGATION_SERVER_H #define GD_NAVIGATION_SERVER_H +#include "core/rid.h" +#include "core/rid_owner.h" #include "servers/navigation_server.h" #include "nav_map.h" @@ -73,9 +75,9 @@ class GdNavigationServer : public NavigationServer { std::vector commands; - mutable RID_Owner map_owner; - mutable RID_Owner region_owner; - mutable RID_Owner agent_owner; + mutable RID_PtrOwner map_owner; + mutable RID_PtrOwner region_owner; + mutable RID_PtrOwner agent_owner; bool active; Vector active_maps; diff --git a/modules/gdnavigation/nav_rid.h b/modules/gdnavigation/nav_rid.h index 96e22800c267..b7cee7423703 100644 --- a/modules/gdnavigation/nav_rid.h +++ b/modules/gdnavigation/nav_rid.h @@ -37,7 +37,7 @@ @author AndreaCatania */ -class NavRid : public RID_Data { +class NavRid { RID self; public: diff --git a/scene/animation/skeleton_ik.h b/scene/animation/skeleton_ik.h index 9ae010dc4e4e..f14ade2bd498 100644 --- a/scene/animation/skeleton_ik.h +++ b/scene/animation/skeleton_ik.h @@ -98,7 +98,7 @@ class FabrikInverseKinematic { }; public: - struct Task : public RID_Data { + struct Task { RID self; Skeleton *skeleton; diff --git a/servers/physics/constraint_sw.h b/servers/physics/constraint_sw.h index a28aa7461871..20fb8d862d56 100644 --- a/servers/physics/constraint_sw.h +++ b/servers/physics/constraint_sw.h @@ -33,7 +33,7 @@ #include "body_sw.h" -class ConstraintSW : public RID_Data { +class ConstraintSW { BodySW **_body_ptr; int _body_count; diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 7c950829ca46..cd6fc6c0a58c 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -99,28 +99,28 @@ RID PhysicsServerSW::shape_create(ShapeType p_shape) { void PhysicsServerSW::shape_set_data(RID p_shape, const Variant &p_data) { - ShapeSW *shape = shape_owner.get(p_shape); + ShapeSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); shape->set_data(p_data); }; void PhysicsServerSW::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) { - ShapeSW *shape = shape_owner.get(p_shape); + ShapeSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); shape->set_custom_bias(p_bias); } PhysicsServer::ShapeType PhysicsServerSW::shape_get_type(RID p_shape) const { - const ShapeSW *shape = shape_owner.get(p_shape); + const ShapeSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, SHAPE_CUSTOM); return shape->get_type(); }; Variant PhysicsServerSW::shape_get_data(RID p_shape) const { - const ShapeSW *shape = shape_owner.get(p_shape); + const ShapeSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, Variant()); ERR_FAIL_COND_V(!shape->is_configured(), Variant()); return shape->get_data(); @@ -135,7 +135,7 @@ real_t PhysicsServerSW::shape_get_margin(RID p_shape) const { real_t PhysicsServerSW::shape_get_custom_solver_bias(RID p_shape) const { - const ShapeSW *shape = shape_owner.get(p_shape); + const ShapeSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0); return shape->get_custom_bias(); } @@ -146,7 +146,7 @@ RID PhysicsServerSW::space_create() { RID id = space_owner.make_rid(space); space->set_self(id); RID area_id = area_create(); - AreaSW *area = area_owner.get(area_id); + AreaSW *area = area_owner.getornull(area_id); ERR_FAIL_COND_V(!area, RID()); space->set_default_area(area); area->set_space(space); @@ -161,7 +161,7 @@ RID PhysicsServerSW::space_create() { void PhysicsServerSW::space_set_active(RID p_space, bool p_active) { - SpaceSW *space = space_owner.get(p_space); + SpaceSW *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); if (p_active) active_spaces.insert(space); @@ -171,7 +171,7 @@ void PhysicsServerSW::space_set_active(RID p_space, bool p_active) { bool PhysicsServerSW::space_is_active(RID p_space) const { - const SpaceSW *space = space_owner.get(p_space); + const SpaceSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, false); return active_spaces.has(space); @@ -179,7 +179,7 @@ bool PhysicsServerSW::space_is_active(RID p_space) const { void PhysicsServerSW::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) { - SpaceSW *space = space_owner.get(p_space); + SpaceSW *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); space->set_param(p_param, p_value); @@ -187,14 +187,14 @@ void PhysicsServerSW::space_set_param(RID p_space, SpaceParameter p_param, real_ real_t PhysicsServerSW::space_get_param(RID p_space, SpaceParameter p_param) const { - const SpaceSW *space = space_owner.get(p_space); + const SpaceSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_param(p_param); } PhysicsDirectSpaceState *PhysicsServerSW::space_get_direct_state(RID p_space) { - SpaceSW *space = space_owner.get(p_space); + SpaceSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, NULL); ERR_FAIL_COND_V_MSG(!doing_sync || space->is_locked(), NULL, "Space state is inaccessible right now, wait for iteration or physics process notification."); @@ -203,21 +203,21 @@ PhysicsDirectSpaceState *PhysicsServerSW::space_get_direct_state(RID p_space) { void PhysicsServerSW::space_set_debug_contacts(RID p_space, int p_max_contacts) { - SpaceSW *space = space_owner.get(p_space); + SpaceSW *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); space->set_debug_contacts(p_max_contacts); } Vector PhysicsServerSW::space_get_contacts(RID p_space) const { - SpaceSW *space = space_owner.get(p_space); + SpaceSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, Vector()); return space->get_debug_contacts(); } int PhysicsServerSW::space_get_contact_count(RID p_space) const { - SpaceSW *space = space_owner.get(p_space); + SpaceSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_debug_contact_count(); } @@ -232,12 +232,12 @@ RID PhysicsServerSW::area_create() { void PhysicsServerSW::area_set_space(RID p_area, RID p_space) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); SpaceSW *space = NULL; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } @@ -250,7 +250,7 @@ void PhysicsServerSW::area_set_space(RID p_area, RID p_space) { RID PhysicsServerSW::area_get_space(RID p_area) const { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, RID()); SpaceSW *space = area->get_space(); @@ -261,7 +261,7 @@ RID PhysicsServerSW::area_get_space(RID p_area) const { void PhysicsServerSW::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_space_override_mode(p_mode); @@ -269,7 +269,7 @@ void PhysicsServerSW::area_set_space_override_mode(RID p_area, AreaSpaceOverride PhysicsServer::AreaSpaceOverrideMode PhysicsServerSW::area_get_space_override_mode(RID p_area) const { - const AreaSW *area = area_owner.get(p_area); + const AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, AREA_SPACE_OVERRIDE_DISABLED); return area->get_space_override_mode(); @@ -277,10 +277,10 @@ PhysicsServer::AreaSpaceOverrideMode PhysicsServerSW::area_get_space_override_mo void PhysicsServerSW::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform, bool p_disabled) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - ShapeSW *shape = shape_owner.get(p_shape); + ShapeSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); area->add_shape(shape, p_transform, p_disabled); @@ -288,10 +288,10 @@ void PhysicsServerSW::area_add_shape(RID p_area, RID p_shape, const Transform &p void PhysicsServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - ShapeSW *shape = shape_owner.get(p_shape); + ShapeSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); ERR_FAIL_COND(!shape->is_configured()); @@ -300,7 +300,7 @@ void PhysicsServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) { void PhysicsServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_shape_transform(p_shape_idx, p_transform); @@ -308,14 +308,14 @@ void PhysicsServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, cons int PhysicsServerSW::area_get_shape_count(RID p_area) const { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, -1); return area->get_shape_count(); } RID PhysicsServerSW::area_get_shape(RID p_area, int p_shape_idx) const { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, RID()); ShapeSW *shape = area->get_shape(p_shape_idx); @@ -325,7 +325,7 @@ RID PhysicsServerSW::area_get_shape(RID p_area, int p_shape_idx) const { } Transform PhysicsServerSW::area_get_shape_transform(RID p_area, int p_shape_idx) const { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Transform()); return area->get_shape_transform(p_shape_idx); @@ -333,7 +333,7 @@ Transform PhysicsServerSW::area_get_shape_transform(RID p_area, int p_shape_idx) void PhysicsServerSW::area_remove_shape(RID p_area, int p_shape_idx) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->remove_shape(p_shape_idx); @@ -341,7 +341,7 @@ void PhysicsServerSW::area_remove_shape(RID p_area, int p_shape_idx) { void PhysicsServerSW::area_clear_shapes(RID p_area) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); while (area->get_shape_count()) @@ -350,7 +350,7 @@ void PhysicsServerSW::area_clear_shapes(RID p_area) { void PhysicsServerSW::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); ERR_FAIL_INDEX(p_shape_idx, area->get_shape_count()); FLUSH_QUERY_CHECK(area); @@ -360,20 +360,20 @@ void PhysicsServerSW::area_set_shape_disabled(RID p_area, int p_shape_idx, bool void PhysicsServerSW::area_attach_object_instance_id(RID p_area, ObjectID p_id) { if (space_owner.owns(p_area)) { - SpaceSW *space = space_owner.get(p_area); + SpaceSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_instance_id(p_id); } ObjectID PhysicsServerSW::area_get_object_instance_id(RID p_area) const { if (space_owner.owns(p_area)) { - SpaceSW *space = space_owner.get(p_area); + SpaceSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, 0); return area->get_instance_id(); } @@ -381,17 +381,17 @@ ObjectID PhysicsServerSW::area_get_object_instance_id(RID p_area) const { void PhysicsServerSW::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) { if (space_owner.owns(p_area)) { - SpaceSW *space = space_owner.get(p_area); + SpaceSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_param(p_param, p_value); }; void PhysicsServerSW::area_set_transform(RID p_area, const Transform &p_transform) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_transform(p_transform); }; @@ -399,10 +399,10 @@ void PhysicsServerSW::area_set_transform(RID p_area, const Transform &p_transfor Variant PhysicsServerSW::area_get_param(RID p_area, AreaParameter p_param) const { if (space_owner.owns(p_area)) { - SpaceSW *space = space_owner.get(p_area); + SpaceSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Variant()); return area->get_param(p_param); @@ -410,7 +410,7 @@ Variant PhysicsServerSW::area_get_param(RID p_area, AreaParameter p_param) const Transform PhysicsServerSW::area_get_transform(RID p_area) const { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Transform()); return area->get_transform(); @@ -418,7 +418,7 @@ Transform PhysicsServerSW::area_get_transform(RID p_area) const { void PhysicsServerSW::area_set_collision_layer(RID p_area, uint32_t p_layer) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_collision_layer(p_layer); @@ -426,7 +426,7 @@ void PhysicsServerSW::area_set_collision_layer(RID p_area, uint32_t p_layer) { void PhysicsServerSW::area_set_collision_mask(RID p_area, uint32_t p_mask) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_collision_mask(p_mask); @@ -434,7 +434,7 @@ void PhysicsServerSW::area_set_collision_mask(RID p_area, uint32_t p_mask) { void PhysicsServerSW::area_set_monitorable(RID p_area, bool p_monitorable) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); FLUSH_QUERY_CHECK(area); @@ -443,7 +443,7 @@ void PhysicsServerSW::area_set_monitorable(RID p_area, bool p_monitorable) { void PhysicsServerSW::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_monitor_callback(p_receiver ? p_receiver->get_instance_id() : 0, p_method); @@ -451,7 +451,7 @@ void PhysicsServerSW::area_set_monitor_callback(RID p_area, Object *p_receiver, void PhysicsServerSW::area_set_ray_pickable(RID p_area, bool p_enable) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_ray_pickable(p_enable); @@ -459,7 +459,7 @@ void PhysicsServerSW::area_set_ray_pickable(RID p_area, bool p_enable) { bool PhysicsServerSW::area_is_ray_pickable(RID p_area) const { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, false); return area->is_ray_pickable(); @@ -467,7 +467,7 @@ bool PhysicsServerSW::area_is_ray_pickable(RID p_area) const { void PhysicsServerSW::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - AreaSW *area = area_owner.get(p_area); + AreaSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_area_monitor_callback(p_receiver ? p_receiver->get_instance_id() : 0, p_method); @@ -489,12 +489,12 @@ RID PhysicsServerSW::body_create(BodyMode p_mode, bool p_init_sleeping) { void PhysicsServerSW::body_set_space(RID p_body, RID p_space) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); SpaceSW *space = NULL; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } @@ -507,7 +507,7 @@ void PhysicsServerSW::body_set_space(RID p_body, RID p_space) { RID PhysicsServerSW::body_get_space(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); SpaceSW *space = body->get_space(); @@ -518,7 +518,7 @@ RID PhysicsServerSW::body_get_space(RID p_body) const { void PhysicsServerSW::body_set_mode(RID p_body, BodyMode p_mode) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_mode(p_mode); @@ -526,7 +526,7 @@ void PhysicsServerSW::body_set_mode(RID p_body, BodyMode p_mode) { PhysicsServer::BodyMode PhysicsServerSW::body_get_mode(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, BODY_MODE_STATIC); return body->get_mode(); @@ -534,10 +534,10 @@ PhysicsServer::BodyMode PhysicsServerSW::body_get_mode(RID p_body) const { void PhysicsServerSW::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform, bool p_disabled) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); - ShapeSW *shape = shape_owner.get(p_shape); + ShapeSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); body->add_shape(shape, p_transform, p_disabled); @@ -545,10 +545,10 @@ void PhysicsServerSW::body_add_shape(RID p_body, RID p_shape, const Transform &p void PhysicsServerSW::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); - ShapeSW *shape = shape_owner.get(p_shape); + ShapeSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); ERR_FAIL_COND(!shape->is_configured()); @@ -556,7 +556,7 @@ void PhysicsServerSW::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) { } void PhysicsServerSW::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_shape_transform(p_shape_idx, p_transform); @@ -564,14 +564,14 @@ void PhysicsServerSW::body_set_shape_transform(RID p_body, int p_shape_idx, cons int PhysicsServerSW::body_get_shape_count(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, -1); return body->get_shape_count(); } RID PhysicsServerSW::body_get_shape(RID p_body, int p_shape_idx) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); ShapeSW *shape = body->get_shape(p_shape_idx); @@ -582,7 +582,7 @@ RID PhysicsServerSW::body_get_shape(RID p_body, int p_shape_idx) const { void PhysicsServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); FLUSH_QUERY_CHECK(body); @@ -592,7 +592,7 @@ void PhysicsServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, bool Transform PhysicsServerSW::body_get_shape_transform(RID p_body, int p_shape_idx) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Transform()); return body->get_shape_transform(p_shape_idx); @@ -600,7 +600,7 @@ Transform PhysicsServerSW::body_get_shape_transform(RID p_body, int p_shape_idx) void PhysicsServerSW::body_remove_shape(RID p_body, int p_shape_idx) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->remove_shape(p_shape_idx); @@ -608,7 +608,7 @@ void PhysicsServerSW::body_remove_shape(RID p_body, int p_shape_idx) { void PhysicsServerSW::body_clear_shapes(RID p_body) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); while (body->get_shape_count()) @@ -617,7 +617,7 @@ void PhysicsServerSW::body_clear_shapes(RID p_body) { void PhysicsServerSW::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_continuous_collision_detection(p_enable); @@ -625,7 +625,7 @@ void PhysicsServerSW::body_set_enable_continuous_collision_detection(RID p_body, bool PhysicsServerSW::body_is_continuous_collision_detection_enabled(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->is_continuous_collision_detection_enabled(); @@ -633,7 +633,7 @@ bool PhysicsServerSW::body_is_continuous_collision_detection_enabled(RID p_body) void PhysicsServerSW::body_set_collision_layer(RID p_body, uint32_t p_layer) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_layer(p_layer); @@ -642,7 +642,7 @@ void PhysicsServerSW::body_set_collision_layer(RID p_body, uint32_t p_layer) { uint32_t PhysicsServerSW::body_get_collision_layer(RID p_body) const { - const BodySW *body = body_owner.get(p_body); + const BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_layer(); @@ -650,7 +650,7 @@ uint32_t PhysicsServerSW::body_get_collision_layer(RID p_body) const { void PhysicsServerSW::body_set_collision_mask(RID p_body, uint32_t p_mask) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_mask(p_mask); @@ -659,7 +659,7 @@ void PhysicsServerSW::body_set_collision_mask(RID p_body, uint32_t p_mask) { uint32_t PhysicsServerSW::body_get_collision_mask(RID p_body) const { - const BodySW *body = body_owner.get(p_body); + const BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_mask(); @@ -667,7 +667,7 @@ uint32_t PhysicsServerSW::body_get_collision_mask(RID p_body) const { void PhysicsServerSW::body_attach_object_instance_id(RID p_body, uint32_t p_id) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_instance_id(p_id); @@ -675,7 +675,7 @@ void PhysicsServerSW::body_attach_object_instance_id(RID p_body, uint32_t p_id) uint32_t PhysicsServerSW::body_get_object_instance_id(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_instance_id(); @@ -683,13 +683,13 @@ uint32_t PhysicsServerSW::body_get_object_instance_id(RID p_body) const { void PhysicsServerSW::body_set_user_flags(RID p_body, uint32_t p_flags) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); }; uint32_t PhysicsServerSW::body_get_user_flags(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return 0; @@ -697,7 +697,7 @@ uint32_t PhysicsServerSW::body_get_user_flags(RID p_body) const { void PhysicsServerSW::body_set_param(RID p_body, BodyParameter p_param, real_t p_value) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_param(p_param, p_value); @@ -705,20 +705,20 @@ void PhysicsServerSW::body_set_param(RID p_body, BodyParameter p_param, real_t p real_t PhysicsServerSW::body_get_param(RID p_body, BodyParameter p_param) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_param(p_param); }; void PhysicsServerSW::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_kinematic_margin(p_margin); } real_t PhysicsServerSW::body_get_kinematic_safe_margin(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_kinematic_margin(); @@ -726,7 +726,7 @@ real_t PhysicsServerSW::body_get_kinematic_safe_margin(RID p_body) const { void PhysicsServerSW::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_state(p_state, p_variant); @@ -734,7 +734,7 @@ void PhysicsServerSW::body_set_state(RID p_body, BodyState p_state, const Varian Variant PhysicsServerSW::body_get_state(RID p_body, BodyState p_state) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Variant()); return body->get_state(p_state); @@ -742,7 +742,7 @@ Variant PhysicsServerSW::body_get_state(RID p_body, BodyState p_state) const { void PhysicsServerSW::body_set_applied_force(RID p_body, const Vector3 &p_force) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_applied_force(p_force); @@ -751,14 +751,14 @@ void PhysicsServerSW::body_set_applied_force(RID p_body, const Vector3 &p_force) Vector3 PhysicsServerSW::body_get_applied_force(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3()); return body->get_applied_force(); }; void PhysicsServerSW::body_set_applied_torque(RID p_body, const Vector3 &p_torque) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_applied_torque(p_torque); @@ -767,14 +767,14 @@ void PhysicsServerSW::body_set_applied_torque(RID p_body, const Vector3 &p_torqu Vector3 PhysicsServerSW::body_get_applied_torque(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector3()); return body->get_applied_torque(); }; void PhysicsServerSW::body_add_central_force(RID p_body, const Vector3 &p_force) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->add_central_force(p_force); @@ -782,7 +782,7 @@ void PhysicsServerSW::body_add_central_force(RID p_body, const Vector3 &p_force) } void PhysicsServerSW::body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_pos) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->add_force(p_force, p_pos); @@ -790,7 +790,7 @@ void PhysicsServerSW::body_add_force(RID p_body, const Vector3 &p_force, const V }; void PhysicsServerSW::body_add_torque(RID p_body, const Vector3 &p_torque) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->add_torque(p_torque); @@ -798,7 +798,7 @@ void PhysicsServerSW::body_add_torque(RID p_body, const Vector3 &p_torque) { }; void PhysicsServerSW::body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); _update_shapes(); @@ -809,7 +809,7 @@ void PhysicsServerSW::body_apply_central_impulse(RID p_body, const Vector3 &p_im void PhysicsServerSW::body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); _update_shapes(); @@ -820,7 +820,7 @@ void PhysicsServerSW::body_apply_impulse(RID p_body, const Vector3 &p_pos, const void PhysicsServerSW::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); _update_shapes(); @@ -831,7 +831,7 @@ void PhysicsServerSW::body_apply_torque_impulse(RID p_body, const Vector3 &p_imp void PhysicsServerSW::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); _update_shapes(); @@ -846,7 +846,7 @@ void PhysicsServerSW::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_v void PhysicsServerSW::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_axis_lock(p_axis, p_lock); @@ -855,14 +855,14 @@ void PhysicsServerSW::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_loc bool PhysicsServerSW::body_is_axis_locked(RID p_body, BodyAxis p_axis) const { - const BodySW *body = body_owner.get(p_body); + const BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->is_axis_locked(p_axis); } void PhysicsServerSW::body_add_collision_exception(RID p_body, RID p_body_b) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->add_exception(p_body_b); @@ -871,7 +871,7 @@ void PhysicsServerSW::body_add_collision_exception(RID p_body, RID p_body_b) { void PhysicsServerSW::body_remove_collision_exception(RID p_body, RID p_body_b) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->remove_exception(p_body_b); @@ -880,7 +880,7 @@ void PhysicsServerSW::body_remove_collision_exception(RID p_body, RID p_body_b) void PhysicsServerSW::body_get_collision_exceptions(RID p_body, List *p_exceptions) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); for (int i = 0; i < body->get_exceptions().size(); i++) { @@ -890,20 +890,20 @@ void PhysicsServerSW::body_get_collision_exceptions(RID p_body, List *p_exc void PhysicsServerSW::body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); }; real_t PhysicsServerSW::body_get_contacts_reported_depth_threshold(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return 0; }; void PhysicsServerSW::body_set_omit_force_integration(RID p_body, bool p_omit) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_omit_force_integration(p_omit); @@ -911,49 +911,49 @@ void PhysicsServerSW::body_set_omit_force_integration(RID p_body, bool p_omit) { bool PhysicsServerSW::body_is_omitting_force_integration(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->get_omit_force_integration(); }; void PhysicsServerSW::body_set_max_contacts_reported(RID p_body, int p_contacts) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_max_contacts_reported(p_contacts); } int PhysicsServerSW::body_get_max_contacts_reported(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, -1); return body->get_max_contacts_reported(); } void PhysicsServerSW::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(0), p_method, p_udata); } void PhysicsServerSW::body_set_ray_pickable(RID p_body, bool p_enable) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_ray_pickable(p_enable); } bool PhysicsServerSW::body_is_ray_pickable(RID p_body) const { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->is_ray_pickable(); } bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result, bool p_exclude_raycast_shapes) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); ERR_FAIL_COND_V(body->get_space()->is_locked(), false); @@ -965,7 +965,7 @@ bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, cons int PhysicsServerSW::body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); ERR_FAIL_COND_V(body->get_space()->is_locked(), false); @@ -977,7 +977,7 @@ int PhysicsServerSW::body_test_ray_separation(RID p_body, const Transform &p_tra PhysicsDirectBodyState *PhysicsServerSW::body_get_direct_state(RID p_body) { - BodySW *body = body_owner.get(p_body); + BodySW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, NULL); ERR_FAIL_COND_V_MSG(!doing_sync || body->get_space()->is_locked(), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification."); @@ -989,7 +989,7 @@ PhysicsDirectBodyState *PhysicsServerSW::body_get_direct_state(RID p_body) { RID PhysicsServerSW::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) { - BodySW *body_A = body_owner.get(p_body_A); + BodySW *body_A = body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); if (!p_body_B.is_valid()) { @@ -997,7 +997,7 @@ RID PhysicsServerSW::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RI p_body_B = body_A->get_space()->get_static_global_body(); } - BodySW *body_B = body_owner.get(p_body_B); + BodySW *body_B = body_owner.getornull(p_body_B); ERR_FAIL_COND_V(!body_B, RID()); ERR_FAIL_COND_V(body_A == body_B, RID()); @@ -1010,7 +1010,7 @@ RID PhysicsServerSW::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RI void PhysicsServerSW::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointSW *pin_joint = static_cast(joint); @@ -1018,7 +1018,7 @@ void PhysicsServerSW::pin_joint_set_param(RID p_joint, PinJointParam p_param, re } real_t PhysicsServerSW::pin_joint_get_param(RID p_joint, PinJointParam p_param) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, 0); PinJointSW *pin_joint = static_cast(joint); @@ -1027,7 +1027,7 @@ real_t PhysicsServerSW::pin_joint_get_param(RID p_joint, PinJointParam p_param) void PhysicsServerSW::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointSW *pin_joint = static_cast(joint); @@ -1035,7 +1035,7 @@ void PhysicsServerSW::pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) { } Vector3 PhysicsServerSW::pin_joint_get_local_a(RID p_joint) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointSW *pin_joint = static_cast(joint); @@ -1044,7 +1044,7 @@ Vector3 PhysicsServerSW::pin_joint_get_local_a(RID p_joint) const { void PhysicsServerSW::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_PIN); PinJointSW *pin_joint = static_cast(joint); @@ -1052,7 +1052,7 @@ void PhysicsServerSW::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) { } Vector3 PhysicsServerSW::pin_joint_get_local_b(RID p_joint) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointSW *pin_joint = static_cast(joint); @@ -1061,7 +1061,7 @@ Vector3 PhysicsServerSW::pin_joint_get_local_b(RID p_joint) const { RID PhysicsServerSW::joint_create_hinge(RID p_body_A, const Transform &p_frame_A, RID p_body_B, const Transform &p_frame_B) { - BodySW *body_A = body_owner.get(p_body_A); + BodySW *body_A = body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); if (!p_body_B.is_valid()) { @@ -1069,7 +1069,7 @@ RID PhysicsServerSW::joint_create_hinge(RID p_body_A, const Transform &p_frame_A p_body_B = body_A->get_space()->get_static_global_body(); } - BodySW *body_B = body_owner.get(p_body_B); + BodySW *body_B = body_owner.getornull(p_body_B); ERR_FAIL_COND_V(!body_B, RID()); ERR_FAIL_COND_V(body_A == body_B, RID()); @@ -1082,7 +1082,7 @@ RID PhysicsServerSW::joint_create_hinge(RID p_body_A, const Transform &p_frame_A RID PhysicsServerSW::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) { - BodySW *body_A = body_owner.get(p_body_A); + BodySW *body_A = body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); if (!p_body_B.is_valid()) { @@ -1090,7 +1090,7 @@ RID PhysicsServerSW::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pi p_body_B = body_A->get_space()->get_static_global_body(); } - BodySW *body_B = body_owner.get(p_body_B); + BodySW *body_B = body_owner.getornull(p_body_B); ERR_FAIL_COND_V(!body_B, RID()); ERR_FAIL_COND_V(body_A == body_B, RID()); @@ -1103,7 +1103,7 @@ RID PhysicsServerSW::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pi void PhysicsServerSW::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_HINGE); HingeJointSW *hinge_joint = static_cast(joint); @@ -1111,7 +1111,7 @@ void PhysicsServerSW::hinge_joint_set_param(RID p_joint, HingeJointParam p_param } real_t PhysicsServerSW::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, 0); HingeJointSW *hinge_joint = static_cast(joint); @@ -1120,7 +1120,7 @@ real_t PhysicsServerSW::hinge_joint_get_param(RID p_joint, HingeJointParam p_par void PhysicsServerSW::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_HINGE); HingeJointSW *hinge_joint = static_cast(joint); @@ -1128,7 +1128,7 @@ void PhysicsServerSW::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, b } bool PhysicsServerSW::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, false); ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, false); HingeJointSW *hinge_joint = static_cast(joint); @@ -1137,20 +1137,20 @@ bool PhysicsServerSW::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) c void PhysicsServerSW::joint_set_solver_priority(RID p_joint, int p_priority) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); joint->set_priority(p_priority); } int PhysicsServerSW::joint_get_solver_priority(RID p_joint) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); return joint->get_priority(); } void PhysicsServerSW::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); joint->disable_collisions_between_bodies(p_disable); @@ -1170,7 +1170,7 @@ void PhysicsServerSW::joint_disable_collisions_between_bodies(RID p_joint, const } bool PhysicsServerSW::joint_is_disabled_collisions_between_bodies(RID p_joint) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, true); return joint->is_disabled_collisions_between_bodies(); @@ -1178,14 +1178,14 @@ bool PhysicsServerSW::joint_is_disabled_collisions_between_bodies(RID p_joint) c PhysicsServerSW::JointType PhysicsServerSW::joint_get_type(RID p_joint) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, JOINT_PIN); return joint->get_type(); } RID PhysicsServerSW::joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { - BodySW *body_A = body_owner.get(p_body_A); + BodySW *body_A = body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); if (!p_body_B.is_valid()) { @@ -1193,7 +1193,7 @@ RID PhysicsServerSW::joint_create_slider(RID p_body_A, const Transform &p_local_ p_body_B = body_A->get_space()->get_static_global_body(); } - BodySW *body_B = body_owner.get(p_body_B); + BodySW *body_B = body_owner.getornull(p_body_B); ERR_FAIL_COND_V(!body_B, RID()); ERR_FAIL_COND_V(body_A == body_B, RID()); @@ -1206,7 +1206,7 @@ RID PhysicsServerSW::joint_create_slider(RID p_body_A, const Transform &p_local_ void PhysicsServerSW::slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_SLIDER); SliderJointSW *slider_joint = static_cast(joint); @@ -1214,7 +1214,7 @@ void PhysicsServerSW::slider_joint_set_param(RID p_joint, SliderJointParam p_par } real_t PhysicsServerSW::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0); SliderJointSW *slider_joint = static_cast(joint); @@ -1223,7 +1223,7 @@ real_t PhysicsServerSW::slider_joint_get_param(RID p_joint, SliderJointParam p_p RID PhysicsServerSW::joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { - BodySW *body_A = body_owner.get(p_body_A); + BodySW *body_A = body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); if (!p_body_B.is_valid()) { @@ -1231,7 +1231,7 @@ RID PhysicsServerSW::joint_create_cone_twist(RID p_body_A, const Transform &p_lo p_body_B = body_A->get_space()->get_static_global_body(); } - BodySW *body_B = body_owner.get(p_body_B); + BodySW *body_B = body_owner.getornull(p_body_B); ERR_FAIL_COND_V(!body_B, RID()); ERR_FAIL_COND_V(body_A == body_B, RID()); @@ -1244,7 +1244,7 @@ RID PhysicsServerSW::joint_create_cone_twist(RID p_body_A, const Transform &p_lo void PhysicsServerSW::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_CONE_TWIST); ConeTwistJointSW *cone_twist_joint = static_cast(joint); @@ -1252,7 +1252,7 @@ void PhysicsServerSW::cone_twist_joint_set_param(RID p_joint, ConeTwistJointPara } real_t PhysicsServerSW::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0); ConeTwistJointSW *cone_twist_joint = static_cast(joint); @@ -1261,7 +1261,7 @@ real_t PhysicsServerSW::cone_twist_joint_get_param(RID p_joint, ConeTwistJointPa RID PhysicsServerSW::joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) { - BodySW *body_A = body_owner.get(p_body_A); + BodySW *body_A = body_owner.getornull(p_body_A); ERR_FAIL_COND_V(!body_A, RID()); if (!p_body_B.is_valid()) { @@ -1269,7 +1269,7 @@ RID PhysicsServerSW::joint_create_generic_6dof(RID p_body_A, const Transform &p_ p_body_B = body_A->get_space()->get_static_global_body(); } - BodySW *body_B = body_owner.get(p_body_B); + BodySW *body_B = body_owner.getornull(p_body_B); ERR_FAIL_COND_V(!body_B, RID()); ERR_FAIL_COND_V(body_A == body_B, RID()); @@ -1282,7 +1282,7 @@ RID PhysicsServerSW::joint_create_generic_6dof(RID p_body_A, const Transform &p_ void PhysicsServerSW::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, real_t p_value) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointSW *generic_6dof_joint = static_cast(joint); @@ -1290,7 +1290,7 @@ void PhysicsServerSW::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_ } real_t PhysicsServerSW::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, 0); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0); Generic6DOFJointSW *generic_6dof_joint = static_cast(joint); @@ -1299,7 +1299,7 @@ real_t PhysicsServerSW::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis void PhysicsServerSW::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); ERR_FAIL_COND(joint->get_type() != JOINT_6DOF); Generic6DOFJointSW *generic_6dof_joint = static_cast(joint); @@ -1307,7 +1307,7 @@ void PhysicsServerSW::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_a } bool PhysicsServerSW::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) { - JointSW *joint = joint_owner.get(p_joint); + JointSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, false); ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, false); Generic6DOFJointSW *generic_6dof_joint = static_cast(joint); @@ -1320,7 +1320,7 @@ void PhysicsServerSW::free(RID p_rid) { if (shape_owner.owns(p_rid)) { - ShapeSW *shape = shape_owner.get(p_rid); + ShapeSW *shape = shape_owner.getornull(p_rid); while (shape->get_owners().size()) { ShapeOwnerSW *so = shape->get_owners().front()->key(); @@ -1331,7 +1331,7 @@ void PhysicsServerSW::free(RID p_rid) { memdelete(shape); } else if (body_owner.owns(p_rid)) { - BodySW *body = body_owner.get(p_rid); + BodySW *body = body_owner.getornull(p_rid); /* if (body->get_state_query()) @@ -1353,7 +1353,7 @@ void PhysicsServerSW::free(RID p_rid) { } else if (area_owner.owns(p_rid)) { - AreaSW *area = area_owner.get(p_rid); + AreaSW *area = area_owner.getornull(p_rid); /* if (area->get_monitor_query()) @@ -1371,7 +1371,7 @@ void PhysicsServerSW::free(RID p_rid) { memdelete(area); } else if (space_owner.owns(p_rid)) { - SpaceSW *space = space_owner.get(p_rid); + SpaceSW *space = space_owner.getornull(p_rid); while (space->get_objects().size()) { CollisionObjectSW *co = (CollisionObjectSW *)space->get_objects().front()->get(); @@ -1386,7 +1386,7 @@ void PhysicsServerSW::free(RID p_rid) { memdelete(space); } else if (joint_owner.owns(p_rid)) { - JointSW *joint = joint_owner.get(p_rid); + JointSW *joint = joint_owner.getornull(p_rid); for (int i = 0; i < joint->get_body_count(); i++) { diff --git a/servers/physics/physics_server_sw.h b/servers/physics/physics_server_sw.h index 0b7b9fb145b9..37ebfb09c04b 100644 --- a/servers/physics/physics_server_sw.h +++ b/servers/physics/physics_server_sw.h @@ -31,6 +31,7 @@ #ifndef PHYSICS_SERVER_SW #define PHYSICS_SERVER_SW +#include "core/rid_owner.h" #include "joints_sw.h" #include "servers/physics_server.h" #include "shape_sw.h" @@ -58,11 +59,11 @@ class PhysicsServerSW : public PhysicsServer { PhysicsDirectBodyStateSW *direct_state; - mutable RID_Owner shape_owner; - mutable RID_Owner space_owner; - mutable RID_Owner area_owner; - mutable RID_Owner body_owner; - mutable RID_Owner joint_owner; + mutable RID_PtrOwner shape_owner; + mutable RID_PtrOwner space_owner; + mutable RID_PtrOwner area_owner; + mutable RID_PtrOwner body_owner; + mutable RID_PtrOwner joint_owner; //void _clear_query(QuerySW *p_query); friend class CollisionObjectSW; diff --git a/servers/physics/shape_sw.h b/servers/physics/shape_sw.h index 202b61f18723..c9f38dd51cf6 100644 --- a/servers/physics/shape_sw.h +++ b/servers/physics/shape_sw.h @@ -48,7 +48,7 @@ SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_creat class ShapeSW; -class ShapeOwnerSW : public RID_Data { +class ShapeOwnerSW { public: virtual void _shape_changed() = 0; virtual void remove_shape(ShapeSW *p_shape) = 0; @@ -56,7 +56,7 @@ class ShapeOwnerSW : public RID_Data { virtual ~ShapeOwnerSW() {} }; -class ShapeSW : public RID_Data { +class ShapeSW { RID self; AABB aabb; diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index 222da7ed5847..49e1a57879d9 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -176,7 +176,7 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transfo if (p_result_max <= 0) return 0; - ShapeSW *shape = static_cast(PhysicsServer::get_singleton())->shape_owner.get(p_shape); + ShapeSW *shape = static_cast(PhysicsServer::get_singleton())->shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0); AABB aabb = p_xform.xform(shape->get_aabb()); @@ -224,7 +224,7 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Transfo bool PhysicsDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, ShapeRestInfo *r_info) { - ShapeSW *shape = static_cast(PhysicsServer::get_singleton())->shape_owner.get(p_shape); + ShapeSW *shape = static_cast(PhysicsServer::get_singleton())->shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, false); AABB aabb = p_xform.xform(shape->get_aabb()); @@ -333,7 +333,7 @@ bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform &p_sh if (p_result_max <= 0) return 0; - ShapeSW *shape = static_cast(PhysicsServer::get_singleton())->shape_owner.get(p_shape); + ShapeSW *shape = static_cast(PhysicsServer::get_singleton())->shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0); AABB aabb = p_shape_xform.xform(shape->get_aabb()); @@ -405,7 +405,7 @@ static void _rest_cbk_result(const Vector3 &p_point_A, const Vector3 &p_point_B, } bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform &p_shape_xform, real_t p_margin, ShapeRestInfo *r_info, const Set &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - ShapeSW *shape = static_cast(PhysicsServer::get_singleton())->shape_owner.get(p_shape); + ShapeSW *shape = static_cast(PhysicsServer::get_singleton())->shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0); AABB aabb = p_shape_xform.xform(shape->get_aabb()); diff --git a/servers/physics/space_sw.h b/servers/physics/space_sw.h index 09200f1f47b2..6db5c2224b79 100644 --- a/servers/physics/space_sw.h +++ b/servers/physics/space_sw.h @@ -59,7 +59,7 @@ class PhysicsDirectSpaceStateSW : public PhysicsDirectSpaceState { PhysicsDirectSpaceStateSW(); }; -class SpaceSW : public RID_Data { +class SpaceSW { public: enum ElapsedTime { diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index 225aab3a92db..b973fa75a925 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -721,7 +721,7 @@ Variant Physics2DDirectBodyStateSW::get_contact_collider_shape_metadata(int p_co return Variant(); } - Body2DSW *other = Physics2DServerSW::singletonsw->body_owner.get(body->contacts[p_contact_idx].collider); + Body2DSW *other = Physics2DServerSW::singletonsw->body_owner.getornull(body->contacts[p_contact_idx].collider); int sidx = body->contacts[p_contact_idx].collider_shape; if (sidx < 0 || sidx >= other->get_shape_count()) { diff --git a/servers/physics_2d/constraint_2d_sw.h b/servers/physics_2d/constraint_2d_sw.h index f3314f0ffc1c..6f99b3fb5d9f 100644 --- a/servers/physics_2d/constraint_2d_sw.h +++ b/servers/physics_2d/constraint_2d_sw.h @@ -33,7 +33,7 @@ #include "body_2d_sw.h" -class Constraint2DSW : public RID_Data { +class Constraint2DSW { Body2DSW **_body_ptr; int _body_count; diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index 809c5c40e06d..65873d9612ea 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -126,28 +126,28 @@ RID Physics2DServerSW::concave_polygon_shape_create() { void Physics2DServerSW::shape_set_data(RID p_shape, const Variant &p_data) { - Shape2DSW *shape = shape_owner.get(p_shape); + Shape2DSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); shape->set_data(p_data); }; void Physics2DServerSW::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) { - Shape2DSW *shape = shape_owner.get(p_shape); + Shape2DSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); shape->set_custom_bias(p_bias); } Physics2DServer::ShapeType Physics2DServerSW::shape_get_type(RID p_shape) const { - const Shape2DSW *shape = shape_owner.get(p_shape); + const Shape2DSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, SHAPE_CUSTOM); return shape->get_type(); }; Variant Physics2DServerSW::shape_get_data(RID p_shape) const { - const Shape2DSW *shape = shape_owner.get(p_shape); + const Shape2DSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, Variant()); ERR_FAIL_COND_V(!shape->is_configured(), Variant()); return shape->get_data(); @@ -155,7 +155,7 @@ Variant Physics2DServerSW::shape_get_data(RID p_shape) const { real_t Physics2DServerSW::shape_get_custom_solver_bias(RID p_shape) const { - const Shape2DSW *shape = shape_owner.get(p_shape); + const Shape2DSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0); return shape->get_custom_bias(); } @@ -219,9 +219,9 @@ void Physics2DServerSW::_shape_col_cbk(const Vector2 &p_point_A, const Vector2 & bool Physics2DServerSW::shape_collide(RID p_shape_A, const Transform2D &p_xform_A, const Vector2 &p_motion_A, RID p_shape_B, const Transform2D &p_xform_B, const Vector2 &p_motion_B, Vector2 *r_results, int p_result_max, int &r_result_count) { - Shape2DSW *shape_A = shape_owner.get(p_shape_A); + Shape2DSW *shape_A = shape_owner.getornull(p_shape_A); ERR_FAIL_COND_V(!shape_A, false); - Shape2DSW *shape_B = shape_owner.get(p_shape_B); + Shape2DSW *shape_B = shape_owner.getornull(p_shape_B); ERR_FAIL_COND_V(!shape_B, false); if (p_result_max == 0) { @@ -246,7 +246,7 @@ RID Physics2DServerSW::space_create() { RID id = space_owner.make_rid(space); space->set_self(id); RID area_id = area_create(); - Area2DSW *area = area_owner.get(area_id); + Area2DSW *area = area_owner.getornull(area_id); ERR_FAIL_COND_V(!area, RID()); space->set_default_area(area); area->set_space(space); @@ -257,7 +257,7 @@ RID Physics2DServerSW::space_create() { void Physics2DServerSW::space_set_active(RID p_space, bool p_active) { - Space2DSW *space = space_owner.get(p_space); + Space2DSW *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); if (p_active) active_spaces.insert(space); @@ -267,7 +267,7 @@ void Physics2DServerSW::space_set_active(RID p_space, bool p_active) { bool Physics2DServerSW::space_is_active(RID p_space) const { - const Space2DSW *space = space_owner.get(p_space); + const Space2DSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, false); return active_spaces.has(space); @@ -275,7 +275,7 @@ bool Physics2DServerSW::space_is_active(RID p_space) const { void Physics2DServerSW::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) { - Space2DSW *space = space_owner.get(p_space); + Space2DSW *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); space->set_param(p_param, p_value); @@ -283,35 +283,35 @@ void Physics2DServerSW::space_set_param(RID p_space, SpaceParameter p_param, rea real_t Physics2DServerSW::space_get_param(RID p_space, SpaceParameter p_param) const { - const Space2DSW *space = space_owner.get(p_space); + const Space2DSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_param(p_param); } void Physics2DServerSW::space_set_debug_contacts(RID p_space, int p_max_contacts) { - Space2DSW *space = space_owner.get(p_space); + Space2DSW *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); space->set_debug_contacts(p_max_contacts); } Vector Physics2DServerSW::space_get_contacts(RID p_space) const { - Space2DSW *space = space_owner.get(p_space); + Space2DSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, Vector()); return space->get_debug_contacts(); } int Physics2DServerSW::space_get_contact_count(RID p_space) const { - Space2DSW *space = space_owner.get(p_space); + Space2DSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, 0); return space->get_debug_contact_count(); } Physics2DDirectSpaceState *Physics2DServerSW::space_get_direct_state(RID p_space) { - Space2DSW *space = space_owner.get(p_space); + Space2DSW *space = space_owner.getornull(p_space); ERR_FAIL_COND_V(!space, NULL); ERR_FAIL_COND_V_MSG((using_threads && !doing_sync) || space->is_locked(), NULL, "Space state is inaccessible right now, wait for iteration or physics process notification."); @@ -328,12 +328,12 @@ RID Physics2DServerSW::area_create() { void Physics2DServerSW::area_set_space(RID p_area, RID p_space) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); Space2DSW *space = NULL; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } @@ -346,7 +346,7 @@ void Physics2DServerSW::area_set_space(RID p_area, RID p_space) { RID Physics2DServerSW::area_get_space(RID p_area) const { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, RID()); Space2DSW *space = area->get_space(); @@ -357,7 +357,7 @@ RID Physics2DServerSW::area_get_space(RID p_area) const { void Physics2DServerSW::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_space_override_mode(p_mode); @@ -365,7 +365,7 @@ void Physics2DServerSW::area_set_space_override_mode(RID p_area, AreaSpaceOverri Physics2DServer::AreaSpaceOverrideMode Physics2DServerSW::area_get_space_override_mode(RID p_area) const { - const Area2DSW *area = area_owner.get(p_area); + const Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, AREA_SPACE_OVERRIDE_DISABLED); return area->get_space_override_mode(); @@ -373,10 +373,10 @@ Physics2DServer::AreaSpaceOverrideMode Physics2DServerSW::area_get_space_overrid void Physics2DServerSW::area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform, bool p_disabled) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - Shape2DSW *shape = shape_owner.get(p_shape); + Shape2DSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); area->add_shape(shape, p_transform, p_disabled); @@ -384,10 +384,10 @@ void Physics2DServerSW::area_add_shape(RID p_area, RID p_shape, const Transform2 void Physics2DServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - Shape2DSW *shape = shape_owner.get(p_shape); + Shape2DSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); ERR_FAIL_COND(!shape->is_configured()); @@ -395,7 +395,7 @@ void Physics2DServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) } void Physics2DServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_shape_transform(p_shape_idx, p_transform); @@ -403,7 +403,7 @@ void Physics2DServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, co void Physics2DServerSW::area_set_shape_disabled(RID p_area, int p_shape, bool p_disabled) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); ERR_FAIL_INDEX(p_shape, area->get_shape_count()); FLUSH_QUERY_CHECK(area); @@ -413,14 +413,14 @@ void Physics2DServerSW::area_set_shape_disabled(RID p_area, int p_shape, bool p_ int Physics2DServerSW::area_get_shape_count(RID p_area) const { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, -1); return area->get_shape_count(); } RID Physics2DServerSW::area_get_shape(RID p_area, int p_shape_idx) const { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, RID()); Shape2DSW *shape = area->get_shape(p_shape_idx); @@ -430,7 +430,7 @@ RID Physics2DServerSW::area_get_shape(RID p_area, int p_shape_idx) const { } Transform2D Physics2DServerSW::area_get_shape_transform(RID p_area, int p_shape_idx) const { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Transform2D()); return area->get_shape_transform(p_shape_idx); @@ -438,7 +438,7 @@ Transform2D Physics2DServerSW::area_get_shape_transform(RID p_area, int p_shape_ void Physics2DServerSW::area_remove_shape(RID p_area, int p_shape_idx) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->remove_shape(p_shape_idx); @@ -446,7 +446,7 @@ void Physics2DServerSW::area_remove_shape(RID p_area, int p_shape_idx) { void Physics2DServerSW::area_clear_shapes(RID p_area) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); while (area->get_shape_count()) @@ -456,20 +456,20 @@ void Physics2DServerSW::area_clear_shapes(RID p_area) { void Physics2DServerSW::area_attach_object_instance_id(RID p_area, ObjectID p_id) { if (space_owner.owns(p_area)) { - Space2DSW *space = space_owner.get(p_area); + Space2DSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_instance_id(p_id); } ObjectID Physics2DServerSW::area_get_object_instance_id(RID p_area) const { if (space_owner.owns(p_area)) { - Space2DSW *space = space_owner.get(p_area); + Space2DSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, 0); return area->get_instance_id(); } @@ -477,20 +477,20 @@ ObjectID Physics2DServerSW::area_get_object_instance_id(RID p_area) const { void Physics2DServerSW::area_attach_canvas_instance_id(RID p_area, ObjectID p_id) { if (space_owner.owns(p_area)) { - Space2DSW *space = space_owner.get(p_area); + Space2DSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_canvas_instance_id(p_id); } ObjectID Physics2DServerSW::area_get_canvas_instance_id(RID p_area) const { if (space_owner.owns(p_area)) { - Space2DSW *space = space_owner.get(p_area); + Space2DSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, 0); return area->get_canvas_instance_id(); } @@ -498,17 +498,17 @@ ObjectID Physics2DServerSW::area_get_canvas_instance_id(RID p_area) const { void Physics2DServerSW::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) { if (space_owner.owns(p_area)) { - Space2DSW *space = space_owner.get(p_area); + Space2DSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_param(p_param, p_value); }; void Physics2DServerSW::area_set_transform(RID p_area, const Transform2D &p_transform) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_transform(p_transform); }; @@ -516,10 +516,10 @@ void Physics2DServerSW::area_set_transform(RID p_area, const Transform2D &p_tran Variant Physics2DServerSW::area_get_param(RID p_area, AreaParameter p_param) const { if (space_owner.owns(p_area)) { - Space2DSW *space = space_owner.get(p_area); + Space2DSW *space = space_owner.getornull(p_area); p_area = space->get_default_area()->get_self(); } - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Variant()); return area->get_param(p_param); @@ -527,7 +527,7 @@ Variant Physics2DServerSW::area_get_param(RID p_area, AreaParameter p_param) con Transform2D Physics2DServerSW::area_get_transform(RID p_area) const { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, Transform2D()); return area->get_transform(); @@ -535,14 +535,14 @@ Transform2D Physics2DServerSW::area_get_transform(RID p_area) const { void Physics2DServerSW::area_set_pickable(RID p_area, bool p_pickable) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_pickable(p_pickable); } void Physics2DServerSW::area_set_monitorable(RID p_area, bool p_monitorable) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); FLUSH_QUERY_CHECK(area); @@ -551,7 +551,7 @@ void Physics2DServerSW::area_set_monitorable(RID p_area, bool p_monitorable) { void Physics2DServerSW::area_set_collision_mask(RID p_area, uint32_t p_mask) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_collision_mask(p_mask); @@ -559,7 +559,7 @@ void Physics2DServerSW::area_set_collision_mask(RID p_area, uint32_t p_mask) { void Physics2DServerSW::area_set_collision_layer(RID p_area, uint32_t p_layer) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_collision_layer(p_layer); @@ -567,7 +567,7 @@ void Physics2DServerSW::area_set_collision_layer(RID p_area, uint32_t p_layer) { void Physics2DServerSW::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_monitor_callback(p_receiver ? p_receiver->get_instance_id() : 0, p_method); @@ -575,7 +575,7 @@ void Physics2DServerSW::area_set_monitor_callback(RID p_area, Object *p_receiver void Physics2DServerSW::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { - Area2DSW *area = area_owner.get(p_area); + Area2DSW *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); area->set_area_monitor_callback(p_receiver ? p_receiver->get_instance_id() : 0, p_method); @@ -593,11 +593,11 @@ RID Physics2DServerSW::body_create() { void Physics2DServerSW::body_set_space(RID p_body, RID p_space) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); Space2DSW *space = NULL; if (p_space.is_valid()) { - space = space_owner.get(p_space); + space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); } @@ -610,7 +610,7 @@ void Physics2DServerSW::body_set_space(RID p_body, RID p_space) { RID Physics2DServerSW::body_get_space(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); Space2DSW *space = body->get_space(); @@ -621,7 +621,7 @@ RID Physics2DServerSW::body_get_space(RID p_body) const { void Physics2DServerSW::body_set_mode(RID p_body, BodyMode p_mode) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); FLUSH_QUERY_CHECK(body); @@ -630,7 +630,7 @@ void Physics2DServerSW::body_set_mode(RID p_body, BodyMode p_mode) { Physics2DServer::BodyMode Physics2DServerSW::body_get_mode(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, BODY_MODE_STATIC); return body->get_mode(); @@ -638,10 +638,10 @@ Physics2DServer::BodyMode Physics2DServerSW::body_get_mode(RID p_body) const { void Physics2DServerSW::body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform, bool p_disabled) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); - Shape2DSW *shape = shape_owner.get(p_shape); + Shape2DSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); body->add_shape(shape, p_transform, p_disabled); @@ -649,10 +649,10 @@ void Physics2DServerSW::body_add_shape(RID p_body, RID p_shape, const Transform2 void Physics2DServerSW::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); - Shape2DSW *shape = shape_owner.get(p_shape); + Shape2DSW *shape = shape_owner.getornull(p_shape); ERR_FAIL_COND(!shape); ERR_FAIL_COND(!shape->is_configured()); @@ -660,7 +660,7 @@ void Physics2DServerSW::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) } void Physics2DServerSW::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_shape_transform(p_shape_idx, p_transform); @@ -668,28 +668,28 @@ void Physics2DServerSW::body_set_shape_transform(RID p_body, int p_shape_idx, co void Physics2DServerSW::body_set_shape_metadata(RID p_body, int p_shape_idx, const Variant &p_metadata) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_shape_metadata(p_shape_idx, p_metadata); } Variant Physics2DServerSW::body_get_shape_metadata(RID p_body, int p_shape_idx) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Variant()); return body->get_shape_metadata(p_shape_idx); } int Physics2DServerSW::body_get_shape_count(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, -1); return body->get_shape_count(); } RID Physics2DServerSW::body_get_shape(RID p_body, int p_shape_idx) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, RID()); Shape2DSW *shape = body->get_shape(p_shape_idx); @@ -699,7 +699,7 @@ RID Physics2DServerSW::body_get_shape(RID p_body, int p_shape_idx) const { } Transform2D Physics2DServerSW::body_get_shape_transform(RID p_body, int p_shape_idx) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Transform2D()); return body->get_shape_transform(p_shape_idx); @@ -707,7 +707,7 @@ Transform2D Physics2DServerSW::body_get_shape_transform(RID p_body, int p_shape_ void Physics2DServerSW::body_remove_shape(RID p_body, int p_shape_idx) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->remove_shape(p_shape_idx); @@ -715,7 +715,7 @@ void Physics2DServerSW::body_remove_shape(RID p_body, int p_shape_idx) { void Physics2DServerSW::body_clear_shapes(RID p_body) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); while (body->get_shape_count()) @@ -724,7 +724,7 @@ void Physics2DServerSW::body_clear_shapes(RID p_body) { void Physics2DServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); FLUSH_QUERY_CHECK(body); @@ -733,7 +733,7 @@ void Physics2DServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, boo } void Physics2DServerSW::body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable, float p_margin) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count()); FLUSH_QUERY_CHECK(body); @@ -743,14 +743,14 @@ void Physics2DServerSW::body_set_shape_as_one_way_collision(RID p_body, int p_sh void Physics2DServerSW::body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_continuous_collision_detection_mode(p_mode); } Physics2DServerSW::CCDMode Physics2DServerSW::body_get_continuous_collision_detection_mode(RID p_body) const { - const Body2DSW *body = body_owner.get(p_body); + const Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, CCD_MODE_DISABLED); return body->get_continuous_collision_detection_mode(); @@ -758,7 +758,7 @@ Physics2DServerSW::CCDMode Physics2DServerSW::body_get_continuous_collision_dete void Physics2DServerSW::body_attach_object_instance_id(RID p_body, uint32_t p_id) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_instance_id(p_id); @@ -766,7 +766,7 @@ void Physics2DServerSW::body_attach_object_instance_id(RID p_body, uint32_t p_id uint32_t Physics2DServerSW::body_get_object_instance_id(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_instance_id(); @@ -774,7 +774,7 @@ uint32_t Physics2DServerSW::body_get_object_instance_id(RID p_body) const { void Physics2DServerSW::body_attach_canvas_instance_id(RID p_body, uint32_t p_id) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_canvas_instance_id(p_id); @@ -782,7 +782,7 @@ void Physics2DServerSW::body_attach_canvas_instance_id(RID p_body, uint32_t p_id uint32_t Physics2DServerSW::body_get_canvas_instance_id(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_canvas_instance_id(); @@ -790,14 +790,14 @@ uint32_t Physics2DServerSW::body_get_canvas_instance_id(RID p_body) const { void Physics2DServerSW::body_set_collision_layer(RID p_body, uint32_t p_layer) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_layer(p_layer); }; uint32_t Physics2DServerSW::body_get_collision_layer(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_layer(); @@ -805,14 +805,14 @@ uint32_t Physics2DServerSW::body_get_collision_layer(RID p_body) const { void Physics2DServerSW::body_set_collision_mask(RID p_body, uint32_t p_mask) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_collision_mask(p_mask); }; uint32_t Physics2DServerSW::body_get_collision_mask(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_collision_mask(); @@ -820,7 +820,7 @@ uint32_t Physics2DServerSW::body_get_collision_mask(RID p_body) const { void Physics2DServerSW::body_set_param(RID p_body, BodyParameter p_param, real_t p_value) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_param(p_param, p_value); @@ -828,7 +828,7 @@ void Physics2DServerSW::body_set_param(RID p_body, BodyParameter p_param, real_t real_t Physics2DServerSW::body_get_param(RID p_body, BodyParameter p_param) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_param(p_param); @@ -836,7 +836,7 @@ real_t Physics2DServerSW::body_get_param(RID p_body, BodyParameter p_param) cons void Physics2DServerSW::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_state(p_state, p_variant); @@ -844,7 +844,7 @@ void Physics2DServerSW::body_set_state(RID p_body, BodyState p_state, const Vari Variant Physics2DServerSW::body_get_state(RID p_body, BodyState p_state) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Variant()); return body->get_state(p_state); @@ -852,7 +852,7 @@ Variant Physics2DServerSW::body_get_state(RID p_body, BodyState p_state) const { void Physics2DServerSW::body_set_applied_force(RID p_body, const Vector2 &p_force) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_applied_force(p_force); @@ -861,14 +861,14 @@ void Physics2DServerSW::body_set_applied_force(RID p_body, const Vector2 &p_forc Vector2 Physics2DServerSW::body_get_applied_force(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, Vector2()); return body->get_applied_force(); }; void Physics2DServerSW::body_set_applied_torque(RID p_body, real_t p_torque) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_applied_torque(p_torque); @@ -877,14 +877,14 @@ void Physics2DServerSW::body_set_applied_torque(RID p_body, real_t p_torque) { real_t Physics2DServerSW::body_get_applied_torque(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return body->get_applied_torque(); }; void Physics2DServerSW::body_apply_central_impulse(RID p_body, const Vector2 &p_impulse) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->apply_central_impulse(p_impulse); @@ -892,7 +892,7 @@ void Physics2DServerSW::body_apply_central_impulse(RID p_body, const Vector2 &p_ } void Physics2DServerSW::body_apply_torque_impulse(RID p_body, real_t p_torque) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); _update_shapes(); @@ -902,7 +902,7 @@ void Physics2DServerSW::body_apply_torque_impulse(RID p_body, real_t p_torque) { void Physics2DServerSW::body_apply_impulse(RID p_body, const Vector2 &p_pos, const Vector2 &p_impulse) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); _update_shapes(); @@ -912,7 +912,7 @@ void Physics2DServerSW::body_apply_impulse(RID p_body, const Vector2 &p_pos, con }; void Physics2DServerSW::body_add_central_force(RID p_body, const Vector2 &p_force) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->add_central_force(p_force); @@ -921,7 +921,7 @@ void Physics2DServerSW::body_add_central_force(RID p_body, const Vector2 &p_forc void Physics2DServerSW::body_add_force(RID p_body, const Vector2 &p_offset, const Vector2 &p_force) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->add_force(p_offset, p_force); @@ -929,7 +929,7 @@ void Physics2DServerSW::body_add_force(RID p_body, const Vector2 &p_offset, cons }; void Physics2DServerSW::body_add_torque(RID p_body, real_t p_torque) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->add_torque(p_torque); @@ -938,7 +938,7 @@ void Physics2DServerSW::body_add_torque(RID p_body, real_t p_torque) { void Physics2DServerSW::body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); _update_shapes(); @@ -953,7 +953,7 @@ void Physics2DServerSW::body_set_axis_velocity(RID p_body, const Vector2 &p_axis void Physics2DServerSW::body_add_collision_exception(RID p_body, RID p_body_b) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->add_exception(p_body_b); @@ -962,7 +962,7 @@ void Physics2DServerSW::body_add_collision_exception(RID p_body, RID p_body_b) { void Physics2DServerSW::body_remove_collision_exception(RID p_body, RID p_body_b) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->remove_exception(p_body_b); @@ -971,7 +971,7 @@ void Physics2DServerSW::body_remove_collision_exception(RID p_body, RID p_body_b void Physics2DServerSW::body_get_collision_exceptions(RID p_body, List *p_exceptions) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); for (int i = 0; i < body->get_exceptions().size(); i++) { @@ -981,20 +981,20 @@ void Physics2DServerSW::body_get_collision_exceptions(RID p_body, List *p_e void Physics2DServerSW::body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); }; real_t Physics2DServerSW::body_get_contacts_reported_depth_threshold(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, 0); return 0; }; void Physics2DServerSW::body_set_omit_force_integration(RID p_body, bool p_omit) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_omit_force_integration(p_omit); @@ -1002,35 +1002,35 @@ void Physics2DServerSW::body_set_omit_force_integration(RID p_body, bool p_omit) bool Physics2DServerSW::body_is_omitting_force_integration(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); return body->get_omit_force_integration(); }; void Physics2DServerSW::body_set_max_contacts_reported(RID p_body, int p_contacts) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_max_contacts_reported(p_contacts); } int Physics2DServerSW::body_get_max_contacts_reported(RID p_body) const { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, -1); return body->get_max_contacts_reported(); } void Physics2DServerSW::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(0), p_method, p_udata); } bool Physics2DServerSW::body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_INDEX_V(p_body_shape, body->get_shape_count(), false); @@ -1039,14 +1039,14 @@ bool Physics2DServerSW::body_collide_shape(RID p_body, int p_body_shape, RID p_s void Physics2DServerSW::body_set_pickable(RID p_body, bool p_pickable) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND(!body); body->set_pickable(p_pickable); } bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, real_t p_margin, MotionResult *r_result, bool p_exclude_raycast_shapes) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); ERR_FAIL_COND_V(body->get_space()->is_locked(), false); @@ -1058,7 +1058,7 @@ bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from, int Physics2DServerSW::body_test_ray_separation(RID p_body, const Transform2D &p_transform, bool p_infinite_inertia, Vector2 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin) { - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, false); ERR_FAIL_COND_V(!body->get_space(), false); ERR_FAIL_COND_V(body->get_space()->is_locked(), false); @@ -1073,7 +1073,7 @@ Physics2DDirectBodyState *Physics2DServerSW::body_get_direct_state(RID p_body) { if (!body_owner.owns(p_body)) return NULL; - Body2DSW *body = body_owner.get(p_body); + Body2DSW *body = body_owner.getornull(p_body); ERR_FAIL_COND_V(!body, NULL); ERR_FAIL_COND_V(!body->get_space(), NULL); ERR_FAIL_COND_V_MSG(body->get_space()->is_locked(), NULL, "Body state is inaccessible right now, wait for iteration or physics process notification."); @@ -1086,7 +1086,7 @@ Physics2DDirectBodyState *Physics2DServerSW::body_get_direct_state(RID p_body) { void Physics2DServerSW::joint_set_param(RID p_joint, JointParam p_param, real_t p_value) { - Joint2DSW *joint = joint_owner.get(p_joint); + Joint2DSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); switch (p_param) { @@ -1098,7 +1098,7 @@ void Physics2DServerSW::joint_set_param(RID p_joint, JointParam p_param, real_t real_t Physics2DServerSW::joint_get_param(RID p_joint, JointParam p_param) const { - const Joint2DSW *joint = joint_owner.get(p_joint); + const Joint2DSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, -1); switch (p_param) { @@ -1111,7 +1111,7 @@ real_t Physics2DServerSW::joint_get_param(RID p_joint, JointParam p_param) const } void Physics2DServerSW::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) { - Joint2DSW *joint = joint_owner.get(p_joint); + Joint2DSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND(!joint); joint->disable_collisions_between_bodies(p_disable); @@ -1131,7 +1131,7 @@ void Physics2DServerSW::joint_disable_collisions_between_bodies(RID p_joint, con } bool Physics2DServerSW::joint_is_disabled_collisions_between_bodies(RID p_joint) const { - const Joint2DSW *joint = joint_owner.get(p_joint); + const Joint2DSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, true); return joint->is_disabled_collisions_between_bodies(); @@ -1139,11 +1139,11 @@ bool Physics2DServerSW::joint_is_disabled_collisions_between_bodies(RID p_joint) RID Physics2DServerSW::pin_joint_create(const Vector2 &p_pos, RID p_body_a, RID p_body_b) { - Body2DSW *A = body_owner.get(p_body_a); + Body2DSW *A = body_owner.getornull(p_body_a); ERR_FAIL_COND_V(!A, RID()); Body2DSW *B = NULL; if (body_owner.owns(p_body_b)) { - B = body_owner.get(p_body_b); + B = body_owner.getornull(p_body_b); ERR_FAIL_COND_V(!B, RID()); } @@ -1156,10 +1156,10 @@ RID Physics2DServerSW::pin_joint_create(const Vector2 &p_pos, RID p_body_a, RID RID Physics2DServerSW::groove_joint_create(const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, RID p_body_a, RID p_body_b) { - Body2DSW *A = body_owner.get(p_body_a); + Body2DSW *A = body_owner.getornull(p_body_a); ERR_FAIL_COND_V(!A, RID()); - Body2DSW *B = body_owner.get(p_body_b); + Body2DSW *B = body_owner.getornull(p_body_b); ERR_FAIL_COND_V(!B, RID()); Joint2DSW *joint = memnew(GrooveJoint2DSW(p_a_groove1, p_a_groove2, p_b_anchor, A, B)); @@ -1170,10 +1170,10 @@ RID Physics2DServerSW::groove_joint_create(const Vector2 &p_a_groove1, const Vec RID Physics2DServerSW::damped_spring_joint_create(const Vector2 &p_anchor_a, const Vector2 &p_anchor_b, RID p_body_a, RID p_body_b) { - Body2DSW *A = body_owner.get(p_body_a); + Body2DSW *A = body_owner.getornull(p_body_a); ERR_FAIL_COND_V(!A, RID()); - Body2DSW *B = body_owner.get(p_body_b); + Body2DSW *B = body_owner.getornull(p_body_b); ERR_FAIL_COND_V(!B, RID()); Joint2DSW *joint = memnew(DampedSpringJoint2DSW(p_anchor_a, p_anchor_b, A, B)); @@ -1184,7 +1184,7 @@ RID Physics2DServerSW::damped_spring_joint_create(const Vector2 &p_anchor_a, con void Physics2DServerSW::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) { - Joint2DSW *j = joint_owner.get(p_joint); + Joint2DSW *j = joint_owner.getornull(p_joint); ERR_FAIL_COND(!j); ERR_FAIL_COND(j->get_type() != JOINT_PIN); @@ -1193,7 +1193,7 @@ void Physics2DServerSW::pin_joint_set_param(RID p_joint, PinJointParam p_param, } real_t Physics2DServerSW::pin_joint_get_param(RID p_joint, PinJointParam p_param) const { - Joint2DSW *j = joint_owner.get(p_joint); + Joint2DSW *j = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!j, 0); ERR_FAIL_COND_V(j->get_type() != JOINT_PIN, 0); @@ -1203,7 +1203,7 @@ real_t Physics2DServerSW::pin_joint_get_param(RID p_joint, PinJointParam p_param void Physics2DServerSW::damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value) { - Joint2DSW *j = joint_owner.get(p_joint); + Joint2DSW *j = joint_owner.getornull(p_joint); ERR_FAIL_COND(!j); ERR_FAIL_COND(j->get_type() != JOINT_DAMPED_SPRING); @@ -1213,7 +1213,7 @@ void Physics2DServerSW::damped_string_joint_set_param(RID p_joint, DampedStringP real_t Physics2DServerSW::damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const { - Joint2DSW *j = joint_owner.get(p_joint); + Joint2DSW *j = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!j, 0); ERR_FAIL_COND_V(j->get_type() != JOINT_DAMPED_SPRING, 0); @@ -1223,7 +1223,7 @@ real_t Physics2DServerSW::damped_string_joint_get_param(RID p_joint, DampedStrin Physics2DServer::JointType Physics2DServerSW::joint_get_type(RID p_joint) const { - Joint2DSW *joint = joint_owner.get(p_joint); + Joint2DSW *joint = joint_owner.getornull(p_joint); ERR_FAIL_COND_V(!joint, JOINT_PIN); return joint->get_type(); @@ -1235,7 +1235,7 @@ void Physics2DServerSW::free(RID p_rid) { if (shape_owner.owns(p_rid)) { - Shape2DSW *shape = shape_owner.get(p_rid); + Shape2DSW *shape = shape_owner.getornull(p_rid); while (shape->get_owners().size()) { ShapeOwner2DSW *so = shape->get_owners().front()->key(); @@ -1246,7 +1246,7 @@ void Physics2DServerSW::free(RID p_rid) { memdelete(shape); } else if (body_owner.owns(p_rid)) { - Body2DSW *body = body_owner.get(p_rid); + Body2DSW *body = body_owner.getornull(p_rid); /* if (body->get_state_query()) @@ -1268,7 +1268,7 @@ void Physics2DServerSW::free(RID p_rid) { } else if (area_owner.owns(p_rid)) { - Area2DSW *area = area_owner.get(p_rid); + Area2DSW *area = area_owner.getornull(p_rid); /* if (area->get_monitor_query()) @@ -1286,7 +1286,7 @@ void Physics2DServerSW::free(RID p_rid) { memdelete(area); } else if (space_owner.owns(p_rid)) { - Space2DSW *space = space_owner.get(p_rid); + Space2DSW *space = space_owner.getornull(p_rid); while (space->get_objects().size()) { CollisionObject2DSW *co = (CollisionObject2DSW *)space->get_objects().front()->get(); @@ -1299,7 +1299,7 @@ void Physics2DServerSW::free(RID p_rid) { memdelete(space); } else if (joint_owner.owns(p_rid)) { - Joint2DSW *joint = joint_owner.get(p_rid); + Joint2DSW *joint = joint_owner.getornull(p_rid); joint_owner.free(p_rid); memdelete(joint); diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index c8f443e3b61d..6a636bb72a7e 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -31,6 +31,7 @@ #ifndef PHYSICS_2D_SERVER_SW #define PHYSICS_2D_SERVER_SW +#include "core/rid_owner.h" #include "joints_2d_sw.h" #include "servers/physics_2d_server.h" #include "shape_2d_sw.h" @@ -61,11 +62,11 @@ class Physics2DServerSW : public Physics2DServer { Physics2DDirectBodyStateSW *direct_state; - mutable RID_Owner shape_owner; - mutable RID_Owner space_owner; - mutable RID_Owner area_owner; - mutable RID_Owner body_owner; - mutable RID_Owner joint_owner; + mutable RID_PtrOwner shape_owner; + mutable RID_PtrOwner space_owner; + mutable RID_PtrOwner area_owner; + mutable RID_PtrOwner body_owner; + mutable RID_PtrOwner joint_owner; static Physics2DServerSW *singletonsw; diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h index a336dcecf51e..0a9d55ec4e96 100644 --- a/servers/physics_2d/shape_2d_sw.h +++ b/servers/physics_2d/shape_2d_sw.h @@ -48,7 +48,7 @@ SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_creat class Shape2DSW; -class ShapeOwner2DSW : public RID_Data { +class ShapeOwner2DSW { public: virtual void _shape_changed() = 0; virtual void remove_shape(Shape2DSW *p_shape) = 0; @@ -56,7 +56,7 @@ class ShapeOwner2DSW : public RID_Data { virtual ~ShapeOwner2DSW() {} }; -class Shape2DSW : public RID_Data { +class Shape2DSW { RID self; Rect2 aabb; diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 08a261da2ae4..150fda4322ae 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -198,7 +198,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Trans if (p_result_max <= 0) return 0; - Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); + Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0); Rect2 aabb = p_xform.xform(shape->get_aabb()); @@ -240,7 +240,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Trans bool Physics2DDirectSpaceStateSW::cast_motion(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); + Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, false); Rect2 aabb = p_xform.xform(shape->get_aabb()); @@ -313,7 +313,7 @@ bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D & if (p_result_max <= 0) return 0; - Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); + Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0); Rect2 aabb = p_shape_xform.xform(shape->get_aabb()); @@ -404,7 +404,7 @@ static void _rest_cbk_result(const Vector2 &p_point_A, const Vector2 &p_point_B, bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, ShapeRestInfo *r_info, const Set &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); + Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.getornull(p_shape); ERR_FAIL_COND_V(!shape, 0); Rect2 aabb = p_shape_xform.xform(shape->get_aabb()); diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h index 94f8cf9d7186..e4b3714d1584 100644 --- a/servers/physics_2d/space_2d_sw.h +++ b/servers/physics_2d/space_2d_sw.h @@ -61,7 +61,7 @@ class Physics2DDirectSpaceStateSW : public Physics2DDirectSpaceState { Physics2DDirectSpaceStateSW(); }; -class Space2DSW : public RID_Data { +class Space2DSW { public: enum ElapsedTime { diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 0008b809b789..4d281f27a055 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -82,7 +82,7 @@ class RasterizerScene { virtual VS::EnvironmentBG environment_get_background(RID p_env) = 0; virtual int environment_get_canvas_max_layer(RID p_env) = 0; - struct InstanceBase : RID_Data { + struct InstanceBase { VS::InstanceType base_type; RID base; @@ -608,7 +608,7 @@ class RasterizerCanvas { CANVAS_RECT_CLIP_UV = 32 }; - struct Light : public RID_Data { + struct Light { bool enabled; Color color; @@ -678,7 +678,7 @@ class RasterizerCanvas { virtual void light_internal_update(RID p_rid, Light *p_light) = 0; virtual void light_internal_free(RID p_rid) = 0; - struct Item : public RID_Data { + struct Item { struct Command { @@ -1065,7 +1065,7 @@ class RasterizerCanvas { virtual void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) = 0; virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow) = 0; - struct LightOccluderInstance : public RID_Data { + struct LightOccluderInstance { bool enabled; RID canvas; diff --git a/servers/visual/visual_server_canvas.cpp b/servers/visual/visual_server_canvas.cpp index c90e061eb72b..02213e0d4c73 100644 --- a/servers/visual/visual_server_canvas.cpp +++ b/servers/visual/visual_server_canvas.cpp @@ -74,7 +74,7 @@ void _collect_ysort_children(VisualServerCanvas::Item *p_canvas_item, Transform2 } } -void _mark_ysort_dirty(VisualServerCanvas::Item *ysort_owner, RID_Owner &canvas_item_owner) { +void _mark_ysort_dirty(VisualServerCanvas::Item *ysort_owner, RID_PtrOwner &canvas_item_owner) { do { ysort_owner->ysort_children_count = -1; ysort_owner = canvas_item_owner.owns(ysort_owner->parent) ? canvas_item_owner.getornull(ysort_owner->parent) : NULL; @@ -320,7 +320,7 @@ void VisualServerCanvas::canvas_set_item_mirroring(RID p_canvas, RID p_item, con } void VisualServerCanvas::canvas_set_modulate(RID p_canvas, const Color &p_color) { - Canvas *canvas = canvas_owner.get(p_canvas); + Canvas *canvas = canvas_owner.getornull(p_canvas); ERR_FAIL_COND(!canvas); canvas->modulate = p_color; } @@ -331,7 +331,7 @@ void VisualServerCanvas::canvas_set_disable_scale(bool p_disable) { void VisualServerCanvas::canvas_set_parent(RID p_canvas, RID p_parent, float p_scale) { - Canvas *canvas = canvas_owner.get(p_canvas); + Canvas *canvas = canvas_owner.getornull(p_canvas); ERR_FAIL_COND(!canvas); canvas->parent = p_parent; @@ -355,11 +355,11 @@ void VisualServerCanvas::canvas_item_set_parent(RID p_item, RID p_parent) { if (canvas_owner.owns(canvas_item->parent)) { - Canvas *canvas = canvas_owner.get(canvas_item->parent); + Canvas *canvas = canvas_owner.getornull(canvas_item->parent); canvas->erase_item(canvas_item); } else if (canvas_item_owner.owns(canvas_item->parent)) { - Item *item_owner = canvas_item_owner.get(canvas_item->parent); + Item *item_owner = canvas_item_owner.getornull(canvas_item->parent); item_owner->child_items.erase(canvas_item); if (item_owner->sort_y) { @@ -373,14 +373,14 @@ void VisualServerCanvas::canvas_item_set_parent(RID p_item, RID p_parent) { if (p_parent.is_valid()) { if (canvas_owner.owns(p_parent)) { - Canvas *canvas = canvas_owner.get(p_parent); + Canvas *canvas = canvas_owner.getornull(p_parent); Canvas::ChildItem ci; ci.item = canvas_item; canvas->child_items.push_back(ci); canvas->children_order_dirty = true; } else if (canvas_item_owner.owns(p_parent)) { - Item *item_owner = canvas_item_owner.get(p_parent); + Item *item_owner = canvas_item_owner.getornull(p_parent); item_owner->child_items.push_back(canvas_item); item_owner->children_order_dirty = true; @@ -983,7 +983,7 @@ void VisualServerCanvas::canvas_item_set_draw_index(RID p_item, int p_index) { void VisualServerCanvas::canvas_item_set_material(RID p_item, RID p_material) { - Item *canvas_item = canvas_item_owner.get(p_item); + Item *canvas_item = canvas_item_owner.getornull(p_item); ERR_FAIL_COND(!canvas_item); canvas_item->material = p_material; @@ -991,7 +991,7 @@ void VisualServerCanvas::canvas_item_set_material(RID p_item, RID p_material) { void VisualServerCanvas::canvas_item_set_use_parent_material(RID p_item, bool p_enable) { - Item *canvas_item = canvas_item_owner.get(p_item); + Item *canvas_item = canvas_item_owner.getornull(p_item); ERR_FAIL_COND(!canvas_item); canvas_item->use_parent_material = p_enable; @@ -1005,7 +1005,7 @@ RID VisualServerCanvas::canvas_light_create() { } void VisualServerCanvas::canvas_light_attach_to_canvas(RID p_light, RID p_canvas) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); if (clight->canvas.is_valid()) { @@ -1021,70 +1021,70 @@ void VisualServerCanvas::canvas_light_attach_to_canvas(RID p_light, RID p_canvas if (clight->canvas.is_valid()) { - Canvas *canvas = canvas_owner.get(clight->canvas); + Canvas *canvas = canvas_owner.getornull(clight->canvas); canvas->lights.insert(clight); } } void VisualServerCanvas::canvas_light_set_enabled(RID p_light, bool p_enabled) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->enabled = p_enabled; } void VisualServerCanvas::canvas_light_set_scale(RID p_light, float p_scale) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->scale = p_scale; } void VisualServerCanvas::canvas_light_set_transform(RID p_light, const Transform2D &p_transform) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->xform = p_transform; } void VisualServerCanvas::canvas_light_set_texture(RID p_light, RID p_texture) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->texture = p_texture; } void VisualServerCanvas::canvas_light_set_texture_offset(RID p_light, const Vector2 &p_offset) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->texture_offset = p_offset; } void VisualServerCanvas::canvas_light_set_color(RID p_light, const Color &p_color) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->color = p_color; } void VisualServerCanvas::canvas_light_set_height(RID p_light, float p_height) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->height = p_height; } void VisualServerCanvas::canvas_light_set_energy(RID p_light, float p_energy) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->energy = p_energy; } void VisualServerCanvas::canvas_light_set_z_range(RID p_light, int p_min_z, int p_max_z) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->z_min = p_min_z; @@ -1092,7 +1092,7 @@ void VisualServerCanvas::canvas_light_set_z_range(RID p_light, int p_min_z, int } void VisualServerCanvas::canvas_light_set_layer_range(RID p_light, int p_min_layer, int p_max_layer) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->layer_max = p_max_layer; @@ -1100,21 +1100,21 @@ void VisualServerCanvas::canvas_light_set_layer_range(RID p_light, int p_min_lay } void VisualServerCanvas::canvas_light_set_item_cull_mask(RID p_light, int p_mask) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->item_mask = p_mask; } void VisualServerCanvas::canvas_light_set_item_shadow_cull_mask(RID p_light, int p_mask) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->item_shadow_mask = p_mask; } void VisualServerCanvas::canvas_light_set_mode(RID p_light, VS::CanvasLightMode p_mode) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->mode = p_mode; @@ -1122,7 +1122,7 @@ void VisualServerCanvas::canvas_light_set_mode(RID p_light, VS::CanvasLightMode void VisualServerCanvas::canvas_light_set_shadow_enabled(RID p_light, bool p_enabled) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); if (clight->shadow_buffer.is_valid() == p_enabled) @@ -1138,7 +1138,7 @@ void VisualServerCanvas::canvas_light_set_shadow_buffer_size(RID p_light, int p_ ERR_FAIL_COND(p_size < 32 || p_size > 16384); - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); int new_size = next_power_of_2(p_size); @@ -1157,21 +1157,21 @@ void VisualServerCanvas::canvas_light_set_shadow_gradient_length(RID p_light, fl ERR_FAIL_COND(p_length < 0); - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->shadow_gradient_length = p_length; } void VisualServerCanvas::canvas_light_set_shadow_filter(RID p_light, VS::CanvasLightShadowFilter p_filter) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->shadow_filter = p_filter; } void VisualServerCanvas::canvas_light_set_shadow_color(RID p_light, const Color &p_color) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->shadow_color = p_color; @@ -1179,7 +1179,7 @@ void VisualServerCanvas::canvas_light_set_shadow_color(RID p_light, const Color void VisualServerCanvas::canvas_light_set_shadow_smooth(RID p_light, float p_smooth) { - RasterizerCanvas::Light *clight = canvas_light_owner.get(p_light); + RasterizerCanvas::Light *clight = canvas_light_owner.getornull(p_light); ERR_FAIL_COND(!clight); clight->shadow_smooth = p_smooth; } @@ -1192,12 +1192,12 @@ RID VisualServerCanvas::canvas_light_occluder_create() { } void VisualServerCanvas::canvas_light_occluder_attach_to_canvas(RID p_occluder, RID p_canvas) { - RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder); + RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.getornull(p_occluder); ERR_FAIL_COND(!occluder); if (occluder->canvas.is_valid()) { - Canvas *canvas = canvas_owner.get(occluder->canvas); + Canvas *canvas = canvas_owner.getornull(occluder->canvas); canvas->occluders.erase(occluder); } @@ -1208,24 +1208,24 @@ void VisualServerCanvas::canvas_light_occluder_attach_to_canvas(RID p_occluder, if (occluder->canvas.is_valid()) { - Canvas *canvas = canvas_owner.get(occluder->canvas); + Canvas *canvas = canvas_owner.getornull(occluder->canvas); canvas->occluders.insert(occluder); } } void VisualServerCanvas::canvas_light_occluder_set_enabled(RID p_occluder, bool p_enabled) { - RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder); + RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.getornull(p_occluder); ERR_FAIL_COND(!occluder); occluder->enabled = p_enabled; } void VisualServerCanvas::canvas_light_occluder_set_polygon(RID p_occluder, RID p_polygon) { - RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder); + RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.getornull(p_occluder); ERR_FAIL_COND(!occluder); if (occluder->polygon.is_valid()) { - LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_polygon); + LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.getornull(p_polygon); if (occluder_poly) { occluder_poly->owners.erase(occluder); } @@ -1235,7 +1235,7 @@ void VisualServerCanvas::canvas_light_occluder_set_polygon(RID p_occluder, RID p occluder->polygon_buffer = RID(); if (occluder->polygon.is_valid()) { - LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_polygon); + LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.getornull(p_polygon); if (!occluder_poly) { occluder->polygon = RID(); ERR_FAIL_COND(!occluder_poly); @@ -1249,14 +1249,14 @@ void VisualServerCanvas::canvas_light_occluder_set_polygon(RID p_occluder, RID p } void VisualServerCanvas::canvas_light_occluder_set_transform(RID p_occluder, const Transform2D &p_xform) { - RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder); + RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.getornull(p_occluder); ERR_FAIL_COND(!occluder); occluder->xform = p_xform; } void VisualServerCanvas::canvas_light_occluder_set_light_mask(RID p_occluder, int p_mask) { - RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_occluder); + RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.getornull(p_occluder); ERR_FAIL_COND(!occluder); occluder->light_mask = p_mask; @@ -1300,7 +1300,7 @@ void VisualServerCanvas::canvas_occluder_polygon_set_shape(RID p_occluder_polygo } void VisualServerCanvas::canvas_occluder_polygon_set_shape_as_lines(RID p_occluder_polygon, const PoolVector &p_shape) { - LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_occluder_polygon); + LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.getornull(p_occluder_polygon); ERR_FAIL_COND(!occluder_poly); ERR_FAIL_COND(p_shape.size() & 1); @@ -1324,7 +1324,7 @@ void VisualServerCanvas::canvas_occluder_polygon_set_shape_as_lines(RID p_occlud void VisualServerCanvas::canvas_occluder_polygon_set_cull_mode(RID p_occluder_polygon, VS::CanvasOccluderPolygonCullMode p_mode) { - LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_occluder_polygon); + LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.getornull(p_occluder_polygon); ERR_FAIL_COND(!occluder_poly); occluder_poly->cull_mode = p_mode; for (Set::Element *E = occluder_poly->owners.front(); E; E = E->next()) { @@ -1336,12 +1336,12 @@ bool VisualServerCanvas::free(RID p_rid) { if (canvas_owner.owns(p_rid)) { - Canvas *canvas = canvas_owner.get(p_rid); + Canvas *canvas = canvas_owner.getornull(p_rid); ERR_FAIL_COND_V(!canvas, false); while (canvas->viewports.size()) { - VisualServerViewport::Viewport *vp = VSG::viewport->viewport_owner.get(canvas->viewports.front()->get()); + VisualServerViewport::Viewport *vp = VSG::viewport->viewport_owner.getornull(canvas->viewports.front()->get()); ERR_FAIL_COND_V(!vp, true); Map::Element *E = vp->canvas_map.find(p_rid); @@ -1372,18 +1372,18 @@ bool VisualServerCanvas::free(RID p_rid) { } else if (canvas_item_owner.owns(p_rid)) { - Item *canvas_item = canvas_item_owner.get(p_rid); + Item *canvas_item = canvas_item_owner.getornull(p_rid); ERR_FAIL_COND_V(!canvas_item, true); if (canvas_item->parent.is_valid()) { if (canvas_owner.owns(canvas_item->parent)) { - Canvas *canvas = canvas_owner.get(canvas_item->parent); + Canvas *canvas = canvas_owner.getornull(canvas_item->parent); canvas->erase_item(canvas_item); } else if (canvas_item_owner.owns(canvas_item->parent)) { - Item *item_owner = canvas_item_owner.get(canvas_item->parent); + Item *item_owner = canvas_item_owner.getornull(canvas_item->parent); item_owner->child_items.erase(canvas_item); if (item_owner->sort_y) { @@ -1409,11 +1409,11 @@ bool VisualServerCanvas::free(RID p_rid) { } else if (canvas_light_owner.owns(p_rid)) { - RasterizerCanvas::Light *canvas_light = canvas_light_owner.get(p_rid); + RasterizerCanvas::Light *canvas_light = canvas_light_owner.getornull(p_rid); ERR_FAIL_COND_V(!canvas_light, true); if (canvas_light->canvas.is_valid()) { - Canvas *canvas = canvas_owner.get(canvas_light->canvas); + Canvas *canvas = canvas_owner.getornull(canvas_light->canvas); if (canvas) canvas->lights.erase(canvas_light); } @@ -1428,12 +1428,12 @@ bool VisualServerCanvas::free(RID p_rid) { } else if (canvas_light_occluder_owner.owns(p_rid)) { - RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.get(p_rid); + RasterizerCanvas::LightOccluderInstance *occluder = canvas_light_occluder_owner.getornull(p_rid); ERR_FAIL_COND_V(!occluder, true); if (occluder->polygon.is_valid()) { - LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(occluder->polygon); + LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.getornull(occluder->polygon); if (occluder_poly) { occluder_poly->owners.erase(occluder); } @@ -1441,7 +1441,7 @@ bool VisualServerCanvas::free(RID p_rid) { if (occluder->canvas.is_valid() && canvas_owner.owns(occluder->canvas)) { - Canvas *canvas = canvas_owner.get(occluder->canvas); + Canvas *canvas = canvas_owner.getornull(occluder->canvas); canvas->occluders.erase(occluder); } @@ -1450,7 +1450,7 @@ bool VisualServerCanvas::free(RID p_rid) { } else if (canvas_light_occluder_polygon_owner.owns(p_rid)) { - LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.get(p_rid); + LightOccluderPolygon *occluder_poly = canvas_light_occluder_polygon_owner.getornull(p_rid); ERR_FAIL_COND_V(!occluder_poly, true); VSG::storage->free(occluder_poly->occluder); diff --git a/servers/visual/visual_server_canvas.h b/servers/visual/visual_server_canvas.h index a2c641ce76f2..8044afe164e1 100644 --- a/servers/visual/visual_server_canvas.h +++ b/servers/visual/visual_server_canvas.h @@ -90,7 +90,7 @@ class VisualServerCanvas { } }; - struct LightOccluderPolygon : RID_Data { + struct LightOccluderPolygon { bool active; Rect2 aabb; @@ -104,9 +104,9 @@ class VisualServerCanvas { } }; - RID_Owner canvas_light_occluder_polygon_owner; + RID_PtrOwner canvas_light_occluder_polygon_owner; - RID_Owner canvas_light_occluder_owner; + RID_PtrOwner canvas_light_occluder_owner; struct Canvas : public VisualServerViewport::CanvasBase { @@ -150,9 +150,9 @@ class VisualServerCanvas { } }; - mutable RID_Owner canvas_owner; - RID_Owner canvas_item_owner; - RID_Owner canvas_light_owner; + mutable RID_PtrOwner canvas_owner; + RID_PtrOwner canvas_item_owner; + RID_PtrOwner canvas_light_owner; bool disable_scale; diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index f5767e93a2e8..69ab4a6b9b94 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -46,7 +46,7 @@ RID VisualServerScene::camera_create() { void VisualServerScene::camera_set_perspective(RID p_camera, float p_fovy_degrees, float p_z_near, float p_z_far) { - Camera *camera = camera_owner.get(p_camera); + Camera *camera = camera_owner.getornull(p_camera); ERR_FAIL_COND(!camera); camera->type = Camera::PERSPECTIVE; camera->fov = p_fovy_degrees; @@ -56,7 +56,7 @@ void VisualServerScene::camera_set_perspective(RID p_camera, float p_fovy_degree void VisualServerScene::camera_set_orthogonal(RID p_camera, float p_size, float p_z_near, float p_z_far) { - Camera *camera = camera_owner.get(p_camera); + Camera *camera = camera_owner.getornull(p_camera); ERR_FAIL_COND(!camera); camera->type = Camera::ORTHOGONAL; camera->size = p_size; @@ -65,7 +65,7 @@ void VisualServerScene::camera_set_orthogonal(RID p_camera, float p_size, float } void VisualServerScene::camera_set_frustum(RID p_camera, float p_size, Vector2 p_offset, float p_z_near, float p_z_far) { - Camera *camera = camera_owner.get(p_camera); + Camera *camera = camera_owner.getornull(p_camera); ERR_FAIL_COND(!camera); camera->type = Camera::FRUSTUM; camera->size = p_size; @@ -76,14 +76,14 @@ void VisualServerScene::camera_set_frustum(RID p_camera, float p_size, Vector2 p void VisualServerScene::camera_set_transform(RID p_camera, const Transform &p_transform) { - Camera *camera = camera_owner.get(p_camera); + Camera *camera = camera_owner.getornull(p_camera); ERR_FAIL_COND(!camera); camera->transform = p_transform.orthonormalized(); } void VisualServerScene::camera_set_cull_mask(RID p_camera, uint32_t p_layers) { - Camera *camera = camera_owner.get(p_camera); + Camera *camera = camera_owner.getornull(p_camera); ERR_FAIL_COND(!camera); camera->visible_layers = p_layers; @@ -91,14 +91,14 @@ void VisualServerScene::camera_set_cull_mask(RID p_camera, uint32_t p_layers) { void VisualServerScene::camera_set_environment(RID p_camera, RID p_env) { - Camera *camera = camera_owner.get(p_camera); + Camera *camera = camera_owner.getornull(p_camera); ERR_FAIL_COND(!camera); camera->env = p_env; } void VisualServerScene::camera_set_use_vertical_aspect(RID p_camera, bool p_enable) { - Camera *camera = camera_owner.get(p_camera); + Camera *camera = camera_owner.getornull(p_camera); ERR_FAIL_COND(!camera); camera->vaspect = p_enable; } @@ -275,28 +275,28 @@ RID VisualServerScene::scenario_create() { void VisualServerScene::scenario_set_debug(RID p_scenario, VS::ScenarioDebugMode p_debug_mode) { - Scenario *scenario = scenario_owner.get(p_scenario); + Scenario *scenario = scenario_owner.getornull(p_scenario); ERR_FAIL_COND(!scenario); scenario->debug = p_debug_mode; } void VisualServerScene::scenario_set_environment(RID p_scenario, RID p_environment) { - Scenario *scenario = scenario_owner.get(p_scenario); + Scenario *scenario = scenario_owner.getornull(p_scenario); ERR_FAIL_COND(!scenario); scenario->environment = p_environment; } void VisualServerScene::scenario_set_fallback_environment(RID p_scenario, RID p_environment) { - Scenario *scenario = scenario_owner.get(p_scenario); + Scenario *scenario = scenario_owner.getornull(p_scenario); ERR_FAIL_COND(!scenario); scenario->fallback_environment = p_environment; } void VisualServerScene::scenario_set_reflection_atlas_size(RID p_scenario, int p_size, int p_subdiv) { - Scenario *scenario = scenario_owner.get(p_scenario); + Scenario *scenario = scenario_owner.getornull(p_scenario); ERR_FAIL_COND(!scenario); VSG::scene_render->reflection_atlas_set_size(scenario->reflection_atlas, p_size); VSG::scene_render->reflection_atlas_set_subdivision(scenario->reflection_atlas, p_subdiv); @@ -330,7 +330,7 @@ RID VisualServerScene::instance_create() { void VisualServerScene::instance_set_base(RID p_instance, RID p_base) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); Scenario *scenario = instance->scenario; @@ -503,7 +503,7 @@ void VisualServerScene::instance_set_base(RID p_instance, RID p_base) { } void VisualServerScene::instance_set_scenario(RID p_instance, RID p_scenario) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); if (instance->scenario) { @@ -547,7 +547,7 @@ void VisualServerScene::instance_set_scenario(RID p_instance, RID p_scenario) { if (p_scenario.is_valid()) { - Scenario *scenario = scenario_owner.get(p_scenario); + Scenario *scenario = scenario_owner.getornull(p_scenario); ERR_FAIL_COND(!scenario); instance->scenario = scenario; @@ -580,14 +580,14 @@ void VisualServerScene::instance_set_scenario(RID p_instance, RID p_scenario) { } void VisualServerScene::instance_set_layer_mask(RID p_instance, uint32_t p_mask) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); instance->layer_mask = p_mask; } void VisualServerScene::instance_set_transform(RID p_instance, const Transform &p_transform) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); if (instance->transform == p_transform) @@ -611,14 +611,14 @@ void VisualServerScene::instance_set_transform(RID p_instance, const Transform & } void VisualServerScene::instance_attach_object_instance_id(RID p_instance, ObjectID p_id) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); instance->object_id = p_id; } void VisualServerScene::instance_set_blend_shape_weight(RID p_instance, int p_shape, float p_weight) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); if (instance->update_item.in_list()) { @@ -631,7 +631,7 @@ void VisualServerScene::instance_set_blend_shape_weight(RID p_instance, int p_sh void VisualServerScene::instance_set_surface_material(RID p_instance, int p_surface, RID p_material) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); if (instance->base_type == VS::INSTANCE_MESH) { @@ -654,7 +654,7 @@ void VisualServerScene::instance_set_surface_material(RID p_instance, int p_surf void VisualServerScene::instance_set_visible(RID p_instance, bool p_visible) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); if (instance->visible == p_visible) @@ -697,7 +697,7 @@ inline bool is_geometry_instance(VisualServer::InstanceType p_type) { void VisualServerScene::instance_set_use_lightmap(RID p_instance, RID p_lightmap_instance, RID p_lightmap) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); if (instance->lightmap_capture) { @@ -708,7 +708,7 @@ void VisualServerScene::instance_set_use_lightmap(RID p_instance, RID p_lightmap } if (p_lightmap_instance.is_valid()) { - Instance *lightmap_instance = instance_owner.get(p_lightmap_instance); + Instance *lightmap_instance = instance_owner.getornull(p_lightmap_instance); ERR_FAIL_COND(!lightmap_instance); ERR_FAIL_COND(lightmap_instance->base_type != VS::INSTANCE_LIGHTMAP_CAPTURE); instance->lightmap_capture = lightmap_instance; @@ -721,7 +721,7 @@ void VisualServerScene::instance_set_use_lightmap(RID p_instance, RID p_lightmap void VisualServerScene::instance_set_custom_aabb(RID p_instance, AABB p_aabb) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); ERR_FAIL_COND(!is_geometry_instance(instance->base_type)); @@ -747,7 +747,7 @@ void VisualServerScene::instance_set_custom_aabb(RID p_instance, AABB p_aabb) { void VisualServerScene::instance_attach_skeleton(RID p_instance, RID p_skeleton) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); if (instance->skeleton == p_skeleton) @@ -770,7 +770,7 @@ void VisualServerScene::instance_set_exterior(RID p_instance, bool p_enabled) { } void VisualServerScene::instance_set_extra_visibility_margin(RID p_instance, real_t p_margin) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); instance->extra_margin = p_margin; @@ -780,7 +780,7 @@ void VisualServerScene::instance_set_extra_visibility_margin(RID p_instance, rea Vector VisualServerScene::instances_cull_aabb(const AABB &p_aabb, RID p_scenario) const { Vector instances; - Scenario *scenario = scenario_owner.get(p_scenario); + Scenario *scenario = scenario_owner.getornull(p_scenario); ERR_FAIL_COND_V(!scenario, instances); const_cast(this)->update_dirty_instances(); // check dirty instances before culling @@ -804,7 +804,7 @@ Vector VisualServerScene::instances_cull_aabb(const AABB &p_aabb, RID Vector VisualServerScene::instances_cull_ray(const Vector3 &p_from, const Vector3 &p_to, RID p_scenario) const { Vector instances; - Scenario *scenario = scenario_owner.get(p_scenario); + Scenario *scenario = scenario_owner.getornull(p_scenario); ERR_FAIL_COND_V(!scenario, instances); const_cast(this)->update_dirty_instances(); // check dirty instances before culling @@ -826,7 +826,7 @@ Vector VisualServerScene::instances_cull_ray(const Vector3 &p_from, co Vector VisualServerScene::instances_cull_convex(const Vector &p_convex, RID p_scenario) const { Vector instances; - Scenario *scenario = scenario_owner.get(p_scenario); + Scenario *scenario = scenario_owner.getornull(p_scenario); ERR_FAIL_COND_V(!scenario, instances); const_cast(this)->update_dirty_instances(); // check dirty instances before culling @@ -850,7 +850,7 @@ Vector VisualServerScene::instances_cull_convex(const Vector &p void VisualServerScene::instance_geometry_set_flag(RID p_instance, VS::InstanceFlags p_flags, bool p_enabled) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); switch (p_flags) { @@ -871,7 +871,7 @@ void VisualServerScene::instance_geometry_set_flag(RID p_instance, VS::InstanceF } void VisualServerScene::instance_geometry_set_cast_shadows_setting(RID p_instance, VS::ShadowCastingSetting p_shadow_casting_setting) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); instance->cast_shadows = p_shadow_casting_setting; @@ -879,7 +879,7 @@ void VisualServerScene::instance_geometry_set_cast_shadows_setting(RID p_instanc } void VisualServerScene::instance_geometry_set_material_override(RID p_instance, RID p_material) { - Instance *instance = instance_owner.get(p_instance); + Instance *instance = instance_owner.getornull(p_instance); ERR_FAIL_COND(!instance); if (instance->material_override.is_valid()) { @@ -3468,14 +3468,14 @@ bool VisualServerScene::free(RID p_rid) { if (camera_owner.owns(p_rid)) { - Camera *camera = camera_owner.get(p_rid); + Camera *camera = camera_owner.getornull(p_rid); camera_owner.free(p_rid); memdelete(camera); } else if (scenario_owner.owns(p_rid)) { - Scenario *scenario = scenario_owner.get(p_rid); + Scenario *scenario = scenario_owner.getornull(p_rid); while (scenario->instances.first()) { instance_set_scenario(scenario->instances.first()->self()->self, RID()); @@ -3490,7 +3490,7 @@ bool VisualServerScene::free(RID p_rid) { update_dirty_instances(); - Instance *instance = instance_owner.get(p_rid); + Instance *instance = instance_owner.getornull(p_rid); instance_set_use_lightmap(p_rid, RID(), RID()); instance_set_scenario(p_rid, RID()); diff --git a/servers/visual/visual_server_scene.h b/servers/visual/visual_server_scene.h index a174d9e616ef..a2d65791a06b 100644 --- a/servers/visual/visual_server_scene.h +++ b/servers/visual/visual_server_scene.h @@ -37,6 +37,7 @@ #include "core/math/octree.h" #include "core/os/semaphore.h" #include "core/os/thread.h" +#include "core/rid_owner.h" #include "core/self_list.h" #include "servers/arvr/arvr_interface.h" @@ -57,7 +58,7 @@ class VisualServerScene { /* CAMERA API */ - struct Camera : public RID_Data { + struct Camera { enum Type { PERSPECTIVE, @@ -88,7 +89,7 @@ class VisualServerScene { } }; - mutable RID_Owner camera_owner; + mutable RID_PtrOwner camera_owner; virtual RID camera_create(); virtual void camera_set_perspective(RID p_camera, float p_fovy_degrees, float p_z_near, float p_z_far); @@ -103,7 +104,7 @@ class VisualServerScene { struct Instance; - struct Scenario : RID_Data { + struct Scenario { VS::ScenarioDebugMode debug; RID self; @@ -121,7 +122,7 @@ class VisualServerScene { Scenario() { debug = VS::SCENARIO_DEBUG_DISABLED; } }; - mutable RID_Owner scenario_owner; + mutable RID_PtrOwner scenario_owner; static void *_instance_pair(void *p_self, OctreeElementID, Instance *p_A, int, OctreeElementID, Instance *p_B, int); static void _instance_unpair(void *p_self, OctreeElementID, Instance *p_A, int, OctreeElementID, Instance *p_B, int, void *); @@ -432,7 +433,7 @@ class VisualServerScene { RID reflection_probe_instance_cull_result[MAX_REFLECTION_PROBES_CULLED]; int reflection_probe_cull_count; - RID_Owner instance_owner; + RID_PtrOwner instance_owner; virtual RID instance_create(); diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp index b9cdceead052..e05eb4d52390 100644 --- a/servers/visual/visual_server_viewport.cpp +++ b/servers/visual/visual_server_viewport.cpp @@ -84,7 +84,7 @@ void VisualServerViewport::_draw_viewport(Viewport *p_viewport, ARVRInterface::E if (!p_viewport->hide_canvas && !p_viewport->disable_environment && VSG::scene->scenario_owner.owns(p_viewport->scenario)) { - VisualServerScene::Scenario *scenario = VSG::scene->scenario_owner.get(p_viewport->scenario); + VisualServerScene::Scenario *scenario = VSG::scene->scenario_owner.getornull(p_viewport->scenario); ERR_FAIL_COND(!scenario); if (VSG::scene_render->is_environment(scenario->environment)) { scenario_draw_canvas_bg = VSG::scene_render->environment_get_background(scenario->environment) == VS::ENV_BG_CANVAS; diff --git a/servers/visual/visual_server_viewport.h b/servers/visual/visual_server_viewport.h index e8d36f70af9c..f701e3612a25 100644 --- a/servers/visual/visual_server_viewport.h +++ b/servers/visual/visual_server_viewport.h @@ -31,6 +31,7 @@ #ifndef VISUALSERVERVIEWPORT_H #define VISUALSERVERVIEWPORT_H +#include "core/rid_owner.h" #include "core/self_list.h" #include "rasterizer.h" #include "servers/arvr/arvr_interface.h" @@ -38,10 +39,10 @@ class VisualServerViewport { public: - struct CanvasBase : public RID_Data { + struct CanvasBase { }; - struct Viewport : public RID_Data { + struct Viewport { RID self; RID parent; @@ -127,7 +128,7 @@ class VisualServerViewport { } }; - mutable RID_Owner viewport_owner; + mutable RID_PtrOwner viewport_owner; struct ViewportSort { _FORCE_INLINE_ bool operator()(const Viewport *p_left, const Viewport *p_right) const {