[Decompilation] [th02] Items: Tile invalidation

Part of P0243, funded by Yanga.
This commit is contained in:
nmlgc 2023-06-03 19:01:06 +02:00
parent 943da08767
commit 1099383256
3 changed files with 26 additions and 74 deletions

View File

@ -21,6 +21,7 @@ extern "C" {
#include "th02/main/item/shared.hpp"
#include "th02/main/player/player.hpp"
#include "th02/main/pointnum/pointnum.hpp"
#include "th02/main/tile/tile.hpp"
#include "th02/sprites/main_pat.h"
// Constants
@ -73,6 +74,28 @@ extern union {
extern int32_t item_score_this_frame;
// -----
void near items_invalidate(void)
{
for(int i = 0; i < ITEM_COUNT; i++) {
if(items[i].flag == F_FREE) {
continue;
}
item_pos_t near* pos = &items[i].pos[page_back];
screen_y_t top = pos->screen_top.to_pixel();
tiles_invalidate_rect(pos->screen_left, top, ITEM_W, ITEM_H);
pos->screen_left = items[i].pos[page_front].screen_left;
pos->screen_top = items[i].pos[page_front].screen_top;
if(items[i].flag == F_REMOVE) {
items[i].flag = F_FREE;
}
}
pointnums_invalidate();
}
// Returns `true` if the player collided with and collected the item.
bool16 pascal near item_hittest_y(item_t near& item)
{

View File

@ -3,7 +3,6 @@
static const int POINTNUM_DIGITS = 4;
void near pointnums_init_for_rank_and_reset(void);
void near pointnums_invalidate(void);
// ZUN landmine: [points] is not limited to POINTNUM_DIGITS. Larger values will
// be truncated to their least significant POINTNUM_DIGITS, with their first
@ -13,4 +12,5 @@ void pascal near pointnums_add(
);
// These are called from the respective item functions.
void near pointnums_invalidate(void);
void near pointnums_update_and_render(void);

View File

@ -1852,7 +1852,7 @@ loc_BCF9:
call sub_C6B2
call sub_10D42
call farfp_23A72
call sub_D874
call @items_invalidate$qv
call sub_4288
call sub_E2D9
cmp word_2034C, 0
@ -4913,81 +4913,10 @@ loc_D86E:
leave
retn 4
sub_D743 endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_D874 proc near
var_2 = word ptr -2
push bp
mov bp, sp
sub sp, 2
push si
push di
xor si, si
jmp short loc_D8FA
; ---------------------------------------------------------------------------
loc_D880:
mov bx, si
shl bx, 4
cmp _items[bx].ITEM_flag, F_FREE
jz short loc_D8F9
mov ax, si
shl ax, 4
mov dl, _page_back
mov dh, 0
shl dx, 2
add ax, dx
add ax, offset _items.ITEM_pos
mov di, ax
mov ax, [di+item_pos_t.ITEM_screen_top]
sar ax, 4
mov [bp+var_2], ax
call @tiles_invalidate_rect$qiiii pascal, [di+item_pos_t.ITEM_screen_left], ax, (16 shl 16) or 16
mov bx, si
shl bx, 4
mov al, _page_front
mov ah, 0
shl ax, 2
add bx, ax
mov ax, _items[bx].ITEM_pos.ITEM_screen_left
mov [di+item_pos_t.ITEM_screen_left], ax
mov bx, si
shl bx, 4
mov al, _page_front
mov ah, 0
shl ax, 2
add bx, ax
mov ax, _items[bx].ITEM_pos.ITEM_screen_top
mov [di+item_pos_t.ITEM_screen_top], ax
mov bx, si
shl bx, 4
cmp _items[bx].ITEM_flag, F_REMOVE
jnz short loc_D8F9
mov bx, si
shl bx, 4
mov _items[bx].ITEM_flag, F_FREE
loc_D8F9:
inc si
loc_D8FA:
cmp si, ITEM_COUNT
jl short loc_D880
call @pointnums_invalidate$qv
pop di
pop si
leave
retn
sub_D874 endp
main_01__TEXT ends
ITEM_TEXT segment byte public 'CODE' use16
@items_invalidate$qv procdesc near
@items_update_and_render$qv procdesc near
ITEM_TEXT ends