~zanneth/bedside

24bbe17dc62f2cd7b93d3617bdbefd743b1523a4 — Charles Magahern 11 months ago 4f6bd34
Run with SwapInterval::Immediate so that input feels responsive
4 files changed, 18 insertions(+), 11 deletions(-)

M src/components/path.rs
M src/gradient.rs
M src/main.rs
M src/render_context.rs
M src/components/path.rs => src/components/path.rs +2 -2
@@ 6,9 6,9 @@ use crate::render_context::RenderContext;
use crate::scene::Scene;
use crate::vertex_array::*;

use bytemuck::{bytes_of, cast_slice};
use bytemuck::cast_slice;
use std::mem::size_of;
use ultraviolet::{Vec2, Vec4};
use ultraviolet::Vec2;

#[derive(Copy, Clone, Debug, PartialEq)]
pub enum DrawingMode {

M src/gradient.rs => src/gradient.rs +2 -0
@@ 1,3 1,5 @@
#![allow(dead_code)]

use ultraviolet::Vec2;
use crate::color::*;


M src/main.rs => src/main.rs +12 -8
@@ 19,6 19,7 @@ mod util;
mod vertex_array;
mod window;


use crate::{
    components::{
        camera::CameraComponent,


@@ 38,10 39,11 @@ use crate::{
    window::Window,
};

use ultraviolet::{Rotor3, Vec3};
use crate::components::path::PathBuilder;
use crate::input_context::{Event, TouchPhase};
use crate::texture::Texture;
use std::time::SystemTime;
use ultraviolet::{Rotor3, Vec3};

const RESOLUTION: (u32, u32) = (1280, 720);



@@ 112,14 114,16 @@ fn main() {
    square.material = Some(MaterialComponent::with_color(&Color::CYAN));
    scene.add_entity(square);

    let start = SystemTime::now();
    app.engine.register_system(move |scene, _, _| {
        unsafe {
            static mut THETA: f32 = 0.0;
            let square = scene.find_entity_mut(square_id).unwrap();
            square.transform.as_mut().unwrap().rotation = Rotor3::from_rotation_xy(THETA);

            THETA += 0.1;
        }
        const R_PER_SEC: f32 = 2.0 * std::f32::consts::PI;
        
        let now = SystemTime::now();
        let t = now.duration_since(start).unwrap();
        let theta = t.as_secs_f32() * R_PER_SEC;
        
        let square = scene.find_entity_mut(square_id).unwrap();
        square.transform.as_mut().unwrap().rotation = Rotor3::from_rotation_xy(theta);
    });

    // run the scene

M src/render_context.rs => src/render_context.rs +2 -1
@@ 9,6 9,7 @@ use crate::sdl::SDLContext;
use crate::shader_program::*;

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[allow(dead_code)]
pub enum FontFamily {
    RobotoMono,
    DINPro,


@@ 65,7 66,7 @@ impl<'a> RenderContext<'a> {
        let img_context = sdl2::image::init(InitFlag::PNG)?;

        // set swap interval on SDL video context
        sdl_ctx.video.gl_set_swap_interval(SwapInterval::VSync)?;
        sdl_ctx.video.gl_set_swap_interval(SwapInterval::Immediate)?;

        // initialize shader program
        let shader_program = ShaderProgramBuilder::new()