Struct gemini_engine::elements::view::View
source · pub struct View {
pub width: usize,
pub height: usize,
pub background_char: ColChar,
pub coord_numbers_in_render: bool,
/* private fields */
}
Expand description
The View struct is the canvas on which you will print all of your ViewElements. In normal use, you would clear the View, blit
all your ViewElements to it and then render. The following example demonstrates a piece of code that will render a View of width 9 and height 3, with a single Point in the middle
use gemini_engine::elements::{view::{Wrapping, ColChar}, View, Point, Vec2D};
let mut view = View::new(9, 3, ColChar::BACKGROUND);
let point = Point::new(Vec2D::new(4,1), ColChar::SOLID);
view.blit(&point, Wrapping::Panic);
view.display_render().unwrap();
Fields§
§width: usize
The width of the View
height: usize
The height of the View
background_char: ColChar
The character that the View will be filled with by default on clear
coord_numbers_in_render: bool
A boolean determining whether the render should contain numbers on the top and left signifying the corresponding pixels’ X/Y value values
Implementations§
source§impl View
impl View
sourcepub fn new(width: usize, height: usize, background_char: ColChar) -> View
pub fn new(width: usize, height: usize, background_char: ColChar) -> View
Create a new View
using width
, height
and background_char
parameters
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut view = View::new(40, 8, ColChar::BACKGROUND);
let mut point = Point::new(Vec2D { x: 10, y: 5 }, ColChar::SOLID);
loop {
view.clear();
point.pos.x += 1;
view.blit(&point, Wrapping::Wrap);
view.display_render().unwrap();
gameloop::sleep_fps(FPS, None);
}
}
More examples
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let mut view = View::new(350, 90, ColChar::BACKGROUND);
let mut viewport = Viewport::new(
Transform3D::new_tr(Vec3D::new(0.0, 0.0, 5.0), Vec3D::new(-0.5, 0.3, 0.0)),
FOV,
view.center(),
);
let cube = Mesh3D::default_cube();
fps_gameloop!(
{
view.clear();
viewport.transform.rotation.y -= 0.05;
},
{
view.blit(
&viewport.render(vec![&cube], DisplayMode::Solid),
Wrapping::Ignore,
);
view.display_render().unwrap();
},
FPS,
|elapsed: gameloop::Duration, frame_skip| {
println!(
"Elapsed: {:.2?}µs | Frame skip: {}",
elapsed.as_micros(),
frame_skip
);
}
);
}
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() {
let mut view = View::new(50, 12, ColChar::BACKGROUND);
let mut blocks = vec![
Rect::new(Vec2D::new(0, 0), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 2), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 4), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 6), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 8), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 10), BLOCK_SIZE, FILL_CHAR),
];
let mut i = 0;
fps_gameloop!(
{
i += 1;
for (j, block) in blocks.iter_mut().enumerate() {
if i % 2_u32.pow(j as u32) == 0 {
block.pos.x += 1;
}
}
},
{
view.clear();
for block in &blocks {
view.blit(block, Wrapping::Wrap);
}
view.display_render().unwrap();
if blocks.iter().all(|b| b.pos.x % view.width as isize == 0) {
thread::sleep(Duration::from_secs(2));
};
},
200.0
);
}
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
fn main() {
let mut view = View::new(60, 10, BACKGROUND_CHAR);
view.coord_numbers_in_render = true;
let mut point = Point::new(Vec2D::from((5u8, 9u8)), FILL_CHAR);
let mut line = Line::new(Vec2D::new(2, 8), Vec2D::new(28, 7), FILL_CHAR);
let mut line1_direction = -1;
let rect = Rect::new(
Vec2D { x: 11, y: 1 },
Vec2D { x: 9, y: 3 },
ColChar::SOLID.with_rgb(200, 30, 0),
);
let test_image = r"
______
/|_||_\`.__
( _ _ _\
=`-(_)--(_)-' ";
let mut sprite = Sprite::new(
Vec2D::new(30, 1),
test_image,
Modifier::from_rgb(20, 200, 0),
);
let mut blit_elapsed = Duration::default();
let mut render_elapsed = Duration::default();
fps_gameloop!(
{
point.pos.x += 2;
// loop the position back to the other side. This can be done with `Wrapping::Wrap` but it won't change the element's actual position, so the point position being printed would continue to increase without looping
point.pos %= view.size();
line.pos1.y += line1_direction;
line.pos0.y = 10 - line.pos1.y;
if line.pos1.y > 7 {
line1_direction = -1;
} else if line.pos1.y < 3 {
line1_direction = 1;
}
sprite.pos.x += 1;
},
{
view.clear();
let now = Instant::now();
view.blit(&point, Wrapping::Panic);
view.blit(&line, Wrapping::Panic);
view.blit(&rect, Wrapping::Panic);
view.blit(&sprite, Wrapping::Wrap);
blit_elapsed = now.elapsed();
let now = Instant::now();
view.display_render().unwrap();
render_elapsed = now.elapsed();
},
FPS,
|total_elapsed: Duration, _frame_skip| {
println!(
"Blitting: {:.2?} microseconds | Rendering: {:.2?} microseconds| Total: {:.2?}",
blit_elapsed.as_micros(),
render_elapsed.as_micros(),
total_elapsed.as_micros()
);
println!("Point position: {}", point.pos);
}
);
}
sourcepub fn size(&self) -> Vec2D
pub fn size(&self) -> Vec2D
Examples found in repository?
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
fn main() {
let mut view = View::new(60, 10, BACKGROUND_CHAR);
view.coord_numbers_in_render = true;
let mut point = Point::new(Vec2D::from((5u8, 9u8)), FILL_CHAR);
let mut line = Line::new(Vec2D::new(2, 8), Vec2D::new(28, 7), FILL_CHAR);
let mut line1_direction = -1;
let rect = Rect::new(
Vec2D { x: 11, y: 1 },
Vec2D { x: 9, y: 3 },
ColChar::SOLID.with_rgb(200, 30, 0),
);
let test_image = r"
______
/|_||_\`.__
( _ _ _\
=`-(_)--(_)-' ";
let mut sprite = Sprite::new(
Vec2D::new(30, 1),
test_image,
Modifier::from_rgb(20, 200, 0),
);
let mut blit_elapsed = Duration::default();
let mut render_elapsed = Duration::default();
fps_gameloop!(
{
point.pos.x += 2;
// loop the position back to the other side. This can be done with `Wrapping::Wrap` but it won't change the element's actual position, so the point position being printed would continue to increase without looping
point.pos %= view.size();
line.pos1.y += line1_direction;
line.pos0.y = 10 - line.pos1.y;
if line.pos1.y > 7 {
line1_direction = -1;
} else if line.pos1.y < 3 {
line1_direction = 1;
}
sprite.pos.x += 1;
},
{
view.clear();
let now = Instant::now();
view.blit(&point, Wrapping::Panic);
view.blit(&line, Wrapping::Panic);
view.blit(&rect, Wrapping::Panic);
view.blit(&sprite, Wrapping::Wrap);
blit_elapsed = now.elapsed();
let now = Instant::now();
view.display_render().unwrap();
render_elapsed = now.elapsed();
},
FPS,
|total_elapsed: Duration, _frame_skip| {
println!(
"Blitting: {:.2?} microseconds | Rendering: {:.2?} microseconds| Total: {:.2?}",
blit_elapsed.as_micros(),
render_elapsed.as_micros(),
total_elapsed.as_micros()
);
println!("Point position: {}", point.pos);
}
);
}
sourcepub fn center(&self) -> Vec2D
pub fn center(&self) -> Vec2D
Return a Vec2D
representing the centre of the View
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let mut view = View::new(350, 90, ColChar::BACKGROUND);
let mut viewport = Viewport::new(
Transform3D::new_tr(Vec3D::new(0.0, 0.0, 5.0), Vec3D::new(-0.5, 0.3, 0.0)),
FOV,
view.center(),
);
let cube = Mesh3D::default_cube();
fps_gameloop!(
{
view.clear();
viewport.transform.rotation.y -= 0.05;
},
{
view.blit(
&viewport.render(vec![&cube], DisplayMode::Solid),
Wrapping::Ignore,
);
view.display_render().unwrap();
},
FPS,
|elapsed: gameloop::Duration, frame_skip| {
println!(
"Elapsed: {:.2?}µs | Frame skip: {}",
elapsed.as_micros(),
frame_skip
);
}
);
}
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the View
of all pixels
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut view = View::new(40, 8, ColChar::BACKGROUND);
let mut point = Point::new(Vec2D { x: 10, y: 5 }, ColChar::SOLID);
loop {
view.clear();
point.pos.x += 1;
view.blit(&point, Wrapping::Wrap);
view.display_render().unwrap();
gameloop::sleep_fps(FPS, None);
}
}
More examples
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let mut view = View::new(350, 90, ColChar::BACKGROUND);
let mut viewport = Viewport::new(
Transform3D::new_tr(Vec3D::new(0.0, 0.0, 5.0), Vec3D::new(-0.5, 0.3, 0.0)),
FOV,
view.center(),
);
let cube = Mesh3D::default_cube();
fps_gameloop!(
{
view.clear();
viewport.transform.rotation.y -= 0.05;
},
{
view.blit(
&viewport.render(vec![&cube], DisplayMode::Solid),
Wrapping::Ignore,
);
view.display_render().unwrap();
},
FPS,
|elapsed: gameloop::Duration, frame_skip| {
println!(
"Elapsed: {:.2?}µs | Frame skip: {}",
elapsed.as_micros(),
frame_skip
);
}
);
}
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() {
let mut view = View::new(50, 12, ColChar::BACKGROUND);
let mut blocks = vec![
Rect::new(Vec2D::new(0, 0), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 2), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 4), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 6), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 8), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 10), BLOCK_SIZE, FILL_CHAR),
];
let mut i = 0;
fps_gameloop!(
{
i += 1;
for (j, block) in blocks.iter_mut().enumerate() {
if i % 2_u32.pow(j as u32) == 0 {
block.pos.x += 1;
}
}
},
{
view.clear();
for block in &blocks {
view.blit(block, Wrapping::Wrap);
}
view.display_render().unwrap();
if blocks.iter().all(|b| b.pos.x % view.width as isize == 0) {
thread::sleep(Duration::from_secs(2));
};
},
200.0
);
}
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
fn main() {
let mut view = View::new(60, 10, BACKGROUND_CHAR);
view.coord_numbers_in_render = true;
let mut point = Point::new(Vec2D::from((5u8, 9u8)), FILL_CHAR);
let mut line = Line::new(Vec2D::new(2, 8), Vec2D::new(28, 7), FILL_CHAR);
let mut line1_direction = -1;
let rect = Rect::new(
Vec2D { x: 11, y: 1 },
Vec2D { x: 9, y: 3 },
ColChar::SOLID.with_rgb(200, 30, 0),
);
let test_image = r"
______
/|_||_\`.__
( _ _ _\
=`-(_)--(_)-' ";
let mut sprite = Sprite::new(
Vec2D::new(30, 1),
test_image,
Modifier::from_rgb(20, 200, 0),
);
let mut blit_elapsed = Duration::default();
let mut render_elapsed = Duration::default();
fps_gameloop!(
{
point.pos.x += 2;
// loop the position back to the other side. This can be done with `Wrapping::Wrap` but it won't change the element's actual position, so the point position being printed would continue to increase without looping
point.pos %= view.size();
line.pos1.y += line1_direction;
line.pos0.y = 10 - line.pos1.y;
if line.pos1.y > 7 {
line1_direction = -1;
} else if line.pos1.y < 3 {
line1_direction = 1;
}
sprite.pos.x += 1;
},
{
view.clear();
let now = Instant::now();
view.blit(&point, Wrapping::Panic);
view.blit(&line, Wrapping::Panic);
view.blit(&rect, Wrapping::Panic);
view.blit(&sprite, Wrapping::Wrap);
blit_elapsed = now.elapsed();
let now = Instant::now();
view.display_render().unwrap();
render_elapsed = now.elapsed();
},
FPS,
|total_elapsed: Duration, _frame_skip| {
println!(
"Blitting: {:.2?} microseconds | Rendering: {:.2?} microseconds| Total: {:.2?}",
blit_elapsed.as_micros(),
render_elapsed.as_micros(),
total_elapsed.as_micros()
);
println!("Point position: {}", point.pos);
}
);
}
sourcepub fn blit(&mut self, element: &impl ViewElement, wrapping: Wrapping)
pub fn blit(&mut self, element: &impl ViewElement, wrapping: Wrapping)
Blit a struct implementing ViewElement
to the View
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut view = View::new(40, 8, ColChar::BACKGROUND);
let mut point = Point::new(Vec2D { x: 10, y: 5 }, ColChar::SOLID);
loop {
view.clear();
point.pos.x += 1;
view.blit(&point, Wrapping::Wrap);
view.display_render().unwrap();
gameloop::sleep_fps(FPS, None);
}
}
More examples
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let mut view = View::new(350, 90, ColChar::BACKGROUND);
let mut viewport = Viewport::new(
Transform3D::new_tr(Vec3D::new(0.0, 0.0, 5.0), Vec3D::new(-0.5, 0.3, 0.0)),
FOV,
view.center(),
);
let cube = Mesh3D::default_cube();
fps_gameloop!(
{
view.clear();
viewport.transform.rotation.y -= 0.05;
},
{
view.blit(
&viewport.render(vec![&cube], DisplayMode::Solid),
Wrapping::Ignore,
);
view.display_render().unwrap();
},
FPS,
|elapsed: gameloop::Duration, frame_skip| {
println!(
"Elapsed: {:.2?}µs | Frame skip: {}",
elapsed.as_micros(),
frame_skip
);
}
);
}
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() {
let mut view = View::new(50, 12, ColChar::BACKGROUND);
let mut blocks = vec![
Rect::new(Vec2D::new(0, 0), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 2), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 4), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 6), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 8), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 10), BLOCK_SIZE, FILL_CHAR),
];
let mut i = 0;
fps_gameloop!(
{
i += 1;
for (j, block) in blocks.iter_mut().enumerate() {
if i % 2_u32.pow(j as u32) == 0 {
block.pos.x += 1;
}
}
},
{
view.clear();
for block in &blocks {
view.blit(block, Wrapping::Wrap);
}
view.display_render().unwrap();
if blocks.iter().all(|b| b.pos.x % view.width as isize == 0) {
thread::sleep(Duration::from_secs(2));
};
},
200.0
);
}
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
fn main() {
let mut view = View::new(60, 10, BACKGROUND_CHAR);
view.coord_numbers_in_render = true;
let mut point = Point::new(Vec2D::from((5u8, 9u8)), FILL_CHAR);
let mut line = Line::new(Vec2D::new(2, 8), Vec2D::new(28, 7), FILL_CHAR);
let mut line1_direction = -1;
let rect = Rect::new(
Vec2D { x: 11, y: 1 },
Vec2D { x: 9, y: 3 },
ColChar::SOLID.with_rgb(200, 30, 0),
);
let test_image = r"
______
/|_||_\`.__
( _ _ _\
=`-(_)--(_)-' ";
let mut sprite = Sprite::new(
Vec2D::new(30, 1),
test_image,
Modifier::from_rgb(20, 200, 0),
);
let mut blit_elapsed = Duration::default();
let mut render_elapsed = Duration::default();
fps_gameloop!(
{
point.pos.x += 2;
// loop the position back to the other side. This can be done with `Wrapping::Wrap` but it won't change the element's actual position, so the point position being printed would continue to increase without looping
point.pos %= view.size();
line.pos1.y += line1_direction;
line.pos0.y = 10 - line.pos1.y;
if line.pos1.y > 7 {
line1_direction = -1;
} else if line.pos1.y < 3 {
line1_direction = 1;
}
sprite.pos.x += 1;
},
{
view.clear();
let now = Instant::now();
view.blit(&point, Wrapping::Panic);
view.blit(&line, Wrapping::Panic);
view.blit(&rect, Wrapping::Panic);
view.blit(&sprite, Wrapping::Wrap);
blit_elapsed = now.elapsed();
let now = Instant::now();
view.display_render().unwrap();
render_elapsed = now.elapsed();
},
FPS,
|total_elapsed: Duration, _frame_skip| {
println!(
"Blitting: {:.2?} microseconds | Rendering: {:.2?} microseconds| Total: {:.2?}",
blit_elapsed.as_micros(),
render_elapsed.as_micros(),
total_elapsed.as_micros()
);
println!("Point position: {}", point.pos);
}
);
}
sourcepub fn display_render(&self) -> Result<()>
pub fn display_render(&self) -> Result<()>
Display the View
. View
implements the Display
trait and so can be rendered in many ways (such as println!("{view}");
), but this is intended to be the fastest way possible.
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut view = View::new(40, 8, ColChar::BACKGROUND);
let mut point = Point::new(Vec2D { x: 10, y: 5 }, ColChar::SOLID);
loop {
view.clear();
point.pos.x += 1;
view.blit(&point, Wrapping::Wrap);
view.display_render().unwrap();
gameloop::sleep_fps(FPS, None);
}
}
More examples
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
fn main() {
let mut view = View::new(350, 90, ColChar::BACKGROUND);
let mut viewport = Viewport::new(
Transform3D::new_tr(Vec3D::new(0.0, 0.0, 5.0), Vec3D::new(-0.5, 0.3, 0.0)),
FOV,
view.center(),
);
let cube = Mesh3D::default_cube();
fps_gameloop!(
{
view.clear();
viewport.transform.rotation.y -= 0.05;
},
{
view.blit(
&viewport.render(vec![&cube], DisplayMode::Solid),
Wrapping::Ignore,
);
view.display_render().unwrap();
},
FPS,
|elapsed: gameloop::Duration, frame_skip| {
println!(
"Elapsed: {:.2?}µs | Frame skip: {}",
elapsed.as_micros(),
frame_skip
);
}
);
}
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() {
let mut view = View::new(50, 12, ColChar::BACKGROUND);
let mut blocks = vec![
Rect::new(Vec2D::new(0, 0), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 2), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 4), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 6), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 8), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 10), BLOCK_SIZE, FILL_CHAR),
];
let mut i = 0;
fps_gameloop!(
{
i += 1;
for (j, block) in blocks.iter_mut().enumerate() {
if i % 2_u32.pow(j as u32) == 0 {
block.pos.x += 1;
}
}
},
{
view.clear();
for block in &blocks {
view.blit(block, Wrapping::Wrap);
}
view.display_render().unwrap();
if blocks.iter().all(|b| b.pos.x % view.width as isize == 0) {
thread::sleep(Duration::from_secs(2));
};
},
200.0
);
}
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
fn main() {
let mut view = View::new(60, 10, BACKGROUND_CHAR);
view.coord_numbers_in_render = true;
let mut point = Point::new(Vec2D::from((5u8, 9u8)), FILL_CHAR);
let mut line = Line::new(Vec2D::new(2, 8), Vec2D::new(28, 7), FILL_CHAR);
let mut line1_direction = -1;
let rect = Rect::new(
Vec2D { x: 11, y: 1 },
Vec2D { x: 9, y: 3 },
ColChar::SOLID.with_rgb(200, 30, 0),
);
let test_image = r"
______
/|_||_\`.__
( _ _ _\
=`-(_)--(_)-' ";
let mut sprite = Sprite::new(
Vec2D::new(30, 1),
test_image,
Modifier::from_rgb(20, 200, 0),
);
let mut blit_elapsed = Duration::default();
let mut render_elapsed = Duration::default();
fps_gameloop!(
{
point.pos.x += 2;
// loop the position back to the other side. This can be done with `Wrapping::Wrap` but it won't change the element's actual position, so the point position being printed would continue to increase without looping
point.pos %= view.size();
line.pos1.y += line1_direction;
line.pos0.y = 10 - line.pos1.y;
if line.pos1.y > 7 {
line1_direction = -1;
} else if line.pos1.y < 3 {
line1_direction = 1;
}
sprite.pos.x += 1;
},
{
view.clear();
let now = Instant::now();
view.blit(&point, Wrapping::Panic);
view.blit(&line, Wrapping::Panic);
view.blit(&rect, Wrapping::Panic);
view.blit(&sprite, Wrapping::Wrap);
blit_elapsed = now.elapsed();
let now = Instant::now();
view.display_render().unwrap();
render_elapsed = now.elapsed();
},
FPS,
|total_elapsed: Duration, _frame_skip| {
println!(
"Blitting: {:.2?} microseconds | Rendering: {:.2?} microseconds| Total: {:.2?}",
blit_elapsed.as_micros(),
render_elapsed.as_micros(),
total_elapsed.as_micros()
);
println!("Point position: {}", point.pos);
}
);
}