The Physics Server is a process which gives HeroEngine a representation of world geometry on the server side. Because the entire world space can be too large to be represented in one Area Server process, the physics server is designed to scale by being instantiated more than once.
Placement in the engine infrastructure
Within the Engine infrastructure of HeroEngine, each Physics Server is a dynamic process, which is started and stopped by the Physics Server Director process as needed. The Physics Server Director manages the instantiations of the Physics Server processes, ensuring that processing space is available for any areas requesting physics services. Each dynamic Physics Server process is run on one of the machines in the Server Group, depending on load.
A single Physics Server process might handle the physics and path planning for multiple areas.
A separate PathMaker process is also managed by the Physics Server Director. The PathMaker process uses the same executable as the Physics Server process, but is tasked with a different purpose. Each World has only one PathMaker process, which handles updates to all areas in that world, in a queued fashion. The PathMaker process will detect whenever the .dat files for an area have changed in the repository, which will trigger the PathMaker to queue up a request to create a new HeroPath navmesh for that area. The new HeroPath navmesh is then stored in the Repository for that Area.
For various tutorials on how physics works in HeroEngine, see Physics tutorials
Building the Physics Server and Director
Non-source code customers
As a non-source code customers, these executables will be provided.
Source code customers
For source code customers, these executables are built by the HJServers solution in $/hjservers/ where "$" represents the root of the branch.
In addition to building this solution, the physics server relies on several DLL plug-ins. These are built and copied to the $/hjservers/run directory by building the HJServers solution file in $/he_plugins/compiler/vc8/. The file $/rebuild_stuff.cmd will automatically rebuild everything needed by running it with a parameter of "hj" or "all".
Using the Physics Server
A game can use physics server features by calling the physics server external functions from script code. The application of the HeroEngine Publish Package that is built along with the release of the latest code/executables will add these external function definitions. Because the physics server is a separate process from the area server running the script code, all responses from the physics server will return to the script engine asynchronously. For each physics server request that has a response, a script entry point has been defined in the _MethodCallbacksClassMethods script. To use these functions, the game will need to create classes which implement the callback methods. When making a physics request, a NodeRef to a node which has the class is required. The callback method will be called on the node provided.
This section includes a few of the commonly used physics functions, but is not complete. For a complete list of physics-related functions, search on "Physics" in the _ExternalFunctions server-side script.
external function StartPhysics()
The most important external function is the call that requests a scene for the area from the pool of physics servers. If this function is not called in an area server, all other physics external functions will return false. This registration process can fail. It does not currently have an asynchronous notification.
external function PhysicsCoreDump(dumpFileName as String) as Boolean
This is a debugging function. It instructs the physics server assigned to this area server to dump an xml file containing a description of all actors currently in all scenes on the physics server. There is no notification method.
external function PhysicsStartLogging(logFileName as String) as Boolean
This is a debugging function. It causes the physics server assigned to the area server to log all api calls to the given file name. There is no notification method.
external function RaycastOneHit(requestingNode as NodeRef, requestID as ID, sourcePoint as Vector3, direction as Vector3, length as Float) as Boolean
This function asks the physics server to perform a raycast. The raycast stops after the first piece of geometry is hit. The notification method is method _RaycastOneHitResult(requestID as ID, nodeStruck as NodeRef, locationStruck as Vector3). If no geometry was hit, the nodeStruck will be set to None.
external function OverlapRay(requestingNode as NodeRef, requestID as ID, sourcePoint as Vector3, destinationPoint as Vector3) as Boolean external function OverlapSphere(requestingNode as NodeRef, requestID as ID, sourcePoint as Vector3, radius as Float) as Boolean external function OverlapAABB(requestingNode as NodeRef, requestID as ID, center as Vector3, extents as Vector3) as Boolean external function OverlapCapsule(requestingNode as NodeRef, requestID as ID, point1 as Vector3, point2 as Vector3, radius as Float) as Boolean external function OverlapSweptCapsule(requestingNode as NodeRef, requestID as ID, point1 as Vector3, point2 as Vector3, radius as Float, motion as Vector3) as Boolean external function OverlapOBB(requestingNode as NodeRef, requestID as ID, center as Vector3, extents as Vector3, rotation as Vector3) as Boolean external function OverlapSweptOBB(requestingNode as NodeRef, requestID as ID, center as Vector3, extents as Vector3, rotation as Vector3, motion as Vector3) as Boolean
All the overlap request functions test a particular test shape against the geometry in the scene. The results of the test are given by calling the method _OverlapResult(requestID as ID, instancesOverlapped as List of NodeRef).
Physics Character functions
external function CreatePhysicsBoxCharacter(requestingNode as NodeRef, physics_character_id_out references ID, extents as Vector3, slopeLimit as Float, skinWidth as Float, position as Vector3, gravity as Float) as Boolean external function CreatePhysicsCapsuleCharacter(requestingNode as NodeRef, physics_character_id_out references ID, height as Float, width as Float, slopeLimit as Float, skinWidth as Float, position as Vector3, gravity as Float) as Boolean
The Physics Character functions create a PhysX Character Controller in the physics scene. The character controller is a generic approximation of a character's volume (box or capsule) that can be moved around the scene. The Character Controller, when told to move, will do continuous collision detection and handle wall-sliding, slope limits and steps. This is merely a collision detection system and not intended to mimic the precise movement of animated characters. Nor can it respond in precisely the same way that any arbitrary character controller on the client will. But for some situations, this can be used to detect (with some degree of accuracy) where characters "should" end up. Think of possibilities like knock-back resolution or cheat detection. Moving lots of character controllers is an expensive operation, so this should be done low-frequency and only when necessary. The callback method _PhysicsCharacterCreated(characterID as ID, successful as Boolean) will be called asynchronously with the response of the create request.
external function TeleportPhysicsCharacter(requestingNode as NodeRef, characterID as ID, position as Vector3) as Boolean external function MovePhysicsCharacter(requestingNode as NodeRef, characterID as ID, positionDelta as Vector3) as Boolean
These functions are used to move the physics character around the scene. Teleportation is movement that ignores collision response. Move requests follow the continuous collision model and may not actually move the character exactly to where the positionDelta describes. Both of these requests receive a callback on method _PhysicsCharacterMoveComplete(characterID as ID, position as Vector3).
external function DestroyPhysicsCharacter(requestingNode as NodeRef, characterID as ID) as Boolean
This function removes a physics character from the scene. The callback method _PhysicsCharacterDestroyed(characterID as ID, success as Boolean) is called with the result.