From 24515f009ec36f3460d4e08c5be255c6bba9fd98 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 23 Apr 2012 14:35:41 +0800 Subject: [PATCH] issue #1177: Updated ios project configuration. --- .../project.pbxproj.REMOVED.git-id | 2 +- cocos2dx/CCDirector.cpp | 10 +- cocos2dx/platform/CCEGLViewProtocol.cpp | 205 +++++++++--------- cocos2dx/platform/CCEGLViewProtocol.h | 4 +- cocos2dx/platform/ios/CCEGLView_ios.h | 21 +- cocos2dx/platform/ios/CCEGLView_ios.mm | 47 +--- cocos2dx/platform/ios/CCES2Renderer.m | 2 +- cocos2dx/platform/ios/EAGLView.mm | 180 ++++----------- 8 files changed, 167 insertions(+), 304 deletions(-) diff --git a/HelloWorld/proj.ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id b/HelloWorld/proj.ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id index f346310483..f83c2ae670 100644 --- a/HelloWorld/proj.ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/HelloWorld/proj.ios/HelloWorld.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -8241040b5b40344918b886a37a17003c74c0b3f0 \ No newline at end of file +602577df19c20f69c1a4ae96072923365b422b34 \ No newline at end of file diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index 53779fe0c4..e8c4b182ef 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -472,11 +472,15 @@ CCSize CCDirector::getWinSizeInPixels() void CCDirector::reshapeProjection(const CCSize& newWindowSize) { CC_UNUSED_PARAM(newWindowSize); - m_obWinSizeInPoints = m_pobOpenGLView->getSize(); - m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * m_fContentScaleFactor, + if (m_pobOpenGLView) + { + m_obWinSizeInPoints = m_pobOpenGLView->getSize(); + m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * m_fContentScaleFactor, m_obWinSizeInPoints.height * m_fContentScaleFactor); + + setProjection(m_eProjection); + } - setProjection(m_eProjection); } // scene management diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index b3f07ea3a2..c2aeee8624 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -6,45 +6,42 @@ #include "CCDictionary.h" #include "CCInteger.h" -#undef COCOS2D_DEBUG; -#define COCOS2D_DEBUG 1 NS_CC_BEGIN -#define MAX_TOUCHES 5 - -static CCTouch* s_pTouches[MAX_TOUCHES] = { NULL }; + +static CCTouch* s_pTouches[CC_MAX_TOUCHES] = { NULL }; static unsigned int s_indexBitsUsed = 0; static CCDictionary s_TouchesIntergerDict; -static int getUnUsedIndex() -{ - int i; - int temp = s_indexBitsUsed; - - for (i = 0; i < MAX_TOUCHES; i++) { - if (! (temp & 0x00000001)) { - s_indexBitsUsed |= (1 << i); - return i; - } - - temp >>= 1; - } - - // all bits are used - return -1; -} - -static void removeUsedIndexBit(int index) -{ - if (index < 0 || index >= MAX_TOUCHES) - { - return; - } - - unsigned int temp = 1 << index; - temp = ~temp; - s_indexBitsUsed &= temp; +static int getUnUsedIndex() +{ + int i; + int temp = s_indexBitsUsed; + + for (i = 0; i < CC_MAX_TOUCHES; i++) { + if (! (temp & 0x00000001)) { + s_indexBitsUsed |= (1 << i); + return i; + } + + temp >>= 1; + } + + // all bits are used + return -1; +} + +static void removeUsedIndexBit(int index) +{ + if (index < 0 || index >= CC_MAX_TOUCHES) + { + return; + } + + unsigned int temp = 1 << index; + temp = ~temp; + s_indexBitsUsed &= temp; } CCEGLViewProtocol::CCEGLViewProtocol() @@ -66,7 +63,7 @@ bool CCEGLViewProtocol::isIpad() CCSize CCEGLViewProtocol::getSize() { - CCSize size(m_sSizeInPoint.width, m_sSizeInPoint.height); + CCSize size(m_sSizeInPoint.width, m_sSizeInPoint.height); return size; } @@ -97,19 +94,19 @@ void CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor) void CCEGLViewProtocol::setViewPortInPoints(float x , float y , float w , float h) { - float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR(); - glViewport((GLint)(x * factor) + m_rcViewPort.origin.x, - (GLint)(y * factor) + m_rcViewPort.origin.y, - (GLsizei)(w * factor), + float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR(); + glViewport((GLint)(x * factor) + m_rcViewPort.origin.x, + (GLint)(y * factor) + m_rcViewPort.origin.y, + (GLsizei)(w * factor), (GLsizei)(h * factor)); } void CCEGLViewProtocol::setScissorInPoints(float x , float y , float w , float h) { - float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR(); - glScissor((GLint)(x * factor) + m_rcViewPort.origin.x, - (GLint)(y * factor) + m_rcViewPort.origin.y, - (GLsizei)(w * factor), + float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR(); + glScissor((GLint)(x * factor) + m_rcViewPort.origin.x, + (GLint)(y * factor) + m_rcViewPort.origin.y, + (GLsizei)(w * factor), (GLsizei)(h * factor)); } @@ -135,26 +132,26 @@ void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float { nUnusedIndex = getUnUsedIndex(); - // The touches is more than MAX_TOUCHES ? - if (nUnusedIndex == -1) { - CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex); - return; + // The touches is more than MAX_TOUCHES ? + if (nUnusedIndex == -1) { + CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex); + return; } CCTouch* pTouch = s_pTouches[nUnusedIndex] = new CCTouch(); - pTouch->SetTouchInfo(nUnusedIndex, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, - (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor); - - CCInteger* pInterObj = new CCInteger(nUnusedIndex); - s_TouchesIntergerDict.setObject(pInterObj, id); + pTouch->SetTouchInfo(nUnusedIndex, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, + (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor); + + CCInteger* pInterObj = new CCInteger(nUnusedIndex); + s_TouchesIntergerDict.setObject(pInterObj, id); set.addObject(pTouch); pInterObj->release(); } } - if (set.count() == 0) - { - CCLOG("touchesBegan: count = 0"); + if (set.count() == 0) + { + CCLOG("touchesBegan: count = 0"); return; } @@ -168,33 +165,33 @@ void CCEGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float { int id = ids[i]; float x = xs[i]; - float y = ys[i]; - - CCInteger* pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id); - if (pIndex == NULL) { - CCLOG("if the index doesn't exist, it is an error"); - return; - } - - CCLOG("Moving touches with id: %d, x=%f, y=%f", id, x, y); - CCTouch* pTouch = s_pTouches[pIndex->getValue()]; - if (pTouch) - { - pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, - (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor); - set.addObject(pTouch); - } - else - { - // It is error, should return. - CCLOG("Moving touches with id: %d error", id); - return; - } + float y = ys[i]; + + CCInteger* pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id); + if (pIndex == NULL) { + CCLOG("if the index doesn't exist, it is an error"); + return; + } + + CCLOG("Moving touches with id: %d, x=%f, y=%f", id, x, y); + CCTouch* pTouch = s_pTouches[pIndex->getValue()]; + if (pTouch) + { + pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, + (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor); + set.addObject(pTouch); + } + else + { + // It is error, should return. + CCLOG("Moving touches with id: %d error", id); + return; + } } - if (set.count() == 0) - { - CCLOG("touchesMoved: count = 0"); + if (set.count() == 0) + { + CCLOG("touchesMoved: count = 0"); return; } @@ -215,35 +212,35 @@ void CCEGLViewProtocol::getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[ CCLOG("if the index doesn't exist, it is an error"); return; } - /* Add to the set to send to the director */ - CCTouch* pTouch = s_pTouches[pIndex->getValue()]; - if (pTouch) - { - CCLOG("Ending touches with id: %d, x=%f, y=%f", id, x, y); - - pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, - (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor); - set.addObject(pTouch); - - // release the object - pTouch->release(); - s_pTouches[pIndex->getValue()] = NULL; - removeUsedIndexBit(pIndex->getValue()); - - s_TouchesIntergerDict.removeObjectForKey(id); - - } - else - { - CCLOG("Ending touches with id: %d error", id); - return; + /* Add to the set to send to the director */ + CCTouch* pTouch = s_pTouches[pIndex->getValue()]; + if (pTouch) + { + CCLOG("Ending touches with id: %d, x=%f, y=%f", id, x, y); + + pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, + (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor); + set.addObject(pTouch); + + // release the object + pTouch->release(); + s_pTouches[pIndex->getValue()] = NULL; + removeUsedIndexBit(pIndex->getValue()); + + s_TouchesIntergerDict.removeObjectForKey(id); + + } + else + { + CCLOG("Ending touches with id: %d error", id); + return; } } - if (set.count() == 0) - { - CCLOG("touchesEnded or touchesCancel: count = 0"); + if (set.count() == 0) + { + CCLOG("touchesEnded or touchesCancel: count = 0"); return; } } diff --git a/cocos2dx/platform/CCEGLViewProtocol.h b/cocos2dx/platform/CCEGLViewProtocol.h index a5438586a6..d3f880d5e2 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.h +++ b/cocos2dx/platform/CCEGLViewProtocol.h @@ -5,6 +5,8 @@ NS_CC_BEGIN +#define CC_MAX_TOUCHES 5 + class EGLTouchDelegate; class CCSet; @@ -41,7 +43,7 @@ private: protected: EGLTouchDelegate* m_pDelegate; float m_fScreenScaleFactor; - CCSize m_sSizeInPixel; + CCSize m_sSizeInPixel; CCSize m_sSizeInPoint; CCRect m_rcViewPort; }; diff --git a/cocos2dx/platform/ios/CCEGLView_ios.h b/cocos2dx/platform/ios/CCEGLView_ios.h index 4ff36d2ce4..fa89874119 100644 --- a/cocos2dx/platform/ios/CCEGLView_ios.h +++ b/cocos2dx/platform/ios/CCEGLView_ios.h @@ -26,15 +26,13 @@ THE SOFTWARE. #define __CC_EGLVIEW_IPHONE_H__ #include "CCCommon.h" +#include "CCEGLViewProtocol.h" NS_CC_BEGIN -class CCSet; -class CCTouch; -class EGLTouchDelegate; -class CCSize; -class CC_DLL CCEGLView + +class CC_DLL CCEGLView : public CCEGLViewProtocol { public: CCEGLView(); @@ -47,25 +45,16 @@ public: void setContentScaleFactor(float contentScaleFactor); // keep compatible - void release(); - void setTouchDelegate(EGLTouchDelegate * pDelegate); + void end(); void swapBuffers(); - void setViewPortInPoints(float x, float y, float w, float h); - void setScissorInPoints(float x, float y, float w, float h); - void touchesBegan(CCSet *set); - void touchesMoved(CCSet *set); - void touchesEnded(CCSet *set); - void touchesCancelled(CCSet *set); float getMainScreenScale(); void setIMEKeyboardState(bool bOpen); static CCEGLView& sharedOpenGLView(); - -private: - EGLTouchDelegate *m_pDelegate; + }; NS_CC_END diff --git a/cocos2dx/platform/ios/CCEGLView_ios.mm b/cocos2dx/platform/ios/CCEGLView_ios.mm index 84b4c2ec85..ee1ce01c2f 100644 --- a/cocos2dx/platform/ios/CCEGLView_ios.mm +++ b/cocos2dx/platform/ios/CCEGLView_ios.mm @@ -31,7 +31,6 @@ THE SOFTWARE. NS_CC_BEGIN CCEGLView::CCEGLView() -: m_pDelegate(0) { } @@ -41,9 +40,10 @@ CCEGLView::~CCEGLView() } -cocos2d::CCSize CCEGLView::getSize() +CCSize CCEGLView::getSize() { cocos2d::CCSize size([[EAGLView sharedEGLView] getWidth], [[EAGLView sharedEGLView] getHeight]); + return size; } @@ -69,7 +69,7 @@ bool CCEGLView::isOpenGLReady() [view setNeedsLayout]; } -void CCEGLView::release() +void CCEGLView::end() { [CCDirectorCaller destroy]; @@ -77,53 +77,12 @@ void CCEGLView::release() [[EAGLView sharedEGLView] removeFromSuperview]; } -void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate) -{ - m_pDelegate = pDelegate; -} void CCEGLView::swapBuffers() { [[EAGLView sharedEGLView] swapBuffers]; } - -void CCEGLView::touchesBegan(CCSet *set) -{ - if (m_pDelegate) { - m_pDelegate->touchesBegan(set, NULL); - } -} -void CCEGLView::touchesMoved(CCSet *set) -{ - if (m_pDelegate) { - m_pDelegate->touchesMoved(set, NULL); - } -} - -void CCEGLView::touchesEnded(CCSet *set) -{ - if (m_pDelegate) { - m_pDelegate->touchesEnded(set, NULL); - } -} - -void CCEGLView::touchesCancelled(CCSet *set) -{ - if (m_pDelegate) { - m_pDelegate->touchesCancelled(set, NULL); - } -} - -void CCEGLView::setViewPortInPoints(float x, float y, float w, float h) -{ - glViewport((GLint)x, (GLint)y, (GLint)w, (GLint)h); -} - -void CCEGLView::setScissorInPoints(float x, float y, float w, float h) -{ - glScissor((GLint)x, (GLint)y, (GLint)w, (GLint)h); -} void CCEGLView::setIMEKeyboardState(bool bOpen) { diff --git a/cocos2dx/platform/ios/CCES2Renderer.m b/cocos2dx/platform/ios/CCES2Renderer.m index 43c4323933..fff8a09c09 100644 --- a/cocos2dx/platform/ios/CCES2Renderer.m +++ b/cocos2dx/platform/ios/CCES2Renderer.m @@ -87,7 +87,7 @@ } - CHECK_GL_ERROR_DEBUG(); + CHECK_GL_ERROR(); } return self; diff --git a/cocos2dx/platform/ios/EAGLView.mm b/cocos2dx/platform/ios/EAGLView.mm index 72d9d3ed5a..4f302cd0b7 100755 --- a/cocos2dx/platform/ios/EAGLView.mm +++ b/cocos2dx/platform/ios/EAGLView.mm @@ -62,7 +62,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. */ #import - +#import "CCEGLView.h" #import "EAGLView.h" #import "CCES2Renderer.h" #import "CCDirector.h" @@ -74,7 +74,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. //CLASS IMPLEMENTATIONS: -static EAGLView *view; +static EAGLView *view = 0; @interface EAGLView (Private) - (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup; @@ -142,8 +142,7 @@ static EAGLView *view; [self release]; return nil; } - touchesIntergerDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 4, NULL, NULL); - indexBitsUsed = 0x00000000; + view = self; } @@ -204,34 +203,6 @@ static EAGLView *view; return bound.height; } --(int) getUnUsedIndex -{ - int i; - int temp = indexBitsUsed; - - for (i = 0; i < MAX_TOUCHES; i++) { - if (! (temp & 0x00000001)) { - indexBitsUsed |= (1 << i); - return i; - } - - temp >>= 1; - } - - // all bits are used - return -1; -} - --(void) removeUsedIndexBit:(int) index -{ - if (index < 0 || index >= MAX_TOUCHES) { - return; - } - - unsigned int temp = 1 << index; - temp = ~temp; - indexBitsUsed &= temp; -} -(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup { @@ -265,7 +236,6 @@ static EAGLView *view; - (void) dealloc { - CFRelease(touchesIntergerDict); [renderer_ release]; [super dealloc]; } @@ -394,124 +364,66 @@ static EAGLView *view; - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - cocos2d::CCSet set; - cocos2d::CCTouch *pTouch; + int ids[CC_MAX_TOUCHES] = {0}; + float xs[CC_MAX_TOUCHES] = {0.0f}; + float ys[CC_MAX_TOUCHES] = {0.0f}; + int i = 0; for (UITouch *touch in touches) { - NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch); - int unUsedIndex = 0; - - // it is a new touch - if (! index) { - unUsedIndex = [self getUnUsedIndex]; - - // The touches is more than MAX_TOUCHES ? - if (unUsedIndex == -1) { - return; - } - - pTouch = s_pTouches[unUsedIndex] = new cocos2d::CCTouch(); - float x = [touch locationInView: [touch view]].x; - float y = [touch locationInView: [touch view]].y; - pTouch->SetTouchInfo(x, y); - - CFDictionaryAddValue(touchesIntergerDict, touch, [NSNumber numberWithInt:unUsedIndex]); - - set.addObject(pTouch); - } - + ids[i] = (int)touch; + xs[i] = [touch locationInView: [touch view]].x; + ys[i] = [touch locationInView: [touch view]].y; + ++i; } - - if (set.count() == 0) - return; - - cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesBegan(&set); + cocos2d::CCEGLView::sharedOpenGLView().handleTouchesBegin(i, ids, xs, ys); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - cocos2d::CCSet set; - for (UITouch *touch in touches) { - NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch); - if (! index) { - // if the index doesn't exist, it is an error - return; - } - - cocos2d::CCTouch *pTouch = s_pTouches[[index intValue]]; - if (! pTouch) { - // if the pTouch is null, it is an error - return; - } - - float x = [touch locationInView: [touch view]].x; - float y = [touch locationInView: [touch view]].y; - pTouch->SetTouchInfo(x, y); - - set.addObject(pTouch); - } + int ids[CC_MAX_TOUCHES] = {0}; + float xs[CC_MAX_TOUCHES] = {0.0f}; + float ys[CC_MAX_TOUCHES] = {0.0f}; - cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesMoved(&set); + int i = 0; + for (UITouch *touch in touches) { + ids[i] = (int)touch; + xs[i] = [touch locationInView: [touch view]].x; + ys[i] = [touch locationInView: [touch view]].y; + ++i; + } + cocos2d::CCEGLView::sharedOpenGLView().handleTouchesMove(i, ids, xs, ys); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - cocos2d::CCSet set; - for (UITouch *touch in touches) { - NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch); - if (! index) { - // if the index doesn't exist, it is an error - return; - } - - cocos2d::CCTouch *pTouch = s_pTouches[[index intValue]]; - if (! pTouch) { - // if the pTouch is null, it is an error - return; - } - - float x = [touch locationInView: [touch view]].x; - float y = [touch locationInView: [touch view]].y; - pTouch->SetTouchInfo(x, y); - - set.addObject(pTouch); - CFDictionaryRemoveValue(touchesIntergerDict, touch); - pTouch->release(); - s_pTouches[[index intValue]] = NULL; - [self removeUsedIndexBit:[index intValue]]; - } + int ids[CC_MAX_TOUCHES] = {0}; + float xs[CC_MAX_TOUCHES] = {0.0f}; + float ys[CC_MAX_TOUCHES] = {0.0f}; - cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesEnded(&set); + int i = 0; + for (UITouch *touch in touches) { + ids[i] = (int)touch; + xs[i] = [touch locationInView: [touch view]].x; + ys[i] = [touch locationInView: [touch view]].y; + ++i; + } + cocos2d::CCEGLView::sharedOpenGLView().handleTouchesEnd(i, ids, xs, ys); } - + - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { - cocos2d::CCSet set; - for (UITouch *touch in touches) { - NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch); - if (! index) { - // if the index doesn't exist, it is an error - return; - } - - cocos2d::CCTouch *pTouch = s_pTouches[[index intValue]]; - if (! pTouch) { - // if the pTouch is null, it is an error - return; - } - - float x = [touch locationInView: [touch view]].x; - float y = [touch locationInView: [touch view]].y; - pTouch->SetTouchInfo(x, y); - - set.addObject(pTouch); - CFDictionaryRemoveValue(touchesIntergerDict, touch); - pTouch->release(); - s_pTouches[[index intValue]] = NULL; - [self removeUsedIndexBit:[index intValue]]; - } + int ids[CC_MAX_TOUCHES] = {0}; + float xs[CC_MAX_TOUCHES] = {0.0f}; + float ys[CC_MAX_TOUCHES] = {0.0f}; - cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesCancelled(&set); + int i = 0; + for (UITouch *touch in touches) { + ids[i] = (int)touch; + xs[i] = [touch locationInView: [touch view]].x; + ys[i] = [touch locationInView: [touch view]].y; + ++i; + } + cocos2d::CCEGLView::sharedOpenGLView().handleTouchesCancel(i, ids, xs, ys); } #pragma mark -