First irrlicht code added.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3101 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-02-04 00:31:40 +00:00
parent 00b98173ca
commit 4d2ace56b3
8 changed files with 234 additions and 38 deletions

View File

@ -73,6 +73,8 @@ supertuxkart_SOURCES = \
grand_prix_manager.hpp \
graphics/camera.cpp \
graphics/camera.hpp \
graphics/irr_device.cpp \
graphics/irr_device.cpp \
graphics/nitro.cpp \
graphics/nitro.hpp \
graphics/moving_texture.hpp \

View File

@ -37,12 +37,18 @@
#else
# define CONFIGDIR ".supertuxkart"
#endif
#ifdef HAVE_IRRLICHT
# include "irrlicht.h"
#endif
// ul.h includes windows.h, so this define is necessary
#define _WINSOCKAPI_
#include <plib/ul.h>
#include "btBulletDynamicsCommon.h"
#ifdef HAVE_IRRLICHT
# include "graphics/irr_driver.hpp"
#endif
#include "material_manager.hpp"
#include "utils/string_utils.hpp"
@ -81,8 +87,21 @@ bool macSetBundlePathIfRelevant(std::string& data_dir)
FileManager* file_manager = 0;
/** With irrlicht the constructor creates a NULL device. This is necessary to
* handle the Chicken/egg problem with irrlicht: access to the file system
* is given from the device, but we can't create the device before reading
* the user_config file (for resolution, fullscreen). So we create a dummy
* device here to begin with, which is then later (once the real device
* exists) changed in reInit().
*
*/
FileManager::FileManager()
{
#ifdef HAVE_IRRLICHT
//
m_device = createDevice(video::EDT_NULL);
m_file_system = m_device->getFileSystem();
#endif
m_is_full_path = false;
if ( getenv ( "SUPERTUXKART_DATADIR" ) != NULL )
@ -90,9 +109,17 @@ FileManager::FileManager()
#ifdef __APPLE__
else if( macSetBundlePathIfRelevant( m_root_dir ) ) { /* nothing to do */ }
#endif
#ifdef HAVE_IRRLICHT
else if(m_file_system->existFile("data/stk_config.data"))
#else
else if ( access ( "data/stk_config.data", F_OK ) == 0 )
#endif
m_root_dir = "." ;
#ifdef HAVE_IRRLICHT
else if(m_file_system->existFile("../data/stk_config.data"))
#else
else if ( access ( "../data/stk_config.data", F_OK ) == 0 )
#endif
m_root_dir = ".." ;
else
#ifdef SUPERTUXKART_DATADIR
@ -149,12 +176,32 @@ FileManager::FileManager()
}
} // FileManager
//-----------------------------------------------------------------------------
#ifdef HAVE_IRRLICHT
/** This function is used to re-initialise the file-manager after reading in
* the user configuration data.
*/
void FileManager::reInit()
{
// Drop the NULL device
m_device->drop();
m_device = irr_driver->getDevice();
m_device->grab(); // To make sure that the device still exists while
// file_manager has a pointer to the file system.
m_file_system = m_device->getFileSystem();
} // reInit
#endif
//-----------------------------------------------------------------------------
FileManager::~FileManager()
{
popMusicSearchPath();
popModelSearchPath();
popTextureSearchPath();
#ifdef HAVE_IRRLICHT
// m_file_system is ref-counted, so no delete/drop necessary.
m_file_system = NULL;
m_device->drop();
#endif
} // ~FileManager
//-----------------------------------------------------------------------------
@ -162,14 +209,20 @@ bool FileManager::findFile(std::string& full_path,
const std::string& fname,
const std::vector<std::string>& search_path) const
{
#ifndef HAVE_IRRLICHT
struct stat mystat;
#endif
for(std::vector<std::string>::const_iterator i = search_path.begin();
i != search_path.end(); ++i)
{
//full_path=m_root_dir + "/" + *i + "/" + fname;
full_path = *i + "/" + fname;
#ifdef HAVE_IRRLICHT
if(m_file_system->existFile(full_path.c_str())) return true;
#else
if(stat(full_path.c_str(), &mystat) >= 0) return true;
#endif
}
full_path="";
return false;
@ -308,23 +361,6 @@ std::string FileManager::getHighscoreFile(const std::string& fname) const
{
return getHomeDir()+"/"+fname;
} // getHighscoreFile
//-----------------------------------------------------------------------------
void FileManager::initConfigDir()
{
#ifdef WIN32
/*nothing*/
#else
/*if HOME environment variable exists
create directory $HOME/.supertuxkart*/
if(getenv("HOME")!=NULL)
{
std::string pathname;
pathname = getenv("HOME");
pathname += "/.supertuxkart";
mkdir(pathname.c_str(), 0755);
}
#endif
} // initConfigDir
//-----------------------------------------------------------------------------
void FileManager::listFiles(std::set<std::string>& result, const std::string& dir,

View File

@ -17,17 +17,29 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_FILE_MANAGER_H
#define HEADER_FILE_MANAGER_H
#ifndef HEADER_FILE_MANAGER_HPP
#define HEADER_FILE_MANAGER_HPP
#include <string>
#include <vector>
#include <set>
#include "callback_manager.hpp"
#ifdef HAVE_IRRLICHT
# include "irrlicht.h"
using namespace irr;
#endif
class FileManager
{
private:
#ifdef HAVE_IRRLICHT
/** Handle to irrlicht's file systems. */
io::IFileSystem *m_file_system;
/** Pointer to the irrlicht device. This is necessary before reInit is
* called to store the NULL device initially created. See Constructor
* for details. */
IrrlichtDevice *m_device;
#endif
bool m_is_full_path;
std::string m_root_dir;
std::vector<std::string> m_texture_search_path,
@ -35,10 +47,17 @@ private:
m_music_search_path;
bool findFile (std::string& full_path,
const std::string& fname,
const std::vector<std::string>& search_path) const;
const std::vector<std::string>& search_path)
const;
void makePath (std::string& path, const std::string& dir,
const std::string& fname) const;
public:
FileManager();
~FileManager();
#ifdef HAVE_IRRLICHT
void reInit();
#endif
std::string getHomeDir () const;
std::string getTrackDir () const;
@ -59,10 +78,10 @@ public:
std::string getSFXFile (const std::string& fname) const;
std::string getFontFile (const std::string& fname) const;
std::string getModelFile (const std::string& fname) const;
void listFiles(std::set<std::string>& result, const std::string& dir,
bool is_full_path=false, bool make_full_path=false)
const;
void listFiles (std::set<std::string>& result,
const std::string& dir,
bool is_full_path=false,
bool make_full_path=false) const;
void pushTextureSearchPath(const std::string& path)
{ m_texture_search_path.push_back(path);}
@ -73,13 +92,8 @@ public:
void popTextureSearchPath () {m_texture_search_path.pop_back(); }
void popModelSearchPath () {m_model_search_path.pop_back(); }
void popMusicSearchPath () {m_music_search_path.pop_back(); }
void initConfigDir();
private:
void makePath (std::string& path, const std::string& dir,
const std::string& fname) const;
};
extern FileManager* file_manager;
#endif

77
src/graphics/irr_driver.cpp Executable file
View File

@ -0,0 +1,77 @@
// $Id: sdldrv.hpp 694 2006-08-29 07:42:36Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef HAVE_IRRLICHT
#include "graphics/irr_driver.hpp"
using namespace core;
#include "user_config.hpp"
IrrDriver *irr_driver = NULL;
IrrDriver::IrrDriver()
{
// Try different drivers: start with opengl, then DirectX
for(int driver_type=0; driver_type<3; driver_type++)
{
video::E_DRIVER_TYPE type = driver_type==0
? video::EDT_OPENGL
: (driver_type==1
? video::EDT_DIRECT3D9
: video::EDT_DIRECT3D8);
// Try 32 and 16 bit per pixels
for(int bits=32; bits>15; bits -=16)
{
m_device = createDevice(type,
dimension2d<irr::s32>(user_config->m_width,
user_config->m_height ),
bits, //bits per pixel
user_config->m_fullscreen,
false, // stencil buffers
false, // vsync
this // event receiver
);
if(m_device) break;
} // for bits=24, 16
if(m_device) break;
} // for edt_types
if(!m_device)
{
fprintf(stderr, "Couldn't initialise irrlicht device. Quitting.\n");
exit(-1);
}
} // IrrDriver
// ----------------------------------------------------------------------------
IrrDriver::~IrrDriver()
{
m_device->drop();
} // ~IrrDriver
// ----------------------------------------------------------------------------
// Irrlicht Event handler.
bool IrrDriver::OnEvent(const irr::SEvent &event)
{
return false;
} // OnEvent
// ----------------------------------------------------------------------------
#endif // HAVE_IRRLICHT

45
src/graphics/irr_driver.hpp Executable file
View File

@ -0,0 +1,45 @@
// $Id: sdldrv.hpp 694 2006-08-29 07:42:36Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef HAVE_IRRLICHT
#ifndef HEADER_IRR_DRIVER_HPP
#define HEADER_IRR_DRIVER_HPP
#include "irrlicht.h"
using namespace irr;
class IrrDriver : public IEventReceiver
{
private:
/** The irrlicht device. */
IrrlichtDevice *m_device;
public:
IrrDriver();
~IrrDriver();
IrrlichtDevice *getDevice() const { return m_device; }
bool OnEvent(const irr::SEvent &event);
}; // IrrDriver
extern IrrDriver *irr_driver;
#endif // HEADER_IRR_DRIVER_HPP
#endif // HAVE_IRRLICHT

View File

@ -42,7 +42,7 @@
Name="VCCLCompilerTool"
Optimization="0"
WholeProgramOptimization="false"
AdditionalIncludeDirectories="../../../src;../../../src/bullet/src;&quot;$(STK_INCLUDE)&quot;;../../../src/enet/include;&quot;C:\cygwin\home\joerg\irrlicht-1.5\include&quot;"
AdditionalIncludeDirectories="../../../src;../../../src/bullet/src;&quot;$(STK_INCLUDE)&quot;;../../../src/enet/include;&quot;$(IRR_INCLUDE)&quot;"
PreprocessorDefinitions="BT_NO_PROFILE;HAVE_OPENAL;HAVE_OGGVORBIS;_DEBUG;_CONSOLE;WIN32;NOMINMAX;VERSION=\&quot;SVN\&quot;;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;DEBUG;PACKAGE=\&quot;supertuxkart\&quot;;HAVE_GETTEXT;ENABLE_NLS;HAVE_GLUT;HAVE_IRRLICHT"
GeneratePreprocessedFile="0"
MinimalRebuild="true"
@ -68,7 +68,7 @@
AdditionalDependencies="opengl32.lib user32.lib gdi32.lib winmm.lib advapi32.lib SDL.lib SDLmain.lib OpenAL32.lib libogg.lib libvorbis.lib libvorbisfile.lib sg.lib ssg.lib ul.lib ssgAux.lib fnt.lib intl.lib Irrlicht.lib ws2_32.lib"
OutputFile="./../../../$(ProjectName)_irr_d.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;$(STK_LIB)&quot;;&quot;C:\cygwin\home\joerg\irrlicht-1.5\lib\Win32-visualstudio&quot;"
AdditionalLibraryDirectories="&quot;$(STK_LIB)&quot;;&quot;$(IRR_LIB)&quot;"
IgnoreAllDefaultLibraries="false"
IgnoreDefaultLibraryNames="libcmt.lib"
GenerateDebugInformation="true"
@ -724,6 +724,10 @@
RelativePath="..\..\graphics\camera.cpp"
>
</File>
<File
RelativePath="..\..\graphics\irr_driver.cpp"
>
</File>
<File
RelativePath="..\..\graphics\moving_texture.cpp"
>
@ -1422,6 +1426,10 @@
RelativePath="..\..\graphics\camera.hpp"
>
</File>
<File
RelativePath="..\..\graphics\irr_driver.hpp"
>
</File>
<File
RelativePath="..\..\graphics\moving_texture.hpp"
>

View File

@ -59,6 +59,9 @@
#include "audio/sound_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "challenges/unlock_manager.hpp"
#ifdef HAVE_IRRLICHT
# include "graphics/irr_driver.hpp"
#endif
#include "graphics/scene.hpp"
#include "gui/menu_manager.hpp"
#include "gui/menu_manager.hpp"
@ -433,11 +436,16 @@ void InitTuxkart()
{
file_manager = new FileManager();
translations = new Translations();
loader = new Loader();
loader->setCreateStateCallback(getAppState);
// unlock manager is needed when reading the config file
unlock_manager = new UnlockManager();
user_config = new UserConfig();
#ifdef HAVE_IRRLICHT
irr_driver = new IrrDriver();
// Re-init file manager to use the new device.
file_manager->reInit();
#endif
loader = new Loader();
loader->setCreateStateCallback(getAppState);
sound_manager = new SoundManager();
sfx_manager = new SFXManager();
// The order here can be important, e.g. KartPropertiesManager needs
@ -505,6 +513,9 @@ void CleanTuxKart()
if(translations) delete translations;
if(file_manager) delete file_manager;
if(stk_scene) delete stk_scene;
#ifdef HAVE_IRRLICHT
if(irr_driver) delete irr_driver;
#endif
}
//=============================================================================

View File

@ -355,7 +355,10 @@ SDLDriver::~SDLDriver()
// FIXME LEAK: delete m_action_map if defined
SDL_FreeSurface(m_main_surface);
#ifndef HAVE_IRRLICHT
// Irrlicht calls SDL_Quit otherwise
SDL_Quit();
#endif
} // ~SDLDriver
//-----------------------------------------------------------------------------