summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-12-17 01:02:01 +0100
committerNao Pross <naopross@thearcway.org>2018-12-17 01:02:01 +0100
commit122644bb1e07be36bc25871f2953b9090777f252 (patch)
tree46c76d0117005b12416e107de0ffc5dc5db12d6d /src
parentCreate basic structure (diff)
downloadSubconscious-rs-122644bb1e07be36bc25871f2953b9090777f252.tar.gz
Subconscious-rs-122644bb1e07be36bc25871f2953b9090777f252.zip
Add window in a graphics thread
Diffstat (limited to 'src')
-rw-r--r--src/graphics.rs61
-rw-r--r--src/main.rs7
2 files changed, 66 insertions, 2 deletions
diff --git a/src/graphics.rs b/src/graphics.rs
index c3917af..ca98946 100644
--- a/src/graphics.rs
+++ b/src/graphics.rs
@@ -1,5 +1,64 @@
+extern crate sfml;
+
+
+use sfml::window::{
+ ContextSettings,
+ Event,
+ Style,
+};
+
+use sfml::graphics::{
+ RenderWindow,
+ RenderTarget,
+ Color,
+};
+
+
+struct State {
+ running: bool
+}
pub fn start() {
-
+ let default_window_size = (1280, 720);
+ let default_framerate = 80;
+
+ let mut state = State {
+ running: true
+ };
+
+ let context_settings = ContextSettings {
+ antialiasing_level: 0,
+ ..Default::default()
+ };
+
+ let mut window = RenderWindow::new(
+ default_window_size,
+ "Subconscious",
+ Style::CLOSE,
+ &context_settings
+ );
+
+ window.set_framerate_limit(default_framerate);
+ window.set_vertical_sync_enabled(true);
+
+
+ while state.running {
+ render(&mut window);
+ update(&mut window, &mut state);
+ }
+}
+
+fn render(window: &mut RenderWindow) {
+ window.clear(&Color::BLACK);
+ window.display();
+}
+
+fn update(window: &mut RenderWindow, state: &mut State) {
+ while let Some(ev) = window.poll_event() {
+ match ev {
+ Event::Closed => state.running = false,
+ _ => {},
+ }
+ }
} \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 8de52c0..2679ac4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,5 +4,10 @@ mod graphics;
fn main() {
game::start();
- graphics::start();
+
+ let graphics_thread = std::thread::spawn(move || {
+ graphics::start();
+ });
+
+ graphics_thread.join().unwrap();
}