summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-18 12:38:11 -0500
committerpommicket <pommicket@gmail.com>2022-12-18 12:38:11 -0500
commit73ee0bb21050b305dac5352e07c7cfe03947be66 (patch)
tree97f141816265d752f54c5534d6c85de2e592e8dc
parent53446631bf579c85786af1b4c8fcd54566c0d391 (diff)
remove windows cmd window (hopefully, needs testing)
-rw-r--r--README.md2
-rw-r--r--src/main.rs27
-rw-r--r--src/sdl.rs5
-rw-r--r--src/win.rs85
4 files changed, 113 insertions, 6 deletions
diff --git a/README.md b/README.md
index fbce169..b3e971b 100644
--- a/README.md
+++ b/README.md
@@ -14,12 +14,14 @@ you can also reduce `max-iterations` and increase `distance-threshold` if it's s
- R to create a new SDF - use this a lot! most SDFs are boring!
- Space to "unpause time" (start animating). On some SDFs this might not do much.
Press space again to pause time, and shift+space to rewind time.
+- [ and ] to go forwards and backwards in time
- 0 to reset location + time
- =/- (equals/minus) to expand/contract the surface (change the "level set" of the SDF you're looking at)
- Ctrl+C to copy SDF to clipboard, Ctrl+V to paste SDF from clipboard. On Linux
if you close the application the clipboard contents will be lost (thanks a lot X11).
- F to go fullscreen
- Escape to quit
+- You can use Shift to move faster and Ctrl to move slower.
## saving SDFs
diff --git a/src/main.rs b/src/main.rs
index eb3728a..b73e036 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,7 +1,6 @@
/*
@TODO:
- publish git repo
-- remove cmd window on windows
- exe & window icon
- options for:
- max framerate
@@ -17,7 +16,7 @@
- GenRandom integers (+ gen_random_scale_bias)
- record a video
- better SDL api: Context + Window<'a> impl !Send+!Sync
-
+- gallery view
-----
cool seeds:
commit ae29a61c9917da5ad9fbb7a24151bff506669ffb "cool stuff"
@@ -45,6 +44,7 @@ a263736466a167436f6d706f736583a1695472616e736c61746583a163463332fa3f4811e4a16346
// LICENSE: i'm not gonna sue you for "copyright infringement". go wild.
+#![windows_subsystem = "windows"]
extern crate nalgebra;
pub mod sdf;
@@ -476,6 +476,8 @@ impl State {
let mut dy = 0.0;
let mut dz = 0.0;
let mut dl = 0.0;
+ let mut dt = 0.0;
+
let window = &self.window;
use win::Key::*;
@@ -503,19 +505,32 @@ impl State {
if window.any_key_down(&[Minus]) {
dl -= 1.0;
}
+ if window.any_key_down(&[LeftBracket]) {
+ dt -= 1.0;
+ }
+ if window.any_key_down(&[RightBracket]) {
+ dt += 1.0;
+ }
let mut speed_multiplier = if window.is_shift_down() { 10.0 } else { 1.0 };
speed_multiplier *= if window.is_ctrl_down() { 0.1 } else { 1.0 };
+ speed_multiplier *= frame_dt;
+
+ if dt != 0.0 {
+ let dt = dt * speed_multiplier;
+ self.view.pause();
+ self.view.time += f64::from(dt);
+ }
let motion = Vec3::new(dx, dy, dz);
if let Some(motion) = motion.try_normalize(0.001) {
- let move_speed = 4.0 * speed_multiplier;
- let motion = motion * frame_dt * move_speed;
+ let move_amount = 4.0 * speed_multiplier;
+ let motion = motion * move_amount;
let motion = self.view.rotation() * motion;
self.view.pos += motion;
}
- let level_set_speed = 1.0 * speed_multiplier;
- self.view.level_set += dl * frame_dt * level_set_speed;
+ let level_set_amount = 1.0 * speed_multiplier;
+ self.view.level_set += dl * level_set_amount;
}
let window = &mut self.window;
diff --git a/src/sdl.rs b/src/sdl.rs
index 056e8d8..b354c59 100644
--- a/src/sdl.rs
+++ b/src/sdl.rs
@@ -671,6 +671,7 @@ impl SDL_AudioSpec {
#[link(name = "SDL2", kind = "dylib")]
extern "C" {
fn SDL_Init(flags: u32) -> c_int;
+ fn SDL_SetMainReady();
fn SDL_CreateWindow(
title: *const c_char,
x: c_int,
@@ -979,6 +980,10 @@ unsafe fn get_err() -> String {
String::from_utf8_lossy(cstr.to_bytes()).to_string()
}
+pub unsafe fn set_main_ready() {
+ SDL_SetMainReady();
+}
+
pub unsafe fn create_window(
title: &str,
width: i32,
diff --git a/src/win.rs b/src/win.rs
index 146ba54..5a30dc5 100644
--- a/src/win.rs
+++ b/src/win.rs
@@ -76,10 +76,24 @@ pub enum Key {
NumPad7,
NumPad8,
NumPad9,
+ NumPadPeriod,
+ NumPadPlus,
+ NumPadMinus,
+ NumPadDivide,
+ NumPadMultiply,
+ NumPadEnter,
+ NumLock,
Up,
Left,
Right,
Down,
+ PrintScreen,
+ ScrollLock,
+ Pause,
+ Home,
+ End,
+ Insert,
+ Delete,
PageUp,
PageDown,
Space,
@@ -91,6 +105,20 @@ pub enum Key {
RCtrl,
LAlt,
RAlt,
+ LGui,
+ RGui,
+ LeftBracket,
+ RightBracket,
+ Backslash,
+ Semicolon,
+ Quote,
+ Comma,
+ Period,
+ Slash,
+ Backtick,
+ Backspace,
+ Tab,
+ CapsLock,
F1,
F2,
F3,
@@ -153,6 +181,13 @@ impl Key {
LEFT => Key::Left,
RIGHT => Key::Right,
DOWN => Key::Down,
+ PRINTSCREEN => Key::PrintScreen,
+ SCROLLLOCK => Key::ScrollLock,
+ PAUSE => Key::Pause,
+ HOME => Key::Home,
+ END => Key::End,
+ INSERT => Key::Insert,
+ DELETE => Key::Delete,
ESCAPE => Key::Escape,
PAGEUP => Key::PageUp,
PAGEDOWN => Key::PageDown,
@@ -178,12 +213,33 @@ impl Key {
KP_7 => Key::NumPad7,
KP_8 => Key::NumPad8,
KP_9 => Key::NumPad9,
+ KP_PERIOD => Key::NumPadPeriod,
+ KP_PLUS => Key::NumPadPlus,
+ KP_MINUS => Key::NumPadMinus,
+ KP_DIVIDE => Key::NumPadDivide,
+ KP_MULTIPLY => Key::NumPadMultiply,
+ KP_ENTER => Key::NumPadEnter,
+ NUMLOCKCLEAR => Key::NumLock,
LSHIFT => Key::LShift,
RSHIFT => Key::RShift,
LCTRL => Key::LCtrl,
RCTRL => Key::RCtrl,
LALT => Key::LAlt,
RALT => Key::RAlt,
+ LGUI => Key::LGui,
+ RGUI => Key::RGui,
+ LEFTBRACKET => Key::LeftBracket,
+ RIGHTBRACKET => Key::RightBracket,
+ BACKSLASH => Key::Backslash,
+ SEMICOLON => Key::Semicolon,
+ APOSTROPHE => Key::Quote,
+ COMMA => Key::Comma,
+ PERIOD => Key::Period,
+ SLASH => Key::Slash,
+ GRAVE => Key::Backtick,
+ BACKSPACE => Key::Backspace,
+ TAB => Key::Tab,
+ CAPSLOCK => Key::CapsLock,
_ => return None,
})
}
@@ -231,6 +287,16 @@ impl Key {
Key::N9 => N9,
Key::Minus => MINUS,
Key::Equals => EQUALS,
+ Key::LeftBracket => LEFTBRACKET,
+ Key::RightBracket => RIGHTBRACKET,
+ Key::Backslash => BACKSLASH,
+ Key::Semicolon => SEMICOLON,
+ Key::Comma => COMMA,
+ Key::Period => PERIOD,
+ Key::Slash => SLASH,
+ Key::Quote => APOSTROPHE,
+ Key::Backtick => GRAVE,
+ Key::Backspace => BACKSPACE,
Key::Up => UP,
Key::Left => LEFT,
Key::Right => RIGHT,
@@ -238,6 +304,8 @@ impl Key {
Key::Escape => ESCAPE,
Key::PageUp => PAGEUP,
Key::PageDown => PAGEDOWN,
+ Key::Tab => TAB,
+ Key::CapsLock => CAPSLOCK,
Key::F1 => F1,
Key::F2 => F2,
Key::F3 => F3,
@@ -260,12 +328,28 @@ impl Key {
Key::NumPad7 => KP_7,
Key::NumPad8 => KP_8,
Key::NumPad9 => KP_9,
+ Key::NumPadPeriod => KP_PERIOD,
+ Key::NumPadPlus => KP_PLUS,
+ Key::NumPadMinus => KP_MINUS,
+ Key::NumPadMultiply => KP_MULTIPLY,
+ Key::NumPadDivide => KP_DIVIDE,
+ Key::NumPadEnter => KP_ENTER,
+ Key::NumLock => NUMLOCKCLEAR,
+ Key::ScrollLock => SCROLLLOCK,
+ Key::PrintScreen => PRINTSCREEN,
+ Key::Pause => PAUSE,
+ Key::Home => HOME,
+ Key::End => END,
+ Key::Insert => INSERT,
+ Key::Delete => DELETE,
Key::LShift => LSHIFT,
Key::RShift => RSHIFT,
Key::LCtrl => LCTRL,
Key::RCtrl => RCTRL,
Key::LAlt => LALT,
Key::RAlt => RALT,
+ Key::LGui => LGUI,
+ Key::RGui => RGUI,
}
}
}
@@ -1034,6 +1118,7 @@ impl Window {
}
unsafe {
+ sdl::set_main_ready();
sdl::set_hint("SDL_NO_SIGNAL_HANDLERS", "1"); // don't replace Ctrl+C, TERM with quit event
sdl::init()?;
#[cfg(debug_assertions)]