rust/hwrunner/src/main.rs
author Wuzzy <Wuzzy2@mail.ru>
Mon, 14 Jan 2019 21:19:57 +0100
changeset 14611 c5f18710a184
parent 14355 7ae81969330f
child 14723 29dbe9ce8b7d
permissions -rw-r--r--
Remove "loser" messages in challenges The point of challenges is not to "win", but to reach a highscore, so we need not to rub failure into the player's face.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14208
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     1
use glutin::{
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     2
    dpi::LogicalSize,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     3
    Event,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     4
    WindowEvent,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     5
    EventsLoop,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     6
    GlWindow,
14209
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
     7
    GlContext
14208
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     8
};
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
     9
14209
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    10
use gfx::{
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    11
    texture,
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    12
    format,
14355
alfadur
parents: 14314
diff changeset
    13
    Encoder,
alfadur
parents: 14314
diff changeset
    14
    Device
14209
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    15
};
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    16
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    17
use gfx_window_glutin::init_existing;
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    18
14314
b8871dd33ec4 add gfx setup ffi
alfadur
parents: 14209
diff changeset
    19
use hedgewars_engine::instance::EngineInstance;
14209
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    20
14208
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    21
fn init(event_loop: &EventsLoop, size: LogicalSize) -> GlWindow {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    22
    use glutin::{
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    23
        ContextBuilder,
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    24
        WindowBuilder
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    25
    };
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    26
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    27
    let window = WindowBuilder::new()
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    28
        .with_title("hwengine")
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    29
        .with_dimensions(size);
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    30
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    31
    let context = ContextBuilder::new();
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    32
    GlWindow::new(window, context, event_loop).unwrap()
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    33
}
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    34
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    35
fn main() {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    36
    let mut event_loop = EventsLoop::new();
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    37
    let window = init(&event_loop, LogicalSize::new(1024.0, 768.0));
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    38
14209
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    39
    let (mut device, mut factory, color_view, depth_view) =
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    40
        init_existing::<format::Rgba8, format::Depth>(&window);
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    41
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    42
    let mut encoder: Encoder<_, _> = factory.create_command_buffer().into();
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    43
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    44
    let engine = EngineInstance::new();
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    45
14208
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    46
    let mut is_running = true;
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    47
    while is_running {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    48
        event_loop.poll_events(|event| {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    49
            match event {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    50
                Event::WindowEvent { event, ..} => match event {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    51
                    WindowEvent::CloseRequested => {
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    52
                        is_running = false;
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    53
                    },
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    54
                    _ => ()
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    55
                },
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    56
                _ => ()
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    57
            }
14209
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    58
        });
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    59
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    60
        encoder.clear(&color_view, [0.5, 0.0, 0.0, 1.0]);
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    61
        engine.render(&mut encoder, &color_view);
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    62
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    63
        encoder.flush(&mut device);
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    64
3b83ec44e10b pass hwrunner gl context into engine
alfadur
parents: 14208
diff changeset
    65
        window.swap_buffers().unwrap();
14355
alfadur
parents: 14314
diff changeset
    66
        device.cleanup();
14208
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    67
    }
675aa499a70e add standalone engine runner
alfadur
parents:
diff changeset
    68
}