Skip to content

Commit

Permalink
[Decompilation] [th05] Shinki's 32×32 balls: Update function
Browse files Browse the repository at this point in the history
Completes P0188, funded by [Anonymous] and nrook.
  • Loading branch information
nmlgc committed Mar 27, 2022
1 parent adffa1c commit e881f95
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 116 deletions.
66 changes: 66 additions & 0 deletions th05/main/bullet/b6ball.cpp
Expand Up @@ -2,16 +2,22 @@

#include "platform.h"
#include "pc98.h"
#include "th01/math/overlap.hpp"
#include "th01/math/subpixel.hpp"
#include "th04/math/motion.hpp"
extern "C" {
#include "th04/math/vector.hpp"
#include "th04/main/playfld.hpp"
#include "th04/main/player/player.hpp"
#include "th04/main/bullet/clearzap.hpp"
#include "th05/sprites/main_pat.h"
#include "th05/main/playperf.hpp"
}
#include "th05/main/custom.h"
#include "th05/main/bullet/b6ball.hpp"

inline void optimization_barrier(void) {}

void near b6balls_add(void)
{
subpixel_t speed = playperf_speedtune(b6ball_template.speed);
Expand All @@ -29,3 +35,63 @@ void near b6balls_add(void)
return;
}
}

void near b6balls_update(void)
{
CUSTOM_VERIFY(b6ball_t, B6BALL_COUNT);

b6ball_t near *p;
int i;
for((p = b6balls, i = 1); i < (1 + B6BALL_COUNT); (i++, p++)) {
if(p->flag == B6BF_FREE) {
continue;
}
if(p->flag == B6BF_CLOUD) {
p->cloud_radius -= 2.0f;
if(p->cloud_radius.v < to_sp(B6BALL_W / 2)) {
static_cast<unsigned char>(p->flag)++;
} else {
continue;
}
}

if(bullet_clear_time || bullet_zap.active) {
p->flag = B6BF_DECAY;
}

p->age++;
/* DX:AX = */ p->pos.update_seg3();
if(!playfield_encloses(_AX, _DX, B6BALL_W, B6BALL_H)) {
optimization_barrier();
p->flag = B6BF_FREE;
} else if(p->flag != B6BF_DECAY) {
_AX -= player_pos.cur.x.v;
_DX -= player_pos.cur.y.v;
if(overlap_wh_inplace_fast(
_AX, _DX, to_sp(B6BALL_W / 2), to_sp(B6BALL_H / 2)
)) {
player_is_hit = true;
p->flag = B6BF_DECAY;
continue;
}
optimization_barrier();
} else if(p->patnum_tiny < PAT_DECAY_B6BALL) {
// Rather brave to assume that the regular patnums of this entity
// can't be smaller. You know how you properly DRY decay state
// initialization? By moving it into a function...
p->patnum_tiny = PAT_DECAY_B6BALL;
p->pos.velocity.x.v /= 2;
p->pos.velocity.y.v /= 2;
p->decay_frames = 0;
} else /* if(p->flag == B6BF_DECAY) */ {
p->decay_frames++;
if((p->decay_frames % 4) == 0) {
p->patnum_tiny++;
if(p->patnum_tiny >= (PAT_DECAY_B6BALL_last + 1)) {
p->flag = B6BF_FREE;
}
}
}
loop_end:
}
}
4 changes: 2 additions & 2 deletions th05/main/bullet/b6ball.hpp
Expand Up @@ -18,7 +18,7 @@ typedef struct {
b6ball_flag_t flag;
unsigned char angle; // unused
PlayfieldMotion pos;
unsigned int age;
unsigned int age; // unused and broken, because it's never reset
Subpixel cloud_radius;
int patnum_tiny;
int decay_frames;
Expand All @@ -33,5 +33,5 @@ typedef struct {
// Spawns a new ball bullet according to the [b6ball_template].
void near b6balls_add();

void pascal near b6balls_update();
void near b6balls_update();
void pascal near b6balls_render();
112 changes: 0 additions & 112 deletions th05/main/bullet/b6balls_add_update.asm

This file was deleted.

4 changes: 2 additions & 2 deletions th05_main.asm
Expand Up @@ -19673,10 +19673,10 @@ main_035_TEXT ends

BOSS_6_TEXT segment byte public 'CODE' use16
@b6balls_add$qv procdesc near
@b6balls_update$qv procdesc near
BOSS_6_TEXT ends

BOSS_X_TEXT segment byte public 'CODE' use16
include th05/main/bullet/b6balls_add_update.asm

; =============== S U B R O U T I N E =======================================

Expand Down Expand Up @@ -21130,7 +21130,7 @@ loc_1E522:
call @boss_defeat_update$qui pascal, 65

loc_1E527:
call b6balls_update
call @b6balls_update$qv
call @curvebullets_update$qv
call hud_hp_update_and_render pascal, _boss_hp, 22800
pop di
Expand Down

0 comments on commit e881f95

Please sign in to comment.