00001 /* 00002 Bullet Continuous Collision Detection and Physics Library 00003 Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com 00004 00005 This software is provided 'as-is', without any express or implied warranty. 00006 In no event will the authors be held liable for any damages arising from the use of this software. 00007 Permission is granted to anyone to use this software for any purpose, 00008 including commercial applications, and to alter it and redistribute it freely, 00009 subject to the following restrictions: 00010 00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00013 3. This notice may not be removed or altered from any source distribution. 00014 */ 00015 00016 #include "SequentialThreadSupport.h" 00017 00018 00019 #include "SpuCollisionTaskProcess.h" 00020 #include "SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h" 00021 00022 SequentialThreadSupport::SequentialThreadSupport(SequentialThreadConstructionInfo& threadConstructionInfo) 00023 { 00024 startThreads(threadConstructionInfo); 00025 } 00026 00028 SequentialThreadSupport::~SequentialThreadSupport() 00029 { 00030 stopSPU(); 00031 } 00032 00033 #include <stdio.h> 00034 00036 void SequentialThreadSupport::sendRequest(uint32_t uiCommand, ppu_address_t uiArgument0, uint32_t taskId) 00037 { 00038 switch (uiCommand) 00039 { 00040 case CMD_GATHER_AND_PROCESS_PAIRLIST: 00041 { 00042 btSpuStatus& spuStatus = m_activeSpuStatus[0]; 00043 spuStatus.m_userPtr=(void*)uiArgument0; 00044 spuStatus.m_userThreadFunc(spuStatus.m_userPtr,spuStatus.m_lsMemory); 00045 } 00046 break; 00047 default: 00048 { 00050 btAssert(0 && "Not implemented"); 00051 } 00052 00053 }; 00054 00055 00056 } 00057 00059 void SequentialThreadSupport::waitForResponse(unsigned int *puiArgument0, unsigned int *puiArgument1) 00060 { 00061 btAssert(m_activeSpuStatus.size()); 00062 btSpuStatus& spuStatus = m_activeSpuStatus[0]; 00063 *puiArgument0 = spuStatus.m_taskId; 00064 *puiArgument1 = spuStatus.m_status; 00065 } 00066 00067 void SequentialThreadSupport::startThreads(SequentialThreadConstructionInfo& threadConstructionInfo) 00068 { 00069 m_activeSpuStatus.resize(1); 00070 printf("STS: Not starting any threads\n"); 00071 btSpuStatus& spuStatus = m_activeSpuStatus[0]; 00072 spuStatus.m_userPtr = 0; 00073 spuStatus.m_taskId = 0; 00074 spuStatus.m_commandId = 0; 00075 spuStatus.m_status = 0; 00076 spuStatus.m_lsMemory = threadConstructionInfo.m_lsMemoryFunc(); 00077 spuStatus.m_userThreadFunc = threadConstructionInfo.m_userThreadFunc; 00078 printf("STS: Created local store at %p for task %s\n", spuStatus.m_lsMemory, threadConstructionInfo.m_uniqueName); 00079 } 00080 00081 void SequentialThreadSupport::startSPU() 00082 { 00083 } 00084 00085 void SequentialThreadSupport::stopSPU() 00086 { 00087 m_activeSpuStatus.clear(); 00088 } 00089 00090 void SequentialThreadSupport::setNumTasks(int numTasks) 00091 { 00092 printf("SequentialThreadSupport::setNumTasks(%d) is not implemented and has no effect\n",numTasks); 00093 } 00094 00095 00096 00097 00098 class btDummyBarrier : public btBarrier 00099 { 00100 private: 00101 00102 public: 00103 btDummyBarrier() 00104 { 00105 } 00106 00107 virtual ~btDummyBarrier() 00108 { 00109 } 00110 00111 void sync() 00112 { 00113 } 00114 00115 virtual void setMaxCount(int n) {} 00116 virtual int getMaxCount() {return 1;} 00117 }; 00118 00119 class btDummyCriticalSection : public btCriticalSection 00120 { 00121 00122 public: 00123 btDummyCriticalSection() 00124 { 00125 } 00126 00127 virtual ~btDummyCriticalSection() 00128 { 00129 } 00130 00131 unsigned int getSharedParam(int i) 00132 { 00133 btAssert(i>=0&&i<31); 00134 return mCommonBuff[i+1]; 00135 } 00136 00137 void setSharedParam(int i,unsigned int p) 00138 { 00139 btAssert(i>=0&&i<31); 00140 mCommonBuff[i+1] = p; 00141 } 00142 00143 void lock() 00144 { 00145 mCommonBuff[0] = 1; 00146 } 00147 00148 void unlock() 00149 { 00150 mCommonBuff[0] = 0; 00151 } 00152 }; 00153 00154 00155 00156 00157 btBarrier* SequentialThreadSupport::createBarrier() 00158 { 00159 return new btDummyBarrier(); 00160 } 00161 00162 btCriticalSection* SequentialThreadSupport::createCriticalSection() 00163 { 00164 return new btDummyCriticalSection(); 00165 00166 } 00167 00168 void SequentialThreadSupport::deleteBarrier(btBarrier* barrier) 00169 { 00170 delete barrier; 00171 } 00172 00173 void SequentialThreadSupport::deleteCriticalSection(btCriticalSection* criticalSection) 00174 { 00175 delete criticalSection; 00176 } 00177 00178 00179 00180 00181