2
\$\begingroup\$

In C++, how can one make it's game load content developped by other people?

For instance in Java you can look for jar files and load specific class from it.

\$\endgroup\$
  • \$\begingroup\$ Java cheats due to how it loads classes into the JVM and the fact that a class-loader is just another class that tells the JVM how to load classes. They don't even need to be files. C++ / C# sort of have similar things that they can import arbitrary DLLs, but there tends to be a lot of security problems associated with doing that (even though Java is the same). Generally though DLLs have a higher barrier to entry in comparison. That said, I would suggest starting with XML-style data that represents how objects behave. Check out Arcen's title Starward Rogue for an example; mind its complex. \$\endgroup\$ – Draco18s Jun 5 '17 at 20:58
  • 2
    \$\begingroup\$ Java does not "cheat" in any way, it just provides mechanism for runtime loading, as many other languages also do. The ability to load more components at runtime is considered quite important for modern programming languages (and is even available in C++, although with some barriers, as you mention). \$\endgroup\$ – Polygnome Jun 5 '17 at 21:35
  • \$\begingroup\$ There are a ton of ways to do this. It's too broad for our site's format. \$\endgroup\$ – Almo Jun 5 '17 at 22:06
  • 1
    \$\begingroup\$ Take a look into scripting languages, Virtual Machines, and the Bytecode pattern too, if you want people to be able to author mods that a player needn't fully trust to apply/install. In contrast to loading a DLL or similar, where malicious mod code could try to do nasty things to the player's computer (downloading malware, leaking personal info, mucking with files...), the virtual machine lets you lock down what the mod is allowed to access, so the worst a mod can do (if your VM is well designed) is muck with the game itself. \$\endgroup\$ – DMGregory Jun 6 '17 at 0:19
2
\$\begingroup\$

There are 2 primary approaches to this:

  1. Make your game open source. People have access to the source of the game and can make changes to the code.

  2. Design a modular game. For the modules you want to allow people to mod, for example the Game AI, provide hooks. These hooks in C++ will either be in the form of dll calls (or COM, even) to user provided C++ implementations, or by a script, such as lua. You can allow people to introduce new content, such as textures, models, levels, etc by using standardized formats (e.g. png, fbx, json, xml), or specifying the proprietary format you use.

Further information, such as how to best design such dll interfaces are usually opinion based or highly dependent on specifics.

\$\endgroup\$

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