Adding Games Through DLL
Im working on a gaming client and I want to be able to add games to the client through dlls. For example to add a game to the client all the user needs to do is load the appropriate dll and you can play pac man. The game client would be using OpenGl and SDL so I need to run graphics,input and sound functions from dlls.
why would it be a dll? could it be a file format of its own that they can just plug in ?
i think you need to tell us a bit more about what you have and what your wanting to do.
i think you need to tell us a bit more about what you have and what your wanting to do.
Quote:Original post by Supaflyfrank
Im working on a gaming client and I want to be able to add games to the client through dlls. For example to add a game to the client all the user needs to do is load the appropriate dll and you can play pac man. The game client would be using OpenGl and SDL so I need to run graphics,input and sound functions from dlls.
Uhm, Okay. And your question is ?
I believe what you're looking for is Runtime Linking. You could dynamically load the game's DLL, then call a specific function from the DLL (say, "game_main") to act as a starting point for the game similar to the "main" function in C/C++.
From a design perspective your core client could contain an interface pointer for example IPlugIn which has methods such as IPlugIn::Run(). When the DLL is loaded at runtime your core application would then obtain a handle to an object within the DLL which inherits from the IPlugIn class:
class CPacMan : public IPlugIn
{
};
So, your core client would execute the basic steps below:
1) Create a pointer of type IPlugIn
2) Load the DLL
3) Call into the DLL to return a pointer to a function to create the object (you can't just export the class)
4) Call the Run() method on the returned object and have the DLL handle all game logic
This of course isn't perfect but just something to think about if nothing else.
class CPacMan : public IPlugIn
{
};
So, your core client would execute the basic steps below:
1) Create a pointer of type IPlugIn
2) Load the DLL
3) Call into the DLL to return a pointer to a function to create the object (you can't just export the class)
4) Call the Run() method on the returned object and have the DLL handle all game logic
class IPlugIn{public: IPlugIn( void ); virtual ~IPlugIn( void ); virtual void Run( void ) == 0;};// this would be defined in your DLL__declspec( dllexport ) CPacMan* CrateLogic( void ){ return new CPacMan();}// so would thisclass CPacMan : public IPlugIn{ CPacMan( void ); virtual ~CPacMan( void ); virtual void Run( void );};int main( void ){ // define a pointer to the IPlugIn interface IPlugIn* pGameLogic; // go through all your steps here to load the DLL of choice // obtain a handle to the DLLs "CreateLogic" method for example // obtain a pointer to the CPacMan object pGameLogic = (IPlugIn*)(DLL function here) // run the logic pGameLogic->Run();};
This of course isn't perfect but just something to think about if nothing else.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement