Add sleep to avoid 100% busy CPU loop in PhysicsServerExample
Added btClock::usleep Fix broken TinyRenderer example code.
This commit is contained in:
@@ -96,8 +96,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
if os.is("Windows") then
|
if os.is("Windows") then
|
||||||
default_python_include_dir = "C:/Python34/include"
|
default_python_include_dir = "C:\Python-3.5.2/include"
|
||||||
default_python_lib_dir = "C:/Python34/libs"
|
default_python_lib_dir = "C:/Python-3.5.2/libs"
|
||||||
end
|
end
|
||||||
|
|
||||||
newoption
|
newoption
|
||||||
@@ -164,7 +164,7 @@ end
|
|||||||
platforms {"x32"}
|
platforms {"x32"}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
platforms {"x64"}
|
platforms {"x32","x64"}
|
||||||
end
|
end
|
||||||
|
|
||||||
configuration {"x32"}
|
configuration {"x32"}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
rem premake4 --with-pe vs2010
|
rem premake4 --with-pe vs2010
|
||||||
rem premake4 --bullet2demos vs2010
|
rem premake4 --bullet2demos vs2010
|
||||||
cd build3
|
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 premake4 --targetdir="../server2bin" vs2010
|
||||||
rem cd vs2010
|
rem cd vs2010
|
||||||
rem rename 0_Bullet3Solution.sln 0_server.sln
|
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)
|
while (data->m_args.m_cs->getSharedParam(0)==eExampleBrowserIsUnInitialized)
|
||||||
{
|
{
|
||||||
|
b3Clock::usleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -366,6 +367,7 @@ void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data)
|
|||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
// printf("polling..");
|
// printf("polling..");
|
||||||
|
b3Clock::usleep(1000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ static CommonExampleInterface* sCurrentDemo = 0;
|
|||||||
static b3AlignedObjectArray<const char*> allNames;
|
static b3AlignedObjectArray<const char*> allNames;
|
||||||
static float gFixedTimeStep = 0;
|
static float gFixedTimeStep = 0;
|
||||||
bool gAllowRetina = true;
|
bool gAllowRetina = true;
|
||||||
|
bool gDisableDemoSelection = false;
|
||||||
static class ExampleEntries* gAllExamples=0;
|
static class ExampleEntries* gAllExamples=0;
|
||||||
bool sUseOpenGL2 = false;
|
bool sUseOpenGL2 = false;
|
||||||
bool drawGUI=true;
|
bool drawGUI=true;
|
||||||
@@ -556,9 +556,11 @@ struct MyMenuItemHander :public Gwen::Event::Handler
|
|||||||
Gwen::String laa = Gwen::Utility::UnicodeToString(la);
|
Gwen::String laa = Gwen::Utility::UnicodeToString(la);
|
||||||
//const char* ha = laa.c_str();
|
//const char* ha = laa.c_str();
|
||||||
|
|
||||||
|
if (!gDisableDemoSelection )
|
||||||
selectDemo(sCurrentHightlighted);
|
{
|
||||||
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
selectDemo(sCurrentHightlighted);
|
||||||
|
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void onButtonC(Gwen::Controls::Base* pControl)
|
void onButtonC(Gwen::Controls::Base* pControl)
|
||||||
{
|
{
|
||||||
@@ -580,8 +582,11 @@ struct MyMenuItemHander :public Gwen::Event::Handler
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// printf("onKeyReturn ! \n");
|
// printf("onKeyReturn ! \n");
|
||||||
selectDemo(sCurrentHightlighted);
|
if (!gDisableDemoSelection )
|
||||||
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
{
|
||||||
|
selectDemo(sCurrentHightlighted);
|
||||||
|
saveCurrentSettings(sCurrentDemoIndex, startFileName);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1228,5 +1233,6 @@ void OpenGLExampleBrowser::update(float deltaTime)
|
|||||||
|
|
||||||
void OpenGLExampleBrowser::setSharedMemoryInterface(class SharedMemoryInterface* sharedMem)
|
void OpenGLExampleBrowser::setSharedMemoryInterface(class SharedMemoryInterface* sharedMem)
|
||||||
{
|
{
|
||||||
|
gDisableDemoSelection = true;
|
||||||
sSharedMem = sharedMem;
|
sSharedMem = sharedMem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ struct MotionThreadLocalStorage
|
|||||||
};
|
};
|
||||||
|
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
|
int skip1 = 0;
|
||||||
|
|
||||||
void MotionThreadFunc(void* userPtr,void* lsMemory)
|
void MotionThreadFunc(void* userPtr,void* lsMemory)
|
||||||
{
|
{
|
||||||
@@ -134,8 +135,15 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
|
|||||||
if (deltaTimeInSeconds<(1./5000.))
|
if (deltaTimeInSeconds<(1./5000.))
|
||||||
{
|
{
|
||||||
skip++;
|
skip++;
|
||||||
|
skip1++;
|
||||||
|
if (0==(skip1&0x3))
|
||||||
|
{
|
||||||
|
b3Clock::usleep(250);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
skip1=0;
|
||||||
|
|
||||||
//process special controller commands, such as
|
//process special controller commands, such as
|
||||||
//VR controller button press/release and controller motion
|
//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;
|
skip=0;
|
||||||
|
skip1=0;
|
||||||
//do nothing
|
//do nothing
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -638,8 +647,10 @@ void PhysicsServerExample::initPhysics()
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
m_threadSupport->runTask(B3_THREAD_SCHEDULE_TASK, (void*) &this->m_args[w], w);
|
m_threadSupport->runTask(B3_THREAD_SCHEDULE_TASK, (void*) &this->m_args[w], w);
|
||||||
|
|
||||||
while (m_args[w].m_cs->getSharedParam(0)==eMotionIsUnInitialized)
|
while (m_args[w].m_cs->getSharedParam(0)==eMotionIsUnInitialized)
|
||||||
{
|
{
|
||||||
|
b3Clock::usleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,6 +680,7 @@ void PhysicsServerExample::exitPhysics()
|
|||||||
|
|
||||||
} else
|
} 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)
|
if (numPixelsCopied)
|
||||||
*numPixelsCopied = 0;
|
*numPixelsCopied = 0;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ const T& b3ClockMin(const T& a, const T& b)
|
|||||||
|
|
||||||
#else //_WIN32
|
#else //_WIN32
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif //_WIN32
|
#endif //_WIN32
|
||||||
|
|
||||||
|
|
||||||
@@ -227,3 +228,21 @@ double b3Clock::getTimeInSeconds()
|
|||||||
return double(getTimeMicroseconds()/1.e6);
|
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.
|
/// the Clock was created.
|
||||||
double getTimeInSeconds();
|
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:
|
private:
|
||||||
struct b3ClockData* m_data;
|
struct b3ClockData* m_data;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ project ("pybullet")
|
|||||||
kind "SharedLib"
|
kind "SharedLib"
|
||||||
targetsuffix ("")
|
targetsuffix ("")
|
||||||
targetprefix ("")
|
targetprefix ("")
|
||||||
targetextension (".so")
|
|
||||||
includedirs {"../../src", "../../examples",
|
includedirs {"../../src", "../../examples",
|
||||||
"../../examples/ThirdPartyLibs"}
|
"../../examples/ThirdPartyLibs"}
|
||||||
defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER"}
|
defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER"}
|
||||||
|
|||||||
Reference in New Issue
Block a user