Added generic console device. Only works with software drivers.

todo: user input from console. clean up when the task is killed. present() ASCII output would be nice! :-D

Added new files to projects

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2234 dfc29bdd-3216-0410-991c-e03cc46cb475
master
bitplane 2009-02-27 08:36:43 +00:00
parent 20657b83e3
commit 74e456a1cc
14 changed files with 394 additions and 23 deletions

View File

@ -1,3 +1,7 @@
Changes in 1.6
- Added generic console device. You can now use Irrlicht to create and manipuate graphics on a shell where no graphics hardware
or windowing system is available. To enable it uncomment #define _IRR_USE_CONSOLE_DEVICE_ in IrrCompileConfig.h
Changes in 1.6 TA
- implemented isALoadableFileFormat ( File *file ) for the Archive Loader
Changes in 1.6 TA

View File

@ -19,6 +19,7 @@
//! _IRR_OSX_PLATFORM_ for Apple systems running OSX
//! _IRR_POSIX_API_ for Posix compatible systems
//! _IRR_USE_SDL_DEVICE_ for platform independent SDL framework
//! _IRR_USE_CONSOLE_DEVICE_ for no windowing system, like for running as a service
//! _IRR_USE_WINDOWS_DEVICE_ for Windows API based device
//! _IRR_USE_WINDOWS_CE_DEVICE_ for Windows CE API based device
//! _IRR_USE_LINUX_DEVICE_ for X11 based device
@ -27,7 +28,11 @@
//! DEVICE is the windowing system used, several PLATFORMs support more than one DEVICE
//! Moreover, the DEVICE defined here is not directly related to the Irrlicht devices created in the app (but may depend on each other).
//#define _IRR_USE_SDL_DEVICE_ 1
//! Uncomment this line to compile with the SDL device instead of platform specific devices
//#define _IRR_USE_SDL_DEVICE_
//! Uncomment this line to compile as a console application with no windowing system. Hardware drivers will be disabled.
//#define _IRR_USE_CONSOLE_DEVICE_
//! WIN32 for Windows32
//! WIN64 for Windows64
@ -35,7 +40,7 @@
#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64) || defined(_WIN32_WCE)
#define _IRR_WINDOWS_
#define _IRR_WINDOWS_API_
#ifndef _IRR_USE_SDL_DEVICE_
#if !defined(_IRR_USE_SDL_DEVICE_) && !defined(_IRR_USE_CONSOLE_DEVICE_)
#define _IRR_USE_WINDOWS_DEVICE_
#endif
#endif
@ -57,7 +62,7 @@
#define MACOSX // legacy support
#endif
#define _IRR_OSX_PLATFORM_
#if !defined(_IRR_USE_LINUX_DEVICE_) // for X11 windowing declare this
#if !defined(_IRR_USE_LINUX_DEVICE_) && !defined(_IRR_USE_CONSOLE_DEVICE_)
#define _IRR_USE_OSX_DEVICE_
#endif
#endif
@ -71,7 +76,7 @@
#endif
#define _IRR_POSIX_API_
#ifndef _IRR_USE_SDL_DEVICE_
#if !defined(_IRR_USE_SDL_DEVICE_) && !defined(_IRR_USE_CONSOLE_DEVICE_)
#define _IRR_USE_LINUX_DEVICE_
#endif
#endif
@ -90,7 +95,7 @@ to the compiler settings: -DIRR_COMPILE_WITH_DX9_DEV_PACK
and this to the linker settings: -ld3dx9 -ld3dx8 **/
#if defined(_IRR_WINDOWS_API_) && (!defined(__GNUC__) || defined(IRR_COMPILE_WITH_DX9_DEV_PACK))
#define _IRR_COMPILE_WITH_DIRECT3D_8_
//#define _IRR_COMPILE_WITH_DIRECT3D_8_
#define _IRR_COMPILE_WITH_DIRECT3D_9_
#endif
@ -413,5 +418,13 @@ precision will be lower but speed higher. currently X86 only
#undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#endif
//! Remove joystick support and hardware drivers when compiling as a service
#if defined(_IRR_USE_CONSOLE_DEVICE_)
#undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#undef _IRR_COMPILE_WITH_OPENGL_
#undef _IRR_COMPILE_WITH_DIRECT3D_8_
#undef _IRR_COMPILE_WITH_DIRECT3D_9_
#endif
#endif // __IRR_COMPILE_CONFIG_H_INCLUDED__

View File

@ -127,21 +127,21 @@ namespace core
return Width*Height;
}
//! Get the optimal size according to some properties
/** This is a function often used for texture dimension
calculations. The function returns the next larger or
smaller dimension which is a power-of-two dimension
(2^n,2^m) and/or square (Width=Height).
\param requirePowerOfTwo Forces the result to use only
powers of two as values.
\param requireSquare Makes width==height in the result
\param larger Choose whether the result is larger or
smaller than the current dimension. If one dimension
need not be changed it is kept with any value of larger.
\param maxValue Maximum texturesize. if value > 0 size is
clamped to maxValue
\return The optimal dimension under the given
constraints. */
//! Get the optimal size according to some properties
/** This is a function often used for texture dimension
calculations. The function returns the next larger or
smaller dimension which is a power-of-two dimension
(2^n,2^m) and/or square (Width=Height).
\param requirePowerOfTwo Forces the result to use only
powers of two as values.
\param requireSquare Makes width==height in the result
\param larger Choose whether the result is larger or
smaller than the current dimension. If one dimension
need not be changed it is kept with any value of larger.
\param maxValue Maximum texturesize. if value > 0 size is
clamped to maxValue
\return The optimal dimension under the given
constraints. */
dimension2d<T> getOptimalSize(
bool requirePowerOfTwo=true,
bool requireSquare=false,

View File

@ -0,0 +1,179 @@
// Copyright (C) 2009 Gaz Davidson
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CIrrDeviceConsole.h"
#ifdef _IRR_USE_CONSOLE_DEVICE_
#include "os.h"
#ifdef _IRR_WINDOWS_API_
#define WIN32_LEAN_AND_MEAN
#if !defined(_IRR_XBOX_PLATFORM_)
#include <windows.h>
#endif
#else
#include <time.h>
#endif
namespace irr
{
//! constructor
CIrrDeviceConsole::CIrrDeviceConsole(const SIrrlichtCreationParameters& params)
: CIrrDeviceStub(params), IsDeviceRunning(true)
{
switch (params.DriverType)
{
case video::EDT_SOFTWARE:
#ifdef _IRR_COMPILE_WITH_SOFTWARE_
VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
#else
os::Printer::log("Software driver was not compiled in.", ELL_ERROR);
#endif
break;
case video::EDT_BURNINGSVIDEO:
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
VideoDriver = video::createSoftwareDriver2(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
#else
os::Printer::log("Burning's Video driver was not compiled in.", ELL_ERROR);
#endif
break;
case video::EDT_DIRECT3D8:
case video::EDT_DIRECT3D9:
case video::EDT_OPENGL:
os::Printer::log("The console device cannot use hardware drivers", ELL_ERROR);
break;
default:
break;
}
if (VideoDriver)
createGUIAndScene();
}
//! destructor
CIrrDeviceConsole::~CIrrDeviceConsole()
{
// GUI and scene are dropped in the stub
}
//! runs the device. Returns false if device wants to be deleted
bool CIrrDeviceConsole::run()
{
// increment timer
os::Timer::tick();
// todo: process keyboard input with cin/getch and catch kill signals
return IsDeviceRunning;
}
//! Cause the device to temporarily pause execution and let other processes to run
// This should bring down processor usage without major performance loss for Irrlicht
void CIrrDeviceConsole::yield()
{
#ifdef _IRR_WINDOWS_API_
Sleep(1);
#else
struct timespec ts = {0,0};
nanosleep(&ts, NULL);
#endif
}
//! Pause execution and let other processes to run for a specified amount of time.
void CIrrDeviceConsole::sleep(u32 timeMs, bool pauseTimer)
{
const bool wasStopped = Timer ? Timer->isStopped() : true;
#ifdef _IRR_WINDOWS_API_
Sleep(timeMs);
#else
struct timespec ts;
ts.tv_sec = (time_t) (timeMs / 1000);
ts.tv_nsec = (long) (timeMs % 1000) * 1000000;
if (pauseTimer && !wasStopped)
Timer->stop();
nanosleep(&ts, NULL);
#endif
if (pauseTimer && !wasStopped)
Timer->start();
}
//! sets the caption of the window
void CIrrDeviceConsole::setWindowCaption(const wchar_t* text)
{
// do nothing - there is no caption
}
//! returns if window is active. if not, nothing need to be drawn
bool CIrrDeviceConsole::isWindowActive() const
{
// there is no window, but we always assume it is active
return true;
}
//! returns if window has focus
bool CIrrDeviceConsole::isWindowFocused() const
{
// no way to tell, so we always assume it is
return true;
}
//! returns if window is minimized
bool CIrrDeviceConsole::isWindowMinimized() const
{
return false;
}
//! presents a surface in the client area
//! returns false on failure
bool CIrrDeviceConsole::present(video::IImage* surface, void* windowId, core::rect<s32>* src)
{
// always fails!
return false;
}
//! notifies the device that it should close itself
void CIrrDeviceConsole::closeDevice()
{
//
}
//! Sets if the window should be resizeable in windowed mode.
void CIrrDeviceConsole::setResizeAble(bool resize)
{
// do nothing
}
extern "C" IRRLICHT_API IrrlichtDevice* IRRCALLCONV createDeviceEx(
const SIrrlichtCreationParameters& parameters)
{
CIrrDeviceConsole* dev = new CIrrDeviceConsole(parameters);
if (dev && !dev->getVideoDriver() && parameters.DriverType != video::EDT_NULL)
{
dev->closeDevice(); // close device
dev->run(); // consume quit message
dev->drop();
dev = 0;
}
return dev;
}
} // end namespace irr
#endif // _IRR_USE_CONSOLE_DEVICE_

View File

@ -0,0 +1,70 @@
// Copyright (C) 2009 Gaz Davidson
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_IRR_DEVICE_CONSOLE_H_INCLUDED__
#define __C_IRR_DEVICE_CONSOLE_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_USE_CONSOLE_DEVICE_
#include "SIrrCreationParameters.h"
#include "CIrrDeviceStub.h"
#include "IImagePresenter.h"
namespace irr
{
class CIrrDeviceConsole : public CIrrDeviceStub, video::IImagePresenter
{
public:
//! constructor
CIrrDeviceConsole(const SIrrlichtCreationParameters& params);
//! destructor
virtual ~CIrrDeviceConsole();
//! runs the device. Returns false if device wants to be deleted
virtual bool run();
//! Cause the device to temporarily pause execution and let other processes to run
// This should bring down processor usage without major performance loss for Irrlicht
virtual void yield();
//! Pause execution and let other processes to run for a specified amount of time.
virtual void sleep(u32 timeMs, bool pauseTimer);
//! sets the caption of the window
virtual void setWindowCaption(const wchar_t* text);
//! returns if window is active. if not, nothing need to be drawn
virtual bool isWindowActive() const;
//! returns if window has focus
virtual bool isWindowFocused() const;
//! returns if window is minimized
virtual bool isWindowMinimized() const;
//! presents a surface in the client area
virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0);
//! notifies the device that it should close itself
virtual void closeDevice();
//! Sets if the window should be resizeable in windowed mode.
virtual void setResizeAble(bool resize=false);
private:
bool IsDeviceRunning;
};
} // end namespace irr
#endif // _IRR_USE_CONSOLE_DEVICE_
#endif // __C_IRR_DEVICE_CONSOLE_H_INCLUDED__

View File

@ -521,7 +521,6 @@ bool CIrrDeviceWin32::run()
void CIrrDeviceWin32::yield()
{
Sleep(1);
}
//! Pause execution and let other processes to run for a specified amount of time.

View File

@ -444,6 +444,8 @@
<Unit filename="CGUIFont.h" />
<Unit filename="CGUIImage.cpp" />
<Unit filename="CGUIImage.h" />
<Unit filename="CGUIImageList.cpp" />
<Unit filename="CGUIImageList.h" />
<Unit filename="CGUIInOutFader.cpp" />
<Unit filename="CGUIInOutFader.h" />
<Unit filename="CGUIListBox.cpp" />
@ -472,6 +474,8 @@
<Unit filename="CGUITable.h" />
<Unit filename="CGUIToolBar.cpp" />
<Unit filename="CGUIToolBar.h" />
<Unit filename="CGUITreeView.cpp" />
<Unit filename="CGUITreeView.h" />
<Unit filename="CGUIWindow.cpp" />
<Unit filename="CGUIWindow.h" />
<Unit filename="CGeometryCreator.cpp" />
@ -508,6 +512,8 @@
<Unit filename="CImageWriterPSD.h" />
<Unit filename="CImageWriterTGA.cpp" />
<Unit filename="CImageWriterTGA.h" />
<Unit filename="CIrrDeviceConsole.cpp" />
<Unit filename="CIrrDeviceConsole.h" />
<Unit filename="CIrrDeviceLinux.cpp" />
<Unit filename="CIrrDeviceLinux.h" />
<Unit filename="CIrrDeviceStub.cpp" />

View File

@ -9,7 +9,7 @@ CppCompiler=-D__GNUWIN32__ -W -DWIN32 -DNDEBUG -D_WINDOWS -D_MBCS -D_USRDLL -DIR
Includes=..\..\include;zlib
Linker=-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lwinmm -lopengl32_@@_
Libs=
UnitCount=607
UnitCount=613
Folders=doc,gui_impl,include,include/core,include/gui,include/io,include/scene,include/video,io_impl,other_impl,other_impl/extern,other_impl/extern/jpeglib,other_impl/extern/libpng,other_impl/extern/zlib,scene_impl,scene_impl/animators,scene_impl/collision,scene_impl/mesh,scene_impl/mesh/loaders,scene_impl/mesh/writers,scene_impl/nodes,scene_impl/nodes/particles,video_impl,"video_impl/Burning Video",video_impl/DirectX8,video_impl/DirectX9,video_impl/Null,video_impl/OpenGL,video_impl/Software
ObjFiles=
PrivateResource=
@ -6117,3 +6117,63 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit608]
FileName=CGUIImageList.cpp
CompileCpp=1
Folder=gui_impl
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit609]
FileName=CGUIImageList.h
CompileCpp=1
Folder=gui_impl
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit610]
FileName=CGUITreeView.cpp
CompileCpp=1
Folder=gui_impl
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit611]
FileName=CGUITreeView.h
CompileCpp=1
Folder=gui_impl
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit612]
FileName=CIrrDeviceConsole.cpp
CompileCpp=1
Folder=other_impl
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit613]
FileName=CIrrDeviceConsole.h
CompileCpp=1
Folder=other_impl
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

View File

@ -1999,6 +1999,14 @@
</Filter>
<Filter
Name="irr impl">
<File
RelativePath="CIrrDeviceConsole.cpp"
>
</File>
<File
RelativePath="CIrrDeviceConsole.h"
>
</File>
<File
RelativePath="CIrrDeviceLinux.cpp">
</File>

View File

@ -2774,6 +2774,14 @@
<Filter
Name="irr impl"
>
<File
RelativePath=".\CIrrDeviceConsole.cpp"
>
</File>
<File
RelativePath=".\CIrrDeviceConsole.h"
>
</File>
<File
RelativePath="CIrrDeviceLinux.cpp"
>

View File

@ -2766,6 +2766,14 @@
<Filter
Name="irr impl"
>
<File
RelativePath=".\CIrrDeviceConsole.cpp"
>
</File>
<File
RelativePath=".\CIrrDeviceConsole.h"
>
</File>
<File
RelativePath="CIrrDeviceLinux.cpp"
>

View File

@ -2413,6 +2413,14 @@
<Filter
Name="irr impl"
>
<File
RelativePath="CIrrDeviceConsole.cpp"
>
</File>
<File
RelativePath="CIrrDeviceConsole.h"
>
</File>
<File
RelativePath="CIrrDeviceLinux.cpp"
>

View File

@ -942,6 +942,14 @@
<File
RelativePath=".\CGeometryCreator.h">
</File>
<File
RelativePath=".\CIrrDeviceConsole.cpp"
>
</File>
<File
RelativePath=".\CIrrDeviceConsole.h"
>
</File>
<File
RelativePath=".\CIrrDeviceLinux.cpp">
</File>

View File

@ -34,7 +34,7 @@ IRRIMAGEOBJ = CColorConverter.o CImage.o CImageLoaderBMP.o CImageLoaderJPG.o CIm
IRRVIDEOOBJ = CVideoModeList.o CFPSCounter.o $(IRRDRVROBJ) $(IRRIMAGEOBJ)
IRRSWRENDEROBJ = CSoftwareDriver.o CSoftwareTexture.o CTRFlat.o CTRFlatWire.o CTRGouraud.o CTRGouraudWire.o CTRTextureFlat.o CTRTextureFlatWire.o CTRTextureGouraud.o CTRTextureGouraudAdd.o CTRTextureGouraudNoZ.o CTRTextureGouraudWire.o CZBuffer.o CTRTextureGouraudVertexAlpha2.o CTRTextureGouraudNoZ2.o CTRTextureLightMap2_M2.o CTRTextureLightMap2_M4.o CTRTextureLightMap2_M1.o CSoftwareDriver2.o CSoftwareTexture2.o CTRTextureGouraud2.o CTRGouraud2.o CTRGouraudAlpha2.o CTRGouraudAlphaNoZ2.o CTRTextureDetailMap2.o CTRTextureGouraudAdd2.o CTRTextureGouraudAddNoZ2.o CTRTextureWire2.o CTRTextureLightMap2_Add.o CTRTextureLightMapGouraud2_M4.o IBurningShader.o CTRTextureBlend.o CTRTextureGouraudAlpha.o CTRTextureGouraudAlphaNoZ.o CDepthBuffer.o CBurningShader_Raster_Reference.o
IRRIOOBJ = CFileList.o CFileSystem.o CLimitReadFile.o CMemoryFile.o CReadFile.o CWriteFile.o CXMLReader.o CXMLWriter.o CZipReader.o CPakReader.o irrXML.o CAttributes.o
IRROTHEROBJ = CIrrDeviceSDL.o CIrrDeviceLinux.o CIrrDeviceStub.o CIrrDeviceWin32.o CLogger.o COSOperator.o Irrlicht.o os.o
IRROTHEROBJ = CIrrDeviceSDL.o CIrrDeviceLinux.o CIrrDeviceConsole.o CIrrDeviceStub.o CIrrDeviceWin32.o CLogger.o COSOperator.o Irrlicht.o os.o
IRRGUIOBJ = CGUIButton.o CGUICheckBox.o CGUIComboBox.o CGUIContextMenu.o CGUIEditBox.o CGUIEnvironment.o CGUIFileOpenDialog.o CGUIFont.o CGUIImage.o CGUIInOutFader.o CGUIListBox.o CGUIMenu.o CGUIMeshViewer.o CGUIMessageBox.o CGUIModalScreen.o CGUIScrollBar.o CGUISpinBox.o CGUISkin.o CGUIStaticText.o CGUITabControl.o CGUITable.o CGUIToolBar.o CGUIWindow.o CGUIColorSelectDialog.o CDefaultGUIElementFactory.o CGUISpriteBank.o CGUIImageList.o CGUITreeView.o
ZLIBOBJ = zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/trees.o zlib/uncompr.o zlib/zutil.o
JPEGLIBOBJ = jpeglib/jcapimin.o jpeglib/jcapistd.o jpeglib/jccoefct.o jpeglib/jccolor.o jpeglib/jcdctmgr.o jpeglib/jchuff.o jpeglib/jcinit.o jpeglib/jcmainct.o jpeglib/jcmarker.o jpeglib/jcmaster.o jpeglib/jcomapi.o jpeglib/jcparam.o jpeglib/jcphuff.o jpeglib/jcprepct.o jpeglib/jcsample.o jpeglib/jctrans.o jpeglib/jdapimin.o jpeglib/jdapistd.o jpeglib/jdatadst.o jpeglib/jdatasrc.o jpeglib/jdcoefct.o jpeglib/jdcolor.o jpeglib/jddctmgr.o jpeglib/jdhuff.o jpeglib/jdinput.o jpeglib/jdmainct.o jpeglib/jdmarker.o jpeglib/jdmaster.o jpeglib/jdmerge.o jpeglib/jdphuff.o jpeglib/jdpostct.o jpeglib/jdsample.o jpeglib/jdtrans.o jpeglib/jerror.o jpeglib/jfdctflt.o jpeglib/jfdctfst.o jpeglib/jfdctint.o jpeglib/jidctflt.o jpeglib/jidctfst.o jpeglib/jidctint.o jpeglib/jidctred.o jpeglib/jmemmgr.o jpeglib/jmemnobs.o jpeglib/jquant1.o jpeglib/jquant2.o jpeglib/jutils.o