diff options
| author | sschirm <[email protected]> | 2016-12-23 14:20:36 +0100 |
|---|---|---|
| committer | sschirm <[email protected]> | 2016-12-23 14:56:17 +0100 |
| commit | ef6937e69e8ee3f409cf9d460d5ad300a65d5924 (patch) | |
| tree | 710426e8daa605551ce3f34b581897011101c30f /APEX_1.4/samples_v2/SampleBase | |
| parent | Initial commit: (diff) | |
| download | physx-3.4-ef6937e69e8ee3f409cf9d460d5ad300a65d5924.tar.xz physx-3.4-ef6937e69e8ee3f409cf9d460d5ad300a65d5924.zip | |
PhysX 3.4 / APEX 1.4 release candidate @21506124
Diffstat (limited to 'APEX_1.4/samples_v2/SampleBase')
| -rw-r--r-- | APEX_1.4/samples_v2/SampleBase/ApexController.cpp | 25 | ||||
| -rw-r--r-- | APEX_1.4/samples_v2/SampleBase/ApexController.h | 33 | ||||
| -rw-r--r-- | APEX_1.4/samples_v2/SampleBase/ApexRenderer.cpp | 12 | ||||
| -rw-r--r-- | APEX_1.4/samples_v2/SampleBase/CommonUIController.cpp | 35 | ||||
| -rw-r--r-- | APEX_1.4/samples_v2/SampleBase/CommonUIController.h | 8 |
5 files changed, 100 insertions, 13 deletions
diff --git a/APEX_1.4/samples_v2/SampleBase/ApexController.cpp b/APEX_1.4/samples_v2/SampleBase/ApexController.cpp index d8c7eb67..cf63f274 100644 --- a/APEX_1.4/samples_v2/SampleBase/ApexController.cpp +++ b/APEX_1.4/samples_v2/SampleBase/ApexController.cpp @@ -32,6 +32,9 @@ ApexController::ApexController(PxSimulationFilterShader filterShader, CFirstPers , mFilterShader(filterShader) , mLastSimulationTime(0) , mPaused(false) +, mUseFixedTimestep(true) +, mFixedTimestep(1.0/60.0) +, mTimeRemainder(0.0) { QueryPerformanceFrequency(&mPerformanceFreq); } @@ -271,8 +274,26 @@ void ApexController::Animate(double dt) if (mPaused) return; - // slower physics if fps is too low - dt = PxClamp(dt, 0.001, 0.33); + if (mFixedTimestep) + { + mTimeRemainder += dt; + if (mTimeRemainder <= 0.0) + { + return; + } + mTimeRemainder -= mFixedTimestep; + if (mTimeRemainder > 0.0) + { + // slower physics if fps is below 1/mFixedTimestep + mTimeRemainder = 0.0; + } + dt = mFixedTimestep; + } + else + { + // slower physics if fps is too low + dt = PxClamp(dt, 0.001, 0.33); + } LARGE_INTEGER time0; QueryPerformanceCounter(&time0); diff --git a/APEX_1.4/samples_v2/SampleBase/ApexController.h b/APEX_1.4/samples_v2/SampleBase/ApexController.h index 15ecaf64..653e47ee 100644 --- a/APEX_1.4/samples_v2/SampleBase/ApexController.h +++ b/APEX_1.4/samples_v2/SampleBase/ApexController.h @@ -126,7 +126,34 @@ class ApexController : public ISampleController mPaused = !mPaused; } - private: + void toggleFixedTimestep() + { + mUseFixedTimestep = !mUseFixedTimestep; + if (mUseFixedTimestep) + { + mTimeRemainder = 0.0; + } + } + + bool usingFixedTimestep() const + { + return mUseFixedTimestep; + } + + void setFixedTimestep(double fixedTimestep) + { + if (fixedTimestep > 0.0) + { + mFixedTimestep = fixedTimestep; + } + } + + double getFixedTimestep() + { + return mFixedTimestep; + } + +private: void initPhysX(); void releasePhysX(); @@ -187,6 +214,10 @@ class ApexController : public ISampleController LARGE_INTEGER mPerformanceFreq; bool mPaused; + + bool mUseFixedTimestep; + double mFixedTimestep; + double mTimeRemainder; }; #endif diff --git a/APEX_1.4/samples_v2/SampleBase/ApexRenderer.cpp b/APEX_1.4/samples_v2/SampleBase/ApexRenderer.cpp index 54328c65..62a23f54 100644 --- a/APEX_1.4/samples_v2/SampleBase/ApexRenderer.cpp +++ b/APEX_1.4/samples_v2/SampleBase/ApexRenderer.cpp @@ -253,16 +253,10 @@ void ApexRenderer::DeviceDestroyed() void ApexRenderer::onInitialize() { - std::stringstream ss; - ss << GetCommandLineA(); char buf[256]; - ss >> &buf[0]; - - PathRemoveFileSpecA(&buf[0]); - - ss.clear(); - ss << buf << "/../../samples_v2/"; - ss >> buf; + sprintf(buf, "%s", GetCommandLineA()); + PathRemoveFileSpecA(buf); + sprintf(buf + strlen(buf), "/../../samples_v2/"); mApex.getResourceCallback()->addSearchDir(&buf[1]); diff --git a/APEX_1.4/samples_v2/SampleBase/CommonUIController.cpp b/APEX_1.4/samples_v2/SampleBase/CommonUIController.cpp index 08be4392..f548d36b 100644 --- a/APEX_1.4/samples_v2/SampleBase/CommonUIController.cpp +++ b/APEX_1.4/samples_v2/SampleBase/CommonUIController.cpp @@ -45,6 +45,10 @@ HRESULT CommonUIController::DeviceCreated(ID3D11Device* pDevice) TwAddVarCB(mSettingsBar, "WireFrame", TW_TYPE_BOOLCPP, CommonUIController::setWireframeEnabled, CommonUIController::getWireframeEnabled, this, "group=Main key=o"); TwAddButton(mSettingsBar, "Reload Shaders", CommonUIController::onReloadShadersButton, this, "group=Main key=f5"); + TwAddVarCB(mSettingsBar, "Fixed Sim Frequency Enabled", TW_TYPE_BOOLCPP, CommonUIController::setFixedTimestepEnabled, + CommonUIController::getFixedTimestepEnabled, this, "group=Main key=t"); + TwAddVarCB(mSettingsBar, "Fixed Sim Frequency", TW_TYPE_UINT32, CommonUIController::setFixedSimFrequency, + CommonUIController::getFixedSimFrequency, this, "group=Main min=30 max=1000"); TwAddVarRW(mSettingsBar, "Ambient Color", TW_TYPE_COLOR3F, &(mApexRenderer->getAmbientColor()), "group='Scene'"); TwAddVarRW(mSettingsBar, "Point Light Color", TW_TYPE_COLOR3F, &(mApexRenderer->getPointLightColor()), "group='Scene'"); TwAddVarRW(mSettingsBar, "Point Light Pos", TW_TYPE_DIR3F, &(mApexRenderer->getPointLightPos()), "group='Scene'"); @@ -60,6 +64,7 @@ HRESULT CommonUIController::DeviceCreated(ID3D11Device* pDevice) addHintLine("Rotate camera - RMB"); addHintLine("Move camera - WASDQE(SHIFT)"); addHintLine("Play/Pause - P"); + addHintLine("Fixed/Variable sim freq - T"); addHintLine("Reload shaders - F5"); addHintLine("Wireframe - O"); @@ -205,6 +210,36 @@ void TW_CALL CommonUIController::getWireframeEnabled(void* value, void* clientDa } +void TW_CALL CommonUIController::setFixedTimestepEnabled(const void* value, void* clientData) +{ + CommonUIController* controller = static_cast<CommonUIController*>(clientData); + const bool enable = *static_cast<const bool*>(value); + if (controller->mApexController->usingFixedTimestep() != enable) + { + controller->mApexController->toggleFixedTimestep(); + } +} + +void TW_CALL CommonUIController::getFixedTimestepEnabled(void* value, void* clientData) +{ + CommonUIController* controller = static_cast<CommonUIController*>(clientData); + *static_cast<bool*>(value) = controller->mApexController->usingFixedTimestep(); +} + + +void TW_CALL CommonUIController::setFixedSimFrequency(const void* value, void* clientData) +{ + CommonUIController* controller = static_cast<CommonUIController*>(clientData); + controller->mApexController->setFixedTimestep(1.0 / *static_cast<const uint32_t*>(value)); +} + +void TW_CALL CommonUIController::getFixedSimFrequency(void* value, void* clientData) +{ + CommonUIController* controller = static_cast<CommonUIController*>(clientData); + *static_cast<uint32_t*>(value) = static_cast<uint32_t>(1.0 / controller->mApexController->getFixedTimestep() + 0.5); +} + + void TW_CALL CommonUIController::onReloadShadersButton(void* clientData) { CommonUIController* controller = static_cast<CommonUIController*>(clientData); diff --git a/APEX_1.4/samples_v2/SampleBase/CommonUIController.h b/APEX_1.4/samples_v2/SampleBase/CommonUIController.h index 9790957f..252395fd 100644 --- a/APEX_1.4/samples_v2/SampleBase/CommonUIController.h +++ b/APEX_1.4/samples_v2/SampleBase/CommonUIController.h @@ -51,7 +51,13 @@ class CommonUIController : public ISampleController static void TW_CALL onReloadShadersButton(void* clientData); - private: + static void TW_CALL setFixedTimestepEnabled(const void* value, void* clientData); + static void TW_CALL getFixedTimestepEnabled(void* value, void* clientData); + + static void TW_CALL setFixedSimFrequency(const void* value, void* clientData); + static void TW_CALL getFixedSimFrequency(void* value, void* clientData); + +private: void toggleCameraSpeed(bool overspeed); CFirstPersonCamera* mCamera; |