rust/theme-editor/src/main.rs
author Wuzzy <Wuzzy2@mail.ru>
Mon, 07 Oct 2019 14:18:31 +0200
changeset 15447 6031c0cfec89
parent 14128 59ec51b78737
permissions -rw-r--r--
Make sure AI doesn't skip after collecting ammo. Fixes bug #796
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
     1
use sdl2::{
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
     2
    keyboard::Scancode,
14035
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
     3
    event::EventType,
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
     4
    surface::Surface,
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
     5
    pixels::{
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
     6
        PixelFormatEnum, Color
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
     7
    }
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
     8
};
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
     9
14095
43d956f41cd4 update theme editor
alfadur
parents: 14059
diff changeset
    10
use integral_geometry::{Point, Size, Rect, Line};
14035
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    11
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    12
use rand::{
14035
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    13
    thread_rng, RngCore, Rng,
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    14
    distributions::uniform::SampleUniform
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    15
};
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    16
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    17
use landgen::{
14095
43d956f41cd4 update theme editor
alfadur
parents: 14059
diff changeset
    18
    template_based::TemplatedLandGenerator,
43d956f41cd4 update theme editor
alfadur
parents: 14059
diff changeset
    19
    outline_template::OutlineTemplate,
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    20
    LandGenerator,
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    21
    LandGenerationParameters
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    22
};
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    23
use land2d::Land2D;
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    24
use lfprng::LaggedFibonacciPRNG;
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    25
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    26
struct LandSource<T> {
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    27
    rnd: LaggedFibonacciPRNG,
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    28
    generator: T
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    29
}
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    30
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    31
impl <T: LandGenerator> LandSource<T> {
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    32
    fn new(generator: T) -> Self {
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    33
        let mut init = [0u8; 64];
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    34
        thread_rng().fill_bytes(&mut init);
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    35
        LandSource {
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    36
            rnd: LaggedFibonacciPRNG::new(&init),
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    37
            generator
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    38
        }
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    39
    }
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
    40
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    41
    fn next(&mut self, parameters: LandGenerationParameters<u32>) -> Land2D<u32> {
14128
59ec51b78737 fix compile errors
alfadur
parents: 14107
diff changeset
    42
        self.generator.generate_land(&parameters, &mut self.rnd)
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    43
    }
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    44
}
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
    45
14035
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    46
fn fill_pixels(pixels: &mut [u8], land: &Land2D<u32>) {
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    47
    for (surf_row, land_row) in pixels.chunks_mut(land.width() * 4).zip(land.rows()) {
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    48
        for (surf_pixel, land_pixel) in surf_row.chunks_mut(4).zip(land_row) {
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    49
            if let [b, g, r, a] = surf_pixel {
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    50
                *a = 255; *r = *land_pixel as u8;
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    51
            }
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    52
        }
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    53
    }
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    54
}
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    55
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    56
fn fill_texture(surface: &mut Surface, land: &Land2D<u32>) {
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    57
    if surface.must_lock() {
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    58
        surface.with_lock_mut(|data| fill_pixels(data, land));
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    59
    } else {
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    60
        surface.without_lock_mut().map(|data| fill_pixels(data, land));
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    61
    }
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    62
}
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    63
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    64
fn rnd<T: Default + SampleUniform + Ord>(max: T) -> T {
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    65
    thread_rng().gen_range(T::default(), max)
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    66
}
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    67
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    68
const WINDOW_WIDTH: u32 = 800;
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    69
const WINDOW_HEIGHT: u32 = 600;
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    70
const WINDOW_SIZE: Size = Size {width: WINDOW_WIDTH as usize, height: WINDOW_HEIGHT as usize};
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    71
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    72
const PLAY_WIDTH: u32 = 3072;
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    73
const PLAY_HEIGHT: u32 = 1424;
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    74
const PLAY_SIZE: Size = Size {width: PLAY_WIDTH as usize, height: PLAY_HEIGHT as usize};
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    75
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    76
const LAND_WIDTH: u32 = 4096;
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    77
const LAND_HEIGHT: u32 = 2048;
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    78
const LAND_SIZE: Size = Size {width: LAND_WIDTH as usize, height: LAND_HEIGHT as usize};
14035
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
    79
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
    80
fn point() -> Point {
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    81
    Point::new(rnd(LAND_WIDTH as i32), rnd(LAND_HEIGHT as i32))
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
    82
}
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
    83
fn rect() -> Rect {
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    84
    Rect::new(rnd(LAND_WIDTH as i32), rnd(LAND_HEIGHT as i32), rnd(120) + 8, rnd(120) + 8)
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
    85
}
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
    86
14103
a8e194ae26e8 add basic land template to theme editor
alfadur
parents: 14095
diff changeset
    87
fn land_rect() -> Rect {
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    88
    Rect::at_origin(PLAY_SIZE)
14103
a8e194ae26e8 add basic land template to theme editor
alfadur
parents: 14095
diff changeset
    89
}
a8e194ae26e8 add basic land template to theme editor
alfadur
parents: 14095
diff changeset
    90
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    91
fn basic_template() -> OutlineTemplate {
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    92
    OutlineTemplate::new(PLAY_SIZE)
14103
a8e194ae26e8 add basic land template to theme editor
alfadur
parents: 14095
diff changeset
    93
        .with_fill_points(vec![land_rect().center()])
a8e194ae26e8 add basic land template to theme editor
alfadur
parents: 14095
diff changeset
    94
        .add_island(&land_rect().split_at(land_rect().center()))
a8e194ae26e8 add basic land template to theme editor
alfadur
parents: 14095
diff changeset
    95
}
a8e194ae26e8 add basic land template to theme editor
alfadur
parents: 14095
diff changeset
    96
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    97
macro_rules! pseudo_yaml {
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    98
    [$({x: $x: tt, y: $y: tt, w: $w: tt, h: $h: tt}),*] => {
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
    99
        [$(Rect::new($x, $y, $w, $h)),*]
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   100
    }
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   101
}
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   102
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   103
fn test_template() -> OutlineTemplate {
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   104
    let island = pseudo_yaml![
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   105
        {x: 810, y: 1424, w: 1, h: 1},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   106
        {x: 560, y: 1160, w: 130, h: 170},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   107
        {x: 742, y: 1106, w: 316, h: 150},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   108
        {x: 638, y: 786, w: 270, h: 180},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   109
        {x: 646, y: 576, w: 242, h: 156},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   110
        {x: 952, y: 528, w: 610, h: 300},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   111
        {x: 1150, y: 868, w: 352, h: 324},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   112
        {x: 1050, y: 1424, w: 500, h: 1},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   113
        {x: 1650, y: 1500, w: 1, h: 1},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   114
        {x: 1890, y: 1424, w: 1, h: 1},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   115
        {x: 1852, y: 1304, w: 74, h: 12},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   116
        {x: 1648, y: 975, w: 68, h: 425},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   117
        {x: 1826, y: 992, w: 140, h: 142},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   118
        {x: 1710, y: 592, w: 150, h: 350},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   119
        {x: 1988, y: 594, w: 148, h: 242},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   120
        {x: 2018, y: 872, w: 276, h: 314},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   121
        {x: 2110, y: 1250, w: 130, h: 86},
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   122
        {x: 2134, y: 1424, w: 1, h: 1}
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   123
    ];
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   124
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   125
    OutlineTemplate::new(PLAY_SIZE)
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   126
        .add_island(&island)
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   127
        .add_fill_points(&[Point::new(1023, 0)])
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   128
}
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   129
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   130
fn init_source() -> LandSource<TemplatedLandGenerator> {
14103
a8e194ae26e8 add basic land template to theme editor
alfadur
parents: 14095
diff changeset
   131
    let template = test_template();
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   132
    let generator = TemplatedLandGenerator::new(template);
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   133
    LandSource::new(generator)
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   134
}
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   135
14107
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   136
fn draw_center_mark(land: &mut Land2D<u32>) {
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   137
    for i in 0..32 {
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   138
        land.draw_thick_line(Line::new(Point::new(LAND_WIDTH as i32 / 2, 0),
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   139
                                       Point::new(LAND_WIDTH as i32 / 2, LAND_HEIGHT as i32)), 10, 128);
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   140
        land.draw_thick_line(Line::new(Point::new(0, LAND_HEIGHT as i32 / 2),
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   141
                                       Point::new(LAND_WIDTH as i32, LAND_HEIGHT as i32 / 2)), 10, 128);
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   142
        land.fill_circle(Point::new(LAND_WIDTH as i32, LAND_HEIGHT as i32) / 2, 60, 128);
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   143
    }
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   144
}
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   145
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   146
fn draw_random_lines(land: &mut Land2D<u32>) {
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   147
    for i in 0..32 {
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   148
        land.draw_thick_line(Line::new(point(), point()), rnd(5), 128);
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   149
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   150
        land.fill_circle(point(), rnd(60), 128);
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   151
    }
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   152
}
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   153
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   154
fn main() {
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   155
    let sdl = sdl2::init().unwrap();
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   156
    let _image = sdl2::image::init(sdl2::image::INIT_PNG).unwrap();
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   157
    let events = sdl.event().unwrap();
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   158
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   159
    let mut pump = sdl.event_pump().unwrap();
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   160
    let video = sdl.video().unwrap();
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   161
    let window = video.window("Theme Editor", WINDOW_WIDTH, WINDOW_HEIGHT)
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   162
        .position_centered()
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   163
        .build().unwrap();
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   164
14059
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   165
    let mut source = init_source();
3185fb34f3b5 update theme editor to use new land generator implementation
alfadur
parents: 14038
diff changeset
   166
    let mut land = source.next(
14128
59ec51b78737 fix compile errors
alfadur
parents: 14107
diff changeset
   167
        LandGenerationParameters::new(0, u32::max_value(), 1, false, false));
14107
c6923ce139a2 mark the center in the theme editor
alfadur
parents: 14104
diff changeset
   168
    draw_center_mark(&mut land);
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   169
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   170
    let mut land_surf = Surface::new(LAND_WIDTH, LAND_HEIGHT, PixelFormatEnum::ARGB8888).unwrap();
14035
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
   171
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
   172
    fill_texture(&mut land_surf, &land);
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
   173
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
   174
    let mut win_surf = window.surface(&pump).unwrap();
14104
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   175
    let dest_rect = win_surf.rect();
7845beb87cb5 add an existing template to the theme editor
alfadur
parents: 14103
diff changeset
   176
    land_surf.blit_scaled(land_surf.rect(), &mut win_surf, dest_rect).unwrap();
14035
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
   177
    win_surf.update_window();
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
   178
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   179
    'pool: loop {
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   180
        use sdl2::event::Event::*;
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   181
        pump.pump_events();
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   182
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   183
        while let Some(event) = pump.poll_event() {
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   184
            match event {
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   185
                Quit{ .. } => break 'pool,
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   186
                _ => ()
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   187
            }
14035
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
   188
        }
14033
0f517cbfe16d start a theme editor as an excuse to see land generator in action
alfadur
parents:
diff changeset
   189
    }
14035
2ebd505e62c1 make theme editor render some random map lines
alfadur
parents: 14033
diff changeset
   190
}