Skip to content

Commit 3b94e5a

Browse files
authored
Simplify use_spatial_hash flag (#1730)
* 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. * Propagate default of `false` to all uses * Update documentation * Update release notes
1 parent 0e9e94e commit 3b94e5a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

arcade/sprite_list/sprite_list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SpriteList(Generic[SpriteType]):
9393

9494
def __init__(
9595
self,
96-
use_spatial_hash: Optional[bool] = None,
96+
use_spatial_hash: bool = False,
9797
spatial_hash_cell_size: int = 128,
9898
atlas: Optional["TextureAtlas"] = None,
9999
capacity: int = 100,
@@ -156,7 +156,7 @@ def __init__(
156156

157157
self._spatial_hash_cell_size = spatial_hash_cell_size
158158
self.spatial_hash: Optional[SpatialHash] = None
159-
if use_spatial_hash is True:
159+
if use_spatial_hash:
160160
self.spatial_hash = SpatialHash(cell_size=self._spatial_hash_cell_size)
161161

162162
self.properties: Optional[Dict[str, Any]] = None

arcade/tilemap/tilemap.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class TileMap:
108108
:param Union[str, Path] map_file: A JSON map file for a Tiled map to initialize from
109109
:param float scaling: Global scaling to apply to all Sprites.
110110
:param Dict[str, Dict[str, Any]] layer_options: Extra parameters for each layer.
111-
:param Optional[bool] use_spatial_hash: If set to True, this will make moving a sprite
111+
:param bool use_spatial_hash: If set to True, this will make moving a sprite
112112
in the SpriteList slower, but it will speed up collision detection
113113
with items in the SpriteList. Great for doing collision detection
114114
with static walls/platforms.
@@ -179,7 +179,7 @@ def __init__(
179179
map_file: Union[str, Path] = "",
180180
scaling: float = 1.0,
181181
layer_options: Optional[Dict[str, Dict[str, Any]]] = None,
182-
use_spatial_hash: Optional[bool] = None,
182+
use_spatial_hash: bool = False,
183183
hit_box_algorithm: Optional[HitBoxAlgorithm] = None,
184184
tiled_map: Optional[pytiled_parser.TiledMap] = None,
185185
offset: Vec2 = Vec2(0, 0),
@@ -626,7 +626,7 @@ def _process_image_layer(
626626
layer: pytiled_parser.ImageLayer,
627627
texture_atlas: "TextureAtlas",
628628
scaling: float = 1.0,
629-
use_spatial_hash: Optional[bool] = None,
629+
use_spatial_hash: bool = False,
630630
hit_box_algorithm: Optional[HitBoxAlgorithm] = None,
631631
offset: Vec2 = Vec2(0, 0),
632632
custom_class: Optional[type] = None,
@@ -717,7 +717,7 @@ def _process_tile_layer(
717717
layer: pytiled_parser.TileLayer,
718718
texture_atlas: "TextureAtlas",
719719
scaling: float = 1.0,
720-
use_spatial_hash: Optional[bool] = None,
720+
use_spatial_hash: bool = False,
721721
hit_box_algorithm: Optional[HitBoxAlgorithm] = None,
722722
offset: Vec2 = Vec2(0, 0),
723723
custom_class: Optional[type] = None,
@@ -792,7 +792,7 @@ def _process_object_layer(
792792
layer: pytiled_parser.ObjectLayer,
793793
texture_atlas: "TextureAtlas",
794794
scaling: float = 1.0,
795-
use_spatial_hash: Optional[bool] = None,
795+
use_spatial_hash: bool = False,
796796
hit_box_algorithm: Optional[HitBoxAlgorithm] = None,
797797
offset: Vec2 = Vec2(0, 0),
798798
custom_class: Optional[type] = None,
@@ -984,7 +984,7 @@ def load_tilemap(
984984
map_file: Union[str, Path],
985985
scaling: float = 1.0,
986986
layer_options: Optional[Dict[str, Dict[str, Any]]] = None,
987-
use_spatial_hash: Optional[bool] = None,
987+
use_spatial_hash: bool = False,
988988
hit_box_algorithm: Optional[HitBoxAlgorithm] = None,
989989
offset: Vec2 = Vec2(0, 0),
990990
texture_atlas: Optional["TextureAtlas"] = None,
@@ -1001,7 +1001,7 @@ def load_tilemap(
10011001
10021002
:param Union[str, Path] map_file: The JSON map file.
10031003
:param float scaling: The global scaling to apply to all Sprite's within the map.
1004-
:param Optional[bool] use_spatial_hash: If set to True, this will make moving a sprite
1004+
:param bool use_spatial_hash: If set to True, this will make moving a sprite
10051005
in the SpriteList slower, but it will speed up collision detection
10061006
with items in the SpriteList. Great for doing collision detection
10071007
with static walls/platforms.

doc/programming_guide/release_notes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ API in a way that is not compatible with how it was used in 2.6.
4747
are also using any custom :py:class:`~arcade.TextureAtlas`.
4848
* The GUI package has been changed significantly.
4949
* Buffered shapes (shape list items) have been moved to their own sub-module.
50+
* `use_spatial_hash` parameter for `SpriteList` and `TileMap` is now a `bool` instead of `Optional[bool]`
5051

5152
Featured Updates
5253
~~~~~~~~~~~~~~~~
@@ -2349,4 +2350,3 @@ Enhancements
23492350
* `Issue 131 <https://github.com/pvcraven/arcade/issues/131>`_: Add example code on how to do full-screen games
23502351
* `Issue 113 <https://github.com/pvcraven/arcade/issues/113>`_: Add example code showing enemy turning around when hitting a wall
23512352
* `Issue 67 <https://github.com/pvcraven/arcade/issues/67>`_: Improved support and documentation for joystick/game controllers
2352-

0 commit comments

Comments
 (0)