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)
{
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

View File

@ -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;
}
}

View File

@ -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;
};

View File

@ -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

View File

@ -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)
{

View File

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

View File

@ -62,7 +62,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
*/
#import <QuartzCore/QuartzCore.h>
#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 -