Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "phasetida-core"
version = "0.1.17"
version = "0.1.18"
edition = "2024"

[lib]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub use states_initializing::clear_states;
pub use states_initializing::init_line_states;
pub use states_initializing::init_line_states_from_json;
pub use states_initializing::init_world_rect;
pub use states_initializing::recalculate_floor_position;

pub use states_input::clear_touch;
pub use states_input::set_touch_down;
Expand Down
21 changes: 20 additions & 1 deletion src/states_initializing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use std::{collections::HashSet, default::Default};
use crate::{
CHART_STATISTICS, FLATTEN_NOTE_INDEX, HIT_EFFECT_POOL, LINE_STATES, SOUND_POOL,
SPLASH_EFFECT_POOL, TOUCH_STATES, WORLD_RECT,
chart::{self, ChartRaw, JudgeLine, WithTimeRange},
chart::{self, ChartRaw, Event1, JudgeLine, WithTimeRange},
input::TouchInfo,
math::Rect,
states::{LineData, LineState, Metadata, NoteState, get_seconds_per_tick},
states_effect::{HitEffect, SoundEffect, SplashEffect},
states_lines::get_line_y_direct,
states_statistics::{self, ChartStatistics},
};

Expand Down Expand Up @@ -94,6 +95,24 @@ pub fn init_line_states(chart_raw: chart::ChartRaw) -> Metadata {
metadata
}

/// Ignore present value, then re calculate [`floor_position`]
pub fn recalculate_floor_position() {
fn process_half(states: &mut [NoteState], bpm: f64, speed_event: &[Event1]) {
for note_state in states {
let note = &mut note_state.note;
let line_y = get_line_y_direct(note.time.into(), bpm, speed_event);
note.floor_position = line_y;
}
}
LINE_STATES.with_borrow_mut(|state| {
for line in state {
let bpm = line.bpm;
process_half(&mut line.notes_below_state, bpm, &line.speed_events);
process_half(&mut line.notes_above_state, bpm, &line.speed_events);
}
});
}

/// Initialize world rect from width and height
pub fn init_world_rect(width: f64, height: f64) {
WORLD_RECT.with_borrow_mut(|world_height| {
Expand Down
19 changes: 11 additions & 8 deletions src/states_lines.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
LINE_STATES,
chart::{self, TimeState, WithTimeRange, WithValue},
chart::{self, Event1, TimeState, WithTimeRange, WithValue},
math::{self, Rect},
states::LineData,
};
Expand All @@ -14,22 +14,25 @@ pub fn tick_lines(time_in_second: f64, world_rect: &Rect) {
}

fn get_line_y(tick_time: f64, line: &LineData) -> f64 {
get_line_y_direct(tick_time, line.bpm, &line.speed_events)
}

pub fn get_line_y_direct(tick_time: f64, bpm: f64, speed_events: &[Event1]) -> f64 {
let mut t = 0.0;
let seconds_per_tick = 60.0 / line.bpm / 32.0;
let speed_events = &line.speed_events;
let seconds_per_tick = 60.0 / bpm / 32.0;
for event in speed_events {
if event.end_time > tick_time && event.start_time > tick_time {
break;
}
if event.start_time < tick_time && tick_time < event.end_time {
if event.start_time <= tick_time && tick_time <= event.end_time {
let duration = event.end_time - event.start_time;
let percent = (tick_time - event.start_time) / duration;
t = (duration * percent).mul_add(event.value, t);
break;
}
if event.end_time < tick_time {
if event.end_time <= tick_time {
t = (event.end_time - event.start_time).mul_add(event.value, t);
}
if event.end_time > tick_time && event.start_time > tick_time {
break;
}
}
t * seconds_per_tick
}
Expand Down
Loading