- GEadded VSYNC for Mac OS X swapbuffers (can be easily undone by commenting out the #define WAIT_FOR_VSYNC 1
- GEdon't crash when attempting to add constraint on game objects without physics controller - GEimproved some physics -> graphics synchronization issues - small experiment with game engine timing to smooth framerate/reduce tearing
This commit is contained in:
@@ -403,9 +403,19 @@ GHOST_TSuccess GHOST_WindowCarbon::setOrder(GHOST_TWindowOrder order)
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
#define WAIT_FOR_VSYNC 1
|
||||
#ifdef WAIT_FOR_VSYNC
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#endif
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCarbon::swapBuffers()
|
||||
{
|
||||
#ifdef WAIT_FOR_VSYNC
|
||||
/* wait for vsync, to avoid tearing artifacts */
|
||||
long VBL = 1;
|
||||
CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
|
||||
#endif
|
||||
|
||||
GHOST_TSuccess succeeded = GHOST_kSuccess;
|
||||
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
|
||||
if (m_aglCtx) {
|
||||
|
||||
@@ -357,10 +357,13 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
|
||||
exitrequested = ketsjiengine->GetExitCode();
|
||||
|
||||
// kick the engine
|
||||
ketsjiengine->NextFrame();
|
||||
bool render = ketsjiengine->NextFrame();
|
||||
|
||||
// render the frame
|
||||
ketsjiengine->Render();
|
||||
if (render)
|
||||
{
|
||||
// render the frame
|
||||
ketsjiengine->Render();
|
||||
}
|
||||
|
||||
// test for the ESC key
|
||||
while (qtest())
|
||||
|
||||
@@ -1947,29 +1947,31 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
|
||||
KX_GameObject *gotar=getGameOb(dat->tar->id.name,sumolist);
|
||||
physctr2 = (PHY_IPhysicsController*) gotar->GetPhysicsController()->GetUserData();
|
||||
}
|
||||
|
||||
PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) gameobj->GetPhysicsController()->GetUserData();
|
||||
|
||||
int constraintId = kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ);
|
||||
//if it is a generic 6DOF constraint, set all the limits accordingly
|
||||
if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT)
|
||||
|
||||
if (gameobj->GetPhysicsController())
|
||||
{
|
||||
int dof;
|
||||
int dofbit=1;
|
||||
for (dof=0;dof<6;dof++)
|
||||
PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) gameobj->GetPhysicsController()->GetUserData();
|
||||
|
||||
int constraintId = kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ);
|
||||
//if it is a generic 6DOF constraint, set all the limits accordingly
|
||||
if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT)
|
||||
{
|
||||
if (dat->flag & dofbit)
|
||||
int dof;
|
||||
int dofbit=1;
|
||||
for (dof=0;dof<6;dof++)
|
||||
{
|
||||
kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]);
|
||||
} else
|
||||
{
|
||||
//minLimit > maxLimit means free(disabled limit) for this degree of freedom
|
||||
kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,1,-1);
|
||||
if (dat->flag & dofbit)
|
||||
{
|
||||
kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]);
|
||||
} else
|
||||
{
|
||||
//minLimit > maxLimit means free(disabled limit) for this degree of freedom
|
||||
kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,1,-1);
|
||||
}
|
||||
dofbit<<=1;
|
||||
}
|
||||
dofbit<<=1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -999,6 +999,9 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
|
||||
{
|
||||
if (meshobj)
|
||||
{
|
||||
bm = CreateBulletShapeFromMesh(meshobj,false);
|
||||
ci.m_localInertiaTensor.setValue(0.f,0.f,0.f);
|
||||
|
||||
// assert(0);
|
||||
|
||||
/*
|
||||
|
||||
@@ -256,9 +256,9 @@ void KX_KetsjiEngine::SetSceneConverter(KX_ISceneConverter* sceneconverter)
|
||||
*/
|
||||
void KX_KetsjiEngine::StartEngine(bool clearIpo)
|
||||
{
|
||||
m_clockTime = m_kxsystem->GetTimeInSeconds();
|
||||
m_frameTime = m_kxsystem->GetTimeInSeconds();
|
||||
m_previousClockTime = m_kxsystem->GetTimeInSeconds();
|
||||
m_clockTime = 0.f;// m_kxsystem->GetTimeInSeconds();
|
||||
m_frameTime = 0.f;//m_kxsystem->GetTimeInSeconds();
|
||||
m_previousClockTime = 0.f;//m_kxsystem->GetTimeInSeconds();
|
||||
|
||||
m_firstframe = true;
|
||||
m_bInitialized = true;
|
||||
@@ -315,22 +315,35 @@ void KX_KetsjiEngine::EndFrame()
|
||||
// swap backbuffer (drawing into this buffer) <-> front/visible buffer
|
||||
m_rasterizer->SwapBuffers();
|
||||
m_rendertools->EndFrame(m_rasterizer);
|
||||
|
||||
|
||||
m_canvas->EndDraw();
|
||||
|
||||
|
||||
}
|
||||
|
||||
// #include "PIL_time.h"
|
||||
//#include "PIL_time.h"
|
||||
//#include "LinearMath/btQuickprof.h"
|
||||
|
||||
void KX_KetsjiEngine::NextFrame()
|
||||
|
||||
bool KX_KetsjiEngine::NextFrame()
|
||||
{
|
||||
m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true);
|
||||
|
||||
if (m_bFixedTime)
|
||||
m_clockTime += 1.0/m_ticrate;
|
||||
else
|
||||
m_clockTime = m_kxsystem->GetTimeInSeconds();
|
||||
|
||||
// static hidden::Clock sClock;
|
||||
|
||||
m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(),true);
|
||||
|
||||
//float dt = sClock.getTimeMicroseconds() * 0.000001f;
|
||||
//sClock.reset();
|
||||
|
||||
if (m_bFixedTime)
|
||||
m_clockTime += 1./m_ticrate;
|
||||
else
|
||||
{
|
||||
|
||||
// m_clockTime += dt;
|
||||
m_clockTime = m_kxsystem->GetTimeInSeconds();
|
||||
}
|
||||
|
||||
double deltatime = m_clockTime - m_frameTime;
|
||||
if (deltatime<0.f)
|
||||
@@ -341,30 +354,41 @@ void KX_KetsjiEngine::NextFrame()
|
||||
m_frameTime = 0.f;
|
||||
}
|
||||
|
||||
|
||||
// Compute the number of logic frames to do each update (fixed tic bricks)
|
||||
int frames =int(deltatime*m_ticrate);
|
||||
// if (frames>1)
|
||||
// printf("****************************************");
|
||||
// printf("dt = %f, deltatime = %f, frames = %d\n",dt, deltatime,frames);
|
||||
|
||||
// if (!frames)
|
||||
// PIL_sleep_ms(4);
|
||||
// PIL_sleep_ms(1);
|
||||
|
||||
KX_SceneList::iterator sceneit;
|
||||
int frameOut = 5;
|
||||
|
||||
if (frames>frameOut)
|
||||
{
|
||||
printf("framedOut: %d\n",frames);
|
||||
|
||||
// printf("framedOut: %d\n",frames);
|
||||
m_frameTime+=(frames-frameOut)*(1.0/m_ticrate);
|
||||
frames = frameOut;
|
||||
}
|
||||
|
||||
|
||||
bool doRender = frames>0;
|
||||
|
||||
float remainingTimeFraction = 0.f;
|
||||
|
||||
if (frames>0)
|
||||
{
|
||||
remainingTimeFraction = (m_clockTime - m_frameTime - frames*(1.0/m_ticrate)) / frames;
|
||||
}
|
||||
while (frames)
|
||||
{
|
||||
if (frames > frameOut)
|
||||
{
|
||||
printf ("what happened\n");
|
||||
}
|
||||
|
||||
|
||||
m_frameTime += 1.0/m_ticrate;
|
||||
m_frameTime += 1.0/m_ticrate + remainingTimeFraction;
|
||||
|
||||
for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
|
||||
// for each scene, call the proceed functions
|
||||
@@ -419,6 +443,7 @@ void KX_KetsjiEngine::NextFrame()
|
||||
// Do some cleanup work for this logic frame
|
||||
m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
|
||||
scene->LogicUpdateFrame(m_frameTime, true);
|
||||
|
||||
scene->LogicEndFrame();
|
||||
|
||||
// Actuators can affect the scenegraph
|
||||
@@ -448,7 +473,7 @@ void KX_KetsjiEngine::NextFrame()
|
||||
scene->setSuspendedTime(m_clockTime);
|
||||
|
||||
DoSound(scene);
|
||||
|
||||
|
||||
m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true);
|
||||
}
|
||||
|
||||
@@ -472,7 +497,7 @@ void KX_KetsjiEngine::NextFrame()
|
||||
frames--;
|
||||
}
|
||||
|
||||
bool bUseAsyncLogicBricks= false;
|
||||
bool bUseAsyncLogicBricks= false;//true;
|
||||
|
||||
if (bUseAsyncLogicBricks)
|
||||
{
|
||||
@@ -532,6 +557,8 @@ void KX_KetsjiEngine::NextFrame()
|
||||
|
||||
// Start logging time spend outside main loop
|
||||
m_logger->StartLog(tc_outside, m_kxsystem->GetTimeInSeconds(), true);
|
||||
|
||||
return doRender;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -201,8 +201,8 @@ public:
|
||||
void SetSceneConverter(KX_ISceneConverter* sceneconverter);
|
||||
void SetGame2IpoMode(bool game2ipo,int startFrame);
|
||||
|
||||
|
||||
void NextFrame();
|
||||
///returns true if an update happened to indicate -> Render
|
||||
bool NextFrame();
|
||||
void Render();
|
||||
|
||||
void StartEngine(bool clearIpo);
|
||||
|
||||
@@ -73,7 +73,7 @@ void KX_MotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float&
|
||||
void KX_MotionState::setWorldPosition(float posX,float posY,float posZ)
|
||||
{
|
||||
m_node->SetLocalPosition(MT_Point3(posX,posY,posZ));
|
||||
|
||||
m_node->SetWorldPosition(MT_Point3(posX,posY,posZ));
|
||||
}
|
||||
|
||||
void KX_MotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
|
||||
@@ -85,6 +85,8 @@ void KX_MotionState::setWorldOrientation(float quatIma0,float quatIma1,float qua
|
||||
orn[3] = quatReal;
|
||||
|
||||
m_node->SetLocalOrientation(orn);
|
||||
m_node->SetWorldOrientation(orn);
|
||||
|
||||
}
|
||||
|
||||
void KX_MotionState::calculateWorldTransformations()
|
||||
|
||||
@@ -108,8 +108,8 @@ public:
|
||||
{
|
||||
btWheelInfo& info = m_vehicle->getWheelInfo(i);
|
||||
PHY_IMotionState* motionState = (PHY_IMotionState*)info.m_clientInfo ;
|
||||
m_vehicle->updateWheelTransform(i);
|
||||
btTransform trans = m_vehicle->getWheelTransformWS(i);
|
||||
m_vehicle->updateWheelTransform(i,true);
|
||||
btTransform trans = m_vehicle->getWheelInfo(i).m_worldTransform;
|
||||
btQuaternion orn = trans.getRotation();
|
||||
const btVector3& pos = trans.getOrigin();
|
||||
motionState->setWorldOrientation(orn.x(),orn.y(),orn.z(),orn[3]);
|
||||
@@ -457,13 +457,13 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
|
||||
ctrl->SynchronizeMotionStates(timeStep);
|
||||
}
|
||||
|
||||
m_dynamicsWorld->stepSimulation(timeStep,5);//5);
|
||||
m_dynamicsWorld->stepSimulation(timeStep,2);
|
||||
|
||||
numCtrl = GetNumControllers();
|
||||
for (i=0;i<numCtrl;i++)
|
||||
{
|
||||
CcdPhysicsController* ctrl = GetPhysicsController(i);
|
||||
ctrl->SynchronizeMotionStates(timeStep);
|
||||
//ctrl->SynchronizeMotionStates(timeStep);
|
||||
}
|
||||
|
||||
for (i=0;i<m_wrapperVehicles.size();i++)
|
||||
|
||||
Reference in New Issue
Block a user