Merge branch 'method_Unmangle' into PBR_PR

This commit is contained in:
Azaezel 2018-12-12 14:54:22 -06:00
commit 8e534dd0c9
636 changed files with 3939 additions and 3454 deletions

View file

@ -418,7 +418,7 @@ void AIClient::onAdd( const char *nameSpace ) {
/**
* Sets the move speed for an AI object
*/
DefineConsoleMethod( AIClient, setMoveSpeed, void, (F32 speed), , "ai.setMoveSpeed( float );" )
DefineEngineMethod( AIClient, setMoveSpeed, void, (F32 speed), , "ai.setMoveSpeed( float );" )
{
AIClient *ai = static_cast<AIClient *>( object );
ai->setMoveSpeed( speed );
@ -427,7 +427,7 @@ DefineConsoleMethod( AIClient, setMoveSpeed, void, (F32 speed), , "ai.setMoveSpe
/**
* Stops all AI movement, halt!
*/
DefineConsoleMethod( AIClient, stop, void, (),, "ai.stop();" )
DefineEngineMethod( AIClient, stop, void, (),, "ai.stop();" )
{
AIClient *ai = static_cast<AIClient *>( object );
ai->setMoveMode( AIClient::ModeStop );
@ -436,7 +436,7 @@ DefineConsoleMethod( AIClient, stop, void, (),, "ai.stop();" )
/**
* Tells the AI to aim at the location provided
*/
DefineConsoleMethod( AIClient, setAimLocation, void, (Point3F v), , "ai.setAimLocation( x y z );" )
DefineEngineMethod( AIClient, setAimLocation, void, (Point3F v), , "ai.setAimLocation( x y z );" )
{
AIClient *ai = static_cast<AIClient *>( object );
@ -446,7 +446,7 @@ DefineConsoleMethod( AIClient, setAimLocation, void, (Point3F v), , "ai.setAimLo
/**
* Tells the AI to move to the location provided
*/
DefineConsoleMethod( AIClient, setMoveDestination, void, (Point3F v), , "ai.setMoveDestination( x y z );" )
DefineEngineMethod( AIClient, setMoveDestination, void, (Point3F v), , "ai.setMoveDestination( x y z );" )
{
AIClient *ai = static_cast<AIClient *>( object );
@ -456,7 +456,7 @@ DefineConsoleMethod( AIClient, setMoveDestination, void, (Point3F v), , "ai.setM
/**
* Returns the point the AI is aiming at
*/
DefineConsoleMethod( AIClient, getAimLocation, Point3F, (),, "ai.getAimLocation();" )
DefineEngineMethod( AIClient, getAimLocation, Point3F, (),, "ai.getAimLocation();" )
{
AIClient *ai = static_cast<AIClient *>( object );
return ai->getAimLocation();
@ -465,7 +465,7 @@ DefineConsoleMethod( AIClient, getAimLocation, Point3F, (),, "ai.getAimLocation(
/**
* Returns the point the AI is set to move to
*/
DefineConsoleMethod( AIClient, getMoveDestination, Point3F, (),, "ai.getMoveDestination();" )
DefineEngineMethod( AIClient, getMoveDestination, Point3F, (),, "ai.getMoveDestination();" )
{
AIClient *ai = static_cast<AIClient *>( object );
return ai->getMoveDestination();
@ -474,7 +474,7 @@ DefineConsoleMethod( AIClient, getMoveDestination, Point3F, (),, "ai.getMoveDest
/**
* Sets the bots target object
*/
DefineConsoleMethod( AIClient, setTargetObject, void, (const char * objName), , "ai.setTargetObject( obj );" )
DefineEngineMethod( AIClient, setTargetObject, void, (const char * objName), , "ai.setTargetObject( obj );" )
{
AIClient *ai = static_cast<AIClient *>( object );
@ -489,7 +489,7 @@ DefineConsoleMethod( AIClient, setTargetObject, void, (const char * objName), ,
/**
* Gets the object the AI is targeting
*/
DefineConsoleMethod( AIClient, getTargetObject, S32, (),, "ai.getTargetObject();" )
DefineEngineMethod( AIClient, getTargetObject, S32, (),, "ai.getTargetObject();" )
{
AIClient *ai = static_cast<AIClient *>( object );
@ -499,7 +499,7 @@ DefineConsoleMethod( AIClient, getTargetObject, S32, (),, "ai.getTargetObject();
/**
* Tells the bot the mission is cycling
*/
DefineConsoleMethod( AIClient, missionCycleCleanup, void, (),, "ai.missionCycleCleanup();" )
DefineEngineMethod( AIClient, missionCycleCleanup, void, (),, "ai.missionCycleCleanup();" )
{
AIClient *ai = static_cast<AIClient*>( object );
ai->missionCycleCleanup();
@ -508,7 +508,7 @@ DefineConsoleMethod( AIClient, missionCycleCleanup, void, (),, "ai.missionCycleC
/**
* Sets the AI to run mode
*/
DefineConsoleMethod( AIClient, move, void, (),, "ai.move();" )
DefineEngineMethod( AIClient, move, void, (),, "ai.move();" )
{
AIClient *ai = static_cast<AIClient *>( object );
ai->setMoveMode( AIClient::ModeMove );
@ -517,7 +517,7 @@ DefineConsoleMethod( AIClient, move, void, (),, "ai.move();" )
/**
* Gets the AI's location in the world
*/
DefineConsoleMethod( AIClient, getLocation, Point3F, (),, "ai.getLocation();" )
DefineEngineMethod( AIClient, getLocation, Point3F, (),, "ai.getLocation();" )
{
AIClient *ai = static_cast<AIClient *>( object );
return ai->getLocation();
@ -526,7 +526,7 @@ DefineConsoleMethod( AIClient, getLocation, Point3F, (),, "ai.getLocation();" )
/**
* Adds an AI Player to the game
*/
DefineConsoleFunction( aiAddPlayer, S32, (const char * name, const char * ns), (""), "'playerName'[, 'AIClassType'] );")
DefineEngineFunction( aiAddPlayer, S32, (const char * name, const char * ns), (""), "'playerName'[, 'AIClassType'] );")
{
// Create the player
AIClient *aiPlayer = new AIClient();
@ -559,7 +559,7 @@ DefineConsoleFunction( aiAddPlayer, S32, (const char * name, const char * ns), (
/**
* Tells the AI to move forward 100 units...TEST FXN
*/
DefineConsoleMethod( AIClient, moveForward, void, (),, "ai.moveForward();" )
DefineEngineMethod( AIClient, moveForward, void, (),, "ai.moveForward();" )
{
AIClient *ai = static_cast<AIClient *>( object );

View file

@ -130,7 +130,7 @@ static inline F32 moveClamp(F32 v)
//-----------------------------------------------------------------------------
/// Construct and connect an AI connection object
ConsoleFunction(aiConnect, S32 , 2, 20, "(...)"
DefineEngineStringlyVariadicFunction(aiConnect, S32 , 2, 20, "(...)"
"@brief Creates a new AIConnection, and passes arguments to its onConnect script callback.\n\n"
"@returns The newly created AIConnection\n"
"@see GameConnection for parameter information\n"
@ -160,7 +160,7 @@ ConsoleFunction(aiConnect, S32 , 2, 20, "(...)"
//-----------------------------------------------------------------------------
DefineConsoleMethod(AIConnection, setMove, void, (const char * field, F32 value), ,"(string field, float value)"
DefineEngineMethod(AIConnection, setMove, void, (const char * field, F32 value), ,"(string field, float value)"
"Set a field on the current move.\n\n"
"@param field One of {'x','y','z','yaw','pitch','roll'}\n"
"@param value Value to set field to.")
@ -190,7 +190,7 @@ DefineConsoleMethod(AIConnection, setMove, void, (const char * field, F32 value)
object->setMove(&move);
}
DefineConsoleMethod(AIConnection,getMove,F32, (const char * field), ,"(string field)"
DefineEngineMethod(AIConnection,getMove,F32, (const char * field), ,"(string field)"
"Get the given field of a move.\n\n"
"@param field One of {'x','y','z','yaw','pitch','roll'}\n"
"@returns The requested field on the current move.")
@ -212,7 +212,7 @@ DefineConsoleMethod(AIConnection,getMove,F32, (const char * field), ,"(string fi
}
DefineConsoleMethod(AIConnection,setFreeLook,void,(bool isFreeLook), ,"(bool isFreeLook)"
DefineEngineMethod(AIConnection,setFreeLook,void,(bool isFreeLook), ,"(bool isFreeLook)"
"Enable/disable freelook on the current move.")
{
Move move = object->getMove();
@ -220,7 +220,7 @@ DefineConsoleMethod(AIConnection,setFreeLook,void,(bool isFreeLook), ,"(bool isF
object->setMove(&move);
}
DefineConsoleMethod(AIConnection, getFreeLook, bool, (), ,"getFreeLook()"
DefineEngineMethod(AIConnection, getFreeLook, bool, (), ,"getFreeLook()"
"Is freelook on for the current move?")
{
return object->getMove().freeLook;
@ -229,7 +229,7 @@ DefineConsoleMethod(AIConnection, getFreeLook, bool, (), ,"getFreeLook()"
//-----------------------------------------------------------------------------
DefineConsoleMethod(AIConnection,setTrigger,void, (S32 idx, bool set), ,"(int trigger, bool set)"
DefineEngineMethod(AIConnection,setTrigger,void, (S32 idx, bool set), ,"(int trigger, bool set)"
"Set a trigger.")
{
if (idx >= 0 && idx < MaxTriggerKeys)
@ -240,7 +240,7 @@ DefineConsoleMethod(AIConnection,setTrigger,void, (S32 idx, bool set), ,"(int tr
}
}
DefineConsoleMethod(AIConnection,getTrigger,bool, (S32 idx), ,"(int trigger)"
DefineEngineMethod(AIConnection,getTrigger,bool, (S32 idx), ,"(int trigger)"
"Is the given trigger set?")
{
if (idx >= 0 && idx < MaxTriggerKeys)
@ -251,7 +251,7 @@ DefineConsoleMethod(AIConnection,getTrigger,bool, (S32 idx), ,"(int trigger)"
//-----------------------------------------------------------------------------
DefineConsoleMethod(AIConnection,getAddress,const char*,(), ,"")
DefineEngineMethod(AIConnection,getAddress,const char*,(), ,"")
{
// Override the netConnection method to return to indicate
// this is an ai connection.

View file

@ -1251,7 +1251,7 @@ ConsoleDocFragment _setAimObject(
"void setAimObject(GameBase targetObject, Point3F offset);"
);
DefineConsoleMethod( AIPlayer, setAimObject, void, ( const char * objName, Point3F offset ), (Point3F::Zero), "( GameBase obj, [Point3F offset] )"
DefineEngineMethod( AIPlayer, setAimObject, void, ( const char * objName, Point3F offset ), (Point3F::Zero), "( GameBase obj, [Point3F offset] )"
"Sets the bot's target object. Optionally set an offset from target location."
"@hide")
{

View file

@ -157,7 +157,7 @@ void MaterialAsset::copyTo(SimObject* object)
Parent::copyTo(object);
}
ConsoleMethod(MaterialAsset, compileShader, void, 2, 2, "() - Compiles the material's generated shader, if any. Not yet implemented\n")
DefineEngineMethod(MaterialAsset, compileShader, void, (), , "Compiles the material's generated shader, if any. Not yet implemented\n")
{
object->compileShader();
}

View file

@ -24,13 +24,14 @@
#include "T3D/components/camera/cameraComponent.h"
//Basically, this only exists for backwards compatibility for parts of the editors
ConsoleMethod(CameraComponent, getMode, const char*, 2, 2, "() - We get the first behavior of the requested type on our owner object.\n"
DefineEngineMethod(CameraComponent, getMode, const char*, (),,
"@brief We get the first behavior of the requested type on our owner object.\n"
"@return (string name) The type of the behavior we're requesting")
{
return "fly";
}
DefineConsoleMethod(CameraComponent, getForwardVector, VectorF, (), ,
DefineEngineMethod(CameraComponent, getForwardVector, VectorF, (), ,
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
@ -44,7 +45,7 @@ DefineConsoleMethod(CameraComponent, getForwardVector, VectorF, (), ,
return returnVec;
}
DefineConsoleMethod(CameraComponent, getRightVector, VectorF, (), ,
DefineEngineMethod(CameraComponent, getRightVector, VectorF, (), ,
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
@ -58,7 +59,7 @@ DefineConsoleMethod(CameraComponent, getRightVector, VectorF, (), ,
return returnVec;
}
DefineConsoleMethod(CameraComponent, getUpVector, VectorF, (), ,
DefineEngineMethod(CameraComponent, getUpVector, VectorF, (), ,
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
@ -72,14 +73,14 @@ DefineConsoleMethod(CameraComponent, getUpVector, VectorF, (), ,
return returnVec;
}
DefineConsoleMethod(CameraComponent, setForwardVector, void, (VectorF newForward), (VectorF(0, 0, 0)),
DefineEngineMethod(CameraComponent, setForwardVector, void, (VectorF newForward), (VectorF(0, 0, 0)),
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
object->setForwardVector(newForward);
}
DefineConsoleMethod(CameraComponent, getWorldPosition, Point3F, (), ,
DefineEngineMethod(CameraComponent, getWorldPosition, Point3F, (), ,
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{

View file

@ -24,21 +24,21 @@
#include "T3D/components/collision/collisionComponent.h"
#include "materials/baseMatInstance.h"
DefineConsoleMethod(CollisionComponent, getNumberOfContacts, S32, (), ,
DefineEngineMethod(CollisionComponent, getNumberOfContacts, S32, (), ,
"Gets the number of contacts this collider has hit.\n"
"@return The number of static fields defined on the object.")
{
return object->getCollisionList()->getCount();
}
DefineConsoleMethod(CollisionComponent, getBestContact, S32, (), ,
DefineEngineMethod(CollisionComponent, getBestContact, S32, (), ,
"Gets the number of contacts this collider has hit.\n"
"@return The number of static fields defined on the object.")
{
return 0;
}
DefineConsoleMethod(CollisionComponent, getContactNormal, Point3F, (), ,
DefineEngineMethod(CollisionComponent, getContactNormal, Point3F, (), ,
"Gets the number of contacts this collider has hit.\n"
"@return The number of static fields defined on the object.")
{
@ -53,7 +53,7 @@ DefineConsoleMethod(CollisionComponent, getContactNormal, Point3F, (), ,
return Point3F::Zero;
}
DefineConsoleMethod(CollisionComponent, getContactMaterial, S32, (), ,
DefineEngineMethod(CollisionComponent, getContactMaterial, S32, (), ,
"Gets the number of contacts this collider has hit.\n"
"@return The number of static fields defined on the object.")
{
@ -69,7 +69,7 @@ DefineConsoleMethod(CollisionComponent, getContactMaterial, S32, (), ,
return 0;
}
DefineConsoleMethod(CollisionComponent, getContactObject, S32, (), ,
DefineEngineMethod(CollisionComponent, getContactObject, S32, (), ,
"Gets the number of contacts this collider has hit.\n"
"@return The number of static fields defined on the object.")
{
@ -81,7 +81,7 @@ DefineConsoleMethod(CollisionComponent, getContactObject, S32, (), ,
return 0;
}
DefineConsoleMethod(CollisionComponent, getContactPoint, Point3F, (), ,
DefineEngineMethod(CollisionComponent, getContactPoint, Point3F, (), ,
"Gets the number of contacts this collider has hit.\n"
"@return The number of static fields defined on the object.")
{
@ -96,7 +96,7 @@ DefineConsoleMethod(CollisionComponent, getContactPoint, Point3F, (), ,
return Point3F::Zero;
}
DefineConsoleMethod(CollisionComponent, getContactTime, S32, (), ,
DefineEngineMethod(CollisionComponent, getContactTime, S32, (), ,
"Gets the number of contacts this collider has hit.\n"
"@return The number of static fields defined on the object.")
{

View file

@ -605,8 +605,8 @@ void Component::addDependency(StringTableEntry name)
//////////////////////////////////////////////////////////////////////////
// Console Methods
//////////////////////////////////////////////////////////////////////////
ConsoleMethod(Component, beginGroup, void, 3, 3, "(groupName)\n"
"Starts the grouping for following fields being added to be grouped into\n"
DefineEngineMethod(Component, beginGroup, void, (String groupName),,
"@brief Starts the grouping for following fields being added to be grouped into\n"
"@param groupName The name of this group\n"
"@param desc The Description of this field\n"
"@param type The DataType for this field (default, int, float, Point2F, bool, enum, Object, keybind, color)\n"
@ -616,11 +616,11 @@ ConsoleMethod(Component, beginGroup, void, 3, 3, "(groupName)\n"
"-object: the T2D object type that are valid choices for the field. The object types observe inheritance, so if you have a t2dSceneObject field you will be able to choose t2dStaticSrpites, t2dAnimatedSprites, etc.\n"
"@return Nothing\n")
{
object->beginFieldGroup(argv[2]);
object->beginFieldGroup(groupName);
}
ConsoleMethod(Component, endGroup, void, 2, 2, "()\n"
"Ends the grouping for prior fields being added to be grouped into\n"
DefineEngineMethod(Component, endGroup, void, (),,
"@brief Ends the grouping for prior fields being added to be grouped into\n"
"@param groupName The name of this group\n"
"@param desc The Description of this field\n"
"@param type The DataType for this field (default, int, float, Point2F, bool, enum, Object, keybind, color)\n"
@ -633,7 +633,7 @@ ConsoleMethod(Component, endGroup, void, 2, 2, "()\n"
object->endFieldGroup();
}
DefineConsoleMethod(Component, addComponentField, void, (String fieldName, String fieldDesc, String fieldType, String defValue, String userData, bool hidden),
DefineEngineMethod(Component, addComponentField, void, (String fieldName, String fieldDesc, String fieldType, String defValue, String userData, bool hidden),
("", "", "", "", "", false),
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
@ -641,7 +641,8 @@ DefineConsoleMethod(Component, addComponentField, void, (String fieldName, Strin
object->addComponentField(fieldName, fieldDesc, fieldType, defValue, userData, hidden);
}
ConsoleMethod(Component, getComponentFieldCount, S32, 2, 2, "() - Get the number of ComponentField's on this object\n"
DefineEngineMethod(Component, getComponentFieldCount, S32, (),,
"@brief Get the number of ComponentField's on this object\n"
"@return Returns the number of BehaviorFields as a nonnegative integer\n")
{
return object->getComponentFieldCount();
@ -650,11 +651,12 @@ ConsoleMethod(Component, getComponentFieldCount, S32, 2, 2, "() - Get the number
// [tom, 1/12/2007] Field accessors split into multiple methods to allow space
// for long descriptions and type data.
ConsoleMethod(Component, getComponentField, const char *, 3, 3, "(int index) - Gets a Tab-Delimited list of information about a ComponentField specified by Index\n"
DefineEngineMethod(Component, getComponentField, const char *, (S32 index),,
"@brief Gets a Tab-Delimited list of information about a ComponentField specified by Index\n"
"@param index The index of the behavior\n"
"@return FieldName, FieldType and FieldDefaultValue, each separated by a TAB character.\n")
{
ComponentField *field = object->getComponentField(dAtoi(argv[2]));
ComponentField *field = object->getComponentField(index);
if (field == NULL)
return "";
@ -664,11 +666,12 @@ ConsoleMethod(Component, getComponentField, const char *, 3, 3, "(int index) - G
return buf;
}
ConsoleMethod(Component, setComponentield, const char *, 3, 3, "(int index) - Gets a Tab-Delimited list of information about a ComponentField specified by Index\n"
DefineEngineMethod(Component, setComponentield, const char *, (S32 index),,
"@brief Gets a Tab-Delimited list of information about a ComponentField specified by Index\n"
"@param index The index of the behavior\n"
"@return FieldName, FieldType and FieldDefaultValue, each separated by a TAB character.\n")
{
ComponentField *field = object->getComponentField(dAtoi(argv[2]));
ComponentField *field = object->getComponentField(index);
if (field == NULL)
return "";
@ -678,7 +681,7 @@ ConsoleMethod(Component, setComponentield, const char *, 3, 3, "(int index) - Ge
return buf;
}
DefineConsoleMethod(Component, getComponentFieldType, const char *, (String fieldName), ,
DefineEngineMethod(Component, getComponentFieldType, const char *, (String fieldName), ,
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
@ -689,36 +692,40 @@ DefineConsoleMethod(Component, getComponentFieldType, const char *, (String fiel
return field->mFieldTypeName;;
}
ConsoleMethod(Component, getBehaviorFieldUserData, const char *, 3, 3, "(int index) - Gets the UserData associated with a field by index in the field list\n"
DefineEngineMethod(Component, getBehaviorFieldUserData, const char *, (S32 index),,
"@brief Gets the UserData associated with a field by index in the field list\n"
"@param index The index of the behavior\n"
"@return Returns a string representing the user data of this field\n")
{
ComponentField *field = object->getComponentField(dAtoi(argv[2]));
ComponentField *field = object->getComponentField(index);
if (field == NULL)
return "";
return field->mUserData;
}
ConsoleMethod(Component, getComponentFieldDescription, const char *, 3, 3, "(int index) - Gets a field description by index\n"
DefineEngineMethod(Component, getComponentFieldDescription, const char *, (S32 index),,
"@brief Gets a field description by index\n"
"@param index The index of the behavior\n"
"@return Returns a string representing the description of this field\n")
{
ComponentField *field = object->getComponentField(dAtoi(argv[2]));
ComponentField *field = object->getComponentField(index);
if (field == NULL)
return "";
return field->mFieldDescription ? field->mFieldDescription : "";
}
ConsoleMethod(Component, addDependency, void, 3, 3, "(string behaviorName) - Gets a field description by index\n"
DefineEngineMethod(Component, addDependency, void, (String behaviorName),,
"@brief Gets a field description by index\n"
"@param index The index of the behavior\n"
"@return Returns a string representing the description of this field\n")
{
object->addDependency(argv[2]);
object->addDependency(behaviorName);
}
ConsoleMethod(Component, setDirty, void, 2, 2, "() - Gets a field description by index\n"
DefineEngineMethod(Component, setDirty, void, (),,
"@brief Gets a field description by index\n"
"@param index The index of the behavior\n"
"@return Returns a string representing the description of this field\n")
{

View file

@ -201,6 +201,8 @@ public:
/// @}
String getMaterialName() { return mMaterialName; }
protected:
void _updateMaterial();

View file

@ -1798,7 +1798,7 @@ DefineEngineMethod(Entity, setBox, void,
}
/*DefineConsoleMethod(Entity, callOnComponents, void, (const char* functionName), ,
/*DefineEngineMethod(Entity, callOnComponents, void, (const char* functionName), ,
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
@ -1821,12 +1821,11 @@ ConsoleMethod(Entity, addComponents, void, 2, 2, "() - Add all fielded behaviors
object->addComponents();
}*/
ConsoleMethod(Entity, addComponent, bool, 3, 3, "(ComponentInstance bi) - Add a behavior to the object\n"
DefineEngineMethod(Entity, addComponent, bool, (Component* comp),,
"@brief Add a behavior to the object\n"
"@param bi The behavior instance to add"
"@return (bool success) Whether or not the behavior was successfully added")
{
Component *comp = dynamic_cast<Component *>(Sim::findObject(argv[2]));
if (comp != NULL)
{
bool success = object->addComponent(comp);
@ -1846,40 +1845,33 @@ ConsoleMethod(Entity, addComponent, bool, 3, 3, "(ComponentInstance bi) - Add a
return false;
}
ConsoleMethod(Entity, removeComponent, bool, 3, 4, "(ComponentInstance bi, [bool deleteBehavior = true])\n"
DefineEngineMethod(Entity, removeComponent, bool, (Component* comp, bool deleteComponent), (true),
"@param bi The behavior instance to remove\n"
"@param deleteBehavior Whether or not to delete the behavior\n"
"@return (bool success) Whether the behavior was successfully removed")
{
bool deleteComponent = true;
if (argc > 3)
deleteComponent = dAtob(argv[3]);
return object->removeComponent(dynamic_cast<Component *>(Sim::findObject(argv[2])), deleteComponent);
return object->removeComponent(comp, deleteComponent);
}
ConsoleMethod(Entity, clearComponents, void, 2, 2, "() - Clear all behavior instances\n"
DefineEngineMethod(Entity, clearComponents, void, (),, "Clear all behavior instances\n"
"@return No return value")
{
object->clearComponents();
}
ConsoleMethod(Entity, getComponentByIndex, S32, 3, 3, "(int index) - Gets a particular behavior\n"
DefineEngineMethod(Entity, getComponentByIndex, Component*, (S32 index),,
"@brief Gets a particular behavior\n"
"@param index The index of the behavior to get\n"
"@return (ComponentInstance bi) The behavior instance you requested")
{
Component *comp = object->getComponent(dAtoi(argv[2]));
return (comp != NULL) ? comp->getId() : 0;
return object->getComponent(index);
}
DefineConsoleMethod(Entity, getComponent, S32, (String componentName), (""),
DefineEngineMethod(Entity, getComponent, Component*, (String componentName), (""),
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
Component *comp = object->getComponent(componentName);
return (comp != NULL) ? comp->getId() : 0;
return object->getComponent(componentName);
}
/*ConsoleMethod(Entity, getBehaviorByType, S32, 3, 3, "(string BehaviorTemplateName) - gets a behavior\n"
@ -1908,13 +1900,14 @@ DefineConsoleMethod(Entity, getComponent, S32, (String componentName), (""),
return object->reOrder(inst, idx);
}*/
ConsoleMethod(Entity, getComponentCount, S32, 2, 2, "() - Get the count of behaviors on an object\n"
DefineEngineMethod(Entity, getComponentCount, S32, (),,
"@brief Get the count of behaviors on an object\n"
"@return (int count) The number of behaviors on an object")
{
return object->getComponentCount();
}
DefineConsoleMethod(Entity, setComponentDirty, void, (S32 componentID, bool forceUpdate), (0, false),
DefineEngineMethod(Entity, setComponentDirty, void, (S32 componentID, bool forceUpdate), (0, false),
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
@ -1923,7 +1916,7 @@ DefineConsoleMethod(Entity, setComponentDirty, void, (S32 componentID, bool forc
object->setComponentDirty(comp, forceUpdate);*/
}
DefineConsoleMethod(Entity, getMoveVector, VectorF, (),,
DefineEngineMethod(Entity, getMoveVector, VectorF, (),,
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
@ -1937,7 +1930,7 @@ DefineConsoleMethod(Entity, getMoveVector, VectorF, (),,
return VectorF::Zero;
}
DefineConsoleMethod(Entity, getMoveRotation, VectorF, (), ,
DefineEngineMethod(Entity, getMoveRotation, VectorF, (), ,
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
@ -1951,7 +1944,7 @@ DefineConsoleMethod(Entity, getMoveRotation, VectorF, (), ,
return VectorF::Zero;
}
DefineConsoleMethod(Entity, getMoveTrigger, bool, (S32 triggerNum), (0),
DefineEngineMethod(Entity, getMoveTrigger, bool, (S32 triggerNum), (0),
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
@ -1972,28 +1965,28 @@ DefineEngineMethod(Entity, getForwardVector, VectorF, (), ,
return forVec;
}
DefineConsoleMethod(Entity, setForwardVector, void, (VectorF newForward), (VectorF(0,0,0)),
DefineEngineMethod(Entity, setForwardVector, void, (VectorF newForward), (VectorF(0,0,0)),
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
object->setForwardVector(newForward);
}
DefineConsoleMethod(Entity, lookAt, void, (Point3F lookPosition),,
DefineEngineMethod(Entity, lookAt, void, (Point3F lookPosition),,
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
//object->setForwardVector(newForward);
}
DefineConsoleMethod(Entity, rotateTo, void, (Point3F lookPosition, F32 degreePerSecond), (1.0),
DefineEngineMethod(Entity, rotateTo, void, (Point3F lookPosition, F32 degreePerSecond), (1.0),
"Get the number of static fields on the object.\n"
"@return The number of static fields defined on the object.")
{
//object->setForwardVector(newForward);
}
DefineConsoleMethod(Entity, notify, void, (String signalFunction, String argA, String argB, String argC, String argD, String argE),
DefineEngineMethod(Entity, notify, void, (String signalFunction, String argA, String argB, String argC, String argD, String argE),
("", "", "", "", "", ""),
"Triggers a signal call to all components for a certain function.")
{
@ -2003,7 +1996,7 @@ DefineConsoleMethod(Entity, notify, void, (String signalFunction, String argA, S
object->notifyComponents(signalFunction, argA, argB, argC, argD, argE);
}
DefineConsoleFunction(findEntitiesByTag, const char*, (SimGroup* searchingGroup, String tags), (nullAsType<SimGroup*>(), ""),
DefineEngineFunction(findEntitiesByTag, const char*, (SimGroup* searchingGroup, String tags), (nullAsType<SimGroup*>(), ""),
"Finds all entities that have the provided tags.\n"
"@param searchingGroup The SimGroup to search inside. If null, we'll search the entire dictionary(this can be slow!).\n"
"@param tags Word delimited list of tags to search for. If multiple tags are included, the list is eclusively parsed, requiring all tags provided to be found on an entity for a match.\n"

View file

@ -326,7 +326,7 @@ DefineEngineMethod( GameConnection, setJoinPassword, void, (const char* password
object->setJoinPassword(password);
}
ConsoleMethod(GameConnection, setConnectArgs, void, 3, 17,
DefineEngineStringlyVariadicMethod(GameConnection, setConnectArgs, void, 3, 17,
"(const char* args) @brief On the client, pass along a variable set of parameters to the server.\n\n"
"Once the connection is established with the server, the server calls its onConnect() method "
@ -2451,41 +2451,37 @@ DefineEngineMethod( GameConnection, getVisibleGhostDistance, F32, (),,
// Object Selection in Torque by Dave Myers
// http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7335
ConsoleMethod(GameConnection, setSelectedObj, bool, 3, 4, "(object, [propagate_to_client])")
DefineEngineMethod(GameConnection, setSelectedObj, bool, (SceneObject* obj, bool propagate_to_client), (false), "")
{
SceneObject* pending_selection;
if (!Sim::findObject(argv[2], pending_selection))
if (!obj)
return false;
bool propagate_to_client = (argc > 3) ? dAtob(argv[3]) : false;
object->setSelectedObj(pending_selection, propagate_to_client);
object->setSelectedObj(obj, propagate_to_client);
return true;
}
ConsoleMethod(GameConnection, getSelectedObj, S32, 2, 2, "()")
DefineEngineMethod(GameConnection, getSelectedObj, SimObject*, (),, "")
{
SimObject* selected = object->getSelectedObj();
return (selected) ? selected->getId(): -1;
return object->getSelectedObj();
}
ConsoleMethod(GameConnection, clearSelectedObj, void, 2, 3, "([propagate_to_client])")
DefineEngineMethod(GameConnection, clearSelectedObj, void, (bool propagate_to_client), (false), "")
{
bool propagate_to_client = (argc > 2) ? dAtob(argv[2]) : false;
object->setSelectedObj(NULL, propagate_to_client);
}
ConsoleMethod(GameConnection, setPreSelectedObjFromRollover, void, 2, 2, "()")
DefineEngineMethod(GameConnection, setPreSelectedObjFromRollover, void, (),, "")
{
object->setPreSelectedObjFromRollover();
}
ConsoleMethod(GameConnection, clearPreSelectedObj, void, 2, 2, "()")
DefineEngineMethod(GameConnection, clearPreSelectedObj, void, (),, "")
{
object->clearPreSelectedObj();
}
ConsoleMethod(GameConnection, setSelectedObjFromPreSelected, void, 2, 2, "()")
DefineEngineMethod(GameConnection, setSelectedObjFromPreSelected, void, (),, "")
{
object->setSelectedObjFromPreSelected();
}
@ -2722,33 +2718,32 @@ void GameConnection::resetDatablockCache()
afx_saved_db_cache_CRC = 0xffffffff;
}
ConsoleFunction(resetDatablockCache, void, 1, 1, "resetDatablockCache()")
DefineEngineFunction(resetDatablockCache, void, (),,"")
{
GameConnection::resetDatablockCache();
}
ConsoleFunction(isDatablockCacheSaved, bool, 1, 1, "resetDatablockCache()")
DefineEngineFunction(isDatablockCacheSaved, bool, (),,"")
{
return afx_saved_db_cache;
}
ConsoleFunction(getDatablockCacheCRC, S32, 1, 1, "getDatablockCacheCRC()")
DefineEngineFunction(getDatablockCacheCRC, S32, (),,"")
{
return (S32)afx_saved_db_cache_CRC;
}
ConsoleFunction(extractDatablockCacheCRC, S32, 2, 2, "extractDatablockCacheCRC(filename)")
DefineEngineFunction(extractDatablockCacheCRC, S32, (const char* fileName),,"")
{
FileStream f_stream;
const char* fileName = argv[1];
if(!f_stream.open(fileName, Torque::FS::File::Read))
if (!f_stream.open(fileName, Torque::FS::File::Read))
{
Con::errorf("Failed to open file '%s'.", fileName);
return -1;
}
U32 stream_sz = f_stream.getStreamSize();
if (stream_sz < 4*32)
if (stream_sz < 4 * 32)
{
Con::errorf("File '%s' is not a valid datablock cache.", fileName);
f_stream.close();
@ -2777,17 +2772,16 @@ ConsoleFunction(extractDatablockCacheCRC, S32, 2, 2, "extractDatablockCacheCRC(f
return (S32)crc_code;
}
ConsoleFunction(setDatablockCacheCRC, void, 2, 2, "setDatablockCacheCRC(crc)")
DefineEngineFunction(setDatablockCacheCRC, void, (U32 crc), , "")
{
GameConnection *conn = GameConnection::getConnectionToServer();
if(!conn)
if (!conn)
return;
U32 crc_u = (U32)dAtoi(argv[1]);
conn->setServerCacheCRC(crc_u);
conn->setServerCacheCRC(crc);
}
ConsoleMethod( GameConnection, saveDatablockCache, void, 2, 2, "saveDatablockCache()")
DefineEngineMethod(GameConnection, saveDatablockCache, void, (),, "")
{
if (GameConnection::serverCacheEnabled() && !afx_saved_db_cache)
{
@ -2802,14 +2796,14 @@ ConsoleMethod( GameConnection, saveDatablockCache, void, 2, 2, "saveDatablockCac
Con::expandScriptFilename(filename_buffer, sizeof(filename_buffer), filename.c_str());
Torque::Path givenPath(Torque::Path::CompressPath(filename_buffer));
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(givenPath);
if ( fileRef == NULL )
if (fileRef == NULL)
Con::errorf("saveDatablockCache() failed to get CRC for file '%s'.", filename.c_str());
else
afx_saved_db_cache_CRC = (S32)fileRef->getChecksum();
}
}
ConsoleMethod( GameConnection, loadDatablockCache, void, 2, 2, "loadDatablockCache()")
DefineEngineMethod(GameConnection, loadDatablockCache, void, (),, "")
{
if (GameConnection::clientCacheEnabled())
{
@ -2817,7 +2811,7 @@ ConsoleMethod( GameConnection, loadDatablockCache, void, 2, 2, "loadDatablockCac
}
}
ConsoleMethod( GameConnection, loadDatablockCache_Begin, bool, 2, 2, "loadDatablockCache_Begin()")
DefineEngineMethod(GameConnection, loadDatablockCache_Begin, bool, (),, "")
{
if (GameConnection::clientCacheEnabled())
{
@ -2827,7 +2821,7 @@ ConsoleMethod( GameConnection, loadDatablockCache_Begin, bool, 2, 2, "loadDatabl
return false;
}
ConsoleMethod( GameConnection, loadDatablockCache_Continue, bool, 2, 2, "loadDatablockCache_Continue()")
DefineEngineMethod(GameConnection, loadDatablockCache_Continue, bool, (),, "")
{
if (GameConnection::clientCacheEnabled())
{

View file

@ -34,7 +34,7 @@ ClientProcessList* ClientProcessList::smClientProcessList = NULL;
ServerProcessList* ServerProcessList::smServerProcessList = NULL;
static U32 gNetOrderNextId = 0;
DefineConsoleFunction( dumpProcessList, void, ( ), ,
DefineEngineFunction( dumpProcessList, void, ( ), ,
"Dumps all ProcessObjects in ServerProcessList and ClientProcessList to the console." )
{
Con::printf( "client process list:" );

View file

@ -114,7 +114,7 @@ static U32 sgServerQueryIndex = 0;
//SERVER FUNCTIONS ONLY
ConsoleFunctionGroupBegin( Containers, "Spatial query functions. <b>Server side only!</b>");
DefineConsoleFunction( containerFindFirst, const char*, (U32 typeMask, Point3F origin, Point3F size), , "(int mask, Point3F point, float x, float y, float z)"
DefineEngineFunction( containerFindFirst, const char*, (U32 typeMask, Point3F origin, Point3F size), , "(int mask, Point3F point, float x, float y, float z)"
"@brief Find objects matching the bitmask type within a box centered at point, with extents x, y, z.\n\n"
"@returns The first object found, or an empty string if nothing was found. Thereafter, you can get more "
"results using containerFindNext()."
@ -146,7 +146,7 @@ DefineConsoleFunction( containerFindFirst, const char*, (U32 typeMask, Point3F o
return buff;
}
DefineConsoleFunction( containerFindNext, const char*, (), , "()"
DefineEngineFunction( containerFindNext, const char*, (), , "()"
"@brief Get more results from a previous call to containerFindFirst().\n\n"
"@note You must call containerFindFirst() to begin the search.\n"
"@returns The next object found, or an empty string if nothing else was found.\n"

View file

@ -440,7 +440,7 @@ static ConsoleDocFragment _lbplayAnimation2(
"void playAnimation(LightAnimData anim);"
);
DefineConsoleMethod( LightBase, playAnimation, void, (const char * anim), (""), "( [LightAnimData anim] )\t"
DefineEngineMethod( LightBase, playAnimation, void, (const char * anim), (""), "( [LightAnimData anim] )\t"
"Plays a light animation on the light. If no LightAnimData is passed the "
"existing one is played."
"@hide")
@ -484,7 +484,7 @@ void LightBase::playAnimation( LightAnimData *animData )
}
}
DefineConsoleMethod( LightBase, pauseAnimation, void, (), , "Stops the light animation." )
DefineEngineMethod( LightBase, pauseAnimation, void, (), , "Stops the light animation." )
{
object->pauseAnimation();
}

View file

@ -494,7 +494,7 @@ ConsoleDocFragment _SpawnSpherespawnObject1(
"bool spawnObject(string additionalProps);"
);
DefineConsoleMethod(SpawnSphere, spawnObject, S32, (String additionalProps), ,
DefineEngineMethod(SpawnSphere, spawnObject, S32, (String additionalProps), ,
"([string additionalProps]) Spawns the object based on the SpawnSphere's "
"class, datablock, properties, and script settings. Allows you to pass in "
"extra properties."

View file

@ -238,7 +238,7 @@ void PhysicsDebrisData::unpackData(BitStream* stream)
shapeName = stream->readSTString();
}
DefineConsoleMethod( PhysicsDebrisData, preload, void, (), ,
DefineEngineMethod( PhysicsDebrisData, preload, void, (), ,
"@brief Loads some information to have readily available at simulation time.\n\n"
"Forces generation of shaders, materials, and other data used by the %PhysicsDebris object. "
"This function should be used while a level is loading in order to shorten "

View file

@ -35,12 +35,11 @@
#include "T3D/physics/physicsWorld.h"
#include "core/util/tNamedFactory.h"
PhysicsPlugin* PhysicsPlugin::smSingleton = NULL;
PhysicsResetSignal PhysicsPlugin::smPhysicsResetSignal;
bool PhysicsPlugin::smSinglePlayer = false;
U32 PhysicsPlugin::smThreadCount = 2;
bool PhysicsPlugin::smGpuAccelerationAllowed = false;
String PhysicsPlugin::smServerWorldName( "server" );
String PhysicsPlugin::smClientWorldName( "client" );
@ -51,6 +50,10 @@ AFTER_MODULE_INIT( Sim )
"@brief Informs the physics simulation if only a single player exists.\n\n"
"If true, optimizations will be implemented to better cater to a single player environmnent.\n\n"
"@ingroup Physics\n");
Con::addVariable("$Physics::gpuAccelerationAllowed", TypeBool, &PhysicsPlugin::smGpuAccelerationAllowed,
"@brief Informs the physics plugin if it is allowed to use gpu acceleration.\n\n"
"Not all physics implemenations or gpus can support gpu acceleration, this simply informs the plugin if it is allowed to try and use it or not.\n\n"
"@ingroup Physics\n");
Con::addVariable( "$pref::Physics::threadCount", TypeS32, &PhysicsPlugin::smThreadCount,
"@brief Number of threads to use in a single pass of the physics engine.\n\n"
"Defaults to 2 if not set.\n\n"
@ -124,31 +127,31 @@ void PhysicsPlugin::_debugDraw( SceneManager *graph, const SceneRenderState *sta
world->onDebugDraw( state );
}
DefineConsoleFunction( physicsPluginPresent, bool, (), , "physicsPluginPresent()"
DefineEngineFunction( physicsPluginPresent, bool, (), , "physicsPluginPresent()"
"@brief Returns true if a physics plugin exists and is initialized.\n\n"
"@ingroup Physics" )
{
return PHYSICSMGR != NULL;
}
DefineConsoleFunction( physicsInit, bool, (const char * library), ("default"), "physicsInit( [string library] )")
DefineEngineFunction( physicsInit, bool, (const char * library), ("default"), "physicsInit( [string library] )")
{
return PhysicsPlugin::activate( library );
}
DefineConsoleFunction( physicsDestroy, void, (), , "physicsDestroy()")
DefineEngineFunction( physicsDestroy, void, (), , "physicsDestroy()")
{
if ( PHYSICSMGR )
PHYSICSMGR->destroyPlugin();
}
DefineConsoleFunction( physicsInitWorld, bool, (const char * worldName), , "physicsInitWorld( String worldName )")
DefineEngineFunction( physicsInitWorld, bool, (const char * worldName), , "physicsInitWorld( String worldName )")
{
bool res = PHYSICSMGR && PHYSICSMGR->createWorld( String( worldName ) );
return res;
}
DefineConsoleFunction( physicsDestroyWorld, void, (const char * worldName), , "physicsDestroyWorld( String worldName )")
DefineEngineFunction( physicsDestroyWorld, void, (const char * worldName), , "physicsDestroyWorld( String worldName )")
{
if ( PHYSICSMGR )
PHYSICSMGR->destroyWorld( worldName );
@ -157,19 +160,19 @@ DefineConsoleFunction( physicsDestroyWorld, void, (const char * worldName), , "p
// Control/query of the stop/started state
// of the currently running simulation.
DefineConsoleFunction( physicsStartSimulation, void, (const char * worldName), , "physicsStartSimulation( String worldName )")
DefineEngineFunction( physicsStartSimulation, void, (const char * worldName), , "physicsStartSimulation( String worldName )")
{
if ( PHYSICSMGR )
PHYSICSMGR->enableSimulation( String( worldName ), true );
}
DefineConsoleFunction( physicsStopSimulation, void, (const char * worldName), , "physicsStopSimulation( String worldName )")
DefineEngineFunction( physicsStopSimulation, void, (const char * worldName), , "physicsStopSimulation( String worldName )")
{
if ( PHYSICSMGR )
PHYSICSMGR->enableSimulation( String( worldName ), false );
}
DefineConsoleFunction( physicsSimulationEnabled, bool, (), , "physicsStopSimulation( String worldName )")
DefineEngineFunction( physicsSimulationEnabled, bool, (), , "physicsStopSimulation( String worldName )")
{
return PHYSICSMGR && PHYSICSMGR->isSimulationEnabled();
}
@ -177,14 +180,14 @@ DefineConsoleFunction( physicsSimulationEnabled, bool, (), , "physicsStopSimulat
// Used for slowing down time on the
// physics simulation, and for pausing/restarting
// the simulation.
DefineConsoleFunction( physicsSetTimeScale, void, (F32 scale), , "physicsSetTimeScale( F32 scale )")
DefineEngineFunction( physicsSetTimeScale, void, (F32 scale), , "physicsSetTimeScale( F32 scale )")
{
if ( PHYSICSMGR )
PHYSICSMGR->setTimeScale( scale );
}
// Get the currently set time scale.
DefineConsoleFunction( physicsGetTimeScale, F32, (), , "physicsGetTimeScale()")
DefineEngineFunction( physicsGetTimeScale, F32, (), , "physicsGetTimeScale()")
{
return PHYSICSMGR && PHYSICSMGR->getTimeScale();
}
@ -193,7 +196,7 @@ DefineConsoleFunction( physicsGetTimeScale, F32, (), , "physicsGetTimeScale()")
// physics simulation that they should store
// their current state for later restoration,
// such as when the editor is closed.
DefineConsoleFunction( physicsStoreState, void, (), , "physicsStoreState()")
DefineEngineFunction( physicsStoreState, void, (), , "physicsStoreState()")
{
PhysicsPlugin::getPhysicsResetSignal().trigger( PhysicsResetEvent_Store );
}
@ -201,13 +204,13 @@ DefineConsoleFunction( physicsStoreState, void, (), , "physicsStoreState()")
// Used to send a signal to objects in the
// physics simulation that they should restore
// their saved state, such as when the editor is opened.
DefineConsoleFunction( physicsRestoreState, void, (), , "physicsRestoreState()")
DefineEngineFunction( physicsRestoreState, void, (), , "physicsRestoreState()")
{
if ( PHYSICSMGR )
PHYSICSMGR->reset();
}
DefineConsoleFunction( physicsDebugDraw, void, (bool enable), , "physicsDebugDraw( bool enable )")
DefineEngineFunction( physicsDebugDraw, void, (bool enable), , "physicsDebugDraw( bool enable )")
{
if ( PHYSICSMGR )
PHYSICSMGR->enableDebugDraw( enable );

View file

@ -96,6 +96,10 @@ public:
/// @see PHYSICSPLUGIN
static PhysicsPlugin* getSingleton() { return smSingleton; }
/// Allow gpu acceleration if supported
static bool smGpuAccelerationAllowed;
static bool gpuAccelerationAllowed() { return smGpuAccelerationAllowed; }
///
static bool activate( const char *library );

View file

@ -26,6 +26,8 @@
//Physics timing
F32 PhysicsWorld::smPhysicsStepTime = 1.0f / 60.f; //default 60fps
U32 PhysicsWorld::smPhysicsMaxSubSteps = 4;
//Gpu acceleration
bool PhysicsWorld::smGpuEnabled = false;
PhysicsWorld::PhysicsWorld()
: mGravity( 0, 0, -20.0f ) // NOTE: This matches the gravity used for player objects.

View file

@ -49,6 +49,9 @@ protected:
/// The current gravity force.
Point3F mGravity;
/// Gpu acceleration
static bool smGpuEnabled;
public:
/// The constructor.
@ -115,6 +118,9 @@ public:
/// Physics timing
static F32 smPhysicsStepTime;
static U32 smPhysicsMaxSubSteps;
/// Gpu acceleration
static bool isGpuEnabled() { return smGpuEnabled; }
};

View file

@ -33,19 +33,43 @@
#define WIN32
#endif
// macOS _DEBUG & NDEBUG
#if defined(TORQUE_OS_MAC) && defined(TORQUE_DEBUG) && !defined(_DEBUG)
#define _DEBUG
#elif defined(TORQUE_OS_MAC) && defined(TORQUE_RELEASE) && !defined(NDEBUG)
#define NDEBUG
#endif
// Linux _DEBUG & NDEBUG
#if defined(TORQUE_OS_LINUX) && defined(TORQUE_DEBUG) && !defined(_DEBUG)
#define _DEBUG
#elif defined(TORQUE_OS_LINUX) && defined(TORQUE_RELEASE) && !defined(NDEBUG)
#define NDEBUG
#endif
//-------------------------------------------------------------------------
//safe release template
template <class T> void SafeReleasePhysx(T* a)
{
if (a)
{
a->release();
a = NULL;
}
}
#include <PxPhysicsAPI.h>
#include <PxExtensionsAPI.h>
#include <PxDefaultErrorCallback.h>
#include <PxDefaultAllocator.h>
#include <PxDefaultSimulationFilterShader.h>
#include <PxDefaultCpuDispatcher.h>
#include <PxShapeExt.h>
#include <PxSimpleFactory.h>
#include <PxFoundation.h>
#include <PxController.h>
#include <PxIO.h>
#include <extensions/PxExtensionsAPI.h>
#include <extensions/PxDefaultErrorCallback.h>
#include <extensions/PxDefaultAllocator.h>
#include <extensions/PxDefaultSimulationFilterShader.h>
#include <extensions/PxDefaultCpuDispatcher.h>
#include <extensions/PxShapeExt.h>
#include <extensions/PxSimpleFactory.h>
#include <foundation/PxFoundation.h>
#include <characterkinematic/PxController.h>
#include <pvd/PxPvd.h>
extern physx::PxPhysics* gPhysics3SDK;

View file

@ -52,12 +52,9 @@ void Px3Body::_releaseActor()
if ( !mActor )
return;
mWorld->releaseWriteLock();
mActor->userData = NULL;
mActor->release();
mActor = NULL;
SafeReleasePhysx(mActor);
mBodyFlags = 0;
if ( mMaterial )
@ -80,7 +77,7 @@ bool Px3Body::init( PhysicsCollision *shape,
AssertFatal( shape, "Px3Body::init - Got a null collision shape!" );
AssertFatal( dynamic_cast<Px3Collision*>( shape ), "Px3Body::init - The collision shape is the wrong type!" );
AssertFatal( !((Px3Collision*)shape)->getShapes().empty(), "Px3Body::init - Got empty collision shape!" );
// Cleanup any previous actor.
_releaseActor();
@ -96,18 +93,20 @@ bool Px3Body::init( PhysicsCollision *shape,
{
mActor = gPhysics3SDK->createRigidDynamic(physx::PxTransform(physx::PxIDENTITY()));
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
actor->setRigidDynamicFlag(physx::PxRigidDynamicFlag::eKINEMATIC, true);
actor->setRigidBodyFlag(physx::PxRigidBodyFlag::eKINEMATIC, true);
actor->setMass(getMax( mass, 1.0f ));
}
else if ( mass > 0.0f )
{
mActor = gPhysics3SDK->createRigidDynamic(physx::PxTransform(physx::PxIDENTITY()));
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
actor->setMaxAngularVelocity(80.f);
}
else
{
mActor = gPhysics3SDK->createRigidStatic(physx::PxTransform(physx::PxIDENTITY()));
mIsStatic = true;
}
}
mMaterial = gPhysics3SDK->createMaterial(0.6f,0.4f,0.1f);
@ -123,12 +122,13 @@ bool Px3Body::init( PhysicsCollision *shape,
Con::errorf("PhysX3 Dynamic Triangle Mesh is not supported.");
}
}
physx::PxShape * pShape = mActor->createShape(*desc->pGeometry,*mMaterial);
physx::PxShape * pShape = physx::PxRigidActorExt::createExclusiveShape(*mActor, *desc->pGeometry, *mMaterial);
physx::PxFilterData colData;
if(isDebris)
colData.word0 = PX3_DEBRIS;
else if(isTrigger)
colData.word0 = PX3_TRIGGER;
colData.word0 = PX3_TRIGGER;
else
colData.word0 = PX3_DEFAULT;
@ -149,10 +149,6 @@ bool Px3Body::init( PhysicsCollision *shape,
physx::PxRigidBodyExt::setMassAndUpdateInertia(*actor,mass);
}
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
mWorld->getScene()->addActor(*mActor);
mIsEnabled = true;
@ -178,9 +174,9 @@ void Px3Body::setMaterial( F32 restitution,
actor->wakeUp();
}
mMaterial->setRestitution(restitution);
mMaterial->setStaticFriction(staticFriction);
mMaterial->setDynamicFriction(friction);
mMaterial->setRestitution(restitution);
mMaterial->setStaticFriction(staticFriction);
mMaterial->setDynamicFriction(friction);
}
@ -322,15 +318,14 @@ Box3F Px3Body::getWorldBounds()
physx::PxBounds3 bounds;
bounds.setEmpty();
physx::PxBounds3 shapeBounds;
physx::PxBounds3 shapeBounds;
U32 shapeCount = mActor->getNbShapes();
physx::PxShape **shapes = new physx::PxShape*[shapeCount];
mActor->getShapes(shapes, shapeCount);
for ( U32 i = 0; i < shapeCount; i++ )
{
// Get the shape's bounds.
// Get the shape's bounds.
shapeBounds = physx::PxShapeExt::getWorldBounds(*shapes[i],*mActor);
// Combine them into the total bounds.
bounds.include( shapeBounds );
@ -350,10 +345,6 @@ void Px3Body::setSimulationEnabled( bool enabled )
if(mBodyFlags & BF_TRIGGER)
return;
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
U32 shapeCount = mActor->getNbShapes();
physx::PxShape **shapes = new physx::PxShape*[shapeCount];
mActor->getShapes(shapes, shapeCount);
@ -367,12 +358,6 @@ void Px3Body::setSimulationEnabled( bool enabled )
void Px3Body::setTransform( const MatrixF &transform )
{
AssertFatal( mActor, "Px3Body::setTransform - The actor is null!" );
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
mActor->setGlobalPose(px3Cast<physx::PxTransform>(transform),false);
@ -380,7 +365,7 @@ void Px3Body::setTransform( const MatrixF &transform )
return;
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
bool kinematic = actor->getRigidDynamicFlags() & physx::PxRigidDynamicFlag::eKINEMATIC;
bool kinematic = actor->getRigidBodyFlags() & physx::PxRigidBodyFlag::eKINEMATIC;
// If its dynamic we have more to do.
if ( isDynamic() && !kinematic )
{
@ -395,10 +380,6 @@ void Px3Body::applyCorrection( const MatrixF &transform )
AssertFatal( mActor, "Px3Body::applyCorrection - The actor is null!" );
AssertFatal( isDynamic(), "Px3Body::applyCorrection - This call is only for dynamics!" );
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
mActor->setGlobalPose( px3Cast<physx::PxTransform>(transform) );
}
@ -406,35 +387,27 @@ void Px3Body::applyImpulse( const Point3F &origin, const Point3F &force )
{
AssertFatal( mActor, "Px3Body::applyImpulse - The actor is null!" );
// This sucks, but it has to happen if we want
// to avoid write lock errors from PhysX right now.
mWorld->releaseWriteLock();
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
if ( mIsEnabled && isDynamic() )
physx::PxRigidBodyExt::addForceAtPos(*actor,px3Cast<physx::PxVec3>(force),
px3Cast<physx::PxVec3>(origin),
physx::PxForceMode::eIMPULSE);
physx::PxRigidBodyExt::addForceAtPos( *actor,px3Cast<physx::PxVec3>(force), px3Cast<physx::PxVec3>(origin), physx::PxForceMode::eIMPULSE );
}
void Px3Body::applyTorque( const Point3F &torque )
void Px3Body::applyTorque(const Point3F &torque)
{
AssertFatal(mActor, "Px3Body::applyImpulse - The actor is null!");
mWorld->releaseWriteLock();
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
if (mIsEnabled && isDynamic())
actor->addTorque( px3Cast<physx::PxVec3>(torque), physx::PxForceMode::eFORCE, true);
actor->addTorque(px3Cast<physx::PxVec3>(torque), physx::PxForceMode::eFORCE, true);
}
void Px3Body::applyForce( const Point3F &force )
void Px3Body::applyForce(const Point3F &force)
{
AssertFatal(mActor, "Px3Body::applyTorque - The actor is null!");
mWorld->releaseWriteLock();
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
if (mIsEnabled && isDynamic())
actor->addForce( px3Cast<physx::PxVec3>(force), physx::PxForceMode::eFORCE, true);
actor->addForce(px3Cast<physx::PxVec3>(force), physx::PxForceMode::eFORCE, true);
}
void Px3Body::findContact(SceneObject **contactObject,

View file

@ -40,7 +40,8 @@ class Px3World;
class Px3Collision;
struct Px3CollisionDesc;
namespace physx{
namespace physx
{
class PxRigidActor;
class PxMaterial;
class PxShape;

View file

@ -36,136 +36,124 @@ Px3Collision::Px3Collision()
}
Px3Collision::~Px3Collision()
{
for ( U32 i=0; i < mColShapes.size(); i++ )
{
Px3CollisionDesc *desc = mColShapes[i];
delete desc->pGeometry;
// Delete the descriptor.
delete desc;
}
{
for ( U32 i=0; i < mColShapes.size(); i++ )
{
Px3CollisionDesc *desc = mColShapes[i];
delete desc->pGeometry;
// Delete the descriptor.
delete desc;
}
mColShapes.clear();
mColShapes.clear();
}
void Px3Collision::addPlane( const PlaneF &plane )
{
physx::PxVec3 pos = px3Cast<physx::PxVec3>(plane.getPosition());
Px3CollisionDesc *desc = new Px3CollisionDesc;
physx::PxVec3 pos = px3Cast<physx::PxVec3>(plane.getPosition());
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxPlaneGeometry();
desc->pose = physx::PxTransform(pos, physx::PxQuat(physx::PxHalfPi, physx::PxVec3(0.0f, -1.0f, 0.0f)));
mColShapes.push_back(desc);
mColShapes.push_back(desc);
}
void Px3Collision::addBox( const Point3F &halfWidth,const MatrixF &localXfm )
{
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxBoxGeometry(px3Cast<physx::PxVec3>(halfWidth));
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxBoxGeometry(px3Cast<physx::PxVec3>(halfWidth));
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
}
void Px3Collision::addSphere( F32 radius,
const MatrixF &localXfm )
void Px3Collision::addSphere( F32 radius, const MatrixF &localXfm )
{
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxSphereGeometry(radius);
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxSphereGeometry(radius);
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
}
void Px3Collision::addCapsule( F32 radius,
F32 height,
const MatrixF &localXfm )
void Px3Collision::addCapsule( F32 radius, F32 height, const MatrixF &localXfm )
{
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxCapsuleGeometry(radius,height*0.5);//uses half height
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxCapsuleGeometry(radius,height*0.5);//uses half height
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
}
bool Px3Collision::addConvex( const Point3F *points,
U32 count,
const MatrixF &localXfm )
bool Px3Collision::addConvex( const Point3F *points, U32 count, const MatrixF &localXfm )
{
physx::PxCooking *cooking = Px3World::getCooking();
physx::PxConvexMeshDesc convexDesc;
convexDesc.points.data = points;
convexDesc.points.stride = sizeof(Point3F);
convexDesc.points.count = count;
convexDesc.flags = physx::PxConvexFlag::eFLIPNORMALS|physx::PxConvexFlag::eCOMPUTE_CONVEX | physx::PxConvexFlag::eINFLATE_CONVEX;
physx::PxCooking *cooking = Px3World::getCooking();
physx::PxConvexMeshDesc convexDesc;
convexDesc.points.data = points;
convexDesc.points.stride = sizeof(Point3F);
convexDesc.points.count = count;
convexDesc.flags = physx::PxConvexFlag::eCOMPUTE_CONVEX | physx::PxConvexFlag::eCHECK_ZERO_AREA_TRIANGLES;
if(PhysicsWorld::isGpuEnabled())
convexDesc.flags |= physx::PxConvexFlag::eGPU_COMPATIBLE;
Px3MemOutStream stream;
if(!cooking->cookConvexMesh(convexDesc,stream))
return false;
Px3MemOutStream stream;
if(!cooking->cookConvexMesh(convexDesc,stream))
return false;
physx::PxConvexMesh* convexMesh;
Px3MemInStream in(stream.getData(), stream.getSize());
convexMesh = gPhysics3SDK->createConvexMesh(in);
physx::PxConvexMesh* convexMesh;
Px3MemInStream in(stream.getData(), stream.getSize());
convexMesh = gPhysics3SDK->createConvexMesh(in);
Px3CollisionDesc *desc = new Px3CollisionDesc;
Px3CollisionDesc *desc = new Px3CollisionDesc;
physx::PxVec3 scale = px3Cast<physx::PxVec3>(localXfm.getScale());
physx::PxQuat rotation = px3Cast<physx::PxQuat>(QuatF(localXfm));
physx::PxMeshScale meshScale(scale,rotation);
desc->pGeometry = new physx::PxConvexMeshGeometry(convexMesh,meshScale);
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
return true;
desc->pGeometry = new physx::PxConvexMeshGeometry(convexMesh,meshScale);
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
return true;
}
bool Px3Collision::addTriangleMesh( const Point3F *vert,
U32 vertCount,
const U32 *index,
U32 triCount,
const MatrixF &localXfm )
bool Px3Collision::addTriangleMesh( const Point3F *vert, U32 vertCount, const U32 *index, U32 triCount, const MatrixF &localXfm )
{
physx::PxCooking *cooking = Px3World::getCooking();
physx::PxTriangleMeshDesc meshDesc;
meshDesc.points.count = vertCount;
meshDesc.points.data = vert;
meshDesc.points.stride = sizeof(Point3F);
physx::PxCooking *cooking = Px3World::getCooking();
physx::PxTriangleMeshDesc meshDesc;
meshDesc.points.count = vertCount;
meshDesc.points.data = vert;
meshDesc.points.stride = sizeof(Point3F);
meshDesc.triangles.count = triCount;
meshDesc.triangles.data = index;
meshDesc.triangles.stride = 3*sizeof(U32);
meshDesc.flags = physx::PxMeshFlag::eFLIPNORMALS;
meshDesc.triangles.count = triCount;
meshDesc.triangles.data = index;
meshDesc.triangles.stride = 3*sizeof(U32);
meshDesc.flags = physx::PxMeshFlag::eFLIPNORMALS;
Px3MemOutStream stream;
if(!cooking->cookTriangleMesh(meshDesc,stream))
return false;
Px3MemOutStream stream;
if(!cooking->cookTriangleMesh(meshDesc,stream))
return false;
physx::PxTriangleMesh *mesh;
Px3MemInStream in(stream.getData(), stream.getSize());
mesh = gPhysics3SDK->createTriangleMesh(in);
physx::PxTriangleMesh *mesh;
Px3MemInStream in(stream.getData(), stream.getSize());
mesh = gPhysics3SDK->createTriangleMesh(in);
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxTriangleMeshGeometry(mesh);
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
return true;
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = new physx::PxTriangleMeshGeometry(mesh);
desc->pose = px3Cast<physx::PxTransform>(localXfm);
mColShapes.push_back(desc);
return true;
}
bool Px3Collision::addHeightfield( const U16 *heights,
const bool *holes,
U32 blockSize,
F32 metersPerSample,
const MatrixF &localXfm )
bool Px3Collision::addHeightfield( const U16 *heights, const bool *holes, U32 blockSize, F32 metersPerSample, const MatrixF &localXfm )
{
const F32 heightScale = 0.03125f;
physx::PxHeightFieldSample* samples = (physx::PxHeightFieldSample*) new physx::PxHeightFieldSample[blockSize*blockSize];
memset(samples,0,blockSize*blockSize*sizeof(physx::PxHeightFieldSample));
const F32 heightScale = 0.03125f;
physx::PxHeightFieldSample* samples = (physx::PxHeightFieldSample*) new physx::PxHeightFieldSample[blockSize*blockSize];
memset(samples,0,blockSize*blockSize*sizeof(physx::PxHeightFieldSample));
physx::PxHeightFieldDesc heightFieldDesc;
heightFieldDesc.nbColumns = blockSize;
heightFieldDesc.nbRows = blockSize;
heightFieldDesc.thickness = -10.f;
heightFieldDesc.convexEdgeThreshold = 0;
heightFieldDesc.format = physx::PxHeightFieldFormat::eS16_TM;
heightFieldDesc.samples.data = samples;
heightFieldDesc.samples.stride = sizeof(physx::PxHeightFieldSample);
physx::PxHeightFieldDesc heightFieldDesc;
heightFieldDesc.nbColumns = blockSize;
heightFieldDesc.nbRows = blockSize;
heightFieldDesc.thickness = -10.f;
heightFieldDesc.convexEdgeThreshold = 0;
heightFieldDesc.format = physx::PxHeightFieldFormat::eS16_TM;
heightFieldDesc.samples.data = samples;
heightFieldDesc.samples.stride = sizeof(physx::PxHeightFieldSample);
physx::PxU8 *currentByte = (physx::PxU8*)heightFieldDesc.samples.data;
physx::PxU8 *currentByte = (physx::PxU8*)heightFieldDesc.samples.data;
for ( U32 row = 0; row < blockSize; row++ )
{
const U32 tess = ( row + 1 ) % 2;
@ -177,7 +165,6 @@ bool Px3Collision::addHeightfield( const U16 *heights,
U32 index = ( blockSize - row - 1 ) + ( column * blockSize );
currentSample->height = (physx::PxI16)heights[ index ];
if ( holes && holes[ getMax( (S32)index - 1, 0 ) ] ) // row index for holes adjusted so PhysX collision shape better matches rendered terrain
{
currentSample->materialIndex0 = physx::PxHeightFieldMaterial::eHOLE;
@ -189,29 +176,30 @@ bool Px3Collision::addHeightfield( const U16 *heights,
currentSample->materialIndex1 = 0;
}
int flag = ( column + tess ) % 2;
if(flag)
currentSample->clearTessFlag();
else
currentSample->setTessFlag();
S32 flag = ( column + tess ) % 2;
if(flag)
currentSample->clearTessFlag();
else
currentSample->setTessFlag();
currentByte += heightFieldDesc.samples.stride;
}
}
physx::PxHeightField * hf = gPhysics3SDK->createHeightField(heightFieldDesc);
physx::PxHeightFieldGeometry *geom = new physx::PxHeightFieldGeometry(hf,physx::PxMeshGeometryFlags(),heightScale,metersPerSample,metersPerSample);
physx::PxCooking *cooking = Px3World::getCooking();
physx::PxHeightField * hf = cooking->createHeightField(heightFieldDesc,gPhysics3SDK->getPhysicsInsertionCallback());
physx::PxHeightFieldGeometry *geom = new physx::PxHeightFieldGeometry(hf,physx::PxMeshGeometryFlags(),heightScale,metersPerSample,metersPerSample);
physx::PxTransform pose= physx::PxTransform(physx::PxQuat(Float_HalfPi, physx::PxVec3(1, 0, 0 )));
physx::PxTransform pose1= physx::PxTransform(physx::PxQuat(Float_Pi, physx::PxVec3(0, 0, 1 )));
physx::PxTransform pose2 = pose1 * pose;
pose2.p = physx::PxVec3(( blockSize - 1 ) * metersPerSample, 0, 0 );
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = geom;
desc->pose = pose2;
physx::PxTransform pose= physx::PxTransform(physx::PxQuat(Float_HalfPi, physx::PxVec3(1, 0, 0 )));
physx::PxTransform pose1= physx::PxTransform(physx::PxQuat(Float_Pi, physx::PxVec3(0, 0, 1 )));
physx::PxTransform pose2 = pose1 * pose;
pose2.p = physx::PxVec3(( blockSize - 1 ) * metersPerSample, 0, 0 );
Px3CollisionDesc *desc = new Px3CollisionDesc;
desc->pGeometry = geom;
desc->pose = pose2;
mColShapes.push_back(desc);
mColShapes.push_back(desc);
SAFE_DELETE(samples);
return true;
return true;
}

View file

@ -23,6 +23,9 @@
#ifndef _PX3COLLISION_H_
#define _PX3COLLISION_H_
#ifndef _PHYSX3_H_
#include "T3D/physics/physx3/px3.h"
#endif
#ifndef _T3D_PHYSICS_PHYSICSCOLLISION_H_
#include "T3D/physics/physicsCollision.h"
#endif

View file

@ -53,7 +53,7 @@ void Px3Player::_releaseController()
{
mController->getActor()->userData = NULL;
mWorld->getStaticChangedSignal().remove( this, &Px3Player::_onStaticChanged );
mController->release();
SafeReleasePhysx(mController);
}
}
@ -136,8 +136,6 @@ Point3F Px3Player::move( const VectorF &disp, CollisionList &outCol )
return newPos;
}
mWorld->releaseWriteLock();
mCollisionList = &outCol;
physx::PxVec3 dispNx( disp.x, disp.y, disp.z );
@ -151,8 +149,8 @@ Point3F Px3Player::move( const VectorF &disp, CollisionList &outCol )
physx::PxFilterData data;
data.word0=groups;
filter.mFilterData = &data;
filter.mFilterFlags = physx::PxSceneQueryFilterFlags(physx::PxControllerFlag::eCOLLISION_DOWN|physx::PxControllerFlag::eCOLLISION_SIDES|physx::PxControllerFlag::eCOLLISION_UP);
filter.mFilterFlags = physx::PxQueryFlags(physx::PxQueryFlag::eDYNAMIC | physx::PxQueryFlag::eSTATIC);
mController->move( dispNx,0.0001f,0, filter );
Point3F newPos = px3Cast<Point3F>( mController->getPosition() );
@ -272,7 +270,6 @@ void Px3Player::enableCollision()
{
AssertFatal( mController, "Px3Player::enableCollision - The controller is null!" );
mWorld->releaseWriteLock();
px3GetFirstShape(mController->getActor())->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE,true);
}
@ -280,7 +277,6 @@ void Px3Player::disableCollision()
{
AssertFatal( mController, "Px3Player::disableCollision - The controller is null!" );
mWorld->releaseWriteLock();
px3GetFirstShape(mController->getActor())->setFlag(physx::PxShapeFlag::eSIMULATION_SHAPE,false);
}
@ -293,8 +289,6 @@ void Px3Player::setTransform( const MatrixF &transform )
{
AssertFatal( mController, "Px3Player::setTransform - The controller is null!" );
mWorld->releaseWriteLock();
Point3F newPos = transform.getPosition();
newPos.z += mOriginOffset;
@ -355,7 +349,6 @@ void Px3Player::setSpacials(const Point3F &nPos, const Point3F &nSize)
F32 height = nSize.z - (radius * 2.0f);
height -= mSkinWidth * 2.0f;
mWorld->releaseWriteLock();
mController->resize(height);
px3GetFirstShape(mController->getActor())->getCapsuleGeometry(mGeometry);
}

View file

@ -83,10 +83,7 @@ Px3ConsoleStream::~Px3ConsoleStream()
{
}
void Px3ConsoleStream::reportError( physx::PxErrorCode code, const char *message, const char* file, int line )
void Px3ConsoleStream::reportError(physx::PxErrorCode::Enum code, const char* message, const char* file, int line)
{
UTF8 info[1024];
dSprintf( info, 1024, "File: %s\nLine: %d\n%s", file, line, message );
Platform::AlertOK( "PhysX Error", info );
// Con::printf( "PhysX Error:\n %s(%d) : %s\n", file, line, message );
}
Con::warnf( "PhysX Warning: %s(%d) : %s", file, line, message );
}

View file

@ -62,11 +62,11 @@ protected:
};
class Px3ConsoleStream : public physx::PxDefaultErrorCallback
class Px3ConsoleStream : public physx::PxErrorCallback
{
protected:
virtual void reportError( physx::PxErrorCode code, const char *message, const char* file, int line );
virtual void reportError(physx::PxErrorCode::Enum code, const char* message, const char* file, int line);
public:

View file

@ -41,27 +41,31 @@
#include "gfx/sim/debugDraw.h"
#include "gfx/primBuilder.h"
physx::PxPhysics* gPhysics3SDK = NULL;
physx::PxCooking* Px3World::smCooking = NULL;
physx::PxFoundation* Px3World::smFoundation = NULL;
physx::PxProfileZoneManager* Px3World::smProfileZoneManager = NULL;
physx::PxDefaultCpuDispatcher* Px3World::smCpuDispatcher=NULL;
physx::PxDefaultCpuDispatcher* Px3World::smCpuDispatcher = NULL;
#ifndef TORQUE_OS_MAC
physx::PxCudaContextManager* Px3World::smCudaContextManager = NULL;
#endif
Px3ConsoleStream* Px3World::smErrorCallback = NULL;
physx::PxVisualDebuggerConnection* Px3World::smPvdConnection=NULL;
physx::PxPvd* Px3World::smPvdConnection = NULL;
physx::PxPvdTransport* Px3World::smPvdTransport = NULL;
physx::PxDefaultAllocator Px3World::smMemoryAlloc;
Px3World::Px3World(): mScene( NULL ),
mProcessList( NULL ),
mIsSimulating( false ),
mErrorReport( false ),
mTickCount( 0 ),
Px3World::Px3World() :
mScene( NULL ),
mIsEnabled( false ),
mIsSimulating( false ),
mIsServer( false ),
mIsSceneLocked( false ),
mTickCount( 0 ),
mProcessList( NULL ),
mEditorTimeScale( 1.0f ),
mAccumulator( 0 ),
mErrorReport( false ),
mControllerManager(NULL),
mIsSceneLocked(false),
mRenderBuffer(NULL)
mRenderBuffer(NULL),
mAccumulator( 0 )
{
}
@ -80,33 +84,25 @@ bool Px3World::restartSDK( bool destroyOnly, Px3World *clientWorld, Px3World *se
// then we cannot reset the SDK.
if ( clientWorld || serverWorld )
return false;
if(smPvdConnection)
smPvdConnection->release();
if(smCooking)
smCooking->release();
if(smCpuDispatcher)
smCpuDispatcher->release();
#ifndef TORQUE_OS_MAC
SafeReleasePhysx(smCudaContextManager);
#endif
SafeReleasePhysx(smCpuDispatcher);
SafeReleasePhysx(smCooking);
smGpuEnabled = false;
// Destroy the existing SDK.
if ( gPhysics3SDK )
{
PxCloseExtensions();
gPhysics3SDK->release();
SafeReleasePhysx(gPhysics3SDK);
}
if(smErrorCallback)
{
SAFE_DELETE(smErrorCallback);
}
SafeReleasePhysx(smPvdConnection);
SafeReleasePhysx(smPvdTransport);
if(smFoundation)
{
smFoundation->release();
SAFE_DELETE(smErrorCallback);
}
SAFE_DELETE(smErrorCallback);
SafeReleasePhysx(smFoundation);
// If we're not supposed to restart... return.
if ( destroyOnly )
@ -114,20 +110,18 @@ bool Px3World::restartSDK( bool destroyOnly, Px3World *clientWorld, Px3World *se
bool memTrack = false;
#ifdef TORQUE_DEBUG
memTrack = true;
memTrack = false;
#endif
smErrorCallback = new Px3ConsoleStream;
smFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, smMemoryAlloc, *smErrorCallback);
smProfileZoneManager = &physx::PxProfileZoneManager::createProfileZoneManager(smFoundation);
gPhysics3SDK = PxCreatePhysics(PX_PHYSICS_VERSION, *smFoundation, physx::PxTolerancesScale(),memTrack,smProfileZoneManager);
smFoundation = PxCreateFoundation(PX_FOUNDATION_VERSION, smMemoryAlloc, *smErrorCallback);
smPvdConnection = PxCreatePvd(*smFoundation);
gPhysics3SDK = PxCreatePhysics(PX_PHYSICS_VERSION, *smFoundation, physx::PxTolerancesScale(),memTrack, smPvdConnection);
if ( !gPhysics3SDK )
{
Con::errorf( "PhysX3 failed to initialize!" );
Platform::messageBox( Con::getVariable( "$appName" ),
avar("PhysX3 could not be started!\r\n"),
MBOk, MIStop );
Platform::messageBox( Con::getVariable( "$appName" ), avar("PhysX3 could not be started!\r\n"), MBOk, MIStop );
Platform::forceShutdown( -1 );
// We shouldn't get here, but this shuts up
@ -135,33 +129,67 @@ bool Px3World::restartSDK( bool destroyOnly, Px3World *clientWorld, Px3World *se
return false;
}
if(!PxInitExtensions(*gPhysics3SDK))
if(!PxInitExtensions(*gPhysics3SDK, smPvdConnection))
{
Con::errorf( "PhysX3 failed to initialize extensions!" );
Platform::messageBox( Con::getVariable( "$appName" ),
avar("PhysX3 could not be started!\r\n"),
MBOk, MIStop );
Platform::messageBox( Con::getVariable( "$appName" ), avar("PhysX3 could not be started!\r\n"), MBOk, MIStop );
Platform::forceShutdown( -1 );
return false;
}
//no gpu support on macOS
#ifndef TORQUE_OS_MAC
//check if we are allowed to use gpu acceleration
if (PhysicsPlugin::gpuAccelerationAllowed())
{
// attempt to create a cuda context manager - only works on nvidia gpu (SM 3.0+ i.e kepler or better)
if (!smCpuDispatcher)
{
//check we have capable gpu, -1 means none found
S32 suggestedGpu = PxGetSuggestedCudaDeviceOrdinal(*smErrorCallback);
if (suggestedGpu != -1)
{
physx::PxCudaContextManagerDesc cudaContextManagerDesc;
smCudaContextManager = PxCreateCudaContextManager(*smFoundation, cudaContextManagerDesc);
if (smCudaContextManager)
smGpuEnabled = true;
}
}
}
#endif
smCooking = PxCreateCooking(PX_PHYSICS_VERSION, *smFoundation, physx::PxCookingParams(physx::PxTolerancesScale()));
//cpu dispatcher
if (!smCpuDispatcher)
smCpuDispatcher = physx::PxDefaultCpuDispatcherCreate(PHYSICSMGR->getThreadCount());
physx::PxCookingParams params = physx::PxCookingParams(physx::PxTolerancesScale());
params.meshWeldTolerance = 0.001f;
params.meshPreprocessParams = physx::PxMeshPreprocessingFlags(physx::PxMeshPreprocessingFlag::eWELD_VERTICES);
#ifndef TORQUE_OS_MAC
if(smGpuEnabled)
params.buildGPUData = true;
#endif
smCooking = PxCreateCooking(PX_PHYSICS_VERSION, *smFoundation, params);
if(!smCooking)
{
Con::errorf( "PhysX3 failed to initialize cooking!" );
Platform::messageBox( Con::getVariable( "$appName" ),
avar("PhysX3 could not be started!\r\n"),
MBOk, MIStop );
Platform::messageBox( Con::getVariable( "$appName" ), avar("PhysX3 could not be started!\r\n"), MBOk, MIStop );
Platform::forceShutdown( -1 );
return false;
}
//TODO: enable/disable this from script
#ifdef TORQUE_DEBUG
physx::PxVisualDebuggerConnectionFlags connectionFlags(physx::PxVisualDebuggerExt::getAllConnectionFlags());
smPvdConnection = physx::PxVisualDebuggerExt::createConnection(gPhysics3SDK->getPvdConnectionManager(),
"localhost", 5425, 100, connectionFlags);
if(!smPvdTransport)
smPvdTransport = physx::PxDefaultPvdSocketTransportCreate("localhost", 5425, 100);
smPvdConnection->connect(*smPvdTransport, physx::PxPvdInstrumentationFlag::eALL);
#endif
//use legacy heightfield
//TODO: new method causing crashes on collision in debug build (unified HeightFields)
PxRegisterLegacyHeightFields(*gPhysics3SDK);
return true;
}
@ -169,8 +197,6 @@ void Px3World::destroyWorld()
{
getPhysicsResults();
mRenderBuffer = NULL;
// Release the tick processing signals.
if ( mProcessList )
{
@ -179,19 +205,9 @@ void Px3World::destroyWorld()
mProcessList = NULL;
}
if(mControllerManager)
{
mControllerManager->release();
mControllerManager = NULL;
}
SafeReleasePhysx(mControllerManager);
// Destroy the scene.
if ( mScene )
{
// Release the scene.
mScene->release();
mScene = NULL;
}
SafeReleasePhysx(mScene);
}
bool Px3World::initWorld( bool isServer, ProcessList *processList )
@ -203,27 +219,32 @@ bool Px3World::initWorld( bool isServer, ProcessList *processList )
}
mIsServer = isServer;
physx::PxSceneDesc sceneDesc(gPhysics3SDK->getTolerancesScale());
sceneDesc.gravity = px3Cast<physx::PxVec3>(mGravity);
sceneDesc.userData = this;
if(!sceneDesc.cpuDispatcher)
{
//Create shared cpu dispatcher
if(!smCpuDispatcher)
smCpuDispatcher = physx::PxDefaultCpuDispatcherCreate(PHYSICSMGR->getThreadCount());
sceneDesc.cpuDispatcher = smCpuDispatcher;
Con::printf("PhysX3 using Cpu: %d workers", smCpuDispatcher->getWorkerCount());
sceneDesc.cpuDispatcher = smCpuDispatcher;
Con::printf("PhysX3 using Cpu: %d workers", smCpuDispatcher->getWorkerCount());
#ifndef TORQUE_OS_MAC
if (smGpuEnabled)
{
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_GPU_DYNAMICS;
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_PCM;
sceneDesc.broadPhaseType = physx::PxBroadPhaseType::eGPU;
sceneDesc.gpuDispatcher = smCudaContextManager->getGpuDispatcher();
Con::printf("PhysX3 using Gpu: %s", smCudaContextManager->getDeviceName());
}
#endif
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_CCD;
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_ACTIVETRANSFORMS;
sceneDesc.filterShader = physx::PxDefaultSimulationFilterShader;
mScene = gPhysics3SDK->createScene(sceneDesc);
//cache renderbuffer for use with debug drawing
mScene = gPhysics3SDK->createScene(sceneDesc);
mRenderBuffer = const_cast<physx::PxRenderBuffer*>(&mScene->getRenderBuffer());
physx::PxDominanceGroupPair debrisDominance( 0.0f, 1.0f );
@ -252,15 +273,16 @@ bool Px3World::_simulate(const F32 dt)
if (numSimulationSubSteps)
{
//clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
S32 clampedSimulationSteps = (numSimulationSubSteps > smPhysicsMaxSubSteps)? smPhysicsMaxSubSteps : numSimulationSubSteps;
S32 clampedSimulationSteps = (numSimulationSubSteps > smPhysicsMaxSubSteps) ? smPhysicsMaxSubSteps : numSimulationSubSteps;
for (S32 i=0;i<clampedSimulationSteps;i++)
{
mScene->fetchResults(true);
if(i > 0)
mScene->fetchResults(true);
mScene->simulate(smPhysicsStepTime);
}
}
mIsSimulating = true;
return true;
@ -299,36 +321,6 @@ void Px3World::getPhysicsResults()
mScene->fetchResults(true);
mIsSimulating = false;
mTickCount++;
// Con::printf( "%s PhysXWorld::getPhysicsResults!", this == smClientWorld ? "Client" : "Server" );
}
void Px3World::releaseWriteLocks()
{
Px3World *world = dynamic_cast<Px3World*>( PHYSICSMGR->getWorld( "server" ) );
if ( world )
world->releaseWriteLock();
world = dynamic_cast<Px3World*>( PHYSICSMGR->getWorld( "client" ) );
if ( world )
world->releaseWriteLock();
}
void Px3World::releaseWriteLock()
{
if ( !mScene || !mIsSimulating )
return;
PROFILE_SCOPE(PxWorld_ReleaseWriteLock);
// We use checkResults here to release the write lock
// but we do not change the simulation flag or increment
// the tick count... we may have gotten results, but the
// simulation hasn't really ticked!
mScene->checkResults( true );
//AssertFatal( mScene->isWritable(), "PhysX3World::releaseWriteLock() - We should have been writable now!" );
}
void Px3World::lockScenes()
@ -388,8 +380,7 @@ void Px3World::unlockScene()
}
bool Px3World::castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo *ri, const Point3F &impulse )
{
{
physx::PxVec3 orig = px3Cast<physx::PxVec3>( startPnt );
physx::PxVec3 dir = px3Cast<physx::PxVec3>( endPnt - startPnt );
physx::PxF32 maxDist = dir.magnitude();
@ -398,15 +389,15 @@ bool Px3World::castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo
U32 groups = 0xffffffff;
groups &= ~( PX3_TRIGGER ); // No trigger shapes!
physx::PxHitFlags outFlags(physx::PxHitFlag::eDISTANCE | physx::PxHitFlag::eIMPACT | physx::PxHitFlag::eNORMAL);
physx::PxHitFlags outFlags(physx::PxHitFlag::eDISTANCE | physx::PxHitFlag::ePOSITION | physx::PxHitFlag::eNORMAL);
physx::PxQueryFilterData filterData(physx::PxQueryFlag::eSTATIC|physx::PxQueryFlag::eDYNAMIC);
filterData.data.word0 = groups;
physx::PxRaycastBuffer buf;
if(!mScene->raycast(orig,dir,maxDist,buf,outFlags,filterData))
return false;
return false;
if(!buf.hasBlock)
return false;
return false;
const physx::PxRaycastHit hit = buf.block;
physx::PxRigidActor *actor = hit.actor;
@ -425,8 +416,8 @@ bool Px3World::castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo
}
if ( impulse.isZero() ||
!actor->isRigidDynamic() ||
actor->is<physx::PxRigidDynamic>()->getRigidDynamicFlags() & physx::PxRigidDynamicFlag::eKINEMATIC )
!actor->is<physx::PxRigidDynamic>() ||
actor->is<physx::PxRigidDynamic>()->getRigidBodyFlags() & physx::PxRigidBodyFlag::eKINEMATIC )
return true;
physx::PxRigidBody *body = actor->is<physx::PxRigidBody>();
@ -453,7 +444,7 @@ PhysicsBody* Px3World::castRay( const Point3F &start, const Point3F &end, U32 bo
groups &= ~( PX3_TRIGGER ); // triggers
groups &= ~( PX3_DEBRIS ); // debris
physx::PxHitFlags outFlags(physx::PxHitFlag::eDISTANCE | physx::PxHitFlag::eIMPACT | physx::PxHitFlag::eNORMAL);
physx::PxHitFlags outFlags(physx::PxHitFlag::eDISTANCE | physx::PxHitFlag::ePOSITION | physx::PxHitFlag::eNORMAL);
physx::PxQueryFilterData filterData;
if(bodyTypes & BT_Static)
filterData.flags |= physx::PxQueryFlag::eSTATIC;
@ -491,12 +482,12 @@ void Px3World::explosion( const Point3F &pos, F32 radius, F32 forceMagnitude )
{
physx::PxRigidActor *actor = buffer.touches[i].actor;
bool dynamic = actor->isRigidDynamic();
bool dynamic = actor->is<physx::PxRigidDynamic>();
if ( !dynamic )
continue;
bool kinematic = actor->is<physx::PxRigidDynamic>()->getRigidDynamicFlags() & physx::PxRigidDynamicFlag::eKINEMATIC;
bool kinematic = actor->is<physx::PxRigidDynamic>()->getRigidBodyFlags() & physx::PxRigidBodyFlag::eKINEMATIC;
if ( kinematic )
continue;
@ -523,8 +514,6 @@ physx::PxController* Px3World::createController( physx::PxControllerDesc &desc )
if ( !mScene )
return NULL;
// We need the writelock!
releaseWriteLock();
physx::PxController* pController = mControllerManager->createController(desc);
AssertFatal( pController, "Px3World::createController - Got a null!" );
return pController;
@ -543,7 +532,7 @@ static ColorI getDebugColor( physx::PxU32 packed )
void Px3World::onDebugDraw( const SceneRenderState *state )
{
if ( !mScene || !mRenderBuffer )
if ( !mScene || !mRenderBuffer)
return;
mScene->setVisualizationParameter(physx::PxVisualizationParameter::eSCALE,1.0f);

View file

@ -23,15 +23,15 @@
#ifndef _PX3WORLD_H_
#define _PX3WORLD_H_
#ifndef _PHYSX3_H_
#include "T3D/physics/physx3/px3.h"
#endif
#ifndef _T3D_PHYSICS_PHYSICSWORLD_H_
#include "T3D/physics/physicsWorld.h"
#endif
#ifndef _MMATH_H_
#include "math/mMath.h"
#endif
#ifndef _PHYSX3_H_
#include "T3D/physics/physx3/px3.h"
#endif
#ifndef _TVECTOR_H_
#include "core/util/tVector.h"
#endif
@ -51,26 +51,29 @@ enum Px3CollisionGroup
class Px3World : public PhysicsWorld
{
protected:
physx::PxScene* mScene;
bool mIsEnabled;
bool mIsSimulating;
bool mIsServer;
bool mIsSceneLocked;
bool mIsSceneLocked;
U32 mTickCount;
ProcessList *mProcessList;
F32 mEditorTimeScale;
bool mErrorReport;
physx::PxRenderBuffer *mRenderBuffer;
physx::PxControllerManager* mControllerManager;
physx::PxRenderBuffer *mRenderBuffer;
F32 mAccumulator;
static Px3ConsoleStream *smErrorCallback;
static physx::PxDefaultAllocator smMemoryAlloc;
static physx::PxFoundation* smFoundation;
static physx::PxCooking *smCooking;
static physx::PxProfileZoneManager* smProfileZoneManager;
static physx::PxDefaultCpuDispatcher* smCpuDispatcher;
static physx::PxVisualDebuggerConnection* smPvdConnection;
F32 mAccumulator;
#ifndef TORQUE_OS_MAC
static physx::PxCudaContextManager* smCudaContextManager;
#endif
static physx::PxPvd* smPvdConnection;
static physx::PxPvdTransport* smPvdTransport;
bool _simulate(const F32 dt);
public:
@ -86,21 +89,20 @@ public:
virtual PhysicsBody* castRay( const Point3F &start, const Point3F &end, U32 bodyTypes = BT_All );
virtual void explosion( const Point3F &pos, F32 radius, F32 forceMagnitude );
virtual bool isEnabled() const { return mIsEnabled; }
physx::PxScene* getScene(){ return mScene;}
physx::PxScene* getScene(){ return mScene; }
void setEnabled( bool enabled );
U32 getTick() { return mTickCount; }
void tickPhysics( U32 elapsedMs );
void getPhysicsResults();
void setEditorTimeScale( F32 timeScale ) { mEditorTimeScale = timeScale; }
const F32 getEditorTimeScale() const { return mEditorTimeScale; }
void releaseWriteLock();
bool isServer(){return mIsServer;}
bool isServer() { return mIsServer; }
physx::PxController* createController( physx::PxControllerDesc &desc );
void lockScene();
void unlockScene();
//static
static bool restartSDK( bool destroyOnly = false, Px3World *clientWorld = NULL, Px3World *serverWorld = NULL );
static void releaseWriteLocks();
static physx::PxCooking *getCooking();
static void lockScenes();
static void unlockScenes();

View file

@ -7518,7 +7518,7 @@ U32 Player::lockAnimation()
return last_anim_lock_tag;
}
ConsoleMethod(Player, isAnimationLocked, bool, 2, 2, "isAnimationLocked()")
DefineEngineMethod(Player, isAnimationLocked, bool, (),, "")
{
return object->isAnimationLocked();
}
@ -7534,14 +7534,13 @@ void Player::setLookAnimationOverride(bool flag)
#endif
}
ConsoleMethod(Player, setLookAnimationOverride, void, 3, 3, "setLookAnimationOverride(flag)")
DefineEngineMethod(Player, setLookAnimationOverride, void, (bool flag),, "")
{
object->setLookAnimationOverride(dAtob(argv[2]));
object->setLookAnimationOverride(flag);
}
ConsoleMethod(Player, copyHeadRotation, void, 3, 3, "copyHeadRotation(other_player)")
DefineEngineMethod(Player, copyHeadRotation, void, (Player* other_player),, "")
{
Player* other_player = dynamic_cast<Player*>(Sim::findObject(argv[2]));
if (other_player)
object->copyHeadRotation(other_player);
}
@ -7610,9 +7609,9 @@ void Player::restoreMovement(U32 tag)
}
}
ConsoleMethod(Player, setMovementSpeedBias, void, 3, 3, "setMovementSpeedBias(F32 bias)")
DefineEngineMethod(Player, setMovementSpeedBias, void, (F32 bias),, "setMovementSpeedBias(F32 bias)")
{
object->setMovementSpeedBias(dAtof(argv[2]));
object->setMovementSpeedBias(bias);
}
void Player::overrideFootfallFX(bool decals, bool sounds, bool dust)
@ -7643,12 +7642,11 @@ void Player::setControllers(Vector<OpenVRTrackedObject*> controllerList)
mControllers[1] = controllerList.size() > 1 ? controllerList[1] : NULL;
}
ConsoleMethod(Player, setVRControllers, void, 4, 4, "")
DefineEngineMethod(Player, setVRControllers, void, (OpenVRTrackedObject* controllerL, OpenVRTrackedObject* controllerR,, "")
{
OpenVRTrackedObject *controllerL, *controllerR;
Vector<OpenVRTrackedObject*> list;
if (Sim::findObject(argv[2], controllerL))
if (controllerL)
{
list.push_back(controllerL);
}
@ -7657,7 +7655,7 @@ ConsoleMethod(Player, setVRControllers, void, 4, 4, "")
list.push_back(NULL);
}
if (Sim::findObject(argv[3], controllerR))
if (controllerR)
{
list.push_back(controllerR);
}

View file

@ -314,7 +314,7 @@ void StaticShape::unpackUpdate(NetConnection *connection, BitStream *bstream)
// This appears to be legacy T2 stuff
// Marked internal, as this is flagged to be deleted
// [8/1/2010 mperry]
DefineConsoleMethod( StaticShape, setPoweredState, void, (bool isPowered), , "(bool isPowered)"
DefineEngineMethod( StaticShape, setPoweredState, void, (bool isPowered), , "(bool isPowered)"
"@internal")
{
if(!object->isServerObject())
@ -322,7 +322,7 @@ DefineConsoleMethod( StaticShape, setPoweredState, void, (bool isPowered), , "(b
object->setPowered(isPowered);
}
DefineConsoleMethod( StaticShape, getPoweredState, bool, (), , "@internal")
DefineEngineMethod( StaticShape, getPoweredState, bool, (), , "@internal")
{
if(!object->isServerObject())
return(false);