issue #1177: Updated ios project configuration.

This commit is contained in:
James Chen 2012-04-23 14:35:41 +08:00
parent 0c6d21c0f9
commit 24515f009e
8 changed files with 167 additions and 304 deletions

View File

@ -1 +1 @@
8241040b5b40344918b886a37a17003c74c0b3f0 602577df19c20f69c1a4ae96072923365b422b34

View File

@ -472,11 +472,15 @@ CCSize CCDirector::getWinSizeInPixels()
void CCDirector::reshapeProjection(const CCSize& newWindowSize) void CCDirector::reshapeProjection(const CCSize& newWindowSize)
{ {
CC_UNUSED_PARAM(newWindowSize); CC_UNUSED_PARAM(newWindowSize);
m_obWinSizeInPoints = m_pobOpenGLView->getSize(); if (m_pobOpenGLView)
m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * m_fContentScaleFactor, {
m_obWinSizeInPoints = m_pobOpenGLView->getSize();
m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * m_fContentScaleFactor,
m_obWinSizeInPoints.height * m_fContentScaleFactor); m_obWinSizeInPoints.height * m_fContentScaleFactor);
setProjection(m_eProjection);
}
setProjection(m_eProjection);
} }
// scene management // scene management

View File

@ -6,45 +6,42 @@
#include "CCDictionary.h" #include "CCDictionary.h"
#include "CCInteger.h" #include "CCInteger.h"
#undef COCOS2D_DEBUG;
#define COCOS2D_DEBUG 1
NS_CC_BEGIN NS_CC_BEGIN
#define MAX_TOUCHES 5
static CCTouch* s_pTouches[CC_MAX_TOUCHES] = { NULL };
static CCTouch* s_pTouches[MAX_TOUCHES] = { NULL };
static unsigned int s_indexBitsUsed = 0; static unsigned int s_indexBitsUsed = 0;
static CCDictionary s_TouchesIntergerDict; static CCDictionary s_TouchesIntergerDict;
static int getUnUsedIndex() static int getUnUsedIndex()
{ {
int i; int i;
int temp = s_indexBitsUsed; int temp = s_indexBitsUsed;
for (i = 0; i < MAX_TOUCHES; i++) { for (i = 0; i < CC_MAX_TOUCHES; i++) {
if (! (temp & 0x00000001)) { if (! (temp & 0x00000001)) {
s_indexBitsUsed |= (1 << i); s_indexBitsUsed |= (1 << i);
return i; return i;
} }
temp >>= 1; temp >>= 1;
} }
// all bits are used // all bits are used
return -1; return -1;
} }
static void removeUsedIndexBit(int index) static void removeUsedIndexBit(int index)
{ {
if (index < 0 || index >= MAX_TOUCHES) if (index < 0 || index >= CC_MAX_TOUCHES)
{ {
return; return;
} }
unsigned int temp = 1 << index; unsigned int temp = 1 << index;
temp = ~temp; temp = ~temp;
s_indexBitsUsed &= temp; s_indexBitsUsed &= temp;
} }
CCEGLViewProtocol::CCEGLViewProtocol() CCEGLViewProtocol::CCEGLViewProtocol()
@ -66,7 +63,7 @@ bool CCEGLViewProtocol::isIpad()
CCSize CCEGLViewProtocol::getSize() CCSize CCEGLViewProtocol::getSize()
{ {
CCSize size(m_sSizeInPoint.width, m_sSizeInPoint.height); CCSize size(m_sSizeInPoint.width, m_sSizeInPoint.height);
return size; return size;
} }
@ -97,19 +94,19 @@ void CCEGLViewProtocol::setContentScaleFactor(float contentScaleFactor)
void CCEGLViewProtocol::setViewPortInPoints(float x , float y , float w , float h) void CCEGLViewProtocol::setViewPortInPoints(float x , float y , float w , float h)
{ {
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR(); float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glViewport((GLint)(x * factor) + m_rcViewPort.origin.x, glViewport((GLint)(x * factor) + m_rcViewPort.origin.x,
(GLint)(y * factor) + m_rcViewPort.origin.y, (GLint)(y * factor) + m_rcViewPort.origin.y,
(GLsizei)(w * factor), (GLsizei)(w * factor),
(GLsizei)(h * factor)); (GLsizei)(h * factor));
} }
void CCEGLViewProtocol::setScissorInPoints(float x , float y , float w , float h) void CCEGLViewProtocol::setScissorInPoints(float x , float y , float w , float h)
{ {
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR(); float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glScissor((GLint)(x * factor) + m_rcViewPort.origin.x, glScissor((GLint)(x * factor) + m_rcViewPort.origin.x,
(GLint)(y * factor) + m_rcViewPort.origin.y, (GLint)(y * factor) + m_rcViewPort.origin.y,
(GLsizei)(w * factor), (GLsizei)(w * factor),
(GLsizei)(h * factor)); (GLsizei)(h * factor));
} }
@ -135,26 +132,26 @@ void CCEGLViewProtocol::handleTouchesBegin(int num, int ids[], float xs[], float
{ {
nUnusedIndex = getUnUsedIndex(); nUnusedIndex = getUnUsedIndex();
// The touches is more than MAX_TOUCHES ? // The touches is more than MAX_TOUCHES ?
if (nUnusedIndex == -1) { if (nUnusedIndex == -1) {
CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex); CCLOG("The touches is more than MAX_TOUCHES, nUnusedIndex = %d", nUnusedIndex);
return; return;
} }
CCTouch* pTouch = s_pTouches[nUnusedIndex] = new CCTouch(); CCTouch* pTouch = s_pTouches[nUnusedIndex] = new CCTouch();
pTouch->SetTouchInfo(nUnusedIndex, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, pTouch->SetTouchInfo(nUnusedIndex, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
(y - m_rcViewPort.origin.y) / m_fScreenScaleFactor); (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
CCInteger* pInterObj = new CCInteger(nUnusedIndex); CCInteger* pInterObj = new CCInteger(nUnusedIndex);
s_TouchesIntergerDict.setObject(pInterObj, id); s_TouchesIntergerDict.setObject(pInterObj, id);
set.addObject(pTouch); set.addObject(pTouch);
pInterObj->release(); pInterObj->release();
} }
} }
if (set.count() == 0) if (set.count() == 0)
{ {
CCLOG("touchesBegan: count = 0"); CCLOG("touchesBegan: count = 0");
return; return;
} }
@ -168,33 +165,33 @@ void CCEGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float
{ {
int id = ids[i]; int id = ids[i];
float x = xs[i]; float x = xs[i];
float y = ys[i]; float y = ys[i];
CCInteger* pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id); CCInteger* pIndex = (CCInteger*)s_TouchesIntergerDict.objectForKey(id);
if (pIndex == NULL) { if (pIndex == NULL) {
CCLOG("if the index doesn't exist, it is an error"); CCLOG("if the index doesn't exist, it is an error");
return; return;
} }
CCLOG("Moving touches with id: %d, x=%f, y=%f", id, x, y); CCLOG("Moving touches with id: %d, x=%f, y=%f", id, x, y);
CCTouch* pTouch = s_pTouches[pIndex->getValue()]; CCTouch* pTouch = s_pTouches[pIndex->getValue()];
if (pTouch) if (pTouch)
{ {
pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
(y - m_rcViewPort.origin.y) / m_fScreenScaleFactor); (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
set.addObject(pTouch); set.addObject(pTouch);
} }
else else
{ {
// It is error, should return. // It is error, should return.
CCLOG("Moving touches with id: %d error", id); CCLOG("Moving touches with id: %d error", id);
return; return;
} }
} }
if (set.count() == 0) if (set.count() == 0)
{ {
CCLOG("touchesMoved: count = 0"); CCLOG("touchesMoved: count = 0");
return; 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"); CCLOG("if the index doesn't exist, it is an error");
return; return;
} }
/* Add to the set to send to the director */ /* Add to the set to send to the director */
CCTouch* pTouch = s_pTouches[pIndex->getValue()]; CCTouch* pTouch = s_pTouches[pIndex->getValue()];
if (pTouch) if (pTouch)
{ {
CCLOG("Ending touches with id: %d, x=%f, y=%f", id, x, y); CCLOG("Ending touches with id: %d, x=%f, y=%f", id, x, y);
pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, pTouch->SetTouchInfo(pIndex->getValue(), (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor,
(y - m_rcViewPort.origin.y) / m_fScreenScaleFactor); (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
set.addObject(pTouch); set.addObject(pTouch);
// release the object // release the object
pTouch->release(); pTouch->release();
s_pTouches[pIndex->getValue()] = NULL; s_pTouches[pIndex->getValue()] = NULL;
removeUsedIndexBit(pIndex->getValue()); removeUsedIndexBit(pIndex->getValue());
s_TouchesIntergerDict.removeObjectForKey(id); s_TouchesIntergerDict.removeObjectForKey(id);
} }
else else
{ {
CCLOG("Ending touches with id: %d error", id); CCLOG("Ending touches with id: %d error", id);
return; return;
} }
} }
if (set.count() == 0) if (set.count() == 0)
{ {
CCLOG("touchesEnded or touchesCancel: count = 0"); CCLOG("touchesEnded or touchesCancel: count = 0");
return; return;
} }
} }

View File

@ -5,6 +5,8 @@
NS_CC_BEGIN NS_CC_BEGIN
#define CC_MAX_TOUCHES 5
class EGLTouchDelegate; class EGLTouchDelegate;
class CCSet; class CCSet;
@ -41,7 +43,7 @@ private:
protected: protected:
EGLTouchDelegate* m_pDelegate; EGLTouchDelegate* m_pDelegate;
float m_fScreenScaleFactor; float m_fScreenScaleFactor;
CCSize m_sSizeInPixel; CCSize m_sSizeInPixel;
CCSize m_sSizeInPoint; CCSize m_sSizeInPoint;
CCRect m_rcViewPort; CCRect m_rcViewPort;
}; };

View File

@ -26,15 +26,13 @@ THE SOFTWARE.
#define __CC_EGLVIEW_IPHONE_H__ #define __CC_EGLVIEW_IPHONE_H__
#include "CCCommon.h" #include "CCCommon.h"
#include "CCEGLViewProtocol.h"
NS_CC_BEGIN NS_CC_BEGIN
class CCSet;
class CCTouch;
class EGLTouchDelegate;
class CCSize;
class CC_DLL CCEGLView
class CC_DLL CCEGLView : public CCEGLViewProtocol
{ {
public: public:
CCEGLView(); CCEGLView();
@ -47,25 +45,16 @@ public:
void setContentScaleFactor(float contentScaleFactor); void setContentScaleFactor(float contentScaleFactor);
// keep compatible // keep compatible
void release(); void end();
void setTouchDelegate(EGLTouchDelegate * pDelegate);
void swapBuffers(); 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(); float getMainScreenScale();
void setIMEKeyboardState(bool bOpen); void setIMEKeyboardState(bool bOpen);
static CCEGLView& sharedOpenGLView(); static CCEGLView& sharedOpenGLView();
private:
EGLTouchDelegate *m_pDelegate;
}; };
NS_CC_END NS_CC_END

View File

@ -31,7 +31,6 @@ THE SOFTWARE.
NS_CC_BEGIN NS_CC_BEGIN
CCEGLView::CCEGLView() 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]); cocos2d::CCSize size([[EAGLView sharedEGLView] getWidth], [[EAGLView sharedEGLView] getHeight]);
return size; return size;
} }
@ -69,7 +69,7 @@ bool CCEGLView::isOpenGLReady()
[view setNeedsLayout]; [view setNeedsLayout];
} }
void CCEGLView::release() void CCEGLView::end()
{ {
[CCDirectorCaller destroy]; [CCDirectorCaller destroy];
@ -77,53 +77,12 @@ void CCEGLView::release()
[[EAGLView sharedEGLView] removeFromSuperview]; [[EAGLView sharedEGLView] removeFromSuperview];
} }
void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
{
m_pDelegate = pDelegate;
}
void CCEGLView::swapBuffers() void CCEGLView::swapBuffers()
{ {
[[EAGLView sharedEGLView] 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) void CCEGLView::setIMEKeyboardState(bool bOpen)
{ {

View File

@ -87,7 +87,7 @@
} }
CHECK_GL_ERROR_DEBUG(); CHECK_GL_ERROR();
} }
return self; return self;

View File

@ -62,7 +62,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
*/ */
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#import "CCEGLView.h"
#import "EAGLView.h" #import "EAGLView.h"
#import "CCES2Renderer.h" #import "CCES2Renderer.h"
#import "CCDirector.h" #import "CCDirector.h"
@ -74,7 +74,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
//CLASS IMPLEMENTATIONS: //CLASS IMPLEMENTATIONS:
static EAGLView *view; static EAGLView *view = 0;
@interface EAGLView (Private) @interface EAGLView (Private)
- (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup; - (BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup;
@ -142,8 +142,7 @@ static EAGLView *view;
[self release]; [self release];
return nil; return nil;
} }
touchesIntergerDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 4, NULL, NULL);
indexBitsUsed = 0x00000000;
view = self; view = self;
} }
@ -204,34 +203,6 @@ static EAGLView *view;
return bound.height; 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 -(BOOL) setupSurfaceWithSharegroup:(EAGLSharegroup*)sharegroup
{ {
@ -265,7 +236,6 @@ static EAGLView *view;
- (void) dealloc - (void) dealloc
{ {
CFRelease(touchesIntergerDict);
[renderer_ release]; [renderer_ release];
[super dealloc]; [super dealloc];
} }
@ -394,124 +364,66 @@ static EAGLView *view;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ {
cocos2d::CCSet set; int ids[CC_MAX_TOUCHES] = {0};
cocos2d::CCTouch *pTouch; float xs[CC_MAX_TOUCHES] = {0.0f};
float ys[CC_MAX_TOUCHES] = {0.0f};
int i = 0;
for (UITouch *touch in touches) { for (UITouch *touch in touches) {
NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch); ids[i] = (int)touch;
int unUsedIndex = 0; xs[i] = [touch locationInView: [touch view]].x;
ys[i] = [touch locationInView: [touch view]].y;
// it is a new touch ++i;
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);
}
} }
cocos2d::CCEGLView::sharedOpenGLView().handleTouchesBegin(i, ids, xs, ys);
if (set.count() == 0)
return;
cocos2d::CCDirector::sharedDirector()->getOpenGLView()->touchesBegan(&set);
} }
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{ {
cocos2d::CCSet set; int ids[CC_MAX_TOUCHES] = {0};
for (UITouch *touch in touches) { float xs[CC_MAX_TOUCHES] = {0.0f};
NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch); float ys[CC_MAX_TOUCHES] = {0.0f};
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);
}
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 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{ {
cocos2d::CCSet set; int ids[CC_MAX_TOUCHES] = {0};
for (UITouch *touch in touches) { float xs[CC_MAX_TOUCHES] = {0.0f};
NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch); float ys[CC_MAX_TOUCHES] = {0.0f};
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]];
}
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 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{ {
cocos2d::CCSet set; int ids[CC_MAX_TOUCHES] = {0};
for (UITouch *touch in touches) { float xs[CC_MAX_TOUCHES] = {0.0f};
NSNumber *index = (NSNumber*)CFDictionaryGetValue(touchesIntergerDict, touch); float ys[CC_MAX_TOUCHES] = {0.0f};
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]];
}
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 - #pragma mark -