1
\$\begingroup\$

I want to make my game-coding very flexible; so I wanted to make the game automatically load new Mobs from a folder named "mobs".

This must be only at startup; not while it's already running.

I just want to put a file with a name like "mouse.jar" (or others -> dynamic) into this folder, and the game should load it at startup.

I already saw this in "Robocode" (Robots) and "MCForge" (whole Mods), so it must be possible.

Can anyone tell me, how is it possible to load classes as resources in game at startup, regardless of the quantity?

\$\endgroup\$
2
2
\$\begingroup\$

You require three things to load code from files and do things with the types and functions defined in those modules.

  • A way to load a module from disk or memory.

  • A way to, given a module, enumerate and use the functionality present in the module.

  • A bunch of types and signatures designed to be shared between the modules, so the code has something to speak in terms of.

In C++ on Windows, you've got LoadLibrary, GetProcAddress, and function pointers/classes.

In C++ on POSIXy platforms, you've got dlopen, dlsym, and the same.

In Java you have ClassLoader, reflection, and common interfaces. The key in Java is that ClassLoader doesn't only know how to load a class by a given package name from your classpath, but can also load arbitrary .class files from file or memory.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.