rust/hedgewars-engine/src/main.rs
author sheepluva
Thu, 24 Jun 2021 00:09:30 +0200
changeset 15827 61da40b657fa
parent 15824 d5c37e78ab83
child 15828 36816af30583
permissions -rw-r--r--
hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     1
extern crate libloading;
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     2
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     3
use libloading::{Library, Symbol};
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     4
use std::ops::Deref;
15827
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
     5
use std::env;
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
     6
use getopts::Options;
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
     7
use std::io::prelude::*;
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
     8
use std::io::{self, Read};
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
     9
use std::net::{Shutdown, TcpStream};
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    10
use image::{GrayImage, imageops};
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    11
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    12
struct EngineInstance {}
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    13
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    14
struct Engine<'a> {
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    15
    protocol_version: Symbol<'a, unsafe fn() -> u32>,
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    16
    start_engine: Symbol<'a, unsafe fn() -> *mut EngineInstance>,
15827
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    17
    generate_preview: Symbol<'a, unsafe fn(engine_state: &mut EngineInstance, preview: &mut PreviewInfo)>,
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    18
    dispose_preview: Symbol<'a, unsafe fn(engine_state: &mut EngineInstance, preview: &mut PreviewInfo)>,
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    19
    cleanup: Symbol<'a, unsafe fn(engine_state: *mut EngineInstance)>,
15827
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    20
    send_ipc: Symbol<'a, unsafe fn(engine_state: &mut EngineInstance, buf: *const u8, size: usize)>,
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    21
    read_ipc: Symbol<'a, unsafe fn(engine_state: &mut EngineInstance, buf: *mut u8, size: usize) -> usize>,
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    22
}
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    23
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    24
#[repr(C)]
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    25
#[derive(Copy, Clone)]
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    26
struct PreviewInfo {
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    27
  width: u32,
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    28
  height: u32,
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    29
  hedgehogs_number: u8,
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    30
  land: *const u8,
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    31
}
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    32
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    33
fn main() {
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    34
    let hwlib = Library::new("libhedgewars_engine.so").unwrap();
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    35
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    36
    unsafe {
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    37
        let engine = Engine {
15824
d5c37e78ab83 hedgewars-engine (rust): fix "protocol_version" -> "hedgewars_engine_protocol_version"
sheepluva
parents: 14187
diff changeset
    38
            protocol_version: hwlib.get(b"hedgewars_engine_protocol_version").unwrap(),
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    39
            start_engine: hwlib.get(b"start_engine").unwrap(),
15827
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    40
            generate_preview: hwlib.get(b"generate_preview").unwrap(),
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    41
            dispose_preview: hwlib.get(b"dispose_preview").unwrap(),
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    42
            cleanup: hwlib.get(b"cleanup").unwrap(),
15827
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    43
            send_ipc: hwlib.get(b"send_ipc").unwrap(),
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    44
            read_ipc: hwlib.get(b"read_ipc").unwrap(),
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    45
        };
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    46
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    47
        println!("Hedgewars engine, protocol version {}", engine.protocol_version.deref()());
15827
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    48
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    49
        let args: Vec<String> = env::args().collect();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    50
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    51
        let mut opts = getopts::Options::new();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    52
        opts.optflag("", "internal", "[internal]");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    53
        opts.optflag("", "landpreview", "[internal]");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    54
        opts.optflag("", "recorder", "[internal]");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    55
        opts.optopt("", "port", "[internal]", "PORT");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    56
        opts.optopt("", "user-prefix", "Set the path to the custom data folder to find game content", "PATH_TO_FOLDER");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    57
        opts.optopt("", "prefix", "Set the path to the system game data folder", "PATH_TO_FOLDER");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    58
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    59
        let matches = match opts.parse(&args[1..]) {
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    60
            Ok(m) => { m }
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    61
            Err(f) => { panic!(f.to_string()) }
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    62
        };
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    63
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    64
        let engine_state = &mut *engine.start_engine.deref()();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    65
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    66
        let port: String = matches.opt_str("port").unwrap();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    67
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    68
        println!("PORT: {}", port);
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    69
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    70
        if matches.opt_present("landpreview") {
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    71
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    72
            let mut stream = TcpStream::connect(format!("127.0.0.1:{}", port)).expect("Failed to connect to IPC port. Feelsbadman.");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    73
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    74
            //stream.write(b"\x01C").unwrap(); // config
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    75
            //stream.write(b"\x01?").unwrap(); // ping
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    76
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    77
            let mut buf = [0;1];
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    78
            loop {
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    79
                let bytes_read = stream.read(&mut buf).unwrap();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    80
                if bytes_read == 0 {
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    81
                    break;
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    82
                }
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    83
                engine.send_ipc.deref()(engine_state, &buf[0], buf.len());
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    84
                // this looks like length 1 is being announced
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    85
                if buf[0] == 1 {
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    86
                    let bytes_read = stream.read(&mut buf).unwrap();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    87
                    if bytes_read == 0 {
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    88
                        break;
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    89
                    }
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    90
                    if buf[0] == 33 {
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    91
                        println!("Ping? Pong!");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    92
                        break;
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    93
                    }
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    94
                }
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    95
            };
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    96
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    97
            let preview_info = &mut PreviewInfo {
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    98
                width: 0,
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
    99
                height: 0,
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   100
                hedgehogs_number: 0,
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   101
                land: std::ptr::null(),
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   102
            };
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   103
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   104
            engine.generate_preview.deref()(engine_state, preview_info);
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   105
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   106
            println!("Sending preview...");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   107
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   108
            //println!("Preview: w = {}, h = {}, n = {}", preview_info.width, preview_info.height, preview_info.hedgehogs_number);
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   109
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   110
            let land_size: usize = (preview_info.width * preview_info.height) as usize;
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   111
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   112
            let land_array: &[u8] = std::slice::from_raw_parts(preview_info.land, land_size);
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   113
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   114
            let raw_image = GrayImage::from_raw(preview_info.width, preview_info.height, land_array.to_vec()).unwrap();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   115
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   116
            const PREVIEW_WIDTH: u32 = 256;
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   117
            const PREVIEW_HEIGHT: u32 = 128;
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   118
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   119
            let preview_image = imageops::resize(&raw_image, PREVIEW_WIDTH, PREVIEW_HEIGHT, imageops::FilterType::Triangle);
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   120
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   121
            stream.write(preview_image.as_raw()).unwrap();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   122
            stream.flush().unwrap();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   123
            stream.write(&[preview_info.hedgehogs_number]).unwrap();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   124
            stream.flush().unwrap();
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   125
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   126
            println!("Preview sent, disconnect");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   127
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   128
            stream.shutdown(Shutdown::Both).expect("IPC shutdown call failed");
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   129
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   130
            engine.dispose_preview.deref()(engine_state, preview_info);
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   131
        }
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   132
61da40b657fa hedgewars-engine (rust): ugly+slow impl for returning lib's previews (QTfrontend "compatible")
sheepluva
parents: 15824
diff changeset
   133
        engine.cleanup.deref()(engine_state);
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
   134
    }
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
   135
}