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

Doc/Cleanup pass on object handling #1227

Merged
merged 64 commits into from
Sep 19, 2023

Conversation

Dragorn421
Copy link
Collaborator

@Dragorn421 Dragorn421 commented May 16, 2022

  • ObjectStatus status[OBJECT_EXCHANGE_BANK_MAX]; -> ObjectEntry slots[19];
  • Object_InitBank -> Object_Init
  • Object_Spawn -> Object_SpawnPersistent
  • Object_GetIndex -> Object_GetSlot
  • "obj bank index" -> "object slot" (objectCtx.slots[actor.objectSlot])
  • Cleanup around usage of object slots, and the WaitForObject scheme
  • other less important renames and cleanup

Sorry for the big PR, starting to cleanup/rename "obj bank index" stuff was a deeper rabbit hole than I expected it to be. It was far from a replace-all change too, the names in master aren't super consistent

include/functions.h Outdated Show resolved Hide resolved
include/z64.h Outdated Show resolved Hide resolved
include/z64actor.h Outdated Show resolved Hide resolved
src/code/z_actor.c Outdated Show resolved Hide resolved
src/overlays/actors/ovl_En_Ex_Item/z_en_ex_item.h Outdated Show resolved Hide resolved
include/z64.h Outdated Show resolved Hide resolved
src/code/z_scene.c Outdated Show resolved Hide resolved
src/code/z_scene.c Outdated Show resolved Hide resolved
@fig02
Copy link
Collaborator

fig02 commented Jun 9, 2022

@MNGoldenEagle suggested using the terminology "slot" to help with the "entry" discussion, and I think this could work really well. Ive already called them slots on my own terms when describing things about the system outside of the codebase

ObjectEntry entries[19]; -> ObjectEntry slots[19]; (imo the struct can stay as entry, there are slots for different entries)
Object_GetEntry -> Object_GetSlot
Object_IsEntryLoaded -> Object_IsLoaded (see my pr comment above on why i think this change makes sense)
actor.objectEntry -> actor.objectSlot

unlike with entry, I dont think the word "index" is needed to clarify that its a number for the slot. It works out well imo

src/code/z_scene.c Outdated Show resolved Hide resolved
src/code/z_scene.c Outdated Show resolved Hide resolved
src/code/z_scene.c Show resolved Hide resolved
include/functions.h Outdated Show resolved Hide resolved
Copy link
Contributor

@hensldm hensldm left a comment

Choose a reason for hiding this comment

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

Seems good to me. Hopefully we can agree on a name for func_80097DD8 eventually.

Copy link
Contributor

@AngheloAlf AngheloAlf left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 49 to 50
void func_80097DD8(PlayState* play, ObjectContext* objectCtx) {
PlayState* play2 = play;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Starting this as a separate comment to start fresh since it has been so long, though technically it is a continuation of #1227 (comment)

I believe that Object_InitContext is a fine name for this. While I do understand concerns that it initializes more than just the literal ObjectContext struct, it gets the point of the function across. We use this method of naming in similar places like Actor_InitContext which does more than just init the literal context structure. It initializes the overlay table, copies the identity matrix to the matrices in play, and inits fw data which mostly concerns save context. It is still actor related things.

In that same vein, I think Object_InitContext is more than suitable for this function name in the same way. Its for the Object system generally.

Note, I named this function with InitContext in the mm version of this PR, which is still under review: zeldaret/mm#1361

Copy link
Contributor

Choose a reason for hiding this comment

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

My current opinion is that Object_InitContext feels like a bad name moreso because the system name of Object_ isn't very good and ideally should be renamed. But if that's not on the cards atm, I agree with fig in calling it Object_InitContext just to get it merged for now.

But if we're up to giving the system a better name, I find it hard not to borrow from og. Perhaps it's because I've been doing a lot of Atari2600 programming lately, but I think I'd prefer to keep the bank swapping terminology given how similar it is to how you'd handle bank switching in older hardware, just in a virtualized form.

For renames I'd personally would like to go with something like this:

Object_ -> ObjectExchange_
ObjectContext -> ObjectExchange
ObjectEntry -> ObjectBank or ObjectExchangeBank
ObjectContext.slot -> ObjectExchange.bankSlot

Object_SpawnPersistent -> ObjectExchange_AllocBank?
func_80097DD8 -> ObjectExchange_Init
Object_UpdateEntries -> ObjectExchange_FetchBanksAsync
Object_GetSlot -> ObjectExchange_GetBankSlot
Object_IsLoaded -> ObjectExchange_IsBankLoaded
func_800981B8 -> ObjectExchange_FetchBanksSync
func_800982FC -> ObjectExchange_BankSwitch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Define "bank"

Copy link
Contributor

Choose a reason for hiding this comment

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

My personal opinion as a programmer is that a bank / memory bank is just a segment of contiguous random access memory. But the definitions I've seen all associate memory banks to physical hardware. For example in bank swapping you aren't spending time transferring data into main memory; a bank swap switches out what physical memory the main processor memory is able to access directly.

In my atari 2600 game for example, I use an 3E+ bankswitching scheme which splits processor memory into 4 1k segments that can be arbitrarily swapped with 64 1k read-only memory segments and 64 0.5k read 0.5k write segments. Bankswitching is done by passing in an 8 bit value storing the main memory segment id and the 0-63 memory bank id to either the read-only memory or read-write register.

More back to Z64, if I were to describe the object swapping system in terms of bank swapping, ObjectEntry would represent the processor accessible memory banks, while the object files themselves would represent external memory banks you'd swap in.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use a naming convention that better adjusts to this game (or at least to the N64 hardware) instead of terminology from the Atari 2600?
Personally I think the bank terminology doesn't fit the object system

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So with the definition of "bank = an area of memory that we can effectively easily swap the data it maps to"
(note: "bank" is not even a good term to use at all from being so poorly defined)

Then the object system doesn't have banks:
You can't swap data in slots besides the highest-indexed/top one, so that fails that definition of "bank"

Copy link
Contributor

Choose a reason for hiding this comment

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

Fwiw, Object_InitContext seems fine/best to me.

Copy link
Contributor

@mzxrules mzxrules Sep 15, 2023

Choose a reason for hiding this comment

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

Can we use a naming convention that better adjusts to this game (or at least to the N64 hardware) instead of terminology from the Atari 2600?

Bank switching was still a relevant technique in console game development in the 90s and early 2000s. I only mention the 2600 because I'm more familiar with the system than the Gameboy/Gameboy Color or SNES.

@Dragorn421 Dunno how to best respond, so i'll start off by admitting that I missed that the variable objectCtx->slots[i+1].segment where i is the updated slot happens to be updated when Object_SpawnPersistent and func_800982FC are called (though the later is a bit particular since the update occurs in Scene_CommandObjectList, meaning the system doesn't fully manage it's memory internally).

(note: "bank" is not even a good term to use at all from being so poorly defined)

I don't think so.

So with the definition of "bank = an area of memory that we can effectively easily swap the data it maps to"
Then the object system doesn't have banks: You can't swap data in slots besides the highest-indexed/top one, so that fails that definition of "bank"

Weird thing about that. It's likely intended that slots are reserved sequentially, but func_800982FC's implementation allows any arbitrary slot to be swapped over with a new object file. If you had same sized segments like the warp pad texture objects, you could safely hotswap them with func_800982FC calls, making func_800982FC behave very similarly to swapping banks, with about the same level of safety.

I've thought more on it, and would like to suggest this set of function names instead. I don't think these names are 100% perfect, but at the same time the original system could arguably use a few rewrites to make things cleaner/safer.

Object_SpawnPersistent -> ObjectExchange_AllocPersistentSegment
func_80097DD8 -> ObjectExchange_Init
Object_UpdateEntries -> ObjectExchange_FetchSegmentsAsync
Object_GetSlot -> ObjectExchange_FindSlot <- could stay Get, but Find is a little more accurate imo.
Object_IsLoaded -> ObjectExchange_IsSegmentLoaded
func_800981B8 -> ObjectExchange_FetchSegmentsSync
func_800982FC -> ObjectExchange_AllocSegment

I'm not really a fan of the concept of object files being "spawned".

}

ASSERT(cmd->objectList.length <= OBJECT_EXCHANGE_BANK_MAX,
ASSERT(cmd->objectList.length <= ARRAY_COUNT(play->objectCtx.slots),
Copy link
Contributor

Choose a reason for hiding this comment

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

Noticed that the ASSERT here is flawed; It should be checking for cmd->objectList.length + play->objectCtx.numPersistentEntries <= ARRAY_COUNT(play->objectCtx.slots) instead

Copy link
Collaborator

Choose a reason for hiding this comment

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

good catch, though yeah we cant do anything about it cause its their mistake. can add a comment though

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Dragorn421 can add this in this pr if you like, would even consider it an @bug

@Dragorn421
Copy link
Collaborator Author

I would like the names for object_initcontext, object_spawnpersistent, and others, as well as commenting on the flawed assert, to be done in another PR (get this one over with)

@fig02
Copy link
Collaborator

fig02 commented Sep 19, 2023

Obejct_SpawnPersistent is already named? what else needs to be done there?
I think it makes most sense to name Object_InitContext with this set of changes cause of how important it is. But any other cleanups, I agree

@Dragorn421
Copy link
Collaborator Author

I was referring to mzx' suggestions which seemed to put an emphasis on the spawnpersistent name
I named Object_InitContext

@fig02 fig02 removed the Needs discussion There is a debate or other required discussion preventing changes from being made label Sep 19, 2023
@fig02 fig02 merged commit 57ce0cf into zeldaret:master Sep 19, 2023
@Dragorn421 Dragorn421 deleted the doc_object_handling branch September 19, 2023 18:11
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.

7 participants