Contribute to the LWJGL open collective
General Java Game Development
January 23, 2017, 04:20:44 »
I have a game engine that I've created and also a separate physics library specifically for racing physics. The game developer using these libraries will make a game both dependent on the engine and the physics library. The tricky part is that the physics library is also dependent on the engine and the engine library used by the physics library must be the exact same library as the one used by the game. By exact same I mean that if I modify a variable through the engine from the game, the physics library will reflect that change. If anyone knows how to implement a system like this, your help would be greatly appreciated.
Re: Multi-level dependencies
Reply #1 on:
January 23, 2017, 08:28:04 »
You don't have to do anything for that to work, regardless of whether the game engine and the physics engine use same classes (by name) and/or static class fields in same classes.
First: There is no such thing as a "library" when the JVM starts up. It will just search for classes by name when during execution, starting with the main method, it sees that another class is needed.
Second: The JVM searches in all .jar files (not necessarily the boundary of a library) and file system directories specified in the classpath/cp VM argument to find the .class file of a requested class to load it. Whenever there are multiple locations containing the same .class file, then the first location (specified in the classpath/cp) will be used.
Third: The JVM and its classloader hierarchy (you likely only use the system class loader) takes care that the same class referenced in different locations/classes will always be "the same"/identical class. And therefore, when a class in your physics engine references a static field of the engine and the game also references the same field in the engine, then it will be the same/identical field.
Last Edit: January 23, 2017, 17:27:30 by Kai
SMF © 2014