Advertisement

dlls, why use them?

Started by February 18, 2000 02:15 PM
4 comments, last by Ridcully 25 years ago
i have been messing around with several approaches to create a 2d game engine and repeatedly heard the concept of using custom DLLs. now i don''t quite understand what the advantage of using them is.. do you encapsulate, for example, the sound totally into one dll or just load some functions you often need from it? thanks ridcully
This should make it clear why DLL''s are very powerful.

void LoadSeenRender( int nRenderToUse )
{
if(USE_OPENGL == nRenderToUse)
{
m_hRender = LoadLibrary( "OpenGLRender.dll" );
}
else if(USE_D3D == nRenderToUse)
{
m_hRender = LoadLibrary( "D3DRender.dll" );
}
m_pfnSeenRenderer = GetPrcoAddress( m_hRender, "SceanRender");
}

void RenderTheSeen( CSeanData * pSeenData )
{
(*m_pfnSeenRenderer)( pSeenData );
}

This is simplified but I think you will see what makes DLL''s so useful.
Advertisement
One other advantage is that if your program is made up of a bunch of dll''s, it''s much easier to upgrade/patch, for the end user. If your code is a single 3 MB executable and there''s a bug in two spots, you''re stuck downloading a 3MB file. If those two bugs were in different dlls you''d download two significantly smaller dlls.
I too am writing a 2D game engine. There are two ways to do this.

1) Make the game that uses your engine an executable, and have it use your engine, a library. Your library could be linked either as a static library (*.lib) or a dynamic library (*.dll). A static library would increase the size of the game .exe, whereas a dynamic library would require the user to have both the DLL and the game EXE.

If the engine is big, and it''s likely someone will have many games using it, it''s better to make it a DLL, so they only have to download the DLL once, and then the EXEs that use it would be small.

2) Make the engine a .EXE, and make the games that use it DLLs. This is the way professional games work like Half-Life, Quake 2, etc. The add-on games are DLLs, containing functions that the engine calls.

~CGameProgrammer( );

~CGameProgrammer( ); Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
thanks for the answers!
i implemented the second method CGameProgrammer mentioned, and it works really fine!
i really want to learn as much as possible about professional games programming because i want to do that for a living later... (and prolly earn money )
I want to mention that the fact CGameProgrammer mentions is not right. ID''s games are not the only games to be called professional. In fact, the Quake engine is the only one I know to have the engine in a .EXE and the game content in a DLL. Other current and coming games like UT or Black&White (believe me, I worked on it...) have the game content in a .EXE and use extern libraries.
It offers the same options as the other way. For an addon you just compile another .EXE with no content which uses the DLLs of the previous game.
You see, just a matter of taste...

HTH,
Alexander Stockinger aka DaJudge
Software Developer

This topic is closed to new replies.

Advertisement