Skip to content

Conversation

@jordanbriere
Copy link
Contributor

@jordanbriere jordanbriere commented Sep 22, 2020

This branch adds networked variants of the entity listeners. The rationale behind this is that, 9 (if not 10) times out of 10, those listeners are used like so:

@OnEntitySomething
def on_entity_something(base_entity):
    try:
        index = base_entity.index
    except ValueError:
        return

    ...


@OnEntitySomethingElse
def on_entity_something_else(base_entity):
    if not base_entity.is_networked():
        return

    ...

Which is redundant. That branch adds the following variants that only get called for networked entities:

@OnNetworkedEntityPreSpawned
def on_networked_entity_pre_spawned(entity):
    ...


@OnNetworkedEntitySpawned
def on_networked_entity_spawned(entity):
    ...


@OnNetworkedEntityCreated
def on_networked_entity_created(entity):
    ...


@OnNetworkedEntityDeleted
def on_networked_entity_deleted(entity):
    ...

Allowing for shorter codes, less calls, as well as removing the needs for every callbacks to validate themselves that they are working with networked entities, etc.

@Ayuto
Copy link
Member

Ayuto commented Sep 23, 2020

Instead of just passing the index we could also pass the BaseEntity instance or maybe the Entity instance?

@jordanbriere
Copy link
Contributor Author

Instead of just passing the index we could also pass the BaseEntity instance or maybe the Entity instance?

I passed the index mainly because this is what we use internally, and that this is what is used first by the majority of codes on our forums (through custom entity class, or containers, etc.). However, now that you mention it, I think passing an Entity is what make the much sense since they are basically our "networked variant" of a BaseEntity and allows for direct class name filtering within a callback. Retrieving the index from it should be fast, since it is cached anyways. Will push that change shortly.

@jordanbriere jordanbriere merged commit a156f96 into master Sep 27, 2020
@jordanbriere jordanbriere deleted the networked_entity_listeners branch September 27, 2020 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants