[Maintenance] [th05] Custom entities: Introduce separate template structures

Since the game uses global state to define its patterns, we'd really
like to see immediately which of the structure fields are relevant for
spawning bullets. This makes it easier to spot which of the patterns
rely on fields set in previous patterns – and there are several that
do.

Part of P0190, funded by nrook.
This commit is contained in:
nmlgc 2022-04-20 23:12:59 +02:00
parent 3b21a75cab
commit 37fac9a2a0
7 changed files with 69 additions and 22 deletions

View File

@ -7,7 +7,7 @@ typedef struct {
unsigned char angle;
PlayfieldMotion pos;
unsigned int age;
int revenge;
bool16 revenge;
int patnum_tiny_base;
int hp;
int damaged_this_frame;
@ -15,10 +15,28 @@ typedef struct {
int8_t padding;
} b4ball_t;
#define b4ball_template (reinterpret_cast<b4ball_t &>(custom_entities[0]))
struct b4ball_template_t {
/* -------------------- */ int8_t _unused_1;
unsigned char angle;
PlayfieldPoint origin;
/* -------------------- */ int16_t _unused_2[5];
bool16 revenge;
int patnum_tiny_base;
int hp;
/* -------------------- */ int16_t _unused_3;
SubpixelLength8 speed;
};
#define b4ball_template ( \
reinterpret_cast<b4ball_template_t &>(custom_entities[0]) \
)
#define b4balls (reinterpret_cast<b4ball_t *>(&custom_entities[1]))
void pascal near b4balls_reset(void);
// Spawns a new ball bullet according to the [b4ball_template]. Reads all
// non-unused fields of the b4ball_template_t structure.
void pascal near b4balls_add(void);
void pascal near b4balls_update(void);
void pascal near b4balls_render(void);

View File

@ -28,7 +28,7 @@ void near b6balls_add(void)
continue;
}
p->flag = B6BF_CLOUD;
p->pos.cur = b6ball_template.pos.cur;
p->pos.cur = b6ball_template.origin;
vector2_near(p->pos.velocity, b6ball_template.angle, speed);
p->patnum_tiny = b6ball_template.patnum_tiny;
p->cloud_radius.set(48.0f);

View File

@ -16,21 +16,32 @@ enum b6ball_flag_t {
typedef struct {
b6ball_flag_t flag;
unsigned char angle; // unused
int8_t unused_1;
PlayfieldMotion pos;
unsigned int age; // unused and broken, because it's never reset
Subpixel cloud_radius;
int patnum_tiny;
int decay_frames;
int16_t unused;
SubpixelLength8 speed; // unused
int8_t padding;
int8_t unused_2[4];
} b6ball_t;
#define b6ball_template (reinterpret_cast<b6ball_t &>(custom_entities[0]))
struct b6ball_template_t {
/* -------------------- */ int8_t _unused_1;
unsigned char angle;
PlayfieldPoint origin;
/* -------------------- */ int16_t _unused_2[6];
int patnum_tiny;
/* -------------------- */ int16_t _unused_3[2];
SubpixelLength8 speed;
};
#define b6ball_template ( \
reinterpret_cast<b6ball_template_t &>(custom_entities[0]) \
)
#define b6balls (reinterpret_cast<b6ball_t *>(&custom_entities[1]))
// Spawns a new ball bullet according to the [b6ball_template].
// Spawns a new ball bullet according to the [b6ball_template]. Reads all
// non-unused fields of the b6ball_template_t structure.
void near b6balls_add();
void near b6balls_update();

View File

@ -13,15 +13,13 @@ enum cheeto_flag_t {
// Defines the [col] instead of the (automatically calculated) [sprite].
typedef struct {
cheeto_flag_t flag;
/* -------------------- */ int8_t _unused_1;
unsigned char angle;
PlayfieldMotion pos;
unsigned int age; // unused and broken, because it's never reset
int16_t unused_2;
PlayfieldPoint origin;
/* -------------------- */ int16_t _unused_2[6];
int col;
int32_t unused_3;
/* -------------------- */ int32_t _unused_3;
SubpixelLength8 speed;
int8_t padding;
} cheeto_template_t;
typedef struct {
@ -58,6 +56,9 @@ extern cheeto_trail_t cheeto_trails[CHEETO_COUNT + 1];
// coordinate! [top] must therefore be between 0 and (RES_Y - 1).
void __fastcall near cheeto_put(uscreen_x_t left, uscreen_y_t top, int sprite);
void near cheetos_add();
// Spawns a new cheeto bullet according to the [cheeto_template]. Reads all
// non-unused fields of the cheeto_template_t structure.
void near cheetos_add(void);
void near cheetos_update();
void pascal near cheetos_render();

View File

@ -43,10 +43,10 @@ void near cheetos_add(void)
vector2_near(head_p->pos.velocity, head_p->angle, head_p->speed);
trail_p->col = cheeto_template.col;
head_p->sprite = bullet_patnum_for_angle(0, head_p->angle);
head_p->pos.cur = cheeto_template.pos.cur;
head_p->pos.cur = cheeto_template.origin;
for(node_i = 0; node_i < CHEETO_TRAIL_NODE_COUNT; node_i++) {
trail_p->node_pos[node_i] = cheeto_template.pos.cur;
trail_p->node_pos[node_i] = cheeto_template.origin;
trail_p->node_sprite[node_i] = head_p->sprite;
}
return;

View File

@ -15,9 +15,26 @@ typedef struct {
int8_t padding;
} sword_t;
#define sword_template (reinterpret_cast<sword_t &>(custom_entities[0]))
struct sword_template_t {
/* -------------------- */ int8_t unused_1;
unsigned char angle;
PlayfieldPoint origin;
/* -------------------- */ int16_t unused_2[4];
unsigned int twirl_time;
/* -------------------- */ int16_t unused_3;
int patnum_tiny;
/* -------------------- */ int16_t unused_4[2];
SubpixelLength8 speed;
};
#define sword_template (\
reinterpret_cast<sword_template_t &>(custom_entities[0]) \
)
#define swords (reinterpret_cast<sword_t *>(&custom_entities[1]))
// Spawns a new sword according to the [sword_template]. Reads all non-unused
// fields of the sword_template_t structure.
void pascal near swords_add(void);
void pascal near swords_update(void);
void pascal near swords_render(void);

View File

@ -53,7 +53,7 @@ cheeto_template_t struc
db ?
CBTMPL_angle db ?
pos motion_t <?>
CBTMPL_age dw ?
dw ?
dw ?
CBTMPL_col dw ?
dd ?
@ -133,10 +133,10 @@ b6ball_t struc
flag db ?
B6B_angle db ?
pos motion_t <?>
B6B_age dw ?
dw ?
cloud_radius dw ?
B6B_patnum_tiny dw ?
B6B_decay_frames dw ?
dw ?
dw ?
B6B_speed db ?
db ?