Skip to content

Commit

Permalink
rename api
Browse files Browse the repository at this point in the history
  • Loading branch information
boralg committed Jul 14, 2024
1 parent 1c27ddb commit 4431e47
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/src/cube_camera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct Uniforms {
}

impl AppState for CubeState {
fn init(display: &mut Display) -> CubeState {
fn new(display: &mut Display) -> CubeState {
let device = &display.device;

let shader = create_shader(device, include_str!("assets/shader.wgsl"));
Expand Down Expand Up @@ -130,7 +130,7 @@ impl AppState for CubeState {
}
}

fn render(&mut self, display: &mut Display) {
fn draw(&mut self, display: &mut Display) {
let clear_color = Color {
r: 252.0 / 255.0,
g: 241.0 / 255.0,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/hello_triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct TriangleState {
}

impl AppState for TriangleState {
fn init(display: &mut Display) -> TriangleState {
fn new(display: &mut Display) -> TriangleState {
let device = &display.device;

let shader = create_shader(device, include_str!("assets/shader.wgsl"));
Expand All @@ -35,7 +35,7 @@ impl AppState for TriangleState {
TriangleState { render_pipeline }
}

fn render(&mut self, display: &mut Display) {
fn draw(&mut self, display: &mut Display) {
let clear_color = Color {
r: 100.0 / 255.0,
g: 149.0 / 255.0,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/hello_window/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ fn main() {}
struct EmptyState {}

impl AppState for EmptyState {
fn init<'a>(_display: &mut Display) -> EmptyState {
fn new<'a>(_display: &mut Display) -> EmptyState {
EmptyState {}
}

fn render<'a>(&mut self, display: &mut Display) {
fn draw<'a>(&mut self, display: &mut Display) {
let output = display.surface.get_current_texture().unwrap();
let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default());

Expand Down
4 changes: 2 additions & 2 deletions examples/src/mandelbrot/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct Uniforms {
}

impl AppState for MandelbrotState {
fn init(display: &mut Display) -> MandelbrotState {
fn new(display: &mut Display) -> MandelbrotState {
let device = &display.device;
let aspect_ratio = display.config.width as f32 / display.config.height as f32;

Expand Down Expand Up @@ -163,7 +163,7 @@ impl AppState for MandelbrotState {
}


fn render(&mut self, display: &mut Display) {
fn draw(&mut self, display: &mut Display) {
let mut dt = now_secs() - self.last_timestep;
#[cfg(target_arch = "wasm32")] {
dt *= -1000f32;
Expand Down
8 changes: 4 additions & 4 deletions sursface/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ pub struct App<'a, State: AppState> {
}

pub trait AppState {
fn init(display: &mut Display) -> Self;
fn new(display: &mut Display) -> Self;
fn create_display(window: Window) -> Display<'static> {
Display::from_window(window)
}

fn render(&mut self, display: &mut Display);
fn draw(&mut self, display: &mut Display);

fn event(&mut self, display: &mut Display, event: WindowEvent) {}
fn device_event(&mut self, display: &mut Display, event: DeviceEvent) {}
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'a, State: AppState> ApplicationHandler for App<'a, State> {
self.display = Some(Arc::new(Mutex::new(Display::from_window(Display::create_window_from_canvas(event_loop, self.canvas.clone())))));
}

let new_state = State::init(&mut self.display.clone().unwrap().lock().unwrap());
let new_state = State::new(&mut self.display.clone().unwrap().lock().unwrap());
self.state = Some(Arc::new(Mutex::new(new_state)));
}

Expand Down Expand Up @@ -133,7 +133,7 @@ impl<'a, State: AppState> ApplicationHandler for App<'a, State> {
display.resize(physical_size);
}
WindowEvent::RedrawRequested => {
state.render(&mut display);
state.draw(&mut display);
display.window.as_ref().request_redraw();
}
_ => ()
Expand Down

0 comments on commit 4431e47

Please sign in to comment.