Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions addons/source-python/packages/source-python/entities/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
# Source.Python Imports
# Entities
from _entities._entity import BaseEntity
from _entities._transmit import transmit_manager


# =============================================================================
Expand Down Expand Up @@ -842,6 +843,71 @@ def set_parent(self, parent, attachment=INVALID_ATTACHMENT_INDEX):

return [parent, attachment]

# =========================================================================
# >> ENTITY TRANSMIT FUNCTIONALITY
# =========================================================================
def hide(self):
"""Hide the entity from all players."""
transmit_manager.hide(self.index)

def hide_from(self, player_index):
"""Hide the entity from player.

:param int player_index:
The target player index to hide this entity.
"""
transmit_manager.hide_from(self.index, player_index)

def show(self):
"""Show the entity to all players."""
transmit_manager.show(self.index)

def show_from(self, player_index):
"""Show the entity to player.

:param int player_index:
The target player index to show this entity.
"""
transmit_manager.show_from(self.index, player_index)

def reset(self):
"""Reset the entity's hidden/shown state."""
transmit_manager.reset(self.index)

def reset_from(self, player_index):
"""Reset the player's entity hidden/shown state.

:param int player_index:
The target player index to reset the player's hidden/shown state.
"""
transmit_manager.reset_from(self.index, player_index)

def is_hidden(self):
"""Return True if the entity is hidden from any player.

:rtype: bool
"""
return transmit_manager.is_hidden(self.index)

def is_hidden_from(self, player_index):
"""Return True if the entity is hidden from the player.

:param int player_index:
The target player index to check if the entity is hidden.
:rtype: bool
"""
return transmit_manager.is_hidden_from(self.index, player_index)

def get_hidden_player(self):
"""Get the players where the entity is hidden.

:return:
A tuple containing :class:`players.entity.Player` instances
in which the entity is hidden.
:rtype: tuple
"""
return transmit_manager.get_hidden_player(self.index)


# =============================================================================
# >> LISTENERS
Expand Down Expand Up @@ -873,3 +939,6 @@ def _on_networked_entity_deleted(index):
# Invalidate the internal entity caches for this entity
for cls in _entity_classes:
cls.cache.pop(index, None)

# Reset the entity's hidden state.
transmit_manager.reset(index)
29 changes: 29 additions & 0 deletions addons/source-python/packages/source-python/entities/transmit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ../entities/transmit.py

"""Provides entity transmission filtering."""


# ============================================================================
# >> FORWARD IMPORTS
# ============================================================================
# Source.Python
# Entities
from _entities._transmit import transmit_manager


# ============================================================================
# >> ALL DECLARATION
# ============================================================================
__all__ = (
'transmit_manager',
'reset_hidden_state',
)


# =============================================================================
# >> FUNCTIONS
# =============================================================================
def reset_hidden_state():
"""Reset all entities' hidden/shown state."""
transmit_manager.reset_all()

58 changes: 58 additions & 0 deletions addons/source-python/packages/source-python/players/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
from auth.manager import auth_manager


# =============================================================================
# >> FORWARD IMPORTS
# =============================================================================
# Source.Python Imports
# Entities
from _entities._transmit import transmit_manager


# =============================================================================
# >> CLASSES
# =============================================================================
Expand Down Expand Up @@ -1004,6 +1012,56 @@ def drop_weapon(self, weapon, target=None, velocity=None):
"""
return [weapon, target, velocity]

# =========================================================================
# >> PLAYER TRANSMIT FUNCTIONALITY
# =========================================================================
def hide_entity(self, entity_index):
"""Hide the entity from player.

:param int entity_index:
The target entity index to hide from the player.
"""
transmit_manager.hide_from(entity_index, self.index)

def show_entity(self, entity_index):
"""Show the entity to player.

:param int entity_index:
The target entity index to show the entity to player.
"""
transmit_manager.show_from(entity_index, self.index)

def reset_entity(self, entity_index):
"""Reset the player's entity hidden/shown state.

:param int entity_index:
The target entity_index to reset the player's hidden/shown state.
"""
transmit_manager.reset_from(entity_index, self.index)

def reset_all_entity(self):
"""Reset the player's hidden/shown state on all entities."""
transmit_manager.reset_player(self.index)

def is_entity_hidden(self, entity_index):
"""Return True if the entity is hidden from the player.

:param int entity_index:
The target entity index to check if the entity is hidden.
:rtype: bool
"""
return transmit_manager.is_hidden_from(entity_index, self.index)

def get_hidden_entity(self):
"""Get the entities that are hidden from the player.

:return:
A tuple containing :class:`entities.entity.Entity` instances
that are hidden from the player.
:rtype: tuple
"""
return transmit_manager.get_hidden_entity(self.index)


# =============================================================================
# >> HELPER FUNCTIONS
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Set(SOURCEPYTHON_ENTITIES_MODULE_HEADERS
core/modules/entities/${SOURCE_ENGINE}/entities_props_wrap.h
core/modules/entities/${SOURCE_ENGINE}/entities_constants_wrap.h
core/modules/entities/entities_entity.h
core/modules/entities/entities_transmit.h
)

Set(SOURCEPYTHON_ENTITIES_MODULE_SOURCES
Expand All @@ -241,6 +242,8 @@ Set(SOURCEPYTHON_ENTITIES_MODULE_SOURCES
core/modules/entities/entities_props_wrap.cpp
core/modules/entities/entities_entity.cpp
core/modules/entities/entities_entity_wrap.cpp
core/modules/entities/entities_transmit.cpp
core/modules/entities/entities_transmit_wrap.cpp
)

# ------------------------------------------------------------------
Expand Down
Loading