Skip to content

Commit 780addc

Browse files
authored
Merge pull request #661 from IcedDog/rpe-rotateWithParent
feat: implement rotateWithFather property
2 parents 0b21e91 + 0a1487e commit 780addc

6 files changed

Lines changed: 30 additions & 11 deletions

File tree

prpr/src/bin.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ impl BinaryData for JudgeLine {
389389
0 => None,
390390
x => Some(x as usize - 1),
391391
};
392-
let show_below = r.read()?;
392+
let flags = r.read::<u8>()?;
393+
let show_below = flags & 1 != 0;
394+
let rot_with_parent = flags & 2 != 0;
393395
let cache = JudgeLineCache::new(&mut notes);
394396
let attach_ui = UIElement::from_u8(r.read()?);
395397
let ctrl_obj = RefCell::new(r.read()?);
@@ -402,6 +404,7 @@ impl BinaryData for JudgeLine {
402404
notes,
403405
color,
404406
parent,
407+
rot_with_parent,
405408
show_below,
406409

407410
attach_ui,
@@ -440,7 +443,7 @@ impl BinaryData for JudgeLine {
440443
None => 0,
441444
Some(index) => index as u64 + 1,
442445
})?;
443-
w.write_val(self.show_below)?;
446+
w.write_val(self.show_below as u8 + self.rot_with_parent as u8 * 2)?;
444447
w.write_val(self.attach_ui.map_or(0, |it| it as u8))?;
445448
w.write(self.ctrl_obj.borrow().deref())?;
446449
w.write(&self.incline)?;

prpr/src/core/chart.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ impl Chart {
129129
}
130130
// TODO optimize
131131
let trs = self.lines.iter().map(|it| it.now_transform(res, &self.lines)).collect::<Vec<_>>();
132-
for (line, tr) in self.lines.iter_mut().zip(trs) {
133-
line.update(res, tr);
132+
let rotations = self.lines.iter().map(|it| it.fetch_rot(&self.lines)).collect::<Vec<_>>();
133+
for ((line, tr), rot) in self.lines.iter_mut().zip(trs).zip(rotations) {
134+
line.update(res, tr, rot);
134135
}
135136
for effect in &mut self.extra.effects {
136137
effect.update(res);

prpr/src/core/line.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ pub struct JudgeLine {
146146
pub notes: Vec<Note>,
147147
pub color: Anim<Color>,
148148
pub parent: Option<usize>,
149+
pub rot_with_parent: bool,
149150
pub z_index: i32,
150151
/// Whether to show notes below the line, here below is defined in the time axis, which means the note should already be judged
151152
///
@@ -157,15 +158,14 @@ pub struct JudgeLine {
157158
}
158159

159160
impl JudgeLine {
160-
pub fn update(&mut self, res: &mut Resource, tr: Matrix) {
161+
pub fn update(&mut self, res: &mut Resource, tr: Matrix, parent_rot: f32) {
161162
// self.object.set_time(res.time); // this is done by chart, chart has to calculate transform for us
162-
let rot = self.object.rotation.now();
163163
self.height.set_time(res.time);
164164
let line_height = self.height.now();
165165
let mut ctrl_obj = self.ctrl_obj.borrow_mut();
166166
self.cache.update_order.retain(|id| {
167167
let note = &mut self.notes[*id as usize];
168-
note.update(res, rot, &tr, &mut ctrl_obj, line_height);
168+
note.update(res, parent_rot, &tr, &mut ctrl_obj, line_height);
169169
!note.dead()
170170
});
171171
drop(ctrl_obj);
@@ -208,18 +208,29 @@ impl JudgeLine {
208208
});
209209
}
210210

211+
pub fn fetch_rot(&self, lines: &[JudgeLine]) -> f32 {
212+
let mut rot = self.object.rotation.now();
213+
if self.rot_with_parent {
214+
if let Some(parent) = self.parent {
215+
rot += lines[parent].fetch_rot(lines);
216+
}
217+
}
218+
rot
219+
}
220+
211221
pub fn fetch_pos(&self, res: &Resource, lines: &[JudgeLine]) -> Vector {
212222
if let Some(parent) = self.parent {
213223
let parent = &lines[parent];
214-
let mut parent_translation = parent.fetch_pos(res, lines);
215-
parent_translation += Rotation2::new(parent.object.rotation.now().to_radians()) * self.object.now_translation(res);
216-
return parent_translation;
224+
let parent_translation = parent.fetch_pos(res, lines);
225+
return parent_translation + Rotation2::new(parent.fetch_rot(lines).to_radians()) * self.object.now_translation(res);
217226
}
218227
self.object.now_translation(res)
219228
}
220229

221230
pub fn now_transform(&self, res: &Resource, lines: &[JudgeLine]) -> Matrix {
222-
self.object.now_rotation().append_translation(&self.fetch_pos(res, lines))
231+
Rotation2::new(self.fetch_rot(lines).to_radians())
232+
.to_homogeneous()
233+
.append_translation(&self.fetch_pos(res, lines))
223234
}
224235

225236
pub fn render(&self, ui: &mut Ui, res: &mut Resource, lines: &[JudgeLine], bpm_list: &mut BpmList, settings: &ChartSettings, id: usize) {

prpr/src/parse/pec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ fn parse_judge_line(mut pec: PECJudgeLine, id: usize, max_time: f32) -> Result<J
172172
notes: pec.notes,
173173
color: Anim::default(),
174174
parent: None,
175+
rot_with_parent: false,
175176
z_index: 0,
176177
show_below: false,
177178
attach_ui: None,

prpr/src/parse/pgr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ fn parse_judge_line(pgr: PgrJudgeLine, max_time: f32, format_version: u32) -> Re
251251
notes,
252252
color: Anim::default(),
253253
parent: None,
254+
rot_with_parent: false,
254255
z_index: 0,
255256
show_below: false,
256257
attach_ui: None,

prpr/src/parse/rpe.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct RPEJudgeLine {
135135
texture: String,
136136
#[serde(rename = "father")]
137137
parent: Option<isize>,
138+
rotate_with_father: Option<bool>,
138139
event_layers: Vec<Option<RPEEventLayer>>,
139140
extended: Option<RPEExtendedEvents>,
140141
notes: Option<Vec<RPENote>>,
@@ -582,6 +583,7 @@ async fn parse_judge_line(
582583
Some(parent as usize)
583584
}
584585
},
586+
rot_with_parent: rpe.rotate_with_father.unwrap_or(false),
585587
z_index: rpe.z_order,
586588
show_below: rpe.is_cover != 1,
587589
attach_ui: rpe.attach_ui,

0 commit comments

Comments
 (0)