Irrlicht only: Added preliminary support for reading materials.xml files

(though the information is not used atm).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3203 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-02-27 00:15:09 +00:00
parent 9314f6fafb
commit 62bc9990ca
19 changed files with 190 additions and 40 deletions

View File

@ -35,7 +35,9 @@ Nitro::Nitro(Kart* kart)
dirtyBSphere();
m_nitro_fire = new ssgSimpleState ();
#ifndef HAVE_IRRLICHT
m_nitro_fire->setTexture(material_manager->getMaterial("nitro-particle.rgb")->getState()->getTexture());
#endif
m_nitro_fire -> setTranslucent () ;
m_nitro_fire -> enable ( GL_TEXTURE_2D ) ;
m_nitro_fire -> setShadeModel ( GL_SMOOTH ) ;

View File

@ -48,13 +48,14 @@ ssgTransform* createShadow( const std::string& name,
result -> setName ( "Shadow" ) ;
#ifndef HAVE_IRRLICHT
ssgVtxTable *gs = new ssgVtxTable ( GL_TRIANGLE_STRIP, va, na, ta, ca ) ;
// FIXME LEAK: va, na, ta, and ca are most likely leaked, since plib
// will mark them as 'not owned' and therefore not free them!
gs -> clrTraversalMaskBits ( SSGTRAV_ISECT|SSGTRAV_HOT ) ;
gs -> setState ( material_manager->getMaterial ( name.c_str() ) -> getState () ) ;
result -> addKid ( gs ) ;
#endif
return result;
}

View File

@ -36,7 +36,9 @@ Smoke::Smoke(Kart* kart)
dirtyBSphere();
m_smokepuff = new ssgSimpleState ();
#ifndef HAVE_IRRLICHT
m_smokepuff->setTexture(material_manager->getMaterial("smoke.rgb")->getState()->getTexture());
#endif
m_smokepuff -> setTranslucent () ;
m_smokepuff -> enable ( GL_TEXTURE_2D ) ;
m_smokepuff -> setShadeModel ( GL_SMOOTH ) ;

View File

@ -131,8 +131,9 @@ void GrandPrixSelect::update(float dt)
}
mat = material_manager->getMaterial( img_filename, true );
#ifndef HAVE_IRRLICHT
m_track_imgs.push_back(mat->getState()->getTextureHandle());
#endif
}
if( !m_track_imgs.empty() )

View File

@ -59,44 +59,50 @@ HelpPageTwo::HelpPageTwo()
widget_manager->breakLine();
// ------ bubble gum -----
#ifndef HAVE_IRRLICHT
widget_manager->addImgWgt( WTOK_IMG1, 10, 12,
powerup_manager->getIcon(POWERUP_BUBBLEGUM)->getState()->getTextureHandle());
#endif
widget_manager->addTextWgt( WTOK_TXT1, 90, 12,
_("BubbleGum - leave a sticky pink puddle behind you"));
widget_manager->setWgtRoundCorners( WTOK_TXT1, WGT_AREA_RGT );
widget_manager->breakLine();
// ------ cakes -----
#ifndef HAVE_IRRLICHT
widget_manager->addImgWgt(WTOK_IMG2, 10, 12,
powerup_manager->getIcon(POWERUP_CAKE)->getState()->getTextureHandle());
#endif
widget_manager->addTextWgt(WTOK_TXT2, 90, 12,
_("Cake - thrown at the closest rival,\nbest on short ranges and long straights"));
widget_manager->setWgtRoundCorners( WTOK_TXT2, WGT_AREA_RGT );
widget_manager->breakLine();
// ------ bowling balls -----
#ifndef HAVE_IRRLICHT
widget_manager->addImgWgt(WTOK_IMG3, 10, 12,
powerup_manager->getIcon(POWERUP_BOWLING)->getState()->getTextureHandle());
#endif
widget_manager->addTextWgt(WTOK_TXT3, 90, 12,
_("Bowling Ball - bounces off walls. If you are looking back,\nit will be thrown backwards."));
widget_manager->setWgtRoundCorners( WTOK_TXT3, WGT_AREA_RGT );
widget_manager->breakLine();
// ------ zipper -----
#ifndef HAVE_IRRLICHT
widget_manager->addImgWgt(WTOK_IMG4, 10, 12,
powerup_manager->getIcon(POWERUP_ZIPPER)->getState()->getTextureHandle());
#endif
widget_manager->addTextWgt(WTOK_TXT4, 90, 12,
_("Zipper - speed boost"));
widget_manager->setWgtRoundCorners(WTOK_TXT4, WGT_AREA_RGT);
widget_manager->breakLine();
// ------ parachute -----
#ifndef HAVE_IRRLICHT
widget_manager->addImgWgt(WTOK_IMG5, 10, 12,
powerup_manager->getIcon(POWERUP_PARACHUTE)->getState()->getTextureHandle());
#endif
widget_manager->addTextWgt(WTOK_TXT5, 90, 12,
_("Parachute - slows down all karts in a better position!"));
@ -104,8 +110,10 @@ HelpPageTwo::HelpPageTwo()
widget_manager->breakLine();
// ------ anvil -----
#ifndef HAVE_IRRLICHT
widget_manager->addImgWgt(WTOK_IMG6, 10, 12,
powerup_manager->getIcon(POWERUP_ANVIL)->getState()->getTextureHandle());
#endif
widget_manager->addTextWgt(WTOK_TXT6, 90, 12,
_("Anvil - slows down greatly the kart in the first position"));
@ -113,9 +121,10 @@ HelpPageTwo::HelpPageTwo()
widget_manager->breakLine();
// ------ plunger -----
#ifndef HAVE_IRRLICHT
widget_manager->addImgWgt(WTOK_IMG7, 10, 12,
powerup_manager->getIcon(POWERUP_PLUNGER)->getState()->getTextureHandle());
#endif
widget_manager->addTextWgt(WTOK_TXT7, 90, 12,
_("Plunger - throw straight to pull an opponent back,\nor throw while looking back to make one lose sight!"));
widget_manager->setWgtRoundCorners( WTOK_TXT7, WGT_AREA_RGT );

View File

@ -97,6 +97,7 @@ RaceGUI::RaceGUI()
m_pos_string[9] = "9th";
m_pos_string[10] = "10th";
#ifndef HAVE_IRRLICHT
m_speed_back_icon = material_manager->getMaterial("speedback.rgb");
m_speed_back_icon->getState()->disable(GL_CULL_FACE);
m_speed_fore_icon = material_manager->getMaterial("speedfore.rgb");
@ -104,6 +105,7 @@ RaceGUI::RaceGUI()
m_plunger_face = material_manager->getMaterial("plungerface.rgb");
m_plunger_face->getState()->disable(GL_CULL_FACE);
#endif
m_fps_counter = 0;
m_fps_string[0]=0;
@ -370,7 +372,9 @@ void RaceGUI::drawPlayerIcons (const KartIconDisplayInfo* info)
// the same icon is displayed more than once in a row.
if(last_players_gst==players_gst)
{
#ifndef HAVE_IRRLICHT
players_gst->getState()->force();
#endif
}
//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.
@ -942,7 +946,9 @@ void RaceGUI::drawStatusText(const float dt)
if (numPlayers == 3 && pla > 1)
plunger_x = offset_x + user_config->m_width/2 - plunger_size/2;
#ifndef HAVE_IRRLICHT
m_plunger_face->getState()->force();
#endif
glBegin ( GL_QUADS ) ;
glTexCoord2f(1, 0); glVertex2i(plunger_x+plunger_size, offset_y);
glTexCoord2f(0, 0); glVertex2i(plunger_x, offset_y);

View File

@ -328,7 +328,9 @@ void Widget::setFont( const WidgetFont FONT )
void Widget::setTexture( const std::string& FILENAME, bool is_full_path )
{
Material *m = material_manager->getMaterial( FILENAME, is_full_path );
#ifndef HAVE_IRRLICHT
m_texture = m->getState()->getTextureHandle();
#endif
}
/** Initialize a display list containing a rectangle that can have rounded

View File

@ -109,11 +109,6 @@ void Item::update(float delta)
else
{
m_collected = false;
#ifdef HAVE_IRRLICHT
#else
m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord()));
#endif
} // T>0
}

View File

@ -66,11 +66,13 @@ PowerupManager::PowerupManager()
//-----------------------------------------------------------------------------
void PowerupManager::removeTextures()
{
#ifndef HAVE_IRRLICHT
for(int i=0; i<POWERUP_MAX; i++)
{
if(m_all_icons [i]) ssgDeRefDelete(m_all_icons [i]->getState());
if(m_all_models[i]) ssgDeRefDelete(m_all_models[i] );
} // for
#endif
callback_manager->clear(CB_COLLECTABLE);
} // removeTextures
@ -115,6 +117,8 @@ void PowerupManager::LoadNode(const lisp::Lisp* lisp, int collectType )
lisp->get("model", sModel );
lisp->get("icon", sIconFile );
#ifdef HAVE_IRRLICHT
#else
// load material
m_all_icons[collectType] = material_manager->getMaterial(sIconFile,
/* full_path */ false,
@ -123,21 +127,19 @@ void PowerupManager::LoadNode(const lisp::Lisp* lisp, int collectType )
if(sModel!="")
{
#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
{
m_all_models[collectType] = 0;
m_all_extends[collectType] = btVector3(0.0f,0.0f,0.0f);
}
#endif
// Load special attributes for certain powerups
switch (collectType) {

View File

@ -120,8 +120,8 @@ void KartModel::loadModels(const std::string &kart_ident)
Vec3 size = max-min;
m_z_offset = min.getZ();
m_kart_width = size.getX();
m_kart_height = size.getY();
m_kart_length = size.getZ();
m_kart_height = size.getZ();
m_kart_length = size.getY();
// 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.

View File

@ -87,13 +87,19 @@ ssgEntity *Loader::load(const std::string& filename, CallbackType t,
{
m_current_callback_type = t;
m_is_full_path = is_full_path;
#ifdef HAVE_IRRLICHT
// FIXME: for now
return NULL;
#else
ssgEntity *obj = optimise ? ssgLoad (filename.c_str(), this)
: ssgLoadAC(filename.c_str(), this);
preProcessObj(obj, false);
return obj;
#endif
} // load
//-----------------------------------------------------------------------------
#ifndef HAVE_IRRLICHT
void Loader::preProcessObj ( ssgEntity *n, bool mirror )
{
if ( n == NULL ) return ;
@ -127,8 +133,9 @@ void Loader::preProcessObj ( ssgEntity *n, bool mirror )
for ( int i = 0 ; i < b -> getNumKids () ; i++ )
preProcessObj ( b -> getKid ( i ), mirror ) ;
}
#endif
//-----------------------------------------------------------------------------
#ifndef HAVE_IRRLICHT
ssgBranch *Loader::animInit (char *data ) const
{
while ( ! isdigit ( *data ) && *data != '\0' )
@ -155,8 +162,9 @@ ssgBranch *Loader::animInit (char *data ) const
return br;
} // animInit
#endif
//-----------------------------------------------------------------------------
#ifndef HAVE_IRRLICHT
/** Handle userdata that is stored in the model files. Mostly the userdata
* indicates that a special branch is to be created (e.g. a ssgCutout instead
* of the standard branch). But some userdata indicate that callbacks need
@ -220,4 +228,4 @@ ssgBranch *Loader::createBranch(char *data) const
fprintf(stderr, "Warning: Ignoring userdata '%s'\n", data);
return NULL ;
} // createBranch
#endif

View File

@ -52,9 +52,11 @@ private:
void makePath (std::string& path, const std::string& dir,
const std::string& fname) const;
#ifndef HAVE_IRRLICHT
ssgBranch *createBranch (char *data) const;
void preProcessObj( ssgEntity *n, bool mirror );
ssgBranch *animInit (char *data) const;
#endif
};
extern Loader* loader;

View File

@ -444,7 +444,9 @@ void InitTuxkart()
irr_driver = new IrrDriver();
#endif
loader = new Loader();
#ifndef HAVE_IRRLICHT
loader->setCreateStateCallback(getAppState);
#endif
sound_manager = new SoundManager();
sfx_manager = new SFXManager();
// The order here can be important, e.g. KartPropertiesManager needs

View File

@ -53,10 +53,14 @@ void MainLoop::loadBackgroundImages()
{
int ind = user_config->getBackgroundIndex();
const std::string &main = stk_config->getMainMenuPicture(ind);
#ifndef HAVE_IRRLICHT
m_title_screen_texture = material_manager->getMaterial(main)->getState()->getTextureHandle();
#endif
const std::string &background = stk_config->getBackgroundPicture(ind);
#ifndef HAVE_IRRLICHT
m_bg_texture = material_manager->getMaterial(background)->getState()->getTextureHandle();
#endif
} // loadBackgroundImages
//-----------------------------------------------------------------------------

View File

@ -18,9 +18,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "material.hpp"
#include <stdexcept>
#include "file_manager.hpp"
#include "stk_config.hpp"
#include "io/xml_node.hpp"
#include "utils/string_utils.hpp"
#define UCLAMP 1
@ -44,6 +47,7 @@ int setSpheremap ( ssgEntity * )
} // setSpheremap
//=============================================================================
#ifndef HAVE_IRRLICHT
bool Material::parseBool ( char **p )
{
/* Skip leading spaces */
@ -76,18 +80,66 @@ float Material::parseFloat ( char **p )
return (float)strtod ( *p, p ) ;
} // parseFloat
#endif
//-----------------------------------------------------------------------------
Material::Material(int index)
Material::Material(unsigned int index)
{
m_texname = "";
#ifndef HAVE_IRRLICHT
m_predraw = m_postdraw = NULL ;
#endif
init (index);
install();
} // Material
//-----------------------------------------------------------------------------
#ifdef HAVE_IRRLICHT
/** Create a new material using the parameters specified in the xml file.
* \param node Node containing the parameters for this material.
* \param index Index in material_manager.
*/
Material::Material(const XMLNode *node, int index)
{
node->get("name", &m_texname);
if(m_texname=="")
{
throw std::runtime_error("No texture name specified in %s file\n");
}
init(index);
bool b=false;
node->get("clampU", &b); if(b) m_clamp_tex +=UCLAMP;
b=false;
node->get("clampV", &b); if(b) m_clamp_tex +=VCLAMP;
node->get("transparency", &m_transparency );
node->get("alpha", &m_alpha_ref );
node->get("light", &m_lighting );
node->get("sphere", &m_sphere_map );
node->get("friction", &m_friction );
node->get("ignore", &m_ignore );
node->get("zipper", &m_zipper );
node->get("reset", &m_resetter );
node->get("collide", &m_collideable );
node->get("maxSpeed", &m_max_speed_fraction);
node->get("slowdownTime", &m_slowdown );
install(/*is_full_path*/false);
} // Material
//-----------------------------------------------------------------------------
/** Create a standard material using the default settings for materials.
* \param fname Name of the texture file.
* \param index Unique index in material_manager.
* \param is_full_path If the fname contains the full path.
*/
Material::Material(const std::string& fname, int index, bool is_full_path)
{
m_texname = fname;
init(index);
install(is_full_path);
} // Material
#else
Material::Material(const std::string& fname, char *description,
int index, bool is_full_path)
{
@ -120,15 +172,18 @@ Material::Material(const std::string& fname, char *description,
}
install(is_full_path);
} // Material
#endif
//-----------------------------------------------------------------------------
Material::~Material()
{
#ifndef HAVE_IRRLICHT
ssgDeRefDelete(m_state);
#endif
} // ~Material
//-----------------------------------------------------------------------------
void Material::init(int index)
void Material::init(unsigned int index)
{
m_index = index ;
m_clamp_tex = 0 ;
@ -146,15 +201,18 @@ void Material::init(int index)
}
//-----------------------------------------------------------------------------
#ifndef HAVE_IRRLICHT
void Material::applyToLeaf(ssgLeaf *l)
{
if ( m_predraw ) l -> setCallback ( SSG_CALLBACK_PREDRAW , m_predraw ) ;
if ( m_postdraw ) l -> setCallback ( SSG_CALLBACK_POSTDRAW, m_postdraw ) ;
} // applyToLeaf
#endif
//-----------------------------------------------------------------------------
void Material::install(bool is_full_path)
{
#ifdef HAVE_IRRLICHT
#else
if ( isSphereMap () )
{
m_predraw = setSpheremap ;
@ -206,6 +264,7 @@ void Material::install(bool is_full_path)
m_state -> setOpaque () ;
m_state -> disable ( GL_BLEND ) ;
}
#endif
// now set the name to the basename, so that all tests work as expected
m_texname = StringUtils::basename(m_texname);

View File

@ -24,13 +24,18 @@
#define _WINSOCKAPI_
#include <plib/ssg.h>
class XMLNode;
class Material
{
private:
#ifdef HAVE_IRRLICHT
#else
ssgSimpleState *m_state;
ssgCallback m_predraw;
ssgCallback m_postdraw;
int m_index;
#endif
unsigned int m_index;
std::string m_texname;
bool m_collideable;
bool m_zipper;
@ -46,26 +51,32 @@ private:
float m_slowdown;
/** Maximum speed at which no more slow down occurs. */
float m_max_speed_fraction;
#ifndef HAVE_IRRLICHT
bool parseBool ( char **p );
int parseInt ( char **p );
float parseFloat ( char **p );
void init (int index);
#endif
void init (unsigned int index);
void install (bool is_full_path=false);
public:
Material(int index);
Material(unsigned int index);
#ifdef HAVE_IRRLICHT
Material(const XMLNode *node, int index);
Material(const std::string& fname, int index, bool is_full_path=false);
#else
Material(const std::string& fname, char *description, int index,
bool is_full_path=false);
#endif
~Material ();
int matches ( char *tx ) ;
#ifndef HAVE_IRRLICHT
ssgSimpleState
*getState () const { return m_state ; }
#endif
bool isIgnore () const { return m_ignore; }
bool isZipper () const { return m_zipper; }
bool isSphereMap () const { return m_sphere_map; }
@ -80,10 +91,11 @@ public:
/** Returns the slowdown that happens if a kart is
* faster than the maximum speed. */
float getSlowDown () const { return m_slowdown; }
#ifndef HAVE_IRRLICHT
void apply () { m_state ->apply(); }
void force () { m_state ->force(); }
void applyToLeaf ( ssgLeaf *l ) ;
void applyToLeaf ( ssgLeaf *l ) ;
#endif
} ;

View File

@ -24,6 +24,7 @@
#include "file_manager.hpp"
#include "material.hpp"
#include "io/xml_node.hpp"
#include "utils/string_utils.hpp"
ssgState *fuzzy_gst;
@ -65,16 +66,21 @@ void MaterialManager::reInit()
void MaterialManager::loadMaterial()
{
// Create the default/empty material.
m_materials.push_back(new Material((int)m_materials.size()));
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
#ifdef HAVE_IRRLICHT
const std::string fname = "materials.xml";
#else
const std::string fname = "materials.dat";
#endif
std::string full_name = file_manager->getTextureFile(fname);
addSharedMaterial(full_name);
#ifndef HAVE_IRRLICHT
ssgSetAppStateCallback(getAppState);
fuzzy_gst = getMaterial("fuzzy.rgb")->getState();
#endif
// Save index of shared textures
m_shared_material_index = (int)m_materials.size();
} // MaterialManager
@ -102,6 +108,29 @@ void MaterialManager::addSharedMaterial(const std::string& filename)
//-----------------------------------------------------------------------------
bool MaterialManager::pushTempMaterial(const std::string& filename)
{
#ifdef HAVE_IRRLICHT
XMLReader *xml = file_manager->getXMLReader(filename);
for(unsigned int i=0; i<xml->getNumNodes(); i++)
{
const XMLNode *node = xml->getNode(i);
if(!node)
{
// We don't have access to the filename at this stage anymore :(
fprintf(stderr, "Unknown node in material.dat file\n");
exit(-1);
}
try
{
m_materials.push_back(new Material(node, m_materials.size() ));
}
catch(std::exception& e)
{
// The message contains a '%s' for the filename
fprintf(stderr, e.what(), filename.c_str());
}
} // for i<xml->getNumNodes)(
return true;
#else
FILE *fd = fopen(filename.c_str(), "r" );
if ( fd == NULL ) return false;
@ -111,6 +140,7 @@ bool MaterialManager::pushTempMaterial(const std::string& filename)
fclose ( fd ) ;
return true;
#endif
} // pushTempMaterial
//-----------------------------------------------------------------------------
@ -124,6 +154,7 @@ void MaterialManager::popTempMaterial()
} // popTempMaterial
//-----------------------------------------------------------------------------
#ifndef HAVE_IRRLICHT
char* MaterialManager::parseFileName(char **str)
{
char *p = *str ;
@ -158,8 +189,9 @@ char* MaterialManager::parseFileName(char **str)
return f ;
} // parseFilename
#endif
//-----------------------------------------------------------------------------
#ifndef HAVE_IRRLICHT
int MaterialManager::parseMaterial ( FILE *fd )
{
char str [ 1024 ] ;
@ -177,13 +209,14 @@ int MaterialManager::parseMaterial ( FILE *fd )
if ( f != NULL )
{
m_materials.push_back(new Material (f, s, (int)m_materials.size() ));
m_materials.push_back(new Material (f, s, m_materials.size() ));
return true ;
}
}
return false ;
} // parseMaterial
#endif
//-----------------------------------------------------------------------------
Material *MaterialManager::getMaterial ( ssgLeaf *l )
@ -229,16 +262,22 @@ Material *MaterialManager::getMaterial(const std::string& fname,
}
// Add the new material
Material* m=new Material(fname,"", (int)m_materials.size(), is_full_path);
#ifdef HAVE_IRRLICHT
Material* m=new Material(fname, m_materials.size(), is_full_path);
#else
Material* m=new Material(fname, "", m_materials.size(), is_full_path);
#endif
m_materials.push_back(m);
if(make_permanent) m_shared_material_index = (int)m_materials.size();
return m ;
} // getMaterial
//=============================================================================
#ifndef HAVE_IRRLICHT
ssgState *getAppState ( char *fname )
{
Material *m = material_manager->getMaterial ( fname ) ;
return ( m == NULL ) ? NULL : m -> getState () ;
} // getAppState
#endif

View File

@ -26,13 +26,16 @@
#include <vector>
class Material;
class XMLReader;
class MaterialManager
{
private:
#ifndef HAVE_IRRLICHT
char *parseFileName(char **str);
int parseMaterial(FILE *fd);
#endif
void parseMaterialFile(const std::string& filename);
int m_shared_material_index;
@ -51,8 +54,9 @@ public:
};
extern ssgState *fuzzy_gst;//, *herringbones_gst;
#ifndef HAVE_IRRLICHT
ssgState *getAppState ( char *fname ) ;
#endif
extern MaterialManager *material_manager;
#endif

View File

@ -111,9 +111,9 @@ void Vec3::setPitchRoll(const Vec3 &normal)
#ifdef HAVE_IRRLICHT
const core::vector3df Vec3::toIrrHPR() const
{
core::vector3df r(RAD_TO_DEGREE( getZ()),
core::vector3df r(RAD_TO_DEGREE( getY()),
RAD_TO_DEGREE(-getX()),
RAD_TO_DEGREE( getY()) );
RAD_TO_DEGREE(-getZ()) );
return r;
} // toIrrHPR