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
Generic actor params getters #1359
base: main
Are you sure you want to change the base?
Conversation
Bump on the comment
which was in reaction to - invisble = this->actor.params & SPAWN_INVISIBLE;
+ invisble = PARAMS_GET_NOSHIFT(this->actor.params, 15, 1); // SPAWN_INVISIBLE Personally I'm waiting on solving that to continue reviewing as this comes up often-ish (also many conflicts in here... I hope it's manageable 😨) |
Is it still (or I guess was it even) the plan for actor's to make their own macros, with descriptive names, that just build off these ones? |
Not that this dictates what we do, but Ive been learning about tww/tp lately, and they ended up taking the generic approach in those games: inline u32 fopAcM_GetParamBit(void* ac, u8 shift, u8 bit) {
return (fopAcM_GetParam(ac) >> shift) & ((1 << bit) - 1);
} (also, they actually called them param(s) in those games which I did not know. pretty neat) |
The intention I had going into this is that these generic params macros introduced in this PR would be used to build specific macros for individual actors as they are documented. There are already some examples of this in this PR, from actors that had already received some params documentation prior. For example #define OBJSWITCH_TYPE(thisx) PARAMS_GET((thisx)->params, 0, 3)
#define OBJSWITCH_SUBTYPE(thisx) PARAMS_GET((thisx)->params, 4, 3)
#define OBJSWITCH_SWITCH_FLAG(thisx) PARAMS_GET((thisx)->params, 8, 6)
#define OBJSWITCH_FROZEN(thisx) PARAMS_GET((thisx)->params, 7, 1) And then uses the specific macros. |
(on the topic of that example, Id like to standardize having overall I am okay with that approach though |
I feel like its about time to get this PR in. It will help greatly with actor documentation.
This change was not requested above in review, but I made it on my own (in communication with tharo):
I dont feel the generalized macro system needs to support this one-off use cases. It keeps the generalized system more clear to only need to worry about I tried to split my commits to make it easier to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I was kinda against this until I realized the authors have already done this for every actor, and it wasn't just a prescription for future docs to have to use. since its already been implemented though, LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approval is slightly biased since I completed the most recent set of changes. But I'm moreso approving the overall concept and initial implementation :)
@@ -6,6 +6,9 @@ | |||
|
|||
struct BgMoriHineri; | |||
|
|||
// Due to a unique access pattern, this param cannot use the generic "PARAMS_GET_U" macros | |||
#define TWISTED_HALLWAY_GET_PARAM_15(thisx) (((thisx)->params & (NBITS_TO_MASK(1) << (15))) >> ((15) - (1))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate how overwritten this is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its written in the same form as the generic macros. The point is to easily let you see the bit width and position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its also 1 of 2 cases where a custom actor-specific actor macro is needed. Imo we can figure out these edge cases another time, like when the actor is documented
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I don't find that the generic macro easy to follow logically in it's raw form. Probably more important though is that the macro isn't a proper params getter; the bit gets extracted but then you have a secondary operation "baked in" of the value being shifted into the bit 1 spot instead of bit 0 like the majority of params getters. This is an important detail that is being obfuscated by the macro, and makes it hard to follow the subsequent logic.
In this unusual instance, I feel PARAMS_GET_NOSHIFT
would be the more appropriate way to extract the value. The right shift needs to be exposed to the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw I agree with mxz here. PARAMS_GET_NOSHIFT seems better so you can explicitly show the unique shift (probably the same for en_ishi as well which seems to have the same structure). However also agree we could wait until the actors are documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can either of you write out how both cases would be used with NOSHIFT? I would be willing to change it now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#define TWISTED_HALLWAY_GET_PARAM_15(thisx) (PARAMS_GET_NOSHIFT((thisx)->params, 15, 1) >> 14)
Oh wait en_ishi is different. Don't think NOSHIFT works. My bad.
Edit: #define TWISTED_HALLWAY_GET_PARAM_15(thisx) PARAMS_GET_NOMASK(PARAMS_GET_NOSHIFT((thisx)->params, 15, 1), 14)
should also work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
en_ishi does work like #define ISHI_GET_SWITCH_FLAG_UPPER(thisx) PARAMS_GET_NOSHIFT(PARAMS_GET_NOMASK((thisx)->params, 12 - 2), 2, 4)
but they may be a bit too much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do something more like:
#define TWISTED_HALLWAY_GET_TYPE_NOSHIFT(x) PARAMS_GET_NOSHIFT(x, 15, 1)
...
this->dyna.actor.params = TWISTED_HALLWAY_GET_TYPE_NOSHIFT(this->dyna.actor.params) >> 14;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest just reverting this (to main), and we can indeed figure it out (or not) later, but not let it stop the whole thing
Creates generic params getter macros that can be built upon to create specific macros for extracting values stored in the params field.
There are unfortunately quite a number of distinct patterns that must be met, so there are 6 different getters:
The last two are very rare, are they worth having?
There is also one case that I could not turn into a macro, it was a mask by 0x33 (0b110011). Since this bit range is not continuous and all of the getter macros take a number of bits rather than the mask itself, this mask could not be constructed.