My Project
|
Animate the entire scene for a fixed time interval advance. More...
#include <EnvironmentSim.h>
Public Member Functions | |
virtual SIMULATOR_TYPE | GetSimulatorType () |
return the current type of simulator. More... | |
virtual void | Animate (double dTimeDelta) |
called each frame to simulate the game world. More... | |
virtual void | CheckLoadPhysics (CShapeSphere *points, int nPointCount=1) |
when this function is called, it ensures that the physics object around one or more points are properly loaded. More... | |
virtual void | Release () |
delete this object. More... | |
![]() | |
void | CheckLoadPhysics (const Vector3 &vCenter, float fRadius) |
virtual CNetTime * | GetNetTime () |
get the net time object More... | |
Additional Inherited Members | |
![]() | |
enum | SIMULATOR_TYPE { SIM_TYPE_STANDALONE = 0, SIM_TYPE_SERVER = 1, SIM_TYPE_CLIENT = 2 } |
![]() | |
static void | EnableLog (bool bWriteLog) |
static bool | IsLogEnabled () |
Animate the entire scene for a fixed time interval advance.
Path-finding, collision detection and response are implemented in this module. Game physics, AI controller, some script triggering are also done by the simulator. The simulator will not allow a time advance that is too big, but smaller time advance will make the game run too slow. In most cases, it is called 30 times per seconds. The most frequently used functions are: (1) m_pRootScene : Set the scene to compute (2) Animate(dTimeDelta) : Compute next scene
Character simulation now supports unlimited number of global and local characters. The simulator will automatically put unrelated game object to sleep and wake up related ones.In case of a single server, 2000 players with 100,000++ creatures may be in the scene. However, there may only be 3000+ sentient game objects, all others are put to sleep. The simulation complexity is O(N.log(M)), where N is number of sentient game objects, M is the total number of characters attached to the scene.
Some attributes of IGameObject may affect the simulation behavior of the simulator. The most important ones are:
m_nGroup: the group ID to which this object belongs to. In order to be detected by other game object. Object needs to be in group 0 to 31. default value is 0 m_dwSentientField: a bit field of sentient object. from lower bit to higher bits, it matches to the 0-31 groups.
An object can only be waken up by or perceive other objects whose group ID is marked in the object's m_dwSentientField. For example. if the sentient field of object is 101 (binary form), then it can only detect objects whose group ID is 0 and 2.
|
virtual |
called each frame to simulate the game world.
desc: Environment collision detection and response call this function at every frame move.
dTimeDelta | in seconds. |
It's up to this simulator to decide how much computation is done each call. In other words, some computational extensive checking is done every few seconds and in multiple calls. In other words, the function will guarantee that the amount of computation for each call is balanced. Collision pairs are saved in m_pCollisionPairs, which may be used for AI simulation or game interface
[RIGHT: persistent collision] the ideal collision is like this: Once in collision always in collision, unless the user or sim has moved object away. Collision in this sense is better interpreted as touched against one other, like player and NPC.
[WRONG: collision only occurs once, then disapears]Collision is handled like this: we will implement one step look ahead method. Suppose initially, a player is not in collision with any object. By taking commands from the user, we will need to move the player to a new position. So we save the player's old state, and move the player one frame ahead. Then we will generate collision .
time lag more than MAX_SIM_LAG(1) second will be detected by the environment simulator
the simulation is divided in to sub steps. int nStepCount = (int)ceil(dTimeDelta/MAX_SIM_STEP); double fSubStepDeltaTime = dTimeDelta; if(nStepCount<=1) nStepCount = 1; else fSubStepDeltaTime /= nStepCount; global biped simulation in multiple steps for (int i =0; i<nStepCount;i++) { CGlobals::GetPhysicsWorld()->StartPhysics(fSubStepDeltaTime); CGlobals::GetPhysicsWorld()->GetPhysicsResults(); Simulate(fSubStepDeltaTime); }
TODO: simulate other physical object here.
Implements ParaEngine::IEnvironmentSim.
|
virtual |
when this function is called, it ensures that the physics object around one or more points are properly loaded.
the scene must be loaded before calling this function
It increases the hit count of these physics objects by 1. The garbage collector in the physics world may use the hit count to move out unused static physics object from the physics scene (Novodex). This function might be called for the current player, each active mobile object in the scene and the camera eye position.
points | if not NULL, it will further check if it hits any of the sphere points. |
nPointCount | the number of points defined in points. |
breadth first transversing the scene(the root tile is ignored) pTile is now the root tile. object attached to it are never rendered directly
add other tiles
since 2009.8, all physics objects are attached to the leaf node, so we need to cull tile using a larger radius rather than the input fRadius.
rough culling algorithm using the quad tree terrain tiles test against a sphere round the eye
go down the quad tree terrain tile to render objects
even we know that the tile is empty, we still need to see if there is anything in the queueNode for rendering so when both queue are empty, we can exit the main rendering transversing loop
Implements ParaEngine::IEnvironmentSim.
|
inlinevirtual |
return the current type of simulator.
0 means standalone simulator, 1 means server, 2 means client.
Implements ParaEngine::IEnvironmentSim.
|
virtual |