Exemplo n.º 1
0
void	PhysicsServerExample::initPhysics()
{
	///for this testing we use Z-axis up
	int upAxis = 2;
	m_guiHelper->setUpAxis(upAxis);


	


	m_threadSupport = createMotionThreadSupport(MAX_MOTION_NUM_THREADS);
		
		

		for (int i=0;i<m_threadSupport->getNumTasks();i++)
		{
			MotionThreadLocalStorage* storage = (MotionThreadLocalStorage*) m_threadSupport->getThreadLocalMemory(i);
			b3Assert(storage);
			storage->threadId = i;
			//storage->m_sharedMem = data->m_sharedMem;
		}


		

		for (int w=0;w<MAX_MOTION_NUM_THREADS;w++)
		{
			m_args[w].m_cs = m_threadSupport->createCriticalSection();
			m_args[w].m_cs->setSharedParam(0,eMotionIsUnInitialized);
			int numMoving = 0;
 			m_args[w].m_positions.resize(numMoving);
			m_args[w].m_physicsServerPtr = &m_physicsServer;
			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);
			}
		}

		m_args[0].m_cs->setSharedParam(1,eGUIHelperIdle);
		m_multiThreadedHelper->setCriticalSection(m_args[0].m_cs);
		m_isConnected = m_physicsServer.connectSharedMemory( m_guiHelper);
}
Exemplo n.º 2
0
    virtual void    initPhysics()
    {
        b3Printf("initPhysics");
        
        

        m_threadSupport = createThreadSupport(m_numThreads);



        for (int i=0;i<m_threadSupport->getNumTasks();i++)
        {
            SampleThreadLocalStorage* storage = (SampleThreadLocalStorage*)m_threadSupport->getThreadLocalMemory(i);
            b3Assert(storage);
            storage->threadId = i;
        }


        
        args.m_cs = m_threadSupport->createCriticalSection();
        args.m_cs->setSharedParam(0,100);
        
        for (int i=0;i<100;i++)
        {
            SampleJob1* job = new SampleJob1(i);
            args.submitJob(job);
        }

       
        int i;
        for (i=0;i<m_numThreads;i++)
        {
            m_threadSupport->runTask(B3_THREAD_SCHEDULE_TASK, (void*) &args, i);
        }
         b3Printf("Threads started");

    }