mirror of
https://github.com/luksamuk/engine-psx.git
synced 2025-04-28 13:28:02 +03:00
Change parallax scrollx to float factor
This commit is contained in:
parent
f6c6d49761
commit
bb4df1993d
5 changed files with 14 additions and 6 deletions
|
@ -3,7 +3,7 @@ width = 256
|
|||
height = 44
|
||||
u0 = 0
|
||||
v0 = 0
|
||||
scrollx = 0 # TODO
|
||||
scrollx = 0.0 # TODO
|
||||
y0 = 64
|
||||
single = false
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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];
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue