diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-19 15:21:54 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-19 15:21:54 -0600 |
| commit | 619984fa33aec8b9629770928c51ee81a3d3a63f (patch) | |
| tree | fa6de3852d08dea6f77ba2549d98b9fcb457309a /codegen | |
| parent | befa22c1f3ff0c1f0cb745b3f4e736910c053a8b (diff) | |
| download | azalea-drasl-619984fa33aec8b9629770928c51ee81a3d3a63f.tar.xz | |
Replace lazy_static with once_cell::sync::Lazy (#43)
* Remove lazy_static in azalea-chat
* replace lazy_static with once_cell everywhere
* fix
* fix import
* ignore a clippy warning in shape codegen
Diffstat (limited to 'codegen')
| -rwxr-xr-x | codegen/lib/code/shapes.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/codegen/lib/code/shapes.py b/codegen/lib/code/shapes.py index 9cf3093a..83521dac 100755 --- a/codegen/lib/code/shapes.py +++ b/codegen/lib/code/shapes.py @@ -49,14 +49,8 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report, # look at downloads/generator-mod-*/blockCollisionShapes.json for format of blocks and shapes generated_shape_code = '' - # we make several lazy_static! blocks so it doesn't complain about - # recursion and hopefully the compiler can paralleize it? - generated_shape_code += 'lazy_static! {' - for i, (shape_id, shape) in enumerate(sorted(shapes.items(), key=lambda shape: int(shape[0]))): - if i > 0 and i % 10 == 0: - generated_shape_code += '}\nlazy_static! {' + for (shape_id, shape) in sorted(shapes.items(), key=lambda shape: int(shape[0])): generated_shape_code += generate_code_for_shape(shape_id, shape) - generated_shape_code += '}' # BlockState::PurpurStairs_NorthTopStraightTrue => &SHAPE24, generated_match_inner_code = '' @@ -93,11 +87,12 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report, // modify it, change that file. #![allow(clippy::explicit_auto_deref)] +#![allow(clippy::redundant_closure)] use super::VoxelShape; use crate::collision::{{self, Shapes}}; use azalea_block::*; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; pub trait BlockWithShape {{ fn shape(&self) -> &'static VoxelShape; @@ -119,7 +114,7 @@ def generate_code_for_shape(shape_id: str, parts: list[list[float]]): def make_arguments(part: list[float]): return ', '.join(map(lambda n: str(n).rstrip('0'), part)) code = '' - code += f'static ref SHAPE{shape_id}: VoxelShape = ' + code += f'static SHAPE{shape_id}: Lazy<VoxelShape> = Lazy::new(|| {{' steps = [] if parts == []: steps.append('collision::empty_shape()') @@ -136,5 +131,6 @@ def generate_code_for_shape(shape_id: str, parts: list[list[float]]): for step in steps[:-1]: code += f' let s = {step};\n' code += f' {steps[-1]}\n' - code += '};\n' + code += '}\n' + code += '});\n' return code |
