diff options
| author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-01-06 12:11:03 +1300 | 
|---|---|---|
| committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-01-06 12:11:03 +1300 | 
| commit | 4735200272ac8a8165bd43784a41ca5b3725bc16 (patch) | |
| tree | db893c2c07e858b26a2ab6711b926076a35775a4 /src/devices | |
| parent | f82cda3c621c4efcaab040a9c11029fa11e53b05 (diff) | |
| download | bedrock-pc-4735200272ac8a8165bd43784a41ca5b3725bc16.zip | |
Reduce width of ScreenDevice::draw_sprite method
This method was exceeding the 80-character line limit, which was
interfering with the centering behaviour of my text editor.
Diffstat (limited to 'src/devices')
| -rw-r--r-- | src/devices/screen.rs | 28 | 
1 files changed, 15 insertions, 13 deletions
| diff --git a/src/devices/screen.rs b/src/devices/screen.rs index 02de8b9..ee11f52 100644 --- a/src/devices/screen.rs +++ b/src/devices/screen.rs @@ -456,11 +456,12 @@ impl ScreenDevice {          let mut position = self.cursor;          let mut pointer: usize = 0; -        macro_rules! inc_x   { ($v:expr) => { position.x = position.x.wrapping_add($v) }; } -        macro_rules! dec_x   { ($v:expr) => { position.x = position.x.wrapping_sub($v) }; } -        macro_rules! inc_y   { ($v:expr) => { position.y = position.y.wrapping_add($v) }; } -        macro_rules! dec_y   { ($v:expr) => { position.y = position.y.wrapping_sub($v) }; } -        macro_rules! plot { () => { +        macro_rules! for8 { ($block:block) => { for _ in 0..8 { $block } }; } +        macro_rules! r   { ($v:expr) => { position.x = position.x.wrapping_add($v) }; } +        macro_rules! l   { ($v:expr) => { position.x = position.x.wrapping_sub($v) }; } +        macro_rules! d   { ($v:expr) => { position.y = position.y.wrapping_add($v) }; } +        macro_rules! u   { ($v:expr) => { position.y = position.y.wrapping_sub($v) }; } +        macro_rules! px { () => {              let colour = sprite[pointer];              if !(transparent && colour == 0) {                  self.draw_pixel(self.sprite_colours[colour as usize], layer, position); @@ -468,16 +469,17 @@ impl ScreenDevice {              pointer += 1;          }; } +          match params & 0x07 { -            0x00 => {                       for _ in 0..8 { for _ in 0..8 { plot!(); inc_x!(1); } dec_x!(8); inc_y!(1); } } -            0x01 => { inc_x!(7);            for _ in 0..8 { for _ in 0..8 { plot!(); dec_x!(1); } inc_x!(8); inc_y!(1); } } -            0x02 => {            inc_y!(7); for _ in 0..8 { for _ in 0..8 { plot!(); inc_x!(1); } dec_x!(8); dec_y!(1); } } -            0x03 => { inc_x!(7); inc_y!(7); for _ in 0..8 { for _ in 0..8 { plot!(); dec_x!(1); } inc_x!(8); dec_y!(1); } } +            0 => {               for8!{{ for8!{{ px!(); r!(1); }} l!(8); d!(1); }} } +            1 => { r!(7);        for8!{{ for8!{{ px!(); l!(1); }} r!(8); d!(1); }} } +            2 => {        d!(7); for8!{{ for8!{{ px!(); r!(1); }} l!(8); u!(1); }} } +            3 => { r!(7); d!(7); for8!{{ for8!{{ px!(); l!(1); }} r!(8); u!(1); }} } -            0x04 => {                       for _ in 0..8 { for _ in 0..8 { plot!(); inc_y!(1); } dec_y!(8); inc_x!(1); } } -            0x05 => { inc_x!(7);            for _ in 0..8 { for _ in 0..8 { plot!(); inc_y!(1); } dec_y!(8); dec_x!(1); } } -            0x06 => {            inc_y!(7); for _ in 0..8 { for _ in 0..8 { plot!(); dec_y!(1); } inc_y!(8); inc_x!(1); } } -            0x07 => { inc_x!(7); inc_y!(7); for _ in 0..8 { for _ in 0..8 { plot!(); dec_y!(1); } inc_y!(8); dec_x!(1); } } +            4 => {               for8!{{ for8!{{ px!(); d!(1); }} u!(8); r!(1); }} } +            5 => { r!(7);        for8!{{ for8!{{ px!(); d!(1); }} u!(8); l!(1); }} } +            6 => {         d!(7);for8!{{ for8!{{ px!(); u!(1); }} d!(8); r!(1); }} } +            7 => { r!(7); d!(7); for8!{{ for8!{{ px!(); u!(1); }} d!(8); l!(1); }} }              _ => unreachable!(),          } | 
