diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 5aeb8984f..5a8425e27 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -18,9 +18,10 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "graphics/irr_driver.hpp" -#include "gui/engine.hpp" +#include "material_manager.hpp" #include "user_config.hpp" +#include "gui/engine.hpp" #include "io/file_manager.hpp" IrrDriver *irr_driver = NULL; @@ -31,6 +32,8 @@ IrrDriver::IrrDriver() // Try different drivers: start with opengl, then DirectX for(int driver_type=0; driver_type<3; driver_type++) { + // FIXME: directX+SLD is not supported anyway - so we could + // remove support for this here anyway. video::E_DRIVER_TYPE type = driver_type==0 ? video::EDT_OPENGL : (driver_type==1 @@ -79,7 +82,9 @@ IrrDriver::~IrrDriver() */ scene::IAnimatedMesh *IrrDriver::getAnimatedMesh(const std::string &filename) { - return m_scene_manager->getMesh(filename.c_str()); + scene::IAnimatedMesh *m = m_scene_manager->getMesh(filename.c_str()); + setAllMaterialFlags(m); + return m; } // getAnimatedMesh // ---------------------------------------------------------------------------- @@ -90,9 +95,31 @@ scene::IMesh *IrrDriver::getMesh(const std::string &filename) { scene::IAnimatedMesh *m = m_scene_manager->getMesh(filename.c_str()); if(!m) return NULL; + setAllMaterialFlags(m); return m->getMesh(0); } // getMesh +// ---------------------------------------------------------------------------- +/** Sets the material flags in this mesh depending on the settings in + * material_manager. + * \param mesh The mesh to change the settings in. + */ +void IrrDriver::setAllMaterialFlags(scene::IAnimatedMesh *mesh) const +{ + unsigned int n=mesh->getMeshBufferCount(); + for(unsigned int i=0; igetMeshBuffer(i); + video::SMaterial &irr_material=mb->getMaterial(); + for(unsigned int j=0; jsetAllMaterialFlags(t, mb); + } // for j #include "material_manager.hpp" #include "material.hpp" #include "shadow.hpp" diff --git a/src/gui/state_manager.cpp b/src/gui/state_manager.cpp index b8a498359..f38940909 100644 --- a/src/gui/state_manager.cpp +++ b/src/gui/state_manager.cpp @@ -220,6 +220,7 @@ namespace StateManager void resetAndGoToMenu(std::string name) { + race_manager->exitRace(); input_manager->setMode(InputManager::MENU); g_menu_stack.clear(); g_menu_stack.push_back(name); diff --git a/src/io/xml_node.cpp b/src/io/xml_node.cpp index 1b439d0a3..f119c25ac 100644 --- a/src/io/xml_node.cpp +++ b/src/io/xml_node.cpp @@ -30,6 +30,31 @@ XMLNode::XMLNode(const std::string &name, io::IXMLReader *xml) core::stringw value = xml->getAttributeValue(i); m_attributes[name] = value; } // for i +#ifdef TEST_ONLY + while(xml->read()) + { + switch (xml->getNodeType()) + { + case io::EXN_ELEMENT: break; + case io::EXN_ELEMENT_END: + printf("found end\n"); + break;// Ignore all other types + case io::EXN_UNKNOWN: + printf("found end\n"); + break; + case io::EXN_COMMENT: + printf("found end\n"); + break; + case io::EXN_TEXT: + printf("found end\n"); + break; + default: + printf("found end\n"); + break; + } // switch + + } // while +#endif } // XMLNode // ---------------------------------------------------------------------------- diff --git a/src/io/xml_node.hpp b/src/io/xml_node.hpp index 3b0a4daf8..53d0eade1 100644 --- a/src/io/xml_node.hpp +++ b/src/io/xml_node.hpp @@ -33,12 +33,15 @@ class XMLNode { private: /** Name of this element. */ - std::string m_name; + std::string m_name; /** List of all attributes. */ std::map m_attributes; + /** List of all sub nodes. */ + std::vector m_nodes; public: XMLNode(const std::string &name, io::IXMLReader *xml); const std::string &getName() const {return m_name; } + XMLNode *getNode(const std::string &name); int get(const std::string &attribute, std::string *value) const; int get(const std::string &attribute, int *value) const; int get(const std::string &attribute, float *value) const; diff --git a/src/items/flyable.hpp b/src/items/flyable.hpp index 936255895..af762a8db 100644 --- a/src/items/flyable.hpp +++ b/src/items/flyable.hpp @@ -20,10 +20,9 @@ #ifndef HEADER_FLYABLE_HPP #define HEADER_FLYABLE_HPP -#ifdef HAVE_IRRLICHT #include "irrlicht.h" using namespace irr; -#endif + #include "audio/sfx_manager.hpp" #include "items/powerup_manager.hpp" #include "karts/moveable.hpp" @@ -32,9 +31,6 @@ using namespace irr; class FlyableInfo; class Kart; class MovingPhysics; -#ifndef HAVE_IRRLICHT -class ssgEntity; -#endif class Flyable : public Moveable, public TerrainInfo { @@ -65,11 +61,7 @@ protected: // so we need arrays of these variables to have different values // for bowling balls, missiles, ... static float m_st_speed[POWERUP_MAX]; // Speed of the projectile -#ifdef HAVE_IRRLICHT static scene::IMesh *m_st_model[POWERUP_MAX]; // 3d model -#else - static ssgEntity* m_st_model[POWERUP_MAX]; // 3d model -#endif static float m_st_min_height[POWERUP_MAX]; // min height above track static float m_st_max_height[POWERUP_MAX]; // max height above track static float m_st_force_updown[POWERUP_MAX]; // force pushing up/down @@ -109,13 +101,8 @@ public: * terrain. Missiles can 'follow the terrain' with this adjustment, * but gravity will basically be disabled. */ void setAdjustZVelocity(bool f) { m_adjust_z_velocity = f; } -#ifdef HAVE_IRRLICHT static void init (const lisp::Lisp* lisp, scene::IMesh *model, PowerupType type); -#else - static void init (const lisp::Lisp* lisp, ssgEntity *model, - PowerupType type); -#endif virtual void update (float); void updateFromServer(const FlyableInfo &f, float dt); diff --git a/src/items/rubber_band.cpp b/src/items/rubber_band.cpp index 2497b4925..0be204dc4 100644 --- a/src/items/rubber_band.cpp +++ b/src/items/rubber_band.cpp @@ -45,14 +45,6 @@ RubberBand::RubberBand(Plunger *plunger, const Kart &kart) : m_attached_state = RB_TO_PLUNGER; assert(m_buffer->getVertexType()==video::EVT_STANDARD); - irr::video::S3DVertex* vertices=(video::S3DVertex*)m_buffer->getVertices(); - - video::SColor c(77, 179, 0, 0); - vertices[0].Color = c; - vertices[1].Color = c; - vertices[2].Color = c; - vertices[3].Color = c; - updatePosition(); m_node = irr_driver->addMesh(m_mesh); } // RubberBand diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 5b8853435..e412e8c2e 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -256,13 +256,10 @@ Kart::~Kart() delete m_tuning; delete m_vehicle_raycaster; delete m_uprightConstraint; -#ifdef HAVE_IRRLICHT -#else for(int i=0; igetKartFile(m_model_filename); + std::string full_path = file_manager->getKartFile(m_model_filename, + kart_ident); m_mesh = irr_driver->getMesh(full_path); Vec3 min, max; MeshTools::minMax3D(m_mesh, &min, &max); diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index 759bc87bf..b78bf4049 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -77,11 +77,7 @@ 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 5f9b12ee8..ecae98eb3 100644 --- a/src/karts/moveable.cpp +++ b/src/karts/moveable.cpp @@ -33,6 +33,7 @@ Moveable::Moveable() m_motion_state = 0; m_first_time = true; m_mesh = NULL; + m_animated_mesh = NULL; m_node = NULL; } // Moveable @@ -42,6 +43,9 @@ Moveable::~Moveable() // The body is being removed from the world in kart/projectile if(m_body) delete m_body; if(m_motion_state) delete m_motion_state; + if(m_node) irr_driver->removeNode(m_node); + if(m_mesh) irr_driver->removeMesh(m_mesh); + if(m_animated_mesh) irr_driver->removeMesh(m_animated_mesh); // FIXME LEAK: what about model? ssgDeRefDelete(m_model_transform) } // ~Moveable diff --git a/src/karts/moveable.hpp b/src/karts/moveable.hpp index c51932b99..c041b62f9 100644 --- a/src/karts/moveable.hpp +++ b/src/karts/moveable.hpp @@ -45,7 +45,7 @@ private: Vec3 m_hpr; protected: - UserPointer m_user_pointer; + UserPointer m_user_pointer; scene::IAnimatedMesh *m_animated_mesh; scene::IMesh *m_mesh; scene::ISceneNode *m_node; diff --git a/src/material.cpp b/src/material.cpp index 484fdcd70..f2c1e8a3f 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -30,14 +30,6 @@ #define UCLAMP 1 #define VCLAMP 2 -//----------------------------------------------------------------------------- -Material::Material(unsigned int index) -{ - m_texname = ""; - init (index); - install(); -} // Material - //----------------------------------------------------------------------------- /** Create a new material using the parameters specified in the xml file. * \param node Node containing the parameters for this material. @@ -112,19 +104,22 @@ void Material::init(unsigned int index) //----------------------------------------------------------------------------- void Material::install(bool is_full_path) { - if(m_texname!="") - { - // Avoid irrlicht warning about not being able to load texture. - m_texture = irr_driver->getTexture(file_manager->getTextureFile(m_texname)); - } - if ( m_transparency ) - { - //m_texture->MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; - } - - // FIXME: more parameters need to be set! + // FIXME: do we actually still need the texture here? Irrlicht should + // cache them anyway. + // Avoid irrlicht warning about not being able to load texture. + m_texture = irr_driver->getTexture(file_manager->getTextureFile(m_texname)); // now set the name to the basename, so that all tests work as expected m_texname = StringUtils::basename(m_texname); -} +} // isntall +//----------------------------------------------------------------------------- +/** Sets the appropriate flags in an irrlicht SMaterial. + * \param material The irrlicht SMaterial which gets the flags set. + */ +void Material::setMaterialProperties(scene::IMeshBuffer *mb) const +{ + if(m_transparency) + mb->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; + // FIXME: more parameters need to be set! +} // setMaterialProperties diff --git a/src/material.hpp b/src/material.hpp index 5653483ec..b0e78ad33 100644 --- a/src/material.hpp +++ b/src/material.hpp @@ -51,16 +51,14 @@ private: void install (bool is_full_path=false); public: + Material(const XMLNode *node, int index); + Material(const std::string& fname, int index, + bool is_full_path=false); + ~Material (); - Material(unsigned int index); - Material(const XMLNode *node, int index); - Material(const std::string& fname, int index, bool is_full_path=false); - - ~Material (); - - int matches ( char *tx ) ; + void setMaterialProperties(scene::IMeshBuffer *mb) const; /** Returns the ITexture associated with this material. */ - video::ITexture *getTexture() const { return m_texture; } + video::ITexture *getTexture() const { return m_texture; } bool isIgnore () const { return m_ignore; } bool isZipper () const { return m_zipper; } bool isSphereMap () const { return m_sphere_map; } diff --git a/src/material_manager.cpp b/src/material_manager.cpp index 26a474e98..cf1ea0930 100644 --- a/src/material_manager.cpp +++ b/src/material_manager.cpp @@ -27,8 +27,6 @@ #include "io/xml_node.hpp" #include "utils/string_utils.hpp" -ssgState *fuzzy_gst; - MaterialManager *material_manager=0; MaterialManager::MaterialManager() @@ -43,6 +41,24 @@ MaterialManager::MaterialManager() // be moved into a separate function. } +//----------------------------------------------------------------------------- +/** Searches for the material in the given texture, and calls a function + * in the material to set the irrlicht material flags. + * \param t Pointer to the texture. + * \param mb Pointer to the mesh buffer. +*/ +void MaterialManager::setAllMaterialFlags(video::ITexture* t, + scene::IMeshBuffer *mb) const +{ + const std::string image = StringUtils::basename(t->getName().c_str()); + // Search backward so that temporary (track) textures are found first + for(int i = (int)m_materials.size()-1; i>=0; i-- ) + { + if(m_materials[i]->getTexFname()==image) + m_materials[i]->setMaterialProperties(mb); + } // for i +} // setAllMaterialFlags + //----------------------------------------------------------------------------- int MaterialManager::addEntity(Material *m) { @@ -65,9 +81,6 @@ void MaterialManager::reInit() //----------------------------------------------------------------------------- void MaterialManager::loadMaterial() { - // Create the default/empty material. - m_materials.push_back(new Material(m_materials.size())); - // Use temp material for reading, but then set the shared // material index later, so that these materials are not popped const std::string fname = "materials.xml"; @@ -134,12 +147,6 @@ void MaterialManager::popTempMaterial() } // for i } // popTempMaterial -//----------------------------------------------------------------------------- -Material *MaterialManager::getMaterial ( ssgLeaf *l ) -{ - return m_materials[l -> getExternalPropertyIndex ()] ; -} // getMaterial - //----------------------------------------------------------------------------- /** Returns the material of a given name, if it doesn't exist, it is loaded. * Materials that are just loaded are not permanent, and so get deleted after diff --git a/src/material_manager.hpp b/src/material_manager.hpp index babc50312..8a0acfa18 100644 --- a/src/material_manager.hpp +++ b/src/material_manager.hpp @@ -17,11 +17,12 @@ // 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_MATERIAL_MANAGER_HP +#ifndef HEADER_MATERIAL_MANAGER_HPP #define HEADER_MATERIAL_MANAGER_HPP -#define _WINSOCKAPI_ -#include +#include "irrlicht.h" +using namespace irr; + #include #include @@ -40,8 +41,9 @@ public: MaterialManager(); void loadMaterial (); void reInit (); + void setAllMaterialFlags(video::ITexture* t, + scene::IMeshBuffer *mb) const; int addEntity (Material *m); - Material *getMaterial (ssgLeaf *lf); Material *getMaterial (const std::string& t, bool is_full_path=false, bool make_permanent=false); void addSharedMaterial(const std::string& filename); diff --git a/src/physics/moving_physics.cpp b/src/physics/moving_physics.cpp index 095cdafa0..d396ddc46 100644 --- a/src/physics/moving_physics.cpp +++ b/src/physics/moving_physics.cpp @@ -59,6 +59,7 @@ MovingPhysics::MovingPhysics(const XMLNode *xml_node) } m_mesh = obj->getMesh(0); m_node = irr_driver->addMesh(m_mesh); + //m_node->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL); Vec3 xyz(0,0,0); int result = xml_node->getXYZ(&xyz); if(!XMLNode::hasZ(result)) // needs height diff --git a/src/race_manager.cpp b/src/race_manager.cpp index a80693a77..e3b1cd505 100644 --- a/src/race_manager.cpp +++ b/src/race_manager.cpp @@ -260,7 +260,7 @@ void RaceManager::startNextRace() } // startNextRace //----------------------------------------------------------------------------- /** If there are more races to do, it starts the next race, otherwise it - * calls exit_race to finish the race. + * calls exitRace to finish the race. */ void RaceManager::next() { @@ -284,14 +284,14 @@ void RaceManager::next() network_manager->setState(NetworkManager::NS_MAIN_MENU); else network_manager->setState(NetworkManager::NS_WAIT_FOR_AVAILABLE_CHARACTERS); - exit_race(); + exitRace(); } } // next //----------------------------------------------------------------------------- /** In GP displays the GP result screen, and then deletes the world. */ -void RaceManager::exit_race() +void RaceManager::exitRace() { // Only display the grand prix result screen if all tracks // were finished, and not when a race is aborted. @@ -375,7 +375,7 @@ void RaceManager::exit_race() world = 0; m_track_number = 0; m_active_race = false; -} // exit_Race +} // exitRace //----------------------------------------------------------------------------- /** A kart has finished the race at the specified time (which can be diff --git a/src/race_manager.hpp b/src/race_manager.hpp index 8e79acef8..b6f9ac984 100644 --- a/src/race_manager.hpp +++ b/src/race_manager.hpp @@ -226,7 +226,7 @@ public: void startNew(); // start new race/GP/... void next(); // start the next race or go back to the start screen void rerunRace(); // Rerun the same race again - void exit_race(); // exit a race (and don't start the next one) + void exitRace(); // exit a race (and don't start the next one) /** get information about given mode (returns true if 'mode' is of linear races type) info is stored in its ID for conveniance, see the macros above for exact meaning diff --git a/src/static_ssg.cpp b/src/static_ssg.cpp index e27dd5a21..295b6bc1f 100644 --- a/src/static_ssg.cpp +++ b/src/static_ssg.cpp @@ -19,6 +19,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifdef XX #include "static_ssg.hpp" #include @@ -413,3 +414,6 @@ int InfoTriangle::collision(sgSphere *s) } return 0; } // InfoTriangle::collision + + +#endif \ No newline at end of file diff --git a/src/static_ssg.hpp b/src/static_ssg.hpp index fa7c54f9c..2c14852b6 100644 --- a/src/static_ssg.hpp +++ b/src/static_ssg.hpp @@ -17,6 +17,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#ifdef XX #ifndef _HEADER_STATICSSG_ #define _HEADER_STATICSSG_ @@ -98,3 +99,4 @@ public: int collision(sgSphere *s, AllHits *allHits); }; #endif +#endif \ No newline at end of file diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 2af60fec1..1e72723b4 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -81,6 +81,7 @@ Track::Track( std::string filename_, float w, float h, bool stretch ) Track::~Track() { } // ~Track + //----------------------------------------------------------------------------- /** Removes the physical body from the world. * Called at the end of a race. @@ -1161,7 +1162,7 @@ void Track::convertTrackToBullet(const scene::IMesh *mesh) mb->getVertexType()); continue; } - video::SMaterial irrMaterial=mb->getMaterial(); + video::SMaterial &irrMaterial=mb->getMaterial(); video::ITexture* t=irrMaterial.getTexture(0); const Material* material=0; @@ -1205,6 +1206,15 @@ bool Track::loadMainTrack(const XMLNode &node) exit(-1); } m_all_meshes.push_back(mesh); + + Vec3 min, max; + MeshTools::minMax3D(mesh, &min, &max); + RaceManager::getWorld()->getPhysics()->init(min, max); + // This will (at this stage) only convert the main track model. + convertTrackToBullet(mesh); + m_track_mesh->createBody(); + + scene::ISceneNode *scene_node = irr_driver->addOctTree(mesh); core::vector3df xyz(0,0,0); node.getXYZ(&xyz); @@ -1215,13 +1225,7 @@ bool Track::loadMainTrack(const XMLNode &node) m_all_nodes.push_back(scene_node); scene_node->setMaterialFlag(video::EMF_LIGHTING, false); - Vec3 min, max; - MeshTools::minMax3D(mesh, &min, &max); - RaceManager::getWorld()->getPhysics()->init(min, max); - // This will (at this stage) only convert the main track model. - convertTrackToBullet(mesh); - m_track_mesh->createBody(); return true; } // loadMainTrack @@ -1237,15 +1241,16 @@ void Track::createWater(const XMLNode &node) getIdent()); //scene::IMesh *mesh = irr_driver->getMesh(full_path); - scene::IMesh *mesh = irr_driver->getSceneManager()->getMesh(full_path.c_str()); + scene::IAnimatedMesh *mesh = irr_driver->getSceneManager()->getMesh(full_path.c_str()); + irr_driver->getSceneManager()->addWaterSurfaceSceneNode(mesh->getMesh(0)); // scene::IAnimatedMesh *mesh = irr_driver->getSceneManager()->addHillPlaneMesh("myHill", // core::dimension2d(20,20), // core::dimension2d(40,40), 0, 0, // core::dimension2d(0,0), // core::dimension2d(10,10)); - scene::SMeshBuffer b(*(scene::SMeshBuffer*)(mesh->getMeshBuffer(0))); - scene::SMeshBuffer* buffer = new scene::SMeshBuffer(*(scene::SMeshBuffer*)(mesh->getMeshBuffer(0))); + scene::SMeshBuffer b(*(scene::SMeshBuffer*)(mesh->getMesh(0)->getMeshBuffer(0))); + //scene::SMeshBuffer* buffer = new scene::SMeshBuffer(*(scene::SMeshBuffer*)(mesh->getMeshBuffer(0))); float wave_height = 2.0f; float wave_speed = 300.0f;