My Project
Public Member Functions | List of all members
ParaEngine::CEnvironmentSim Class Reference

Animate the entire scene for a fixed time interval advance. More...

#include <EnvironmentSim.h>

Inheritance diagram for ParaEngine::CEnvironmentSim:
ParaEngine::IEnvironmentSim

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...
 
- Public Member Functions inherited from ParaEngine::IEnvironmentSim
void CheckLoadPhysics (const Vector3 &vCenter, float fRadius)
 
virtual CNetTimeGetNetTime ()
 get the net time object More...
 

Additional Inherited Members

- Public Types inherited from ParaEngine::IEnvironmentSim
enum  SIMULATOR_TYPE { SIM_TYPE_STANDALONE = 0, SIM_TYPE_SERVER = 1, SIM_TYPE_CLIENT = 2 }
 
- Static Public Member Functions inherited from ParaEngine::IEnvironmentSim
static void EnableLog (bool bWriteLog)
 
static bool IsLogEnabled ()
 

Detailed Description

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.

See also
m_dwGroup if this is 0x0000, it will detect no objects. If this is 0xffff, it will detects all objects in any of the 32 groups. if this is 0x0001, it will only detect group 0. m_fPeceptiveRadius:the radius within which this biped could see or perceive other bipeds.

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.

Member Function Documentation

§ Animate()

void CEnvironmentSim::Animate ( double  dTimeDelta)
virtual

called each frame to simulate the game world.

desc: Environment collision detection and response call this function at every frame move.

Parameters
dTimeDeltain 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.

§ CheckLoadPhysics()

void CEnvironmentSim::CheckLoadPhysics ( CShapeSphere points,
int  nPointCount = 1 
)
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.

Parameters
pointsif not NULL, it will further check if it hits any of the sphere points.
nPointCountthe 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.

§ GetSimulatorType()

virtual SIMULATOR_TYPE ParaEngine::CEnvironmentSim::GetSimulatorType ( )
inlinevirtual

return the current type of simulator.

0 means standalone simulator, 1 means server, 2 means client.

Implements ParaEngine::IEnvironmentSim.

§ Release()

void CEnvironmentSim::Release ( )
virtual

delete this object.

Such as Delete this;

Implements ParaEngine::IEnvironmentSim.


The documentation for this class was generated from the following files: