Sign in to follow this  
  • entries
    37
  • comments
    68
  • views
    46505

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

Sign in to follow this  
coldacid

289 views

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[/font]
Sign in to follow this  


2 Comments


Recommended Comments

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.

Share this comment


Link to comment
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.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now