Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by jblouir

I am having issues with module loading order. I ran into some circular dependency issues, and decided to create a module called "gameincludes" that has a requires block containing all modules that I require for the game to run. For some reason I am getting some errors regarding ig.Entity being undefined.

What I would like to know is, is the module list inside of the "requires" block, guaranteed order? i.e, in the below example, will impact.game load before impact.font which will load before 'game.namespace.gameincludes'?

in my main.js

ig.module( 
	'game.main' 
)
.requires(

'impact.game',
'impact.font',
'game.namespace.gameincludes')

##

1 decade ago by jblouir

As a side note, I removed all "requires" blocks from all the modules inside of 'game.namespace.gameincludes', because if the include order is correct in 'game.namespace.gameincludes' then it shouldnt matter that the modules inside there need to require anything, this would make my life a lot simpler as I only have to worry about including the right files in the all inclusive includes module 'game.namespace.gameincludes'.

1 decade ago by jblouir

Including 'impact.entity' inside of the correct modules inside of 'game.namespace.gameincludes' fixed the error, considering 'impact.game' requires 'impact.entity' and this is in the requires list in the main game before my includes module 'game.namespace.gameincludes', this doesnt make sense to me.

To me this "requires" block should be, for each item in the requires list, loading their required modules then execute the defines function, in order from top to bottom, like a recursive loop.

But it looks like this order is not guaranteed, which makes everything very confusing.

It seems that if I want to do this, I have to be aware of dependencies at the point of definition, and those at the point of execution.

I cant determine order at the point of definition, so anything that is executed inside of the "defines" block must be put into the "requires" list for that module.

If I have dependencies in executed code, its fine as long as none of that code is executed before the games main init method is run.

This can happen if, for example, you have chosen to create your own namespace with some static enums or singletons that are accessed by executed code.

1 decade ago by jblouir

But if you want to define a namespace, that is created inside of a module, for example, "mygamenamspace", that is required by other modules, it is necessary to put the "namespace module" in the requires block of all code that requires it inside of the defines block.

I personally feel this is a bit heavy, there are tons of repetition when writing .requires blocks, if anyone has any ideas about how to avoid needing to add these requirements to each module I am open to suggestions.

1 decade ago by jblouir

Ok, if the only thing guaranteed is that all modules in a requires block will be loaded before the defines is called, then the only way to guarantee order, is to have nested includes modules.

(by includes module I mean a module with just "requires" items and no "defines" block. Its only purpose being to trigger the loading of other modules)

for example

namespaceincludesmodule requires the namespace module
enumsincludesmodule require namespaceincludesmodule and the enum modules
otherincludesmodule require enumsincludesmodule and other modules etc
...n

this feels like hackery, which is a shame.

1 decade ago by jblouir

Best Solution:

Keep a global includes module, so everything is guaranteed to be loaded.

But anywhere you need to have something included at definition time inside of the defines block, these must be put into the requires list, it should be quite easy to make code templates for these in whatever editor you use.

1 decade ago by FelipeBudinich

Thanks very much for documenting your process, I was running into a very similar issue.
Page 1 of 1
« first « previous next › last »