Skip to content

Commit c59ad47

Browse files
authored
Merge pull request #88 from SlimeYummy/feat/context-u32
change: context usize to u32
2 parents 459e06e + 23c4202 commit c59ad47

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ozz-animation-rs"
3-
version = "0.9.1"
3+
version = "0.9.2"
44
authors = ["SlimeYummy <zzzcccnnn@outlook.com>"]
55
edition = "2021"
66
rust-version = "1.75"

src/sampling_job.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ pub struct SamplingContext {
190190
animation_id: u64,
191191
ratio: f32,
192192

193-
translation_cursor: usize,
194-
rotation_cursor: usize,
195-
scale_cursor: usize,
193+
translation_cursor: u32,
194+
rotation_cursor: u32,
195+
scale_cursor: u32,
196196
}
197197

198198
unsafe impl Send for SamplingContext {}
@@ -517,19 +517,19 @@ impl SamplingContext {
517517
/// Current cursors in the animation. 0 means that the context is invalid.
518518
#[inline]
519519
pub fn translation_cursor(&self) -> usize {
520-
return self.translation_cursor;
520+
return self.translation_cursor as usize;
521521
}
522522

523523
/// Current cursors in the animation. 0 means that the context is invalid.
524524
#[inline]
525525
pub fn rotation_cursor(&self) -> usize {
526-
return self.rotation_cursor;
526+
return self.rotation_cursor as usize;
527527
}
528528

529529
/// Current cursors in the animation. 0 means that the context is invalid.
530530
#[inline]
531531
pub fn scale_cursor(&self) -> usize {
532-
return self.scale_cursor;
532+
return self.scale_cursor as usize;
533533
}
534534
}
535535

@@ -654,11 +654,11 @@ const _: () = {
654654
RelPtr::emplace(pos + fp, resolver.scale_keys_pos, fo);
655655

656656
let (fp, fo) = out_field!(out.translation_cursor);
657-
usize::resolve(&self.translation_cursor, pos + fp, (), fo);
657+
u32::resolve(&self.translation_cursor, pos + fp, (), fo);
658658
let (fp, fo) = out_field!(out.rotation_cursor);
659-
usize::resolve(&self.rotation_cursor, pos + fp, (), fo);
659+
u32::resolve(&self.rotation_cursor, pos + fp, (), fo);
660660
let (fp, fo) = out_field!(out.scale_cursor);
661-
usize::resolve(&self.scale_cursor, pos + fp, (), fo);
661+
u32::resolve(&self.scale_cursor, pos + fp, (), fo);
662662

663663
let (fp, fo) = out_field!(out.outdated_translations_ptr);
664664
RelPtr::emplace(pos + fp, resolver.outdated_translations_pos, fo);
@@ -744,9 +744,9 @@ const _: () = {
744744
.copy_from_slice(archived.translation_keys());
745745
context.rotation_keys_mut().copy_from_slice(archived.rotation_keys());
746746
context.scale_keys_mut().copy_from_slice(archived.scale_keys());
747-
context.translation_cursor = archived.translation_cursor as usize;
748-
context.rotation_cursor = archived.rotation_cursor as usize;
749-
context.scale_cursor = archived.scale_cursor as usize;
747+
context.translation_cursor = archived.translation_cursor;
748+
context.rotation_cursor = archived.rotation_cursor;
749+
context.scale_cursor = archived.scale_cursor;
750750
context
751751
.outdated_translations_mut()
752752
.copy_from_slice(archived.outdated_translations());
@@ -1132,19 +1132,19 @@ where
11321132
.last_mut()
11331133
.map(|x| *x = 0xFF >> last_offset);
11341134

1135-
ctx.translation_cursor = animation.num_aligned_tracks() * 2;
1135+
ctx.translation_cursor = (animation.num_aligned_tracks() as u32) * 2;
11361136
}
11371137

1138-
while ctx.translation_cursor < animation.translations().len() {
1139-
let track = animation.translations()[ctx.translation_cursor].track as usize;
1138+
while ctx.translation_cursor() < animation.translations().len() {
1139+
let track = animation.translations()[ctx.translation_cursor()].track as usize;
11401140
let key_idx = ctx.translation_keys()[track * 2 + 1] as usize;
11411141
let ani_ratio = animation.translations()[key_idx].ratio;
11421142
if ani_ratio > ratio {
11431143
break;
11441144
}
11451145

11461146
ctx.outdated_translations_mut()[track / 32] |= 1 << ((track & 0x1F) / 4);
1147-
let base = (animation.translations()[ctx.translation_cursor].track as usize) * 2;
1147+
let base = (animation.translations()[ctx.translation_cursor()].track as usize) * 2;
11481148
ctx.translation_keys_mut()[base] = ctx.translation_keys()[base + 1];
11491149
ctx.translation_keys_mut()[base + 1] = ctx.translation_cursor as i32;
11501150
ctx.translation_cursor = ctx.translation_cursor + 1;
@@ -1202,19 +1202,19 @@ where
12021202
.last_mut()
12031203
.map(|x| *x = 0xFF >> last_offset);
12041204

1205-
ctx.rotation_cursor = animation.num_aligned_tracks() * 2;
1205+
ctx.rotation_cursor = (animation.num_aligned_tracks() as u32) * 2;
12061206
}
12071207

1208-
while ctx.rotation_cursor < animation.rotations().len() {
1209-
let track = animation.rotations()[ctx.rotation_cursor].track() as usize;
1208+
while ctx.rotation_cursor() < animation.rotations().len() {
1209+
let track = animation.rotations()[ctx.rotation_cursor()].track() as usize;
12101210
let key_idx = ctx.rotation_keys()[track * 2 + 1] as usize;
12111211
let ani_ratio = animation.rotations()[key_idx].ratio;
12121212
if ani_ratio > ratio {
12131213
break;
12141214
}
12151215

12161216
ctx.outdated_rotations_mut()[track / 32] |= 1 << ((track & 0x1F) / 4);
1217-
let base = (animation.rotations()[ctx.rotation_cursor].track() as usize) * 2;
1217+
let base = (animation.rotations()[ctx.rotation_cursor()].track() as usize) * 2;
12181218
ctx.rotation_keys_mut()[base] = ctx.rotation_keys()[base + 1];
12191219
ctx.rotation_keys_mut()[base + 1] = ctx.rotation_cursor as i32;
12201220
ctx.rotation_cursor = ctx.rotation_cursor + 1;
@@ -1270,19 +1270,19 @@ where
12701270
let last_offset = ((animation.num_soa_tracks() + 7) / 8 * 8) - animation.num_soa_tracks();
12711271
ctx.outdated_scales_mut().last_mut().map(|x| *x = 0xFF >> last_offset);
12721272

1273-
ctx.scale_cursor = animation.num_aligned_tracks() * 2;
1273+
ctx.scale_cursor = (animation.num_aligned_tracks() as u32) * 2;
12741274
}
12751275

1276-
while ctx.scale_cursor < animation.scales().len() {
1277-
let track = animation.scales()[ctx.scale_cursor].track as usize;
1276+
while ctx.scale_cursor() < animation.scales().len() {
1277+
let track = animation.scales()[ctx.scale_cursor()].track as usize;
12781278
let key_idx = ctx.scale_keys()[track * 2 + 1] as usize;
12791279
let ani_ratio = animation.scales()[key_idx].ratio;
12801280
if ani_ratio > ratio {
12811281
break;
12821282
}
12831283

12841284
ctx.outdated_scales_mut()[track / 32] |= 1 << ((track & 0x1F) / 4);
1285-
let base = (animation.scales()[ctx.scale_cursor].track as usize) * 2;
1285+
let base = (animation.scales()[ctx.scale_cursor()].track as usize) * 2;
12861286
ctx.scale_keys_mut()[base] = ctx.scale_keys()[base + 1];
12871287
ctx.scale_keys_mut()[base + 1] = ctx.scale_cursor as i32;
12881288
ctx.scale_cursor = ctx.scale_cursor + 1;
@@ -1794,9 +1794,9 @@ mod sampling_tests {
17941794
assert_eq!(archived.size as usize, ctx.size());
17951795
assert_eq!(archived.animation_id, ctx.animation_id);
17961796
assert_eq!(archived.ratio, ctx.ratio);
1797-
assert_eq!(archived.translation_cursor as usize, ctx.translation_cursor);
1798-
assert_eq!(archived.rotation_cursor as usize, ctx.rotation_cursor);
1799-
assert_eq!(archived.scale_cursor as usize, ctx.scale_cursor);
1797+
assert_eq!(archived.translation_cursor, ctx.translation_cursor);
1798+
assert_eq!(archived.rotation_cursor, ctx.rotation_cursor);
1799+
assert_eq!(archived.scale_cursor, ctx.scale_cursor);
18001800
unsafe {
18011801
assert_eq!(archived.translations(), ctx.translations());
18021802
assert_eq!(archived.rotations(), ctx.rotations());

0 commit comments

Comments
 (0)