formatting
note that i'm intentionally not using rustfmt. i've tried to like that tool, but in the end i just really don't like it. too many edge cases and subjectivity and not enough customization. which is probably the intent. which makes me hate it that much more. fuck you, rustfmt.
This commit is contained in:
parent
43333687a8
commit
eb6a363afd
|
@ -11,7 +11,7 @@ use libretrogd::utils::rnd_value;
|
|||
struct AudioChannelStatus {
|
||||
size: usize,
|
||||
position: usize,
|
||||
playing: bool
|
||||
playing: bool,
|
||||
}
|
||||
|
||||
fn load_and_convert_wav(path: &Path, target_spec: &AudioSpec) -> Result<AudioBuffer> {
|
||||
|
@ -95,7 +95,6 @@ fn main() -> Result<()> {
|
|||
if system.input_devices.keyboard.is_key_pressed(Scancode::Num3) {
|
||||
if using_queue_commands {
|
||||
system.audio_queue.play_buffer(&sounds[2], false);
|
||||
|
||||
} else {
|
||||
audio_device.play_buffer(&sounds[2], false)?;
|
||||
}
|
||||
|
@ -104,7 +103,6 @@ fn main() -> Result<()> {
|
|||
if system.input_devices.keyboard.is_key_pressed(Scancode::Num4) {
|
||||
if using_queue_commands {
|
||||
system.audio_queue.play_buffer(&sounds[3], false);
|
||||
|
||||
} else {
|
||||
audio_device.play_buffer(&sounds[3], false)?;
|
||||
}
|
||||
|
@ -174,7 +172,7 @@ fn main() -> Result<()> {
|
|||
} else {
|
||||
"Direct Commands"
|
||||
},
|
||||
160, 16, FontRenderOpts::Color(9), &system.font
|
||||
160, 16, FontRenderOpts::Color(9), &system.font,
|
||||
);
|
||||
|
||||
system.video.print_string("Audio Channels", 16, 32, FontRenderOpts::Color(14), &system.font);
|
||||
|
@ -191,7 +189,7 @@ fn main() -> Result<()> {
|
|||
),
|
||||
16, y,
|
||||
FontRenderOpts::Color(15),
|
||||
&system.font
|
||||
&system.font,
|
||||
);
|
||||
y += 16;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ fn new_bounce_particles(entities: &mut Entities, x: f32, y: f32) {
|
|||
BOUNCE_PARTICLE_COLOR,
|
||||
BOUNCE_PARTICLE_LIFETIME,
|
||||
angle,
|
||||
BOUNCE_PARTICLE_SPEED
|
||||
BOUNCE_PARTICLE_SPEED,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ fn render_system_sprites(context: &mut Context) {
|
|||
BlitMethod::Transparent(0),
|
||||
&context.sprites[sprite_index.0],
|
||||
position.0.x as i32,
|
||||
position.0.y as i32
|
||||
position.0.y as i32,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ fn event_handler(event: &Event, context: &mut Context) -> bool {
|
|||
match event {
|
||||
Event::Kill(entity) => {
|
||||
context.entities.remove_entity(*entity);
|
||||
},
|
||||
}
|
||||
Event::CollideAgainstEdge(entity) => {
|
||||
let positions = context.entities.components::<Position>();
|
||||
let position = positions.get(entity).unwrap();
|
||||
|
@ -223,7 +223,7 @@ fn event_handler(event: &Event, context: &mut Context) -> bool {
|
|||
let y = position.0.y + (BALL_SIZE / 2) as f32;
|
||||
drop(positions);
|
||||
new_bounce_particles(&mut context.entities, x, y);
|
||||
},
|
||||
}
|
||||
Event::LeaveTrail(position) => {
|
||||
new_trail_particle_entity(&mut context.entities, position.x, position.y, TRAIL_PARTICLE_LIFETIME);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ impl Game {
|
|||
&balls_bmp,
|
||||
&Rect::new(i as i32 * BALL_SIZE as i32, 0, BALL_SIZE as u32, BALL_SIZE as u32),
|
||||
0,
|
||||
0
|
||||
0,
|
||||
);
|
||||
sprites.push(sprite);
|
||||
}
|
||||
|
@ -61,10 +61,10 @@ impl Game {
|
|||
font,
|
||||
sprites,
|
||||
entities,
|
||||
event_publisher
|
||||
event_publisher,
|
||||
},
|
||||
component_systems,
|
||||
event_listeners
|
||||
event_listeners,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ fn event_handler(event: &Event, context: &mut Core) -> bool {
|
|||
if context.entities.has_entity(*entity) {
|
||||
remove_entity(&mut context.entities, *entity);
|
||||
}
|
||||
},
|
||||
}
|
||||
Event::RemoveAttachment(entity) => {
|
||||
if context.entities.has_entity(*entity) {
|
||||
remove_entity_attachment(&mut context.entities, *entity);
|
||||
|
@ -36,15 +36,15 @@ fn event_handler(event: &Event, context: &mut Core) -> bool {
|
|||
if context.entities.has_entity(*entity) {
|
||||
turn_and_move_entity(context, *entity, *direction);
|
||||
}
|
||||
},
|
||||
}
|
||||
Event::MoveForward(entity) => {
|
||||
if context.entities.has_entity(*entity) {
|
||||
move_entity_forward(context, *entity);
|
||||
}
|
||||
},
|
||||
}
|
||||
Event::Spawn(entity) => {
|
||||
// todo
|
||||
},
|
||||
}
|
||||
Event::AnimationFinished(entity) => {
|
||||
if context.entities.has_entity(*entity) {
|
||||
// if the entity's 'attack' animation just finished, move them back to 'idle'
|
||||
|
@ -59,25 +59,25 @@ fn event_handler(event: &Event, context: &mut Core) -> bool {
|
|||
}
|
||||
Event::SpawnSlimeRandomly => {
|
||||
spawn_slime_randomly(context);
|
||||
},
|
||||
}
|
||||
Event::SetActivity(entity, activity) => {
|
||||
if context.entities.has_entity(*entity) {
|
||||
set_entity_activity(&mut context.entities, *entity, *activity);
|
||||
}
|
||||
},
|
||||
}
|
||||
Event::Attack(entity) => {
|
||||
if context.entities.has_entity(*entity) {
|
||||
attack(context, *entity);
|
||||
}
|
||||
},
|
||||
}
|
||||
Event::Hit(target, source, damage, damage_position) => {
|
||||
if context.entities.has_entity(*target) {
|
||||
hit_entity(context, *target, *source, *damage, *damage_position);
|
||||
}
|
||||
},
|
||||
}
|
||||
Event::Kill(entity) => {
|
||||
kill_entity(context, *entity);
|
||||
},
|
||||
}
|
||||
Event::Pickup(picked_up_by, picked_up) => {
|
||||
if context.entities.has_entity(*picked_up_by) && context.entities.has_entity(*picked_up) {
|
||||
pickup(context, *picked_up_by, *picked_up);
|
||||
|
|
|
@ -150,7 +150,7 @@ pub fn apply_damage_at(context: &mut Core, area: Circle, damage: i32, source: En
|
|||
let circle = Circle::new(
|
||||
position.0.x as i32 + bound.width as i32 / 2,
|
||||
position.0.y as i32 + bound.height as i32 / 2,
|
||||
bound.radius
|
||||
bound.radius,
|
||||
);
|
||||
if area.overlaps(&circle) {
|
||||
context.event_publisher.queue(Event::Hit(*entity, source, damage, source_position.0));
|
||||
|
@ -630,7 +630,7 @@ fn update_system_pickups(context: &mut Core) {
|
|||
let pickuper_circle = Circle::new(
|
||||
pickuper_position.0.x as i32 + pickuper_bounds.width as i32 / 2,
|
||||
pickuper_position.0.y as i32 + pickuper_bounds.height as i32 / 2,
|
||||
pickuper_bounds.radius
|
||||
pickuper_bounds.radius,
|
||||
);
|
||||
|
||||
for (pickupable_entity, pickupable) in pickupables.iter() {
|
||||
|
@ -640,7 +640,7 @@ fn update_system_pickups(context: &mut Core) {
|
|||
let pickupable_circle = Circle::new(
|
||||
pickupable_position.0.x as i32 + pickupable_bounds.width as i32 / 2,
|
||||
pickupable_position.0.y as i32 + pickupable_bounds.height as i32 / 2,
|
||||
pickupable_bounds.radius
|
||||
pickupable_bounds.radius,
|
||||
);
|
||||
|
||||
if pickupable_circle.overlaps(&pickuper_circle) {
|
||||
|
@ -673,11 +673,11 @@ fn render_system_sprites(context: &mut Core) {
|
|||
FlickerMethod::OnOff => {
|
||||
// skip to the next entity, this one isn't visible
|
||||
continue;
|
||||
},
|
||||
}
|
||||
FlickerMethod::Color(draw_color) => {
|
||||
blit_method = BlitMethod::TransparentSingle {
|
||||
transparent_color: 0,
|
||||
draw_color
|
||||
draw_color,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ impl AppState<Game> for GamePlayState {
|
|||
State::Pending => {
|
||||
init_everything(context, Path::new("./assets/arena.map.json"), 0.5, 2.0, 100);
|
||||
spawn_player_randomly(&mut context.core);
|
||||
},
|
||||
}
|
||||
State::TransitionIn => {
|
||||
self.fade = 0.0;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ pub fn update_fade_transition(state: State, fade: &mut f32, delta: f32, context:
|
|||
context.core.system.palette.lerp(0..=255, &context.core.fade_out_palette, &context.core.palette, *fade);
|
||||
false
|
||||
}
|
||||
},
|
||||
}
|
||||
State::TransitionOut(_) => {
|
||||
*fade -= delta;
|
||||
if *fade <= 0.0 {
|
||||
|
@ -75,7 +75,7 @@ pub fn update_fade_transition(state: State, fade: &mut f32, delta: f32, context:
|
|||
context.core.system.palette.lerp(0..=255, &context.core.fade_out_palette, &context.core.palette, *fade);
|
||||
false
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
true
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ impl TileMap {
|
|||
if self.collision()[index] == TILE_FLAG_COLLISION {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
}
|
||||
None => return true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn event_listener(event: &Event, context: &mut Core) -> bool {
|
|||
Event::Remove(entity) => {
|
||||
context.entities.remove_entity(*entity);
|
||||
true
|
||||
},
|
||||
}
|
||||
Event::SpawnPixel => {
|
||||
let speed = rnd_value(1, 10) as f32 * 10.0;
|
||||
let angle = (rnd_value(0, 359) as f32).to_radians();
|
||||
|
@ -33,7 +33,7 @@ pub fn event_listener(event: &Event, context: &mut Core) -> bool {
|
|||
context.entities.add_component(id, Velocity(Vector2::from_angle(angle) * speed));
|
||||
context.entities.add_component(id, Color(color));
|
||||
true
|
||||
},
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ impl AppState<App> for DemoState {
|
|||
fn update(&mut self, state: State, context: &mut App) -> Option<StateChange<App>> {
|
||||
if state == State::Active {
|
||||
if context.core.system.input_devices.keyboard.is_key_pressed(Scancode::Escape) {
|
||||
return Some(StateChange::Pop(1))
|
||||
return Some(StateChange::Pop(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ impl AppState<App> for DemoState {
|
|||
match new_state {
|
||||
State::Pending => {
|
||||
self.init(context);
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ impl CoreStateWithEvents<Event> for Core {
|
|||
|
||||
pub struct Support {
|
||||
pub component_systems: ComponentSystems<Core, Core>,
|
||||
pub event_listeners: EventListeners<Event, Core>
|
||||
pub event_listeners: EventListeners<Event, Core>,
|
||||
}
|
||||
|
||||
impl SupportSystems for Support {}
|
||||
|
@ -217,7 +217,7 @@ impl App {
|
|||
support: Support {
|
||||
component_systems,
|
||||
event_listeners,
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
||||
|
||||
use libretrogd::graphics::*;
|
||||
use libretrogd::{SCREEN_HEIGHT, SCREEN_WIDTH};
|
||||
use libretrogd::graphics::*;
|
||||
|
||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
let mut source = Bitmap::new(SCREEN_WIDTH, SCREEN_HEIGHT).unwrap();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::path::Path;
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
||||
|
||||
use libretrogd::graphics::*;
|
||||
use libretrogd::math::*;
|
||||
|
@ -69,7 +69,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
framebuffer.blit(
|
||||
black_box(BlitMethod::SolidFlipped {
|
||||
horizontal_flip: false,
|
||||
vertical_flip: false
|
||||
vertical_flip: false,
|
||||
}),
|
||||
black_box(&solid_bmp),
|
||||
black_box(100),
|
||||
|
@ -83,7 +83,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
framebuffer.blit(
|
||||
black_box(BlitMethod::SolidFlipped {
|
||||
horizontal_flip: true,
|
||||
vertical_flip: false
|
||||
vertical_flip: false,
|
||||
}),
|
||||
black_box(&solid_bmp),
|
||||
black_box(100),
|
||||
|
@ -97,7 +97,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
framebuffer.blit(
|
||||
black_box(BlitMethod::SolidFlipped {
|
||||
horizontal_flip: false,
|
||||
vertical_flip: true
|
||||
vertical_flip: true,
|
||||
}),
|
||||
black_box(&solid_bmp),
|
||||
black_box(100),
|
||||
|
@ -111,7 +111,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
framebuffer.blit(
|
||||
black_box(BlitMethod::SolidFlipped {
|
||||
horizontal_flip: true,
|
||||
vertical_flip: true
|
||||
vertical_flip: true,
|
||||
}),
|
||||
black_box(&solid_bmp),
|
||||
black_box(100),
|
||||
|
@ -128,7 +128,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
black_box(BlitMethod::TransparentFlipped {
|
||||
transparent_color: 0,
|
||||
horizontal_flip: false,
|
||||
vertical_flip: false
|
||||
vertical_flip: false,
|
||||
}),
|
||||
black_box(&trans_bmp),
|
||||
black_box(100),
|
||||
|
@ -143,7 +143,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
black_box(BlitMethod::TransparentFlipped {
|
||||
transparent_color: 0,
|
||||
horizontal_flip: true,
|
||||
vertical_flip: false
|
||||
vertical_flip: false,
|
||||
}),
|
||||
black_box(&trans_bmp),
|
||||
black_box(100),
|
||||
|
@ -158,7 +158,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
black_box(BlitMethod::TransparentFlipped {
|
||||
transparent_color: 0,
|
||||
horizontal_flip: false,
|
||||
vertical_flip: true
|
||||
vertical_flip: true,
|
||||
}),
|
||||
black_box(&trans_bmp),
|
||||
black_box(100),
|
||||
|
@ -173,7 +173,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
black_box(BlitMethod::TransparentFlipped {
|
||||
transparent_color: 0,
|
||||
horizontal_flip: true,
|
||||
vertical_flip: true
|
||||
vertical_flip: true,
|
||||
}),
|
||||
black_box(&trans_bmp),
|
||||
black_box(100),
|
||||
|
@ -492,7 +492,6 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
|||
)
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
|
|
|
@ -46,38 +46,38 @@ impl std::fmt::Debug for AudioCommand {
|
|||
.field("buffer", buffer)
|
||||
.field("loops", loops)
|
||||
.finish()
|
||||
},
|
||||
}
|
||||
PlayRcBuffer { buffer, loops } => {
|
||||
f.debug_struct("PlayRcBuffer")
|
||||
.field("buffer", buffer)
|
||||
.field("loops", loops)
|
||||
.finish()
|
||||
},
|
||||
}
|
||||
PlayBufferOnChannel { channel, buffer, loops } => {
|
||||
f.debug_struct("PlayBufferOnChannel")
|
||||
.field("channel", channel)
|
||||
.field("buffer", buffer)
|
||||
.field("loops", loops)
|
||||
.finish()
|
||||
},
|
||||
}
|
||||
PlayRcBufferOnChannel { channel, buffer, loops } => {
|
||||
f.debug_struct("PlayRcBufferOnChannel")
|
||||
.field("channel", channel)
|
||||
.field("buffer", buffer)
|
||||
.field("loops", loops)
|
||||
.finish()
|
||||
},
|
||||
}
|
||||
PlayGenerator { loops, .. } => {
|
||||
f.debug_struct("PlayGenerator")
|
||||
.field("loops", loops)
|
||||
.finish_non_exhaustive()
|
||||
},
|
||||
}
|
||||
PlayGeneratorOnChannel { channel, loops, .. } => {
|
||||
f.debug_struct("PlayGeneratorOnChannel")
|
||||
.field("channel", channel)
|
||||
.field("loops", loops)
|
||||
.finish_non_exhaustive()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,31 +247,31 @@ impl AudioQueue {
|
|||
match command {
|
||||
StopChannel(channel_index) => {
|
||||
device.stop_channel(channel_index)?;
|
||||
},
|
||||
}
|
||||
StopAllChannels => {
|
||||
device.stop_all();
|
||||
},
|
||||
}
|
||||
PlayBuffer { buffer, loops } => {
|
||||
device.play_buffer(&buffer, loops)?;
|
||||
}
|
||||
PlayRcBuffer { buffer, loops } => {
|
||||
device.play_buffer(&buffer, loops)?;
|
||||
},
|
||||
}
|
||||
PlayBufferOnChannel { channel, buffer, loops } => {
|
||||
device.play_buffer_on_channel(channel, &buffer, loops)?;
|
||||
}
|
||||
PlayRcBufferOnChannel { channel, buffer, loops } => {
|
||||
device.play_buffer_on_channel(channel, &buffer, loops)?;
|
||||
},
|
||||
}
|
||||
PlayGenerator { generator, loops } => {
|
||||
device.play_generator(generator, loops)?;
|
||||
},
|
||||
}
|
||||
PlayGeneratorOnChannel { channel, generator, loops } => {
|
||||
device.play_generator_on_channel(channel, generator, loops)?;
|
||||
},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ pub type EntityId = usize;
|
|||
|
||||
// alias `Component` to always be `'static` ...
|
||||
pub trait Component: 'static {}
|
||||
|
||||
impl<T: 'static> Component for T {}
|
||||
|
||||
pub type ComponentStore<T> = RefCell<HashMap<EntityId, T>>;
|
||||
|
@ -495,12 +496,16 @@ mod tests {
|
|||
|
||||
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
|
||||
struct Name(&'static str);
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
|
||||
struct Position(i32, i32);
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
|
||||
struct Velocity(i32, i32);
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
|
||||
struct Health(u32);
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
|
||||
struct Counter(u32);
|
||||
|
||||
|
@ -761,7 +766,7 @@ mod tests {
|
|||
pub fn new(entities: Entities) -> Self {
|
||||
ComponentSystemContext {
|
||||
delta: 0.0,
|
||||
entities
|
||||
entities,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ impl<EventType, ContextType> EventListeners<EventType, ContextType> {
|
|||
// HACK?: comparing function pointers -- see above "HACK?" comment. same concern here.
|
||||
self.listeners.retain(|&l| l as usize != listener as usize);
|
||||
// return true if the listener was removed
|
||||
return before_size != self.listeners.len()
|
||||
return before_size != self.listeners.len();
|
||||
}
|
||||
|
||||
/// Moves the queue from the given [`EventPublisher`] to this manager in preparation for
|
||||
|
@ -141,7 +141,6 @@ impl<EventType, ContextType> EventListeners<EventType, ContextType> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -194,7 +193,7 @@ mod tests {
|
|||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
@ -337,6 +336,5 @@ mod tests {
|
|||
vec![Message("hello"), Dummy, Foobar(3)],
|
||||
context.events
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -349,7 +349,7 @@ unsafe fn per_pixel_rotozoom_blit(
|
|||
top_left_x.min(bottom_left_x).min(top_right_x).min(bottom_right_x) as i32 - 1,
|
||||
top_left_y.min(bottom_left_y).min(top_right_y).min(bottom_right_y) as i32 - 1,
|
||||
top_left_x.max(bottom_left_x).max(top_right_x).max(bottom_right_x) as i32 + 1,
|
||||
top_left_y.max(bottom_left_y).max(top_right_y).max(bottom_right_y) as i32 + 1
|
||||
top_left_y.max(bottom_left_y).max(top_right_y).max(bottom_right_y) as i32 + 1,
|
||||
);
|
||||
|
||||
// now we're ready to draw. we'll be iterating through each pixel on the area we calculated
|
||||
|
@ -422,7 +422,7 @@ impl Bitmap {
|
|||
} else {
|
||||
*dest_pixels = *src_pixels;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -439,7 +439,7 @@ impl Bitmap {
|
|||
self, src, src_region, dest_x, dest_y, horizontal_flip, vertical_flip,
|
||||
|src_pixels, dest_pixels| {
|
||||
*dest_pixels = *src_pixels;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -461,7 +461,7 @@ impl Bitmap {
|
|||
} else {
|
||||
*dest_pixels = *src_pixels;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ impl Bitmap {
|
|||
self, src, src_region, dest_x, dest_y,
|
||||
|src_pixels, dest_pixels| {
|
||||
*dest_pixels = (*src_pixels).wrapping_add(offset);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -495,7 +495,7 @@ impl Bitmap {
|
|||
self, src, src_region, dest_x, dest_y, horizontal_flip, vertical_flip,
|
||||
|src_pixels, dest_pixels| {
|
||||
*dest_pixels = (*src_pixels).wrapping_add(offset);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -513,7 +513,7 @@ impl Bitmap {
|
|||
if *src_pixels != transparent_color {
|
||||
*dest_pixels = *src_pixels;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -536,7 +536,7 @@ impl Bitmap {
|
|||
*dest_pixels = *src_pixels;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -556,7 +556,7 @@ impl Bitmap {
|
|||
if *src_pixels != transparent_color {
|
||||
*dest_pixels = *src_pixels;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -581,7 +581,7 @@ impl Bitmap {
|
|||
*dest_pixels = *src_pixels;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -600,7 +600,7 @@ impl Bitmap {
|
|||
if *src_pixels != transparent_color {
|
||||
*dest_pixels = (*src_pixels).wrapping_add(offset);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -621,7 +621,7 @@ impl Bitmap {
|
|||
if *src_pixels != transparent_color {
|
||||
*dest_pixels = (*src_pixels).wrapping_add(offset);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -640,7 +640,7 @@ impl Bitmap {
|
|||
if *src_pixels != transparent_color {
|
||||
*dest_pixels = draw_color;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -661,7 +661,7 @@ impl Bitmap {
|
|||
if *src_pixels != transparent_color {
|
||||
*dest_pixels = draw_color;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -680,7 +680,7 @@ impl Bitmap {
|
|||
|src_pixel, dest_bitmap, draw_x, draw_y| {
|
||||
dest_bitmap.set_pixel(draw_x, draw_y, src_pixel);
|
||||
//dest_bitmap.set_pixel(draw_x + 1, draw_y, src_pixel);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -706,7 +706,7 @@ impl Bitmap {
|
|||
};
|
||||
dest_bitmap.set_pixel(draw_x, draw_y, draw_pixel);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -727,7 +727,7 @@ impl Bitmap {
|
|||
if transparent_color != src_pixel {
|
||||
dest_bitmap.set_pixel(draw_x, draw_y, src_pixel);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -756,7 +756,7 @@ impl Bitmap {
|
|||
dest_bitmap.set_pixel(draw_x, draw_y, draw_pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -776,7 +776,7 @@ impl Bitmap {
|
|||
|src_pixel, dest_bitmap, draw_x, draw_y| {
|
||||
let src_pixel = src_pixel.wrapping_add(offset);
|
||||
dest_bitmap.set_pixel(draw_x, draw_y, src_pixel);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -799,7 +799,7 @@ impl Bitmap {
|
|||
let src_pixel = src_pixel.wrapping_add(offset);
|
||||
dest_bitmap.set_pixel(draw_x, draw_y, src_pixel);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -888,52 +888,52 @@ impl Bitmap {
|
|||
SolidOffset(offset) => self.solid_palette_offset_blit(src, src_region, dest_x, dest_y, offset),
|
||||
SolidFlippedOffset { horizontal_flip, vertical_flip, offset } => {
|
||||
self.solid_flipped_palette_offset_blit(src, src_region, dest_x, dest_y, horizontal_flip, vertical_flip, offset)
|
||||
},
|
||||
}
|
||||
Transparent(transparent_color) => {
|
||||
self.transparent_blit(src, src_region, dest_x, dest_y, transparent_color)
|
||||
},
|
||||
}
|
||||
TransparentFlipped { transparent_color, horizontal_flip, vertical_flip } => {
|
||||
self.transparent_flipped_blit(src, src_region, dest_x, dest_y, transparent_color, horizontal_flip, vertical_flip)
|
||||
},
|
||||
}
|
||||
TransparentOffset { transparent_color, offset } => {
|
||||
self.transparent_palette_offset_blit(src, src_region, dest_x, dest_y, transparent_color, offset)
|
||||
},
|
||||
}
|
||||
TransparentFlippedOffset { transparent_color, horizontal_flip, vertical_flip, offset } => {
|
||||
self.transparent_flipped_palette_offset_blit(src, src_region, dest_x, dest_y, transparent_color, horizontal_flip, vertical_flip, offset)
|
||||
},
|
||||
}
|
||||
TransparentSingle { transparent_color, draw_color } => {
|
||||
self.transparent_single_color_blit(src, src_region, dest_x, dest_y, transparent_color, draw_color)
|
||||
},
|
||||
}
|
||||
TransparentFlippedSingle { transparent_color, horizontal_flip, vertical_flip, draw_color } => {
|
||||
self.transparent_flipped_single_color_blit(src, src_region, dest_x, dest_y, transparent_color, horizontal_flip, vertical_flip, draw_color)
|
||||
},
|
||||
}
|
||||
RotoZoom { angle, scale_x, scale_y } => {
|
||||
self.rotozoom_blit(src, src_region, dest_x, dest_y, angle, scale_x, scale_y)
|
||||
},
|
||||
}
|
||||
RotoZoomOffset { angle, scale_x, scale_y, offset } => {
|
||||
self.rotozoom_palette_offset_blit(src, src_region, dest_x, dest_y, angle, scale_x, scale_y, offset)
|
||||
},
|
||||
}
|
||||
RotoZoomTransparent { angle, scale_x, scale_y, transparent_color } => {
|
||||
self.rotozoom_transparent_blit(src, src_region, dest_x, dest_y, angle, scale_x, scale_y, transparent_color)
|
||||
},
|
||||
}
|
||||
RotoZoomTransparentOffset { angle, scale_x, scale_y, transparent_color, offset } => {
|
||||
self.rotozoom_transparent_palette_offset_blit(src, src_region, dest_x, dest_y, angle, scale_x, scale_y, transparent_color, offset)
|
||||
},
|
||||
}
|
||||
SolidBlended { blend_map } => {
|
||||
self.solid_blended_blit(src, src_region, dest_x, dest_y, blend_map)
|
||||
},
|
||||
}
|
||||
SolidFlippedBlended { horizontal_flip, vertical_flip, blend_map } => {
|
||||
self.solid_flipped_blended_blit(src, src_region, dest_x, dest_y, horizontal_flip, vertical_flip, blend_map)
|
||||
},
|
||||
}
|
||||
TransparentBlended { transparent_color, blend_map } => {
|
||||
self.transparent_blended_blit(src, src_region, dest_x, dest_y, transparent_color, blend_map)
|
||||
},
|
||||
}
|
||||
TransparentFlippedBlended { transparent_color, horizontal_flip, vertical_flip, blend_map } => {
|
||||
self.transparent_flipped_blended_blit(src, src_region, dest_x, dest_y, transparent_color, horizontal_flip, vertical_flip, blend_map)
|
||||
},
|
||||
}
|
||||
RotoZoomBlended { angle, scale_x, scale_y, blend_map } => {
|
||||
self.rotozoom_blended_blit(src, src_region, dest_x, dest_y, angle, scale_x, scale_y, blend_map)
|
||||
},
|
||||
}
|
||||
RotoZoomTransparentBlended { angle, scale_x, scale_y, transparent_color, blend_map } => {
|
||||
self.rotozoom_transparent_blended_blit(src, src_region, dest_x, dest_y, angle, scale_x, scale_y, transparent_color, blend_map)
|
||||
}
|
||||
|
|
|
@ -333,7 +333,7 @@ impl LocalImageDescriptor {
|
|||
y: reader.read_u16::<LittleEndian>()?,
|
||||
width: reader.read_u16::<LittleEndian>()?,
|
||||
height: reader.read_u16::<LittleEndian>()?,
|
||||
flags: reader.read_u8()?
|
||||
flags: reader.read_u8()?,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -444,29 +444,29 @@ impl Bitmap {
|
|||
if frame_palette.is_some() {
|
||||
palette = frame_palette;
|
||||
}
|
||||
},
|
||||
}
|
||||
EXTENSION_INTRODUCER => {
|
||||
let label = GifExtensionLabel::from(reader.read_u8()?)?;
|
||||
match label {
|
||||
GifExtensionLabel::GraphicControl => {
|
||||
current_graphic_control = Some(GraphicControlExtension::read(reader)?);
|
||||
},
|
||||
}
|
||||
GifExtensionLabel::PlainText => {
|
||||
let _plain_text = PlainTextExtension::read(reader)?;
|
||||
// todo: do something with this maybe
|
||||
},
|
||||
}
|
||||
GifExtensionLabel::Application => {
|
||||
let _application = ApplicationExtension::read(reader)?;
|
||||
// todo: do something with this maybe
|
||||
},
|
||||
}
|
||||
GifExtensionLabel::Comment => {
|
||||
let _comment = CommentExtension::read(reader)?;
|
||||
// todo: do something with this maybe
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(GifError::BadFile(format!("Unexpected byte found {} not a file trailer, image separator or extension introducer", current_byte)))
|
||||
return Err(GifError::BadFile(format!("Unexpected byte found {} not a file trailer, image separator or extension introducer", current_byte)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -493,7 +493,6 @@ impl Bitmap {
|
|||
palette: &Palette,
|
||||
settings: GifSettings,
|
||||
) -> Result<(), GifError> {
|
||||
|
||||
let mut header = GifHeader {
|
||||
signature: *b"GIF",
|
||||
version: *b"89a",
|
||||
|
@ -516,7 +515,7 @@ impl Bitmap {
|
|||
match settings {
|
||||
GifSettings::Default => {
|
||||
transparent_color = 0;
|
||||
},
|
||||
}
|
||||
GifSettings::TransparentColor(color) => {
|
||||
transparent_color = color;
|
||||
}
|
||||
|
@ -543,7 +542,7 @@ impl Bitmap {
|
|||
&self,
|
||||
path: &Path,
|
||||
palette: &Palette,
|
||||
settings: GifSettings
|
||||
settings: GifSettings,
|
||||
) -> Result<(), GifError> {
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
|
|
|
@ -392,7 +392,7 @@ impl Bitmap {
|
|||
Err(IffError::IOError(io_error))
|
||||
if io_error.kind() == io::ErrorKind::UnexpectedEof =>
|
||||
{
|
||||
break
|
||||
break;
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
|
|
|
@ -364,7 +364,7 @@ pub mod tests {
|
|||
x: 0,
|
||||
y: 0,
|
||||
width: 16,
|
||||
height: 32
|
||||
height: 32,
|
||||
},
|
||||
bmp.full_bounds()
|
||||
);
|
||||
|
@ -373,7 +373,7 @@ pub mod tests {
|
|||
x: 0,
|
||||
y: 0,
|
||||
width: 16,
|
||||
height: 32
|
||||
height: 32,
|
||||
},
|
||||
*bmp.clip_region()
|
||||
);
|
||||
|
@ -428,7 +428,7 @@ pub mod tests {
|
|||
x: 0,
|
||||
y: 0,
|
||||
width: 16,
|
||||
height: 8
|
||||
height: 8,
|
||||
},
|
||||
bmp.full_bounds()
|
||||
);
|
||||
|
|
|
@ -92,7 +92,7 @@ impl BlendMap {
|
|||
blend_map.set_mapping(
|
||||
source_color,
|
||||
idx as u8,
|
||||
(gradient_size - 1) - (lit / (256 / gradient_size as u32) as u8) + source_color
|
||||
(gradient_size - 1) - (lit / (256 / gradient_size as u32) as u8) + source_color,
|
||||
).unwrap();
|
||||
}
|
||||
blend_map
|
||||
|
@ -106,7 +106,7 @@ impl BlendMap {
|
|||
gradient_start: u8,
|
||||
gradient_end: u8,
|
||||
palette: &Palette,
|
||||
f: impl Fn(f32, f32) -> f32
|
||||
f: impl Fn(f32, f32) -> f32,
|
||||
) -> BlendMap {
|
||||
let (gradient_start, gradient_end) = if gradient_start > gradient_end {
|
||||
(gradient_end, gradient_start)
|
||||
|
@ -126,7 +126,7 @@ impl BlendMap {
|
|||
blend_map.set_mapping(
|
||||
source_color,
|
||||
dest_color,
|
||||
(gradient_size - 1).wrapping_sub(weight / (256 / gradient_size as u32) as u8) + gradient_start
|
||||
(gradient_size - 1).wrapping_sub(weight / (256 / gradient_size as u32) as u8) + gradient_start,
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ impl BlendMap {
|
|||
Ok(BlendMap {
|
||||
start_color,
|
||||
end_color,
|
||||
mapping: maps.into_boxed_slice()
|
||||
mapping: maps.into_boxed_slice(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -212,7 +212,7 @@ impl Font for BitmaskFont {
|
|||
}
|
||||
width = std::cmp::max(width, x);
|
||||
x = 0;
|
||||
},
|
||||
}
|
||||
'\r' => (),
|
||||
ch => {
|
||||
if x == 0 {
|
||||
|
|
|
@ -7,12 +7,13 @@ use std::path::Path;
|
|||
use byteorder::{ReadBytesExt, WriteBytesExt};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::NUM_COLORS;
|
||||
use crate::graphics::*;
|
||||
use crate::NUM_COLORS;
|
||||
use crate::utils::abs_diff;
|
||||
|
||||
// silly "hack" (???) which allows us to alias the generic constraint `RangeBounds<u8> + Iterator<Item = u8>` to `ColorRange`
|
||||
pub trait ColorRange: RangeBounds<u8> + Iterator<Item=u8> {}
|
||||
|
||||
impl<T> ColorRange for T where T: RangeBounds<u8> + Iterator<Item=u8> {}
|
||||
|
||||
pub static VGA_PALETTE_BYTES: &[u8] = include_bytes!("../../assets/vga.pal");
|
||||
|
@ -161,7 +162,7 @@ fn read_palette_6bit<T: ReadBytesExt>(
|
|||
num_colors: usize,
|
||||
) -> Result<[u32; NUM_COLORS], PaletteError> {
|
||||
if num_colors > NUM_COLORS {
|
||||
return Err(PaletteError::OutOfRange(num_colors))
|
||||
return Err(PaletteError::OutOfRange(num_colors));
|
||||
}
|
||||
let mut colors = [0u32; NUM_COLORS];
|
||||
for i in 0..num_colors {
|
||||
|
@ -180,7 +181,7 @@ fn write_palette_6bit<T: WriteBytesExt>(
|
|||
num_colors: usize,
|
||||
) -> Result<(), PaletteError> {
|
||||
if num_colors > NUM_COLORS {
|
||||
return Err(PaletteError::OutOfRange(num_colors))
|
||||
return Err(PaletteError::OutOfRange(num_colors));
|
||||
}
|
||||
for i in 0..num_colors {
|
||||
let (r, g, b) = from_rgb32(colors[i as usize]);
|
||||
|
@ -197,7 +198,7 @@ fn read_palette_8bit<T: ReadBytesExt>(
|
|||
num_colors: usize,
|
||||
) -> Result<[u32; NUM_COLORS], PaletteError> {
|
||||
if num_colors > NUM_COLORS {
|
||||
return Err(PaletteError::OutOfRange(num_colors))
|
||||
return Err(PaletteError::OutOfRange(num_colors));
|
||||
}
|
||||
let mut colors = [0u32; NUM_COLORS];
|
||||
for i in 0..num_colors {
|
||||
|
@ -216,7 +217,7 @@ fn write_palette_8bit<T: WriteBytesExt>(
|
|||
num_colors: usize,
|
||||
) -> Result<(), PaletteError> {
|
||||
if num_colors > NUM_COLORS {
|
||||
return Err(PaletteError::OutOfRange(num_colors))
|
||||
return Err(PaletteError::OutOfRange(num_colors));
|
||||
}
|
||||
for i in 0..num_colors {
|
||||
let (r, g, b) = from_rgb32(colors[i as usize]);
|
||||
|
@ -336,7 +337,7 @@ impl Palette {
|
|||
num_colors: usize,
|
||||
) -> Result<Palette, PaletteError> {
|
||||
if num_colors > NUM_COLORS {
|
||||
return Err(PaletteError::OutOfRange(num_colors))
|
||||
return Err(PaletteError::OutOfRange(num_colors));
|
||||
}
|
||||
let colors = match format {
|
||||
PaletteFormat::Vga => read_palette_6bit(reader, num_colors)?,
|
||||
|
@ -391,7 +392,7 @@ impl Palette {
|
|||
num_colors: usize,
|
||||
) -> Result<(), PaletteError> {
|
||||
if num_colors > NUM_COLORS {
|
||||
return Err(PaletteError::OutOfRange(num_colors))
|
||||
return Err(PaletteError::OutOfRange(num_colors));
|
||||
}
|
||||
let f = File::create(path)?;
|
||||
let mut writer = BufWriter::new(f);
|
||||
|
@ -415,7 +416,7 @@ impl Palette {
|
|||
num_colors: usize,
|
||||
) -> Result<(), PaletteError> {
|
||||
if num_colors > NUM_COLORS {
|
||||
return Err(PaletteError::OutOfRange(num_colors))
|
||||
return Err(PaletteError::OutOfRange(num_colors));
|
||||
}
|
||||
match format {
|
||||
PaletteFormat::Vga => write_palette_6bit(writer, &self.colors, num_colors),
|
||||
|
|
|
@ -74,7 +74,7 @@ impl Matrix3x3 {
|
|||
Matrix3x3::new(
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, c, -s,
|
||||
0.0, s, c
|
||||
0.0, s, c,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ impl Matrix3x3 {
|
|||
Matrix3x3::new(
|
||||
c, 0.0, s,
|
||||
0.0, 1.0, 0.0,
|
||||
-s, 0.0, c
|
||||
-s, 0.0, c,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ impl Matrix3x3 {
|
|||
Matrix3x3::new(
|
||||
c, -s, 0.0,
|
||||
s, c, 0.0,
|
||||
0.0, 0.0, 1.0
|
||||
0.0, 0.0, 1.0,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ impl Matrix3x3 {
|
|||
Matrix3x3::new(
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
x, y, 1.0
|
||||
x, y, 1.0,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ impl Matrix3x3 {
|
|||
Matrix3x3::new(
|
||||
x, 0.0, 0.0,
|
||||
0.0, y, 0.0,
|
||||
0.0, 0.0, 1.0
|
||||
0.0, 0.0, 1.0,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ impl Mul for Matrix3x3 {
|
|||
self.m[Matrix3x3::M21] * rhs.m[Matrix3x3::M13] + self.m[Matrix3x3::M22] * rhs.m[Matrix3x3::M23] + self.m[Matrix3x3::M23] * rhs.m[Matrix3x3::M33],
|
||||
self.m[Matrix3x3::M31] * rhs.m[Matrix3x3::M11] + self.m[Matrix3x3::M32] * rhs.m[Matrix3x3::M21] + self.m[Matrix3x3::M33] * rhs.m[Matrix3x3::M31],
|
||||
self.m[Matrix3x3::M31] * rhs.m[Matrix3x3::M12] + self.m[Matrix3x3::M32] * rhs.m[Matrix3x3::M22] + self.m[Matrix3x3::M33] * rhs.m[Matrix3x3::M32],
|
||||
self.m[Matrix3x3::M31] * rhs.m[Matrix3x3::M13] + self.m[Matrix3x3::M32] * rhs.m[Matrix3x3::M23] + self.m[Matrix3x3::M33] * rhs.m[Matrix3x3::M33]
|
||||
self.m[Matrix3x3::M31] * rhs.m[Matrix3x3::M13] + self.m[Matrix3x3::M32] * rhs.m[Matrix3x3::M23] + self.m[Matrix3x3::M33] * rhs.m[Matrix3x3::M33],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ impl MulAssign for Matrix3x3 {
|
|||
self.m[Matrix3x3::M21] * rhs.m[Matrix3x3::M13] + self.m[Matrix3x3::M22] * rhs.m[Matrix3x3::M23] + self.m[Matrix3x3::M23] * rhs.m[Matrix3x3::M33],
|
||||
self.m[Matrix3x3::M31] * rhs.m[Matrix3x3::M11] + self.m[Matrix3x3::M32] * rhs.m[Matrix3x3::M21] + self.m[Matrix3x3::M33] * rhs.m[Matrix3x3::M31],
|
||||
self.m[Matrix3x3::M31] * rhs.m[Matrix3x3::M12] + self.m[Matrix3x3::M32] * rhs.m[Matrix3x3::M22] + self.m[Matrix3x3::M33] * rhs.m[Matrix3x3::M32],
|
||||
self.m[Matrix3x3::M31] * rhs.m[Matrix3x3::M13] + self.m[Matrix3x3::M32] * rhs.m[Matrix3x3::M23] + self.m[Matrix3x3::M33] * rhs.m[Matrix3x3::M33]
|
||||
self.m[Matrix3x3::M31] * rhs.m[Matrix3x3::M13] + self.m[Matrix3x3::M32] * rhs.m[Matrix3x3::M23] + self.m[Matrix3x3::M33] * rhs.m[Matrix3x3::M33],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ impl Mul<Vector2> for Matrix3x3 {
|
|||
fn mul(self, rhs: Vector2) -> Self::Output {
|
||||
Vector2 {
|
||||
x: rhs.x * self.m[Matrix3x3::M11] + rhs.y * self.m[Matrix3x3::M12] + self.m[Matrix3x3::M13] + self.m[Matrix3x3::M31],
|
||||
y: rhs.x * self.m[Matrix3x3::M21] + rhs.y * self.m[Matrix3x3::M22] + self.m[Matrix3x3::M23] + self.m[Matrix3x3::M32]
|
||||
y: rhs.x * self.m[Matrix3x3::M21] + rhs.y * self.m[Matrix3x3::M22] + self.m[Matrix3x3::M23] + self.m[Matrix3x3::M32],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ pub mod tests {
|
|||
let m = Matrix3x3::new(
|
||||
1.0, 2.0, 3.0,
|
||||
4.0, 5.0, 6.0,
|
||||
7.0, 8.0, 9.0
|
||||
7.0, 8.0, 9.0,
|
||||
);
|
||||
let t = m.transpose();
|
||||
assert_eq!(1.0, t.m[Matrix3x3::M11]);
|
||||
|
|
|
@ -10,9 +10,12 @@ pub mod matrix3x3;
|
|||
pub mod rect;
|
||||
pub mod vector2;
|
||||
|
||||
pub const PI: f32 = std::f32::consts::PI; // 180 degrees
|
||||
pub const HALF_PI: f32 = PI / 2.0; // 90 degrees
|
||||
pub const QUARTER_PI: f32 = PI / 4.0; // 45 degrees
|
||||
pub const PI: f32 = std::f32::consts::PI;
|
||||
// 180 degrees
|
||||
pub const HALF_PI: f32 = PI / 2.0;
|
||||
// 90 degrees
|
||||
pub const QUARTER_PI: f32 = PI / 4.0;
|
||||
// 45 degrees
|
||||
pub const TWO_PI: f32 = PI * 2.0; // 360 degrees
|
||||
|
||||
pub const RADIANS_0: f32 = 0.0;
|
||||
|
|
|
@ -13,7 +13,7 @@ pub enum TransitionTo {
|
|||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
pub enum TransitionDirection {
|
||||
In,
|
||||
Out
|
||||
Out,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
|
@ -133,7 +133,7 @@ impl<ContextType> StateContainer<ContextType> {
|
|||
State::Pending | State::Paused | State::Resume => {
|
||||
self.change_state(State::TransitionIn, context);
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
Err(StateError::AppStateInvalidState(self.current_state))
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ impl<ContextType> States<ContextType> {
|
|||
match command {
|
||||
StateChange::Push(new_state) => {
|
||||
self.pending_state = Some(new_state);
|
||||
},
|
||||
}
|
||||
StateChange::Pop(count) => {
|
||||
if let Some(state) = self.states.front_mut() {
|
||||
state.pending_transition_out(TransitionTo::Dead);
|
||||
|
@ -351,7 +351,7 @@ impl<ContextType> States<ContextType> {
|
|||
state.change_state(State::Resume, context);
|
||||
state.transition_in(context)?;
|
||||
}
|
||||
},
|
||||
}
|
||||
State::Paused => {
|
||||
state.pause(context)?;
|
||||
|
||||
|
@ -362,11 +362,11 @@ impl<ContextType> States<ContextType> {
|
|||
new_state.change_state(State::Pending, context);
|
||||
self.states.push_front(new_state);
|
||||
}
|
||||
},
|
||||
}
|
||||
State::Active => state.activate(context)?,
|
||||
State::TransitionOut(to) => state.transition_out(to, context)?,
|
||||
State::TransitionIn => state.transition_in(context)?,
|
||||
_ => {},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -383,29 +383,29 @@ impl<ContextType> States<ContextType> {
|
|||
Some(State::Paused) => {
|
||||
// should never happen now. leaving here just in case ...
|
||||
return Err(StateError::AppStateInvalidState(State::Paused));
|
||||
},
|
||||
}
|
||||
Some(State::Dead) => {
|
||||
// should never happen now. leaving here just in case ...
|
||||
return Err(StateError::AppStateInvalidState(State::Dead));
|
||||
},
|
||||
}
|
||||
Some(State::TransitionIn) => {
|
||||
let state = self.states.front_mut().unwrap();
|
||||
if state.state().transition(State::TransitionIn, context) {
|
||||
// state has indicated it is done transitioning, so we can switch it to active
|
||||
state.pending_activate();
|
||||
}
|
||||
},
|
||||
}
|
||||
Some(State::TransitionOut(to)) => {
|
||||
let state = self.states.front_mut().unwrap();
|
||||
if state.state().transition(State::TransitionOut(to), context) {
|
||||
// state has indicated it is done transitioning, so we can switch it to whatever
|
||||
// it was transitioning to
|
||||
match to {
|
||||
TransitionTo::Paused => { state.pending_pause(); },
|
||||
TransitionTo::Paused => { state.pending_pause(); }
|
||||
TransitionTo::Dead => { state.pending_kill(); }
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ impl<ContextType> States<ContextType> {
|
|||
match current_state {
|
||||
State::Active | State::TransitionIn | State::TransitionOut(_) => {
|
||||
state.state().render(current_state, context);
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ mod tests {
|
|||
match new_state {
|
||||
State::TransitionIn | State::TransitionOut(_) => {
|
||||
self.counter = self.transition_length;
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -567,7 +567,7 @@ mod tests {
|
|||
StateChange(FOO, TransitionIn, Pending),
|
||||
Transition(FOO, TransitionIn),
|
||||
Update(FOO, TransitionIn),
|
||||
Render(FOO, TransitionIn)
|
||||
Render(FOO, TransitionIn),
|
||||
]
|
||||
);
|
||||
// state finished transitioning in, now moves to active
|
||||
|
@ -577,7 +577,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FOO, Active, TransitionIn),
|
||||
Update(FOO, Active),
|
||||
Render(FOO, Active)
|
||||
Render(FOO, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -592,7 +592,7 @@ mod tests {
|
|||
StateChange(FOO, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
Update(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
Render(FOO, TransitionOut(TransitionTo::Dead))
|
||||
Render(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// state finished transitioning out, now dies
|
||||
|
@ -628,7 +628,7 @@ mod tests {
|
|||
StateChange(FOO, TransitionIn, Pending),
|
||||
Transition(FOO, TransitionIn),
|
||||
Update(FOO, TransitionIn),
|
||||
Render(FOO, TransitionIn)
|
||||
Render(FOO, TransitionIn),
|
||||
]
|
||||
);
|
||||
// wait for transition to finish
|
||||
|
@ -639,7 +639,7 @@ mod tests {
|
|||
vec![
|
||||
Transition(FOO, TransitionIn),
|
||||
Update(FOO, TransitionIn),
|
||||
Render(FOO, TransitionIn)
|
||||
Render(FOO, TransitionIn),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -650,7 +650,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FOO, Active, TransitionIn),
|
||||
Update(FOO, Active),
|
||||
Render(FOO, Active)
|
||||
Render(FOO, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -665,7 +665,7 @@ mod tests {
|
|||
StateChange(FOO, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
Update(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
Render(FOO, TransitionOut(TransitionTo::Dead))
|
||||
Render(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// wait for transition to finish
|
||||
|
@ -676,7 +676,7 @@ mod tests {
|
|||
vec![
|
||||
Transition(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
Update(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
Render(FOO, TransitionOut(TransitionTo::Dead))
|
||||
Render(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -715,7 +715,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionIn, Pending),
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning in, now moves to active
|
||||
|
@ -725,7 +725,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FIRST, Active, TransitionIn),
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -741,7 +741,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionOut(TransitionTo::Paused), Active),
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
]
|
||||
);
|
||||
// state finished transitioning out, now is paused
|
||||
|
@ -755,7 +755,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionIn, Pending),
|
||||
Transition(SECOND, TransitionIn),
|
||||
Update(SECOND, TransitionIn),
|
||||
Render(SECOND, TransitionIn)
|
||||
Render(SECOND, TransitionIn),
|
||||
]
|
||||
);
|
||||
// second state finished transitioning in, now moves to active
|
||||
|
@ -765,7 +765,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(SECOND, Active, TransitionIn),
|
||||
Update(SECOND, Active),
|
||||
Render(SECOND, Active)
|
||||
Render(SECOND, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -781,7 +781,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Update(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead))
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// second state finished transitioning out, now dies. first state wakes up again and
|
||||
|
@ -795,7 +795,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionIn, Resume),
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning in, now moves to active
|
||||
|
@ -805,7 +805,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FIRST, Active, TransitionIn),
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -821,7 +821,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning out, now dies
|
||||
|
@ -859,7 +859,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionIn, Pending),
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
// wait for transition to finish
|
||||
|
@ -870,7 +870,7 @@ mod tests {
|
|||
vec![
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -881,7 +881,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FIRST, Active, TransitionIn),
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -898,7 +898,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionOut(TransitionTo::Paused), Active),
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
]
|
||||
);
|
||||
// wait for transition to finish
|
||||
|
@ -909,7 +909,7 @@ mod tests {
|
|||
vec![
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -923,7 +923,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionIn, Pending),
|
||||
Transition(SECOND, TransitionIn),
|
||||
Update(SECOND, TransitionIn),
|
||||
Render(SECOND, TransitionIn)
|
||||
Render(SECOND, TransitionIn),
|
||||
]
|
||||
);
|
||||
// wait for transition to finish
|
||||
|
@ -934,7 +934,7 @@ mod tests {
|
|||
vec![
|
||||
Transition(SECOND, TransitionIn),
|
||||
Update(SECOND, TransitionIn),
|
||||
Render(SECOND, TransitionIn)
|
||||
Render(SECOND, TransitionIn),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -945,7 +945,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(SECOND, Active, TransitionIn),
|
||||
Update(SECOND, Active),
|
||||
Render(SECOND, Active)
|
||||
Render(SECOND, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -961,7 +961,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Update(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead))
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// wait for transition to finish
|
||||
|
@ -972,7 +972,7 @@ mod tests {
|
|||
vec![
|
||||
Transition(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Update(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead))
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -987,7 +987,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionIn, Resume),
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
// wait for transition to finish
|
||||
|
@ -998,7 +998,7 @@ mod tests {
|
|||
vec![
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -1009,7 +1009,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FIRST, Active, TransitionIn),
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -1025,7 +1025,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// wait for transition to finish
|
||||
|
@ -1036,7 +1036,7 @@ mod tests {
|
|||
vec![
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -1075,7 +1075,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionIn, Pending),
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning in, now moves to active
|
||||
|
@ -1085,7 +1085,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FIRST, Active, TransitionIn),
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -1101,7 +1101,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionOut(TransitionTo::Paused), Active),
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
]
|
||||
);
|
||||
// state finished transitioning out, now is paused
|
||||
|
@ -1115,7 +1115,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionIn, Pending),
|
||||
Transition(SECOND, TransitionIn),
|
||||
Update(SECOND, TransitionIn),
|
||||
Render(SECOND, TransitionIn)
|
||||
Render(SECOND, TransitionIn),
|
||||
]
|
||||
);
|
||||
// second state finished transitioning in, now moves to active
|
||||
|
@ -1125,7 +1125,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(SECOND, Active, TransitionIn),
|
||||
Update(SECOND, Active),
|
||||
Render(SECOND, Active)
|
||||
Render(SECOND, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -1141,7 +1141,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Update(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead))
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// second state finished transitioning out, now dies.
|
||||
|
@ -1151,7 +1151,7 @@ mod tests {
|
|||
context.take_log(),
|
||||
vec![
|
||||
StateChange(SECOND, Dead, TransitionOut(TransitionTo::Dead)),
|
||||
StateChange(FIRST, Dead, Paused)
|
||||
StateChange(FIRST, Dead, Paused),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -1187,7 +1187,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionIn, Pending),
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning in, now moves to active
|
||||
|
@ -1197,7 +1197,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FIRST, Active, TransitionIn),
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -1213,7 +1213,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning out, now dies.
|
||||
|
@ -1227,7 +1227,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionIn, Pending),
|
||||
Transition(SECOND, TransitionIn),
|
||||
Update(SECOND, TransitionIn),
|
||||
Render(SECOND, TransitionIn)
|
||||
Render(SECOND, TransitionIn),
|
||||
]
|
||||
);
|
||||
// second state finished transitioning in, now moves to active
|
||||
|
@ -1237,7 +1237,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(SECOND, Active, TransitionIn),
|
||||
Update(SECOND, Active),
|
||||
Render(SECOND, Active)
|
||||
Render(SECOND, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -1252,7 +1252,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Update(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead))
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// state finished transitioning out, now dies
|
||||
|
@ -1279,7 +1279,7 @@ mod tests {
|
|||
id,
|
||||
counter: 0,
|
||||
push_after,
|
||||
pop_after
|
||||
pop_after,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1337,7 +1337,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionIn, Pending),
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning in, now moves to active
|
||||
|
@ -1347,7 +1347,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FIRST, Active, TransitionIn),
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
// wait for first state's counter to count up to where it should push the second state
|
||||
|
@ -1357,7 +1357,7 @@ mod tests {
|
|||
context.take_log(),
|
||||
vec![
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -1370,7 +1370,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionOut(TransitionTo::Paused), Active),
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Paused)),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning out, now is paused. second state will transition in
|
||||
|
@ -1383,7 +1383,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionIn, Pending),
|
||||
Transition(SECOND, TransitionIn),
|
||||
Update(SECOND, TransitionIn),
|
||||
Render(SECOND, TransitionIn)
|
||||
Render(SECOND, TransitionIn),
|
||||
]
|
||||
);
|
||||
// second state finished transitioning in, now moves to active
|
||||
|
@ -1393,7 +1393,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(SECOND, Active, TransitionIn),
|
||||
Update(SECOND, Active),
|
||||
Render(SECOND, Active)
|
||||
Render(SECOND, Active),
|
||||
]
|
||||
);
|
||||
// wait for second state's counter to count up to where it should pop itself
|
||||
|
@ -1403,7 +1403,7 @@ mod tests {
|
|||
context.take_log(),
|
||||
vec![
|
||||
Update(SECOND, Active),
|
||||
Render(SECOND, Active)
|
||||
Render(SECOND, Active),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -1416,7 +1416,7 @@ mod tests {
|
|||
StateChange(SECOND, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Update(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead))
|
||||
Render(SECOND, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// second state finished transitioning out, now dies. first state wakes up again and
|
||||
|
@ -1430,7 +1430,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionIn, Resume),
|
||||
Transition(FIRST, TransitionIn),
|
||||
Update(FIRST, TransitionIn),
|
||||
Render(FIRST, TransitionIn)
|
||||
Render(FIRST, TransitionIn),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning in, now moves to active
|
||||
|
@ -1440,7 +1440,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FIRST, Active, TransitionIn),
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
// wait for first state's counter to count up to where it should pop itself
|
||||
|
@ -1450,7 +1450,7 @@ mod tests {
|
|||
context.take_log(),
|
||||
vec![
|
||||
Update(FIRST, Active),
|
||||
Render(FIRST, Active)
|
||||
Render(FIRST, Active),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -1463,7 +1463,7 @@ mod tests {
|
|||
StateChange(FIRST, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Update(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead))
|
||||
Render(FIRST, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
// first state finished transitioning out, now dies
|
||||
|
@ -1499,7 +1499,7 @@ mod tests {
|
|||
StateChange(FOO, TransitionIn, Pending),
|
||||
Transition(FOO, TransitionIn),
|
||||
Update(FOO, TransitionIn),
|
||||
Render(FOO, TransitionIn)
|
||||
Render(FOO, TransitionIn),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -1513,7 +1513,7 @@ mod tests {
|
|||
vec![
|
||||
StateChange(FOO, Active, TransitionIn),
|
||||
Update(FOO, Active),
|
||||
Render(FOO, Active)
|
||||
Render(FOO, Active),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -1528,7 +1528,7 @@ mod tests {
|
|||
StateChange(FOO, TransitionOut(TransitionTo::Dead), Active),
|
||||
Transition(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
Update(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
Render(FOO, TransitionOut(TransitionTo::Dead))
|
||||
Render(FOO, TransitionOut(TransitionTo::Dead)),
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -146,15 +146,15 @@ impl From<sdl2::event::Event> for SystemEvent {
|
|||
keycode: keycode.map(|keycode| keycode.into()),
|
||||
scancode: scancode.map(|scancode| scancode.into()),
|
||||
keymod: KeyModifiers::from_bits_truncate(keymod.bits()),
|
||||
repeat
|
||||
repeat,
|
||||
})
|
||||
},
|
||||
}
|
||||
sdl2::event::Event::KeyUp { keycode, scancode, keymod, repeat, .. } => {
|
||||
SystemEvent::Keyboard(KeyboardEvent::KeyUp {
|
||||
keycode: keycode.map(|keycode| keycode.into()),
|
||||
scancode: scancode.map(|scancode| scancode.into()),
|
||||
keymod: KeyModifiers::from_bits_truncate(keymod.bits()),
|
||||
repeat
|
||||
repeat,
|
||||
})
|
||||
}
|
||||
sdl2::event::Event::MouseMotion { mousestate, x, y, xrel, yrel, .. } => {
|
||||
|
@ -165,7 +165,7 @@ impl From<sdl2::event::Event> for SystemEvent {
|
|||
y_delta: yrel,
|
||||
buttons: MouseButtons::from_bits_truncate(mousestate.to_sdl_state()),
|
||||
})
|
||||
},
|
||||
}
|
||||
sdl2::event::Event::MouseButtonDown { mouse_btn, clicks, x, y, .. } => {
|
||||
SystemEvent::Mouse(MouseEvent::MouseButtonDown {
|
||||
x,
|
||||
|
@ -173,7 +173,7 @@ impl From<sdl2::event::Event> for SystemEvent {
|
|||
clicks,
|
||||
button: mouse_btn.into(),
|
||||
})
|
||||
},
|
||||
}
|
||||
sdl2::event::Event::MouseButtonUp { mouse_btn, clicks, x, y, .. } => {
|
||||
SystemEvent::Mouse(MouseButtonUp {
|
||||
x,
|
||||
|
@ -181,7 +181,7 @@ impl From<sdl2::event::Event> for SystemEvent {
|
|||
clicks,
|
||||
button: mouse_btn.into(),
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
_ => SystemEvent::Unimplemented,
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ fn is_x11_compositor_skipping_problematic() -> bool {
|
|||
Ok(value) => value.eq_ignore_ascii_case("KDE"),
|
||||
Err(_) => false
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ impl SystemBuilder {
|
|||
"1"
|
||||
} else {
|
||||
"0"
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// build all the individual SDL subsystems
|
||||
|
|
|
@ -202,7 +202,7 @@ impl LzwBytesWriter {
|
|||
pub fn write_code<T: WriteBytesExt>(
|
||||
&mut self,
|
||||
writer: &mut T,
|
||||
code: LzwCode
|
||||
code: LzwCode,
|
||||
) -> Result<(), LzwError> {
|
||||
self.packer.push_code(code)?;
|
||||
|
||||
|
@ -351,14 +351,14 @@ impl LzwBytesReader {
|
|||
) -> Result<Option<LzwCode>, LzwError> {
|
||||
loop {
|
||||
if let Some(code) = self.unpacker.take_code() {
|
||||
return Ok(Some(code))
|
||||
return Ok(Some(code));
|
||||
} else {
|
||||
match self.read_byte(reader) {
|
||||
Ok(Some(byte)) => self.unpacker.push_byte(byte)?,
|
||||
Ok(None) => return Ok(None),
|
||||
Err(LzwError::IOError(error)) if error.kind() == std::io::ErrorKind::UnexpectedEof => {
|
||||
return Ok(None)
|
||||
},
|
||||
return Ok(None);
|
||||
}
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ impl LzwBytesReader {
|
|||
pub fn lzw_encode<S, D>(
|
||||
src: &mut S,
|
||||
dest: &mut D,
|
||||
min_code_size: usize
|
||||
min_code_size: usize,
|
||||
) -> Result<(), LzwError>
|
||||
where
|
||||
S: ReadBytesExt,
|
||||
|
@ -413,7 +413,7 @@ where
|
|||
writer.write_code(dest, end_of_info_code)?;
|
||||
writer.flush(dest)?;
|
||||
return Ok(());
|
||||
},
|
||||
}
|
||||
Err(error) => return Err(LzwError::IOError(error))
|
||||
};
|
||||
|
||||
|
@ -581,7 +581,7 @@ where
|
|||
current_bit_size = min_code_size + 1;
|
||||
reader.reset_bit_size();
|
||||
break 'inner;
|
||||
},
|
||||
}
|
||||
Some(code) => code,
|
||||
None => return Err(LzwError::EncodingError(String::from("Unexpected end of code stream"))),
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue