diff --git a/src/Makefile.am b/src/Makefile.am index f560bdb7f..7d107db7b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -57,6 +57,8 @@ supertuxkart_SOURCES = \ audio/sound_manager.hpp \ utils/constants.hpp \ utils/coord.hpp \ + utils/mesh_tools.hpp \ + utils/mesh_tools.cpp \ utils/random_generator.hpp \ utils/random_generator.cpp \ utils/ssg_help.cpp \ diff --git a/src/challenges/challenge_data.cpp b/src/challenges/challenge_data.cpp index b25d824d3..20eeaa2ca 100755 --- a/src/challenges/challenge_data.cpp +++ b/src/challenges/challenge_data.cpp @@ -134,7 +134,10 @@ void ChallengeData::error(const char *id) const std::ostringstream msg; msg << "Undefined or incorrect value for '" << id << "' in challenge file '" << m_filename << "'."; +#ifndef HAVE_IRRLICHT + // FIXME: disable this till all tracks are converted throw std::runtime_error(msg.str()); +#endif } // error // ---------------------------------------------------------------------------- /** Checks if this challenge is valid, i.e. contains a valid track or a valid diff --git a/src/file_manager.cpp b/src/file_manager.cpp index 1958911b6..30348410d 100644 --- a/src/file_manager.cpp +++ b/src/file_manager.cpp @@ -135,6 +135,9 @@ FileManager::FileManager() pushTextureSearchPath(m_root_dir+"/data/textures"); pushModelSearchPath (m_root_dir+"/data/models" ); pushMusicSearchPath (m_root_dir+"/data/music" ); +#ifdef HAVE_IRRLICHT + m_file_system->addFolderFileArchive("data/models"); +#endif // Add more paths from the STK_MUSIC_PATH environment variable if(getenv("SUPERTUXKART_MUSIC_PATH")!=NULL) { @@ -176,16 +179,24 @@ FileManager::FileManager() } } // FileManager +//----------------------------------------------------------------------------- +/** Remove the dummy file system (which is called from IrrDriver before + * creating the actual device. + */ +#ifdef HAVE_IRRLICHT +void FileManager::dropFileSystem() +{ + m_device->drop(); +} // dropFileSystem +#endif //----------------------------------------------------------------------------- #ifdef HAVE_IRRLICHT /** This function is used to re-initialise the file-manager after reading in * the user configuration data. */ -void FileManager::reInit() +void FileManager::setDevice(IrrlichtDevice *device) { - // Drop the NULL device - m_device->drop(); - m_device = irr_driver->getDevice(); + m_device = device; 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(); @@ -205,6 +216,26 @@ FileManager::~FileManager() } // ~FileManager //----------------------------------------------------------------------------- +void FileManager::pushModelSearchPath(const std::string& path) +{ + m_model_search_path.push_back(path); +#ifdef HAVE_IRRLICHT + m_file_system->addFolderFileArchive(path.c_str()); +#endif +} // pushModelSearchPath + +//----------------------------------------------------------------------------- +void FileManager::pushTextureSearchPath(const std::string& path) +{ + m_texture_search_path.push_back(path); +#ifdef HAVE_IRRLICHT + m_file_system->addFolderFileArchive(path.c_str()); +#endif +} // pushTextureSearchPath + +//----------------------------------------------------------------------------- + + bool FileManager::findFile(std::string& full_path, const std::string& fname, const std::vector& search_path) const @@ -212,7 +243,8 @@ bool FileManager::findFile(std::string& full_path, #ifndef HAVE_IRRLICHT struct stat mystat; #endif - + + // FIXME: this should become a reverse iterator. for(std::vector::const_iterator i = search_path.begin(); i != search_path.end(); ++i) { diff --git a/src/file_manager.hpp b/src/file_manager.hpp index 89f4b2549..c029e48ba 100644 --- a/src/file_manager.hpp +++ b/src/file_manager.hpp @@ -56,7 +56,8 @@ public: FileManager(); ~FileManager(); #ifdef HAVE_IRRLICHT - void reInit(); + void setDevice(IrrlichtDevice *device); + void dropFileSystem(); #endif std::string getHomeDir () const; @@ -83,10 +84,8 @@ public: bool is_full_path=false, bool make_full_path=false) const; - void pushTextureSearchPath(const std::string& path) - { m_texture_search_path.push_back(path);} - void pushModelSearchPath (const std::string& path) - { m_model_search_path.push_back(path); } + void pushTextureSearchPath(const std::string& path); + void pushModelSearchPath (const std::string& path); void pushMusicSearchPath (const std::string& path) { m_music_search_path.push_back(path); } void popTextureSearchPath () {m_texture_search_path.pop_back(); } diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 2c7043024..8a2617870 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -24,6 +24,7 @@ #include #include "user_config.hpp" #include "audio/sound_manager.hpp" +#include "graphics/irr_driver.hpp" #include "karts/player_kart.hpp" #include "modes/world.hpp" #include "race_manager.hpp" @@ -35,7 +36,11 @@ Camera::Camera(int camera_index, const Kart* kart) { m_mode = CM_NORMAL; m_index = camera_index; +#ifdef HAVE_IRRLICHT + m_camera = irr_driver->addCamera(); +#else m_context = new ssgContext ; +#endif m_distance = kart->getKartProperties()->getCameraDistance(); m_kart = kart; m_xyz = kart->getXYZ(); @@ -43,11 +48,13 @@ Camera::Camera(int camera_index, const Kart* kart) // FIXME: clipping should be configurable for slower machines const Track* track = RaceManager::getTrack(); +#ifdef HAVE_IRRLICHT +#else if (track->useFog()) m_context -> setNearFar ( 0.05f, track->getFogEnd() ) ; else m_context -> setNearFar ( 0.05f, 1000.0f ) ; - +#endif setScreenPosition(camera_index); } // Camera @@ -55,7 +62,10 @@ Camera::Camera(int camera_index, const Kart* kart) Camera::~Camera() { reset(); +#ifdef HAVE_IRRLICHT +#else if(m_context) delete m_context; +#endif } // ---------------------------------------------------------------------------- @@ -66,12 +76,18 @@ void Camera::setScreenPosition(int camera_index) if (num_players == 1) { +#ifdef HAVE_IRRLICHT +#else m_context -> setFOV ( 75.0f, 0.0f ) ; +#endif m_x = 0.0f; m_y = 0.0f; m_w = 1.0f; m_h = 1.0f ; } else if (num_players == 2) { +#ifdef HAVE_IRRLICHT +#else m_context -> setFOV ( 85.0f, 85.0f*3.0f/8.0f ) ; +#endif switch ( camera_index ) { case 0 : m_x = 0.0f; m_y = 0.5f; m_w = 1.0f; m_h = 0.5f; break; @@ -80,18 +96,28 @@ void Camera::setScreenPosition(int camera_index) } else if (num_players == 3) { +#ifdef HAVE_IRRLICHT +#else m_context -> setFOV ( 50.0f, 0.0f ); +#endif switch ( camera_index ) { case 0 : m_x = 0.0f; m_y = 0.5f; m_w = 0.5f; m_h = 0.5f; break; case 1 : m_x = 0.5f; m_y = 0.5f; m_w = 0.5f; m_h = 0.5f; break; case 2 : m_x = 0.0f; m_y = 0.0f; m_w = 1.0f; m_h = 0.5f; - m_context -> setFOV ( 85.0f, 85.0f*3.0f/8.0f ); break; +#ifdef HAVE_IRRLICHT +#else + m_context -> setFOV ( 85.0f, 85.0f*3.0f/8.0f ); +#endif + break; } } else if (num_players == 4) { +#ifdef HAVE_IRRLICHT +#else m_context -> setFOV ( 50.0f, 0.0f ); +#endif switch ( camera_index ) { case 0 : m_x = 0.0f; m_y = 0.5f; m_w = 0.5f; m_h = 0.5f; break; @@ -234,7 +260,12 @@ void Camera::update (float dt) Coord c(result); m_xyz = c.getXYZ(); m_hpr = c.getHPR(); +#ifdef HAVE_IRRLICHT + m_camera->setPosition(m_xyz.toIrrVector()); + //m_camera->setTarget(kart_xyz.toIrrVector()); +#else m_context -> setCamera(&c.toSgCoord()); +#endif if(race_manager->getNumLocalPlayers() < 2) sound_manager->positionListener(m_xyz, kart_xyz - m_xyz); } // update @@ -249,7 +280,10 @@ void Camera::finalCamera(float dt) m_xyz += m_velocity*dt; m_hpr += m_angular_velocity*dt; Coord coord(m_xyz, m_hpr); +#ifdef HAVE_IRRLICHT +#else m_context->setCamera(&coord.toSgCoord()); +#endif } #undef TEST_END_CAMERA_POSITION #ifdef TEST_END_CAMERA_POSITION @@ -281,7 +315,9 @@ void Camera::apply () (int)((float)height * m_y), (int)((float)width * m_w), (int)((float)height * m_h) ) ; - +#ifdef HAVE_IRRLICHT +#else m_context -> makeCurrent () ; +#endif } // apply diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index 842052b26..ac5dc3097 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -23,8 +23,12 @@ #define HEADER_CAMERA_HPP #include "utils/vec3.hpp" - +#ifdef HAVE_IRRLICHT +#include "irrlicht.h" +using namespace irr; +#else class ssgContext; +#endif class Kart; class Camera @@ -39,7 +43,12 @@ public: CM_SIMPLE_REPLAY }; protected: +#ifdef HAVE_IRRLICHT + scene::ICameraSceneNode + *m_camera; +#else ssgContext *m_context; +#endif Vec3 m_xyz; // current position of camera Vec3 m_hpr; // heading, pitch, roll of camera const Kart *m_kart; // the kart the camera is attached to @@ -54,7 +63,8 @@ protected: float m_final_time; // time when final camera mode started private: - void finalCamera (float dt); // handle the final camera + void finalCamera (float dt); // handle the final camera + public: Camera (int camera_index, const Kart* kart); ~Camera (); diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 86c101b1c..7da5a3853 100755 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1,4 +1,4 @@ -// $Id: sdldrv.hpp 694 2006-08-29 07:42:36Z hiker $ +// $Id: irr_driver.cpp 694 2006-08-29 07:42:36Z hiker $ // // SuperTuxKart - a fun racing game with go-kart // Copyright (C) 2009 Joerg Henrichs @@ -22,11 +22,13 @@ using namespace core; #include "user_config.hpp" +#include "file_manager.hpp" IrrDriver *irr_driver = NULL; IrrDriver::IrrDriver() { + file_manager->dropFileSystem(); // Try different drivers: start with opengl, then DirectX for(int driver_type=0; driver_type<3; driver_type++) { @@ -56,7 +58,10 @@ IrrDriver::IrrDriver() fprintf(stderr, "Couldn't initialise irrlicht device. Quitting.\n"); exit(-1); } - + // Stores the new file system pointer. + file_manager->setDevice(m_device); + m_device->setWindowCaption(L"SuperTuxKart"); + m_scene_manager = m_device->getSceneManager(); } // IrrDriver // ---------------------------------------------------------------------------- @@ -65,6 +70,64 @@ IrrDriver::~IrrDriver() m_device->drop(); } // ~IrrDriver + +// ---------------------------------------------------------------------------- +/** Loads an animated mesh and returns a pointer to it. + * \param filename File to load. + */ +scene::IAnimatedMesh *IrrDriver::getAnimatedMesh(const std::string &filename) +{ + return m_scene_manager->getMesh(filename.c_str()); +} // getAnimatedMesh + +// ---------------------------------------------------------------------------- +/** Adds a mesh that will be optimised using an oct tree. + * \param mesh Mesh to add. + */ +scene::ISceneNode *IrrDriver::addOctTree(scene::IMesh *mesh) +{ + return m_scene_manager->addOctTreeSceneNode(mesh); +} // addOctTree + +// ---------------------------------------------------------------------------- +/** Adds a static mesh to scene. This should be used for smaller objects, + * since the node is not optimised. + * \param mesh The mesh to add. + */ +scene::ISceneNode *IrrDriver::addMesh(scene::IMesh *mesh) +{ + return m_scene_manager->addMeshSceneNode(mesh); +} // addMesh + +// ---------------------------------------------------------------------------- +/** Adds an animated mesh to the scene. + * \param mesh The animated mesh to add. + */ +scene::ISceneNode *IrrDriver::addAnimatedMesh(scene::IAnimatedMesh *mesh) +{ + return m_scene_manager->addAnimatedMeshSceneNode(mesh); +} // addAnimatedMesh + +// ---------------------------------------------------------------------------- +/** Adds a camera to the scene. + */ +scene::ICameraSceneNode *IrrDriver::addCamera() + { + return m_scene_manager->addCameraSceneNode(); + } // addCamera + +// ---------------------------------------------------------------------------- +/** Update, called once per frame. + * \param dt Time since last update + */ +void IrrDriver::update(float dt) +{ + + m_device->getVideoDriver()->beginScene(true, true, video::SColor(255,100,101,140)); + m_scene_manager->drawAll(); + m_device->getVideoDriver()->endScene(); +} // update + // ---------------------------------------------------------------------------- // Irrlicht Event handler. bool IrrDriver::OnEvent(const irr::SEvent &event) diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 210ca6156..abbcfc425 100755 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -1,4 +1,4 @@ -// $Id: sdldrv.hpp 694 2006-08-29 07:42:36Z hiker $ +// $Id: irr_driver.hpp 694 2006-08-29 07:42:36Z hiker $ // // SuperTuxKart - a fun racing game with go-kart // Copyright (C) 2009 Joerg Henrichs @@ -22,6 +22,8 @@ #ifndef HEADER_IRR_DRIVER_HPP #define HEADER_IRR_DRIVER_HPP +#include + #include "irrlicht.h" using namespace irr; @@ -30,12 +32,21 @@ class IrrDriver : public IEventReceiver private: /** The irrlicht device. */ IrrlichtDevice *m_device; + scene::ISceneManager *m_scene_manager; public: - IrrDriver(); - ~IrrDriver(); - IrrlichtDevice *getDevice() const { return m_device; } - bool OnEvent(const irr::SEvent &event); + IrrDriver(); + ~IrrDriver(); + IrrlichtDevice *getDevice() const { return m_device; } + scene::ISceneManager *getSceneManager() const { return m_scene_manager; } + scene::IAnimatedMesh *getAnimatedMesh(const std::string &name); + bool OnEvent(const irr::SEvent &event); + scene::ISceneNode *addOctTree(scene::IMesh *mesh); + scene::ISceneNode *addMesh(scene::IMesh *mesh); + scene::ISceneNode *addAnimatedMesh(scene::IAnimatedMesh *mesh); + scene::ICameraSceneNode + *addCamera(); + void update(float dt); }; // IrrDriver extern IrrDriver *irr_driver; diff --git a/src/graphics/scene.cpp b/src/graphics/scene.cpp index 8e0ad6eeb..422107b1a 100644 --- a/src/graphics/scene.cpp +++ b/src/graphics/scene.cpp @@ -142,7 +142,10 @@ void Scene::draw(float dt) { // Use this for faster profiling by disabling drawing the scene graph //if(!user_config->m_profile)ssgCullAndDraw ( m_scenegraph ); +#ifdef HAVE_IRRLICHT +#else ssgCullAndDraw ( m_scenegraph ); +#endif } #ifdef HAVE_GLUT else diff --git a/src/gui/char_sel.cpp b/src/gui/char_sel.cpp index 393486e7b..8e6fba7b5 100644 --- a/src/gui/char_sel.cpp +++ b/src/gui/char_sel.cpp @@ -331,8 +331,10 @@ void CharSel::switchCharacter(int n) m_kart = new ssgTransform; m_kart->ref(); KartModel* kartentity = kp->getKartModel(); - +#ifdef HAVE_IRRLICHT +#else m_kart->addKid(kartentity->getRoot()); +#endif } } // switchCharacter diff --git a/src/gui/config_display.cpp b/src/gui/config_display.cpp index 3d00d745d..ce144d46b 100644 --- a/src/gui/config_display.cpp +++ b/src/gui/config_display.cpp @@ -22,10 +22,10 @@ #include #include "main_loop.hpp" -#include "widget_manager.hpp" +#include "sdldrv.hpp" #include "user_config.hpp" #include "menu_manager.hpp" -#include "sdldrv.hpp" +#include "gui/widget_manager.hpp" #include "utils/translation.hpp" #include "utils/string_utils.hpp" diff --git a/src/gui/font.cpp b/src/gui/font.cpp index 84302bbed..eaa7de9bd 100644 --- a/src/gui/font.cpp +++ b/src/gui/font.cpp @@ -45,17 +45,22 @@ int delete_fonts() // ============================================================================= Font::Font(const char *fontname) { +#ifndef HAVE_IRRLICHT m_fnt = new fntTexFont(file_manager->getFontFile(fontname).c_str(), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR); m_text_out = new fntRenderer(); m_text_out->setFont(m_fnt); +#endif } // Font // ----------------------------------------------------------------------------- Font::~Font() { +#ifdef HAVE_IRRLICHT +#else delete m_text_out; delete m_fnt; +#endif } // ~Font // ----------------------------------------------------------------------------- @@ -66,7 +71,8 @@ void Font::Print(const char *text, int size, float scale_x, float scale_y, int left, int right, int top, int bottom, bool doShadow) { - +#ifdef HAVE_IRRLICHT +#else // Only scale for lower resolution float fontScaling = user_config->m_width<800 ? ((float)user_config->m_width/800.0f) : 1.0f; @@ -92,7 +98,6 @@ void Font::Print(const char *text, int size, int height = top-bottom+1; y = (height - H)/2 + bottom; } - m_text_out->begin(); m_text_out->setPointSize((float)sz); if(doShadow) @@ -113,7 +118,7 @@ void Font::Print(const char *text, int size, } m_text_out->puts(text); m_text_out->end(); - +#endif } // Print // ----------------------------------------------------------------------------- @@ -147,7 +152,7 @@ void Font::PrintBold(const std::string &text, int size, int x, int y, y = (height - H)/2 + bottom; } - +#ifndef HAVE_IRRLICHT m_text_out->begin(); m_text_out->setPointSize((float)sz); @@ -184,13 +189,14 @@ void Font::PrintBold(const std::string &text, int size, int x, int y, m_text_out->puts(text.c_str()); } m_text_out->end(); - +#endif } // PrintBold // ---------------------------------------------------------------------------- void Font::getBBox(const std::string &text, int size, bool italic, float *left, float *right, float *bot, float *top) { +#ifndef HAVE_IRRLICHT m_fnt->getBBox(text.c_str(), (float)size, italic, left, right, bot, top); if(user_config->m_width<800) { float fract=(float)user_config->m_width/800.0f; @@ -199,7 +205,7 @@ void Font::getBBox(const std::string &text, int size, bool italic, if(bot) *bot *= fract; if(top) *top *= fract; } - +#endif } // ---------------------------------------------------------------------------- @@ -209,6 +215,7 @@ void Font::getBBoxMultiLine(const std::string &text, int size, bool italic, // Plib does not handle multi-lines strings as expected. So as a work // around we split strings into lines, and compute the size for each // line, and take the maximum size at the end. +#ifndef HAVE_IRRLICHT std::vector s=StringUtils::split(text,'\n'); m_fnt->getBBox(s[0].c_str(), (float)size, italic, left, right, bot, top); for(unsigned int i=1; iref(); KartModel* kartentity = WINNING_KART->getKartModel(); +#ifdef HAVE_IRRLICHT +#else m_kart->addKid(kartentity->getRoot()); +#endif m_winner_sound->play(); diff --git a/src/gui/race_gui.cpp b/src/gui/race_gui.cpp index 8f5a378ed..9d0f6268d 100644 --- a/src/gui/race_gui.cpp +++ b/src/gui/race_gui.cpp @@ -374,7 +374,10 @@ void RaceGUI::drawPlayerIcons (const KartIconDisplayInfo* info) } //The material of the icons should not have a non-zero alpha_ref value, //because if so the next call can make the text look aliased. +#ifdef HAVE_IRRLICHT +#else players_gst -> apply (); +#endif last_players_gst = players_gst; glBegin ( GL_QUADS ) ; glColor4f ( 1, 1, 1, 1 ) ; @@ -612,6 +615,8 @@ void RaceGUI::drawSpeed(Kart* kart, int offset_x, int offset_y, offset_x += (int)((user_config->m_width-10)*ratio_x) - width; offset_y += (int)(10*ratio_y); +#ifdef HAVE_IRRLICHT +#else glMatrixMode(GL_MODELVIEW); m_speed_back_icon->getState()->force(); // If the colour isn't set, the speedometer is blended with the last @@ -661,7 +666,7 @@ void RaceGUI::drawSpeed(Kart* kart, int offset_x, int offset_y, glEnd () ; } // speed<0 - +#endif } // drawSpeed //----------------------------------------------------------------------------- diff --git a/src/ide/vc9/supertuxkart.vcproj b/src/ide/vc9/supertuxkart.vcproj index ac86a3467..9cb4bfcdc 100644 --- a/src/ide/vc9/supertuxkart.vcproj +++ b/src/ide/vc9/supertuxkart.vcproj @@ -728,6 +728,10 @@ RelativePath="..\..\graphics\irr_driver.cpp" > + + @@ -1430,6 +1434,10 @@ RelativePath="..\..\graphics\irr_driver.hpp" > + + diff --git a/src/items/attachment.cpp b/src/items/attachment.cpp index a9cf6947d..fd04e8d6e 100644 --- a/src/items/attachment.cpp +++ b/src/items/attachment.cpp @@ -35,8 +35,10 @@ Attachment::Attachment(Kart* _kart) m_type = ATTACH_NOTHING; m_time_left = 0.0; m_kart = _kart; - m_holder = new ssgSelector(); m_previous_owner = NULL; +#ifdef HAVE_IRRLICHT +#else + m_holder = new ssgSelector(); m_kart->getModelTransform()->addKid(m_holder); for(int i=ATTACH_FIRST; iaddKid(p); } m_holder->select(0); +#endif } // Attachment //----------------------------------------------------------------------------- @@ -80,7 +83,10 @@ void Attachment::clear() { m_type=ATTACH_NOTHING; m_time_left=0.0; +#ifdef HAVE_IRRLICHT +#else m_holder->select(0); +#endif // Resets the weight of the kart if the previous attachment affected it // (e.g. anvil). This must be done *after* setting m_type to diff --git a/src/items/attachment_manager.cpp b/src/items/attachment_manager.cpp index 261449a09..d807b1120 100644 --- a/src/items/attachment_manager.cpp +++ b/src/items/attachment_manager.cpp @@ -68,8 +68,11 @@ void AttachmentManager::loadModels() { // FIXME LEAK: these models are not removed (unimportant, since they // have to be in memory till the end of the game. +#ifdef HAVE_IRRLICHT +#else m_attachments[iat[i].attachment]=loader->load(iat[i].file, CB_ATTACHMENT); m_attachments[iat[i].attachment]->ref(); +#endif } // for } // reInit diff --git a/src/items/flyable.cpp b/src/items/flyable.cpp index d805c47d1..a2b947c5b 100644 --- a/src/items/flyable.cpp +++ b/src/items/flyable.cpp @@ -64,9 +64,12 @@ Flyable::Flyable(Kart *kart, PowerupType type, float mass) : Moveable() m_max_lifespan = -1; // Add the graphical model +#ifdef HAVE_IRRLICHT +#else ssgTransform *m = getModelTransform(); m->addKid(m_st_model[type]); stk_scene->add(m); +#endif } // Flyable // ---------------------------------------------------------------------------- void Flyable::createPhysics(float y_offset, const btVector3 &velocity, @@ -128,8 +131,10 @@ void Flyable::init(const lisp::Lisp* lisp, ssgEntity *model, // Store the size of the model Vec3 min, max; - +#ifdef HAVE_IRRLICHT +#else SSGHelp::MinMax(model, &min, &max); +#endif m_st_extend[type] = btVector3(max-min); m_st_model[type] = model; } // init @@ -257,9 +262,12 @@ void Flyable::hit(Kart *kart_hit, MovingPhysics* moving_physics) projectile_manager->notifyRemove(); // Now remove this projectile from the graph: +#ifdef HAVE_IRRLICHT +#else ssgTransform *m = getModelTransform(); m->removeAllKids(); stk_scene->remove(m); +#endif // The explosion is a bit higher in the air Vec3 pos_explosion=getXYZ(); diff --git a/src/items/item.cpp b/src/items/item.cpp index ab248cf49..cd8e9cca4 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -37,11 +37,14 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal, m_type = type; m_collected = false; m_time_till_return = 0.0f; // not strictly necessary, see isCollected() +#ifdef HAVE_IRRLICHT +#else m_root = new ssgTransform(); m_root->ref(); m_root->setTransform(const_cast(&m_coord.toSgCoord())); m_root->addKid(model); stk_scene->add(m_root); +#endif } // Item //----------------------------------------------------------------------------- @@ -94,9 +97,12 @@ void Item::update(float delta) if(!m_rotate) return; // have it rotate +#ifdef HAVE_IRRLICHT +#else Vec3 rotation(delta*M_PI, 0, 0); m_coord.setHPR(m_coord.getHPR()+rotation); m_root->setTransform(const_cast(&m_coord.toSgCoord())); +#endif } } // update diff --git a/src/items/item_manager.cpp b/src/items/item_manager.cpp index 881698944..7b49f7325 100644 --- a/src/items/item_manager.cpp +++ b/src/items/item_manager.cpp @@ -108,6 +108,8 @@ void ItemManager::removeTextures() //----------------------------------------------------------------------------- ItemManager::~ItemManager() { +#ifdef HAVE_IRRLICHT +#else for(CI_type i=m_all_models.begin(); i!=m_all_models.end(); ++i) { // We can't use ssgDeRefDelete here, since then the object would be @@ -115,6 +117,7 @@ ItemManager::~ItemManager() // accesses. i->second->deRef(); } +#endif m_all_models.clear(); } // ~ItemManager @@ -131,6 +134,8 @@ void ItemManager::loadDefaultItems() for(std::set::iterator i = files.begin(); i != files.end(); ++i) { +#ifdef HAVE_IRRLICHT +#else if(!StringUtils::has_suffix(*i, ".ac")) continue; ssgEntity* h = loader->load(*i, CB_ITEM, /*optimise*/true, @@ -139,6 +144,7 @@ void ItemManager::loadDefaultItems() h->ref(); h->setName(shortName.c_str()); m_all_models[shortName] = h; +#endif } // for i @@ -196,8 +202,11 @@ void ItemManager::setDefaultItemStyle() } } // if i->second } +#ifndef HAVE_IRRLICHT + // For now disable this, irrlicht does not yet load any items. throw std::runtime_error(msg.str()); exit(-1); +#endif } // if bError } // setDefaultItemStyle diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index 19012eb08..bdf4a5a4a 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -122,9 +122,12 @@ void Plunger::update(float dt) { setHasHit(); projectile_manager->notifyRemove(); +#ifdef HAVE_IRRLICHT +#else ssgTransform *m = getModelTransform(); m->removeAllKids(); stk_scene->remove(m); +#endif } if(m_rubber_band != NULL) m_rubber_band->update(dt); return; @@ -171,7 +174,10 @@ void Plunger::hit(Kart *kart, MovingPhysics *mp) // objects is simply removed from the scene graph, it might be auto-deleted // because the ref count reaches zero. Vec3 hell(0, 0, -10000); +#ifdef HAVE_IRRLICHT +#else getModelTransform()->setTransform(hell.toFloat()); +#endif RaceManager::getWorld()->getPhysics()->removeBody(getBody()); } else @@ -182,7 +188,10 @@ void Plunger::hit(Kart *kart, MovingPhysics *mp) // objects is simply removed from the scene graph, it might be auto-deleted // because the ref count reaches zero. Vec3 hell(0, 0, -10000); +#ifdef HAVE_IRRLICHT +#else getModelTransform()->setTransform(hell.toFloat()); +#endif RaceManager::getWorld()->getPhysics()->removeBody(getBody()); if(kart) diff --git a/src/items/powerup_manager.cpp b/src/items/powerup_manager.cpp index dc6fe9ee8..f8cac4d7f 100644 --- a/src/items/powerup_manager.cpp +++ b/src/items/powerup_manager.cpp @@ -123,12 +123,15 @@ void PowerupManager::LoadNode(const lisp::Lisp* lisp, int collectType ) if(sModel!="") { - // FIXME LEAK: not freed (uniportant, since the models have to exist +#ifdef HAVE_IRRLICHT +#else + // FIXME LEAK: not freed (unimportant, since the models have to exist // for the whole game anyway). ssgEntity* e = loader->load(sModel, CB_COLLECTABLE); m_all_models[collectType] = e; e->ref(); e->clrTraversalMaskBits(SSGTRAV_ISECT|SSGTRAV_HOT); +#endif } else { diff --git a/src/items/projectile_manager.cpp b/src/items/projectile_manager.cpp index 56436d301..91de59bdd 100644 --- a/src/items/projectile_manager.cpp +++ b/src/items/projectile_manager.cpp @@ -35,7 +35,8 @@ ProjectileManager *projectile_manager=0; void ProjectileManager::loadData() { - +#ifdef HAVE_IRRLICHT +#else // Load the explosion model and find the actual selector branch in it. // Only the explosion model is loaded here, see powerup_manager. m_explosion_model = find_selector((ssgBranch*)loader->load("explode.ac", @@ -46,7 +47,7 @@ void ProjectileManager::loadData() fprintf ( stderr, "explode.ac doesn't have an 'explosion' object.\n" ) ; exit ( 1 ) ; } - +#endif } // loadData //----------------------------------------------------------------------------- @@ -65,8 +66,11 @@ void ProjectileManager::cleanup() for(Projectiles::iterator i = m_active_projectiles.begin(); i != m_active_projectiles.end(); ++i) { +#ifdef HAVE_IRRLICHT +#else ssgTransform *m = (*i)->getModelTransform(); m->removeAllKids(); +#endif delete *i; } m_active_projectiles.clear(); diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 4adf9e14d..e6e49c281 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -270,7 +270,10 @@ void Kart::eliminate() // make the kart invisible by placing it way under the track sgVec3 hell; hell[0]=0.0f; hell[1]=0.0f; hell[2] = -10000.0f; +#ifdef HAVE_IRRLICHT +#else getModelTransform()->setTransform(hell); +#endif } // eliminate //----------------------------------------------------------------------------- @@ -643,12 +646,18 @@ void Kart::update(float dt) if( (!isOnGround() || m_rescue) && m_shadow_enabled) { m_shadow_enabled = false; +#ifdef HAVE_IRRLICHT +#else m_model_transform->removeKid(m_shadow); +#endif } if(!m_shadow_enabled && isOnGround() && !m_rescue) { m_shadow_enabled = true; +#ifdef HAVE_IRRLICHT +#else m_model_transform->addKid(m_shadow); +#endif } } // update @@ -984,10 +993,15 @@ void Kart::loadData() { float r [ 2 ] = { -10.0f, 100.0f } ; - +#ifdef HAVE_IRRLICHT + m_kart_properties->getKartModel()->attachModel(&m_root); +#else ssgEntity *obj = m_kart_properties->getKartModel()->getRoot(); +#endif createPhysics(); +#ifdef HAVE_IRRLICHT +#else SSGHelp::createDisplayLists(obj); // create all display lists ssgRangeSelector *lod = new ssgRangeSelector ; @@ -995,7 +1009,7 @@ void Kart::loadData() lod -> setRanges ( r, 2 ) ; getModelTransform() -> addKid ( lod ) ; - +#endif // Attach Particle System m_smoke_system = new Smoke(this); m_smoke_system->ref(); @@ -1004,11 +1018,13 @@ void Kart::loadData() if(m_kart_properties->hasSkidmarks()) m_skidmarks = new SkidMarks(*this); - +#ifdef HAVE_IRRLICHT +#else m_shadow = createShadow(m_kart_properties->getShadowFile(), -1, 1, -1, 1); m_shadow->ref(); m_model_transform->addKid ( m_shadow ); m_shadow_enabled = true; +#endif } // loadData //----------------------------------------------------------------------------- diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index 55802a2d3..8e16424f0 100755 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -19,9 +19,12 @@ #include "karts/kart_model.hpp" +#include "file_manager.hpp" #include "loader.hpp" #include "stk_config.hpp" #include "user_config.hpp" +#include "graphics/irr_driver.hpp" +#include "graphics/mesh_tools.hpp" #include "utils/constants.hpp" #include "utils/ssg_help.hpp" @@ -43,12 +46,20 @@ KartModel::KartModel() m_max_suspension[i] = 1.3f; m_dampen_suspension_amplitude[i] = 2.5f; } +#ifdef HAVE_IRRLICHT + m_wheel_filename[0] = "wheel-front-right.3ds"; + m_wheel_filename[1] = "wheel-front-left.3ds"; + m_wheel_filename[2] = "wheel-rear-right.3ds"; + m_wheel_filename[3] = "wheel-rear-left.a3ds"; + m_mesh = NULL; +#else m_wheel_filename[0] = "wheel-front-right.ac"; m_wheel_filename[1] = "wheel-front-left.ac"; m_wheel_filename[2] = "wheel-rear-right.ac"; m_wheel_filename[3] = "wheel-rear-left.ac"; + m_root = NULL; +#endif - m_root = NULL; } // KartModel // ---------------------------------------------------------------------------- @@ -72,15 +83,48 @@ KartModel::~KartModel() // This automatically frees the wheels and the kart model. // m_root can be zero in case of STKConfig, which has a kart_properties // attribute (for the default values) as well. +#ifdef HAVE_IRRLICHT +#else if(m_root) m_root->removeAllKids(); ssgDeRefDelete(m_root); +#endif } // ~KartModel // ---------------------------------------------------------------------------- +/** Attach the kart model and wheels to the scene node. + * \param node Node to attach the models to. + */ +void KartModel::attachModel(scene::ISceneNode **node) +{ + *node = irr_driver->addMesh(m_mesh); + for(unsigned int i=0; i<4; i++) + { + // *node->addChild(m_wh + } +} // attachModel + +// ---------------------------------------------------------------------------- + /** Loads the 3d model and all wheels. */ -void KartModel::loadModels() +void KartModel::loadModels(const std::string &kart_ident) { +#ifdef HAVE_IRRLICHT + std::string full_path = file_manager->getKartFile(m_model_filename); + m_mesh = irr_driver->getAnimatedMesh(full_path)->getMesh(0); + Vec3 min, max; + MeshTools::minMax3D(m_mesh, &min, &max); + Vec3 size = max-min; + m_z_offset = min.getZ(); + m_kart_width = size.getX(); + m_kart_height = size.getY(); + m_kart_length = size.getZ(); + // FIXME: How do we handle this? it's a mesh only, so we can't + // simply move it in a transform (unless we turn it into a scene + // node). m_z_offset should probably be made available to kart. + // Vec3 move_kart_to_0_z(0, 0, m_z_offset); + // m_root->setTransform(move_kart_to_0_z); +#else ssgEntity *obj = loader->load(m_model_filename, CB_KART); if(!obj) { @@ -100,6 +144,7 @@ void KartModel::loadModels() sgVec3 move_kart_to_0_z; sgSetVec3(move_kart_to_0_z, 0, 0, m_z_offset); m_root->setTransform(move_kart_to_0_z); +#endif // Now set default some default parameters (if not defined) that // depend on the size of the kart model (wheel position, center @@ -122,6 +167,12 @@ void KartModel::loadModels() // depend on the size of the model. for(unsigned int i=0; i<4; i++) { +#ifdef HAVE_IRRLICHT + std::string full_wheel = file_manager->getKartFile(m_wheel_filename[i], + kart_ident); + m_wheel_model[i] = irr_driver->getAnimatedMesh(full_wheel)->getMesh(0); + // FIXME: wheel handling still missing. +#else m_wheel_model[i] = loader->load(m_wheel_filename[i], CB_KART); m_wheel_transform[i]= new ssgTransform(); #ifdef DEBUG @@ -142,6 +193,7 @@ void KartModel::loadModels() hpr); m_wheel_transform[i]->setTransform(wheel_loc); } // if m_wheel_model[i] +#endif } // for i<4 if(!m_wheel_model[0]) { @@ -220,6 +272,9 @@ void KartModel::setDefaultPhysicsPosition(const Vec3 ¢er_shift, void KartModel::adjustWheels(float rotation, float steer, const float suspension[4]) { +#ifdef HAVE_IRRLICHT + // FIXME: missing +#else sgMat4 wheel_front; sgMat4 wheel_steer; sgMat4 wheel_rot; @@ -261,7 +316,7 @@ void KartModel::adjustWheels(float rotation, float steer, sgCopyVec3(wheel_rot[3], m_wheel_graphics_position[3].toFloat()); wheel_rot[3][2] += clamped_suspension[3]; m_wheel_transform[3]->setTransform(wheel_rot); - +#endif } // adjustWheels // ---------------------------------------------------------------------------- diff --git a/src/karts/kart_model.hpp b/src/karts/kart_model.hpp index 911fa0ee4..e7a2a12d4 100755 --- a/src/karts/kart_model.hpp +++ b/src/karts/kart_model.hpp @@ -23,7 +23,12 @@ #include #define _WINSOCKAPI_ +#ifdef HAVE_IRRLICHT +#include "irrlicht.h" +using namespace irr; +#else #include +#endif #include "no_copy.hpp" #include "lisp/lisp.hpp" @@ -37,8 +42,13 @@ class KartModel { private: +#ifdef HAVE_IRRLICHT + /** The mesh of the model. */ + scene::IMesh *m_mesh; +#else /** The transform node/root of the kart model. */ ssgTransform *m_root; +#endif /** Value used to indicate undefined entries. */ static float UNDEFINED; @@ -46,8 +56,13 @@ private: /** Name of the 3d model file. */ std::string m_model_filename; +#ifdef HAVE_IRRLICHT + /** The four wheel models. */ + scene::IMesh *m_wheel_model[4]; +#else /** The four wheel models. */ ssgEntity *m_wheel_model[4]; +#endif /** Filename of the wheel models. */ std::string m_wheel_filename[4]; @@ -73,10 +88,15 @@ private: /** value used to divide the visual movement of wheels (because the actual movement of wheels in bullet is too large and looks strange). 1=no change, 2=half the amplitude */ float m_dampen_suspension_amplitude[4]; - + +#ifdef HAVE_IRRLICHT + /** The transform for the wheels, used to rotate the wheels and display + * the suspension in the race. */ +#else /** The transform for the wheels, used to rotate the wheels and display * the suspension in the race. */ ssgTransform *m_wheel_transform[4]; +#endif float m_kart_width; /**< Width of kart. */ float m_kart_length; /**< Length of kart. */ @@ -91,8 +111,12 @@ public: KartModel(); ~KartModel(); void loadInfo(const lisp::Lisp* lisp); - void loadModels(); - ssgTransform *getRoot() { return m_root; } + void loadModels(const std::string &kart_ident); +#ifdef HAVE_IRRLICHT + void attachModel(scene::ISceneNode **node); +#else + ssgTransform *getRoot() const { return m_root; } +#endif /** Returns the position of a wheel relative to the kart. * \param i Index of the wheel: 0=front right, 1 = front left, 2 = rear @@ -108,9 +132,6 @@ public: const Vec3& getWheelPhysicsPosition(int i) const {return m_wheel_physics_position[i];} - /** Returns the model of a wheel. */ - ssgEntity *getWheelModel(int i) const {return m_wheel_model[i];} - /** Returns the radius of the graphical wheels. * \param i Index of the wheel: 0=front right, 1 = front left, 2 = rear * right, 3 = rear left. */ diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 2948b9782..e51b35f99 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -142,7 +142,7 @@ void KartProperties::load(const std::string &filename, const std::string &node, // Only load the model if the .kart file has the appropriate version, // otherwise warnings are printed. if(m_version>=1) - m_kart_model.loadModels(); + m_kart_model.loadModels(m_ident); if(m_gravity_center_shift.getX()==UNDEFINED) { m_gravity_center_shift.setX(0); diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index 80f44c8c8..6190f9b9e 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -77,7 +77,11 @@ void KartPropertiesManager::loadKartData(bool dont_load_models) std::string kart_file; try { +#ifdef HAVE_IRRLICHT + kart_file = file_manager->getKartFile((*i)+".irrkart"); +#else kart_file = file_manager->getKartFile((*i)+".kart"); +#endif } catch (std::exception& e) { diff --git a/src/karts/moveable.cpp b/src/karts/moveable.cpp index c017db52c..f5e75f040 100644 --- a/src/karts/moveable.cpp +++ b/src/karts/moveable.cpp @@ -23,6 +23,7 @@ #include "material_manager.hpp" #include "material.hpp" #include "user_config.hpp" +#include "graphics/irr_driver.hpp" #include "karts/player_kart.hpp" #include "utils/coord.hpp" @@ -31,9 +32,12 @@ Moveable::Moveable() m_body = 0; m_motion_state = 0; m_first_time = true ; +#ifdef HAVE_IRRLICHT + m_mesh = 0; +#else m_model_transform = new ssgTransform(); - m_model_transform->ref(); +#endif } // Moveable //----------------------------------------------------------------------------- @@ -51,8 +55,11 @@ void Moveable::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr) Vec3 xyz=getXYZ()+off_xyz; Vec3 hpr=getHPR()+off_hpr; sgCoord c=Coord(xyz, hpr).toSgCoord(); - +#ifdef HAVE_IRRLICHT + m_root->setPosition(xyz.toIrrVector()); +#else m_model_transform->setTransform(&c); +#endif } // updateGraphics //----------------------------------------------------------------------------- diff --git a/src/karts/moveable.hpp b/src/karts/moveable.hpp index 9e4e3a9cc..d1b3e09ff 100644 --- a/src/karts/moveable.hpp +++ b/src/karts/moveable.hpp @@ -22,8 +22,14 @@ #define HEADER_MOVEABLE_HPP #define _WINSOCKAPI_ -#include +#ifdef HAVE_IRRLICHT +# include "irrlicht.h" + using namespace irr; +#else +# include +#endif #include "btBulletDynamicsCommon.h" + #include "user_pointer.hpp" #include "physics/kart_motion_state.hpp" #include "utils/vec3.hpp" @@ -45,7 +51,13 @@ private: protected: UserPointer m_user_pointer; +#ifdef HAVE_IRRLICHT + scene::IAnimatedMesh *m_animated_mesh; + scene::IMesh *m_mesh; + scene::ISceneNode *m_root; +#else ssgTransform *m_model_transform; /**getLinearVelocity();} + &getVelocity() const {return m_body->getLinearVelocity();} const btVector3 &getVelocityLC() const {return m_velocityLC; } virtual void setVelocity(const btVector3& v) {m_body->setLinearVelocity(v); } diff --git a/src/loader.hpp b/src/loader.hpp index b29e1610d..56f98157f 100644 --- a/src/loader.hpp +++ b/src/loader.hpp @@ -17,8 +17,8 @@ // 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_LOADER_H -#define HEADER_LOADER_H +#ifndef HEADER_LOADER_HPP +#define HEADER_LOADER_HPP #define _WINSOCKAPI_ #include diff --git a/src/main.cpp b/src/main.cpp index 6a22af403..6c2959102 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -230,7 +230,8 @@ int handleCmdLine(int argc, char **argv) fprintf(stdout, "Track %s has not been unlocked yet. \n", argv[i+1]); fprintf(stdout, "Use --list-tracks to list available tracks.\n\n"); return 0; - } + } + i++; } else if( (!strcmp(argv[i], "--stk-config")) && i+1reInit(); #endif loader = new Loader(); loader->setCreateStateCallback(getAppState); @@ -552,7 +551,9 @@ int main(int argc, char *argv[] ) //FIXME: this needs a better organization inputDriver = new SDLDriver (); - ssgInit () ; +#ifndef HAVE_IRRLICHT + ssgInit(); +#endif main_loop = new MainLoop(); // loadMaterials needs ssgLoadTextures (internally), which can diff --git a/src/main_loop.cpp b/src/main_loop.cpp index b295430b9..d520e6bdf 100644 --- a/src/main_loop.cpp +++ b/src/main_loop.cpp @@ -21,15 +21,16 @@ #include #include +#include "history.hpp" #include "sdldrv.hpp" #include "material_manager.hpp" #include "race_manager.hpp" -#include "modes/world.hpp" -#include "user_config.hpp" -#include "history.hpp" #include "audio/sound_manager.hpp" +#include "graphics/irr_driver.hpp" #include "graphics/scene.hpp" #include "gui/menu_manager.hpp" +#include "modes/world.hpp" +#include "user_config.hpp" #include "network/network_manager.hpp" MainLoop* main_loop = 0; @@ -204,8 +205,12 @@ void MainLoop::run() menu_manager->update(); sound_manager->update(dt); +#ifdef HAVE_IRRLICHT + irr_driver->update(dt); +#else glFlush(); SDL_GL_SwapBuffers(); +#endif } // while !m_exit } // run diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 2b2c3e4e7..4392cd25b 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -141,10 +141,12 @@ void World::init() break; } } // if !user_config->m_profile - +#ifdef HAVE_IRRLICHT +#else newkart -> getModelTransform() -> clrTraversalMaskBits(SSGTRAV_ISECT|SSGTRAV_HOT); stk_scene->add ( newkart -> getModelTransform() ) ; +#endif m_kart.push_back(newkart); newkart->setWorldKartId(m_kart.size()-1); } // for i diff --git a/src/sdldrv.cpp b/src/sdldrv.cpp index 1beee8444..1b71cfb6b 100755 --- a/src/sdldrv.cpp +++ b/src/sdldrv.cpp @@ -59,7 +59,11 @@ SDLDriver::SDLDriver() : m_sensed_input(0), m_action_map(0), m_main_surface(0), m_flags(0), m_stick_infos(0), m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0) { +#ifdef HAVE_IRRLICHT + if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_TIMER) < 0) +#else if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER) < 0) +#endif { fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); exit(1); @@ -105,8 +109,9 @@ SDLDriver::SDLDriver() SDL_JoystickEventState(SDL_ENABLE); initStickInfos(); - +#ifndef HAVE_IRRLICHT SDL_WM_SetCaption("SuperTuxKart", NULL); +#endif // Get into menu mode initially. setMode(MENU); @@ -255,6 +260,7 @@ void SDLDriver::toggleFullscreen(bool resetTextures) */ void SDLDriver::setVideoMode(bool resetTextures) { +#ifndef HAVE_IRRLICHT //Is SDL_FreeSurface necessary? SDL wiki says not?? SDL_FreeSurface(m_main_surface); @@ -299,7 +305,7 @@ void SDLDriver::setVideoMode(bool resetTextures) } } // !m_main_surface } // !m_main_surface - +#endif #if defined(WIN32) || defined(__APPLE__) if(resetTextures) { diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 1b659db85..64429dc33 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -24,7 +24,9 @@ #include #define _WINSOCKAPI_ #include - +#ifdef HAVE_IRRLICHT +#include "irrlicht.h" +#endif #include "file_manager.hpp" #include "loader.hpp" #include "stk_config.hpp" @@ -32,6 +34,8 @@ #include "isect.hpp" #include "user_config.hpp" #include "audio/sound_manager.hpp" +#include "graphics/irr_driver.hpp" +#include "graphics/mesh_tools.hpp" #include "graphics/scene.hpp" #include "items/item.hpp" #include "items/item_manager.hpp" @@ -63,6 +67,10 @@ Track::Track( std::string filename_, float w, float h, bool stretch ) m_screenshot = ""; m_top_view = ""; m_version = 0; +#ifdef HAVE_IRRLICHT + m_all_nodes.clear(); + m_all_meshes.clear(); +#endif m_has_final_camera = false; m_is_arena = false; loadTrack(m_filename); @@ -827,9 +835,9 @@ void Track::draw2Dview (float x_offset, float y_offset) const } // draw2Dview //----------------------------------------------------------------------------- -void Track::loadTrack(std::string filename_) +void Track::loadTrack(const std::string &filename) { - m_filename = filename_; + m_filename = filename; m_ident = StringUtils::basename(StringUtils::without_extension(m_filename)); std::string path = StringUtils::without_extension(m_filename); @@ -1085,22 +1093,80 @@ Track::readDrivelineFromFile(std::vector& line, const std::string& file_ex //* Convert the ssg track tree into its physics equivalents. void Track::createPhysicsModel() { +#ifndef HAVE_IRRLICHT if(!m_model) return; +#endif m_track_mesh = new TriangleMesh(); m_non_collision_mesh = new TriangleMesh(); +#ifdef HAVE_IRRLICHT + convertTrackToBullet(); +#else // Collect all triangles in the track_mesh sgMat4 mat; sgMakeIdentMat4(mat); convertTrackToBullet(m_model, mat); m_track_mesh->createBody(); +#endif m_non_collision_mesh->createBody(btCollisionObject::CF_NO_CONTACT_RESPONSE); } // createPhysicsModel // ----------------------------------------------------------------------------- //* Convert the ssg track tree into its physics equivalents. +#ifdef HAVE_IRRLICHT +void Track::convertTrackToBullet() +{ + // 0: start line + // 1: left/right drivelines or so + // 2: road + // 3: zipper or collectables?? + // 4: barriers + // 5: plane + for(unsigned int i=0; igetMeshBufferCount(); i++) { + scene::IMeshBuffer *mb = track->getMeshBuffer(i); + // FIXME: take translation/rotation into accou + if(mb->getVertexType()!=video::EVT_STANDARD) { + fprintf(stderr, "WARNING: Physics::convertTrack: Ignoring type '%d'!", + mb->getVertexType()); + continue; + } + video::SMaterial irrMaterial=mb->getMaterial(); + video::ITexture* t=irrMaterial.getTexture(0); + // FIXME: if no material is given, perhaps define a default? + const Material* material=0; + if(t) { + //material=g_MaterialManager->getMaterial(t->getName()); + printf("%s\n",t->getName()); + } + + u16 *mbIndices = mb->getIndices(); + btVector3 vertices[3]; + irr::video::S3DVertex* mbVertices=(irr::video::S3DVertex*)mb->getVertices(); + for(unsigned int j=0; jgetIndexCount(); j+=3) { + for(unsigned int k=0; k<3; k++) { + int indx=mbIndices[j+k]; + // FIXME: notice: irrlicht's and STK's axis are different + // (STK: Z up, irrlicht: Y up). We might want to change + // this as well, makes it easier to work with bullet and + // irrlicht together, without having to swap indices. + vertices[k] = btVector3( mbVertices[indx].Pos.X, + mbVertices[indx].Pos.Z, + mbVertices[indx].Pos.Y ); + } // for k + m_track_mesh->addTriangle(vertices[0], vertices[1], vertices[2], material); + } // for j + } // for icreateBody(); + +} // convertTrackToBullet + +#else void Track::convertTrackToBullet(ssgEntity *track, sgMat4 m) { if(!track) return; @@ -1166,7 +1232,7 @@ void Track::convertTrackToBullet(ssgEntity *track, sgMat4 m) assert(!"Unkown ssg type in convertTrackToBullet"); } } // convertTrackToBullet - +#endif // ---------------------------------------------------------------------------- void Track::loadTrackModel() { @@ -1184,7 +1250,11 @@ void Track::loadTrackModel() // no temporary materials.dat file, ignore (void)e; } +#ifdef HAVE_IRRLICHT + std::string path = file_manager->getTrackFile(getIdent()+".irrloc"); +#else std::string path = file_manager->getTrackFile(getIdent()+".loc"); +#endif FILE *fd = fopen (path.c_str(), "r" ); if ( fd == NULL ) @@ -1195,8 +1265,11 @@ void Track::loadTrackModel() } // Start building the scene graph +#ifdef HAVE_IRRLICHT +#else m_model = new ssgBranch ; stk_scene->add(m_model); +#endif char s [ 1024 ] ; @@ -1359,10 +1432,11 @@ void Track::loadTrackModel() if ( need_hat ) { sgVec3 nrm ; - +#ifdef HAVE_IRRLICHT +#else loc.xyz[2] = 1000.0f ; loc.xyz[2] = getHeightAndNormal ( m_model, loc.xyz, nrm ) ; - +#endif if ( fit_skin ) { float sy = sin ( -loc.hpr [ 0 ] * SG_DEGREES_TO_RADIANS ) ; @@ -1375,10 +1449,16 @@ void Track::loadTrackModel() } } // if need_hat +#ifdef HAVE_IRRLICHT + std::string full_path = file_manager->getTrackFile(fname, getIdent()); + scene::IAnimatedMesh *obj = irr_driver->getAnimatedMesh(full_path); + m_all_meshes.push_back(obj->getMesh(0)); +#else ssgEntity *obj = loader->load(file_manager->getModelFile(fname), CB_TRACK, /* optimise */ true, /*is_full_path*/ true); +#endif if(!obj) { fclose(fd); @@ -1388,6 +1468,13 @@ void Track::loadTrackModel() file_manager->popModelSearchPath (); throw std::runtime_error(msg.str()); } +#ifdef HAVE_IRRLICHT + // FIXME: for now only static objects + scene::ISceneNode *node = irr_driver->addOctTree(obj->getMesh(0)); + m_all_nodes.push_back(node); + node->setMaterialFlag(video::EMF_LIGHTING, false); + +#else SSGHelp::createDisplayLists(obj); ssgRangeSelector *lod = new ssgRangeSelector ; ssgTransform *trans = new ssgTransform ( & loc ) ; @@ -1398,6 +1485,7 @@ void Track::loadTrackModel() trans -> addKid(lod ); m_model-> addKid(trans ); lod -> setRanges(r, 2); +#endif if(user_config->m_track_debug) addDebugToScene(user_config->m_track_debug); @@ -1414,7 +1502,12 @@ void Track::loadTrackModel() file_manager->popModelSearchPath (); Vec3 min, max; +#ifdef HAVE_IRRLICHT + // FIXME: for now assume that mesh 0 is the actual track. + MeshTools::minMax3D(m_all_meshes[0], &min, &max); +#else SSGHelp::MinMax(m_model, &min, &max); +#endif RaceManager::getWorld()->getPhysics()->init(min, max); createPhysicsModel(); } // loadTrack @@ -1427,7 +1520,10 @@ void Track::itemCommand (sgVec3 *xyz, int type, int bNeedHeight ) if(bNeedHeight) (*xyz)[2] = 1000000.0f; // Even if 3d data are given, make sure that the item is on the ground +#ifdef HAVE_IRRLICHT +#else (*xyz)[2] = getHeight( m_model, *xyz ) + 0.06f; +#endif // Some modes (e.g. time trial) don't have any bonus boxes if(type==ITEM_BONUS_BOX && !RaceManager::getWorld()->enableBonusBoxes()) diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 99a003a88..d07b5dedd 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -15,8 +15,8 @@ // 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_TRACK_H -#define HEADER_TRACK_H +#ifndef HEADER_TRACK_HPP +#define HEADER_TRACK_HPP #ifdef __APPLE__ # include @@ -29,6 +29,10 @@ #endif #include #include +#ifdef HAVE_IRRLICHT +#include "irrlicht.h" +using namespace irr; +#endif #include #include #include "LinearMath/btTransform.h" @@ -52,7 +56,12 @@ private: std::string m_designer; std::string m_filename; std::vector m_groups; - ssgBranch* m_model; +#ifdef HAVE_IRRLICHT + std::vector m_all_nodes; + std::vector m_all_meshes; +#else + ssgBranch *m_model; +#endif TriangleMesh* m_track_mesh; TriangleMesh* m_non_collision_mesh; bool m_has_final_camera; @@ -154,7 +163,10 @@ public: bool isShortcut (const int OLDSEC, const int NEWSEC) const; void addMusic (MusicInformation* mi) {m_music.push_back(mi); } +#ifdef HAVE_IRRLICHT +#else ssgBranch* getModel () const {return m_model; } +#endif float getGravity () const {return m_gravity; } /** Returns the version of the .track file. */ int getVersion () const {return m_version; } @@ -196,13 +208,16 @@ public: } private: - void loadTrack (std::string filename); + void loadTrack (const std::string &filename); void itemCommand (sgVec3 *xyz, int item_type, int bNeedHeight); void loadDriveline (); void readDrivelineFromFile (std::vector& line, const std::string& file_ext); +#ifdef HAVE_IRRLICHT + void convertTrackToBullet (); +#else void convertTrackToBullet (ssgEntity *track, sgMat4 m); - +#endif float pointSideToLine(const Vec3& L1, const Vec3& L2, const Vec3& P ) const; int pointInQuad(const Vec3& A, const Vec3& B, diff --git a/src/tracks/track_manager.cpp b/src/tracks/track_manager.cpp index 8a8719c17..327bab34c 100644 --- a/src/tracks/track_manager.cpp +++ b/src/tracks/track_manager.cpp @@ -131,7 +131,11 @@ void TrackManager::loadTrackList () try { // getTrackFile appends dir, so it's opening: *dir/*dir.track +#ifdef HAVE_IRRLICHT + config_file = file_manager->getTrackFile((*dir)+".irrtrack"); +#else config_file = file_manager->getTrackFile((*dir)+".track"); +#endif } catch (std::exception& e) { diff --git a/src/utils/vec3.hpp b/src/utils/vec3.hpp index ee54e3e35..45c948ab3 100755 --- a/src/utils/vec3.hpp +++ b/src/utils/vec3.hpp @@ -14,9 +14,13 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HEADER_VEC3_H -#define HEADER_VEC3_H +#ifndef HEADER_VEC3_HPP +#define HEADER_VEC3_HPP +#ifdef HAVE_IRRLICHT +#include "irrlicht.h" +using namespace irr; +#endif #define _WINSOCKAPI_ #include @@ -28,8 +32,11 @@ class Vec3 : public btVector3 { private: +#ifdef HAVE_IRRLICHT + core::vector3df m_irr_vector; +#endif inline float clampToUnity(float f) {return f<-1?f:(f>1?1:f);} - void setPitchRoll(const Vec3 &normal); + void setPitchRoll(const Vec3 &normal); public: inline Vec3(sgVec3 a) : btVector3(a[0], a[1], a[2]) {} @@ -54,6 +61,14 @@ public: inline const void setPitch(float f) {m_y = f;} inline const void setRoll(float f) {m_z = f;} float* toFloat() const {return (float*)this; } +#ifdef HAVE_IRRLICHT + /** Converts a Vec3 to an irrlicht 3d floating point vector. */ + const core::vector3df &toIrrVector() + { + m_irr_vector.set(m_x, m_z, m_y); + return m_irr_vector; + } +#endif void degreeToRad(); Vec3& operator=(const btVector3& a) {*(btVector3*)this=a; return *this;} Vec3& operator=(const btMatrix3x3& m) {setHPR(m); return *this;}