diff options
| author | mat <git@matdoes.dev> | 2026-01-18 23:08:59 -0900 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-01-18 23:08:59 -0900 |
| commit | 70bd9c94dd7ca68777a0ead5f9432812e535bee3 (patch) | |
| tree | 62b1c211792268b95a9e08c3636938a817f62af6 /codegen/lib | |
| parent | d31574bc0967a7422bac00aeda6687ca684689d4 (diff) | |
| download | azalea-drasl-70bd9c94dd7ca68777a0ead5f9432812e535bee3.tar.xz | |
use lookup table for is_collision_shape_empty and is_collision_shape_full
Diffstat (limited to 'codegen/lib')
| -rw-r--r-- | codegen/lib/code/shapes.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/codegen/lib/code/shapes.py b/codegen/lib/code/shapes.py index da23e20f..c43864a2 100644 --- a/codegen/lib/code/shapes.py +++ b/codegen/lib/code/shapes.py @@ -113,9 +113,14 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report): generated_map_code = f"static COLLISION_SHAPES_MAP: [&LazyLock<VoxelShape>; {len(collision_shapes_map)}] = [" empty_shape_match_code = convert_ints_to_rust_ranges(empty_shapes) - block_shape_match_code = convert_ints_to_rust_ranges(full_shapes) + simple_collision_shapes_map = [2] * len(collision_shapes_map) for block_state_id, shape_id in enumerate(collision_shapes_map): generated_map_code += f"&SHAPE{shape_id},\n" + if shape_id == 0: + simple_collision_shapes_map[block_state_id] = 0 + elif shape_id == 1: + simple_collision_shapes_map[block_state_id] = 1 + simple_collision_shapes_map = ",".join(map(str, simple_collision_shapes_map)) generated_map_code += "];\n" generated_map_code += f"static OUTLINE_SHAPES_MAP: [&LazyLock<VoxelShape>; {len(outline_shapes_map)}] = [" @@ -171,14 +176,16 @@ impl BlockWithShape for BlockState {{ }} fn is_collision_shape_empty(&self) -> bool {{ - matches!(self.id(), {empty_shape_match_code}) + BASIC_COLLISION_SHAPES_MAP[self.id() as usize] == 0 }} fn is_collision_shape_full(&self) -> bool {{ - matches!(self.id(), {block_shape_match_code}) + BASIC_COLLISION_SHAPES_MAP[self.id() as usize] == 1 }} }} +static BASIC_COLLISION_SHAPES_MAP: &[u8; {len(collision_shapes_map)}] = &[{simple_collision_shapes_map}]; + {generated_map_code} """ |
