Commit f8010d72 authored by hybrid's avatar hybrid

Changed the device creation to make more use of SIrrlichtCreationParameters....

Changed the device creation to make more use of SIrrlichtCreationParameters. This should increase maintainability and ease addition of more configurable properties. The windows devices need to be adapted still, but should compile for now...

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1369 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 93ec1e0a
......@@ -41,9 +41,6 @@ namespace irr
{
public:
//! Destructor
virtual ~IrrlichtDevice() {}
//! Runs the device.
/** Also increments the virtual timer by calling
ITimer::tick();. You can prevent this
......
This diff is collapsed.
......@@ -47,10 +47,7 @@ namespace irr
public:
//! constructor
CIrrDeviceLinux(video::E_DRIVER_TYPE deviceType,
const core::dimension2d<s32>& windowSize, u32 bits,
bool fullscreen, bool stencilbuffer, bool vsync, bool antiAlias, IEventReceiver* receiver,
Window window, const char* version);
CIrrDeviceLinux(const SIrrlichtCreationParameters& param);
//! destructor
virtual ~CIrrDeviceLinux();
......@@ -87,11 +84,9 @@ namespace irr
private:
//! create the driver
void createDriver(const core::dimension2d<s32>& windowSize,
bool vsync);
void createDriver();
bool createWindow(const core::dimension2d<s32>& windowSize, u32 bits,
Window externalWindow);
bool createWindow();
void createKeyMap();
......@@ -308,11 +303,6 @@ namespace irr
GLXContext Context;
#endif
#endif
bool Fullscreen;
bool StencilBuffer;
bool AntiAlias;
video::E_DRIVER_TYPE DriverType;
u32 Width, Height, Depth;
bool Close;
bool WindowActive;
......
......@@ -37,17 +37,10 @@ namespace irr
const char* wmDeleteWindow = "WM_DELETE_WINDOW";
//! constructor
CIrrDeviceSDL::CIrrDeviceSDL(video::E_DRIVER_TYPE driverType,
const core::dimension2d<s32>& windowSize,
u32 bits,
bool fullscreen, bool stencilbuffer, bool vsync,
bool antiAlias, IEventReceiver* receiver,
void* windowID, const char* version)
: CIrrDeviceStub(version, receiver), Depth(bits),
Fullscreen(fullscreen), Stencilbuffer(stencilbuffer), Vsync(vsync),
AntiAlias(antiAlias), Resizeable(false),
Screen((SDL_Surface*)windowID), SDL_Flags(SDL_HWSURFACE|SDL_ANYFORMAT),
Width(windowSize.Width), Height(windowSize.Height), Close(0),
CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), Resizeable(false),
Screen((SDL_Surface*)param.WindowId), SDL_Flags(SDL_HWSURFACE|SDL_ANYFORMAT),
Width(param.WindowSize.Width), Height(param.WindowSize.Height), Close(0),
WindowActive(false)
{
#ifdef _DEBUG
......@@ -56,7 +49,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(video::E_DRIVER_TYPE driverType,
// Initialize SDL... Timer for sleep, video for the obvious, and
// noparachute prevents SDL from catching fatal errors.
if ( SDL_Init( SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE ) < 0 )
if (SDL_Init( SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE ) < 0)
{
os::Printer::log( "Unable to initialize SDL!", SDL_GetError());
Close = 1;
......@@ -81,31 +74,30 @@ CIrrDeviceSDL::CIrrDeviceSDL(video::E_DRIVER_TYPE driverType,
// enable key to character translation
SDL_EnableUNICODE(1);
if ( Fullscreen )
if ( CreationParams.Fullscreen )
SDL_Flags |= SDL_FULLSCREEN;
if (driverType == video::EDT_OPENGL)
if (CreationParams.DriverType == video::EDT_OPENGL)
SDL_Flags |= SDL_OPENGL;
else
SDL_Flags |= SDL_DOUBLEBUF;
// create window
if (driverType != video::EDT_NULL)
if (CreationParams.DriverType != video::EDT_NULL)
{
// create the window, only if we do not use the null device
createWindow(driverType);
createWindow();
}
// create cursor control
CursorControl = new CCursorControl(this);
// create driver
createDriver(driverType, windowSize);
createDriver();
if (VideoDriver)
createGUIAndScene();
}
//! destructor
CIrrDeviceSDL::~CIrrDeviceSDL()
{
......@@ -115,15 +107,14 @@ CIrrDeviceSDL::~CIrrDeviceSDL()
}
bool CIrrDeviceSDL::createWindow(video::E_DRIVER_TYPE driverType)
bool CIrrDeviceSDL::createWindow()
{
if ( Close )
return false;
if (driverType == video::EDT_OPENGL)
if (CreationParams.DriverType == video::EDT_OPENGL)
{
if (Depth==16)
if (CreationParams.Bits==16)
{
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
......@@ -135,12 +126,12 @@ bool CIrrDeviceSDL::createWindow(video::E_DRIVER_TYPE driverType)
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
}
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, Depth);
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, CreationParams.Bits);
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
}
if ( !Screen )
Screen = SDL_SetVideoMode( Width, Height, Depth, SDL_Flags );
Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags );
if ( !Screen )
{
os::Printer::log( "Could not initialize display!" );
......@@ -152,10 +143,9 @@ bool CIrrDeviceSDL::createWindow(video::E_DRIVER_TYPE driverType)
//! create the driver
void CIrrDeviceSDL::createDriver(video::E_DRIVER_TYPE driverType,
const core::dimension2d<s32>& windowSize)
void CIrrDeviceSDL::createDriver()
{
switch(driverType)
switch(CreationParams.DriverType)
{
case video::EDT_DIRECT3D8:
case video::EDT_DIRECT3D9:
......@@ -164,7 +154,7 @@ void CIrrDeviceSDL::createDriver(video::E_DRIVER_TYPE driverType,
case video::EDT_SOFTWARE:
#ifdef _IRR_COMPILE_WITH_SOFTWARE_
VideoDriver = video::createSoftwareDriver(windowSize, Fullscreen, FileSystem, this);
VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
#else
os::Printer::log("No Software driver support compiled in.", ELL_ERROR);
#endif
......@@ -172,7 +162,7 @@ void CIrrDeviceSDL::createDriver(video::E_DRIVER_TYPE driverType,
case video::EDT_BURNINGSVIDEO:
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
VideoDriver = video::createSoftwareDriver2(windowSize, Fullscreen, FileSystem, this);
VideoDriver = video::createSoftwareDriver2(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
#else
os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);
#endif
......@@ -180,14 +170,14 @@ void CIrrDeviceSDL::createDriver(video::E_DRIVER_TYPE driverType,
case video::EDT_OPENGL:
#ifdef _IRR_COMPILE_WITH_OPENGL_
VideoDriver = video::createOpenGLDriver(windowSize, Fullscreen, Stencilbuffer, FileSystem, Vsync, AntiAlias);
VideoDriver = video::createOpenGLDriver(CreationParams.WindowSize, CreationParams.Fullscreen, CreationParams.Stencilbuffer, FileSystem, CreationParams.Vsync, CreationParams.AntiAlias);
#else
os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
#endif
break;
case video::EDT_NULL:
VideoDriver = video::createNullDriver(FileSystem, windowSize);
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
break;
default:
......@@ -388,7 +378,7 @@ void CIrrDeviceSDL::setResizeAble(bool resize)
else
SDL_Flags &= ~SDL_RESIZABLE;
SDL_FreeSurface(Screen);
Screen = SDL_SetVideoMode( Width, Height, Depth, SDL_Flags );
Screen = SDL_SetVideoMode( Width, Height, CreationParams.Bits, SDL_Flags );
Resizeable = resize;
}
}
......@@ -543,17 +533,7 @@ void CIrrDeviceSDL::createKeyMap()
IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(const SIrrlichtCreationParameters& param)
{
CIrrDeviceSDL* dev = new CIrrDeviceSDL(
param.DriverType,
param.WindowSize,
param.Bits,
param.Fullscreen,
param.Stencilbuffer,
param.Vsync,
param.AntiAlias,
param.EventReceiver,
param.WindowId,
param.SDK_version_do_not_use);
CIrrDeviceSDL* dev = new CIrrDeviceSDL(param);
if (dev && !dev->getVideoDriver() && param.DriverType != video::EDT_NULL)
{
......
......@@ -26,11 +26,7 @@ namespace irr
public:
//! constructor
CIrrDeviceSDL(video::E_DRIVER_TYPE deviceType,
const core::dimension2d<s32>& windowSize, u32 bits,
bool fullscreen, bool stencilbuffer, bool vsync,
bool antiAlias, IEventReceiver* receiver,
void* windowID, const char* version);
CIrrDeviceSDL(const SIrrlichtCreationParameters& param);
//! destructor
virtual ~CIrrDeviceSDL();
......@@ -156,19 +152,13 @@ namespace irr
private:
//! create the driver
void createDriver(video::E_DRIVER_TYPE driverType,
const core::dimension2d<s32>& windowSize);
void createDriver();
bool createWindow(video::E_DRIVER_TYPE driverType);
bool createWindow();
void createKeyMap();
s32 MouseX, MouseY;
u32 Depth;
bool Fullscreen;
bool Stencilbuffer;
bool Vsync;
bool AntiAlias;
bool Resizeable;
SDL_Surface* Screen;
......
......@@ -17,10 +17,10 @@ namespace irr
{
//! constructor
CIrrDeviceStub::CIrrDeviceStub(const char* version, IEventReceiver* recv)
CIrrDeviceStub::CIrrDeviceStub(const SIrrlichtCreationParameters& params)
: IrrlichtDevice(), VideoDriver(0), GUIEnvironment(0), SceneManager(0),
Timer(0), CursorControl(0), UserReceiver(recv), Logger(0), Operator(0),
FileSystem(io::createFileSystem()), InputReceivingSceneManager(0)
Timer(0), CursorControl(0), UserReceiver(params.EventReceiver), Logger(0), Operator(0),
FileSystem(0), InputReceivingSceneManager(0), CreationParams(params)
{
Timer = new CTimer();
if (os::Printer::Logger)
......@@ -37,11 +37,12 @@ CIrrDeviceStub::CIrrDeviceStub(const char* version, IEventReceiver* recv)
os::Printer::Logger = Logger;
FileSystem = io::createFileSystem();
core::stringc s = "Irrlicht Engine version ";
s.append(getVersion());
os::Printer::log(s.c_str(), ELL_INFORMATION);
checkVersion(version);
checkVersion(params.SDK_version_do_not_use);
}
......
......@@ -7,6 +7,7 @@
#include "IrrlichtDevice.h"
#include "IImagePresenter.h"
#include "SIrrCreationParameters.h"
#include "CVideoModeList.h"
namespace irr
......@@ -52,7 +53,7 @@ namespace irr
public:
//! constructor
CIrrDeviceStub(const char* version, IEventReceiver* resv);
CIrrDeviceStub(const SIrrlichtCreationParameters& param);
//! destructor
virtual ~CIrrDeviceStub();
......@@ -114,12 +115,13 @@ namespace irr
scene::ISceneManager* SceneManager;
ITimer* Timer;
gui::ICursorControl* CursorControl;
video::CVideoModeList VideoModeList;
IEventReceiver* UserReceiver;
CLogger* Logger;
IOSOperator* Operator;
io::IFileSystem* FileSystem;
scene::ISceneManager* InputReceivingSceneManager;
video::CVideoModeList VideoModeList;
SIrrlichtCreationParameters CreationParams;
};
} // end namespace irr
......
......@@ -283,10 +283,9 @@ CIrrDeviceWin32::CIrrDeviceWin32(video::E_DRIVER_TYPE driverType,
bool stencilbuffer, bool vsync,
bool antiAlias,
bool highPrecisionFPU,
IEventReceiver* receiver,
HWND externalWindow,
const char* version)
: CIrrDeviceStub(version, receiver), HWnd(0), ChangedToFullScreen(false),
const SIrrlichtCreationParameters& params)
: CIrrDeviceStub(param), HWnd(0), ChangedToFullScreen(false),
FullScreen(fullscreen), IsNonNTWindows(false), Resized(false),
ExternalWindow(false), Win32CursorControl(0)
{
......@@ -938,9 +937,8 @@ IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(
parameters.Vsync,
parameters.AntiAlias,
parameters.HighPrecisionFPU,
parameters.EventReceiver,
reinterpret_cast<HWND>(parameters.WindowId),
parameters.SDK_version_do_not_use);
parameters);
if (dev && !dev->getVideoDriver() && parameters.DriverType != video::EDT_NULL)
{
......
......@@ -26,9 +26,8 @@ namespace irr
core::dimension2d<s32> windowSize, u32 bits,
bool fullscreen, bool stencilbuffer, bool vsync,
bool antiAlias, bool highPrecisionFPU,
IEventReceiver* receiver,
HWND window,
const char* version);
const SIrrlichtCreationParameters& params);
//! destructor
virtual ~CIrrDeviceWin32();
......
......@@ -282,10 +282,9 @@ CIrrDeviceWinCE::CIrrDeviceWinCE(video::E_DRIVER_TYPE driverType,
bool stencilbuffer, bool vsync,
bool antiAlias,
bool highPrecisionFPU,
IEventReceiver* receiver,
HWND externalWindow,
const char* version)
: CIrrDeviceStub(version, receiver), HWnd(0), ChangedToFullScreen(false),
const SIrrlichtCreationParameters& params)
: CIrrDeviceStub(params), HWnd(externalWindow), ChangedToFullScreen(false),
FullScreen(fullscreen), Resized(false),
ExternalWindow(false), Win32CursorControl(0)
{
......@@ -303,7 +302,7 @@ CIrrDeviceWinCE::CIrrDeviceWinCE(video::E_DRIVER_TYPE driverType,
#endif
// create the window, only if we do not use the null device
if (driverType != video::EDT_NULL && externalWindow==0)
if (driverType != video::EDT_NULL && HWnd==0)
{
const wchar_t* ClassName = L"CIrrDeviceWinCE";
......@@ -361,7 +360,6 @@ CIrrDeviceWinCE::CIrrDeviceWinCE(video::E_DRIVER_TYPE driverType,
// attach external window
if (externalWindow)
{
HWnd = externalWindow;
RECT r;
GetWindowRect(HWnd, &r);
windowSize.Width = r.right - r.left;
......@@ -789,9 +787,8 @@ IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(
parameters.Vsync,
parameters.AntiAlias,
parameters.HighPrecisionFPU,
parameters.EventReceiver,
reinterpret_cast<HWND>(parameters.WindowId),
parameters.SDK_version_do_not_use);
parameters);
if (dev && !dev->getVideoDriver() && parameters.DriverType != video::EDT_NULL)
{
......
......@@ -30,9 +30,8 @@ namespace irr
core::dimension2d<s32> windowSize, u32 bits,
bool fullscreen, bool stencilbuffer, bool vsync,
bool antiAlias, bool highPrecisionFPU,
IEventReceiver* receiver,
HWND window,
const char* version);
const SIrrlichtCreationParameters& params);
//! destructor
virtual ~CIrrDeviceWinCE();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment