Skip to content

Instantly share code, notes, and snippets.

View mmmovania's full-sized avatar

Muhammad Mobeen Movania mmmovania

  • Habib University
  • Karachi, PAKISTAN
  • 00:30 - 5h ahead
View GitHub Profile
void InitializeHavok() {
InitMemory();
InitPhysicalWorld();
if (g_bVdbEnabled)
InitVDB();
}
void InitMemory() {
#if defined(HK_COMPILER_HAS_INTRINSICS_IA32) &&
HK_CONFIG_SIMD == HK_CONFIG_SIMD_ENABLED
// Flush all denormal/subnormal numbers to zero.
// Operations on denormals are very slow,
// up to 100 times slower than normal numbers.
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
void OnError(const char* msg, void* userArgGivenToInit) {
std::cerr < < "Report: " < < msg < < std::endl;
}
int totalNumThreadsUsed;
// Get the number of physical threads available on the system
hkHardwareInfo hwInfo;
hkGetHardwareInfo(hwInfo);
totalNumThreadsUsed = hwInfo.m_numThreads;
// We use one less than this for our thread pool, because we must also use this thread for our simulation
hkCpuJobThreadPoolCinfo threadPoolCinfo;
threadPoolCinfo.m_numThreads = totalNumThreadsUsed - 1;
hkJobQueueCinfo info;
info.m_jobQueueHwSetup.m_numCpuThreads = totalNumThreadsUsed;
g_pJobQueue = new hkJobQueue(info);
hkMonitorStream::getInstance().resize(200000);
void InitPhysicalWorld() {
g_pWorldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;
g_pWorldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_REMOVE_ENTITY;
g_pWorld = new hkpWorld(g_pWorldInfo);
g_pWorld->m_wantDeactivation = false;
g_pWorld->markForWrite();
hkpAgentRegisterUtil::registerAllAgents( g_pWorld->getCollisionDispatcher() );
g_pWorld->registerWithJobQueue( g_pJobQueue );
}
void InitVDB() {
hkArray contexts;
{
g_pContext = new hkpPhysicsContext();
hkpPhysicsContext::registerAllPhysicsProcesses();
g_pContext->addWorld(g_pWorld);
contexts.pushBack(g_pContext);
g_pWorld->unmarkForWrite();
}
void StepHavok() {
g_pWorld->stepMultithreaded( g_pJobQueue, g_pThreadPool, timeStep);
if(g_bVdbEnabled)
StepVDB();
hkMonitorStream::getInstance().reset();
g_pThreadPool->clearTimerData();
}
void StepVDB() {
g_pContext->syncTimers(g_pThreadPool);
g_pVdb->step(timeStep);
}
void ShutdownHavok() {
g_pWorld->markForWrite();
g_pWorld->removeReference();
delete g_pJobQueue;
// Clean up the thread pool
g_pThreadPool->removeReference();
if (g_bVdbEnabled)