DLL loading for an engine?

Started by
14 comments, last by FxMazter 20 years, 3 months ago
Why don''t you just compile into .lib/.a libraries. These act like a dll, but are compiled within the executable. It allows you to work in the same way as a dll (keeping different pieces of code seperated) but less easier to hack (dll calls could be intercepted, hacked, etc; dlls would make your game easily cheatable/patchable).

"My basic needs in life are food, love and a C++ compiler"
[Project AlterNova] [Novanet]
[www.LifeIsDigital.net - My open source projects and articles.
Advertisement
quote:Original post by Vich
Why don''t you just compile into .lib/.a libraries. These act like a dll, but are compiled within the executable. It allows you to work in the same way as a dll (keeping different pieces of code seperated) but less easier to hack (dll calls could be intercepted, hacked, etc; dlls would make your game easily cheatable/patchable).


Because then he only has to change and redistribute a single DLL as opposed to the whole app.

there is a difference between "planning ahead" and "over-engineering".

thinking up concepts like a "dll loader" is (in *most* cases) definitely overkill. what about a "function caller" or a "pointer storer" or a "variable holder"... you get the point.
What I would do is make abstract interfaces (pure virtual classes) for each class I want pluggable. Each DLL would be required to provide a common getInstance() function. Then I would use a config file (lua script, ini file, text file, whatever) to configure which interfaces point to which DLL. When the dlls are loaded, you point the appropriate functions (newRenderer(), for example) to the newInstance funciton of the DLL.

So at the very least you would only need ti call one function from the game to load the DLLs and set up the function pointers, and possible a mechanism for switching out the dlls at runtime. There''s no need to make a DLLManager class, really. The publically available functions could be global (or wrapped in a namespace) and all of the dll handles could be local static variables in that source module.

Of course, you could go further and have all of the pluggable interfaces inherit from a common base class (IPluggable for example), but unless your needs are super generic, that wouldn''t make much sense. For example, you would never load a Scenegraph in place of a Renderer. So it makes much better sense to have all of the newInstance functions return a pointer to the appropriate interface (IRenderer, IScengraph) rather than an IPluggable.

If your game does not require all of the interfaces to be loaded, then the only complexity you have to deal with is deciding which are required, and guarding against trying to get an instance of an interface that has not been loaded. It''s a safe bet that an IRenderer and an IScengraph will be required, but an IAudio might not be. So you might want something like this:

typedef IAudio *(* NEWAUDIO)();static HANDLE s_audioDLL;static NEWAUDIO s_newAudio = NULL;static void loadAudio(const char *name){   s_audioDLL = LoadLibrary(name);   s_newAudio = GetProcAddress(audioDLL, "newInstance");}// global InitPlugIns functionbool initPlugins(){   // parse the config file, ensure required plugins are loaded,   // load optional plugins   ...   char *audioName = ConfigGetValue("IAudio");   loadAudio(audioName);   return true;}// global NewAudio functionIAudio *NewAudio(){   if(NULL != s_newAudio)      return s_newAudio();}


Simple. And again, a more generic, flexible system could be designed - but if you don''t really need a more flexible or generic system then it''s overkill.
Depends what systems are likely to change. In my game engine, the DLL''d systems are Game and Render (and soon to be sound if I get round to doing sound, heh). The rest of them are bundled in the exe as I deemed that making them pluggable had no real advantage.
Thank you Aldacron, thats somewhat the kind of posts I was hoping for

And currently my system works similar to the one you described, but it all happens in my SystemManager.

I have looked at the OGRE engine and also noticed that they have their dllloading functions global as you described it. So that may be a good way of doing it

But hence, I have already made the SystemManager and the SystemEnumerator... so I think I''m gonna let it be as it is, heh

Thank you guys for the posts anyway

This topic is closed to new replies.

Advertisement