Skip to content

Commit 49017ac

Browse files
committed
Rewrote Spatial Hashing
1 parent 1c4393d commit 49017ac

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pymunk/space.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,19 @@ def use_spatial_hash(self, dim: float, count: int) -> None:
554554
"""
555555
cp.cpSpaceUseSpatialHash(self._space, dim, count)
556556

557-
def get_space_hash_objects_per_cell(self) -> List:
558-
cell_counts = ffi.new(f'int[{cp.cpSpaceGetSpatialHashTotalCells(self._space)}]')
559-
cp.cpSpaceGetSpatialHashObjectCounts(self._space, cell_counts)
560-
return cell_counts
561557

558+
def get_space_hash_indicies(self, hash_indicies_len, l, r, b, t) -> List:
559+
hash_indicies = ffi.new(f'int[{hash_indicies_len}]')
560+
cp.cpSpaceGetSpatialHashIndices(self._space, hash_indicies, l, r, b, t)
561+
return hash_indicies
562+
563+
def create_space_hash_objects_count(self, hash_indicies_len) -> List:
564+
hash_indicies = ffi.new(f'int[{hash_indicies_len}]')
565+
return hash_indicies
566+
567+
def get_space_hash_objects_count(self, cell_counts, hash_indicies, hash_indicies_len) -> None:
568+
cp.cpSpaceGetSpatialHashObjectCounts(self._space, cell_counts, hash_indicies, hash_indicies_len)
569+
562570
def step(self, dt: float) -> None:
563571
"""Update the space for the given time step.
564572

pymunk_cffi/chipmunk_cdef.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,11 +1233,11 @@ void cpSpaceReindexShapesForBody(cpSpace *space, cpBody *body);
12331233
/// Switch the space to use a spatial has as it's spatial index.
12341234
void cpSpaceUseSpatialHash(cpSpace *space, cpFloat dim, int count);
12351235

1236-
// MARK: P7 (Crowd Crushing)
1236+
//MARK: P7 (Crowd Crushing)
12371237

1238-
int cpSpaceGetSpatialHashTotalCells(cpSpace * space);
1238+
void cpSpaceGetSpatialHashIndices(cpSpace *space, int *hash_indices, int l, int r, int b, int t);
12391239

1240-
void cpSpaceGetSpatialHashObjectCounts(cpSpace * space, int *cell_counts);
1240+
void cpSpaceGetSpatialHashObjectCounts(cpSpace *space, int *cell_counts, int *hash_indices, int hash_indices_len);
12411241

12421242
// MARK: Time Stepping
12431243

0 commit comments

Comments
 (0)