rust/lib-hwengine-future/src/lib.rs
branchtransitional_engine
changeset 16039 a236360669cc
parent 16035 0caa3dfb3ba2
child 16040 6c5b3c576fc6
equal deleted inserted replaced
16036:7b8d96fc8799 16039:a236360669cc
       
     1 mod ai;
       
     2 
     1 use integral_geometry::{Point, Size};
     3 use integral_geometry::{Point, Size};
     2 
     4 
     3 use landgen::{
     5 use landgen::{
     4     outline_template_based::outline_template::OutlineTemplate,
     6     outline_template_based::outline_template::OutlineTemplate,
     5     maze::MazeTemplate,
     7     maze::MazeTemplate,
     8 };
    10 };
     9 use lfprng::LaggedFibonacciPRNG;
    11 use lfprng::LaggedFibonacciPRNG;
    10 use mapgen::{theme::Theme, MapGenerator};
    12 use mapgen::{theme::Theme, MapGenerator};
    11 use std::fs;
    13 use std::fs;
    12 use std::{ffi::CStr, path::Path};
    14 use std::{ffi::CStr, path::Path};
       
    15 use ai::*;
    13 
    16 
    14 #[repr(C)]
    17 #[repr(C)]
    15 pub struct GameField {
    18 pub struct GameField {
    16     collision: land2d::Land2D<u16>,
    19     collision: land2d::Land2D<u16>,
    17     pixels: land2d::Land2D<u32>,
    20     pixels: land2d::Land2D<u32>,
    41         collision: land2d::Land2D::new(&Size::new(width as usize, height as usize), 0),
    44         collision: land2d::Land2D::new(&Size::new(width as usize, height as usize), 0),
    42         pixels: land2d::Land2D::new(&Size::new(width as usize, height as usize), 0),
    45         pixels: land2d::Land2D::new(&Size::new(width as usize, height as usize), 0),
    43         landgen_parameters: None,
    46         landgen_parameters: None,
    44     });
    47     });
    45 
    48 
    46     Box::leak(game_field)
    49     Box::into_raw(game_field)
    47 }
    50 }
    48 
    51 
    49 #[no_mangle]
    52 #[no_mangle]
    50 pub extern "C" fn generate_outline_templated_game_field(
    53 pub extern "C" fn generate_outline_templated_game_field(
    51     feature_size: u32,
    54     feature_size: u32,
    81         collision,
    84         collision,
    82         pixels: land2d::Land2D::new(&size, 0),
    85         pixels: land2d::Land2D::new(&size, 0),
    83         landgen_parameters: Some(params),
    86         landgen_parameters: Some(params),
    84     });
    87     });
    85 
    88 
    86     Box::leak(game_field)
    89     Box::into_raw(game_field)
    87 }
    90 }
    88 
    91 
    89 #[no_mangle]
    92 #[no_mangle]
    90 pub extern "C" fn generate_wfc_templated_game_field(
    93 pub extern "C" fn generate_wfc_templated_game_field(
    91     feature_size: u32,
    94     feature_size: u32,
   121         collision,
   124         collision,
   122         pixels: land2d::Land2D::new(&size, 0),
   125         pixels: land2d::Land2D::new(&size, 0),
   123         landgen_parameters: Some(params),
   126         landgen_parameters: Some(params),
   124     });
   127     });
   125 
   128 
   126     Box::leak(game_field)
   129     Box::into_raw(game_field)
   127 }
   130 }
   128 
   131 
   129 #[no_mangle]
   132 #[no_mangle]
   130 pub extern "C" fn generate_maze_game_field(
   133 pub extern "C" fn generate_maze_game_field(
   131     feature_size: u32,
   134     feature_size: u32,
   164         collision,
   167         collision,
   165         pixels: land2d::Land2D::new(&size, 0),
   168         pixels: land2d::Land2D::new(&size, 0),
   166         landgen_parameters: Some(params),
   169         landgen_parameters: Some(params),
   167     });
   170     });
   168 
   171 
   169     Box::leak(game_field)
   172     Box::into_raw(game_field)
   170 }
   173 }
   171 
   174 
   172 #[no_mangle]
   175 #[no_mangle]
   173 pub extern "C" fn apply_theme(
   176 pub extern "C" fn apply_theme(
   174     game_field: &mut GameField,
   177     game_field: &mut GameField,
   242 
   245 
   243 #[no_mangle]
   246 #[no_mangle]
   244 pub extern "C" fn dispose_game_field(game_field: *mut GameField) {
   247 pub extern "C" fn dispose_game_field(game_field: *mut GameField) {
   245     unsafe { drop(Box::from_raw(game_field)) };
   248     unsafe { drop(Box::from_raw(game_field)) };
   246 }
   249 }
       
   250 
       
   251 #[no_mangle]
       
   252 pub extern "C" fn create_ai(game_field: &GameField) -> *mut AI {
       
   253     Box::into_raw(Box::new(AI::new(game_field)))
       
   254 }
       
   255 
       
   256 #[no_mangle]
       
   257 pub extern "C" fn ai_clear_team(ai: &mut AI) {
       
   258     *ai.get_team_mut() = vec![];
       
   259 }
       
   260 
       
   261 #[no_mangle]
       
   262 pub extern "C" fn ai_add_team_hedgehog(ai: &mut AI, x: f32, y: f32) {
       
   263     ai.get_team_mut().push(Hedgehog{x, y});
       
   264 }
       
   265 
       
   266 #[no_mangle]
       
   267 pub extern "C" fn ai_think(ai: &AI) {
       
   268 
       
   269 }
       
   270 
       
   271 #[no_mangle]
       
   272 pub extern "C" fn dispose_ai(ai: *mut AI) {
       
   273     unsafe { drop(Box::from_raw(ai)) };
       
   274 }