diff --git a/assets/levels/R2/parallax.toml b/assets/levels/R2/parallax.toml index 5d91003..b093034 100644 --- a/assets/levels/R2/parallax.toml +++ b/assets/levels/R2/parallax.toml @@ -3,7 +3,7 @@ width = 256 height = 44 u0 = 0 v0 = 0 -scrollx = 0 # TODO +scrollx = 0.0 # TODO y0 = 64 single = false diff --git a/include/parallax.h b/include/parallax.h index a99ddde..52c14f2 100644 --- a/include/parallax.h +++ b/include/parallax.h @@ -35,7 +35,7 @@ typedef struct { typedef struct { uint8_t num_parts; uint8_t is_single; - int16_t scrollx; + int32_t scrollx; int16_t y0; uint16_t width; // Sum of all widths, calculated on load! ParallaxPart *parts; diff --git a/src/parallax.c b/src/parallax.c index d2b9185..0cae626 100644 --- a/src/parallax.c +++ b/src/parallax.c @@ -33,7 +33,7 @@ load_parallax(Parallax *parallax, const char *filename) strip->num_parts = get_byte(bytes, &b); strip->is_single = get_byte(bytes, &b); - strip->scrollx = get_short_be(bytes, &b); + strip->scrollx = get_long_be(bytes, &b); strip->y0 = get_short_be(bytes, &b); strip->parts = alloc_arena_malloc( diff --git a/tools/buildprl/buildprl.py b/tools/buildprl/buildprl.py index 88fc0d7..107793c 100755 --- a/tools/buildprl/buildprl.py +++ b/tools/buildprl/buildprl.py @@ -12,6 +12,14 @@ c_ushort = c_ushort.__ctype_be__ c_int = c_int.__ctype_be__ +def tofixed(value: float, scale: int) -> int: + return int(value * (1 << scale)) + + +def tofixed12(value: float) -> int: + return tofixed(value, 12) + + @dataclass class ParallaxPart: u0: int = 0 @@ -31,14 +39,14 @@ class ParallaxPart: @dataclass class ParallaxStrip: single: bool = False - scrollx: int = 0 + scrollx: float = 0 y0: int = 0 parts: [ParallaxPart] = field(default_factory=list) def write_to(self, f): f.write(c_ubyte(len(self.parts))) f.write(c_ubyte(int(self.single))) - f.write(c_short(self.scrollx)) + f.write(c_int(tofixed12(self.scrollx))) f.write(c_short(self.y0)) for p in self.parts: p.write_to(f) diff --git a/tools/layouts/prl.hexpat b/tools/layouts/prl.hexpat index e3eac01..08d3016 100644 --- a/tools/layouts/prl.hexpat +++ b/tools/layouts/prl.hexpat @@ -11,7 +11,7 @@ struct ParallaxPart { struct ParallaxStrip { u8 num_parts; u8 is_single; - be s16 scrollx; + be s32 scrollx; be s16 y0; ParallaxPart parts[num_parts]; };