Skip to content

Commit

Permalink
[Decompilation] [th01] Boss entities: Clamped movement + unblitting +…
Browse files Browse the repository at this point in the history
… blitting

A function which does so many individual things that I can't even
summarize it in a comment without spelling out each line of code. And
then, this entire clamped movement system is only used for Kikuri's
soul sprites. The usage code for every other entity just parties on
the [cur_left] and [cur_top] members, and passes a delta of (0, 0) to
this function. 🤷

Part of P0108, funded by Yanga.
  • Loading branch information
nmlgc committed Aug 12, 2020
1 parent 2a091ee commit 52def53
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 373 deletions.
1 change: 1 addition & 0 deletions Research/Borland C++ decompilation.md
Expand Up @@ -40,6 +40,7 @@ where the scalar-type variable is declared in relation to them.
| `ADD [m8], imm8` | Only achievable through a C++ method operating on a member? |
| `MOV AL, [m8]`<br />`ADD AL, imm8`<br />`MOV [m8], AL` | Opposite; *not* an inlined function |
| `CWD`<br />`SUB AX, DX`<br />`SAR AX, 1` | `AX / 2`, `AX` is *int* |
| `MOV [new_var], AX`<br />`CWD`<br />`XOR AX, DX`<br />`SUB AX, DX` | `abs(AX)`, defined in `<stdlib.h>`. `AX` is *int* |

### Arithmetic on a register *after* assigning it to a variable?

Expand Down
29 changes: 29 additions & 0 deletions th01/main/boss/entity.cpp
Expand Up @@ -528,3 +528,32 @@ void CBossEntity::sloppy_unput() const
{
egc_copy_rect_1_to_0_16(cur_left, cur_top, (vram_w * BYTE_DOTS), h);
}

void CBossEntity::move_lock_unput_and_put_8(
int, int delta_x, int delta_y, int lock_frames
)
{
if(move_lock_frame == 0) {
move(delta_x, delta_y);

int unput_left = (prev_delta_x > 0)
? ((prev_left / BYTE_DOTS) * BYTE_DOTS)
: (((cur_left / BYTE_DOTS) * BYTE_DOTS) + (vram_w * BYTE_DOTS));
egc_copy_rect_1_to_0_16(unput_left, prev_top, 8, h);

int unput_top = (cur_top > prev_top)
? prev_top
: (cur_top + h);
egc_copy_rect_1_to_0_16(
prev_left, unput_top, (vram_w << 3), abs(cur_top - prev_top)
);

unput_and_put_8(cur_left, cur_top, bos_image);

move_lock_frame = 1;
} else if(move_lock_frame >= lock_frames) {
move_lock_frame = 0;
} else {
move_lock_frame++;
}
}
31 changes: 31 additions & 0 deletions th01/main/boss/entity.hpp
Expand Up @@ -112,6 +112,31 @@ class CBossEntity {

/// Movement
/// --------
protected:
void move(const int &delta_x, const int &delta_y) {
prev_delta_x = delta_x;
prev_delta_y = delta_y;
prev_left = cur_left;
prev_top = cur_top;

cur_left += prev_delta_x;
if(move_clamp.left > cur_left) {
cur_left = move_clamp.left;
}
if(move_clamp.right < cur_left) {
cur_left = move_clamp.right;
}

cur_top += prev_delta_y;
if(cur_top < move_clamp.top) {
cur_top = move_clamp.top;
}
if(cur_top > move_clamp.bottom) {
cur_top = move_clamp.bottom;
}
}

public:
// Sets [cur_left], [cur_top], [unknown], and the [move_clamp] area.
void pos_set(
int left,
Expand All @@ -122,5 +147,11 @@ class CBossEntity {
int move_clamp_top,
int move_clamp_bottom
);

// (Just read the actual function code, it's impossible to summarize
// without spelling every single line here.)
void move_lock_unput_and_put_8(
int unused, int delta_x, int delta_y, int lock_frames
);
/// --------
};

0 comments on commit 52def53

Please sign in to comment.