1) Prepared support for kart animations.

2) Removed unused plib only loader.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3365 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-04-05 12:53:17 +00:00
parent 0ad78e1168
commit 5e30e66dc2
16 changed files with 74 additions and 341 deletions

View File

@ -157,8 +157,6 @@ supertuxkart_SOURCES = \
highscores.hpp \
highscore_manager.cpp \
highscore_manager.hpp \
loader.cpp \
loader.hpp \
race_manager.cpp \
race_manager.hpp \
main_loop.cpp \

View File

@ -236,7 +236,7 @@ void IrrDriver::removeMesh(scene::IMesh *mesh)
/** Adds an animated mesh to the scene.
* \param mesh The animated mesh to add.
*/
scene::ISceneNode *IrrDriver::addAnimatedMesh(scene::IAnimatedMesh *mesh)
scene::IAnimatedMeshSceneNode *IrrDriver::addAnimatedMesh(scene::IAnimatedMesh *mesh)
{
return m_scene_manager->addAnimatedMeshSceneNode(mesh);
} // addAnimatedMesh
@ -318,6 +318,14 @@ void IrrDriver::setAmbientLight(const video::SColor &light)
*/
void IrrDriver::update(float dt)
{
// FIXME: the run() call interferes with the SDL event handling
// currently implemented in STK (since run() converts all SDL events
// into irrlicht events). To avoid re-writing the STK event handling,
// instead of calling run(), we only update the irrlicht timer (which is
// necessary to get animations to work) - that's the only other operation
// happening in run.
//if(!m_device->run()) return;
m_device->getTimer()->tick();
m_device->getVideoDriver()->beginScene(true, true, video::SColor(255,100,101,140));
m_scene_manager->drawAll();

View File

@ -66,7 +66,8 @@ public:
scene::ISceneNode *addSkyBox(const std::vector<std::string> &texture_names);
void removeNode(scene::ISceneNode *node);
void removeMesh(scene::IMesh *mesh);
scene::ISceneNode *addAnimatedMesh(scene::IAnimatedMesh *mesh);
scene::IAnimatedMeshSceneNode
*addAnimatedMesh(scene::IAnimatedMesh *mesh);
scene::ICameraSceneNode
*addCamera();
void update(float dt);

View File

@ -142,10 +142,6 @@ 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
@ -206,4 +202,3 @@ void Scene::draw(float dt)
glViewport ( 0, 0, user_config->m_width, user_config->m_height ) ;
}

View File

@ -221,10 +221,6 @@
RelativePath="../../../src\isect.cpp"
>
</File>
<File
RelativePath="..\..\loader.cpp"
>
</File>
<File
RelativePath="../../../src\main.cpp"
>
@ -727,10 +723,6 @@
RelativePath="../../../src\isect.hpp"
>
</File>
<File
RelativePath="..\..\loader.hpp"
>
</File>
<File
RelativePath="..\..\main_loop.hpp"
>

View File

@ -29,11 +29,11 @@
#include "network/network_manager.hpp"
#include "utils/constants.hpp"
Attachment::Attachment(Kart* _kart)
Attachment::Attachment(Kart* kart)
{
m_type = ATTACH_NOTHING;
m_time_left = 0.0;
m_kart = _kart;
m_kart = kart;
m_previous_owner = NULL;
m_node = NULL;

View File

@ -187,7 +187,7 @@ void Flyable::getClosestKart(const Kart **minKart, float *minDistSquared,
} // getClosestKart
//-----------------------------------------------------------------------------
void Flyable::update (float dt)
void Flyable::update(float dt)
{
m_time_since_thrown += dt;
if(m_max_lifespan > -1 && m_time_since_thrown > m_max_lifespan) hit(NULL);

View File

@ -17,17 +17,17 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "network/network_manager.hpp"
#include "network/race_state.hpp"
#include "loader.hpp"
#include "items/projectile_manager.hpp"
#include "explosion.hpp"
#include "items/bowling.hpp"
#include "items/cake.hpp"
#include "items/plunger.hpp"
#include "explosion.hpp"
#include "graphics/scene.hpp"
#include "items/powerup_manager.hpp"
#include "items/powerup.hpp"
#include "graphics/scene.hpp"
#include "network/network_manager.hpp"
#include "network/race_state.hpp"
static ssgSelector *find_selector ( ssgBranch *b );

View File

@ -79,6 +79,7 @@ Kart::Kart (const std::string& kart_name, int position,
m_smoke_system = NULL;
m_nitro = NULL;
m_skidmarks = NULL;
m_animated_node = NULL;
m_view_blocked_by_plunger = 0;
@ -1010,7 +1011,12 @@ void Kart::loadData()
{
//float r [ 2 ] = { -10.0f, 100.0f } ;
m_kart_properties->getKartModel()->attachModel(&m_node);
m_kart_properties->getKartModel()->attachModel(&m_animated_node);
//m_kart_properties->getKartModel()->attachModel(&m_node);
m_animated_node->setLoopMode(true);
m_animated_node->setFrameLoop(1,14);
m_animated_node->setAnimationSpeed(15);
createPhysics();
// Attach Particle System

View File

@ -18,8 +18,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_KART_H
#define HEADER_KART_H
#ifndef HEADER_KART_HPP
#define HEADER_KART_HPP
#define _WINSOCKAPI_
#include <plib/sg.h>

View File

@ -76,9 +76,10 @@ KartModel::~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)
void KartModel::attachModel(scene::IAnimatedMeshSceneNode **node)
{
*node = irr_driver->addMesh(m_mesh);
*node = irr_driver->addAnimatedMesh(m_mesh);
for(unsigned int i=0; i<4; i++)
{
m_wheel_node[i] = irr_driver->addMesh(m_wheel_model[i]);
@ -94,7 +95,7 @@ void KartModel::loadModels(const std::string &kart_ident)
{
std::string full_path = file_manager->getKartFile(m_model_filename,
kart_ident);
m_mesh = irr_driver->getMesh(full_path);
m_mesh = irr_driver->getAnimatedMesh(full_path);
Vec3 min, max;
MeshTools::minMax3D(m_mesh, &min, &max);
Vec3 size = max-min;

View File

@ -22,13 +22,8 @@
#include <string>
#define _WINSOCKAPI_
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
using namespace irr;
#else
#include <plib/ssg.h>
#endif
#include "no_copy.hpp"
#include "lisp/lisp.hpp"
@ -42,13 +37,8 @@ using namespace irr;
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
scene::IAnimatedMesh *m_mesh;
/** Value used to indicate undefined entries. */
static float UNDEFINED;
@ -56,16 +46,11 @@ 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];
/** The four scene nodes the wheels are attached to */
scene::ISceneNode *m_wheel_node[4];
#else
/** The four wheel models. */
ssgEntity *m_wheel_model[4];
#endif
/** Filename of the wheel models. */
std::string m_wheel_filename[4];
@ -92,14 +77,8 @@ private:
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. */
@ -115,12 +94,8 @@ public:
~KartModel();
void loadInfo(const lisp::Lisp* lisp);
void loadModels(const std::string &kart_ident);
#ifdef HAVE_IRRLICHT
void attachModel(scene::ISceneNode **node);
scene::IMesh* getModel() const { return m_mesh; }
#else
ssgTransform *getRoot() const { return m_root; }
#endif
void attachModel(scene::IAnimatedMeshSceneNode **node);
scene::IAnimatedMesh* getModel() const { return m_mesh; }
/** Returns the position of a wheel relative to the kart.
* \param i Index of the wheel: 0=front right, 1 = front left, 2 = rear

View File

@ -35,6 +35,7 @@ Moveable::Moveable()
m_mesh = NULL;
m_animated_mesh = NULL;
m_node = NULL;
m_animated_node = NULL;
} // Moveable
//-----------------------------------------------------------------------------
@ -44,19 +45,50 @@ Moveable::~Moveable()
if(m_body) delete m_body;
if(m_motion_state) delete m_motion_state;
if(m_node) irr_driver->removeNode(m_node);
if(m_animated_node) irr_driver->removeNode(m_animated_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
//-----------------------------------------------------------------------------
/** Sets this model to be non-animated.
* \param n The scene node.
*/
void Moveable::setNode(scene::ISceneNode *n)
{
m_node = n;
m_animated_node = NULL;
} // setNode
//-----------------------------------------------------------------------------
/** Sets this model to be animated.
* \param n The animated scene node.
*/
void Moveable::setAnimatedNode(scene::IAnimatedMeshSceneNode *n)
{
m_node = NULL;
m_animated_node = n;
} // setAnimatedNode
//-----------------------------------------------------------------------------
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();
m_node->setPosition(xyz.toIrrVector());
m_node->setRotation(hpr.toIrrHPR());
printf("x %f y %f offx %f offy %f\n",
xyz.x(), xyz.y(), off_xyz.x(), off_xyz.y());
if(m_node)
{
m_node->setPosition(xyz.toIrrVector());
m_node->setRotation(hpr.toIrrHPR());
}
else if(m_animated_node)
{
m_animated_node->setPosition(xyz.toIrrVector());
m_animated_node->setRotation(hpr.toIrrHPR());
}
} // updateGraphics
//-----------------------------------------------------------------------------

View File

@ -49,6 +49,8 @@ protected:
scene::IAnimatedMesh *m_animated_mesh;
scene::IMesh *m_mesh;
scene::ISceneNode *m_node;
scene::IAnimatedMeshSceneNode
*m_animated_node;
int m_first_time ;
btRigidBody *m_body;
KartMotionState *m_motion_state;
@ -57,8 +59,9 @@ public:
Moveable();
virtual ~Moveable();
scene::ISceneNode
*getNode() {return m_node; }
void setNode(scene::ISceneNode *n){m_node = n; }
*getNode() { return m_node ? m_node : m_animated_node; }
void setNode(scene::ISceneNode *n);
void setAnimatedNode(scene::IAnimatedMeshSceneNode *n);
virtual const btVector3
&getVelocity() const {return m_body->getLinearVelocity();}
const btVector3

View File

@ -1,222 +0,0 @@
// $Id: loader.cpp 1610 2008-03-01 03:18:53Z hikerstk $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2004 Steve Baker <sjbaker1@airmail.net>
// (C) 2008 Steve Baker, Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdexcept>
#include <sstream>
#include <sys/stat.h>
#include <string>
#ifdef WIN32
# include <io.h>
# include <stdio.h>
# ifndef __CYGWIN__
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
// Some portabilty defines
# endif
#endif
#include "loader.hpp"
#include "material_manager.hpp"
#include "material.hpp"
#include "graphics/moving_texture.hpp"
#include "io/file_manager.hpp"
#include "physics/physical_object.hpp"
Loader* loader = 0;
Loader::Loader()
{
} // Loader
//-----------------------------------------------------------------------------
Loader::~Loader()
{
} // ~Loader
//-----------------------------------------------------------------------------
void Loader::makeModelPath(char* path, const char* FNAME) const
{
if(m_is_full_path)
{
strcpy(path, FNAME);
return;
}
std::string p=file_manager->getModelFile(FNAME);
strcpy(path, p.c_str());
return;
} // makeModelPath
//-----------------------------------------------------------------------------
/** Loads a .ac model
*
* Loads the .ac model 'filename'. Callbacks contained in this file
* are stored in the callback class t. If optimise is set to false,
* the file will not be flattened, which is necessary for the kart
* models - flattening them will remove the wheel nodes, withouth
* which the wheels do not rotate.
*
* \param filename File to load
*
* \param t Callback category for callbacks included in this
* file (see callback_manager.hpp)
*
* \param optimise Default is true. If set to false, the model will not
* be flattened.
*/
ssgEntity *Loader::load(const std::string& filename,
bool optimise, bool is_full_path)
{
m_is_full_path = is_full_path;
// FIXME: for now
return NULL;
} // load
//-----------------------------------------------------------------------------
#ifndef HAVE_IRRLICHT
void Loader::preProcessObj ( ssgEntity *n, bool mirror )
{
if ( n == NULL ) return ;
n -> dirtyBSphere () ;
if ( n -> isAKindOf ( ssgTypeLeaf() ) )
{
if ( mirror )
for ( int i = 0 ; i < ((ssgLeaf *)n) -> getNumVertices () ; i++ )
((ssgLeaf *)n) -> getVertex ( i ) [ 0 ] *= -1.0f ;
material_manager->getMaterial((ssgLeaf *) n ) -> applyToLeaf ( (ssgLeaf *) n ) ;
return ;
}
if ( mirror && n -> isAKindOf ( ssgTypeTransform () ) )
{
sgMat4 xform ;
((ssgTransform *)n) -> getTransform ( xform ) ;
xform [ 0 ][ 0 ] *= -1.0f ;
xform [ 1 ][ 0 ] *= -1.0f ;
xform [ 2 ][ 0 ] *= -1.0f ;
xform [ 3 ][ 0 ] *= -1.0f ;
((ssgTransform *)n) -> setTransform ( xform ) ;
}
ssgBranch *b = (ssgBranch *) n ;
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' )
data++ ;
const int START_LIM = strtol(data, &data, 0 );
const int END_LIM = strtol(data, &data, 0 );
const float TIME_LIM = (float)strtod(data, &data );
while ( *data <= ' ' && *data != '\0' )
data++ ;
char mode = toupper ( *data ) ;
ssgTimedSelector *br = new ssgTimedSelector;
br->setLimits (START_LIM+1, END_LIM+1 ) ;
br->setDuration(TIME_LIM ) ;
br->setMode ((mode=='O') ? SSG_ANIM_ONESHOT
: (mode=='S') ? SSG_ANIM_SWING
: SSG_ANIM_SHUTTLE ) ;
br->control (SSG_ANIM_START ) ;
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
* to be created, which are then handled by the callback manager.
*/
ssgBranch *Loader::createBranch(char *data) const
{
if ( data == NULL || data[0] != '@' ) return NULL;
data++ ; /* Skip the '@' */
if ( strncmp("billboard", data, strlen("billboard") ) == 0 )
return new ssgCutout();
if ( strncmp("DONT_DELETE", data, strlen("DONT_DELETE") ) == 0 )
{
printf("DONT\n");
ssgBranch *br = new ssgTransform();
br->setUserData(new ssgBase());
return br;
}
if ( strncmp("invisible", data, strlen("invisible") ) == 0 )
return new ssgInvisible();
if ( strncmp ( "switch", data, strlen ( "switch" ) ) == 0 )
{
ssgSelector *sel = new ssgSelector();
sel->select(0);
return sel;
}
if ( strncmp ( "animate", data, strlen ( "animate" ) ) == 0 )
return animInit(data);
if ( strncmp ( "autodcs", data, strlen ( "autodcs" ) ) == 0 )
{
ssgTransform *br = new ssgTransform();
Callback *c = new MovingTexture(data, br);
br->setUserData(new ssgBase());
callback_manager->addCallback(c, m_current_callback_type);
return br;
}
if ( strncmp ( "autotex", data, strlen ( "autotex" ) ) == 0 )
{
ssgTexTrans *br = new ssgTexTrans();
Callback *c = new MovingTexture(data, br);
callback_manager->addCallback(c, m_current_callback_type);
return br;
}
if(strncmp("physics", data, strlen("physics")) == 0)
{
MovingPhysics *mp = new MovingPhysics(std::string(data));
callback_manager->addCallback(mp, m_current_callback_type);
return mp;
}
fprintf(stderr, "Warning: Ignoring userdata '%s'\n", data);
return NULL ;
} // createBranch
#endif

View File

@ -1,56 +0,0 @@
// $Id: loader.hpp 1610 2008-03-01 03:18:53Z hikerstk $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2004 Steve Baker <sjbaker1@airmail.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_LOADER_HPP
#define HEADER_LOADER_HPP
#define _WINSOCKAPI_
#include <plib/ssg.h>
#include <string>
#include <vector>
#include <set>
class Loader : public ssgLoaderOptions
{
private:
bool m_is_full_path;
std::string m_root_dir;
std::vector<std::string> m_texture_search_path,
m_model_search_path,
m_music_search_path;
bool findFile (std::string& full_path,
const std::string& fname,
const std::vector<std::string>& search_path) const;
public:
Loader();
~Loader();
virtual void makeModelPath (char* path, const char* fname) const;
ssgEntity *load(const std::string& filename, bool optimise=true,
bool is_full_path=false);
private:
void makePath (std::string& path, const std::string& dir,
const std::string& fname) const;
};
extern Loader* loader;
#endif