From 251f9e6e2a83bca7b201ad982aa9407ded944272 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 12 Dec 2019 16:44:43 +0100 Subject: [PATCH] Added a son_physics_process callback to spells, spell scripts can register for it in entities. --- data/spell.cpp | 10 ++++++++++ data/spell.h | 1 + entities/entity.cpp | 27 ++++++++++++++++++++++----- entities/entity.h | 15 ++++++++++----- infos/spell_cast_info.cpp | 6 ++++++ infos/spell_cast_info.h | 2 ++ 6 files changed, 51 insertions(+), 10 deletions(-) diff --git a/data/spell.cpp b/data/spell.cpp index b079212..4075161 100644 --- a/data/spell.cpp +++ b/data/spell.cpp @@ -616,6 +616,14 @@ void Spell::son_spell_hit(Ref info) { } } +void Spell::son_physics_process(Ref info, float delta) { + ERR_FAIL_COND(!info.is_valid()); + + if (has_method("_son_physics_process")) { + call("_son_physics_process", info, delta); + } +} + void Spell::con_spell_cast_started(Ref info) { ERR_FAIL_COND(!info.is_valid()); @@ -822,10 +830,12 @@ void Spell::_bind_methods() { ClassDB::bind_method(D_METHOD("son_cast_player_moved", "info"), &Spell::son_cast_player_moved); ClassDB::bind_method(D_METHOD("son_cast_damage_received", "info"), &Spell::son_cast_damage_received); ClassDB::bind_method(D_METHOD("son_spell_hit", "info"), &Spell::son_spell_hit); + ClassDB::bind_method(D_METHOD("son_physics_process", "info", "delta"), &Spell::son_physics_process); BIND_VMETHOD(MethodInfo("_son_cast_player_moved", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo"))); BIND_VMETHOD(MethodInfo("_son_cast_damage_received", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo"))); BIND_VMETHOD(MethodInfo("_son_spell_hit", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo"))); + BIND_VMETHOD(MethodInfo("_son_physics_process", PropertyInfo(Variant::OBJECT, "info", PROPERTY_HINT_RESOURCE_TYPE, "SpellCastInfo"), PropertyInfo(Variant::REAL, "delta"))); //Clientside Event Handlers ClassDB::bind_method(D_METHOD("con_spell_cast_started", "info"), &Spell::con_spell_cast_started); diff --git a/data/spell.h b/data/spell.h index e84bae3..4f9273b 100644 --- a/data/spell.h +++ b/data/spell.h @@ -307,6 +307,7 @@ public: void son_cast_player_moved(Ref info); void son_cast_damage_received(Ref info); void son_spell_hit(Ref info); + void son_physics_process(Ref info, float delta); //Clientside Event Handlers void con_spell_cast_started(Ref info); diff --git a/entities/entity.cpp b/entities/entity.cpp index 65d2424..0660fa9 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -2503,15 +2503,24 @@ void Entity::con_gcd_finished() { } } -void Entity::son_physics_process() { - //if (has_method("_son_category_cooldown_removed")) - // call("_son_category_cooldown_removed", category_cooldown); - +void Entity::son_physics_process(float delta) { for (int i = 0; i < _s_auras.size(); ++i) { Ref ad = _s_auras.get(i); ad->get_aura()->son_physics_process(ad); } + + if (_physics_process_scis.size() > 0) { + for (int i = 0; i < _physics_process_scis.size(); ++i) { + Ref sci = _physics_process_scis.get(i); + + ERR_CONTINUE(!sci.is_valid()); + + sci->physics_process(delta); + } + + _physics_process_scis.clear(); + } } void Entity::son_xp_gained(int value) { @@ -5044,6 +5053,10 @@ Dictionary Entity::data_as_dict(String &data) { return d; } +void Entity::register_for_physics_process(Ref info) { + _physics_process_scis.push_back(info); +} + Entity::Entity() { _deserialized = false; @@ -5379,6 +5392,8 @@ Entity::~Entity() { _s_ai.unref(); _s_pets.clear(); + + _physics_process_scis.clear(); } void Entity::_notification(int p_what) { @@ -5401,7 +5416,7 @@ void Entity::_notification(int p_what) { update(get_process_delta_time()); } break; case NOTIFICATION_PHYSICS_PROCESS: { - son_physics_process(); + son_physics_process(get_physics_process_delta_time()); } break; case NOTIFICATION_EXIT_TREE: { for (int i = 0; i < _s_seen_by.size(); ++i) { @@ -6347,4 +6362,6 @@ void Entity::_bind_methods() { mi.name = "vrpc"; ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "vrpc", &Entity::_vrpc_bind, mi); + + ClassDB::bind_method(D_METHOD("register_for_physics_process", "info"), &Entity::register_for_physics_process); } diff --git a/entities/entity.h b/entities/entity.h index a3a6436..41a442c 100644 --- a/entities/entity.h +++ b/entities/entity.h @@ -448,7 +448,7 @@ public: void con_gcd_started(); void con_gcd_finished(); - void son_physics_process(); + void son_physics_process(float delta); void son_xp_gained(int value); void son_level_up(int value); @@ -886,6 +886,8 @@ public: Dictionary data_as_dict(String &data); + void register_for_physics_process(Ref info); + Entity(); ~Entity(); @@ -1057,12 +1059,11 @@ private: Ref _s_target_bag; Ref _c_target_bag; - //AI + // AI bool _s_is_pet; Entity *_s_pet_owner; - int _s_pet_formation_index; EntityEnums::PetStates _s_pet_state; @@ -1070,15 +1071,19 @@ private: Ref _s_ai; - //Pets + // Pets Vector _s_pets; Vector _c_pets; - //Networking + // Networking Vector _s_sees; Vector _s_seen_by; + + // Callbacks + + Vector > _physics_process_scis; }; #endif diff --git a/infos/spell_cast_info.cpp b/infos/spell_cast_info.cpp index 0edeef4..73f0a78 100644 --- a/infos/spell_cast_info.cpp +++ b/infos/spell_cast_info.cpp @@ -124,6 +124,12 @@ bool SpellCastInfo::update_cast_time(float delta) { return false; } +void SpellCastInfo::physics_process(float delta) { + ERR_FAIL_COND(!_spell.is_valid()); + + _spell->son_physics_process(Ref(this), delta); +} + void SpellCastInfo::resolve_references(Node *owner) { ERR_FAIL_COND(!ObjectDB::instance_validate(owner)); ERR_FAIL_COND(!owner->is_inside_tree()); diff --git a/infos/spell_cast_info.h b/infos/spell_cast_info.h index 448939f..b74cb1b 100644 --- a/infos/spell_cast_info.h +++ b/infos/spell_cast_info.h @@ -42,6 +42,8 @@ public: bool update_cast_time(float delta); + void physics_process(float delta); + void resolve_references(Node *owner); Dictionary to_dict(); void from_dict(const Dictionary &dict);