77
88from __future__ import annotations
99
10- # import logging
1110import random
1211from array import array
1312from collections import deque
3635 from arcade import DefaultTextureAtlas , Texture
3736 from arcade .texture_atlas import TextureAtlasBase
3837
39- # LOG = logging.getLogger(__name__)
40-
41- # The slot index that makes a sprite invisible.
42- # 2^31-1 is usually reserved for primitive restart
43- # NOTE: Possibly we want to use slot 0 for this?
44- _SPRITE_SLOT_INVISIBLE = 2000000000
45-
4638# The default capacity from spritelists
4739_DEFAULT_CAPACITY = 100
4840
@@ -181,13 +173,6 @@ def __init__(
181173
182174 self .properties : dict [str , Any ] | None = None
183175
184- # LOG.debug(
185- # "[%s] Creating SpriteList use_spatial_hash=%s capacity=%s",
186- # id(self),
187- # use_spatial_hash,
188- # self._buf_capacity,
189- # )
190-
191176 # Check if the window/context is available
192177 try :
193178 get_window ()
@@ -275,8 +260,6 @@ def __getitem__(self, i: int) -> SpriteType:
275260
276261 def __setitem__ (self , index : int , sprite : SpriteType ) -> None :
277262 """Replace a sprite at a specific index"""
278- # print(f"{id(self)} : {id(sprite)} __setitem__({index})")
279-
280263 try :
281264 existing_index = self .sprite_list .index (sprite ) # raise ValueError
282265 if existing_index == index :
@@ -385,7 +368,6 @@ def alpha(self) -> int:
385368
386369 @alpha .setter
387370 def alpha (self , value : int ) -> None :
388- # value = clamp(value, 0, 255)
389371 self ._color = self ._color [0 ], self ._color [1 ], self ._color [2 ], value / 255
390372
391373 @property
@@ -402,7 +384,6 @@ def alpha_normalized(self) -> float:
402384
403385 @alpha_normalized .setter
404386 def alpha_normalized (self , value : float ) -> None :
405- # value = clamp(value, 0.0, 1.0)
406387 self ._color = self ._color [0 ], self ._color [1 ], self ._color [2 ], value
407388
408389 @property
@@ -667,10 +648,6 @@ def append(self, sprite: SpriteType) -> None:
667648 if self .spatial_hash is not None :
668649 self .spatial_hash .add (sprite )
669650
670- # Load additional textures attached to the sprite
671- # if hasattr(sprite, "textures") and self._initialized:
672- # for texture in sprite.textures or []:
673- # self._atlas.add(texture)
674651 if self ._initialized :
675652 if sprite .texture is None :
676653 raise ValueError ("Sprite must have a texture when added to a SpriteList" )
@@ -707,7 +684,6 @@ def remove(self, sprite: SpriteType) -> None:
707684 Args:
708685 sprite: Item to remove from the list
709686 """
710- # print(f"{id(self)} : {id(sprite)} remove")
711687 try :
712688 slot = self .sprite_slot [sprite ]
713689 except KeyError :
@@ -719,12 +695,6 @@ def remove(self, sprite: SpriteType) -> None:
719695
720696 self ._sprite_buffer_free_slots .append (slot )
721697
722- # NOTE: Optimize this by deferring removal?
723- # Defer removal
724- # Set the sprite as invisible in the index buffer
725- # idx_slot = self._sprite_index_data.index(slot)
726- # self._sprite_index_data[idx_slot] = _SPRITE_SLOT_INVISIBLE
727-
728698 # Brutal resize for now. Optimize later
729699 self ._sprite_index_data .remove (slot )
730700 self ._sprite_index_data .append (0 )
@@ -864,13 +834,10 @@ def enable_spatial_hashing(self, spatial_hash_cell_size: int = 128) -> None:
864834 spatial_hash_cell_size: The size of the cell in the spatial hash.
865835 """
866836 if self .spatial_hash is None or self .spatial_hash .cell_size != spatial_hash_cell_size :
867- # LOG.debug("Enabled spatial hashing with cell size %s", spatial_hash_cell_size)
868837 from .spatial_hash import SpatialHash
869838
870839 self .spatial_hash = SpatialHash (cell_size = spatial_hash_cell_size )
871840 self ._recalculate_spatial_hashes ()
872- # else:
873- # LOG.debug("Spatial hashing is already enabled with size %s", spatial_hash_cell_size)
874841
875842 def _recalculate_spatial_hashes (self ) -> None :
876843 if self .spatial_hash is None :
@@ -903,7 +870,6 @@ def update_animation(self, delta_time: float = 1 / 60, *args, **kwargs) -> None:
903870 *args: Additional positional arguments
904871 **kwargs: Additional keyword arguments
905872 """
906- # NOTE: Can we limit this to animated sprites?
907873 for sprite in self .sprite_list :
908874 sprite .update_animation (delta_time , * args , ** kwargs )
909875
@@ -966,20 +932,6 @@ def write_sprite_buffers_to_gpu(self) -> None:
966932 self ._write_sprite_buffers_to_gpu ()
967933
968934 def _write_sprite_buffers_to_gpu (self ) -> None :
969- # LOG.debug(
970- # (
971- # "[%s] SpriteList._write_sprite_buffers_to_gpu: "
972- # "pos=%s, size=%s, angle=%s, color=%s tex=%s idx=%s"
973- # ),
974- # id(self),
975- # self._sprite_pos_changed,
976- # self._sprite_size_changed,
977- # self._sprite_angle_changed,
978- # self._sprite_color_changed,
979- # self._sprite_texture_changed,
980- # self._sprite_index_changed,
981- # )
982-
983935 if self ._sprite_pos_changed and self ._sprite_pos_buf :
984936 self ._sprite_pos_buf .orphan ()
985937 self ._sprite_pos_buf .write (self ._sprite_pos_data )
@@ -1172,13 +1124,6 @@ def _grow_sprite_buffers(self) -> None:
11721124 extend_by = self ._buf_capacity
11731125 self ._buf_capacity = self ._buf_capacity * 2
11741126
1175- # LOG.debug(
1176- # "(%s) Increasing buffer capacity from %s to %s",
1177- # self._sprite_buffer_slots,
1178- # extend_by,
1179- # self._buf_capacity,
1180- # )
1181-
11821127 # Extend the buffers so we don't lose the old data
11831128 self ._sprite_pos_data .extend ([0 ] * extend_by * 3 )
11841129 self ._sprite_size_data .extend ([0 ] * extend_by * 2 )
@@ -1208,20 +1153,6 @@ def _grow_index_buffer(self) -> None:
12081153 extend_by = self ._idx_capacity
12091154 self ._idx_capacity = self ._idx_capacity * 2
12101155
1211- # LOG.debug(
1212- # "Buffers: index_slots=%s sprite_slots=%s over-allocation-ratio=%s",
1213- # self._sprite_index_slots,
1214- # self._sprite_buffer_slots,
1215- # self._sprite_index_slots / self._sprite_buffer_slots,
1216- # )
1217-
1218- # LOG.debug(
1219- # "(%s) Increasing index capacity from %s to %s",
1220- # self._sprite_index_slots,
1221- # extend_by,
1222- # self._idx_capacity,
1223- # )
1224-
12251156 self ._sprite_index_data .extend ([0 ] * extend_by )
12261157 if self ._initialized and self ._sprite_index_buf :
12271158 self ._sprite_index_buf .orphan (size = self ._idx_capacity * 4 )
0 commit comments