mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-12 12:50:08 +00:00
Add sleep to avoid 100% busy CPU loop in PhysicsServerExample
Added btClock::usleep Fix broken TinyRenderer example code.
This commit is contained in:
parent
238ba8c642
commit
3bdcf23a05
@ -96,8 +96,8 @@ end
|
||||
|
||||
|
||||
if os.is("Windows") then
|
||||
default_python_include_dir = "C:/Python34/include"
|
||||
default_python_lib_dir = "C:/Python34/libs"
|
||||
default_python_include_dir = "C:\Python-3.5.2/include"
|
||||
default_python_lib_dir = "C:/Python-3.5.2/libs"
|
||||
end
|
||||
|
||||
newoption
|
||||
@ -164,7 +164,7 @@ end
|
||||
platforms {"x32"}
|
||||
end
|
||||
else
|
||||
platforms {"x64"}
|
||||
platforms {"x32","x64"}
|
||||
end
|
||||
|
||||
configuration {"x32"}
|
||||
|
@ -2,7 +2,8 @@
|
||||
rem premake4 --with-pe vs2010
|
||||
rem premake4 --bullet2demos vs2010
|
||||
cd build3
|
||||
premake4 --enable_openvr --targetdir="../bin" vs2010
|
||||
premake4 --enable_openvr --targetdir="../bin" vs2010
|
||||
rem premake4 --enable_openvr --enable_pybullet --targetdir="../bin" vs2010
|
||||
rem premake4 --targetdir="../server2bin" vs2010
|
||||
rem cd vs2010
|
||||
rem rename 0_Bullet3Solution.sln 0_server.sln
|
||||
|
@ -332,6 +332,7 @@ btInProcessExampleBrowserInternalData* btCreateInProcessExampleBrowser(int argc,
|
||||
|
||||
while (data->m_args.m_cs->getSharedParam(0)==eExampleBrowserIsUnInitialized)
|
||||
{
|
||||
b3Clock::usleep(1000);
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -366,6 +367,7 @@ void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data)
|
||||
} else
|
||||
{
|
||||
// printf("polling..");
|
||||
b3Clock::usleep(1000);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -107,7 +107,7 @@ static CommonExampleInterface* sCurrentDemo = 0;
|
||||
static b3AlignedObjectArray<const char*> allNames;
|
||||
static float gFixedTimeStep = 0;
|
||||
bool gAllowRetina = true;
|
||||
|
||||
bool gDisableDemoSelection = false;
|
||||
static class ExampleEntries* gAllExamples=0;
|
||||
bool sUseOpenGL2 = false;
|
||||
bool drawGUI=true;
|
||||
@ -556,9 +556,11 @@ struct MyMenuItemHander :public Gwen::Event::Handler
|
||||
Gwen::String laa = Gwen::Utility::UnicodeToString(la);
|
||||
//const char* ha = laa.c_str();
|
||||
|
||||
|
||||
selectDemo(sCurrentHightlighted);
|
||||
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
||||
if (!gDisableDemoSelection )
|
||||
{
|
||||
selectDemo(sCurrentHightlighted);
|
||||
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
||||
}
|
||||
}
|
||||
void onButtonC(Gwen::Controls::Base* pControl)
|
||||
{
|
||||
@ -580,8 +582,11 @@ struct MyMenuItemHander :public Gwen::Event::Handler
|
||||
*/
|
||||
|
||||
// printf("onKeyReturn ! \n");
|
||||
selectDemo(sCurrentHightlighted);
|
||||
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
||||
if (!gDisableDemoSelection )
|
||||
{
|
||||
selectDemo(sCurrentHightlighted);
|
||||
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1228,5 +1233,6 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
||||
|
||||
void OpenGLExampleBrowser::setSharedMemoryInterface(class SharedMemoryInterface* sharedMem)
|
||||
{
|
||||
gDisableDemoSelection = true;
|
||||
sSharedMem = sharedMem;
|
||||
}
|
||||
|
@ -107,6 +107,7 @@ struct MotionThreadLocalStorage
|
||||
};
|
||||
|
||||
int skip = 0;
|
||||
int skip1 = 0;
|
||||
|
||||
void MotionThreadFunc(void* userPtr,void* lsMemory)
|
||||
{
|
||||
@ -134,8 +135,15 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
|
||||
if (deltaTimeInSeconds<(1./5000.))
|
||||
{
|
||||
skip++;
|
||||
skip1++;
|
||||
if (0==(skip1&0x3))
|
||||
{
|
||||
b3Clock::usleep(250);
|
||||
}
|
||||
} else
|
||||
{
|
||||
skip1=0;
|
||||
|
||||
//process special controller commands, such as
|
||||
//VR controller button press/release and controller motion
|
||||
|
||||
@ -186,8 +194,9 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
|
||||
}
|
||||
|
||||
|
||||
printf("finished, #skip = %d\n",skip);
|
||||
printf("finished, #skip = %d, skip1 = %d\n",skip,skip1);
|
||||
skip=0;
|
||||
skip1=0;
|
||||
//do nothing
|
||||
|
||||
}
|
||||
@ -638,8 +647,10 @@ void PhysicsServerExample::initPhysics()
|
||||
int index = 0;
|
||||
|
||||
m_threadSupport->runTask(B3_THREAD_SCHEDULE_TASK, (void*) &this->m_args[w], w);
|
||||
|
||||
while (m_args[w].m_cs->getSharedParam(0)==eMotionIsUnInitialized)
|
||||
{
|
||||
b3Clock::usleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -669,6 +680,7 @@ void PhysicsServerExample::exitPhysics()
|
||||
|
||||
} else
|
||||
{
|
||||
b3Clock::usleep(1000);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -348,7 +348,12 @@ struct TinyRendererGUIHelper : public GUIHelperInterface
|
||||
|
||||
}
|
||||
|
||||
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int width, int height, int* numPixelsCopied)
|
||||
|
||||
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
|
||||
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
|
||||
float* depthBuffer, int depthBufferSizeInPixels,
|
||||
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
|
||||
int startPixelIndex, int destinationWidth, int destinationHeight, int* numPixelsCopied)
|
||||
{
|
||||
if (numPixelsCopied)
|
||||
*numPixelsCopied = 0;
|
||||
|
@ -36,6 +36,7 @@ const T& b3ClockMin(const T& a, const T& b)
|
||||
|
||||
#else //_WIN32
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#endif //_WIN32
|
||||
|
||||
|
||||
@ -227,3 +228,21 @@ double b3Clock::getTimeInSeconds()
|
||||
return double(getTimeMicroseconds()/1.e6);
|
||||
}
|
||||
|
||||
void b3Clock::usleep(int microSeconds)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int millis = microSeconds/1000;
|
||||
if (millis < 1)
|
||||
{
|
||||
millis = 1;
|
||||
}
|
||||
Sleep(millis);
|
||||
#else
|
||||
|
||||
usleep(microSeconds); /
|
||||
//struct timeval tv;
|
||||
//tv.tv_sec = microSeconds/1000000L;
|
||||
//tv.tv_usec = microSeconds%1000000L;
|
||||
//return select(0, 0, 0, 0, &tv);
|
||||
#endif
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ public:
|
||||
/// the Clock was created.
|
||||
double getTimeInSeconds();
|
||||
|
||||
///Sleep for 'microSeconds', to yield to other threads and not waste 100% CPU cycles.
|
||||
///Note that some operating systems may sleep a longer time.
|
||||
static void usleep(int microSeconds);
|
||||
|
||||
private:
|
||||
struct b3ClockData* m_data;
|
||||
};
|
||||
|
@ -5,7 +5,6 @@ project ("pybullet")
|
||||
kind "SharedLib"
|
||||
targetsuffix ("")
|
||||
targetprefix ("")
|
||||
targetextension (".so")
|
||||
includedirs {"../../src", "../../examples",
|
||||
"../../examples/ThirdPartyLibs"}
|
||||
defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER"}
|
||||
|
Loading…
Reference in New Issue
Block a user