Skip to content

Conversation

@Rozelette
Copy link
Contributor

@Rozelette Rozelette commented Apr 19, 2025

The adds the ObjectExtension system, which allows you to attach extra data to pointers. This is a response to #5204 which I thought was too much of a deviation to be appropriate as a code review. It attempts to solve the same problem as ActorExtension -- adding new fields to structs while minimizing source code changes. The core differences are:

  • Store the extra data in a std::any. This allows it to know the type and be able to properly construct and deconstruct nontrivial objects. This also requires Get and Set to be templated.
  • Introduce the idea that only 1 instance of each base type can be attached. This works nicely with already templated functions. It enables an ObjectExtension::Register helper that hides the implementation details of the system.

Build Artifacts

actorEntry = &play->setupActorList[0];
for (i = 0; i < play->numSetupActors; i++) {
Actor_SpawnEntry(&play->actorCtx, actorEntry++, play);
Actor* spawnedActor = Actor_SpawnEntry(&play->actorCtx, actorEntry++, play);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if this line should be included in the #region, since it was changed and not added. Let me know what the policy is to do here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it really matters, but I think this is fine as is. If you removed the entire region, the code would function exactly as before the change, so I think in that sense the way it is now is correct. The compiler would warn us about the unused assignment afterwards anyway to clue us in that it also needs to be changed (assuming we see it in the sea of warnings lol.)

return NULL;
}

// #region SOH [ObjectExtension]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally this (and the line in Actor_Delete) should be hooks, but I wanted to keep the review focused on the new system. If this is merged, I intend to add those hooks and convert this code to use them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I didn't add a hook when I ported 2ship's ActorExtensions because 2ship itself wasn't using hooks for it so I kind of assumed that there was some technical reason why a hook was difficult to do there. If you've got a way to use a hook I say go nuts.

@Malkierian
Copy link
Contributor

I don't see anything inherently wrong in the code, but I think I'd understand it better if there were an example of it in use.

@leggettc18
Copy link
Contributor

Well there is the ActorListIndex already that you can see in action currently on the Actor Viewer.

@Malkierian Malkierian merged commit e4448f4 into HarbourMasters:develop May 23, 2025
6 checks passed
krazyjakee pushed a commit to krazyjakee/OOT that referenced this pull request Sep 6, 2025
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.

3 participants