mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-19 22:36:49 +00:00
Attempt to fix other player rotations
This doesn't work just yet, but I guess I'm getting closer.
This commit is contained in:
parent
dbfd5fccc4
commit
ca94e26e1c
3 changed files with 35 additions and 10 deletions
|
@ -89,10 +89,20 @@ pub(crate) fn read_packed_float(packed: u16) -> f32 {
|
|||
((packed as f32 / 0.327675) / 100.0) - 1000.0
|
||||
}
|
||||
|
||||
pub(crate) fn write_packed_float(float: f32) -> u16 {
|
||||
pub(crate) fn write_packed_float(float: &f32) -> u16 {
|
||||
(((float + 1000.0) * 100.0) * 0.327675) as u16
|
||||
}
|
||||
|
||||
pub(crate) fn write_packed_rotation_float(float: &f32) -> u8 {
|
||||
let pi = std::f32::consts::PI;
|
||||
|
||||
(0x80 as f32 * (float + pi) / pi) as u8
|
||||
}
|
||||
|
||||
pub(crate) fn read_packed_rotation_float(packed: u8) -> f32 {
|
||||
0.0
|
||||
}
|
||||
|
||||
pub(crate) fn read_packed_position(packed: [u16; 3]) -> Position {
|
||||
Position {
|
||||
x: read_packed_float(packed[0]),
|
||||
|
@ -103,9 +113,9 @@ pub(crate) fn read_packed_position(packed: [u16; 3]) -> Position {
|
|||
|
||||
pub(crate) fn write_packed_position(pos: &Position) -> [u16; 3] {
|
||||
[
|
||||
write_packed_float(pos.x),
|
||||
write_packed_float(pos.y),
|
||||
write_packed_float(pos.z),
|
||||
write_packed_float(&pos.x),
|
||||
write_packed_float(&pos.y),
|
||||
write_packed_float(&pos.z),
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -201,6 +211,10 @@ mod tests {
|
|||
#[test]
|
||||
fn packed_floats() {
|
||||
assert_eq!(read_packed_float(32931), 4.989685);
|
||||
assert_eq!(write_packed_float(5.0), 32931);
|
||||
assert_eq!(write_packed_float(&5.0), 32931);
|
||||
|
||||
assert_eq!(write_packed_rotation_float(&0.0), 128);
|
||||
assert_eq!(write_packed_rotation_float(&-2.7768986), 14);
|
||||
assert_eq!(write_packed_rotation_float(&3.128286), 255);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -290,7 +290,12 @@ impl ZoneConnection {
|
|||
op_code: ServerZoneIpcType::ActorMove,
|
||||
timestamp: timestamp_secs(),
|
||||
data: ServerZoneIpcData::ActorMove(ActorMove {
|
||||
speed: 24,
|
||||
rotation,
|
||||
dir_before_slip: 0x7F,
|
||||
flag1: 0,
|
||||
flag2: 0,
|
||||
speed: 0x3C,
|
||||
unk1: 0xEA,
|
||||
position,
|
||||
..Default::default()
|
||||
}),
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
use binrw::binrw;
|
||||
|
||||
use crate::common::{Position, read_packed_position, write_packed_position};
|
||||
use crate::common::{
|
||||
Position, read_packed_position, read_packed_rotation_float, write_packed_position,
|
||||
write_packed_rotation_float,
|
||||
};
|
||||
|
||||
#[binrw]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ActorMove {
|
||||
pub dir: u8,
|
||||
#[bw(map = write_packed_rotation_float)]
|
||||
#[br(map = read_packed_rotation_float)]
|
||||
pub rotation: f32,
|
||||
pub dir_before_slip: u8,
|
||||
pub flag1: u8,
|
||||
pub flat2: u8,
|
||||
pub flag2: u8,
|
||||
pub speed: u8,
|
||||
#[brw(pad_before = 1, pad_after = 4)] // empty
|
||||
pub unk1: u8,
|
||||
#[brw(pad_after = 4)] // empty
|
||||
#[br(map = read_packed_position)]
|
||||
#[bw(map = write_packed_position)]
|
||||
pub position: Position,
|
||||
|
|
Loading…
Add table
Reference in a new issue