From 619984fa33aec8b9629770928c51ee81a3d3a63f Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sat, 19 Nov 2022 15:21:54 -0600 Subject: 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 --- codegen/lib/code/shapes.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'codegen/lib/code/shapes.py') 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 = 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 -- cgit v1.2.3