diff options
author | Juan Linietsky <juan@godotengine.org> | 2020-02-12 14:24:06 -0300 |
---|---|---|
committer | Juan Linietsky <juan@godotengine.org> | 2020-02-12 14:24:54 -0300 |
commit | cf8c679a23b21d6c6f29cba6a54eaa2eed88bf92 (patch) | |
tree | 52aca947b395362b2addec4843915b15947c32ca /modules | |
parent | 4aa31a2851e3dd5b67193194f899850239b2669d (diff) |
ObjectID converted to a structure, fixes many bugs where used incorrectly as 32 bits.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/bullet/area_bullet.cpp | 6 | ||||
-rw-r--r-- | modules/bullet/area_bullet.h | 3 | ||||
-rw-r--r-- | modules/bullet/bullet_physics_server.cpp | 14 | ||||
-rw-r--r-- | modules/bullet/bullet_physics_server.h | 4 | ||||
-rw-r--r-- | modules/bullet/collision_object_bullet.cpp | 2 | ||||
-rw-r--r-- | modules/bullet/godot_result_callbacks.cpp | 4 | ||||
-rw-r--r-- | modules/bullet/rigid_body_bullet.cpp | 4 | ||||
-rw-r--r-- | modules/bullet/space_bullet.cpp | 2 | ||||
-rw-r--r-- | modules/gdnative/gdnative/gdnative.cpp | 2 | ||||
-rw-r--r-- | modules/gdnative/gdnative/string.cpp | 7 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/gdnative.h | 2 | ||||
-rw-r--r-- | modules/gdnavigation/gd_navigation_server.cpp | 2 | ||||
-rw-r--r-- | modules/gdnavigation/rvo_agent.cpp | 8 | ||||
-rw-r--r-- | modules/gdscript/gdscript_function.cpp | 6 | ||||
-rw-r--r-- | modules/gdscript/gdscript_functions.cpp | 2 | ||||
-rw-r--r-- | modules/visual_script/visual_script.cpp | 8 | ||||
-rw-r--r-- | modules/visual_script/visual_script_property_selector.cpp | 6 |
17 files changed, 40 insertions, 42 deletions
diff --git a/modules/bullet/area_bullet.cpp b/modules/bullet/area_bullet.cpp index 8d03a99556..7806145390 100644 --- a/modules/bullet/area_bullet.cpp +++ b/modules/bullet/area_bullet.cpp @@ -107,7 +107,7 @@ void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer: Object *areaGodoObject = ObjectDB::get_instance(event.event_callback_id); if (!areaGodoObject) { - event.event_callback_id = 0; + event.event_callback_id = ObjectID(); return; } @@ -279,7 +279,7 @@ void AreaBullet::set_event_callback(Type p_callbackObjectType, ObjectID p_id, co ev.event_callback_method = p_method; /// Set if monitoring - if (eventsCallbacks[0].event_callback_id || eventsCallbacks[1].event_callback_id) { + if (eventsCallbacks[0].event_callback_id.is_valid() || eventsCallbacks[1].event_callback_id.is_valid()) { set_godot_object_flags(get_godot_object_flags() | GOF_IS_MONITORING_AREA); } else { set_godot_object_flags(get_godot_object_flags() & (~GOF_IS_MONITORING_AREA)); @@ -287,7 +287,7 @@ void AreaBullet::set_event_callback(Type p_callbackObjectType, ObjectID p_id, co } bool AreaBullet::has_event_callback(Type p_callbackObjectType) { - return eventsCallbacks[static_cast<int>(p_callbackObjectType)].event_callback_id; + return eventsCallbacks[static_cast<int>(p_callbackObjectType)].event_callback_id.is_valid(); } void AreaBullet::on_enter_area(AreaBullet *p_area) { diff --git a/modules/bullet/area_bullet.h b/modules/bullet/area_bullet.h index f770c63bcc..18888c6725 100644 --- a/modules/bullet/area_bullet.h +++ b/modules/bullet/area_bullet.h @@ -50,8 +50,7 @@ public: ObjectID event_callback_id; StringName event_callback_method; - InOutEventCallback() : - event_callback_id(0) {} + InOutEventCallback() {} }; enum OverlapState { diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index fceb5d2b4b..89868babc6 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -359,7 +359,7 @@ void BulletPhysicsServer::area_attach_object_instance_id(RID p_area, ObjectID p_ ObjectID BulletPhysicsServer::area_get_object_instance_id(RID p_area) const { if (space_owner.owns(p_area)) { - return 0; + return ObjectID(); } AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND_V(!area, ObjectID()); @@ -428,14 +428,14 @@ void BulletPhysicsServer::area_set_monitor_callback(RID p_area, Object *p_receiv 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); + area->set_event_callback(CollisionObjectBullet::TYPE_RIGID_BODY, p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method); } void BulletPhysicsServer::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) { 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); + area->set_event_callback(CollisionObjectBullet::TYPE_AREA, p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method); } void BulletPhysicsServer::area_set_ray_pickable(RID p_area, bool p_enable) { @@ -569,16 +569,16 @@ void BulletPhysicsServer::body_clear_shapes(RID p_body) { body->remove_all_shapes(); } -void BulletPhysicsServer::body_attach_object_instance_id(RID p_body, uint32_t p_id) { +void BulletPhysicsServer::body_attach_object_instance_id(RID p_body, ObjectID p_id) { CollisionObjectBullet *body = get_collisin_object(p_body); ERR_FAIL_COND(!body); body->set_instance_id(p_id); } -uint32_t BulletPhysicsServer::body_get_object_instance_id(RID p_body) const { +ObjectID BulletPhysicsServer::body_get_object_instance_id(RID p_body) const { CollisionObjectBullet *body = get_collisin_object(p_body); - ERR_FAIL_COND_V(!body, 0); + ERR_FAIL_COND_V(!body, ObjectID()); return body->get_instance_id(); } @@ -844,7 +844,7 @@ bool BulletPhysicsServer::body_is_omitting_force_integration(RID p_body) const { 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.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); + body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(), p_method, p_udata); } void BulletPhysicsServer::body_set_ray_pickable(RID p_body, bool p_enable) { diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h index 22032d32e3..6ea9a7a974 100644 --- a/modules/bullet/bullet_physics_server.h +++ b/modules/bullet/bullet_physics_server.h @@ -189,8 +189,8 @@ public: virtual void body_clear_shapes(RID p_body); // Used for Rigid and Soft Bodies - virtual void body_attach_object_instance_id(RID p_body, uint32_t p_id); - virtual uint32_t body_get_object_instance_id(RID p_body) const; + virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id); + virtual ObjectID body_get_object_instance_id(RID p_body) const; virtual void body_set_enable_continuous_collision_detection(RID p_body, bool p_enable); virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const; diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp index c916c65d2b..5b7e7281e4 100644 --- a/modules/bullet/collision_object_bullet.cpp +++ b/modules/bullet/collision_object_bullet.cpp @@ -90,7 +90,7 @@ void CollisionObjectBullet::ShapeWrapper::claim_bt_shape(const btVector3 &body_s CollisionObjectBullet::CollisionObjectBullet(Type p_type) : RIDBullet(), type(p_type), - instance_id(0), + instance_id(ObjectID()), collisionLayer(0), collisionMask(0), collisionsEnabled(true), diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp index 6e54d10abf..20467e3ef3 100644 --- a/modules/bullet/godot_result_callbacks.cpp +++ b/modules/bullet/godot_result_callbacks.cpp @@ -112,7 +112,7 @@ btScalar GodotAllConvexResultCallback::addSingleResult(btCollisionWorld::LocalCo result.shape = convexResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID result.rid = gObj->get_self(); result.collider_id = gObj->get_instance_id(); - result.collider = 0 == result.collider_id ? NULL : ObjectDB::get_instance(result.collider_id); + result.collider = result.collider_id.is_null() ? NULL : ObjectDB::get_instance(result.collider_id); ++count; return 1; // not used by bullet @@ -220,7 +220,7 @@ btScalar GodotAllContactResultCallback::addSingleResult(btManifoldPoint &cp, con } result.collider_id = colObj->get_instance_id(); - result.collider = 0 == result.collider_id ? NULL : ObjectDB::get_instance(result.collider_id); + result.collider = result.collider_id.is_null() ? NULL : ObjectDB::get_instance(result.collider_id); result.rid = colObj->get_self(); ++m_count; } diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index dfc9647813..e5804fbde8 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -366,7 +366,7 @@ void RigidBodyBullet::dispatch_callbacks() { Object *obj = ObjectDB::get_instance(force_integration_callback->id); if (!obj) { // Remove integration callback - set_force_integration_callback(0, StringName()); + set_force_integration_callback(ObjectID(), StringName()); } else { const Variant *vp[2] = { &variantBodyDirect, &force_integration_callback->udata }; @@ -395,7 +395,7 @@ void RigidBodyBullet::set_force_integration_callback(ObjectID p_id, const String force_integration_callback = NULL; } - if (p_id != 0) { + if (p_id.is_valid()) { force_integration_callback = memnew(ForceIntegrationCallback); force_integration_callback->id = p_id; force_integration_callback->method = p_method; diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index 69f3d1b393..0e4c4b4731 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -108,7 +108,7 @@ bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const V r_result.shape = btResult.m_shapeId; r_result.rid = gObj->get_self(); r_result.collider_id = gObj->get_instance_id(); - r_result.collider = 0 == r_result.collider_id ? NULL : ObjectDB::get_instance(r_result.collider_id); + r_result.collider = r_result.collider_id.is_null() ? NULL : ObjectDB::get_instance(r_result.collider_id); } else { WARN_PRINT("The raycast performed has hit a collision object that is not part of Godot scene, please check it."); } diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp index 06334556d9..bb868d3b52 100644 --- a/modules/gdnative/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative/gdnative.cpp @@ -171,7 +171,7 @@ bool GDAPI godot_is_instance_valid(const godot_object *p_object) { } godot_object GDAPI *godot_instance_from_id(godot_int p_instance_id) { - return (godot_object *)ObjectDB::get_instance((ObjectID)p_instance_id); + return (godot_object *)ObjectDB::get_instance(ObjectID(p_instance_id)); } void *godot_get_class_tag(const godot_string_name *p_class) { diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index 414b9b9eaf..59901f6139 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -250,7 +250,12 @@ godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, co keys.write[i] = (*keys_proxy)[i]; } - return self->findmk(keys, p_from, r_key); + int key; + int ret = self->findmk(keys, p_from, &key); + if (r_key) { + *r_key = key; + } + return ret; } godot_int GDAPI godot_string_findn(const godot_string *p_self, godot_string p_what) { diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h index e19a2ec149..6fd0bdc87f 100644 --- a/modules/gdnative/include/gdnative/gdnative.h +++ b/modules/gdnative/include/gdnative/gdnative.h @@ -127,7 +127,7 @@ typedef bool godot_bool; /////// int -typedef int godot_int; +typedef int64_t godot_int; /////// real diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp index ddfb3c10fa..2780e2a931 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/gdnavigation/gd_navigation_server.cpp @@ -374,7 +374,7 @@ COMMAND_4(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_ 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); + agent->set_callback(p_receiver == NULL ? ObjectID() : p_receiver->get_instance_id(), p_method, p_udata); if (agent->get_map()) { if (p_receiver == NULL) { diff --git a/modules/gdnavigation/rvo_agent.cpp b/modules/gdnavigation/rvo_agent.cpp index eb66eb3a05..4d19bc15af 100644 --- a/modules/gdnavigation/rvo_agent.cpp +++ b/modules/gdnavigation/rvo_agent.cpp @@ -38,7 +38,7 @@ RvoAgent::RvoAgent() : map(NULL) { - callback.id = ObjectID(0); + callback.id = ObjectID(); } void RvoAgent::set_map(NavMap *p_map) { @@ -62,16 +62,16 @@ void RvoAgent::set_callback(ObjectID p_id, const StringName p_method, const Vari } bool RvoAgent::has_callback() const { - return callback.id != 0; + return callback.id.is_valid(); } void RvoAgent::dispatch_callback() { - if (callback.id == 0) { + if (callback.id.is_null()) { return; } Object *obj = ObjectDB::get_instance(callback.id); if (obj == NULL) { - callback.id = ObjectID(0); + callback.id = ObjectID(); } Variant::CallError responseCallError; diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 452b1933eb..7392bbc10a 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -1274,7 +1274,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a gdfs->state.script = Ref<GDScript>(_script); gdfs->state.ip = ip + ipofs; gdfs->state.line = line; - gdfs->state.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_id() : 0; + gdfs->state.instance_id = (p_instance && p_instance->get_owner()) ? p_instance->get_owner()->get_instance_id() : ObjectID(); //gdfs->state.result_pos=ip+ipofs-1; gdfs->state.defarg = defarg; gdfs->state.instance = p_instance; @@ -1829,7 +1829,7 @@ bool GDScriptFunctionState::is_valid(bool p_extended_check) const { if (p_extended_check) { //class instance gone? - if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) + if (state.instance_id.is_valid() && !ObjectDB::get_instance(state.instance_id)) return false; } @@ -1839,7 +1839,7 @@ bool GDScriptFunctionState::is_valid(bool p_extended_check) const { Variant GDScriptFunctionState::resume(const Variant &p_arg) { ERR_FAIL_COND_V(!function, Variant()); - if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) { + if (state.instance_id.is_valid() && !ObjectDB::get_instance(state.instance_id)) { #ifdef DEBUG_ENABLED ERR_FAIL_V_MSG(Variant(), "Resumed function '" + String(function->get_name()) + "()' after yield, but class instance is gone. At script: " + state.script->get_path() + ":" + itos(state.line)); #else diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index c398633dc5..27d67fda6d 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -1374,7 +1374,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ break; } - uint32_t id = *p_args[0]; + ObjectID id = *p_args[0]; r_ret = ObjectDB::get_instance(id); } break; diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index be7443adfa..e712190344 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -2414,8 +2414,8 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int #ifdef DEBUG_ENABLED - ERR_FAIL_COND_V_MSG(instance_id && !ObjectDB::get_instance(instance_id), Variant(), "Resumed after yield, but class instance is gone."); - ERR_FAIL_COND_V_MSG(script_id && !ObjectDB::get_instance(script_id), Variant(), "Resumed after yield, but script is gone."); + ERR_FAIL_COND_V_MSG(instance_id.is_valid() && !ObjectDB::get_instance(instance_id), Variant(), "Resumed after yield, but class instance is gone."); + ERR_FAIL_COND_V_MSG(script_id.is_valid() && !ObjectDB::get_instance(script_id), Variant(), "Resumed after yield, but script is gone."); #endif @@ -2476,8 +2476,8 @@ Variant VisualScriptFunctionState::resume(Array p_args) { ERR_FAIL_COND_V(function == StringName(), Variant()); #ifdef DEBUG_ENABLED - ERR_FAIL_COND_V_MSG(instance_id && !ObjectDB::get_instance(instance_id), Variant(), "Resumed after yield, but class instance is gone."); - ERR_FAIL_COND_V_MSG(script_id && !ObjectDB::get_instance(script_id), Variant(), "Resumed after yield, but script is gone."); + ERR_FAIL_COND_V_MSG(instance_id.is_valid() && !ObjectDB::get_instance(instance_id), Variant(), "Resumed after yield, but class instance is gone."); + ERR_FAIL_COND_V_MSG(script_id.is_valid() && !ObjectDB::get_instance(script_id), Variant(), "Resumed after yield, but script is gone."); #endif diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp index e629175094..e8c02a41c4 100644 --- a/modules/visual_script/visual_script_property_selector.cpp +++ b/modules/visual_script/visual_script_property_selector.cpp @@ -529,7 +529,6 @@ void VisualScriptPropertySelector::select_method_from_base_type(const String &p_ base_type = p_base; selected = p_current; type = Variant::NIL; - script = 0; properties = false; instance = NULL; virtuals_only = p_virtuals_only; @@ -554,7 +553,6 @@ void VisualScriptPropertySelector::select_from_base_type(const String &p_base, c base_type = p_base; selected = p_current; type = Variant::NIL; - script = 0; properties = true; visual_script_generic = false; instance = NULL; @@ -601,7 +599,6 @@ void VisualScriptPropertySelector::select_from_basic_type(Variant::Type p_type, base_type = ""; selected = p_current; type = p_type; - script = 0; properties = true; visual_script_generic = false; instance = NULL; @@ -623,7 +620,6 @@ void VisualScriptPropertySelector::select_from_action(const String &p_type, cons base_type = p_type; selected = p_current; type = Variant::NIL; - script = 0; properties = false; visual_script_generic = false; instance = NULL; @@ -645,7 +641,6 @@ void VisualScriptPropertySelector::select_from_instance(Object *p_instance, cons base_type = p_basetype; selected = p_current; type = Variant::NIL; - script = 0; properties = true; visual_script_generic = false; instance = p_instance; @@ -667,7 +662,6 @@ void VisualScriptPropertySelector::select_from_visual_script(const String &p_bas base_type = p_base; selected = ""; type = Variant::NIL; - script = 0; properties = true; visual_script_generic = true; instance = NULL; |