mirror of https://github.com/axmolengine/axmol.git
Merge branch 'master' of https://github.com/minggo/cocos2d-x into minggo-master
This commit is contained in:
commit
29191a385e
|
@ -1 +1 @@
|
|||
dcf33885794fe98f449903755c50a2d7e7e1c42d
|
||||
c2fa89866e8523e8328386cf28298e2d676a2113
|
|
@ -59,7 +59,7 @@ bool HelloWorld::applicationDidFinishLaunching()
|
|||
CCDirector::sharedDirector()->setDisplayFPS(true);
|
||||
|
||||
// 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();
|
||||
|
||||
// create sprite instance
|
||||
|
|
|
@ -305,14 +305,14 @@ namespace cocos2d{
|
|||
NSMutableArray<CCNode*>::NSMutableArrayIterator it;
|
||||
for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it)
|
||||
{
|
||||
assert(row < rows.size());
|
||||
|
||||
// if it has no value, break
|
||||
if (! *it)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
assert(row < rows.size());
|
||||
|
||||
rowColumns = rows[row];
|
||||
// can not have zero columns on a row
|
||||
assert(rowColumns);
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -25,6 +25,8 @@ THE SOFTWARE.
|
|||
#ifndef __PLATFORM_IPHONE_UIACCELEROMETER_H__
|
||||
#define __PLATFORM_IPHONE_UIACCELEROMETER_H__
|
||||
|
||||
#include "CCUIAccelerometerDelegate.h"
|
||||
|
||||
namespace cocos2d {
|
||||
|
||||
class CCX_DLL UIAccelerometer
|
||||
|
@ -33,10 +35,13 @@ public:
|
|||
UIAccelerometer();
|
||||
~UIAccelerometer();
|
||||
|
||||
static UIAccelerometer* sharedAccelerometer() { return NULL; }
|
||||
static UIAccelerometer* sharedAccelerometer();
|
||||
|
||||
void removeDelegate(UIAccelerometerDelegate* pDelegate) {}
|
||||
void addDelegate(UIAccelerometerDelegate* pDelegate) {}
|
||||
void removeDelegate(UIAccelerometerDelegate* pDelegate);
|
||||
void addDelegate(UIAccelerometerDelegate* pDelegate);
|
||||
|
||||
private:
|
||||
static UIAccelerometer* m_spUIAccelerometer;
|
||||
};
|
||||
|
||||
}//namespace cocos2d
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ THE SOFTWARE.
|
|||
#include "CCXUIImage.h"
|
||||
|
||||
// @todo EAGLContext static EAGLContext *auxEAGLcontext = NULL;
|
||||
namespace cocos2d {
|
||||
namespace cocos2d {
|
||||
|
||||
class CCAsyncObject : NSObject
|
||||
{
|
||||
|
@ -203,7 +203,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
|||
texture = this->addPVRTCImage(fullpath.c_str());
|
||||
#endif
|
||||
}
|
||||
// Issue #886: TEMPORARY FIX FOR TRANSPARENT JPEGS IN IOS4
|
||||
// Issue #886: TEMPORARY FIX FOR TRANSPARENT JPEGS IN IOS4
|
||||
else if (std::string::npos != lowerCase.find(".jpg") || std::string::npos != lowerCase.find(".jpeg"))
|
||||
{
|
||||
UIImage * image = new UIImage();
|
||||
|
@ -228,11 +228,11 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
|||
}
|
||||
else
|
||||
{
|
||||
//# work around for issue #910
|
||||
#if 0
|
||||
UIImage *image = [UIImage imageNamed:path];
|
||||
tex = [ [CCTexture2D alloc] initWithImage: image ];
|
||||
#else
|
||||
//# work around for issue #910
|
||||
#if 0
|
||||
UIImage *image = [UIImage imageNamed:path];
|
||||
tex = [ [CCTexture2D alloc] initWithImage: image ];
|
||||
#else
|
||||
// prevents overloading the autorelease pool
|
||||
UIImage * image = new UIImage();
|
||||
if(! image->initWithContentsOfFile(fullpath, kImageFormatPNG))
|
||||
|
@ -243,7 +243,7 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
|||
texture = new CCTexture2D();
|
||||
texture->initWithImage(image);
|
||||
CCX_SAFE_DELETE(image);// image->release();
|
||||
#endif
|
||||
#endif
|
||||
if( texture )
|
||||
{
|
||||
m_pTextures->setObject(texture, fullpath);
|
||||
|
@ -395,7 +395,7 @@ void CCTextureCache::removeUnusedTextures()
|
|||
{
|
||||
std::vector<std::string> keys = m_pTextures->allKeys();
|
||||
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);
|
||||
if (value->retainCount() == 1)
|
||||
|
@ -427,5 +427,5 @@ void CCTextureCache::removeTextureForKey(const std::string & textureKeyName)
|
|||
m_pTextures->removeObjectForKey(textureKeyName);
|
||||
}
|
||||
|
||||
}//namespace cocos2d
|
||||
}//namespace cocos2d
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
37854b49027942c354d8be8381c82bd7df1a2457
|
||||
4d614609763ca8fd94ad6f76d0fd8cc17e9dd36e
|
Loading…
Reference in New Issue