AEModernMCPort / Applied-Energistics-3-Fork

A Minecraft Mod about Matter, Energy and using them to conquer the world..
http://ae-mod.info/
Other
37 stars 12 forks source link

Module loading improvements #101

Closed JoJoDeveloping closed 8 years ago

JoJoDeveloping commented 8 years ago

Modules are topologically sorted and only loaded when their dependency tree is valid. Added some doc too.

JoJoDeveloping commented 8 years ago

Going to do this. PS: Do I have to reject my PR and add a new or how do I update this PR?

Elix-x commented 8 years ago

You just push new commits to same branch and they will be automatically adde to PR.

JoJoDeveloping commented 8 years ago

Ok. I think that your "loading modifiers" are somewhat strage named ("required" has to be there, "force" makes it a required one), so I would change them to "soft" for soft-dependency, and always throw an error when a hard-dependeny misses because a missing hard dependency will produce a crash somewhere one way or another. Also, ordering only affects the core modules because forge is responsible for calling onPre-/Post-/Init of external @Mod modules, so should I leave ordering to them (via @Mod(dependency="...after..")?

Elix-x commented 8 years ago

I think that your "loading modifiers" are somewhat strage named ("required" has to be there, "force" makes it a required one), so I would change them to "soft" for soft-dependency, and always throw an error when a hard-dependeny misses because a missing hard dependency will produce a crash somewhere one way or another.

In this case, specifying only required will not load the module if it is not loaded.

Also, ordering only affects the core modules because forge is responsible for calling onPre-/Post-/Init of external @Mod modules, so should I leave ordering to them (via @Mod(dependency="...after..")?

Then how do you force loading of worldgen after core? Neither is @Mod and order is very important. Hardcoding core to load before everything is no-go.

JoJoDeveloping commented 8 years ago

Then how do you force loading of worldgen after core? Neither is @Mod and order is very important. Hardcoding core to load before everything is no-go.

I meant internal modules, aka non-@Mod-modules.

In this case, specifying only required will not load the module if it is not loaded.

I still cannot make sense of your syntax. "required" is required to make it check whether this is a valid dependency, just putting eg "server:module-core" will throw an error, you have to use "required-server:module-core". I also wonder how soft-dependency would be possible, there is no modifier yet to describe that.

Elix-x commented 8 years ago

I meant internal modules, aka non-@Mod-modules.

And i was speaking about them too.

Elix-x commented 8 years ago

Ok, let me explain modifiers to you as i meant them: 3 "layers" of modifiers which are processed in lnhp (lower number higher priority)</sup> order:

  1. Layer:
    • Required: marks this part as hard dependency on other thing, specified in value.
      1. Layer:
    • Side: specified side. Can be used with 1st modifier to restrict it. Can be used alone to mark module to be loaded only in specified side.
      1. Layer:
    • Force: Forces higher priority modifiers. Could also be called crash - crashes gqame if conditions aren't met.

3 types of dependencies: -"Hard hard": crash if not loaded (required-force) -"Soft hard": not load if not loaded (required) -Soft: soft? Call AppEng.getInstance().getModule(name) != null whenever needed. We can add a method called isLoaded(name).

JoJoDeveloping commented 8 years ago

And i was speaking about them too.

core will be loaded before worldgen because both are internal modules whose init functions are called by AppEng.java. Other modules are loaded by forge and we cannot easily affect their load order, so any ordering statements there will have no effect. This means external modules have to declare their ordering themselves in @Mod.

Ok, let me explain modifiers to you as i meant them: 3 "layers" of modifiers which are processed in lnhp (lower number higher priority) order:

  1. Layer:
Required: marks this part as hard dependency on other thing, specified in value.
    Layer:
Side: specified side. Can be used with 1st modifier to restrict it. Can be used alone to mark module > to be loaded only in specified side.
    Layer:
Force: Forces higher priority modifiers. Could also be called crash - crashes gqame if conditions aren't met.

3 types of dependencies: -"Hard hard": crash if not loaded (required-force) -"Soft hard": not load if not loaded (required) -Soft: soft? Call AppEng.getInstance().getModule(name) != null whenever needed. We can add a method called isLoaded(name).

I would use modifiers like "hard", "soft", alongside "client"/"server", and "crash" to be combined with "hard". Additionally there is "after" if I can fit it into the sorting process somehow.

Elix-x commented 8 years ago

core will be loaded before worldgen because both are internal modules whose init functions are called by AppEng.java.

You cannot ensure that currently. If you find worldgen module first, it will be before core in the list and will be loaded before. That's why we need load order sorting.

Additionally there is "after" if I can fit it into the sorting process somehow.

We need both before and after modifiers.

This means external modules have to declare their ordering themselves in @Mod.

That's true. dependency field will simply change nothing with load order for external modules in this case.

I would use modifiers like "hard", "soft", alongside "client"/"server", and "crash" to be combined with "hard".

TMM (Too Many Modifiers) Time???

JoJoDeveloping commented 8 years ago

I made it so that specifying "before" means the module is loaded before its dependency and not specifying means it is loaded after its dependency. There are only to cases (before and after the dependency) so I made the more convenient (after your dependency) the default case.

Elix-x commented 8 years ago

(after your dependency) the default case.

Not logical. Order not specified should mean that it is not specified and can load at any position, otherwise this will cause loops.

As for sorting, look at how Forge sorts mods. Maybe implement similar system.

JoJoDeveloping commented 8 years ago

They build a sophisticated Graph and then add nodes to it. I'll look into tomorrow (I'm at UTC+2, aka MEST) and probably use the same class so that the "loaded classes footprint" is kept minimal.

Elix-x commented 8 years ago

Ok. And don't worry, i'm also somewhere in UTC+?... And don't know what MEST is :D ...

JoJoDeveloping commented 8 years ago

MEST = Middle european summer time. Also, do we need mods to be before/after everything (thinking of "core"), because forge supports it.

JoJoDeveloping commented 8 years ago

Whoops, forget to un-import the ModuleHelper. Will dobit next commit.

Elix-x commented 8 years ago

External addons, will all have to either load before all internal AE modules or after internal AE modules. If we ever decide to API modules system somehow, they will have more fine control.

Elix-x commented 8 years ago

Please rebase.