From 43029f7d6780c1b0f1182ca179e4f08bd70e418d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordan=20Bri=C3=A8re?= Date: Tue, 22 Sep 2020 15:53:37 -0400 Subject: [PATCH 1/5] Added networked variants of the entity listeners. --- .../developing/module_tutorials/listeners.rst | 58 +++++++++++++++++++ .../packages/source-python/entities/_base.py | 14 ++--- .../source-python/entities/dictionary.py | 30 +++++----- .../packages/source-python/entities/hooks.py | 12 ++-- .../source-python/listeners/__init__.py | 28 +++++++++ src/core/modules/listeners/listeners_wrap.cpp | 8 +++ src/core/sp_main.cpp | 28 ++++++++- 7 files changed, 145 insertions(+), 33 deletions(-) diff --git a/addons/source-python/docs/source-python/source/developing/module_tutorials/listeners.rst b/addons/source-python/docs/source-python/source/developing/module_tutorials/listeners.rst index ce79c9bb1..1875e262a 100644 --- a/addons/source-python/docs/source-python/source/developing/module_tutorials/listeners.rst +++ b/addons/source-python/docs/source-python/source/developing/module_tutorials/listeners.rst @@ -202,6 +202,20 @@ Called when an entity has been created. pass +OnNetworkedEntityCreated +--------------- + +Called when a networked entity has been created. + +.. code-block:: python + + from listeners import OnNetworkedEntityCreated + + @OnNetworkedEntityCreated + def on_networked_entity_created(index): + pass + + OnEntityDeleted --------------- @@ -216,6 +230,20 @@ Called when an entity gets deleted. pass +OnNetworkedEntityDeleted +--------------- + +Called when a networked entity gets deleted. + +.. code-block:: python + + from listeners import OnNetworkedEntityDeleted + + @OnNetworkedEntityDeleted + def on_networked_entity_deleted(index): + pass + + OnEntityOutput -------------- @@ -252,6 +280,22 @@ Called before an entity has been spawned. .. note:: This listener gets only called in Black Mesa: Source. +OnNetworkedEntityPreSpawned +------------------ + +Called before a networked entity has been spawned. + +.. code-block:: python + + from listeners import OnNetworkedEntityPreSpawned + + @OnNetworkedEntityPreSpawned + def on_networked_entity_pre_spawned(index): + pass + +.. note:: This listener gets only called in Black Mesa: Source. + + OnEntitySpawned --------------- @@ -266,6 +310,20 @@ Called when an entity has been spawned. pass +OnNetworkedEntitySpawned +--------------- + +Called when a networked entity has been spawned. + +.. code-block:: python + + from listeners import OnNetworkedEntitySpawned + + @OnNetworkedEntitySpawned + def on_networked_entity_spawned(index): + pass + + OnLevelInit ----------- diff --git a/addons/source-python/packages/source-python/entities/_base.py b/addons/source-python/packages/source-python/entities/_base.py index eec4b211a..346004a0c 100644 --- a/addons/source-python/packages/source-python/entities/_base.py +++ b/addons/source-python/packages/source-python/entities/_base.py @@ -785,18 +785,12 @@ def set_parent(self, parent, attachment=INVALID_ATTACHMENT_INDEX): # ============================================================================= # NOTE: This callback is called by sp_main.cpp after all registered entity # deletion listeners have been called. -def _on_entity_deleted(base_entity): - """Called when an entity is removed. +def _on_networked_entity_deleted(index): + """Called when a networked entity is removed. - :param BaseEntity base_entity: - The removed entity. + :param int index: + The removed entity index. """ - try: - # Get the index of the entity... - index = base_entity.index - except ValueError: - return - # Loop through all delays... for delay in _entity_delays.pop(index, ()): diff --git a/addons/source-python/packages/source-python/entities/dictionary.py b/addons/source-python/packages/source-python/entities/dictionary.py index 922e361dd..45d1ad364 100644 --- a/addons/source-python/packages/source-python/entities/dictionary.py +++ b/addons/source-python/packages/source-python/entities/dictionary.py @@ -16,7 +16,7 @@ from entities.entity import Entity from entities.helpers import index_from_inthandle # Listeners -from listeners import on_entity_deleted_listener_manager +from listeners import on_networked_entity_deleted_listener_manager # ============================================================================ @@ -42,8 +42,8 @@ def __init__(self, factory=Entity, *args, **kwargs): self._kwargs = kwargs # Register our OnEntityDeleted listener... - on_entity_deleted_listener_manager.register_listener( - self._on_entity_deleted) + on_networked_entity_deleted_listener_manager.register_listener( + self._on_networked_entity_deleted) # Initialize the dictionary... super().__init__() @@ -79,22 +79,24 @@ def from_inthandle(self, inthandle): def on_automatically_removed(self, index): """Called when an index is automatically removed.""" - def _on_entity_deleted(self, base_entity): - """OnEntityDeleted listener callback.""" - try: - # Get the index of the entity... - index = base_entity.index - except ValueError: + def _on_networked_entity_deleted(self, index): + """Internal networked entity deletion callback. + + :param int index: + The index of the networked entity being removed. + """ + # No need to go further if there is no object associated to this index + if index not in self: return - if index in self: + try: # Call the deletion callback for the index... self.on_automatically_removed(index) - + finally: # Remove the index from the dictionary... super().__delitem__(index) def _unload_instance(self): - """Unregister our OnEntityDeleted listener.""" - on_entity_deleted_listener_manager.unregister_listener( - self._on_entity_deleted) + """Unregister our networked entity deletion listener.""" + on_networked_entity_deleted_listener_manager.unregister_listener( + self._on_networked_entity_deleted) diff --git a/addons/source-python/packages/source-python/entities/hooks.py b/addons/source-python/packages/source-python/entities/hooks.py index 1ae44f2c5..940924ca2 100644 --- a/addons/source-python/packages/source-python/entities/hooks.py +++ b/addons/source-python/packages/source-python/entities/hooks.py @@ -14,7 +14,7 @@ # Filters from filters.entities import EntityIter # Listeners -from listeners import OnEntityCreated +from listeners import OnNetworkedEntityCreated # Entities from entities.entity import Entity # Players @@ -219,9 +219,7 @@ def initialize(self, index): # ============================================================================= # >> LISTENERS # ============================================================================= -@OnEntityCreated -def on_entity_created(base_entity): - """Called when a new entity has been created.""" - if not base_entity.is_networked(): - return - _waiting_entity_hooks.initialize(base_entity.index) +@OnNetworkedEntityCreated +def on_networked_entity_created(index): + """Called when a new networked entity has been created.""" + _waiting_entity_hooks.initialize(index) diff --git a/addons/source-python/packages/source-python/listeners/__init__.py b/addons/source-python/packages/source-python/listeners/__init__.py index d1682744e..e665febe5 100644 --- a/addons/source-python/packages/source-python/listeners/__init__.py +++ b/addons/source-python/packages/source-python/listeners/__init__.py @@ -58,9 +58,13 @@ from _listeners import on_edict_allocated_listener_manager from _listeners import on_edict_freed_listener_manager from _listeners import on_entity_pre_spawned_listener_manager +from _listeners import on_networked_entity_pre_spawned_listener_manager from _listeners import on_entity_created_listener_manager +from _listeners import on_networked_entity_created_listener_manager from _listeners import on_entity_spawned_listener_manager +from _listeners import on_networked_entity_spawned_listener_manager from _listeners import on_entity_deleted_listener_manager +from _listeners import on_networked_entity_deleted_listener_manager from _listeners import on_data_loaded_listener_manager from _listeners import on_combiner_pre_cache_listener_manager from _listeners import on_data_unloaded_listener_manager @@ -355,24 +359,48 @@ class OnEntityPreSpawned(ListenerManagerDecorator): manager = on_entity_pre_spawned_listener_manager +class OnNetworkedEntityPreSpawned(ListenerManagerDecorator): + """Register/unregister a OnNetworkedEntityPreSpawned listener.""" + + manager = on_networked_entity_pre_spawned_listener_manager + + class OnEntityCreated(ListenerManagerDecorator): """Register/unregister a OnEntityCreated listener.""" manager = on_entity_created_listener_manager +class OnNetworkedEntityCreated(ListenerManagerDecorator): + """Register/unregister a OnNetworkedEntityCreated listener.""" + + manager = on_networked_entity_created_listener_manager + + class OnEntitySpawned(ListenerManagerDecorator): """Register/unregister a OnEntitySpawned listener.""" manager = on_entity_spawned_listener_manager +class OnNetworkedEntitySpawned(ListenerManagerDecorator): + """Register/unregister a OnNetworkedEntitySpawned listener.""" + + manager = on_networked_entity_spawned_listener_manager + + class OnEntityDeleted(ListenerManagerDecorator): """Register/unregister a OnEntityDeleted listener.""" manager = on_entity_deleted_listener_manager +class OnNetworkedEntityDeleted(ListenerManagerDecorator): + """Register/unregister a OnNetworkedEntityDeleted listener.""" + + manager = on_networked_entity_deleted_listener_manager + + class OnDataLoaded(ListenerManagerDecorator): """Register/unregister a OnDataLoaded listener.""" diff --git a/src/core/modules/listeners/listeners_wrap.cpp b/src/core/modules/listeners/listeners_wrap.cpp index 1bfc1546f..d40f48b41 100644 --- a/src/core/modules/listeners/listeners_wrap.cpp +++ b/src/core/modules/listeners/listeners_wrap.cpp @@ -51,9 +51,13 @@ DEFINE_MANAGER_ACCESSOR(OnQueryCvarValueFinished) DEFINE_MANAGER_ACCESSOR(OnServerActivate) DEFINE_MANAGER_ACCESSOR(OnTick) DEFINE_MANAGER_ACCESSOR(OnEntityPreSpawned) +DEFINE_MANAGER_ACCESSOR(OnNetworkedEntityPreSpawned) DEFINE_MANAGER_ACCESSOR(OnEntityCreated) +DEFINE_MANAGER_ACCESSOR(OnNetworkedEntityCreated) DEFINE_MANAGER_ACCESSOR(OnEntitySpawned) +DEFINE_MANAGER_ACCESSOR(OnNetworkedEntitySpawned) DEFINE_MANAGER_ACCESSOR(OnEntityDeleted) +DEFINE_MANAGER_ACCESSOR(OnNetworkedEntityDeleted) DEFINE_MANAGER_ACCESSOR(OnDataLoaded) DEFINE_MANAGER_ACCESSOR(OnCombinerPreCache) DEFINE_MANAGER_ACCESSOR(OnDataUnloaded) @@ -153,9 +157,13 @@ void export_listener_managers(scope _listeners) _listeners.attr("on_tick_listener_manager") = object(ptr(GetOnTickListenerManager())); _listeners.attr("on_entity_pre_spawned_listener_manager") = object(ptr(GetOnEntityPreSpawnedListenerManager())); + _listeners.attr("on_networked_entity_pre_spawned_listener_manager") = object(ptr(GetOnNetworkedEntityPreSpawnedListenerManager())); _listeners.attr("on_entity_created_listener_manager") = object(ptr(GetOnEntityCreatedListenerManager())); + _listeners.attr("on_networked_entity_created_listener_manager") = object(ptr(GetOnNetworkedEntityCreatedListenerManager())); _listeners.attr("on_entity_spawned_listener_manager") = object(ptr(GetOnEntitySpawnedListenerManager())); + _listeners.attr("on_networked_entity_spawned_listener_manager") = object(ptr(GetOnNetworkedEntitySpawnedListenerManager())); _listeners.attr("on_entity_deleted_listener_manager") = object(ptr(GetOnEntityDeletedListenerManager())); + _listeners.attr("on_networked_entity_deleted_listener_manager") = object(ptr(GetOnNetworkedEntityDeletedListenerManager())); _listeners.attr("on_data_loaded_listener_manager") = object(ptr(GetOnDataLoadedListenerManager())); _listeners.attr("on_combiner_pre_cache_listener_manager") = object(ptr(GetOnCombinerPreCacheListenerManager())); diff --git a/src/core/sp_main.cpp b/src/core/sp_main.cpp index 2e582c3fa..5c394b1dc 100644 --- a/src/core/sp_main.cpp +++ b/src/core/sp_main.cpp @@ -604,6 +604,12 @@ void CSourcePython::OnEdictFreed( const edict_t *edict ) void CSourcePython::OnEntityPreSpawned( CBaseEntity *pEntity ) { CALL_LISTENERS(OnEntityPreSpawned, ptr((CBaseEntityWrapper*) pEntity)); + + unsigned int uiIndex; + if (!IndexFromBaseEntity(pEntity, uiIndex)) + return; + + CALL_LISTENERS(OnEntityPreSpawned, uiIndex); } #endif @@ -619,11 +625,23 @@ void CSourcePython::OnEntityCreated( CBaseEntity *pEntity ) InitHooks(pEntity); CALL_LISTENERS(OnEntityCreated, ptr((CBaseEntityWrapper*) pEntity)); + + unsigned int uiIndex; + if (!IndexFromBaseEntity(pEntity, uiIndex)) + return; + + CALL_LISTENERS(OnNetworkedEntityCreated, uiIndex); } void CSourcePython::OnEntitySpawned( CBaseEntity *pEntity ) { CALL_LISTENERS(OnEntitySpawned, ptr((CBaseEntityWrapper*) pEntity)); + + unsigned int uiIndex; + if (!IndexFromBaseEntity(pEntity, uiIndex)) + return; + + CALL_LISTENERS(OnNetworkedEntitySpawned, uiIndex); } void CSourcePython::OnEntityDeleted( CBaseEntity *pEntity ) @@ -631,9 +649,15 @@ void CSourcePython::OnEntityDeleted( CBaseEntity *pEntity ) object oEntity(ptr((CBaseEntityWrapper*) pEntity)); CALL_LISTENERS(OnEntityDeleted, oEntity); + unsigned int uiIndex; + if (!IndexFromBaseEntity(pEntity, uiIndex)) + return; + + CALL_LISTENERS(OnNetworkedEntityDeleted, uiIndex); + // Invalidate the internal entity cache once all callbacks have been called. - static object _on_entity_deleted = import("entities").attr("_base").attr("_on_entity_deleted"); - _on_entity_deleted(oEntity); + static object _on_networked_entity_deleted = import("entities").attr("_base").attr("_on_networked_entity_deleted"); + _on_networked_entity_deleted(uiIndex); } void CSourcePython::OnDataLoaded( MDLCacheDataType_t type, MDLHandle_t handle ) From f32d3db07a23a356bbcc8ddeef54f174679dd959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordan=20Bri=C3=A8re?= Date: Wed, 23 Sep 2020 03:59:58 -0400 Subject: [PATCH 2/5] Added missing entries to listeners.__all__. --- .../packages/source-python/listeners/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/source-python/packages/source-python/listeners/__init__.py b/addons/source-python/packages/source-python/listeners/__init__.py index e665febe5..8aec4f521 100644 --- a/addons/source-python/packages/source-python/listeners/__init__.py +++ b/addons/source-python/packages/source-python/listeners/__init__.py @@ -95,11 +95,15 @@ 'OnEdictAllocated', 'OnEdictFreed', 'OnEntityCreated', + 'OnNetworkedEntityCreated', 'OnEntityDeleted', + 'OnNetworkedEntityDeleted', 'OnEntityOutput', 'OnEntityOutputListenerManager', 'OnEntityPreSpawned', + 'OnNetworkedEntityPreSpawned', 'OnEntitySpawned', + 'OnNetworkedEntitySpawned', 'OnLevelInit', 'OnLevelShutdown', 'OnLevelEnd', @@ -129,10 +133,14 @@ 'on_edict_allocated_listener_manager', 'on_edict_freed_listener_manager', 'on_entity_created_listener_manager', + 'on_networked_entity_created_listener_manager', 'on_entity_deleted_listener_manager', + 'on_networked_entity_deleted_listener_manager', 'on_entity_output_listener_manager', 'on_entity_pre_spawned_listener_manager', + 'on_networked_entity_pre_spawned_listener_manager', 'on_entity_spawned_listener_manager', + 'on_networked_entity_spawned_listener_manager', 'on_level_end_listener_manager', 'on_level_init_listener_manager', 'on_level_shutdown_listener_manager', From f69d35c06178af12c0adb7f115d7049f7071ab57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordan=20Bri=C3=A8re?= Date: Wed, 23 Sep 2020 14:56:55 -0400 Subject: [PATCH 3/5] Networked entity listeners now pass an Entity instance to the callbacks rather than an index. --- .../developing/module_tutorials/listeners.rst | 8 ++++---- .../packages/source-python/entities/dictionary.py | 9 ++++++--- .../packages/source-python/entities/hooks.py | 4 ++-- src/core/sp_main.cpp | 15 +++++++++------ 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/addons/source-python/docs/source-python/source/developing/module_tutorials/listeners.rst b/addons/source-python/docs/source-python/source/developing/module_tutorials/listeners.rst index 1875e262a..cbd4e39b1 100644 --- a/addons/source-python/docs/source-python/source/developing/module_tutorials/listeners.rst +++ b/addons/source-python/docs/source-python/source/developing/module_tutorials/listeners.rst @@ -212,7 +212,7 @@ Called when a networked entity has been created. from listeners import OnNetworkedEntityCreated @OnNetworkedEntityCreated - def on_networked_entity_created(index): + def on_networked_entity_created(entity): pass @@ -240,7 +240,7 @@ Called when a networked entity gets deleted. from listeners import OnNetworkedEntityDeleted @OnNetworkedEntityDeleted - def on_networked_entity_deleted(index): + def on_networked_entity_deleted(entity): pass @@ -290,7 +290,7 @@ Called before a networked entity has been spawned. from listeners import OnNetworkedEntityPreSpawned @OnNetworkedEntityPreSpawned - def on_networked_entity_pre_spawned(index): + def on_networked_entity_pre_spawned(entity): pass .. note:: This listener gets only called in Black Mesa: Source. @@ -320,7 +320,7 @@ Called when a networked entity has been spawned. from listeners import OnNetworkedEntitySpawned @OnNetworkedEntitySpawned - def on_networked_entity_spawned(index): + def on_networked_entity_spawned(entity): pass diff --git a/addons/source-python/packages/source-python/entities/dictionary.py b/addons/source-python/packages/source-python/entities/dictionary.py index 45d1ad364..4eb17a0ee 100644 --- a/addons/source-python/packages/source-python/entities/dictionary.py +++ b/addons/source-python/packages/source-python/entities/dictionary.py @@ -76,15 +76,18 @@ def from_inthandle(self, inthandle): """ return self[index_from_inthandle(inthandle)] - def on_automatically_removed(self, index): + def on_automatically_removed(self, entity): """Called when an index is automatically removed.""" def _on_networked_entity_deleted(self, index): """Internal networked entity deletion callback. - :param int index: - The index of the networked entity being removed. + :param Entity entity: + The networked entity being removed. """ + # Get the index of the entity + index = entity.index + # No need to go further if there is no object associated to this index if index not in self: return diff --git a/addons/source-python/packages/source-python/entities/hooks.py b/addons/source-python/packages/source-python/entities/hooks.py index 940924ca2..ab944521e 100644 --- a/addons/source-python/packages/source-python/entities/hooks.py +++ b/addons/source-python/packages/source-python/entities/hooks.py @@ -220,6 +220,6 @@ def initialize(self, index): # >> LISTENERS # ============================================================================= @OnNetworkedEntityCreated -def on_networked_entity_created(index): +def on_networked_entity_created(entity): """Called when a new networked entity has been created.""" - _waiting_entity_hooks.initialize(index) + _waiting_entity_hooks.initialize(entity.index) diff --git a/src/core/sp_main.cpp b/src/core/sp_main.cpp index 5c394b1dc..90b352af9 100644 --- a/src/core/sp_main.cpp +++ b/src/core/sp_main.cpp @@ -609,7 +609,8 @@ void CSourcePython::OnEntityPreSpawned( CBaseEntity *pEntity ) if (!IndexFromBaseEntity(pEntity, uiIndex)) return; - CALL_LISTENERS(OnEntityPreSpawned, uiIndex); + static object Entity = import("entities").attr("entity").attr("Entity"); + CALL_LISTENERS(OnEntityPreSpawned, Entity(uiIndex)); } #endif @@ -630,7 +631,8 @@ void CSourcePython::OnEntityCreated( CBaseEntity *pEntity ) if (!IndexFromBaseEntity(pEntity, uiIndex)) return; - CALL_LISTENERS(OnNetworkedEntityCreated, uiIndex); + static object Entity = import("entities").attr("entity").attr("Entity"); + CALL_LISTENERS(OnNetworkedEntityCreated, Entity(uiIndex)); } void CSourcePython::OnEntitySpawned( CBaseEntity *pEntity ) @@ -641,19 +643,20 @@ void CSourcePython::OnEntitySpawned( CBaseEntity *pEntity ) if (!IndexFromBaseEntity(pEntity, uiIndex)) return; - CALL_LISTENERS(OnNetworkedEntitySpawned, uiIndex); + static object Entity = import("entities").attr("entity").attr("Entity"); + CALL_LISTENERS(OnNetworkedEntitySpawned, Entity(uiIndex)); } void CSourcePython::OnEntityDeleted( CBaseEntity *pEntity ) { - object oEntity(ptr((CBaseEntityWrapper*) pEntity)); - CALL_LISTENERS(OnEntityDeleted, oEntity); + CALL_LISTENERS(OnEntityDeleted, ptr((CBaseEntityWrapper*) pEntity)); unsigned int uiIndex; if (!IndexFromBaseEntity(pEntity, uiIndex)) return; - CALL_LISTENERS(OnNetworkedEntityDeleted, uiIndex); + static object Entity = import("entities").attr("entity").attr("Entity"); + CALL_LISTENERS(OnNetworkedEntityDeleted, Entity(uiIndex)); // Invalidate the internal entity cache once all callbacks have been called. static object _on_networked_entity_deleted = import("entities").attr("_base").attr("_on_networked_entity_deleted"); From 85ad554a4c6967f00d42af51df7d3c04fff42784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordan=20Bri=C3=A8re?= Date: Wed, 23 Sep 2020 15:28:29 -0400 Subject: [PATCH 4/5] Fixed a prototype mixup. --- .../packages/source-python/entities/dictionary.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/source-python/packages/source-python/entities/dictionary.py b/addons/source-python/packages/source-python/entities/dictionary.py index 4eb17a0ee..4fd66359a 100644 --- a/addons/source-python/packages/source-python/entities/dictionary.py +++ b/addons/source-python/packages/source-python/entities/dictionary.py @@ -76,10 +76,10 @@ def from_inthandle(self, inthandle): """ return self[index_from_inthandle(inthandle)] - def on_automatically_removed(self, entity): + def on_automatically_removed(self, index): """Called when an index is automatically removed.""" - def _on_networked_entity_deleted(self, index): + def _on_networked_entity_deleted(self, entity): """Internal networked entity deletion callback. :param Entity entity: From a149d5cb31c06e75f4a196676516fdf3f904b30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordan=20Bri=C3=A8re?= Date: Fri, 25 Sep 2020 06:01:15 -0400 Subject: [PATCH 5/5] Improved the logic so that we don't retrieve the entity index if there is no callback registered. --- src/core/sp_main.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/core/sp_main.cpp b/src/core/sp_main.cpp index 90b352af9..adca9d0b3 100644 --- a/src/core/sp_main.cpp +++ b/src/core/sp_main.cpp @@ -605,12 +605,16 @@ void CSourcePython::OnEntityPreSpawned( CBaseEntity *pEntity ) { CALL_LISTENERS(OnEntityPreSpawned, ptr((CBaseEntityWrapper*) pEntity)); + GET_LISTENER_MANAGER(OnNetworkedEntityPreSpawned, on_networked_entity_pre_spawned_manager); + if (!on_networked_entity_pre_spawned_manager->GetCount()) + return; + unsigned int uiIndex; if (!IndexFromBaseEntity(pEntity, uiIndex)) return; static object Entity = import("entities").attr("entity").attr("Entity"); - CALL_LISTENERS(OnEntityPreSpawned, Entity(uiIndex)); + CALL_LISTENERS_WITH_MNGR(on_networked_entity_pre_spawned_manager, Entity(uiIndex)); } #endif @@ -627,24 +631,32 @@ void CSourcePython::OnEntityCreated( CBaseEntity *pEntity ) CALL_LISTENERS(OnEntityCreated, ptr((CBaseEntityWrapper*) pEntity)); + GET_LISTENER_MANAGER(OnNetworkedEntityCreated, on_networked_entity_created_manager); + if (!on_networked_entity_created_manager->GetCount()) + return; + unsigned int uiIndex; if (!IndexFromBaseEntity(pEntity, uiIndex)) return; static object Entity = import("entities").attr("entity").attr("Entity"); - CALL_LISTENERS(OnNetworkedEntityCreated, Entity(uiIndex)); + CALL_LISTENERS_WITH_MNGR(on_networked_entity_created_manager, Entity(uiIndex)); } void CSourcePython::OnEntitySpawned( CBaseEntity *pEntity ) { CALL_LISTENERS(OnEntitySpawned, ptr((CBaseEntityWrapper*) pEntity)); + GET_LISTENER_MANAGER(OnNetworkedEntitySpawned, on_networked_entity_spawned_manager); + if (!on_networked_entity_spawned_manager->GetCount()) + return; + unsigned int uiIndex; if (!IndexFromBaseEntity(pEntity, uiIndex)) return; static object Entity = import("entities").attr("entity").attr("Entity"); - CALL_LISTENERS(OnNetworkedEntitySpawned, Entity(uiIndex)); + CALL_LISTENERS_WITH_MNGR(on_networked_entity_spawned_manager, Entity(uiIndex)); } void CSourcePython::OnEntityDeleted( CBaseEntity *pEntity ) @@ -655,8 +667,12 @@ void CSourcePython::OnEntityDeleted( CBaseEntity *pEntity ) if (!IndexFromBaseEntity(pEntity, uiIndex)) return; - static object Entity = import("entities").attr("entity").attr("Entity"); - CALL_LISTENERS(OnNetworkedEntityDeleted, Entity(uiIndex)); + GET_LISTENER_MANAGER(OnNetworkedEntityDeleted, on_networked_entity_deleted_manager); + if (on_networked_entity_deleted_manager->GetCount()) + { + static object Entity = import("entities").attr("entity").attr("Entity"); + CALL_LISTENERS_WITH_MNGR(on_networked_entity_deleted_manager, Entity(uiIndex)); + } // Invalidate the internal entity cache once all callbacks have been called. static object _on_networked_entity_deleted = import("entities").attr("_base").attr("_on_networked_entity_deleted");