First there was one, then there were two...

Published July 13, 2006
Advertisement
And now, there are three.

Three what? Three projects comprising Asylum itself. In the beginning, Asylum was monolithic, a single asylum.exe that held all the game code. Then, I spun the engine out from the game, giving me asylum.exe and asylum.dll. Today, I spun the platform-specific code from the engine, which now rests in asylum.exe, while the engine code is in engine.dll. The file formerly known as asylum.dll is now asylum/game.dll and game resources now share a folder with it.

Why did I do this? Because I needed a way to provide services to the game DLL from the engine, without going through callback hell. So, now asylum.exe calls game_main in engine.dll, passing along a struct of function pointers (well, virtual functions) as well as argc and argv. (For Win32 I've had to chop WinMain's lpCmdLine to make argc and argv. I'd show how, but there's more than enough code out on the internet that already demonstrates it.) The game DLL depends on the engine DLL (implicit dynamic linking) while the engine DLL is only interested in what the game DLL registers with it (game states, entities, etc). The engine DLL depends on the executable (reverse explicit dynamic linking -- that means that the executable calls LoadLibrary or dlopen on the DLL rather than the other way around) and when the engine's entry point, game_main, is called, it gets from the executable what it needs.

So far there's pretty much no platform specific code in engine.dll or game.dll, so to get Asylum building on other platforms all I need is to implement the platform specific side of things (getLibraryHandle, getLibraryFunction, getDirectoryPath, etc) and pass along control to game_main. Easier done than said.

Asylum stats:
[font="Courier New"]Total lines of code: 5536
Source files: 77 (doesn't count pch related files or resource files)

Mean lines/file: 71.89610
Median lines/file: 50
Mode lines/file: 32

Most lines: 343
Least lines: 17
0 likes 2 comments

Comments

Anon Mike
Quote:Original post by coldacid
(For Win32 I've had to chop WinMain's lpCmdLine to make argc and argv. I'd show how, but there's more than enough code out on the internet that already demonstrates it.)


For VC you can just use the global variables __argc and __argv. There's also a __wargv for Unicode as well but in my simple test it didn't work and MSDN is not cooperating. There is also CommandLineToArgvW which should work with any Win32 compiler. It's Unicode only.
July 14, 2006 04:27 PM
coldacid
Well, too late for that now. I needed to do something similar with a std::string in the console too, so platform-specific ways of doing this were out of the question anyway.
July 15, 2006 01:06 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement