Bound T2Bullet to T2's update tick; got rid of the old timing code

This commit is contained in:
Robert MacGregor 2015-06-29 18:46:52 -04:00
parent ea2542532f
commit 96f77ba232
8 changed files with 120 additions and 288 deletions

View file

@ -121,7 +121,6 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="source\CGameTime.cpp" />
<ClCompile Include="source\CRigidBody.cpp" /> <ClCompile Include="source\CRigidBody.cpp" />
<ClCompile Include="source\dllmain.cpp" /> <ClCompile Include="source\dllmain.cpp" />
<ClCompile Include="source\t2ConCmds.cpp" /> <ClCompile Include="source\t2ConCmds.cpp" />
@ -394,7 +393,6 @@
<ClInclude Include="include\bullet\vectormath\sse\vectormath_aos.h" /> <ClInclude Include="include\bullet\vectormath\sse\vectormath_aos.h" />
<ClInclude Include="include\bullet\vectormath\sse\vec_aos.h" /> <ClInclude Include="include\bullet\vectormath\sse\vec_aos.h" />
<ClInclude Include="include\bullet\vectormath\vmInclude.h" /> <ClInclude Include="include\bullet\vectormath\vmInclude.h" />
<ClInclude Include="include\CGameTime.h" />
<ClInclude Include="include\config.h" /> <ClInclude Include="include\config.h" />
<ClInclude Include="include\CRigidBody.h" /> <ClInclude Include="include\CRigidBody.h" />
<ClInclude Include="include\stdafx.h" /> <ClInclude Include="include\stdafx.h" />

View file

@ -1,42 +0,0 @@
/*
* CGameTime.h
* Small singleton class that is used for some time-sensitive operations.
* Copyright (c) 2013 Robert MacGregor
*/
#ifndef _INCLUDE_CGAMETIME_H_
#define _INCLUDE_CGAMETIME_H_
#include <time.h>
//! Root Game Namespace
namespace Game
{
//! Singleton class for timing functions in FBLA
class CGameTime
{
public:
//! Get the instance
static CGameTime *getPointer(void);
//! Destroys the instance
static void destroy(void);
//! Update Timer
void update(void);
//! Returns the simtime in seconds
float getSimTime(void);
//! Returns the delta time in seconds
float getDelta(void);
private:
//! Default Constructor
CGameTime(void);
//! Default Destructor
~CGameTime(void);
float time_current_seconds, time_last_seconds, time_delta_seconds;
float time_current_clocks, time_last_clocks, time_delta_clocks;
}; // End Class CGameTime
} // End Namespace Game
#endif // _INCLUDE_CGAMETIME_H_

View file

@ -30,5 +30,4 @@
// TODO: reference additional headers your program requires here // TODO: reference additional headers your program requires here
#include <LinkerAPI.h> #include <LinkerAPI.h>
#include <btBulletDynamicsCommon.h> #include <btBulletDynamicsCommon.h>
#include "CGameTime.h"
#include "config.h" #include "config.h"

View file

@ -14,7 +14,6 @@ const char* conGetVariable(Linker::SimObject *obj,S32 argc, const char* argv[]);
// --- BulletDLL functions ------------------------------------------------ // --- BulletDLL functions ------------------------------------------------
bool conBulletInitialize(Linker::SimObject *obj, S32 argc, const char *argv[]); bool conBulletInitialize(Linker::SimObject *obj, S32 argc, const char *argv[]);
bool conBulletDeinitialize(Linker::SimObject *obj, S32 argc, const char *argv[]); bool conBulletDeinitialize(Linker::SimObject *obj, S32 argc, const char *argv[]);
bool conBulletUpdate(Linker::SimObject *obj, S32 argc, const char *argv[]);
// --- Get Commands ------------------------------------------------------- // --- Get Commands -------------------------------------------------------
const char *conBulletGetPosition(Linker::SimObject *obj, S32 argc, const char *argv[]); const char *conBulletGetPosition(Linker::SimObject *obj, S32 argc, const char *argv[]);
@ -29,3 +28,5 @@ bool conBulletSetRotation(Linker::SimObject *obj, S32 argc, const char *argv[]);
// --- Scene Addition Commands -------------------------------------------- // --- Scene Addition Commands --------------------------------------------
const char *conBulletCreateCube(Linker::SimObject *obj, S32 argc, const char *argv[]); const char *conBulletCreateCube(Linker::SimObject *obj, S32 argc, const char *argv[]);
void updateBullet(const unsigned int& timeDifference);

View file

@ -13,7 +13,7 @@ $Bullet::PhysicsUpdateMS = 100; // The delay in milliseconds before updating sta
//--------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------
// Geek code. // Geek code.
//====================================================================== //======================================================================
function StaticShape::setMass(%this,%mass) function StaticShape::setMass(%this, %mass)
{ {
if (%this.bullet_id $= "") if (%this.bullet_id $= "")
{ {
@ -25,7 +25,7 @@ function StaticShape::setMass(%this,%mass)
%id = bulletCreateCube(%mass, getWord(%size, 0)/2, %id = bulletCreateCube(%mass, getWord(%size, 0)/2,
getWord(%size, 1)/2, getWord(%size, 1)/2,
getWord(%size, 2)/2); getWord(%size, 2)/2, %this);
%this.bullet_id = %id; %this.bullet_id = %id;
%this.bullet_mass = %mass; %this.bullet_mass = %mass;
bulletSetPosition(%id, getWord(%position, 0), bulletSetPosition(%id, getWord(%position, 0),
@ -64,28 +64,6 @@ function StaticShape::setMass(%this,%mass)
return true; return true;
} }
function bulletPhysicsUpdate()
{
cancel($Bullet::ScheduleID);
if (!bulletInitialized() || !$Bullet::Enabled)
{
$Bullet::ObjectCount = 0;
return false;
}
bulletUpdate();
for (%i = 0; %i < $Bullet::ObjectCount; %i++)
{
%object = $Bullet::ObjectArray[%i];
%object.setWorldBoxCenter(bulletGetPosition(%object.bullet_id));
%rotation = bulletGetRotation(%object.bullet_id);
%object.setRotation(%rotation);
}
$Bullet::ScheduleID = schedule($Bullet::PhysicsUpdateMS,0,"bulletPhysicsUpdate");
return true;
}
$Bullet::Enabled = false; $Bullet::Enabled = false;
$Bullet::ScheduleID = 0; $Bullet::ScheduleID = 0;
$Bullet::ObjectCount = 0; $Bullet::ObjectCount = 0;
@ -103,12 +81,16 @@ function ccTogglePhysics(%sender)
$Bullet::Enabled = !$Bullet::Enabled; $Bullet::Enabled = !$Bullet::Enabled;
if ($Bullet::Enabled) if ($Bullet::Enabled)
{ {
messageAll('msgAll', "\c3" @ %sender.namebase SPC "has enabled Bullet physics! ~wfx/misc/bounty_completed.wav"); messageAll('msgAll', "\c3" @ %sender.namebase SPC "has enabled Bullet physics! ~wfx/misc/bounty_completed.wav");
bulletPhysicsUpdate(); bulletInitialize();
} }
else else
{
messageAll('msgAll', "\c3" @ %sender.namebase SPC "has disabled Bullet physics! ~wfx/misc/bounty_completed.wav"); messageAll('msgAll', "\c3" @ %sender.namebase SPC "has disabled Bullet physics! ~wfx/misc/bounty_completed.wav");
bulletDeinitialize();
}
return true; return true;
} }

View file

@ -1,75 +0,0 @@
/*
* CGameTime.cpp
* Small singleton class that is used for some time-sensitive operations.
* Copyright (c) 2013 Robert MacGregor
*/
#include <stdafx.h>
#include <CGameTime.h>
//! Root Game Namespace
namespace Game
{
// This stores an instance of our CGameTime class that is returned at all times except when it is NULL, for which it is then created.
CGameTime *time_instance = NULL;
//! Default Constructor
CGameTime::CGameTime(void) : time_current_seconds(0), // The current sim time in seconds
time_last_seconds(0), // The last stored sim time in seconds
time_delta_seconds(0), // The delta between the current and last sim times in seconds
time_current_clocks(0), // The current sim time in clocks
time_last_clocks(0), // The last sim time in clocks
time_delta_clocks(0) // The delta between the current and last sim times in clocks
{
} // End Default Constructor
//! Default Destructor
CGameTime::~CGameTime(void)
{
} // End Default Destructor
//! Gets the stored instance of CGameTime if it already exists
CGameTime *CGameTime::getPointer(void)
{
if (time_instance == NULL)
time_instance = new CGameTime();
return time_instance;
}
//! Destroys the stored instance of CGameTime
void CGameTime::destroy(void)
{
if (time_instance != NULL)
{
delete time_instance;
time_instance = NULL;
}
}
//! Updates all of the stored times on the instance of CGameTime
void CGameTime::update(void)
{
time_last_clocks = time_current_clocks;
time_current_clocks = clock();
time_delta_clocks = time_current_clocks-time_last_clocks;
// Conversions prevent you trying to divide an integer which would only return 0
time_last_seconds = (float)time_last_clocks/CLOCKS_PER_SEC;
time_current_seconds = (float)time_current_clocks/CLOCKS_PER_SEC;
time_delta_seconds = (float)time_delta_clocks/CLOCKS_PER_SEC;
}
//! Returns the simtime in seconds
float CGameTime::getSimTime(void)
{
return time_current_seconds;
}
//! Returns the delta sim time in seconds
float CGameTime::getDelta(void)
{
return time_delta_seconds;
}
} // End Namespace Game

View file

@ -24,7 +24,6 @@ extern "C"
{ {
Con::addMethodB(NULL, "bulletInitialize", &conBulletInitialize, "Initializes the Bullet physics system.", 0, 0); Con::addMethodB(NULL, "bulletInitialize", &conBulletInitialize, "Initializes the Bullet physics system.", 0, 0);
Con::addMethodB(NULL, "bulletDeinitialize", &conBulletDeinitialize, "Deinitializes the Bullet physics system.", 0, 0); Con::addMethodB(NULL, "bulletDeinitialize", &conBulletDeinitialize, "Deinitializes the Bullet physics system.", 0, 0);
Con::addMethodB(NULL, "bulletUpdate", &conBulletUpdate, "Updates the Bullet physics system. Call this as often as your system can handle.", 0, 0);
Con::addMethodS(NULL, "bulletGetPosition", &conBulletGetPosition, "Queries Bullet for the position of the object identified by the input id.", 2, 2); Con::addMethodS(NULL, "bulletGetPosition", &conBulletGetPosition, "Queries Bullet for the position of the object identified by the input id.", 2, 2);
Con::addMethodS(NULL, "bulletGetRotation", &conBulletGetRotation, "Queries Bullet for the rotation of the object identified by the input id.", 2, 2); Con::addMethodS(NULL, "bulletGetRotation", &conBulletGetRotation, "Queries Bullet for the rotation of the object identified by the input id.", 2, 2);
@ -33,13 +32,13 @@ extern "C"
Con::addMethodB(NULL, "bulletSetGravity", &conBulletSetGravity, "bulletSetGravity(x,y,z)", 4, 4); Con::addMethodB(NULL, "bulletSetGravity", &conBulletSetGravity, "bulletSetGravity(x,y,z)", 4, 4);
Con::addMethodB(NULL, "bulletInitialized", &conBulletInitialized, "Returns whether or not if Bullet has been initialized.", 0,0); Con::addMethodB(NULL, "bulletInitialized", &conBulletInitialized, "Returns whether or not if Bullet has been initialized.", 0,0);
Con::addMethodS(NULL, "bulletCreateCube", &conBulletCreateCube, "bulletMakeCube(mass, scaleX, scaleY, scaleZ)", 5, 5); Con::addMethodS(NULL, "bulletCreateCube", &conBulletCreateCube, "bulletMakeCube(mass, scaleX, scaleY, scaleZ, boundID)", 6, 6);
} }
__declspec(dllexport) void ServerProcess(unsigned int deltaTime) __declspec(dllexport) void ServerProcess(unsigned int deltaTime)
{ {
// Game will pump updates to here updateBullet(deltaTime);
} }
} }

View file

@ -7,84 +7,35 @@
#include "stdafx.h" #include "stdafx.h"
#include "t2ConCmds.h" #include "t2ConCmds.h"
// Linker's implementations
const char* conGuiTsCtrlProject(Linker::SimObject *obj,S32 argc, const char* argv[]) {
Linker::Point3F pt;
Linker::Point3F rt;
dSscanf(argv[2],"%g %g %g",&pt.x,&pt.y,&pt.z);
GuiTSCtrl_project(reinterpret_cast<GuiTSCtrl *>(obj),pt,&rt);
char* buffer = Con::getReturnBuffer(255);
dSprintf(buffer,255,"%g %g %g",rt.x,rt.y,rt.z);
return buffer;
}
bool conNetObjectSetGhostable(Linker::SimObject *obj,S32 argc, const char* argv[]) {
if (dAtob(argv[2])) {
__asm {
push ecx
mov ecx, [obj]
mov eax,[ecx+40h]
or eax, 100h
mov [ecx+40h], eax
pop ecx
}
} else {
__asm {
xor eax, eax
or eax, 100h
not eax
push ecx
mov ecx,[obj]
and eax, [ecx+40h]
mov [ecx+40h],eax
push 40h
mov eax, 0x585BE0
call eax
pop ecx
}
}
return 1;
}
const char* conGetVariable(Linker::SimObject *obj,S32 argc, const char* argv[]) {
return Con::getVariable(argv[1]);
}
// BulletDLL Implementations // BulletDLL Implementations
// *** NOTE *** // *** NOTE ***
// All vectors should have their Y and Z axiis switched due to the Z axis being up and down in Tribes 2 // All vectors should have their Y and Z axiis switched due to the Z axis being up and down in Tribes 2
Game::CGameTime *game_time; static btDefaultCollisionConfiguration *sBulletConfig = NULL;
btDefaultCollisionConfiguration *bullet_config = NULL; static btCollisionDispatcher *sCollisionDispatcher = NULL;
btCollisionDispatcher *bullet_dispatcher = NULL; static btDbvtBroadphase *sBroadphase = NULL;
btDbvtBroadphase *bullet_broadphase = NULL; static btSequentialImpulseConstraintSolver *sConstraintSolver = NULL;
btSequentialImpulseConstraintSolver *bullet_constraint = NULL; static btDiscreteDynamicsWorld *sBulletWorld = NULL;
btDiscreteDynamicsWorld *bullet_world = NULL;
btBoxShape *box_shapes[MAXIMUM_BULLET_NODES]; struct NodeInformation
btRigidBody *rigid_bodies[MAXIMUM_BULLET_NODES]; {
unsigned int mID;
btBoxShape *mShape;
btRigidBody *mRigidBody;
};
unsigned int bullet_node_count; static NodeInformation *sActiveNodes[MAXIMUM_BULLET_NODES];
static unsigned int sRigidBodyCount = 0;
bool conBulletInitialize(Linker::SimObject *obj, S32 argc, const char *argv[]) bool conBulletInitialize(Linker::SimObject *obj, S32 argc, const char *argv[])
{ {
Con::printf("Bullet: Attempting to initialize ..."); Con::printf("Bullet: Attempting to initialize ...");
if (!bullet_world)
{
// Try to create the game timer
game_time = Game::CGameTime::getPointer();
if (!game_time)
{
Con::errorf(1, "Bullet: Failed to initialize! Unable to create timing singleton.");
return false;
}
else
Con::printf("Bullet: Created timing singleton ...");
if (!sBulletWorld)
{
// Try to create the config // Try to create the config
bullet_config = new btDefaultCollisionConfiguration; sBulletConfig = new btDefaultCollisionConfiguration;
if (!bullet_config) if (!sBulletConfig)
{ {
Con::errorf(1, "Bullet: Failed to initialize! Unable to create configuration object."); Con::errorf(1, "Bullet: Failed to initialize! Unable to create configuration object.");
return false; return false;
@ -93,56 +44,56 @@ bool conBulletInitialize(Linker::SimObject *obj, S32 argc, const char *argv[])
Con::printf("Bullet: Bullet configuration object created ..."); Con::printf("Bullet: Bullet configuration object created ...");
//Try to create the dispatcher //Try to create the dispatcher
bullet_dispatcher = new btCollisionDispatcher(bullet_config); sCollisionDispatcher = new btCollisionDispatcher(sBulletConfig);
if (!bullet_dispatcher) if (!sCollisionDispatcher)
{ {
Con::errorf(1, "Bullet: Failed to initialize! Unable to create collision dispatch object."); Con::errorf(1, "Bullet: Failed to initialize! Unable to create collision dispatch object.");
delete bullet_config; delete sBulletConfig;
return false; return false;
} }
else else
Con::printf("Bullet: Bullet collision dispatch object created ..."); Con::printf("Bullet: Bullet collision dispatch object created ...");
// Try to create the broadphase object // Try to create the broadphase object
bullet_broadphase = new btDbvtBroadphase; sBroadphase = new btDbvtBroadphase;
if (!bullet_broadphase) if (!sBroadphase)
{ {
Con::errorf(1, "Bullet: Failed to initialize! Unable to create broadphase object."); Con::errorf(1, "Bullet: Failed to initialize! Unable to create broadphase object.");
delete bullet_dispatcher; delete sCollisionDispatcher;
delete bullet_config; delete sBulletConfig;
return false; return false;
} }
Con::printf("Bullet: Bullet broadphase object created ..."); Con::printf("Bullet: Bullet broadphase object created ...");
// Try to create the sequential impulse constraint solver // Try to create the sequential impulse constraint solver
bullet_constraint = new btSequentialImpulseConstraintSolver; sConstraintSolver = new btSequentialImpulseConstraintSolver;
if (!bullet_constraint) if (!sConstraintSolver)
{ {
Con::errorf(1, "Bullet: Failed to initialize! Unable to create sequential impulse constraint solver object."); Con::errorf(1, "Bullet: Failed to initialize! Unable to create sequential impulse constraint solver object.");
delete bullet_dispatcher; delete sCollisionDispatcher;
delete bullet_config; delete sBulletConfig;
delete bullet_broadphase; delete sBroadphase;
return false; return false;
} }
else else
Con::printf("Bullet: Bullet sequential impulse constraint solver object created ..."); Con::printf("Bullet: Bullet sequential impulse constraint solver object created ...");
// Now try to create the bullet world // Now try to create the bullet world
bullet_world = new btDiscreteDynamicsWorld(bullet_dispatcher, bullet_broadphase, bullet_constraint, bullet_config); sBulletWorld = new btDiscreteDynamicsWorld(sCollisionDispatcher, sBroadphase, sConstraintSolver, sBulletConfig);
if (!bullet_world) if (!sBulletWorld)
{ {
Con::errorf(1, "Bullet: Failed to initialize! Unable to create discrete dynamics world."); Con::errorf(1, "Bullet: Failed to initialize! Unable to create discrete dynamics world.");
delete bullet_dispatcher; delete sCollisionDispatcher;
delete bullet_config; delete sBulletConfig;
delete bullet_broadphase; delete sBroadphase;
delete bullet_constraint; delete sConstraintSolver;
return false; return false;
} }
else else
Con::printf("Bullet: Bullet discrete dynamics world created! Bullet is now ready."); Con::printf("Bullet: Bullet discrete dynamics world created! Bullet is now ready.");
bullet_world->setGravity(btVector3(0,-100,0)); sBulletWorld->setGravity(btVector3(0,-100,0));
bullet_node_count = 0; sRigidBodyCount = 0;
return true; return true;
} }
Con::errorf(1, "Bullet: Already initialized!"); Con::errorf(1, "Bullet: Already initialized!");
@ -151,19 +102,23 @@ bool conBulletInitialize(Linker::SimObject *obj, S32 argc, const char *argv[])
bool conBulletDeinitialize(Linker::SimObject *obj, S32 argc, const char *argv[]) bool conBulletDeinitialize(Linker::SimObject *obj, S32 argc, const char *argv[])
{ {
if (bullet_world) if (sBulletWorld)
{ {
delete bullet_world; delete sBulletWorld;
bullet_world = NULL; sBulletWorld = NULL;
delete bullet_dispatcher;
bullet_dispatcher = NULL; delete sCollisionDispatcher;
delete bullet_config; sCollisionDispatcher = NULL;
bullet_config = NULL;
delete bullet_broadphase; delete sBulletConfig;
bullet_broadphase = NULL; sBulletConfig = NULL;
delete bullet_constraint;
bullet_constraint = NULL; delete sBroadphase;
Game::CGameTime::destroy(); sBroadphase = NULL;
delete sConstraintSolver;
sConstraintSolver = NULL;
Con::printf("Bullet: Successfully deinitialized."); Con::printf("Bullet: Successfully deinitialized.");
return true; return true;
} }
@ -171,26 +126,34 @@ bool conBulletDeinitialize(Linker::SimObject *obj, S32 argc, const char *argv[])
return false; return false;
} }
bool conBulletUpdate(Linker::SimObject *obj, S32 argc, const char *argv[]) void updateBullet(const unsigned int& timeDifference)
{ {
if (bullet_world) if (sBulletWorld)
{ {
if (argc >= 2) sBulletWorld->stepSimulation(timeDifference);
// When we pump an update, we need to step through and push updates to the nodes
for (size_t iteration = 0; iteration < sRigidBodyCount; iteration++)
{ {
btScalar delta = btScalar(atof(argv[1])); char *result = new char[256];
bullet_world->stepSimulation(delta);
// Get the position
btTransform transform = sActiveNodes[iteration]->mRigidBody->getCenterOfMassTransform();
btVector3 position = transform.getOrigin();
// Then the rotation
btQuaternion rotation = sActiveNodes[iteration]->mRigidBody->getOrientation();
// Assemble the output
sprintf(result, "%u.setTransform(\"%f %f %f %f %f %f %f\");", sActiveNodes[iteration]->mID, position.x(), position.z(), position.y(), rotation.x(), rotation.z(), rotation.y(), rotation.w());
Con::evaluate(result, false, NULL, false);
} }
else
bullet_world->stepSimulation(game_time->getDelta());
game_time->update();
return true;
} }
return false;
} }
const char *conBulletGetPosition(Linker::SimObject *obj, S32 argc, const char *argv[]) const char *conBulletGetPosition(Linker::SimObject *obj, S32 argc, const char *argv[])
{ {
if (!bullet_world) if (!sBulletWorld)
{ {
Con::errorf(1, "Bullet: Attempted to retrieve the position of a node without having initialized Bullet!"); Con::errorf(1, "Bullet: Attempted to retrieve the position of a node without having initialized Bullet!");
return "0 0 0"; return "0 0 0";
@ -202,20 +165,20 @@ const char *conBulletGetPosition(Linker::SimObject *obj, S32 argc, const char *a
Con::errorf(1, "Bullet: Attempted to retrieve the position of a out-of-range node! (%u > %u)", id, MAXIMUM_BULLET_NODES); Con::errorf(1, "Bullet: Attempted to retrieve the position of a out-of-range node! (%u > %u)", id, MAXIMUM_BULLET_NODES);
return "0 0 0"; return "0 0 0";
} }
if (id > bullet_node_count) if (id > sRigidBodyCount)
{ {
Con::errorf(1, "Bullet: Attempted to retrieve the position of a non-existent node! (%u)", id); Con::errorf(1, "Bullet: Attempted to retrieve the position of a non-existent node! (%u)", id);
return "0 0 0"; return "0 0 0";
} }
btRigidBody *body = rigid_bodies[id]; NodeInformation *node = sActiveNodes[id];
if (!body) if (!node)
{ {
Con::errorf(1, "Bullet: Node retrieval for object %u successful, however it is nonexistent!", id); Con::errorf(1, "Bullet: Node retrieval for object %u successful, however it is nonexistent!", id);
return "0 0 0"; return "0 0 0";
} }
btTransform transform = body->getCenterOfMassTransform(); btTransform transform = node->mRigidBody->getCenterOfMassTransform();
btVector3 position = transform.getOrigin(); btVector3 position = transform.getOrigin();
char *output = (char*)malloc(sizeof(char)*256); char *output = (char*)malloc(sizeof(char)*256);
@ -225,7 +188,7 @@ const char *conBulletGetPosition(Linker::SimObject *obj, S32 argc, const char *a
const char *conBulletGetRotation(Linker::SimObject *obj, S32 argc, const char *argv[]) const char *conBulletGetRotation(Linker::SimObject *obj, S32 argc, const char *argv[])
{ {
if (!bullet_world) if (!sBulletWorld)
{ {
Con::errorf(1, "Bullet: Attempted to retrieve the rotation of a node without having initialized Bullet!"); Con::errorf(1, "Bullet: Attempted to retrieve the rotation of a node without having initialized Bullet!");
return "0 0 0"; return "0 0 0";
@ -237,20 +200,20 @@ const char *conBulletGetRotation(Linker::SimObject *obj, S32 argc, const char *a
Con::errorf(1, "Bullet: Attempted to retrieve the rotation of a out-of-range node! (%u > %u)", id, MAXIMUM_BULLET_NODES); Con::errorf(1, "Bullet: Attempted to retrieve the rotation of a out-of-range node! (%u > %u)", id, MAXIMUM_BULLET_NODES);
return "0 0 0"; return "0 0 0";
} }
if (id > bullet_node_count) if (id > sRigidBodyCount)
{ {
Con::errorf(1, "Bullet: Attempted to retrieve the rotation of a non-existent node! (%u)", id); Con::errorf(1, "Bullet: Attempted to retrieve the rotation of a non-existent node! (%u)", id);
return "0 0 0"; return "0 0 0";
} }
btRigidBody *body = rigid_bodies[id]; NodeInformation *node = sActiveNodes[id];
if (!body) if (!node)
{ {
Con::errorf(1, "Bullet: Node retrieval for object %u successful, however it is nonexistent!", id); Con::errorf(1, "Bullet: Node retrieval for object %u successful, however it is nonexistent!", id);
return "0 0 0"; return "0 0 0";
} }
btQuaternion rotation = body->getOrientation(); btQuaternion rotation = node->mRigidBody->getOrientation();
char *output = (char*)malloc(sizeof(char)*256); char *output = (char*)malloc(sizeof(char)*256);
sprintf_s(output, 256, "%f %f %f %f", rotation.x(), rotation.y(), rotation.z(), rotation.w()); sprintf_s(output, 256, "%f %f %f %f", rotation.x(), rotation.y(), rotation.z(), rotation.w());
@ -259,22 +222,24 @@ const char *conBulletGetRotation(Linker::SimObject *obj, S32 argc, const char *a
bool conBulletInitialized(Linker::SimObject *obj, S32 argc, const char *argv[]) bool conBulletInitialized(Linker::SimObject *obj, S32 argc, const char *argv[])
{ {
if (!bullet_world) if (!sBulletWorld)
return false; return false;
return true; return true;
} }
const char *conBulletCreateCube(Linker::SimObject *obj, S32 argc, const char *argv[]) const char *conBulletCreateCube(Linker::SimObject *obj, S32 argc, const char *argv[])
{ {
if (!bullet_world) if (!sBulletWorld)
{ {
Con::errorf(1, "Bullet: Attempted to create a cube without having initialized Bullet!"); Con::errorf(1, "Bullet: Attempted to create a cube without having initialized Bullet!");
return "0"; return "0";
} }
btScalar mass = btScalar(atof(argv[1])); btScalar mass = btScalar(atof(argv[1]));
btScalar X = btScalar(atof(argv[2])); btScalar X = btScalar(atof(argv[2]));
btScalar Y = btScalar(atof(argv[4])); btScalar Y = btScalar(atof(argv[4]));
btScalar Z = btScalar(atof(argv[3])); btScalar Z = btScalar(atof(argv[3]));
const unsigned int boundID = atoi(argv[4]);
// Create the Bullet Object // Create the Bullet Object
btTransform start_transform; btTransform start_transform;
@ -282,11 +247,16 @@ const char *conBulletCreateCube(Linker::SimObject *obj, S32 argc, const char *ar
btBoxShape *shape = new btBoxShape(btVector3(X,Y,Z)); btBoxShape *shape = new btBoxShape(btVector3(X,Y,Z));
btRigidBody::btRigidBodyConstructionInfo info(mass, NULL, shape, btVector3(btScalar(0.0f), btScalar(0.0f), btScalar(0.0f))); btRigidBody::btRigidBodyConstructionInfo info(mass, NULL, shape, btVector3(btScalar(0.0f), btScalar(0.0f), btScalar(0.0f)));
btRigidBody *body = new btRigidBody(info); btRigidBody *body = new btRigidBody(info);
bullet_world->addRigidBody(body); sBulletWorld->addRigidBody(body);
unsigned int identification = bullet_node_count; NodeInformation *newNode = new NodeInformation;
rigid_bodies[identification] = body; newNode->mRigidBody = body;
bullet_node_count++; newNode->mShape = shape;
newNode->mID = boundID;
unsigned int identification = sRigidBodyCount;
sActiveNodes[identification] = newNode;
sRigidBodyCount++;
char *output = (char*)malloc(sizeof(char)*256); char *output = (char*)malloc(sizeof(char)*256);
sprintf_s(output, 256, "%u", identification); sprintf_s(output, 256, "%u", identification);
@ -296,7 +266,7 @@ const char *conBulletCreateCube(Linker::SimObject *obj, S32 argc, const char *ar
bool conBulletSetPosition(Linker::SimObject *obj, S32 argc, const char *argv[]) bool conBulletSetPosition(Linker::SimObject *obj, S32 argc, const char *argv[])
{ {
unsigned int id = atoi(argv[1]); unsigned int id = atoi(argv[1]);
if (!bullet_world) if (!sBulletWorld)
{ {
Con::errorf(1, "Bullet: Attempted to set the position of an object %u without having Bullet initialized!", id); Con::errorf(1, "Bullet: Attempted to set the position of an object %u without having Bullet initialized!", id);
return false; return false;
@ -307,14 +277,14 @@ bool conBulletSetPosition(Linker::SimObject *obj, S32 argc, const char *argv[])
Con::errorf(1, "Bullet: Attempted to set the rotation of a out-of-range node! (%u > %u)", id, MAXIMUM_BULLET_NODES); Con::errorf(1, "Bullet: Attempted to set the rotation of a out-of-range node! (%u > %u)", id, MAXIMUM_BULLET_NODES);
return "0 0 0"; return "0 0 0";
} }
if (id > bullet_node_count) if (id > sRigidBodyCount)
{ {
Con::errorf(1, "Bullet: Attempted to set the rotation of a non-existent node! (%u)", id); Con::errorf(1, "Bullet: Attempted to set the rotation of a non-existent node! (%u)", id);
return "0 0 0"; return "0 0 0";
} }
btRigidBody *body = rigid_bodies[id]; NodeInformation *node = sActiveNodes[id];
if (!body) if (!node)
{ {
Con::errorf(1, "Bullet: Node retrieval for object %u successful, however it is nonexistent!", id); Con::errorf(1, "Bullet: Node retrieval for object %u successful, however it is nonexistent!", id);
return "0 0 0"; return "0 0 0";
@ -324,15 +294,15 @@ bool conBulletSetPosition(Linker::SimObject *obj, S32 argc, const char *argv[])
btScalar Y = btScalar(atof(argv[4])); btScalar Y = btScalar(atof(argv[4]));
btScalar Z = btScalar(atof(argv[3])); btScalar Z = btScalar(atof(argv[3]));
btTransform transform = body->getCenterOfMassTransform(); btTransform transform = node->mRigidBody->getCenterOfMassTransform();
btTransform new_transform(transform.getRotation(),btVector3(btScalar(X),btScalar(Y),btScalar(Z))); btTransform new_transform(transform.getRotation(),btVector3(btScalar(X),btScalar(Y),btScalar(Z)));
body->setWorldTransform(new_transform); node->mRigidBody->setWorldTransform(new_transform);
return true; return true;
} }
bool conBulletSetGravity(Linker::SimObject *obj, S32 argc, const char *argv[]) bool conBulletSetGravity(Linker::SimObject *obj, S32 argc, const char *argv[])
{ {
if (!bullet_world) if (!sBulletWorld)
{ {
Con::errorf(1, "Bullet: Attempted to set the gravity of the Bullet world without having Bullet initialized!"); Con::errorf(1, "Bullet: Attempted to set the gravity of the Bullet world without having Bullet initialized!");
return false; return false;
@ -341,14 +311,14 @@ bool conBulletSetGravity(Linker::SimObject *obj, S32 argc, const char *argv[])
btScalar X = btScalar(atof(argv[1])); btScalar X = btScalar(atof(argv[1]));
btScalar Y = btScalar(atof(argv[3])); btScalar Y = btScalar(atof(argv[3]));
btScalar Z = btScalar(atof(argv[2])); btScalar Z = btScalar(atof(argv[2]));
bullet_world->setGravity(btVector3(btScalar(X),btScalar(Y),btScalar(Z))); sBulletWorld->setGravity(btVector3(btScalar(X),btScalar(Y),btScalar(Z)));
return true; return true;
} }
bool conBulletSetMass(Linker::SimObject *obj, S32 argc, const char *argv[]) bool conBulletSetMass(Linker::SimObject *obj, S32 argc, const char *argv[])
{ {
unsigned int id = atoi(argv[1]); unsigned int id = atoi(argv[1]);
if (!bullet_world) if (!sBulletWorld)
{ {
Con::errorf(1, "Bullet: Attempted to set mass of object %u without having Bullet initialized!", id); Con::errorf(1, "Bullet: Attempted to set mass of object %u without having Bullet initialized!", id);
return false; return false;
@ -358,14 +328,14 @@ bool conBulletSetMass(Linker::SimObject *obj, S32 argc, const char *argv[])
Con::errorf(1, "Bullet: Attempted to set the rotation of a out-of-range node! (%u > %u)", id, MAXIMUM_BULLET_NODES); Con::errorf(1, "Bullet: Attempted to set the rotation of a out-of-range node! (%u > %u)", id, MAXIMUM_BULLET_NODES);
return "0 0 0"; return "0 0 0";
} }
if (id > bullet_node_count) if (id > sRigidBodyCount)
{ {
Con::errorf(1, "Bullet: Attempted to set the rotation of a non-existent node! (%u)", id); Con::errorf(1, "Bullet: Attempted to set the rotation of a non-existent node! (%u)", id);
return "0 0 0"; return "0 0 0";
} }
btRigidBody *body = rigid_bodies[id]; NodeInformation *node = sActiveNodes[id];
if (!body) if (!node)
{ {
Con::errorf(1, "Bullet: Node retrieval for object %u successful, however it is nonexistent!", id); Con::errorf(1, "Bullet: Node retrieval for object %u successful, however it is nonexistent!", id);
return "0 0 0"; return "0 0 0";