mirror of https://github.com/axmolengine/axmol.git
fixed #702 tests crashs at the start on wophone device
This commit is contained in:
parent
ab470ad76d
commit
ab2a6cb2bb
|
@ -67,12 +67,15 @@ namespace cocos2d
|
|||
|
||||
void CCAccelerometer::update(float x, float y, float z, long sensorTimeStamp)
|
||||
{
|
||||
m_obAccelerationValue.x = -((double)x / TG3_GRAVITY_EARTH);
|
||||
m_obAccelerationValue.y = -((double)y / TG3_GRAVITY_EARTH);
|
||||
m_obAccelerationValue.z = -((double)z / TG3_GRAVITY_EARTH);
|
||||
m_obAccelerationValue.timestamp = (double)sensorTimeStamp;
|
||||
if (m_pAccelDelegate)
|
||||
{
|
||||
m_obAccelerationValue.x = -((double)x / TG3_GRAVITY_EARTH);
|
||||
m_obAccelerationValue.y = -((double)y / TG3_GRAVITY_EARTH);
|
||||
m_obAccelerationValue.z = -((double)z / TG3_GRAVITY_EARTH);
|
||||
m_obAccelerationValue.timestamp = (double)sensorTimeStamp;
|
||||
|
||||
m_pAccelDelegate->didAccelerate(&m_obAccelerationValue);
|
||||
m_pAccelDelegate->didAccelerate(&m_obAccelerationValue);
|
||||
}
|
||||
}
|
||||
} // end of namespace cococs2d
|
||||
|
||||
|
|
|
@ -68,6 +68,11 @@ static AccelerometerDispatcher* s_pAccelerometerDispatcher;
|
|||
|
||||
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
|
||||
{
|
||||
if (! delegate_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
acceleration_->x = acceleration.x;
|
||||
acceleration_->y = acceleration.y;
|
||||
acceleration_->z = acceleration.z;
|
||||
|
|
|
@ -64,7 +64,6 @@ CCAccelerometer* CCAccelerometer::sharedAccelerometer()
|
|||
void CCAccelerometer::removeDelegate(CCAccelerometerDelegate* pDelegate)
|
||||
{
|
||||
m_pDelegate = NULL;
|
||||
|
||||
m_pSensor->Release();
|
||||
m_pSensor = NULL;
|
||||
}
|
||||
|
@ -73,27 +72,39 @@ void CCAccelerometer::addDelegate(CCAccelerometerDelegate* pDelegate)
|
|||
{
|
||||
m_pDelegate = pDelegate;
|
||||
|
||||
m_pSensor = TCOM_Sensors_DataType_Client::GetInstance();
|
||||
|
||||
if (m_pSensor)
|
||||
do
|
||||
{
|
||||
m_pSensor->StartUp();
|
||||
m_pSensor->SetDelay(TG3_SENSOR_DELAY_FASTEST);
|
||||
if (m_pSensor)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
TApplication* pApp = TApplication::GetCurrentApplication();
|
||||
TWindow* pWnd = pApp->GetActiveWindow();
|
||||
m_pSensor->SetWindowCtrlId(pWnd->GetWindowHwndId(), 0);
|
||||
m_pSensor->Activate(TG3_SENSOR_TYPE_ACCELEROMETER, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("cocos2d: The Accelerometer Sensor Open failed");
|
||||
}
|
||||
m_pSensor = TCOM_Sensors_DataType_Client::GetInstance();
|
||||
|
||||
if (m_pSensor)
|
||||
{
|
||||
m_pSensor->StartUp();
|
||||
m_pSensor->SetDelay(TG3_SENSOR_DELAY_FASTEST);
|
||||
|
||||
TApplication* pApp = TApplication::GetCurrentApplication();
|
||||
TWindow* pWnd = pApp->GetActiveWindow();
|
||||
m_pSensor->SetWindowCtrlId(pWnd->GetWindowHwndId(), 0);
|
||||
m_pSensor->Activate(TG3_SENSOR_TYPE_ACCELEROMETER, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("cocos2d: The Accelerometer Sensor Open failed");
|
||||
}
|
||||
} while (0);
|
||||
|
||||
}
|
||||
|
||||
void CCAccelerometer::didAccelerate(CCAcceleration* pAccelerationValue)
|
||||
{
|
||||
m_pDelegate->didAccelerate(pAccelerationValue);
|
||||
if (m_pDelegate)
|
||||
{
|
||||
m_pDelegate->didAccelerate(pAccelerationValue);
|
||||
}
|
||||
}
|
||||
|
||||
}//namespace cocos2d
|
||||
|
|
|
@ -120,7 +120,8 @@ OBJECTS = \
|
|||
$(OBJECTS_DIR)/TransitionsTest.o \
|
||||
$(OBJECTS_DIR)/UserDefaultTest.o \
|
||||
$(OBJECTS_DIR)/ZwoptexTest.o \
|
||||
$(OBJECTS_DIR)/FontTest.o
|
||||
$(OBJECTS_DIR)/FontTest.o \
|
||||
$(OBJECTS_DIR)/CurrentLanguageTest.o
|
||||
|
||||
ADD_OBJECTS +=
|
||||
|
||||
|
@ -394,3 +395,6 @@ $(OBJECTS_DIR)/ZwoptexTest.o : ../tests/ZwoptexTest/ZwoptexTest.cpp
|
|||
$(OBJECTS_DIR)/FontTest.o : ../tests/FontTest/FontTest.cpp
|
||||
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/FontTest.o ../tests/FontTest/FontTest.cpp
|
||||
|
||||
$(OBJECTS_DIR)/CurrentLanguageTest.o : ../tests/CurrentLanguageTest/CurrentLanguageTest.cpp
|
||||
$(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CurrentLanguageTest.o ../tests/CurrentLanguageTest/CurrentLanguageTest.cpp
|
||||
|
||||
|
|
Loading…
Reference in New Issue