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

Initial event api, license headers #9

Merged
merged 20 commits into from
Jul 22, 2021
Merged

Conversation

i509VCB
Copy link
Contributor

@i509VCB i509VCB commented Jul 7, 2021

The first task here is the new event api for using with QSL. It is quite similar to the api fabric has minus some slight semantic differences and names.

one thing needs to be done before I merge this

  • Setup license headers

Copy link
Member

@TheGlitch76 TheGlitch76 left a comment

Choose a reason for hiding this comment

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

I don't think that copy-pasting Fabric classes is the right way to do this at all. It was not sustainable for Patchwork and I don't want to support that approach here.

Maintaining a fork of Fabric API with the implementation modified to wrap around QSL is infinitely more maintainable because we can merge upstream and keep track of when they change things.

We're not assuming that anything in QSL is considered stable, so it is OK to create Fabric's APIs again almost verbatim (name style changing as needed) until we determine what changes we want.

@i509VCB
Copy link
Contributor Author

i509VCB commented Jul 7, 2021

Hmm glitch that seems more reasonable tbf. However I'd want a few conditions:

Our backend reimplementation of fabric api MUST depend on a fixed version of QSL. Reason being I'll need to expose some internal compat bridges.

@TheGlitch76
Copy link
Member

TheGlitch76 commented Jul 7, 2021

Whatever you need--it's easier to change those kinds of things with experimentation, but it would be hard to lift FAPI out of QSL into a fork at a later date, so that's what's important to me.

@i509VCB i509VCB marked this pull request as ready for review July 13, 2021 05:24
@i509VCB
Copy link
Contributor Author

i509VCB commented Jul 13, 2021

Ready for review. Grammar checking especially.

Note the api is not final yet.

@i509VCB i509VCB requested review from TheGlitch76 and a team July 13, 2021 05:24
@Documented // Documentation
@Retention(RetentionPolicy.CLASS) // For static analysis
@Target({ ElementType.FIELD, ElementType.METHOD })
public @interface ParameterInvokingEvent {
Copy link
Contributor

Choose a reason for hiding this comment

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

That annotation name is still super obscure, at least the doc is clear.

Choose a reason for hiding this comment

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

Do you have a better idea?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sadly, no.
I don't think this can be named in a clear way anyway, and this is the best name so far.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Writing the documentation is probably the best way to communicate what the annotation does.

Choose a reason for hiding this comment

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

ParameterImplementedEvent would be more clear to me, but at this point the documentation is good enough at describing its function that the name probably doesn't matter 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah the age old naming question.

We could go for a more Gradle-like naming scheme with something like InvokesParameterAsCallback for a name.

@Technici4n
Copy link

I'm not sure why you're randomly changing some names (besides ParameterInvokingEvent which is a fine rename). implementation for example is really confusing. And fallback instead of empty is worse as well imo.

@i509VCB
Copy link
Contributor Author

i509VCB commented Jul 13, 2021

Fallback vs empty I'd be fine changing with some discussion.

Implementation was an intentional choice since I have interpreted an Event as a holder object for a generated implementation of T. In the case of an array event, T is implemented via multiple callbacks that implement T.

*
* @param callback the callback.
*/
public abstract void register(T callback);
Copy link

@Haven-King Haven-King Jul 13, 2021

Choose a reason for hiding this comment

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

If we wanted to add callback IDs and dependencies, now would be the time to do it. The signature of register would then be something like

/**
	 * Register a callback to the event.
	 *
     * @param id the identifier of this listener
	 * @param callback the callback
	 * @param after an array of identifiers this callback needs to be run after, if they are present
	 */
public abstract void register(Identifier id, T callback, Identifier... after);

This can fairly easily be implemented in a way that does not impact invocation-time performance. It does not solve all possible problems that might arise from invoker order, but it does offer one more (relatively pain free) mechanism to mod developers.

It's worth noting that for the purpose of Fabric mod compatibility, any implementation needs to be capable of handling cases where id is null, invoking it at any time.

Choose a reason for hiding this comment

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

before is necessary as well.

Copy link

@Haven-King Haven-King Jul 13, 2021

Choose a reason for hiding this comment

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

before is necessary as well.

That complicates things slightly as we can no longer just use varargs, but would be fine with some overrides (and probably better method names 😛).

/**
 * Register a callback to the event.
 *
 * @param id the identifier of this listener
 * @param callback the callback
 */
public void register(Identifier id, T callback) {
  this.register(id, callback, new Identifier[0], new Identifier[0]);
}

/**
 * Register a callback to the event.
 *
 * @param id the identifier of this listener
 * @param callback the callback
 * @param before an array of identifiers this callback needs to be run before, if they are present
 */
public void registerBefore(Identifier id, T callback, Identifier... before) {
  this.register(id, callback, before, new Identifier[0]);
}

/**
 * Register a callback to the event.
 *
 * @param id the identifier of this listener
 * @param callback the callback
 * @param after an array of identifiers this callback needs to be run after, if they are present
 */
public void registerAfter(Identifier id, T callback, Identifier... after) {
  this.register(id, callback, new Identifier[0], after);
}

/**
 * Register a callback to the event.
 *
 * @param id the identifier of this listener
 * @param callback the callback
 * @param before an array of identifiers this callback needs to be run before, if they are present
 * @param after an array of identifiers this callback needs to be run after, if they are present
 */
public abstract void register(Identifier id, T callback, Identifier[] before, Identifier[] after);

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems very workable!

Though, shouldn't those T[]/T... arrays be Identifier[]/Identifier..., according to the javadocs?

Choose a reason for hiding this comment

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

This seems very workable!

Though, shouldn't those T[]/T... arrays be Identifier[]/Identifier..., according to the javadocs?

Oops, yes, I knew I missed something.

Copy link
Contributor

Choose a reason for hiding this comment

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

I know that, I was pointing out the incorrect typing on the varargs/arrays.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not fully convinced on this. Do not the API is NOT final yet

Choose a reason for hiding this comment

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

Not convinced either, as Lambda explained on discord it makes every ID a rigid part of a mod's API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot of a compromise I might accept for int priorities given some surrounding conditions:

https://media.discordapp.net/attachments/522124386128494599/865243382997844008/Screenshot_20210715-094323_Discord.jpg

Haven seems to be on the other side of the coin on identifiers, I do note that identifiers have some advantages but some disadvantages that integers handle properly

changing priority ordering is an intentional act, you must have something to be ordered and know what you are ordered before.

no reordering is done given the absence of dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is now an issue for this chain: #14

Co-authored-by: LambdAurora <aurora42lambda@gmail.com>
@i509VCB
Copy link
Contributor Author

i509VCB commented Jul 14, 2021

@Technici4n returned to empty naming on the special createArrayEvent

@i509VCB i509VCB changed the title Implement Events and reimplement Fabric's Event api Initial event api Jul 15, 2021
Copy link

@Technici4n Technici4n left a comment

Choose a reason for hiding this comment

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

I think this is a good occasion to remove useless API complexity. Maybe ArrayEvent should even be inlined into Event directly.

*
* @param callback the callback.
*/
public abstract void register(T callback);

Choose a reason for hiding this comment

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

Not convinced either, as Lambda explained on discord it makes every ID a rigid part of a mod's API.

Copy link
Member

@TheGlitch76 TheGlitch76 left a comment

Choose a reason for hiding this comment

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

Mostly just some documentation clunk that needs fixed, and this shouldn't be merged until we get the vote on #10 tomorrow or so.

@TheGlitch76
Copy link
Member

I'm still unsure if we should resolve the debate of int/string/no priority before merging this PR.
We can swap it out at any time before API is stabilized, of course, but that doesn't mean we should wait until the last moment.

@Leo40Git
Copy link
Contributor

Heads up: decided package structure is org.quiltmc.qsl.$module.api/impl!

@i509VCB
Copy link
Contributor Author

i509VCB commented Jul 22, 2021

I think we are done with this.

@i509VCB i509VCB changed the title Initial event api Initial event api, license headers Jul 22, 2021
@LambdAurora LambdAurora requested a review from a team July 22, 2021 22:38
@i509VCB i509VCB merged commit 1f6a7dc into QuiltMC:1.17 Jul 22, 2021
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.

None yet

7 participants