1) Support for transparency added (mainly lighthouse track).

2) More cleanup, tests, ...


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3304 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-03-26 23:31:00 +00:00
parent dddb98310e
commit 247914b566
23 changed files with 142 additions and 92 deletions

View File

@ -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; i<n; i++)
{
scene::IMeshBuffer *mb = mesh->getMeshBuffer(i);
video::SMaterial &irr_material=mb->getMaterial();
for(unsigned int j=0; j<video::MATERIAL_MAX_TEXTURES; j++)
{
video::ITexture* t=irr_material.getTexture(j);
if(!t) continue;
material_manager->setAllMaterialFlags(t, mb);
} // for j<MATERIAL_MAX_TEXTURES
} // for i<getMeshBufferCount()
} // setAllMaterialFlags
// ----------------------------------------------------------------------------
/** Converts the mesh into a water scene node.
* \param mesh The mesh which is converted into a water scene node.

View File

@ -38,6 +38,8 @@ private:
/** Irrlicht race font. */
irr::gui::IGUIFont *m_race_font;
void setAllMaterialFlags(scene::IAnimatedMesh *mesh) const;
public:
IrrDriver();
~IrrDriver();

View File

@ -18,6 +18,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <plib/ssg.h>
#include "material_manager.hpp"
#include "material.hpp"
#include "shadow.hpp"

View File

@ -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);

View File

@ -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
// ----------------------------------------------------------------------------

View File

@ -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<std::string, core::stringw> m_attributes;
/** List of all sub nodes. */
std::vector<XMLNode *> 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;

View File

@ -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);

View File

@ -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

View File

@ -256,13 +256,10 @@ Kart::~Kart()
delete m_tuning;
delete m_vehicle_raycaster;
delete m_uprightConstraint;
#ifdef HAVE_IRRLICHT
#else
for(int i=0; i<m_kart_chassis.getNumChildShapes(); i++)
{
delete m_kart_chassis.getChildShape(i);
}
#endif
} // ~Kart
//-----------------------------------------------------------------------------

View File

@ -92,7 +92,8 @@ void KartModel::attachModel(scene::ISceneNode **node)
*/
void KartModel::loadModels(const std::string &kart_ident)
{
std::string full_path = file_manager->getKartFile(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);

View File

@ -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)
{

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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; }

View File

@ -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

View File

@ -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 <plib/ssg.h>
#include "irrlicht.h"
using namespace irr;
#include <string>
#include <vector>
@ -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);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <algorithm>
@ -413,3 +414,6 @@ int InfoTriangle::collision(sgSphere *s)
}
return 0;
} // InfoTriangle::collision
#endif

View File

@ -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

View File

@ -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<f32>(20,20),
// core::dimension2d<u32>(40,40), 0, 0,
// core::dimension2d<f32>(0,0),
// core::dimension2d<f32>(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;