Skip to content

Commit

Permalink
[Decompilation] [th01] Stage objects: Main obstacle update/render fun…
Browse files Browse the repository at this point in the history
…ction

In which ZUN needs a hack to make columns of vertical bumper bars work
at all with the way the Orb's X velocity is implemented… and may have
just deliberately ensured that the Orb can definitely loop infinitely
between two bumpers.

(Those two wrong NOPCALLs aren't worth working around. It would
basically require taking apart the entire function, and they'll be gone
by the next two commits anyway.)

Part of P0203, funded by [Anonymous] and GhostRiderCog.
  • Loading branch information
nmlgc committed Jul 10, 2022
1 parent 8a92de7 commit f85587d
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 594 deletions.
3 changes: 3 additions & 0 deletions Research/Borland C++ decompilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ case it's part of an arithmetic expression that was promoted to `int`.
* The same `fpu_tmp` variable is also used as the destination for `FNSTSW`,
used in comparisons.

* On the stack, `fpu_tmp` is placed after all variables declared at the
beginning of the function.

* Performing arithmetic or comparisons between `float` and `double` variables
*always* `FLD`s the `float` first, before emitting the corresponding FPU
instruction for the `double`, regardless of how the variables are placed in
Expand Down
2 changes: 1 addition & 1 deletion th01/main/player/orb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void orb_force_new(double immediate, orb_force_t force)
extern const float ORB_FORCE_2_0;
extern const double ORB_FORCE_SHOT_BASE;

if(force == OF_BOUNCE_FROM_GROUND) {
if(force == OF_BOUNCE_FROM_SURFACE) {
orb_force = (-orb_velocity_y * ORB_COEFFICIENT_OF_RESTITUTION);
if(orb_velocity_x == OVX_0) {
random_velocity_change(0, OVX_4_LEFT);
Expand Down
24 changes: 23 additions & 1 deletion th01/main/player/orb.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#define ORB_HPP

static const pixel_t ORB_W = 32;
static const pixel_t ORB_H = 32;

static const pixel_t ORB_VISUAL_W = 25;
static const pixel_t ORB_VISUAL_H = 25;

static const pixel_t ORB_HITBOX_W = (ORB_W / 2);
static const pixel_t ORB_HITBOX_H = (ORB_W / 2);

Expand Down Expand Up @@ -37,7 +42,7 @@ enum orb_velocity_x_t {
};

enum orb_force_t {
OF_BOUNCE_FROM_GROUND = 0,
OF_BOUNCE_FROM_SURFACE = 0, // bottom of playfield, or bumper
OF_BOUNCE_FROM_TOP = 1,
OF_SHOT = 2,
OF_IMMEDIATE = 3, // new force passed directly in [immediate]
Expand Down Expand Up @@ -67,6 +72,23 @@ inline double orb_velocity_y_get(void) {
// the orb's velocity for this frame, in pixels to be added to [orb_cur_top].
pixel_t orb_velocity_y_update(void);

// Directly inverts the Orb's X velocity. Not idempotent within the same frame.
inline void orb_velocity_reflect_x(void) {
orb_velocity_x = (
(orb_velocity_x == OVX_4_LEFT ) ? OVX_4_RIGHT :
(orb_velocity_x == OVX_4_RIGHT) ? OVX_4_LEFT :
(orb_velocity_x == OVX_8_LEFT ) ? OVX_8_RIGHT :
(orb_velocity_x == OVX_8_RIGHT) ? OVX_8_LEFT :
/* (orb_velocity_x == OVX_0) */ OVX_0
);
}

// Inverts the Orb's Y velocity by applying a new force in the opposite
// direction. Idempotent within the same frame.
inline void orb_velocity_reflect_y(void) {
orb_force_new(-orb_velocity_y_get(), OF_IMMEDIATE);
}

// Updates [orb_cur_left] depending on the passed [velocity_x], *as well as*
// the global [orb_velocity_x] (!) to bounce the orb off the left or right
// edge of the playfield, if necessary.
Expand Down
2 changes: 1 addition & 1 deletion th01/main/player/orb[data].asm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OVX_4_RIGHT = 2
OVX_8_LEFT = 3
OVX_8_RIGHT = 4

OF_BOUNCE_FROM_GROUND = 0
OF_BOUNCE_FROM_SURFACE = 0
OF_BOUNCE_FROM_TOP = 1
OF_SHOT = 2
OF_IMMEDIATE = 3
Expand Down
4 changes: 2 additions & 2 deletions th01/main/stage/card_hit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void cards_hittest(int stage_num)
: (cards.top[i] - orb_cur_top);

if((
(delta.x < (ORB_W - (ORB_W / 4))) &&
(delta.y < (ORB_H - (ORB_H / 4))) &&
(delta.x < STAGEOBJ_ORB_DISTANCE_X) &&
(delta.y < STAGEOBJ_ORB_DISTANCE_Y) &&
(cards.flag[i] == CARD_ALIVE)
) || (
(test_damage == true) && (cards.flag[i] == CARD_ALIVE)
Expand Down
Loading

0 comments on commit f85587d

Please sign in to comment.