Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapNamePopUp Documentation #352

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

estellarc
Copy link

  • Renamed unk_02071CFC -> map_header_util
  • Renamed ov5_021DD6FC -> map_name_popup

I'm unsure how I should name sub_02071D10 and about the most variables in MapNamePopUp_DrawWindowFrame

#325

Copy link
Collaborator

@lhearachel lhearachel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great overall! Thanks for your contribution. I have some feedback and collaborative thoughts scattered throughout.

You'll also want to do a pull from main before continuing, as some generated headers are being shifted around. I tried to call those out where I saw them.

Comment on lines 14 to 34
u32 MapHeader_GetStringWidth(MessageLoader *msgLoader, u32 entryID, Strbuf *strbuf)
{
u32 width;

MessageLoader_GetStrbuf(msgLoader, entryID, strbuf);
width = Font_CalcStrbufWidth(FONT_SYSTEM, strbuf, 0);

return width;
}

void sub_02071D10(int headerID, u32 heapID, Strbuf *strbuf)
{
u32 mapLabelTextID;
MessageLoader *msgLoader;

msgLoader = MessageLoader_Init(MESSAGE_LOADER_NARC_HANDLE, NARC_INDEX_MSGDATA__PL_MSG, message_bank_location_names, heapID);
mapLabelTextID = MapHeader_GetMapLabelTextID(headerID);

MapHeader_GetStringWidth(msgLoader, mapLabelTextID, strbuf); // It should be MessageLoader_GetStrbuf()
MessageLoader_Free(msgLoader);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first of these two functions seems to be more generic than just MapHeader; rather, it seems like it's used to pull any given string from any given text bank, then return its width. I would suggest naming these functions as:

  • MapHeader_GetStringWidth -> MapHeader_LoadString
  • sub_02071D10 -> MapHeader_LoadName

return width;
}

void sub_02071D10(int headerID, u32 heapID, Strbuf *strbuf)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: Try replacing headerID here with enum MapHeader from generated/map_headers.h after merging from main.

#include <string.h>

#include "field/field_system_sub2_t.h"
#include "text/pl_msg.naix"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore: Replace this with generated/text_banks.h after merging from main.


u32 MapHeader_GetStringWidth(MessageLoader *msgLoader, u32 entryID, Strbuf *strbuf)
{
u32 width;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: Try to declare + define variables inline where possible, e.g., prefer

u32 width = Font_CalcStrbufWidth(FONT_SYSTEM, strbuf, 0);

vs.

u32 width;

// other code

width = Font_CalcStrbufWidth(FONT_SYSTEM, strbuf, 0);


static void MapNamePopUp_LoadPalette(void *src, u16 size, u16 offset)
{
DC_FlushRange((void *)src, size * 32);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is this void * cast necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently not, it gives a match, the same with the const void *on GX_LoadBGPltt

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fairly typical. 😁 An explicit void * cast is almost never necessary, and the compiler will often do it for you.

Comment on lines +73 to +74
// I'm confused by this
narcMemberIdx = mapPopUp->windowID * 2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the structure of the NARC itself (arc/area_win_gra.narc), it looks like the window ID is just which window type is being used for this pop-up. There are 2 files for each pop-up type: a set of tiles, and a palette. So, multiplying the type ID by 2 yields the member index of the tile-data.

Comment on lines 235 to 236
mapPopUp = Heap_AllocFromHeap(4, sizeof(MapNamePopUp));
mapPopUp->strbuf = Strbuf_Init(22, 4);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: Replace these 4s with HEAP_ID_FIELD from constants/heap.h

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
8ad93df

mapPopUp = NULL;
}

void MapNamePop_Show(MapNamePopUp *mapPopUp, s32 mapLabelTextID, s32 mapLabelWindowID)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish:

Suggested change
void MapNamePop_Show(MapNamePopUp *mapPopUp, s32 mapLabelTextID, s32 mapLabelWindowID)
void MapNamePopUp_Show(MapNamePopUp *mapPopUp, s32 mapLabelTextID, s32 mapLabelWindowID)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly me
35429ff

u8 v6;
u8 v7;

v3 = (strWidth + 8) / 8 * 8;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the total number of pixels used by the string. 8 here is the width of a tile in pixels.

u32 mapLabelTextID;
MessageLoader *msgLoader;

msgLoader = MessageLoader_Init(MESSAGE_LOADER_NARC_HANDLE, NARC_INDEX_MSGDATA__PL_MSG, message_bank_location_names, heapID);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After you merge from main, message_bank_location_names will become TEXT_BANK_LOCATION_NAMES.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants