Skip to content

Commit

Permalink
fixed cocos2d#702 tests crashs at the start on wophone device
Browse files Browse the repository at this point in the history
  • Loading branch information
liswei committed Aug 30, 2011
1 parent b020a69 commit deb5cbf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
13 changes: 8 additions & 5 deletions cocos2dx/platform/android/CCAccelerometer_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 5 additions & 0 deletions cocos2dx/platform/ios/AccelerometerDelegateWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ - (void) removeDelegate: (cocos2d::CCAccelerometerDelegate *) delegate

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
if (! delegate_)
{
return;
}

acceleration_->x = acceleration.x;
acceleration_->y = acceleration.y;
acceleration_->z = acceleration.z;
Expand Down
45 changes: 28 additions & 17 deletions cocos2dx/platform/wophone/CCAccelerometer_wophone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ CCAccelerometer* CCAccelerometer::sharedAccelerometer()
void CCAccelerometer::removeDelegate(CCAccelerometerDelegate* pDelegate)
{
m_pDelegate = NULL;

m_pSensor->Release();
m_pSensor = NULL;
}
Expand All @@ -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);

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");
}
if (m_pSensor)
{
break;
}

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
6 changes: 5 additions & 1 deletion tests/test.wophone/Makefile.ARM
Original file line number Diff line number Diff line change
Expand Up @@ -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 +=

Expand Down Expand Up @@ -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

0 comments on commit deb5cbf

Please sign in to comment.