Skip to content

Commit

Permalink
Standardize MAD to use create_entity.h (#1612)
Browse files Browse the repository at this point in the history
More of the same unifying of the stages to all use the shared files.

Required a single ifdef to match. Nothing crazy.
  • Loading branch information
bismurphy authored Sep 16, 2024
1 parent 7adbf52 commit 43a9009
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 55 deletions.
8 changes: 6 additions & 2 deletions src/st/create_entities_horizontal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ void CreateEntitiesToTheLeft(s16 posX) {
FindFirstEntityToTheLeft(posX - g_ScrollDeltaX);
g_LayoutObjPosHorizontal = LAYOUT_OBJ_POSITION_BACKWARD;
}

// MAD only runs once to create one entity to the left.
#if !defined(VERSION_BETA)
while (true) {
#else
if (true) {
#endif
if (g_LayoutObjHorizontal[LAYOUT_OBJ_POS_X] == LAYOUT_OBJ_START ||
posX > g_LayoutObjHorizontal[LAYOUT_OBJ_POS_X]) {
break;
return;
}

expected = 0;
Expand Down
54 changes: 1 addition & 53 deletions src/st/mad/create_entity.c
Original file line number Diff line number Diff line change
@@ -1,56 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
#include "mad.h"

// BSS START size = 0x16
static u16* g_LayoutObjHorizontal;
static u16* g_LayoutObjVertical;
static u8 g_LayoutObjPosHorizontal;
STATIC_PAD_BSS(3);
static u8 g_LayoutObjPosVertical;
STATIC_PAD_BSS(3);
// END BSS

#include "../st_private.h"

#include "../create_entity_from_layout.h"
#include "../create_entity_in_range.h"
#include "../find_entity_horizontal.h"
#include "../create_entities_right.h"

/*
* n.b.! This is different from every other stage's `CreateEntitiesToTheLeft`.
* It will at most create 1 entity to the left and then exit with the horizontal
* array pointer updated to the next element in the sequence.
*/
void CreateEntitiesToTheLeft(s16 posX) {
u8 flag;
s32 expected = 0;

if (posX < 0) {
posX = 0;
}

if (g_LayoutObjPosHorizontal == LAYOUT_OBJ_POSITION_FORWARD) {
FindFirstEntityToTheLeft(posX - g_ScrollDeltaX);
g_LayoutObjPosHorizontal = LAYOUT_OBJ_POSITION_BACKWARD;
}

if (g_LayoutObjHorizontal[LAYOUT_OBJ_POS_X] == LAYOUT_OBJ_START ||
g_LayoutObjHorizontal[LAYOUT_OBJ_POS_X] < posX) {
return;
}

flag = (g_LayoutObjHorizontal[LAYOUT_OBJ_SLOT] >> 8) + 0xff;
expected = 0;
if (flag == 0xFF ||
((g_entityDestroyed[flag >> 5] & (1 << (flag & 0x1f))) == expected)) {
CreateEntityWhenInVerticalRange(g_LayoutObjHorizontal);
}
g_LayoutObjHorizontal -= 5;
}

#include "../find_entity_vertical.h"
#include "../create_entities_vertical.h"
#include "../init_room_entities.h"
#include "../update_room_position.h"
#include "../create_entity_from_entity.h"
#include "../create_entity.h"

0 comments on commit 43a9009

Please sign in to comment.