Added support for moving physics in network play, fixed incorrect path in VS project file.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2247 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -19,7 +19,7 @@ VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ..
|
||||
top_builddir = ../../..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
@@ -33,10 +33,14 @@ POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
subdir = include
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
target_triplet = @target@
|
||||
subdir = src/enet/include
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/configure.in
|
||||
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
@@ -61,11 +65,16 @@ AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
BULLETTREE = @BULLETTREE@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
@@ -73,8 +82,8 @@ ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
ENETTREE = @ENETTREE@
|
||||
EXEEXT = @EXEEXT@
|
||||
GREP = @GREP@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
@@ -84,6 +93,7 @@ LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
NOREGMOVE = @NOREGMOVE@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
@@ -98,40 +108,57 @@ SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_RANLIB = @ac_ct_RANLIB@
|
||||
ac_ct_STRIP = @ac_ct_STRIP@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
|
||||
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
bullet_LIBS = @bullet_LIBS@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
enet_LIBS = @enet_LIBS@
|
||||
exec_prefix = @exec_prefix@
|
||||
have_sdl_config = @have_sdl_config@
|
||||
have_svnversion = @have_svnversion@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
htmldir = @htmldir@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
openal_LIBS = @openal_LIBS@
|
||||
opengl_LIBS = @opengl_LIBS@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sdl_LIBS = @sdl_LIBS@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target = @target@
|
||||
target_alias = @target_alias@
|
||||
target_cpu = @target_cpu@
|
||||
target_os = @target_os@
|
||||
target_vendor = @target_vendor@
|
||||
SUBDIRS = enet
|
||||
all: all-recursive
|
||||
|
||||
@@ -145,9 +172,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/Makefile'; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/enet/include/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign include/Makefile
|
||||
$(AUTOMAKE) --gnu src/enet/include/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
|
||||
@@ -20,7 +20,7 @@ VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ../..
|
||||
top_builddir = ../../../..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
@@ -34,11 +34,15 @@ POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
subdir = include/enet
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
target_triplet = @target@
|
||||
subdir = src/enet/include/enet
|
||||
DIST_COMMON = $(libenetinclude_HEADERS) $(srcdir)/Makefile.am \
|
||||
$(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/configure.in
|
||||
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
@@ -65,11 +69,16 @@ AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
BULLETTREE = @BULLETTREE@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXX = @CXX@
|
||||
CXXCPP = @CXXCPP@
|
||||
CXXDEPMODE = @CXXDEPMODE@
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
@@ -77,8 +86,8 @@ ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
ENETTREE = @ENETTREE@
|
||||
EXEEXT = @EXEEXT@
|
||||
GREP = @GREP@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
@@ -88,6 +97,7 @@ LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
NOREGMOVE = @NOREGMOVE@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
@@ -102,40 +112,57 @@ SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_RANLIB = @ac_ct_RANLIB@
|
||||
ac_ct_STRIP = @ac_ct_STRIP@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
|
||||
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
bullet_LIBS = @bullet_LIBS@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
enet_LIBS = @enet_LIBS@
|
||||
exec_prefix = @exec_prefix@
|
||||
have_sdl_config = @have_sdl_config@
|
||||
have_svnversion = @have_svnversion@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
htmldir = @htmldir@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
openal_LIBS = @openal_LIBS@
|
||||
opengl_LIBS = @opengl_LIBS@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
sdl_LIBS = @sdl_LIBS@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target = @target@
|
||||
target_alias = @target_alias@
|
||||
target_cpu = @target_cpu@
|
||||
target_os = @target_os@
|
||||
target_vendor = @target_vendor@
|
||||
libenetincludedir = $(includedir)/enet
|
||||
libenetinclude_HEADERS = \
|
||||
types.h \
|
||||
@@ -160,9 +187,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/enet/Makefile'; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/enet/include/enet/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign include/enet/Makefile
|
||||
$(AUTOMAKE) --gnu src/enet/include/enet/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
WholeProgramOptimization="false"
|
||||
AdditionalIncludeDirectories="C:\cygwin\home\joerg\nw\src\enet\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
RuntimeLibrary="2"
|
||||
@@ -151,35 +152,35 @@
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\callbacks.c"
|
||||
RelativePath="..\..\enet\callbacks.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\host.c"
|
||||
RelativePath="..\..\enet\host.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\list.c"
|
||||
RelativePath="..\..\enet\list.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\packet.c"
|
||||
RelativePath="..\..\enet\packet.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\peer.c"
|
||||
RelativePath="..\..\enet\peer.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\protocol.c"
|
||||
RelativePath="..\..\enet\protocol.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\unix.c"
|
||||
RelativePath="..\..\enet\unix.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\win32.c"
|
||||
RelativePath="..\..\enet\win32.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
|
||||
@@ -67,4 +67,5 @@ public:
|
||||
} // serialise
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -44,14 +44,16 @@ void RaceState::serialise()
|
||||
|
||||
// 2. Add information about eaten herrings
|
||||
// ---------------------------------------
|
||||
|
||||
// We can't use sizeof() here, since the data structures might be padded
|
||||
len += 1 + m_herring_info.size()* HerringInfo::getLength();
|
||||
|
||||
// 3. Add rocket positions
|
||||
// -----------------------
|
||||
len += 2 + m_flyable_info.size()*FlyableInfo::getLength();
|
||||
|
||||
// 4. Add collisions
|
||||
// =================
|
||||
len += 1 + m_collision_info.size()*getCharLength();
|
||||
|
||||
// Now add the data
|
||||
// ================
|
||||
allocate(len);
|
||||
@@ -76,7 +78,7 @@ void RaceState::serialise()
|
||||
m_herring_info[i].serialise(this);
|
||||
}
|
||||
|
||||
// 4. Projectiles
|
||||
// 3. Projectiles
|
||||
// --------------
|
||||
addShort(m_flyable_info.size());
|
||||
for(unsigned int i=0; i<m_flyable_info.size(); i++)
|
||||
@@ -84,6 +86,15 @@ void RaceState::serialise()
|
||||
m_flyable_info[i].serialise(this);
|
||||
}
|
||||
|
||||
// 4. Collisions
|
||||
// -------------
|
||||
addChar(m_collision_info.size());
|
||||
for(unsigned int i=0; i<m_collision_info.size(); i++)
|
||||
{
|
||||
addChar(m_collision_info[i]);
|
||||
}
|
||||
m_collision_info.clear();
|
||||
|
||||
} // serialise
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -144,6 +155,25 @@ void RaceState::receive(ENetPacket *pkt)
|
||||
FlyableInfo f(this);
|
||||
m_flyable_info[i] = f;
|
||||
}
|
||||
|
||||
// 4. Collisions
|
||||
// -------------
|
||||
unsigned int num_collisions = getChar();
|
||||
// Collisions are stored as pairs, so handle a pair at a time
|
||||
for(unsigned int i=0; i<num_collisions; i+=2)
|
||||
{
|
||||
signed char kart_id1 = getChar();
|
||||
signed char kart_id2 = getChar();
|
||||
if(kart_id2==-1)
|
||||
{ // kart - track collision
|
||||
world->getKart(kart_id1)->crashed(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
world->getPhysics()->KartKartCollision(world->getKart(kart_id1),
|
||||
world->getKart(kart_id2));
|
||||
}
|
||||
} // for(i=0; i<num_collisions; i+=2)
|
||||
clear(); // free message buffer
|
||||
|
||||
} // receive
|
||||
|
||||
@@ -46,7 +46,10 @@ private:
|
||||
std::vector<FlyableInfo> m_flyable_info;
|
||||
/** Stores the controls of each kart at the beginning of its update(). */
|
||||
std::vector<KartControl> m_kart_controls;
|
||||
|
||||
/** Collision information. This vector stores information about which
|
||||
* kart collided with which kart or track (kartid=-1) */
|
||||
std::vector<signed char> m_collision_info;
|
||||
|
||||
public:
|
||||
/** Initialise the global race state. */
|
||||
RaceState() : Message(MT_RACE_STATE)
|
||||
@@ -57,7 +60,24 @@ private:
|
||||
void herringCollected(int kartid, int herring_id, char add_info=-1)
|
||||
{
|
||||
m_herring_info.push_back(HerringInfo(kartid, herring_id, add_info));
|
||||
}
|
||||
} // herringCollected
|
||||
// --------------------------------------------------------------------
|
||||
/** Collects information about collision in which at least one kart was
|
||||
* involved. Other collision (e.g. projectiles, moving physics) are
|
||||
* not needed on the client, so it's not stored at all. If a kart
|
||||
* track collision happens, the second kart id is -1 (necessary to
|
||||
* play back sound effects). A simple int vector is used to store the
|
||||
* pair of collision, so the first collision is using the index 0 and
|
||||
* 1; the second one 2 and 3 etc.
|
||||
* \param kartId1 World id of the kart involved in the collision.
|
||||
* \param kartId2 World id of the 2nd kart involved in the collision,
|
||||
* or -1 if it's the track (which is the default).
|
||||
*/
|
||||
void addCollision(signed char kartId1, signed char kartId2=-1)
|
||||
{
|
||||
m_collision_info.push_back(kartId1);
|
||||
m_collision_info.push_back(kartId2);
|
||||
} // addCollision
|
||||
// --------------------------------------------------------------------
|
||||
void setNumFlyables(int n) { m_flyable_info.resize(n); }
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
@@ -21,20 +21,23 @@
|
||||
#include "ssg_help.hpp"
|
||||
#include "world.hpp"
|
||||
#include "flyable.hpp"
|
||||
|
||||
#include "moving_physics.hpp"
|
||||
#include "user_config.hpp"
|
||||
#include "sound_manager.hpp"
|
||||
#include "material_manager.hpp"
|
||||
#include "network/race_state.hpp"
|
||||
|
||||
/** Initialise physics. */
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** Initialise physics.
|
||||
* Create the bullet dynamics world.
|
||||
*/
|
||||
Physics::Physics(float gravity) : btSequentialImpulseConstraintSolver()
|
||||
{
|
||||
m_collision_conf = new btDefaultCollisionConfiguration();
|
||||
m_dispatcher = new btCollisionDispatcher(m_collision_conf);
|
||||
|
||||
// FIXME: it might be better to use the track dimension here, but they
|
||||
// are not known at this stage.
|
||||
btVector3 worldMin(-1000, -1000, -1000);
|
||||
btVector3 worldMax( 1000, 1000, 1000);
|
||||
m_axis_sweep = new btAxisSweep3(worldMin, worldMax);
|
||||
@@ -63,7 +66,11 @@ Physics::~Physics()
|
||||
} // ~Physics
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
//* Adds a kart to the physics engine
|
||||
/** Adds a kart to the physics engine.
|
||||
* This adds the rigid body, the vehicle, and the upright constraint.
|
||||
* \param kart The kart to add.
|
||||
* \param vehicle The raycast vehicle object.
|
||||
*/
|
||||
void Physics::addKart(const Kart *kart, btRaycastVehicle *vehicle)
|
||||
{
|
||||
m_dynamics_world->addRigidBody(kart->getBody());
|
||||
@@ -73,7 +80,8 @@ void Physics::addKart(const Kart *kart, btRaycastVehicle *vehicle)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Removes a kart from the physics engine. This is used when rescuing a kart
|
||||
* (and during cleanup).
|
||||
* (and during cleanup).
|
||||
* \param kart The kart to remove.
|
||||
*/
|
||||
void Physics::removeKart(const Kart *kart)
|
||||
{
|
||||
@@ -83,6 +91,9 @@ void Physics::removeKart(const Kart *kart)
|
||||
} // removeKart
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Updates the physics simulation and handles all collisions.
|
||||
* \param dt Time step.
|
||||
*/
|
||||
void Physics::update(float dt)
|
||||
{
|
||||
// Bullet can report the same collision more than once (up to 4
|
||||
@@ -105,6 +116,10 @@ void Physics::update(float dt)
|
||||
for(p=m_all_collisions.begin(); p!=m_all_collisions.end(); ++p)
|
||||
{
|
||||
if(p->a->is(UserPointer::UP_KART)) { // kart-kart collision
|
||||
Kart *a=p->a->getPointerKart();
|
||||
Kart *b=p->b->getPointerKart();
|
||||
race_state->addCollision(a->getWorldKartId(),
|
||||
b->getWorldKartId());
|
||||
KartKartCollision(p->a->getPointerKart(), p->b->getPointerKart());
|
||||
} // if kart-kart collision
|
||||
else // now the first object must be a projectile
|
||||
@@ -132,8 +147,13 @@ void Physics::update(float dt)
|
||||
} // update
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Handles the special case of two karts colliding with each other
|
||||
* If both karts have a bomb, they'll explode immediately
|
||||
/** Handles the special case of two karts colliding with each other, which means
|
||||
* that bombs must be passed on. If both karts have a bomb, they'll explode
|
||||
* immediately. This function is called from physics::update on the server
|
||||
* (and if no networking is used), and from race_state on the client to replay
|
||||
* what happened on the server.
|
||||
* \param kartA First kart involved in the collision.
|
||||
* \param kartB Second kart involved in the collision.
|
||||
*/
|
||||
void Physics::KartKartCollision(Kart *kartA, Kart *kartB)
|
||||
{
|
||||
@@ -167,10 +187,15 @@ void Physics::KartKartCollision(Kart *kartA, Kart *kartB)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** This function is called at each internal bullet timestep. It is used
|
||||
* here to do the collision handling: using the contact manifolds after a
|
||||
* physics time step might miss some collisions (when more than one internal
|
||||
* time step was done, and the collision is added and removed).
|
||||
**/
|
||||
* here to do the collision handling: using the contact manifolds after a
|
||||
* physics time step might miss some collisions (when more than one internal
|
||||
* time step was done, and the collision is added and removed). So this
|
||||
* function stores all collisions in a list, which is then handled after the
|
||||
* actual physics timestep. This list only stores a collision, if it's not
|
||||
* already in the list, so a collisions which is reported more than once is
|
||||
* nevertheless only handled once.
|
||||
* Parameters: see bullet documentation for details.
|
||||
*/
|
||||
btScalar Physics::solveGroup(btCollisionObject** bodies, int numBodies,
|
||||
btPersistentManifold** manifold,int numManifolds,
|
||||
btTypedConstraint** constraints,int numConstraints,
|
||||
@@ -213,21 +238,29 @@ btScalar Physics::solveGroup(btCollisionObject** bodies, int numBodies,
|
||||
if(upB->is(UserPointer::UP_FLYABLE)) // 1.1 projectile hits track
|
||||
m_all_collisions.push_back(upB, upA);
|
||||
else if(upB->is(UserPointer::UP_KART))
|
||||
upB->getPointerKart()->crashed(NULL);
|
||||
{
|
||||
Kart *kart=upB->getPointerKart();
|
||||
race_state->addCollision(kart->getWorldKartId());
|
||||
kart->crashed(NULL);
|
||||
}
|
||||
}
|
||||
// 2) object a is a kart
|
||||
// =====================
|
||||
else if(upA->is(UserPointer::UP_KART))
|
||||
{
|
||||
if(upB->is(UserPointer::UP_TRACK))
|
||||
upA->getPointerKart()->crashed(NULL); // Kart hit track
|
||||
{
|
||||
Kart *kart = upA->getPointerKart();
|
||||
race_state->addCollision(kart->getWorldKartId());
|
||||
kart->crashed(NULL); // Kart hit track
|
||||
}
|
||||
else if(upB->is(UserPointer::UP_FLYABLE))
|
||||
m_all_collisions.push_back(upB, upA); // 2.1 projectile hits kart
|
||||
else if(upB->is(UserPointer::UP_KART))
|
||||
m_all_collisions.push_back(upA, upB); // 2.2 kart hits kart
|
||||
}
|
||||
// 3) object is a projectile
|
||||
// ========================
|
||||
// =========================
|
||||
else if(upA->is(UserPointer::UP_FLYABLE))
|
||||
{
|
||||
if(upB->is(UserPointer::UP_TRACK ) || // 3.1) projectile hits track
|
||||
@@ -252,29 +285,35 @@ btScalar Physics::solveGroup(btCollisionObject** bodies, int numBodies,
|
||||
} // solveGroup
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** A debug draw function to show the track and all karts. */
|
||||
void Physics::draw()
|
||||
{
|
||||
if(user_config->m_bullet_debug)
|
||||
if(!user_config->m_bullet_debug) return;
|
||||
|
||||
int num_objects = m_dynamics_world->getNumCollisionObjects();
|
||||
for(int i=0; i<num_objects; i++)
|
||||
{
|
||||
int num_objects = m_dynamics_world->getNumCollisionObjects();
|
||||
for(int i=0; i<num_objects; i++)
|
||||
btCollisionObject *obj = m_dynamics_world->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if(!body) continue;
|
||||
float m[16];
|
||||
btVector3 wireColor(1,0,0);
|
||||
btDefaultMotionState *myMotion = (btDefaultMotionState*)body->getMotionState();
|
||||
if(myMotion)
|
||||
{
|
||||
btCollisionObject *obj = m_dynamics_world->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
if(!body) continue;
|
||||
float m[16];
|
||||
btVector3 wireColor(1,0,0);
|
||||
btDefaultMotionState *myMotion = (btDefaultMotionState*)body->getMotionState();
|
||||
if(myMotion)
|
||||
{
|
||||
myMotion->m_graphicsWorldTrans.getOpenGLMatrix(m);
|
||||
debugDraw(m, obj->getCollisionShape(), wireColor);
|
||||
}
|
||||
} // for i
|
||||
} // if m_bullet_debug
|
||||
myMotion->m_graphicsWorldTrans.getOpenGLMatrix(m);
|
||||
debugDraw(m, obj->getCollisionShape(), wireColor);
|
||||
}
|
||||
} // for i
|
||||
} // draw
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Helper function for Physics::draw(). It calls the shape drawer from
|
||||
* bullet to render the actual object.
|
||||
* \param m OpenGL matrix to apply.
|
||||
* \param s Collision shape to drwa.
|
||||
* \param color Colour to use.
|
||||
*/
|
||||
void Physics::debugDraw(float m[16], btCollisionShape *s, const btVector3 color)
|
||||
|
||||
{
|
||||
|
||||
@@ -87,23 +87,23 @@ private:
|
||||
void push_back(const UserPointer* a, const UserPointer*b) {
|
||||
push_back(CollisionPair(a, b));
|
||||
}
|
||||
};
|
||||
}; // CollisionList
|
||||
|
||||
CollisionList m_all_collisions;
|
||||
void KartKartCollision(Kart *ka, Kart *kb);
|
||||
|
||||
public:
|
||||
Physics (float gravity);
|
||||
~Physics ();
|
||||
void addKart (const Kart *k, btRaycastVehicle *v);
|
||||
void addBody (btRigidBody* b) {m_dynamics_world->addRigidBody(b);}
|
||||
void removeKart (const Kart *k);
|
||||
void removeBody (btRigidBody* b) {m_dynamics_world->removeRigidBody(b);}
|
||||
void update (float dt);
|
||||
void draw ();
|
||||
Physics (float gravity);
|
||||
~Physics ();
|
||||
void addKart (const Kart *k, btRaycastVehicle *v);
|
||||
void addBody (btRigidBody* b) {m_dynamics_world->addRigidBody(b);}
|
||||
void removeKart (const Kart *k);
|
||||
void removeBody (btRigidBody* b) {m_dynamics_world->removeRigidBody(b);}
|
||||
void KartKartCollision(Kart *ka, Kart *kb);
|
||||
void update (float dt);
|
||||
void draw ();
|
||||
btDynamicsWorld*
|
||||
getPhysicsWorld () const {return m_dynamics_world;}
|
||||
void debugDraw (float m[16], btCollisionShape *s, const btVector3 color);
|
||||
getPhysicsWorld () const {return m_dynamics_world;}
|
||||
void debugDraw (float m[16], btCollisionShape *s, const btVector3 color);
|
||||
virtual btScalar solveGroup(btCollisionObject** bodies, int numBodies,
|
||||
btPersistentManifold** manifold,int numManifolds,
|
||||
btTypedConstraint** constraints,int numConstraints,
|
||||
|
||||
Reference in New Issue
Block a user