rust/lib-hwengine-future/src/lib.rs
author unC0Rr
Thu, 29 Aug 2024 17:09:39 +0200
branchtransitional_engine
changeset 16026 ce4b50823a95
parent 16024 3402b2185698
child 16029 9cbd18220eb7
permissions -rw-r--r--
Allow switching between outline and wfc map generators
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
     1
use integral_geometry::{Point, Size};
15923
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15922
diff changeset
     2
15922
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15921
diff changeset
     3
use landgen::{
15923
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15922
diff changeset
     4
    wavefront_collapse::generator::{
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15922
diff changeset
     5
        TemplateDescription as WfcTemplate,
15922
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15921
diff changeset
     6
    },
16026
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
     7
    outline_template_based::outline_template::OutlineTemplate,
15922
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15921
diff changeset
     8
    LandGenerationParameters, LandGenerator,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents: 15921
diff changeset
     9
};
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    10
use lfprng::LaggedFibonacciPRNG;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    11
use mapgen::{theme::Theme, MapGenerator};
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    12
use std::fs;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    13
use std::{ffi::CStr, path::Path};
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    14
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    15
#[repr(C)]
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    16
pub struct GameField {
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    17
    collision: land2d::Land2D<u16>,
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    18
    pixels: land2d::Land2D<u32>,
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    19
    landgen_parameters: Option<LandGenerationParameters<u16>>,
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    20
}
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    21
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    22
#[no_mangle]
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    23
pub extern "C" fn get_game_field_parameters(
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    24
    game_field: &GameField,
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    25
    width: *mut i32,
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    26
    height: *mut i32,
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    27
    play_width: *mut i32,
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    28
    play_height: *mut i32,
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    29
) {
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    30
    unsafe {
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    31
        *width = game_field.collision.width() as i32;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    32
        *height = game_field.collision.height() as i32;
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    33
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    34
        *play_width = game_field.collision.play_width() as i32;
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    35
        *play_height = game_field.collision.play_height() as i32;
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    36
    }
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    37
}
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    38
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    39
#[no_mangle]
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    40
pub extern "C" fn create_empty_game_field(width: u32, height: u32) -> *mut GameField {
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    41
    let game_field = Box::new(GameField {
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    42
        collision: land2d::Land2D::new(&Size::new(width as usize, height as usize), 0),
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    43
        pixels: land2d::Land2D::new(&Size::new(width as usize, height as usize), 0),
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    44
        landgen_parameters: None,
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    45
    });
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    46
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    47
    Box::leak(game_field)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    48
}
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    49
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
    50
#[no_mangle]
16026
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    51
pub extern "C" fn generate_outline_templated_game_field(
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    52
    feature_size: u32,
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    53
    seed: *const i8,
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    54
    template_type: *const i8,
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    55
    data_path: *const i8,
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    56
) -> *mut GameField {
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    57
    let data_path: &str = unsafe { CStr::from_ptr(data_path) }.to_str().unwrap();
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    58
    let data_path = Path::new(&data_path);
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    59
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    60
    let seed: &str = unsafe { CStr::from_ptr(seed) }.to_str().unwrap();
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    61
    let template_type: &str = unsafe { CStr::from_ptr(template_type) }.to_str().unwrap();
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    62
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    63
    let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes());
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    64
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    65
    let yaml_templates =
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    66
        fs::read_to_string(data_path.join(Path::new("map_templates.yaml")).as_path())
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    67
            .expect("Error reading map templates file");
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    68
    let mut map_gen = MapGenerator::<OutlineTemplate>::new(data_path);
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    69
    map_gen.import_yaml_templates(&yaml_templates);
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    70
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    71
    let distance_divisor = feature_size.pow(2) / 8 + 10;
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    72
    let params = LandGenerationParameters::new(0u16, 0x8000u16, distance_divisor, false, false);
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    73
    let template = map_gen
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    74
        .get_template(template_type, &mut random_numbers_gen)
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    75
        .expect("Error reading outline templates file")
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    76
        .clone();
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    77
    let landgen = map_gen.build_generator(template);
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    78
    let collision = landgen.generate_land(&params, &mut random_numbers_gen);
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    79
    let size = collision.size().size();
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    80
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    81
    let game_field = Box::new(GameField {
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    82
        collision,
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    83
        pixels: land2d::Land2D::new(&size, 0),
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    84
        landgen_parameters: Some(params),
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    85
    });
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    86
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    87
    Box::leak(game_field)
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    88
}
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    89
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    90
#[no_mangle]
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
    91
pub extern "C" fn generate_wfc_templated_game_field(
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    92
    feature_size: u32,
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    93
    seed: *const i8,
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
    94
    template_type: *const i8,
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    95
    data_path: *const i8,
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    96
) -> *mut GameField {
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    97
    let data_path: &str = unsafe { CStr::from_ptr(data_path) }.to_str().unwrap();
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    98
    let data_path = Path::new(&data_path);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
    99
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   100
    let seed: &str = unsafe { CStr::from_ptr(seed) }.to_str().unwrap();
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   101
    let template_type: &str = unsafe { CStr::from_ptr(template_type) }.to_str().unwrap();
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   102
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   103
    let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes());
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   104
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   105
    let yaml_templates =
15923
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15922
diff changeset
   106
        fs::read_to_string(data_path.join(Path::new("wfc_templates.yaml")).as_path())
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   107
            .expect("Error reading map templates file");
16024
3402b2185698 Pass full path to WFC for tile loading
unC0Rr
parents: 15923
diff changeset
   108
    let mut map_gen = MapGenerator::<WfcTemplate>::new(data_path);
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   109
    map_gen.import_yaml_templates(&yaml_templates);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   110
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   111
    let distance_divisor = feature_size.pow(2) / 8 + 10;
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   112
    let params = LandGenerationParameters::new(0u16, 0x8000u16, distance_divisor, false, false);
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   113
    let template = map_gen
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   114
        .get_template(template_type, &mut random_numbers_gen)
16026
ce4b50823a95 Allow switching between outline and wfc map generators
unC0Rr
parents: 16024
diff changeset
   115
        .expect("Error reading wfc templates file")
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   116
        .clone();
15923
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15922
diff changeset
   117
    let landgen = map_gen.build_generator(template);
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   118
    let collision = landgen.generate_land(&params, &mut random_numbers_gen);
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   119
    let size = collision.size().size();
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   120
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   121
    let game_field = Box::new(GameField {
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   122
        collision,
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   123
        pixels: land2d::Land2D::new(&size, 0),
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   124
        landgen_parameters: Some(params),
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   125
    });
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   126
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   127
    Box::leak(game_field)
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   128
}
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   129
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   130
#[no_mangle]
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   131
pub extern "C" fn apply_theme(
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   132
    game_field: &mut GameField,
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   133
    data_path: *const i8,
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   134
    theme_name: *const i8,
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   135
) {
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   136
    let data_path: &str = unsafe { CStr::from_ptr(data_path) }.to_str().unwrap();
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   137
    let data_path = Path::new(&data_path);
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   138
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   139
    let theme_name: &str = unsafe { CStr::from_ptr(theme_name) }.to_str().unwrap();
16024
3402b2185698 Pass full path to WFC for tile loading
unC0Rr
parents: 15923
diff changeset
   140
    let map_gen = MapGenerator::<()>::new(data_path);
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   141
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   142
    let theme = Theme::load(
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   143
        data_path
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   144
            .join(Path::new("Themes"))
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   145
            .join(Path::new(theme_name))
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   146
            .as_path(),
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   147
    )
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   148
    .unwrap();
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   149
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   150
    let params = game_field
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   151
        .landgen_parameters
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   152
        .expect("Land generator parameters specified");
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   153
    let pixels = map_gen.make_texture(&game_field.collision, &params, &theme);
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   154
15905
022ec6b916b7 Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents: 15904
diff changeset
   155
    game_field.pixels = pixels.into();
15904
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   156
}
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   157
33798b649d9c Use rust land generator in hwengine
unC0Rr
parents: 15901
diff changeset
   158
#[no_mangle]
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents: 15905
diff changeset
   159
pub extern "C" fn land_get(game_field: &GameField, x: i32, y: i32) -> u16 {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents: 15905
diff changeset
   160
    game_field.collision.get(y, x)
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   161
}
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   162
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   163
#[no_mangle]
15901
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   164
pub extern "C" fn land_set(game_field: &mut GameField, x: i32, y: i32, value: u16) {
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   165
    game_field.collision.map(y, x, |p| *p = value);
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   166
}
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   167
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   168
#[no_mangle]
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   169
pub extern "C" fn land_row(game_field: &mut GameField, row: i32) -> *mut u16 {
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   170
    game_field.collision[row as usize].as_mut_ptr()
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   171
}
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   172
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   173
#[no_mangle]
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   174
pub extern "C" fn land_fill(
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   175
    game_field: &mut GameField,
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   176
    x: i32,
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   177
    y: i32,
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   178
    border_value: u16,
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   179
    fill_value: u16,
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   180
) {
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   181
    game_field
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   182
        .collision
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   183
        .fill(Point::new(x, y), border_value, fill_value)
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   184
}
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   185
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   186
#[no_mangle]
15912
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents: 15905
diff changeset
   187
pub extern "C" fn land_pixel_get(game_field: &GameField, x: i32, y: i32) -> u32 {
6e22f4390b7e Add basics of wavefront collapse algorithm
unC0Rr
parents: 15905
diff changeset
   188
    game_field.pixels.get(y, x)
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   189
}
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   190
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   191
#[no_mangle]
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   192
pub extern "C" fn land_pixel_set(game_field: &mut GameField, x: i32, y: i32, value: u32) {
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   193
    game_field.pixels.map(y, x, |p| *p = value);
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   194
}
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   195
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   196
#[no_mangle]
15901
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   197
pub extern "C" fn land_pixel_row(game_field: &mut GameField, row: i32) -> *mut u32 {
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   198
    game_field.pixels[row as usize].as_mut_ptr()
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   199
}
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   200
f39f0f614dbf Use LandPixels array allocate in hwengine-future library
unC0Rr
parents: 15900
diff changeset
   201
#[no_mangle]
15900
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   202
pub extern "C" fn dispose_game_field(game_field: *mut GameField) {
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   203
    unsafe { drop(Box::from_raw(game_field)) };
128ace913837 Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff changeset
   204
}