From 376f75f159369012b86b644e822dc09c9bf9bc55 Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Thu, 27 Apr 2023 00:55:20 -0600 Subject: [PATCH 1/4] Simplify `use_spatial_hash` flag This changes the flag to a bool instead of Optional[bool]. The behavior should remain unchanged, even when the parameter is not passed in because the default is False. --- arcade/sprite_list/sprite_list.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/sprite_list/sprite_list.py b/arcade/sprite_list/sprite_list.py index 26f0586d3..cce2cf95c 100644 --- a/arcade/sprite_list/sprite_list.py +++ b/arcade/sprite_list/sprite_list.py @@ -93,7 +93,7 @@ class SpriteList(Generic[SpriteType]): def __init__( self, - use_spatial_hash: Optional[bool] = None, + use_spatial_hash: bool = False, spatial_hash_cell_size: int = 128, atlas: Optional["TextureAtlas"] = None, capacity: int = 100, @@ -156,7 +156,7 @@ def __init__( self._spatial_hash_cell_size = spatial_hash_cell_size self.spatial_hash: Optional[SpatialHash] = None - if use_spatial_hash is True: + if use_spatial_hash: self.spatial_hash = SpatialHash(cell_size=self._spatial_hash_cell_size) self.properties: Optional[Dict[str, Any]] = None From d58eb525c2c87be976e54932cf7070fdf6962d2d Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Thu, 27 Apr 2023 12:25:43 -0600 Subject: [PATCH 2/4] Propagate default of `false` to all uses --- arcade/tilemap/tilemap.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arcade/tilemap/tilemap.py b/arcade/tilemap/tilemap.py index c8fa71182..f1d761360 100644 --- a/arcade/tilemap/tilemap.py +++ b/arcade/tilemap/tilemap.py @@ -179,7 +179,7 @@ def __init__( map_file: Union[str, Path] = "", scaling: float = 1.0, layer_options: Optional[Dict[str, Dict[str, Any]]] = None, - use_spatial_hash: Optional[bool] = None, + use_spatial_hash: bool = False, hit_box_algorithm: Optional[HitBoxAlgorithm] = None, tiled_map: Optional[pytiled_parser.TiledMap] = None, offset: Vec2 = Vec2(0, 0), @@ -626,7 +626,7 @@ def _process_image_layer( layer: pytiled_parser.ImageLayer, texture_atlas: "TextureAtlas", scaling: float = 1.0, - use_spatial_hash: Optional[bool] = None, + use_spatial_hash: bool = False, hit_box_algorithm: Optional[HitBoxAlgorithm] = None, offset: Vec2 = Vec2(0, 0), custom_class: Optional[type] = None, @@ -717,7 +717,7 @@ def _process_tile_layer( layer: pytiled_parser.TileLayer, texture_atlas: "TextureAtlas", scaling: float = 1.0, - use_spatial_hash: Optional[bool] = None, + use_spatial_hash: bool = False, hit_box_algorithm: Optional[HitBoxAlgorithm] = None, offset: Vec2 = Vec2(0, 0), custom_class: Optional[type] = None, @@ -792,7 +792,7 @@ def _process_object_layer( layer: pytiled_parser.ObjectLayer, texture_atlas: "TextureAtlas", scaling: float = 1.0, - use_spatial_hash: Optional[bool] = None, + use_spatial_hash: bool = False, hit_box_algorithm: Optional[HitBoxAlgorithm] = None, offset: Vec2 = Vec2(0, 0), custom_class: Optional[type] = None, @@ -984,7 +984,7 @@ def load_tilemap( map_file: Union[str, Path], scaling: float = 1.0, layer_options: Optional[Dict[str, Dict[str, Any]]] = None, - use_spatial_hash: Optional[bool] = None, + use_spatial_hash: bool = False, hit_box_algorithm: Optional[HitBoxAlgorithm] = None, offset: Vec2 = Vec2(0, 0), texture_atlas: Optional["TextureAtlas"] = None, From d132ec293de2285d10e23f10f85a1ec1af22d847 Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Thu, 27 Apr 2023 12:32:17 -0600 Subject: [PATCH 3/4] Update documentation --- arcade/tilemap/tilemap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arcade/tilemap/tilemap.py b/arcade/tilemap/tilemap.py index f1d761360..9d86e2708 100644 --- a/arcade/tilemap/tilemap.py +++ b/arcade/tilemap/tilemap.py @@ -108,7 +108,7 @@ class TileMap: :param Union[str, Path] map_file: A JSON map file for a Tiled map to initialize from :param float scaling: Global scaling to apply to all Sprites. :param Dict[str, Dict[str, Any]] layer_options: Extra parameters for each layer. - :param Optional[bool] use_spatial_hash: If set to True, this will make moving a sprite + :param bool use_spatial_hash: If set to True, this will make moving a sprite in the SpriteList slower, but it will speed up collision detection with items in the SpriteList. Great for doing collision detection with static walls/platforms. @@ -1001,7 +1001,7 @@ def load_tilemap( :param Union[str, Path] map_file: The JSON map file. :param float scaling: The global scaling to apply to all Sprite's within the map. - :param Optional[bool] use_spatial_hash: If set to True, this will make moving a sprite + :param bool use_spatial_hash: If set to True, this will make moving a sprite in the SpriteList slower, but it will speed up collision detection with items in the SpriteList. Great for doing collision detection with static walls/platforms. From 1fee949ffa097c825286f391bffb78b325cb766e Mon Sep 17 00:00:00 2001 From: Code-Apprentice Date: Thu, 27 Apr 2023 12:52:28 -0600 Subject: [PATCH 4/4] Update release notes --- doc/programming_guide/release_notes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/programming_guide/release_notes.rst b/doc/programming_guide/release_notes.rst index d1803725f..bd75fd072 100644 --- a/doc/programming_guide/release_notes.rst +++ b/doc/programming_guide/release_notes.rst @@ -47,6 +47,7 @@ API in a way that is not compatible with how it was used in 2.6. are also using any custom :py:class:`~arcade.TextureAtlas`. * The GUI package has been changed significantly. * Buffered shapes (shape list items) have been moved to their own sub-module. +* `use_spatial_hash` parameter for `SpriteList` and `TileMap` is now a `bool` instead of `Optional[bool]` Featured Updates ~~~~~~~~~~~~~~~~ @@ -2349,4 +2350,3 @@ Enhancements * `Issue 131 `_: Add example code on how to do full-screen games * `Issue 113 `_: Add example code showing enemy turning around when hitting a wall * `Issue 67 `_: Improved support and documentation for joystick/game controllers -