From b1b505010589381fa5ab7293462dcd6205a7e938 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 8 Jan 2021 01:52:06 -0600 Subject: [PATCH] why is my slider rendering wrong --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/game.rs | 13 +++++++++++-- src/slider_render.rs | 20 ++++++++++---------- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a39425..114601c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1132,7 +1132,7 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "libosu" version = "0.0.12" -source = "git+https://github.com/iptq/libosu?rev=7acc09af59b789f78c21c259d4e1e246e9cf0b08#7acc09af59b789f78c21c259d4e1e246e9cf0b08" +source = "git+https://github.com/iptq/libosu?rev=5a8501aec0f4f2232507f80a65b8b31be8756414#5a8501aec0f4f2232507f80a65b8b31be8756414" dependencies = [ "anyhow", "bitflags", diff --git a/Cargo.toml b/Cargo.toml index d9ab3fc..edf9bf5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,4 +19,4 @@ num = "0.3.1" [dependencies.libosu] git = "https://github.com/iptq/libosu" -rev = "7acc09af59b789f78c21c259d4e1e246e9cf0b08" +rev = "5a8501aec0f4f2232507f80a65b8b31be8756414" diff --git a/src/game.rs b/src/game.rs index 59860d8..b8a4d46 100644 --- a/src/game.rs +++ b/src/game.rs @@ -6,7 +6,8 @@ use anyhow::Result; use ggez::{ event::{EventHandler, KeyCode, KeyMods}, graphics::{ - self, DrawMode, DrawParam, FillOptions, FilterMode, Mesh, Rect, StrokeOptions, Text, WHITE, + self, Color, DrawMode, DrawParam, FillOptions, FilterMode, Mesh, Rect, StrokeOptions, Text, + WHITE, }, Context, GameError, GameResult, }; @@ -68,6 +69,14 @@ impl Game { graphics::clear(ctx, [0.0, 0.0, 0.0, 1.0].into()); + let playfield = Mesh::new_rectangle( + ctx, + DrawMode::Stroke(StrokeOptions::default()), + EDITOR_SCREEN, + Color::new(1.0, 1.0, 1.0, 0.5), + )?; + graphics::draw(ctx, &playfield, DrawParam::default())?; + let time = self.song.as_ref().unwrap().position()?; let text = Text::new(format!("time: {}", time).as_ref()); graphics::queue_text(ctx, &text, [0.0, 0.0], Some(WHITE)); @@ -84,7 +93,7 @@ impl Game { let osupx_scale_x = EDITOR_SCREEN.w / 512.0; let osupx_scale_y = EDITOR_SCREEN.h / 384.0; - let cs_osupx = 54.4 - 4.48 * self.beatmap.difficulty.circle_size; + let cs_osupx = self.beatmap.difficulty.circle_size_osupx(); let cs_real = cs_osupx * osupx_scale_x; for ho in visible_hitobjects.iter() { diff --git a/src/slider_render.rs b/src/slider_render.rs index 9160c98..3433650 100644 --- a/src/slider_render.rs +++ b/src/slider_render.rs @@ -1,13 +1,8 @@ -use std::collections::{HashMap, VecDeque}; -use std::mem; -use std::sync::Arc; +use std::collections::VecDeque; use anyhow::Result; use ggez::{ - conf::NumSamples, - graphics::{ - self, Canvas, Color, DrawMode, DrawParam, LineCap, LineJoin, Mesh, Rect, StrokeOptions, - }, + graphics::{self, DrawMode, DrawParam, LineCap, LineJoin, Mesh, Rect, StrokeOptions}, nalgebra::Point2, Context, }; @@ -32,7 +27,7 @@ pub fn render_slider( let osupx_scale_x = rect.w as f64 / 512.0; let osupx_scale_y = rect.h as f64 / 384.0; - let cs_osupx = 54.4 - 4.48 * beatmap.difficulty.circle_size as f64; + let cs_osupx = beatmap.difficulty.circle_size_osupx() as f64; let cs_real = cs_osupx * osupx_scale_x; let (mut boundx, mut boundy, mut boundw, mut boundh) = (0.0f64, 0.0f64, 0.0f64, 0.0f64); @@ -75,9 +70,14 @@ fn get_spline( let points = control_points .iter() .map(|p| Point(p.0 as f64, p.1 as f64)) - .collect(); + .collect::>(); match kind { - SliderSplineKind::Linear => points, + SliderSplineKind::Linear => { + let start = points[0]; + let unit = (points[1] - points[0]).norm(); + let end = points[0] + unit * pixel_length; + vec![start, end] + } SliderSplineKind::Perfect => { let (p1, p2, p3) = (points[0], points[1], points[2]); let (center, radius) = Math::circumcircle(p1, p2, p3);