diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-12-03 01:25:47 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-12-03 01:25:47 +0300 |
commit | 438d114f1ac3c8eaa4c1d9d8ffa31271a51c85e6 (patch) | |
tree | 030c8c62a46ed0b3a527eb7cc25e277e303c59f5 /source/gameengine | |
parent | 08ef0d346653bbe746231fdd3c94b5b3313a84a5 (diff) |
- 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
Diffstat (limited to 'source/gameengine')
7 files changed, 84 insertions, 47 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index b886e4ff54a..f37928fe2d5 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -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()) diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 2432462fecc..03af40ce2c9 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -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) - { - kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]); - } else + int dof; + int dofbit=1; + for (dof=0;dof<6;dof++) { - //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; } } - } } } diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 145b4eb4750..85075d6364c 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -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); /* diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 6a54c613cc0..dcb8e082065 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -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; } diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index ae33e8da998..16b53b6b688 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -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); diff --git a/source/gameengine/Ketsji/KX_MotionState.cpp b/source/gameengine/Ketsji/KX_MotionState.cpp index 6de9cf3b36e..cd01c0466cd 100644 --- a/source/gameengine/Ketsji/KX_MotionState.cpp +++ b/source/gameengine/Ketsji/KX_MotionState.cpp @@ -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() diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index db5de7c7d43..a4fdffd0b58 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -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++) |