Mattias Gustavsson Mage
Joined: 10 Nov 2007 Posts: 457 Location: Royal Leamington Spa, UK
|
Posted: Sun Jul 05, 2009 10:57 pm Post subject: PixieLite: My hardware abstraction code |
[quote] |
|
Lately, I've been spending quite a bit of time on cleaning up, refactoring and documenting my game engine Pixie, and I decided to break out the part which deals with platform abstraction, so that those who might be interested can have a look and see how I've done it, or even make use of it if they can. I'm certainly open to hear your views on it too, or critisism and suggestions for improvement.
The code is public domain, as usual, and my hope is that there will be additional implementations for other platforms than windows, so that it will become a nice, free foundation for anyone who wants to build their own cross-platform game engine.
It can be downloaded here:
PixeLite v 1.0
The code is well commented, and documentation is in the form of a windows help file (included in the download) as well as online:
PixeLite Online Documentation
The systems make use of basic windows functions for input/time and file access, but is using DirectX for sound and visuals. If DirectX isn't available (or fail), it will fall back on standard GDI and WMM, so it is quite a solid system, which so far seems o be working on pretty much everything, from old to new windows versions as well as in VM's and WINE on linux.
The basic idea is that you initialise the systems in your Main-function, like so:
Code: |
// Win32 Platform Includes
#include "Win32/Platform_Win32_OS.h"
#include "Win32/Platform_Win32_Time.h"
#include "Win32/Platform_Win32_Sound.h"
#include "Win32/Platform_Win32_Input.h"
#include "Win32/Platform_Win32_Screen.h"
#include "Win32/Platform_Win32_FileSystem.h"
//*** WinMain ***
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Platform abstraction systems - This is where we choose which platform components we want to use
Platform_Win32_OS* os=new Platform_Win32_OS(hInstance,lpCmdLine);
Platform::SetPlatform_OS(os);
Platform::SetPlatform_Time(new Platform_Win32_Time());
Platform::SetPlatform_Sound(new Platform_Win32_Sound(os));
Platform::SetPlatform_Input(new Platform_Win32_Input(os));
Platform::SetPlatform_Screen(new Platform_Win32_Screen(os));
Platform::SetPlatform_FileSystem(new Platform_Win32_FileSystem());
// Start the game
RunGame();
return 0;
}
|
The system is really meant as the foundation upon which to build more user-friendly systems, as I've done with the full Pixie engine, but it's certainly possible to use it directly too, and I'm thinking that it will be easier for others to port to new platforms if there's not as much code in the project.
I've included a simple test-demo thingy in the download, which shows a bunch of bouncing balls on an ugly background:
which is merely meant to illustrate how to use a couple of the systems.
If someone feels like making a Mac or Linux version of this, it would be awesome, and I'd be happy to help out with what I can :-) The chance of me making a Linux version myself is rather small, but I'll make a Mac version when the time comes when I can afford a Mac :P _________________ www.mattiasgustavsson.com - My blog
www.rivtind.com - My Fantasy world and isometric RPG engine
www.pixieuniversity.com - Software 2D Game Engine
|
|