Merge branch 'master' of https://github.com/minggo/cocos2d-x into minggo-master

This commit is contained in:
walzer 2010-11-24 10:38:01 +08:00
commit 29191a385e
9 changed files with 260 additions and 18 deletions

View File

@ -1 +1 @@
dcf33885794fe98f449903755c50a2d7e7e1c42d c2fa89866e8523e8328386cf28298e2d676a2113

View File

@ -59,7 +59,7 @@ bool HelloWorld::applicationDidFinishLaunching()
CCDirector::sharedDirector()->setDisplayFPS(true); CCDirector::sharedDirector()->setDisplayFPS(true);
// load image texture and get window size // load image texture and get window size
CCTexture2D *pTextrue = CCTextureCache::sharedTextureCache()->addImage("images/helloworld.png"); CCTexture2D *pTextrue = CCTextureCache::sharedTextureCache()->addImage("helloworld.png");
CGSize size = CCDirector::sharedDirector()->getWinSize(); CGSize size = CCDirector::sharedDirector()->getWinSize();
// create sprite instance // create sprite instance

View File

@ -305,14 +305,14 @@ namespace cocos2d{
NSMutableArray<CCNode*>::NSMutableArrayIterator it; NSMutableArray<CCNode*>::NSMutableArrayIterator it;
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
{ {
assert(row < rows.size());
// if it has no value, break // if it has no value, break
if (! *it) if (! *it)
{ {
break; break;
} }
assert(row < rows.size());
rowColumns = rows[row]; rowColumns = rows[row];
// can not have zero columns on a row // can not have zero columns on a row
assert(rowColumns); assert(rowColumns);

View File

@ -0,0 +1,54 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#import <Foundation/Foundation.h>
#import "CCUIAccelerometerDelegate.h"
#import <UIKit/UIKit.h>
@interface AccelerometerDispatcher : NSObject<UIAccelerometerDelegate>
{
NSMutableArray *delegateWrappers;
}
@property(readwrite, retain) NSMutableArray* delegateWrappers;
+ (id) sharedAccelerometerDispather;
- (id) init;
- (void) addDelegate: (cocos2d::UIAccelerometerDelegate *) delegate;
- (void) removeDelegate: (cocos2d::UIAccelerometerDelegate *) delegate;
@end
@interface AccelerometerDelegateWrapper : NSObject {
cocos2d::UIAccelerometerDelegate *delegate_;
}
@property(readwrite) cocos2d::UIAccelerometerDelegate *delegate_;
+ (id) delegateWrapperWithDelegate:(cocos2d::UIAccelerometerDelegate *)delegate;
- (id) initWithDelegate: (cocos2d::UIAccelerometerDelegate *)delegate;
- (void) didAccelerate: (cocos2d::UIAcceleration *)acceleration;
@end

View File

@ -0,0 +1,124 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#import "AccelerometerDelegateWrapper.h"
@implementation AccelerometerDispatcher
static AccelerometerDispatcher* s_pAccelerometerDispatcher;
@synthesize delegateWrappers;
+ (id) sharedAccelerometerDispather
{
if (s_pAccelerometerDispatcher == nil) {
s_pAccelerometerDispatcher = [[self alloc] init];
}
return s_pAccelerometerDispatcher;
}
- (id) init
{
self.delegateWrappers = [NSMutableArray arrayWithCapacity:4];
[[UIAccelerometer sharedAccelerometer] setDelegate: self];
return self;
}
- (void) dealloc
{
[[UIAccelerometer sharedAccelerometer] setDelegate: nil];
[delegateWrappers release];
[super dealloc];
}
- (id) findDelegateWrapperByDelegate: (cocos2d::UIAccelerometerDelegate *) delegate
{
for (AccelerometerDelegateWrapper *wrapper in delegateWrappers) {
if (wrapper.delegate_ == delegate) {
return wrapper;
}
}
return nil;
}
- (void) addDelegate: (cocos2d::UIAccelerometerDelegate *) delegate
{
[delegateWrappers addObject: [AccelerometerDelegateWrapper delegateWrapperWithDelegate:delegate]];
}
- (void) removeDelegate: (cocos2d::UIAccelerometerDelegate *) delegate
{
[delegateWrappers removeObject:[self findDelegateWrapperByDelegate:delegate]];
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
cocos2d::UIAcceleration accelerationCpp;
accelerationCpp.x = acceleration.x;
accelerationCpp.y = acceleration.y;
accelerationCpp.z = acceleration.z;
accelerationCpp.timestamp = acceleration.timestamp;
for (AccelerometerDelegateWrapper *wrapper in delegateWrappers) {
[wrapper didAccelerate: &accelerationCpp];
}
}
@end
@implementation AccelerometerDelegateWrapper
@synthesize delegate_;
+ (id)delegateWrapperWithDelegate:(cocos2d::UIAccelerometerDelegate *)delegate
{
return [[self alloc] initWithDelegate: delegate];
}
- (id) initWithDelegate: (cocos2d::UIAccelerometerDelegate *)delegate
{
delegate->AccelerometerKeep();
self.delegate_ = delegate;
return self;
}
- (void) didAccelerate: (cocos2d::UIAcceleration *)acceleration
{
self.delegate_->didAccelerate(acceleration);
}
- (void) dealloc
{
self.delegate_->AccelerometerDestroy();
[super dealloc];
}
@end

View File

@ -25,6 +25,8 @@ THE SOFTWARE.
#ifndef __PLATFORM_IPHONE_UIACCELEROMETER_H__ #ifndef __PLATFORM_IPHONE_UIACCELEROMETER_H__
#define __PLATFORM_IPHONE_UIACCELEROMETER_H__ #define __PLATFORM_IPHONE_UIACCELEROMETER_H__
#include "CCUIAccelerometerDelegate.h"
namespace cocos2d { namespace cocos2d {
class CCX_DLL UIAccelerometer class CCX_DLL UIAccelerometer
@ -33,10 +35,13 @@ public:
UIAccelerometer(); UIAccelerometer();
~UIAccelerometer(); ~UIAccelerometer();
static UIAccelerometer* sharedAccelerometer() { return NULL; } static UIAccelerometer* sharedAccelerometer();
void removeDelegate(UIAccelerometerDelegate* pDelegate) {} void removeDelegate(UIAccelerometerDelegate* pDelegate);
void addDelegate(UIAccelerometerDelegate* pDelegate) {} void addDelegate(UIAccelerometerDelegate* pDelegate);
private:
static UIAccelerometer* m_spUIAccelerometer;
}; };
}//namespace cocos2d }//namespace cocos2d

View File

@ -0,0 +1,59 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCXUIAccelerometer.h"
#include "AccelerometerDelegateWrapper.h"
namespace cocos2d {
UIAccelerometer* UIAccelerometer::m_spUIAccelerometer = NULL;
UIAccelerometer::UIAccelerometer()
{
}
UIAccelerometer::~UIAccelerometer()
{
}
UIAccelerometer* UIAccelerometer::sharedAccelerometer()
{
if (m_spUIAccelerometer == NULL) {
m_spUIAccelerometer = new UIAccelerometer();
}
return m_spUIAccelerometer;
}
void UIAccelerometer::removeDelegate(UIAccelerometerDelegate* pDelegate)
{
[[AccelerometerDispatcher sharedAccelerometerDispather] removeDelegate:pDelegate];
}
void UIAccelerometer::addDelegate(UIAccelerometerDelegate* pDelegate)
{
[[AccelerometerDispatcher sharedAccelerometerDispather] addDelegate:pDelegate];
}
}

View File

@ -395,7 +395,7 @@ void CCTextureCache::removeUnusedTextures()
{ {
std::vector<std::string> keys = m_pTextures->allKeys(); std::vector<std::string> keys = m_pTextures->allKeys();
std::vector<std::string>::iterator it; std::vector<std::string>::iterator it;
for (it = keys.begin(); it <= keys.end(); it++) for (it = keys.begin(); it != keys.end(); it++)
{ {
CCTexture2D *value = m_pTextures->objectForKey(*it); CCTexture2D *value = m_pTextures->objectForKey(*it);
if (value->retainCount() == 1) if (value->retainCount() == 1)

View File

@ -1 +1 @@
37854b49027942c354d8be8381c82bd7df1a2457 4d614609763ca8fd94ad6f76d0fd8cc17e9dd36e