mirror of https://github.com/axmolengine/axmol.git
issue #21: change INT32 to int, change UINT to unsigned int
This commit is contained in:
parent
167122d2cf
commit
a324e38cb2
|
@ -25,7 +25,6 @@ THE SOFTWARE.
|
||||||
#ifndef __CCCONFIGURATION_H__
|
#ifndef __CCCONFIGURATION_H__
|
||||||
#define __CCCONFIGURATION_H__
|
#define __CCCONFIGURATION_H__
|
||||||
|
|
||||||
#include "platform/platform.h"
|
|
||||||
#include "cocoa/NSObject.h"
|
#include "cocoa/NSObject.h"
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
|
@ -50,8 +50,8 @@ CCDirector* CCDirector::getSharedDirector(void)
|
||||||
{
|
{
|
||||||
if (! pobSharedDirector)
|
if (! pobSharedDirector)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Default Director is TimerDirector
|
// Default Director is TimerDirector
|
||||||
//
|
//
|
||||||
//pobSharedDirector = new CCTimerDirector();
|
//pobSharedDirector = new CCTimerDirector();
|
||||||
//pobSharedDirector->init();
|
//pobSharedDirector->init();
|
||||||
|
@ -175,7 +175,7 @@ void CCDirector::mainLoop(void)
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
/* to avoid flickr, nextScene MUST be here: after tick and before draw.
|
/* to avoid flickr, nextScene MUST be here: after tick and before draw.
|
||||||
XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */
|
XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */
|
||||||
if (m_pNextScene)
|
if (m_pNextScene)
|
||||||
{
|
{
|
||||||
|
@ -325,22 +325,22 @@ void CCDirector::setDeviceOrientation(ccDeviceOrientation kDeviceOrientation)
|
||||||
m_eDeviceOrientation = kDeviceOrientation;
|
m_eDeviceOrientation = kDeviceOrientation;
|
||||||
// how to implementation????
|
// how to implementation????
|
||||||
/*
|
/*
|
||||||
switch( deviceOrientation_) {
|
switch( deviceOrientation_) {
|
||||||
case CCDeviceOrientationPortrait:
|
case CCDeviceOrientationPortrait:
|
||||||
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated:NO];
|
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated:NO];
|
||||||
break;
|
break;
|
||||||
case CCDeviceOrientationPortraitUpsideDown:
|
case CCDeviceOrientationPortraitUpsideDown:
|
||||||
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated:NO];
|
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated:NO];
|
||||||
break;
|
break;
|
||||||
case CCDeviceOrientationLandscapeLeft:
|
case CCDeviceOrientationLandscapeLeft:
|
||||||
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];
|
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];
|
||||||
break;
|
break;
|
||||||
case CCDeviceOrientationLandscapeRight:
|
case CCDeviceOrientationLandscapeRight:
|
||||||
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated:NO];
|
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated:NO];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NSLog(@"Director: Unknown device orientation");
|
NSLog(@"Director: Unknown device orientation");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -371,25 +371,25 @@ void CCDirector::setProjection(ccDirectorProjection kProjection)
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kCCDirectorProjection3D:
|
case kCCDirectorProjection3D:
|
||||||
glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height);
|
glViewport(0, 0, (GLsizei)size.width, (GLsizei)size.height);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(60, (GLfloat)size.width/size.height, 0.5f, 1500.0f);
|
gluPerspective(60, (GLfloat)size.width/size.height, 0.5f, 1500.0f);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( size.width/2, size.height/2, getZEye(),
|
gluLookAt( size.width/2, size.height/2, getZEye(),
|
||||||
size.width/2, size.height/2, 0,
|
size.width/2, size.height/2, 0,
|
||||||
0.0f, 1.0f, 0.0f);
|
0.0f, 1.0f, 0.0f);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kCCDirectorProjectionCustom:
|
case kCCDirectorProjectionCustom:
|
||||||
// if custom, ignore it. The user is resposible for setting the correct projection
|
// if custom, ignore it. The user is resposible for setting the correct projection
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
CCLOG("cocos2d: Director: unrecognized projecgtion");
|
CCLOG("cocos2d: Director: unrecognized projecgtion");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,9 +454,9 @@ void CCDirector::setDepthTest(bool bOn)
|
||||||
{
|
{
|
||||||
if (bOn)
|
if (bOn)
|
||||||
{
|
{
|
||||||
glClearDepthf(1.0f);
|
glClearDepthf(1.0f);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -627,28 +627,28 @@ void CCDirector::applyLandspace(void)
|
||||||
float w = s.width / 2;
|
float w = s.width / 2;
|
||||||
float h = s.height / 2;
|
float h = s.height / 2;
|
||||||
|
|
||||||
// XXX it's using hardcoded values.
|
// XXX it's using hardcoded values.
|
||||||
// What if the the screen size changes in the future?
|
// What if the the screen size changes in the future?
|
||||||
switch (m_eDeviceOrientation)
|
switch (m_eDeviceOrientation)
|
||||||
{
|
{
|
||||||
case CCDeviceOrientationPortrait:
|
case CCDeviceOrientationPortrait:
|
||||||
// nothing
|
// nothing
|
||||||
break;
|
break;
|
||||||
case CCDeviceOrientationPortraitUpsideDown:
|
case CCDeviceOrientationPortraitUpsideDown:
|
||||||
// upside down
|
// upside down
|
||||||
glTranslatef(w,h,0);
|
glTranslatef(w,h,0);
|
||||||
glRotatef(180,0,0,1);
|
glRotatef(180,0,0,1);
|
||||||
glTranslatef(-w,-h,0);
|
glTranslatef(-w,-h,0);
|
||||||
break;
|
break;
|
||||||
case CCDeviceOrientationLandscapeRight:
|
case CCDeviceOrientationLandscapeRight:
|
||||||
glTranslatef(w,h,0);
|
glTranslatef(w,h,0);
|
||||||
glRotatef(90,0,0,1);
|
glRotatef(90,0,0,1);
|
||||||
glTranslatef(-h,-w,0);
|
glTranslatef(-h,-w,0);
|
||||||
break;
|
break;
|
||||||
case CCDeviceOrientationLandscapeLeft:
|
case CCDeviceOrientationLandscapeLeft:
|
||||||
glTranslatef(w,h,0);
|
glTranslatef(w,h,0);
|
||||||
glRotatef(-90,0,0,1);
|
glRotatef(-90,0,0,1);
|
||||||
glTranslatef(-h,-w,0);
|
glTranslatef(-h,-w,0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -671,7 +671,7 @@ void CCDirector::replaceScene(CCScene *pScene)
|
||||||
{
|
{
|
||||||
assert(pScene != NULL);
|
assert(pScene != NULL);
|
||||||
|
|
||||||
UINT32 index = m_pobScenesStack->count();
|
unsigned int index = m_pobScenesStack->count();
|
||||||
|
|
||||||
m_bSendCleanupToScene = true;
|
m_bSendCleanupToScene = true;
|
||||||
m_pobScenesStack->replaceObjectAtIndex(index - 1, pScene);
|
m_pobScenesStack->replaceObjectAtIndex(index - 1, pScene);
|
||||||
|
@ -694,7 +694,7 @@ void CCDirector::popScene(void)
|
||||||
assert(m_pRunningScene != NULL);
|
assert(m_pRunningScene != NULL);
|
||||||
|
|
||||||
m_pobScenesStack->removeLastObject();
|
m_pobScenesStack->removeLastObject();
|
||||||
UINT32 c = m_pobScenesStack->count();
|
unsigned int c = m_pobScenesStack->count();
|
||||||
|
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
{
|
{
|
||||||
|
@ -715,11 +715,11 @@ void CCDirector::end(void)
|
||||||
m_pRunningScene = NULL;
|
m_pRunningScene = NULL;
|
||||||
m_pNextScene = NULL;
|
m_pNextScene = NULL;
|
||||||
|
|
||||||
// remove all objects, but don't release it.
|
// remove all objects, but don't release it.
|
||||||
// runWithScene might be executed after 'end'.
|
// runWithScene might be executed after 'end'.
|
||||||
m_pobScenesStack->removeAllObjects();
|
m_pobScenesStack->removeAllObjects();
|
||||||
|
|
||||||
// don't release the event handlers
|
// don't release the event handlers
|
||||||
// They are needed in case the director is run again
|
// They are needed in case the director is run again
|
||||||
CCTouchDispatcher::getSharedDispatcher()->removeAllDelegates();
|
CCTouchDispatcher::getSharedDispatcher()->removeAllDelegates();
|
||||||
|
|
||||||
|
@ -757,7 +757,7 @@ void CCDirector::setNextScene(void)
|
||||||
{
|
{
|
||||||
m_pRunningScene->onExit();
|
m_pRunningScene->onExit();
|
||||||
|
|
||||||
// issue #709. the root node (scene) should receive the cleanup message too
|
// issue #709. the root node (scene) should receive the cleanup message too
|
||||||
// otherwise it might be leaked.
|
// otherwise it might be leaked.
|
||||||
if (m_bSendCleanupToScene)
|
if (m_bSendCleanupToScene)
|
||||||
{
|
{
|
||||||
|
@ -829,7 +829,7 @@ void CCDirector::preMainLoop(void)
|
||||||
|
|
||||||
// todo: implement later
|
// todo: implement later
|
||||||
#if CC_DIRECTOR_FAST_FPS
|
#if CC_DIRECTOR_FAST_FPS
|
||||||
// display the FPS using a LabelAtlas
|
// display the FPS using a LabelAtlas
|
||||||
// updates the FPS every frame
|
// updates the FPS every frame
|
||||||
void CCDirector::showFPS(void)
|
void CCDirector::showFPS(void)
|
||||||
{
|
{
|
||||||
|
@ -843,8 +843,8 @@ void CCDirector::showFPS(void)
|
||||||
m_fAccumDt = 0;
|
m_fAccumDt = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NSString *str = [[NSString alloc] initWithFormat:@"%.1f", frameRate];
|
NSString *str = [[NSString alloc] initWithFormat:@"%.1f", frameRate];
|
||||||
[FPSLabel setString:str];
|
[FPSLabel setString:str];
|
||||||
[str release];
|
[str release];
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -869,14 +869,14 @@ void CCDisplayLinkDirector::startAnimation(void)
|
||||||
|
|
||||||
m_bInvalid = false;
|
m_bInvalid = false;
|
||||||
|
|
||||||
// approximate frame rate
|
// approximate frame rate
|
||||||
// assumes device refreshes at 60 fps
|
// assumes device refreshes at 60 fps
|
||||||
//int frameInterval = (int) floor(animationInterval * 60.0f);
|
//int frameInterval = (int) floor(animationInterval * 60.0f);
|
||||||
|
|
||||||
//CCLOG(@"cocos2d: Frame interval: %d", frameInterval);
|
//CCLOG(@"cocos2d: Frame interval: %d", frameInterval);
|
||||||
|
|
||||||
//displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(preMainLoop:)];
|
//displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(preMainLoop:)];
|
||||||
//[displayLink setFrameInterval:frameInterval];
|
//[displayLink setFrameInterval:frameInterval];
|
||||||
//[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
//[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __CCDIRECTOR_H__
|
#ifndef __CCDIRECTOR_H__
|
||||||
#define __CCDIRECTOR_H__
|
#define __CCDIRECTOR_H__
|
||||||
|
|
||||||
#include "ccConfig.h"
|
#include "ccConfig.h"
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "Cocos2dDefine.h"
|
#include "Cocos2dDefine.h"
|
||||||
|
@ -32,13 +32,12 @@ THE SOFTWARE.
|
||||||
#include "cocoa/CGGeometry.h"
|
#include "cocoa/CGGeometry.h"
|
||||||
#include "cocoa/NSMutableArray.h"
|
#include "cocoa/NSMutableArray.h"
|
||||||
#include "cocoa/CGGeometry.h"
|
#include "cocoa/CGGeometry.h"
|
||||||
#include "CCXEGLView.h"
|
#include "CCXEGLView.h"
|
||||||
|
#include "platform/platform.h"
|
||||||
|
|
||||||
// OpenGL related
|
// OpenGL related
|
||||||
// #include "support/CCXEGLView.h"
|
// #include "support/CCXEGLView.h"
|
||||||
|
|
||||||
#include "platform/platform.h"
|
|
||||||
|
|
||||||
/** @typedef tPixelFormat
|
/** @typedef tPixelFormat
|
||||||
Possible Pixel Formats for the CCXEGLView
|
Possible Pixel Formats for the CCXEGLView
|
||||||
*/
|
*/
|
||||||
|
@ -296,8 +295,8 @@ public:
|
||||||
// bool attchInViewWithFrame(UIView *pView, CGRect frame);
|
// bool attchInViewWithFrame(UIView *pView, CGRect frame);
|
||||||
|
|
||||||
|
|
||||||
// // set the view where opengl to draw in
|
// // set the view where opengl to draw in
|
||||||
// bool attachWindow(UIWindow *pVindow);
|
// bool attachWindow(UIWindow *pVindow);
|
||||||
|
|
||||||
// Landspace
|
// Landspace
|
||||||
|
|
||||||
|
@ -455,7 +454,7 @@ protected:
|
||||||
|
|
||||||
/* display FPS ? */
|
/* display FPS ? */
|
||||||
bool m_bDisplayFPS;
|
bool m_bDisplayFPS;
|
||||||
INT32 m_nFrames;
|
int m_nFrames;
|
||||||
ccTime m_fAccumDt;
|
ccTime m_fAccumDt;
|
||||||
ccTime m_fFrameRate;
|
ccTime m_fFrameRate;
|
||||||
#if CC_DIRECTOR_FAST_FPS
|
#if CC_DIRECTOR_FAST_FPS
|
||||||
|
@ -503,34 +502,34 @@ protected:
|
||||||
#if CC_ENABLE_PROFILERS
|
#if CC_ENABLE_PROFILERS
|
||||||
ccTime m_fAccumDtForProfiler;
|
ccTime m_fAccumDtForProfiler;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** FastDirector is a Director that triggers the main loop as fast as possible.
|
/** FastDirector is a Director that triggers the main loop as fast as possible.
|
||||||
*
|
*
|
||||||
* Features and Limitations:
|
* Features and Limitations:
|
||||||
* - Faster than "normal" director
|
* - Faster than "normal" director
|
||||||
* - Consumes more battery than the "normal" director
|
* - Consumes more battery than the "normal" director
|
||||||
* - It has some issues while using UIKit objects
|
* - It has some issues while using UIKit objects
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
class CCFastDirector : public CCDirector
|
class CCFastDirector : public CCDirector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static CCFastDirector* getSharedDirector(void);
|
static CCFastDirector* getSharedDirector(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void preMainLoop(void);
|
virtual void preMainLoop(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCFastDirector(void) {}
|
CCFastDirector(void) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool isRunning;
|
bool isRunning;
|
||||||
NSAutoreleasePool *pAutoreleasePool;
|
NSAutoreleasePool *pAutoreleasePool;
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** ThreadedFastDirector is a Director that triggers the main loop from a thread.
|
/** ThreadedFastDirector is a Director that triggers the main loop from a thread.
|
||||||
*
|
*
|
||||||
* Features and Limitations:
|
* Features and Limitations:
|
||||||
|
@ -539,23 +538,23 @@ protected:
|
||||||
* - It can be used with UIKit objects
|
* - It can be used with UIKit objects
|
||||||
*
|
*
|
||||||
* @since v0.8.2
|
* @since v0.8.2
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
class CCThreadedFastDirector : public CCDirector
|
class CCThreadedFastDirector : public CCDirector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static CCThreadedFastDirector* getSharedDirector(void);
|
static CCThreadedFastDirector* getSharedDirector(void);
|
||||||
protected:
|
protected:
|
||||||
virtual void preMainLoop(void);
|
virtual void preMainLoop(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCThreadedFastDirector(void){}
|
CCThreadedFastDirector(void){}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool isRunning;
|
bool isRunning;
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** DisplayLinkDirector is a Director that synchronizes timers with the refresh rate of the display.
|
/** DisplayLinkDirector is a Director that synchronizes timers with the refresh rate of the display.
|
||||||
*
|
*
|
||||||
* Features and Limitations:
|
* Features and Limitations:
|
||||||
|
@ -566,22 +565,22 @@ protected:
|
||||||
* It is the recommended Director if the SDK is 3.1 or newer
|
* It is the recommended Director if the SDK is 3.1 or newer
|
||||||
*
|
*
|
||||||
* @since v0.8.2
|
* @since v0.8.2
|
||||||
*/
|
*/
|
||||||
class CCDisplayLinkDirector : public CCDirector
|
class CCDisplayLinkDirector : public CCDirector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCDisplayLinkDirector(void) {}
|
CCDisplayLinkDirector(void) {}
|
||||||
|
|
||||||
//static CCDisplayLinkDirector* getSharedDirector(void);
|
//static CCDisplayLinkDirector* getSharedDirector(void);
|
||||||
virtual void preMainLoop(void);
|
virtual void preMainLoop(void);
|
||||||
virtual void setAnimationInterval(double dValue);
|
virtual void setAnimationInterval(double dValue);
|
||||||
virtual void startAnimation(void);
|
virtual void startAnimation(void);
|
||||||
virtual void stopAnimation();
|
virtual void stopAnimation();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_bInvalid;
|
bool m_bInvalid;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** TimerDirector is a Director that calls the main loop from an NSTimer object
|
/** TimerDirector is a Director that calls the main loop from an NSTimer object
|
||||||
*
|
*
|
||||||
* Features and Limitations:
|
* Features and Limitations:
|
||||||
|
@ -590,22 +589,22 @@ protected:
|
||||||
* - The invertal update is customizable from 1 to 60
|
* - The invertal update is customizable from 1 to 60
|
||||||
*
|
*
|
||||||
* It is the default Director.
|
* It is the default Director.
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
class CCTimerDirector : public CCDirector
|
class CCTimerDirector : public CCDirector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static CCTimerDirector* getSharedDirector(void);
|
static CCTimerDirector* getSharedDirector(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void preMain(void);
|
virtual void preMain(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCTimerDirector(void) {}
|
CCTimerDirector(void) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NSTimer *pAnimationTimer;
|
NSTimer *pAnimationTimer;
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#endif // __CCDIRECTOR_H__
|
#endif // __CCDIRECTOR_H__
|
||||||
|
|
|
@ -41,7 +41,6 @@ THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Cocoa/CGGeometry.h" // for CGPoint
|
#include "Cocoa/CGGeometry.h" // for CGPoint
|
||||||
#include "platform/platform.h"
|
|
||||||
|
|
||||||
/** draws a point given x and y coordinate */
|
/** draws a point given x and y coordinate */
|
||||||
void ccDrawPoint( CGPoint point );
|
void ccDrawPoint( CGPoint point );
|
||||||
|
|
|
@ -31,35 +31,35 @@ THE SOFTWARE.
|
||||||
|
|
||||||
// data structures
|
// data structures
|
||||||
|
|
||||||
// A list double-linked list used for "updates with priority"
|
// A list double-linked list used for "updates with priority"
|
||||||
typedef struct _listEntry
|
typedef struct _listEntry
|
||||||
{
|
{
|
||||||
struct _listEntry *prev, *next;
|
struct _listEntry *prev, *next;
|
||||||
SelectorProtocol *target; // not retained (retained by hashUpdateEntry)
|
SelectorProtocol *target; // not retained (retained by hashUpdateEntry)
|
||||||
INT32 priority;
|
int priority;
|
||||||
bool paused;
|
bool paused;
|
||||||
|
|
||||||
} tListEntry;
|
} tListEntry;
|
||||||
|
|
||||||
typedef struct _hashUpdateEntry
|
typedef struct _hashUpdateEntry
|
||||||
{
|
{
|
||||||
tListEntry **list; // Which list does it belong to ?
|
tListEntry **list; // Which list does it belong to ?
|
||||||
tListEntry *entry; // entry in the list
|
tListEntry *entry; // entry in the list
|
||||||
SelectorProtocol *target; // hash key (retained)
|
SelectorProtocol *target; // hash key (retained)
|
||||||
UT_hash_handle hh;
|
UT_hash_handle hh;
|
||||||
} tHashUpdateEntry;
|
} tHashUpdateEntry;
|
||||||
|
|
||||||
// Hash Element used for "selectors with interval"
|
// Hash Element used for "selectors with interval"
|
||||||
typedef struct _hashSelectorEntry
|
typedef struct _hashSelectorEntry
|
||||||
{
|
{
|
||||||
NSMutableArray<CCTimer*> *timers;
|
NSMutableArray<CCTimer*> *timers;
|
||||||
SelectorProtocol *target; // hash key (retained)
|
SelectorProtocol *target; // hash key (retained)
|
||||||
UINT32 timerIndex;
|
unsigned int timerIndex;
|
||||||
CCTimer *currentTimer;
|
CCTimer *currentTimer;
|
||||||
bool currentTimerSalvaged;
|
bool currentTimerSalvaged;
|
||||||
bool paused;
|
bool paused;
|
||||||
UT_hash_handle hh;
|
UT_hash_handle hh;
|
||||||
} tHashSelectorEntry;
|
} tHashSelectorEntry;
|
||||||
|
|
||||||
// implementation CCTimer
|
// implementation CCTimer
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ void CCScheduler::scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *p
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSMutableArray will increase it's capacity automatically
|
// NSMutableArray will increase it's capacity automatically
|
||||||
//else if( element->timers->num == element->timers->max )
|
//else if( element->timers->num == element->timers->max )
|
||||||
//ccArrayDoubleCapacity(element->timers);
|
//ccArrayDoubleCapacity(element->timers);
|
||||||
|
|
||||||
CCTimer *pTimer = new CCTimer();
|
CCTimer *pTimer = new CCTimer();
|
||||||
|
@ -246,7 +246,7 @@ void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol
|
||||||
if (pElement)
|
if (pElement)
|
||||||
{
|
{
|
||||||
NSMutableArray<CCTimer*>::NSMutableArrayIterator iter;
|
NSMutableArray<CCTimer*>::NSMutableArrayIterator iter;
|
||||||
UINT32 i;
|
unsigned int i;
|
||||||
for (iter = pElement->timers->begin(), i = 0; iter != pElement->timers->end(); ++iter, ++i)
|
for (iter = pElement->timers->begin(), i = 0; iter != pElement->timers->end(); ++iter, ++i)
|
||||||
{
|
{
|
||||||
CCTimer *pTimer = *iter;
|
CCTimer *pTimer = *iter;
|
||||||
|
@ -285,7 +285,7 @@ void CCScheduler::unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCScheduler::priorityIn(tListEntry **ppList, SelectorProtocol *pTarget, Int32 nPriority, bool bPaused)
|
void CCScheduler::priorityIn(tListEntry **ppList, SelectorProtocol *pTarget, int nPriority, bool bPaused)
|
||||||
{
|
{
|
||||||
tListEntry *pListElement = (tListEntry *)malloc(sizeof(*pListElement));
|
tListEntry *pListElement = (tListEntry *)malloc(sizeof(*pListElement));
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ void CCScheduler::appendIn(_listEntry **ppList, SelectorProtocol *pTarget, bool
|
||||||
HASH_ADD_INT(m_pHashForUpdates, target, pHashElement);
|
HASH_ADD_INT(m_pHashForUpdates, target, pHashElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCScheduler::scheduleUpdateForTarget(SelectorProtocol *pTarget, INT32 nPriority, bool bPaused)
|
void CCScheduler::scheduleUpdateForTarget(SelectorProtocol *pTarget, int nPriority, bool bPaused)
|
||||||
{
|
{
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tHashUpdateEntry *pHashElement = NULL;
|
tHashUpdateEntry *pHashElement = NULL;
|
||||||
|
@ -360,7 +360,7 @@ void CCScheduler::scheduleUpdateForTarget(SelectorProtocol *pTarget, INT32 nPrio
|
||||||
assert(pHashElement == NULL);
|
assert(pHashElement == NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// most of the updates are going to be 0, that's way there
|
// most of the updates are going to be 0, that's way there
|
||||||
// is an special list for updates with priority 0
|
// is an special list for updates with priority 0
|
||||||
if (nPriority == 0)
|
if (nPriority == 0)
|
||||||
{
|
{
|
||||||
|
@ -560,8 +560,8 @@ void CCScheduler::tick(ccTime dt)
|
||||||
|
|
||||||
if (elt->currentTimerSalvaged)
|
if (elt->currentTimerSalvaged)
|
||||||
{
|
{
|
||||||
// The currentTimer told the remove itself. To prevent the timer from
|
// The currentTimer told the remove itself. To prevent the timer from
|
||||||
// accidentally deallocating itself before finishing its step, we retained
|
// accidentally deallocating itself before finishing its step, we retained
|
||||||
// it. Now that step is done, it's safe to release it.
|
// it. Now that step is done, it's safe to release it.
|
||||||
elt->currentTimer->release();
|
elt->currentTimer->release();
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,7 @@ void CCScheduler::tick(ccTime dt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// elt, at this moment, is still valid
|
// elt, at this moment, is still valid
|
||||||
// so it is safe to ask this here (issue #490)
|
// so it is safe to ask this here (issue #490)
|
||||||
elt = (tHashSelectorEntry *)elt->hh.next;
|
elt = (tHashSelectorEntry *)elt->hh.next;
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,13 @@ THE SOFTWARE.
|
||||||
#ifndef __CCSCHEDULER_H__
|
#ifndef __CCSCHEDULER_H__
|
||||||
#define __CCSCHEDULER_H__
|
#define __CCSCHEDULER_H__
|
||||||
|
|
||||||
#include "platform/platform.h"
|
|
||||||
#include "cocoa/NSObject.h"
|
#include "cocoa/NSObject.h"
|
||||||
#include "cocoa/selector_protocol.h"
|
#include "cocoa/selector_protocol.h"
|
||||||
#include "support/data_support/uthash.h"
|
#include "support/data_support/uthash.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// CCTimer
|
// CCTimer
|
||||||
//
|
//
|
||||||
/** Light weight timer */
|
/** Light weight timer */
|
||||||
class CCTimer : public NSObject
|
class CCTimer : public NSObject
|
||||||
{
|
{
|
||||||
|
@ -68,19 +67,19 @@ protected:
|
||||||
ccTime m_fElapsed;
|
ccTime m_fElapsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// CCScheduler
|
// CCScheduler
|
||||||
//
|
//
|
||||||
/** Scheduler is responsible of triggering the scheduled callbacks.
|
/** Scheduler is responsible of triggering the scheduled callbacks.
|
||||||
You should not use NSTimer. Instead use this class.
|
You should not use NSTimer. Instead use this class.
|
||||||
|
|
||||||
There are 2 different types of callbacks (selectors):
|
There are 2 different types of callbacks (selectors):
|
||||||
|
|
||||||
- update selector: the 'update' selector will be called every frame. You can customize the priority.
|
- update selector: the 'update' selector will be called every frame. You can customize the priority.
|
||||||
- custom selector: A custom selector will be called every frame, or with a custom interval of time
|
- custom selector: A custom selector will be called every frame, or with a custom interval of time
|
||||||
|
|
||||||
The 'custom selectors' should be avoided when possible. It is faster, and consumes less memory to use the 'update selector'.
|
The 'custom selectors' should be avoided when possible. It is faster, and consumes less memory to use the 'update selector'.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct _listEntry;
|
struct _listEntry;
|
||||||
|
@ -92,92 +91,92 @@ class CCScheduler : public NSObject
|
||||||
public:
|
public:
|
||||||
~CCScheduler(void);
|
~CCScheduler(void);
|
||||||
|
|
||||||
/** Modifies the time of all scheduled callbacks.
|
/** Modifies the time of all scheduled callbacks.
|
||||||
You can use this property to create a 'slow motion' or 'fast fordward' effect.
|
You can use this property to create a 'slow motion' or 'fast fordward' effect.
|
||||||
Default is 1.0. To create a 'slow motion' effect, use values below 1.0.
|
Default is 1.0. To create a 'slow motion' effect, use values below 1.0.
|
||||||
To create a 'fast fordward' effect, use values higher than 1.0.
|
To create a 'fast fordward' effect, use values higher than 1.0.
|
||||||
@since v0.8
|
@since v0.8
|
||||||
@warning It will affect EVERY scheduled selector / action.
|
@warning It will affect EVERY scheduled selector / action.
|
||||||
*/
|
*/
|
||||||
ccTime getTimeScale(void);
|
ccTime getTimeScale(void);
|
||||||
void setTimeScale(ccTime fTimeScale);
|
void setTimeScale(ccTime fTimeScale);
|
||||||
|
|
||||||
/** 'tick' the scheduler.
|
/** 'tick' the scheduler.
|
||||||
You should NEVER call this method, unless you know what you are doing.
|
You should NEVER call this method, unless you know what you are doing.
|
||||||
*/
|
*/
|
||||||
void tick(ccTime dt);
|
void tick(ccTime dt);
|
||||||
|
|
||||||
/** The scheduled method will be called every 'interval' seconds.
|
/** The scheduled method will be called every 'interval' seconds.
|
||||||
If paused is YES, then it won't be called until it is resumed.
|
If paused is YES, then it won't be called until it is resumed.
|
||||||
If 'interval' is 0, it will be called every frame, but if so, it recommened to use 'scheduleUpdateForTarget:' instead.
|
If 'interval' is 0, it will be called every frame, but if so, it recommened to use 'scheduleUpdateForTarget:' instead.
|
||||||
|
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
void scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *pTarget, float fInterval, bool bPaused);
|
void scheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *pTarget, float fInterval, bool bPaused);
|
||||||
|
|
||||||
/** Schedules the 'update' selector for a given target with a given priority.
|
/** Schedules the 'update' selector for a given target with a given priority.
|
||||||
The 'update' selector will be called every frame.
|
The 'update' selector will be called every frame.
|
||||||
The lower the priority, the earlier it is called.
|
The lower the priority, the earlier it is called.
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
void scheduleUpdateForTarget(SelectorProtocol *pTarget, INT32 nPriority, bool bPaused);
|
void scheduleUpdateForTarget(SelectorProtocol *pTarget, int nPriority, bool bPaused);
|
||||||
|
|
||||||
/** Unshedules a selector for a given target.
|
/** Unshedules a selector for a given target.
|
||||||
If you want to unschedule the "update", use unscheudleUpdateForTarget.
|
If you want to unschedule the "update", use unscheudleUpdateForTarget.
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
void unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *pTarget);
|
void unscheduleSelector(SEL_SCHEDULE pfnSelector, SelectorProtocol *pTarget);
|
||||||
|
|
||||||
/** Unschedules the update selector for a given target
|
/** Unschedules the update selector for a given target
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
void unscheduleUpdateForTarget(SelectorProtocol *pTarget);
|
void unscheduleUpdateForTarget(SelectorProtocol *pTarget);
|
||||||
|
|
||||||
/** Unschedules all selectors for a given target.
|
/** Unschedules all selectors for a given target.
|
||||||
This also includes the "update" selector.
|
This also includes the "update" selector.
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
void unscheduleAllSelectorsForTarget(SelectorProtocol *pTarget);
|
void unscheduleAllSelectorsForTarget(SelectorProtocol *pTarget);
|
||||||
|
|
||||||
/** Unschedules all selectors from all targets.
|
/** Unschedules all selectors from all targets.
|
||||||
You should NEVER call this method, unless you know what you are doing.
|
You should NEVER call this method, unless you know what you are doing.
|
||||||
|
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
void unscheduleAllSelectors(void);
|
void unscheduleAllSelectors(void);
|
||||||
|
|
||||||
/** Pauses the target.
|
/** Pauses the target.
|
||||||
All scheduled selectors/update for a given target won't be 'ticked' until the target is resumed.
|
All scheduled selectors/update for a given target won't be 'ticked' until the target is resumed.
|
||||||
If the target is not present, nothing happens.
|
If the target is not present, nothing happens.
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
void pauseTarget(SelectorProtocol *pTarget);
|
void pauseTarget(SelectorProtocol *pTarget);
|
||||||
|
|
||||||
/** Resumes the target.
|
/** Resumes the target.
|
||||||
The 'target' will be unpaused, so all schedule selectors/update will be 'ticked' again.
|
The 'target' will be unpaused, so all schedule selectors/update will be 'ticked' again.
|
||||||
If the target is not present, nothing happens.
|
If the target is not present, nothing happens.
|
||||||
@since v0.99.3
|
@since v0.99.3
|
||||||
*/
|
*/
|
||||||
void resumeTarget(SelectorProtocol *pTarget);
|
void resumeTarget(SelectorProtocol *pTarget);
|
||||||
|
|
||||||
/** schedules a Timer.
|
/** schedules a Timer.
|
||||||
It will be fired in every frame.
|
It will be fired in every frame.
|
||||||
|
|
||||||
@deprecated Use scheduleSelector:forTarget:interval:paused instead. Will be removed in 1.0
|
@deprecated Use scheduleSelector:forTarget:interval:paused instead. Will be removed in 1.0
|
||||||
*/
|
*/
|
||||||
void scheduleTimer(CCTimer *pTimer);
|
void scheduleTimer(CCTimer *pTimer);
|
||||||
|
|
||||||
/** unschedules an already scheduled Timer
|
/** unschedules an already scheduled Timer
|
||||||
|
|
||||||
@deprecated Use unscheduleSelector:forTarget. Will be removed in v1.0
|
@deprecated Use unscheduleSelector:forTarget. Will be removed in v1.0
|
||||||
*/
|
*/
|
||||||
void unscheduleTimer(CCTimer *pTimer);
|
void unscheduleTimer(CCTimer *pTimer);
|
||||||
|
|
||||||
/** unschedule all timers.
|
/** unschedule all timers.
|
||||||
You should NEVER call this method, unless you know what you are doing.
|
You should NEVER call this method, unless you know what you are doing.
|
||||||
|
|
||||||
@deprecated Use scheduleAllSelectors instead. Will be removed in 1.0
|
@deprecated Use scheduleAllSelectors instead. Will be removed in 1.0
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
void unscheduleAllTimers(void);
|
void unscheduleAllTimers(void);
|
||||||
|
|
||||||
|
@ -185,8 +184,8 @@ public:
|
||||||
// returns a shared instance of the Scheduler
|
// returns a shared instance of the Scheduler
|
||||||
static CCScheduler* getSharedScheduler(void);
|
static CCScheduler* getSharedScheduler(void);
|
||||||
|
|
||||||
/** purges the shared scheduler. It releases the retained instance.
|
/** purges the shared scheduler. It releases the retained instance.
|
||||||
@since v0.99.0
|
@since v0.99.0
|
||||||
*/
|
*/
|
||||||
static void purgeSharedScheduler(void);
|
static void purgeSharedScheduler(void);
|
||||||
|
|
||||||
|
@ -197,14 +196,14 @@ private:
|
||||||
|
|
||||||
// update specific
|
// update specific
|
||||||
|
|
||||||
void priorityIn(struct _listEntry **ppList, SelectorProtocol *pTarget, INT32 nPriority, bool bPaused);
|
void priorityIn(struct _listEntry **ppList, SelectorProtocol *pTarget, int nPriority, bool bPaused);
|
||||||
void appendIn(struct _listEntry **ppList, SelectorProtocol *pTarget, bool bPaused);
|
void appendIn(struct _listEntry **ppList, SelectorProtocol *pTarget, bool bPaused);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ccTime m_fTimeScale;
|
ccTime m_fTimeScale;
|
||||||
|
|
||||||
//
|
//
|
||||||
// "updates with priority" stuff
|
// "updates with priority" stuff
|
||||||
//
|
//
|
||||||
struct _listEntry *m_pUpdatesNegList; // list of priority < 0
|
struct _listEntry *m_pUpdatesNegList; // list of priority < 0
|
||||||
struct _listEntry *m_pUpdates0List; // list priority == 0
|
struct _listEntry *m_pUpdates0List; // list priority == 0
|
||||||
|
|
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "NSObject.h"
|
#include "NSObject.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "platform/platform.h"
|
||||||
|
|
||||||
class NSData : public NSObject
|
class NSData : public NSObject
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,7 +26,6 @@ THE SOFTWARE.
|
||||||
#define __COCOA_NS_MUTATLE_ARRAY_H__
|
#define __COCOA_NS_MUTATLE_ARRAY_H__
|
||||||
|
|
||||||
#include "cocoa/NSObject.h"
|
#include "cocoa/NSObject.h"
|
||||||
#include "platform/platform.h"
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ public:
|
||||||
typedef typename NSObjectArray::reverse_iterator NSMutableArrayRevIterator;
|
typedef typename NSObjectArray::reverse_iterator NSMutableArrayRevIterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NSMutableArray(UINT uSize = 0)
|
NSMutableArray(unsigned int uSize = 0)
|
||||||
{
|
{
|
||||||
m_array.resize(uSize);
|
m_array.resize(uSize);
|
||||||
}
|
}
|
||||||
|
@ -50,12 +49,12 @@ public:
|
||||||
removeAllObjects();
|
removeAllObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT32 count(void)
|
unsigned int count(void)
|
||||||
{
|
{
|
||||||
return m_array.size();
|
return m_array.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT32 getIndexOfObject(T pObject)
|
unsigned int getIndexOfObject(T pObject)
|
||||||
{
|
{
|
||||||
if (m_array.empty() || (pObject == NULL))
|
if (m_array.empty() || (pObject == NULL))
|
||||||
{
|
{
|
||||||
|
@ -63,8 +62,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray<T>::NSMutableArrayIterator iter;
|
NSMutableArray<T>::NSMutableArrayIterator iter;
|
||||||
UINT32 uRet = 0;
|
unsigned int uRet = 0;
|
||||||
INT32 i;
|
int i;
|
||||||
for (iter = m_array.begin(), i = 0; iter != m_array.end(); ++iter, ++i)
|
for (iter = m_array.begin(), i = 0; iter != m_array.end(); ++iter, ++i)
|
||||||
{
|
{
|
||||||
if (*iter == pObject)
|
if (*iter == pObject)
|
||||||
|
@ -101,7 +100,7 @@ public:
|
||||||
T getLastObject(void)
|
T getLastObject(void)
|
||||||
{
|
{
|
||||||
T pObject = NULL;
|
T pObject = NULL;
|
||||||
INT32 count = this->count();
|
int count = this->count();
|
||||||
|
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
|
@ -111,7 +110,7 @@ public:
|
||||||
return pObject;
|
return pObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
T getObjectAtIndex(UINT32 uIndex)
|
T getObjectAtIndex(unsigned int uIndex)
|
||||||
{
|
{
|
||||||
assert(uIndex < count());
|
assert(uIndex < count());
|
||||||
|
|
||||||
|
@ -154,7 +153,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertObjectAtIndex(T pObject, UINT32 uIndex)
|
void insertObjectAtIndex(T pObject, unsigned int uIndex)
|
||||||
{
|
{
|
||||||
// make sure the object is not null
|
// make sure the object is not null
|
||||||
if (pObject == NULL)
|
if (pObject == NULL)
|
||||||
|
@ -172,7 +171,7 @@ public:
|
||||||
// Removing objects
|
// Removing objects
|
||||||
void removeLastObject(void)
|
void removeLastObject(void)
|
||||||
{
|
{
|
||||||
INT32 count = this->count();
|
int count = this->count();
|
||||||
|
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
|
@ -202,7 +201,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeObjectAtIndex(UINT32 uIndex)
|
void removeObjectAtIndex(unsigned int uIndex)
|
||||||
{
|
{
|
||||||
if (m_array.empty() || uIndex == 0)
|
if (m_array.empty() || uIndex == 0)
|
||||||
{
|
{
|
||||||
|
@ -232,7 +231,7 @@ public:
|
||||||
m_array.clear();
|
m_array.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void replaceObjectAtIndex(UINT32 uIndex, T pObject)
|
void replaceObjectAtIndex(unsigned int uIndex, T pObject)
|
||||||
{
|
{
|
||||||
if (uIndex >= count())
|
if (uIndex >= count())
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
/* cocos2d for windows
|
/* cocos2d for windows
|
||||||
*
|
*
|
||||||
* http://cocos2d-win.blogspot.com
|
* http://cocos2d-win.blogspot.com
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010 KOO C.H
|
* Copyright (C) 2010 KOO C.H
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the 'cocos2d for windows' license.
|
* it under the terms of the 'cocos2d for windows' license.
|
||||||
*
|
*
|
||||||
* You will find a copy of this license within the cocos2d for windows
|
* You will find a copy of this license within the cocos2d for windows
|
||||||
* distribution inside the "LICENSE" file.
|
* distribution inside the "LICENSE" file.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef __CCMUTABLE_DICTIONARY_H__
|
#ifndef __CCMUTABLE_DICTIONARY_H__
|
||||||
#define __CCMUTABLE_DICTIONARY_H__
|
#define __CCMUTABLE_DICTIONARY_H__
|
||||||
|
@ -46,7 +46,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return the number of items
|
/// return the number of items
|
||||||
UINT32 count()
|
unsigned int count()
|
||||||
{
|
{
|
||||||
return m_Map.size();
|
return m_Map.size();
|
||||||
}
|
}
|
||||||
|
@ -70,8 +70,8 @@ public:
|
||||||
NSObjectMapIter it;
|
NSObjectMapIter it;
|
||||||
for( it= m_Map.begin(); it != m_Map.end(); ++it)
|
for( it= m_Map.begin(); it != m_Map.end(); ++it)
|
||||||
{
|
{
|
||||||
if (it->second == object)
|
if (it->second == object)
|
||||||
{
|
{
|
||||||
tRet.push_back(it->first);
|
tRet.push_back(it->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ NSObject* CCCopying::copyWithZone(NSZone *pZone)
|
||||||
|
|
||||||
NSObject::NSObject(void)
|
NSObject::NSObject(void)
|
||||||
{
|
{
|
||||||
static UINT uObjectCount = 0;
|
static unsigned int uObjectCount = 0;
|
||||||
|
|
||||||
m_uID = ++uObjectCount;
|
m_uID = ++uObjectCount;
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ bool NSObject::isSingleRefrence(void)
|
||||||
return m_uRefrence == 1;
|
return m_uRefrence == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT32 NSObject::retainCount(void)
|
unsigned int NSObject::retainCount(void)
|
||||||
{
|
{
|
||||||
return m_uRefrence;
|
return m_uRefrence;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ THE SOFTWARE.
|
||||||
#ifndef __COCOA_NSOBJECT_H__
|
#ifndef __COCOA_NSOBJECT_H__
|
||||||
#define __COCOA_NSOBJECT_H__
|
#define __COCOA_NSOBJECT_H__
|
||||||
|
|
||||||
#include "platform/platform.h"
|
|
||||||
class NSZone;
|
class NSZone;
|
||||||
class NSObject;
|
class NSObject;
|
||||||
class NSString;
|
class NSString;
|
||||||
|
@ -40,9 +39,9 @@ class NSObject : public CCCopying
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
// object id
|
// object id
|
||||||
UINT32 m_uID;
|
unsigned int m_uID;
|
||||||
// count of refrence
|
// count of refrence
|
||||||
UINT32 m_uRefrence;
|
unsigned int m_uRefrence;
|
||||||
// is the object autoreleased
|
// is the object autoreleased
|
||||||
bool m_bManaged;
|
bool m_bManaged;
|
||||||
public:
|
public:
|
||||||
|
@ -54,7 +53,7 @@ public:
|
||||||
NSObject* autorelease(void);
|
NSObject* autorelease(void);
|
||||||
NSObject* copy(void);
|
NSObject* copy(void);
|
||||||
bool isSingleRefrence(void);
|
bool isSingleRefrence(void);
|
||||||
UINT32 retainCount(void);
|
unsigned int retainCount(void);
|
||||||
bool isEqual(const NSObject* pObject);
|
bool isEqual(const NSObject* pObject);
|
||||||
|
|
||||||
friend class NSAutoreleasePool;
|
friend class NSAutoreleasePool;
|
||||||
|
|
|
@ -24,7 +24,6 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#ifndef __NS_ZONE_H__
|
#ifndef __NS_ZONE_H__
|
||||||
#define __NS_ZONE_H__
|
#define __NS_ZONE_H__
|
||||||
|
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
|
|
||||||
class NSObject;
|
class NSObject;
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_bActive;
|
bool m_bActive;
|
||||||
INT32 m_nReuseGrid;
|
int m_nReuseGrid;
|
||||||
ccGridSize m_obGridSize;
|
ccGridSize m_obGridSize;
|
||||||
CCTexture2D *m_pobTexture;
|
CCTexture2D *m_pobTexture;
|
||||||
CGPoint m_obStep;
|
CGPoint m_obStep;
|
||||||
|
|
|
@ -28,7 +28,6 @@ THE SOFTWARE.
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "cocoa/NSObject.h"
|
#include "cocoa/NSObject.h"
|
||||||
#include "cocoa/NSZone.h"
|
#include "cocoa/NSZone.h"
|
||||||
#include "platform/platform.h"
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
//! Default tag
|
//! Default tag
|
||||||
|
@ -82,8 +81,8 @@ public:
|
||||||
NSObject* getOriginalTarget(void);
|
NSObject* getOriginalTarget(void);
|
||||||
|
|
||||||
// The action tag. An identifier of the action
|
// The action tag. An identifier of the action
|
||||||
INT32 getTag(void);
|
int getTag(void);
|
||||||
void setTag(INT32 nTag);
|
void setTag(int nTag);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Allocates and initializes the action
|
// Allocates and initializes the action
|
||||||
|
@ -92,7 +91,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
NSObject *m_pOriginalTarget;
|
NSObject *m_pOriginalTarget;
|
||||||
NSObject *m_pTarget;
|
NSObject *m_pTarget;
|
||||||
INT32 m_nTag;
|
int m_nTag;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Base class actions that do have a finite time duration.
|
/** Base class actions that do have a finite time duration.
|
||||||
|
|
|
@ -42,50 +42,50 @@ class CGSize;
|
||||||
class CCTexture2D;
|
class CCTexture2D;
|
||||||
struct transformValues_;
|
struct transformValues_;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
/// CCSprite invalid index on the CCSpriteSheet
|
/// CCSprite invalid index on the CCSpriteSheet
|
||||||
CCSpriteIndexNotInitialized = 0xffffffff,
|
CCSpriteIndexNotInitialized = 0xffffffff,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Whether or not an CCSprite will rotate, scale or translate with it's parent.
|
Whether or not an CCSprite will rotate, scale or translate with it's parent.
|
||||||
Useful in health bars, when you want that the health bar translates with it's parent but you don't
|
Useful in health bars, when you want that the health bar translates with it's parent but you don't
|
||||||
want it to rotate with its parent.
|
want it to rotate with its parent.
|
||||||
@since v0.99.0
|
@since v0.99.0
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
//! Translate with it's parent
|
//! Translate with it's parent
|
||||||
CC_HONOR_PARENT_TRANSFORM_TRANSLATE = 1 << 0,
|
CC_HONOR_PARENT_TRANSFORM_TRANSLATE = 1 << 0,
|
||||||
//! Rotate with it's parent
|
//! Rotate with it's parent
|
||||||
CC_HONOR_PARENT_TRANSFORM_ROTATE = 1 << 1,
|
CC_HONOR_PARENT_TRANSFORM_ROTATE = 1 << 1,
|
||||||
//! Scale with it's parent
|
//! Scale with it's parent
|
||||||
CC_HONOR_PARENT_TRANSFORM_SCALE = 1 << 2,
|
CC_HONOR_PARENT_TRANSFORM_SCALE = 1 << 2,
|
||||||
|
|
||||||
//! All possible transformation enabled. Default value.
|
//! All possible transformation enabled. Default value.
|
||||||
CC_HONOR_PARENT_TRANSFORM_ALL = CC_HONOR_PARENT_TRANSFORM_TRANSLATE | CC_HONOR_PARENT_TRANSFORM_ROTATE | CC_HONOR_PARENT_TRANSFORM_SCALE,
|
CC_HONOR_PARENT_TRANSFORM_ALL = CC_HONOR_PARENT_TRANSFORM_TRANSLATE | CC_HONOR_PARENT_TRANSFORM_ROTATE | CC_HONOR_PARENT_TRANSFORM_SCALE,
|
||||||
|
|
||||||
} ccHonorParentTransform;
|
} ccHonorParentTransform;
|
||||||
|
|
||||||
/** CCSprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
|
/** CCSprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
|
||||||
*
|
*
|
||||||
* CCSprite can be created with an image, or with a sub-rectangle of an image.
|
* CCSprite can be created with an image, or with a sub-rectangle of an image.
|
||||||
*
|
*
|
||||||
* If the parent or any of its ancestors is a CCSpriteSheet then the following features/limitations are valid
|
* If the parent or any of its ancestors is a CCSpriteSheet then the following features/limitations are valid
|
||||||
* - Features when the parent is a CCSpriteSheet:
|
* - Features when the parent is a CCSpriteSheet:
|
||||||
* - MUCH faster rendering, specially if the CCSpriteSheet has many children. All the children will be drawn in a single batch.
|
* - MUCH faster rendering, specially if the CCSpriteSheet has many children. All the children will be drawn in a single batch.
|
||||||
*
|
*
|
||||||
* - Limitations
|
* - Limitations
|
||||||
* - Camera is not supported yet (eg: CCOrbitCamera action doesn't work)
|
* - Camera is not supported yet (eg: CCOrbitCamera action doesn't work)
|
||||||
* - GridBase actions are not supported (eg: CCLens, CCRipple, CCTwirl)
|
* - GridBase actions are not supported (eg: CCLens, CCRipple, CCTwirl)
|
||||||
* - The Alias/Antialias property belongs to CCSpriteSheet, so you can't individually set the aliased property.
|
* - The Alias/Antialias property belongs to CCSpriteSheet, so you can't individually set the aliased property.
|
||||||
* - The Blending function property belongs to CCSpriteSheet, so you can't individually set the blending function property.
|
* - The Blending function property belongs to CCSpriteSheet, so you can't individually set the blending function property.
|
||||||
* - Parallax scroller is not supported, but can be simulated with a "proxy" sprite.
|
* - Parallax scroller is not supported, but can be simulated with a "proxy" sprite.
|
||||||
*
|
*
|
||||||
* If the parent is an standard CCNode, then CCSprite behaves like any other CCNode:
|
* If the parent is an standard CCNode, then CCSprite behaves like any other CCNode:
|
||||||
* - It supports blending functions
|
* - It supports blending functions
|
||||||
* - It supports aliasing / antialiasing
|
* - It supports aliasing / antialiasing
|
||||||
* - But the rendering will be slower: 1 draw per children.
|
* - But the rendering will be slower: 1 draw per children.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class CCSprite : public CCNode, public CCRGBAProtocol, public CCTextureProtocol
|
class CCSprite : public CCNode, public CCRGBAProtocol, public CCTextureProtocol
|
||||||
{
|
{
|
||||||
|
@ -103,8 +103,8 @@ public:
|
||||||
inline ccV3F_C4B_T2F_Quad getQuad(void) { return m_sQuad; }
|
inline ccV3F_C4B_T2F_Quad getQuad(void) { return m_sQuad; }
|
||||||
|
|
||||||
// The index used on the TextureATlas. Don't modify this value unless you know what you are doing
|
// The index used on the TextureATlas. Don't modify this value unless you know what you are doing
|
||||||
inline UINT32 getAtlasIndex(void) { return m_uAtlasIndex; }
|
inline unsigned int getAtlasIndex(void) { return m_uAtlasIndex; }
|
||||||
inline void setAtlasIndex(UINT32 uAtlasIndex) { m_uAtlasIndex = uAtlasIndex; }
|
inline void setAtlasIndex(unsigned int uAtlasIndex) { m_uAtlasIndex = uAtlasIndex; }
|
||||||
|
|
||||||
// returns the rect of the CCSprite
|
// returns the rect of the CCSprite
|
||||||
inline CGRect getTextureRect(void) { return m_obRect; }
|
inline CGRect getTextureRect(void) { return m_obRect; }
|
||||||
|
@ -121,16 +121,16 @@ public:
|
||||||
inline CCSpriteSheet* getSpriteSheet(void) { return m_pobSpriteSheet; }
|
inline CCSpriteSheet* getSpriteSheet(void) { return m_pobSpriteSheet; }
|
||||||
inline void setSpriteSheet(CCSpriteSheet *pobSpriteSheet) { m_pobSpriteSheet = pobSpriteSheet; }
|
inline void setSpriteSheet(CCSpriteSheet *pobSpriteSheet) { m_pobSpriteSheet = pobSpriteSheet; }
|
||||||
|
|
||||||
/** whether or not to transform according to its parent transfomrations.
|
/** whether or not to transform according to its parent transfomrations.
|
||||||
Useful for health bars. eg: Don't rotate the health bar, even if the parent rotates.
|
Useful for health bars. eg: Don't rotate the health bar, even if the parent rotates.
|
||||||
IMPORTANT: Only valid if it is rendered using an CCSpriteSheet.
|
IMPORTANT: Only valid if it is rendered using an CCSpriteSheet.
|
||||||
@since v0.99.0
|
@since v0.99.0
|
||||||
*/
|
*/
|
||||||
inline ccHonorParentTransform getHornorParentTransform(void) { return m_eHonorParentTransform; }
|
inline ccHonorParentTransform getHornorParentTransform(void) { return m_eHonorParentTransform; }
|
||||||
inline void setHornorParentTransform(ccHonorParentTransform eHonorParentTransform) { m_eHonorParentTransform = eHonorParentTransform; }
|
inline void setHornorParentTransform(ccHonorParentTransform eHonorParentTransform) { m_eHonorParentTransform = eHonorParentTransform; }
|
||||||
|
|
||||||
/** offset position of the sprite. Calculated automatically by editors like Zwoptex.
|
/** offset position of the sprite. Calculated automatically by editors like Zwoptex.
|
||||||
@since v0.99.0
|
@since v0.99.0
|
||||||
*/
|
*/
|
||||||
inline CGPoint getOffsetPosition(void) { return m_obOffsetPosition; }
|
inline CGPoint getOffsetPosition(void) { return m_obOffsetPosition; }
|
||||||
inline void setSffsetPosition(CGPoint obOffsetPosition) { m_obOffsetPosition = obOffsetPosition; }
|
inline void setSffsetPosition(CGPoint obOffsetPosition) { m_obOffsetPosition = obOffsetPosition; }
|
||||||
|
@ -140,14 +140,14 @@ public:
|
||||||
inline void setBlendFunc(ccBlendFunc blendFunc) { m_sBlendFunc = blendFunc; }
|
inline void setBlendFunc(ccBlendFunc blendFunc) { m_sBlendFunc = blendFunc; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Creates an sprite with a texture.
|
/** Creates an sprite with a texture.
|
||||||
The rect used will be the size of the texture.
|
The rect used will be the size of the texture.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
static CCSprite* spriteWithTexture(CCTexture2D *pTexture);
|
static CCSprite* spriteWithTexture(CCTexture2D *pTexture);
|
||||||
|
|
||||||
/** Creates an sprite with a texture and a rect.
|
/** Creates an sprite with a texture and a rect.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
static CCSprite* spriteWithTexture(CCTexture2D *pTexture, CGRect rect);
|
static CCSprite* spriteWithTexture(CCTexture2D *pTexture, CGRect rect);
|
||||||
|
|
||||||
|
@ -157,34 +157,34 @@ public:
|
||||||
// Creates an sprite with an sprite frame.
|
// Creates an sprite with an sprite frame.
|
||||||
static CCSprite* spriteWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
static CCSprite* spriteWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
||||||
|
|
||||||
/** Creates an sprite with an sprite frame name.
|
/** Creates an sprite with an sprite frame name.
|
||||||
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
|
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
|
||||||
If the CCSpriteFrame doesn't exist it will raise an exception.
|
If the CCSpriteFrame doesn't exist it will raise an exception.
|
||||||
@since v0.9
|
@since v0.9
|
||||||
*/
|
*/
|
||||||
static CCSprite* spriteWithSpriteFrameName(const char *pszSpriteFrameName);
|
static CCSprite* spriteWithSpriteFrameName(const char *pszSpriteFrameName);
|
||||||
|
|
||||||
/** Creates an sprite with an image filename.
|
/** Creates an sprite with an image filename.
|
||||||
The rect used will be the size of the image.
|
The rect used will be the size of the image.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
static CCSprite* spriteWithFile(const char *pszFileName);
|
static CCSprite* spriteWithFile(const char *pszFileName);
|
||||||
|
|
||||||
/** Creates an sprite with an image filename and a rect.
|
/** Creates an sprite with an image filename and a rect.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
static CCSprite* spriteWithFile(const char *pszFileName, CGRect rect);
|
static CCSprite* spriteWithFile(const char *pszFileName, CGRect rect);
|
||||||
|
|
||||||
/** Creates an sprite with a CGImageRef.
|
/** Creates an sprite with a CGImageRef.
|
||||||
@deprecated Use spriteWithCGImage:key: instead. Will be removed in v1.0 final
|
@deprecated Use spriteWithCGImage:key: instead. Will be removed in v1.0 final
|
||||||
*/
|
*/
|
||||||
// static CCSprite* spriteWithCGImage(CGImageRef pImage);
|
// static CCSprite* spriteWithCGImage(CGImageRef pImage);
|
||||||
|
|
||||||
/** Creates an sprite with a CGImageRef and a key.
|
/** Creates an sprite with a CGImageRef and a key.
|
||||||
The key is used by the CCTextureCache to know if a texture was already created with this CGImage.
|
The key is used by the CCTextureCache to know if a texture was already created with this CGImage.
|
||||||
For example, a valid key is: @"sprite_frame_01".
|
For example, a valid key is: @"sprite_frame_01".
|
||||||
If key is nil, then a new texture will be created each time by the CCTextureCache.
|
If key is nil, then a new texture will be created each time by the CCTextureCache.
|
||||||
@since v0.99.0
|
@since v0.99.0
|
||||||
*/
|
*/
|
||||||
// static CCSprite* spriteWithCGImage(CGImageRef pImage, const char *pszKey);
|
// static CCSprite* spriteWithCGImage(CGImageRef pImage, const char *pszKey);
|
||||||
|
|
||||||
|
@ -201,10 +201,10 @@ public:
|
||||||
|
|
||||||
virtual void removeChild(CCNode* pChild, bool bCleanup);
|
virtual void removeChild(CCNode* pChild, bool bCleanup);
|
||||||
virtual void removeAllChildrenWithCleanup(bool bCleanup);
|
virtual void removeAllChildrenWithCleanup(bool bCleanup);
|
||||||
virtual void reorderChild(CCNode *pChild, INT32 zOrder);
|
virtual void reorderChild(CCNode *pChild, int zOrder);
|
||||||
virtual CCNode* addChild(CCNode *pChild);
|
virtual CCNode* addChild(CCNode *pChild);
|
||||||
virtual CCNode* addChild(CCNode *pChild, INT32 zOrder);
|
virtual CCNode* addChild(CCNode *pChild, int zOrder);
|
||||||
virtual CCNode* addChild(CCNode *pChild, INT32 zOrder, INT32 tag);
|
virtual CCNode* addChild(CCNode *pChild, int zOrder, int tag);
|
||||||
|
|
||||||
virtual void setDirtyRecursively(bool bValue);
|
virtual void setDirtyRecursively(bool bValue);
|
||||||
virtual void setPosition(CGPoint pos);
|
virtual void setPosition(CGPoint pos);
|
||||||
|
@ -234,48 +234,48 @@ public:
|
||||||
virtual void setTexture(CCTexture2D *texture);
|
virtual void setTexture(CCTexture2D *texture);
|
||||||
virtual CCTexture2D* getTexture(void);
|
virtual CCTexture2D* getTexture(void);
|
||||||
|
|
||||||
/** Initializes an sprite with a texture.
|
/** Initializes an sprite with a texture.
|
||||||
The rect used will be the size of the texture.
|
The rect used will be the size of the texture.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
CCSprite* initWithTexture(CCTexture2D *pTexture);
|
CCSprite* initWithTexture(CCTexture2D *pTexture);
|
||||||
|
|
||||||
/** Initializes an sprite with a texture and a rect.
|
/** Initializes an sprite with a texture and a rect.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
CCSprite* initWithTexture(CCTexture2D *pTexture, CGRect rect);
|
CCSprite* initWithTexture(CCTexture2D *pTexture, CGRect rect);
|
||||||
|
|
||||||
// Initializes an sprite with an sprite frame.
|
// Initializes an sprite with an sprite frame.
|
||||||
CCSprite* initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
CCSprite* initWithSpriteFrame(CCSpriteFrame *pSpriteFrame);
|
||||||
|
|
||||||
/** Initializes an sprite with an sprite frame name.
|
/** Initializes an sprite with an sprite frame name.
|
||||||
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
|
An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name.
|
||||||
If the CCSpriteFrame doesn't exist it will raise an exception.
|
If the CCSpriteFrame doesn't exist it will raise an exception.
|
||||||
@since v0.9
|
@since v0.9
|
||||||
*/
|
*/
|
||||||
CCSprite* initWithSpriteFrameName(const char *pszSpriteFrameName);
|
CCSprite* initWithSpriteFrameName(const char *pszSpriteFrameName);
|
||||||
|
|
||||||
/** Initializes an sprite with an image filename.
|
/** Initializes an sprite with an image filename.
|
||||||
The rect used will be the size of the image.
|
The rect used will be the size of the image.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
CCSprite* initWithFile(const char *pszFilename);
|
CCSprite* initWithFile(const char *pszFilename);
|
||||||
|
|
||||||
/** Initializes an sprite with an image filename, and a rect.
|
/** Initializes an sprite with an image filename, and a rect.
|
||||||
The offset will be (0,0).
|
The offset will be (0,0).
|
||||||
*/
|
*/
|
||||||
CCSprite* initWithFile(const char *pszFilename, CGRect rect);
|
CCSprite* initWithFile(const char *pszFilename, CGRect rect);
|
||||||
|
|
||||||
/** Initializes an sprite with a CGImageRef
|
/** Initializes an sprite with a CGImageRef
|
||||||
@deprecated Use spriteWithCGImage:key: instead. Will be removed in v1.0 final
|
@deprecated Use spriteWithCGImage:key: instead. Will be removed in v1.0 final
|
||||||
*/
|
*/
|
||||||
// CCSprite* initWithCGImage(CGImageRef pImage);
|
// CCSprite* initWithCGImage(CGImageRef pImage);
|
||||||
|
|
||||||
/** Initializes an sprite with a CGImageRef and a key
|
/** Initializes an sprite with a CGImageRef and a key
|
||||||
The key is used by the CCTextureCache to know if a texture was already created with this CGImage.
|
The key is used by the CCTextureCache to know if a texture was already created with this CGImage.
|
||||||
For example, a valid key is: @"sprite_frame_01".
|
For example, a valid key is: @"sprite_frame_01".
|
||||||
If key is nil, then a new texture will be created each time by the CCTextureCache.
|
If key is nil, then a new texture will be created each time by the CCTextureCache.
|
||||||
@since v0.99.0
|
@since v0.99.0
|
||||||
*/
|
*/
|
||||||
// CCSprite* initWithCGImage(CGImageRef pImage, const char *pszKey);
|
// CCSprite* initWithCGImage(CGImageRef pImage, const char *pszKey);
|
||||||
|
|
||||||
|
@ -287,16 +287,16 @@ public:
|
||||||
// updates the quad according the the rotation, position, scale values.
|
// updates the quad according the the rotation, position, scale values.
|
||||||
void updateTransform(void);
|
void updateTransform(void);
|
||||||
|
|
||||||
/** tell the sprite to use self-render.
|
/** tell the sprite to use self-render.
|
||||||
@since v0.99.0
|
@since v0.99.0
|
||||||
*/
|
*/
|
||||||
void useSelfRender(void);
|
void useSelfRender(void);
|
||||||
|
|
||||||
// updates the texture rect of the CCSprite.
|
// updates the texture rect of the CCSprite.
|
||||||
void setTextureRect(CGRect rect);
|
void setTextureRect(CGRect rect);
|
||||||
|
|
||||||
/** tell the sprite to use sprite sheet render.
|
/** tell the sprite to use sprite sheet render.
|
||||||
@since v0.99.0
|
@since v0.99.0
|
||||||
*/
|
*/
|
||||||
void useSpriteSheetRender(CCSpriteSheet *pSpriteSheet);
|
void useSpriteSheetRender(CCSpriteSheet *pSpriteSheet);
|
||||||
|
|
||||||
|
@ -320,16 +320,16 @@ public:
|
||||||
// Animation
|
// Animation
|
||||||
|
|
||||||
// changes the display frame based on an animation and an index.
|
// changes the display frame based on an animation and an index.
|
||||||
void setDisplayFrame(const char *pszAnimationName, INT32 nFrameIndex);
|
void setDisplayFrame(const char *pszAnimationName, int nFrameIndex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*
|
/*
|
||||||
@interface CCSprite (Private)
|
@interface CCSprite (Private)
|
||||||
-(void)updateTextureCoords:(CGRect)rect;
|
-(void)updateTextureCoords:(CGRect)rect;
|
||||||
-(void)updateBlendFunc;
|
-(void)updateBlendFunc;
|
||||||
-(void) initAnimationDictionary;
|
-(void) initAnimationDictionary;
|
||||||
-(void) setTextureRect:(CGRect)rect untrimmedSize:(CGSize)size;
|
-(void) setTextureRect:(CGRect)rect untrimmedSize:(CGSize)size;
|
||||||
-(struct transformValues_) getTransformValues; // optimization
|
-(struct transformValues_) getTransformValues; // optimization
|
||||||
@end
|
@end
|
||||||
*/
|
*/
|
||||||
void updateTextureCoords(CGRect rect);
|
void updateTextureCoords(CGRect rect);
|
||||||
|
@ -339,25 +339,25 @@ protected:
|
||||||
struct transformValues_ getTransformValues(void);
|
struct transformValues_ getTransformValues(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//
|
//
|
||||||
// Data used when the sprite is rendered using a CCSpriteSheet
|
// Data used when the sprite is rendered using a CCSpriteSheet
|
||||||
//
|
//
|
||||||
CCTextureAtlas *m_pobTextureAtlas; // Sprite Sheet texture atlas (weak reference)
|
CCTextureAtlas *m_pobTextureAtlas; // Sprite Sheet texture atlas (weak reference)
|
||||||
UINT32 m_uAtlasIndex; // Absolute (real) Index on the SpriteSheet
|
unsigned int m_uAtlasIndex; // Absolute (real) Index on the SpriteSheet
|
||||||
CCSpriteSheet *m_pobSpriteSheet; // Used spritesheet (weak reference)
|
CCSpriteSheet *m_pobSpriteSheet; // Used spritesheet (weak reference)
|
||||||
ccHonorParentTransform m_eHonorParentTransform;// whether or not to transform according to its parent transformations
|
ccHonorParentTransform m_eHonorParentTransform;// whether or not to transform according to its parent transformations
|
||||||
bool m_bDirty; // Sprite needs to be updated
|
bool m_bDirty; // Sprite needs to be updated
|
||||||
bool m_bRecursiveDirty; // Subchildren needs to be updated
|
bool m_bRecursiveDirty; // Subchildren needs to be updated
|
||||||
bool m_bHasChildren; // optimization to check if it contain children
|
bool m_bHasChildren; // optimization to check if it contain children
|
||||||
|
|
||||||
//
|
//
|
||||||
// Data used when the sprite is self-rendered
|
// Data used when the sprite is self-rendered
|
||||||
//
|
//
|
||||||
ccBlendFunc m_sBlendFunc; // Needed for the texture protocol
|
ccBlendFunc m_sBlendFunc; // Needed for the texture protocol
|
||||||
CCTexture2D *m_pobTexture;// Texture used to render the sprite
|
CCTexture2D *m_pobTexture;// Texture used to render the sprite
|
||||||
|
|
||||||
//
|
//
|
||||||
// Shared data
|
// Shared data
|
||||||
//
|
//
|
||||||
|
|
||||||
// whether or not it's parent is a CCSpriteSheet
|
// whether or not it's parent is a CCSpriteSheet
|
||||||
|
|
|
@ -35,73 +35,73 @@ THE SOFTWARE.
|
||||||
class CCSprite;
|
class CCSprite;
|
||||||
class CGRect;
|
class CGRect;
|
||||||
|
|
||||||
/** CCSpriteSheet is like a batch node: if it contains children, it will draw them in 1 single OpenGL call
|
/** CCSpriteSheet is like a batch node: if it contains children, it will draw them in 1 single OpenGL call
|
||||||
* (often known as "batch draw").
|
* (often known as "batch draw").
|
||||||
*
|
*
|
||||||
* A CCSpriteSheet can reference one and only one texture (one image file, one texture atlas).
|
* A CCSpriteSheet can reference one and only one texture (one image file, one texture atlas).
|
||||||
* Only the CCSprites that are contained in that texture can be added to the CCSpriteSheet.
|
* Only the CCSprites that are contained in that texture can be added to the CCSpriteSheet.
|
||||||
* All CCSprites added to a CCSpriteSheet are drawn in one OpenGL ES draw call.
|
* All CCSprites added to a CCSpriteSheet are drawn in one OpenGL ES draw call.
|
||||||
* If the CCSprites are not added to a CCSpriteSheet then an OpenGL ES draw call will be needed for each one, which is less efficient.
|
* If the CCSprites are not added to a CCSpriteSheet then an OpenGL ES draw call will be needed for each one, which is less efficient.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Limitations:
|
* Limitations:
|
||||||
* - The only object that is accepted as child (or grandchild) is CCSprite or any subclass of CCSprite. eg: particles, labels and layer can't be added to a CCSpriteSheet.
|
* - The only object that is accepted as child (or grandchild) is CCSprite or any subclass of CCSprite. eg: particles, labels and layer can't be added to a CCSpriteSheet.
|
||||||
* - Either all its children are Aliased or Antialiased. It can't be a mix. This is because "alias" is a property of the texture, and all the sprites share the same texture.
|
* - Either all its children are Aliased or Antialiased. It can't be a mix. This is because "alias" is a property of the texture, and all the sprites share the same texture.
|
||||||
*
|
*
|
||||||
* @since v0.7.1
|
* @since v0.7.1
|
||||||
*/
|
*/
|
||||||
class CCSpriteSheet : public CCNode, public CCTextureProtocol
|
class CCSpriteSheet : public CCNode, public CCTextureProtocol
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~CCSpriteSheet(void);
|
~CCSpriteSheet(void);
|
||||||
|
|
||||||
/** initializes a CCSpriteSheet with a texture2d and capacity of children.
|
/** initializes a CCSpriteSheet with a texture2d and capacity of children.
|
||||||
The capacity will be increased in 33% in runtime if it run out of space.
|
The capacity will be increased in 33% in runtime if it run out of space.
|
||||||
*/
|
*/
|
||||||
CCSpriteSheet* initWithTexture(CCTexture2D *pobTexture, UINT32 uCapacity);
|
CCSpriteSheet* initWithTexture(CCTexture2D *pobTexture, unsigned int uCapacity);
|
||||||
|
|
||||||
/** initializes a CCSpriteSheet with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
|
/** initializes a CCSpriteSheet with a file image (.png, .jpeg, .pvr, etc) and a capacity of children.
|
||||||
The capacity will be increased in 33% in runtime if it run out of space.
|
The capacity will be increased in 33% in runtime if it run out of space.
|
||||||
The file will be loaded using the TextureMgr.
|
The file will be loaded using the TextureMgr.
|
||||||
*/
|
*/
|
||||||
CCSpriteSheet* initWithFile(const char *pszFileImage, UINT32 uCapacity);
|
CCSpriteSheet* initWithFile(const char *pszFileImage, unsigned int uCapacity);
|
||||||
|
|
||||||
void increaseAtlasCapacity(void);
|
void increaseAtlasCapacity(void);
|
||||||
|
|
||||||
/** creates an sprite with a rect in the CCSpriteSheet.
|
/** creates an sprite with a rect in the CCSpriteSheet.
|
||||||
It's the same as:
|
It's the same as:
|
||||||
- create an standard CCSsprite
|
- create an standard CCSsprite
|
||||||
- set the usingSpriteSheet = YES
|
- set the usingSpriteSheet = YES
|
||||||
- set the textureAtlas to the same texture Atlas as the CCSpriteSheet
|
- set the textureAtlas to the same texture Atlas as the CCSpriteSheet
|
||||||
@deprecated Use [CCSprite spriteWithSpriteSheet:rect] instead;
|
@deprecated Use [CCSprite spriteWithSpriteSheet:rect] instead;
|
||||||
*/
|
*/
|
||||||
CCSprite* createSpriteWithRect(CGRect rect);
|
CCSprite* createSpriteWithRect(CGRect rect);
|
||||||
|
|
||||||
/** initializes a previously created sprite with a rect. This sprite will have the same texture as the CCSpriteSheet.
|
/** initializes a previously created sprite with a rect. This sprite will have the same texture as the CCSpriteSheet.
|
||||||
It's the same as:
|
It's the same as:
|
||||||
- initialize an standard CCSsprite
|
- initialize an standard CCSsprite
|
||||||
- set the usingSpriteSheet = YES
|
- set the usingSpriteSheet = YES
|
||||||
- set the textureAtlas to the same texture Atlas as the CCSpriteSheet
|
- set the textureAtlas to the same texture Atlas as the CCSpriteSheet
|
||||||
@since v0.99.0
|
@since v0.99.0
|
||||||
@deprecated Use [CCSprite initWithSpriteSheet:rect] instead;
|
@deprecated Use [CCSprite initWithSpriteSheet:rect] instead;
|
||||||
*/
|
*/
|
||||||
void initSprite(CCSprite* pobSprite, CGRect rect);
|
void initSprite(CCSprite* pobSprite, CGRect rect);
|
||||||
|
|
||||||
/** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
|
/** removes a child given a certain index. It will also cleanup the running actions depending on the cleanup parameter.
|
||||||
@warning Removing a child from a CCSpriteSheet is very slow
|
@warning Removing a child from a CCSpriteSheet is very slow
|
||||||
*/
|
*/
|
||||||
void removeChildAtIndex(UINT32 uIndex, bool bDoCleanup);
|
void removeChildAtIndex(unsigned int uIndex, bool bDoCleanup);
|
||||||
|
|
||||||
/** removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter.
|
/** removes a child given a reference. It will also cleanup the running actions depending on the cleanup parameter.
|
||||||
@warning Removing a child from a CCSpriteSheet is very slow
|
@warning Removing a child from a CCSpriteSheet is very slow
|
||||||
*/
|
*/
|
||||||
// void removeChild(CCSprite *pobSprite, bool bDoCleanup);
|
// void removeChild(CCSprite *pobSprite, bool bDoCleanup);
|
||||||
|
|
||||||
void insertChild(CCSprite *pobSprite, UINT32 uIndex);
|
void insertChild(CCSprite *pobSprite, unsigned int uIndex);
|
||||||
void removeSpriteFromAtlas(CCSprite *pobSprite);
|
void removeSpriteFromAtlas(CCSprite *pobSprite);
|
||||||
|
|
||||||
UINT32 rebuildIndexInOrder(CCSprite *pobParent, UINT32 uIndex);
|
unsigned int rebuildIndexInOrder(CCSprite *pobParent, unsigned int uIndex);
|
||||||
UINT32 atlasIndexForChild(CCSprite *pobSprite, INT32 nZ);
|
unsigned int atlasIndexForChild(CCSprite *pobSprite, int nZ);
|
||||||
unsigned int highestAtlasIndexInChild(CCSprite *pSprite);
|
unsigned int highestAtlasIndexInChild(CCSprite *pSprite);
|
||||||
unsigned int lowestAtlasIndexInChild(CCSprite *pSprite);
|
unsigned int lowestAtlasIndexInChild(CCSprite *pSprite);
|
||||||
|
|
||||||
|
@ -120,27 +120,27 @@ public:
|
||||||
virtual void removeAllChildrenWithCleanup(bool cleanup);
|
virtual void removeAllChildrenWithCleanup(bool cleanup);
|
||||||
virtual void draw(void);
|
virtual void draw(void);
|
||||||
public:
|
public:
|
||||||
/** creates a CCSpriteSheet with a texture2d and a default capacity of 29 children.
|
/** creates a CCSpriteSheet with a texture2d and a default capacity of 29 children.
|
||||||
The capacity will be increased in 33% in runtime if it run out of space.
|
The capacity will be increased in 33% in runtime if it run out of space.
|
||||||
*/
|
*/
|
||||||
static CCSpriteSheet* spriteSheetWithTexture(CCTexture2D *pobTexture);
|
static CCSpriteSheet* spriteSheetWithTexture(CCTexture2D *pobTexture);
|
||||||
|
|
||||||
/** creates a CCSpriteSheet with a texture2d and capacity of children.
|
/** creates a CCSpriteSheet with a texture2d and capacity of children.
|
||||||
The capacity will be increased in 33% in runtime if it run out of space.
|
The capacity will be increased in 33% in runtime if it run out of space.
|
||||||
*/
|
*/
|
||||||
static CCSpriteSheet* spriteSheetWithTexture(CCTexture2D *pobTexture, UINT32 uCapacity);
|
static CCSpriteSheet* spriteSheetWithTexture(CCTexture2D *pobTexture, unsigned int uCapacity);
|
||||||
|
|
||||||
/** creates a CCSpriteSheet with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 children.
|
/** creates a CCSpriteSheet with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 children.
|
||||||
The capacity will be increased in 33% in runtime if it run out of space.
|
The capacity will be increased in 33% in runtime if it run out of space.
|
||||||
The file will be loaded using the TextureMgr.
|
The file will be loaded using the TextureMgr.
|
||||||
*/
|
*/
|
||||||
static CCSpriteSheet* spriteSheetWithFile(const char *pszFileImage);
|
static CCSpriteSheet* spriteSheetWithFile(const char *pszFileImage);
|
||||||
|
|
||||||
/** creates a CCSpriteSheet with a file image (.png, .jpeg, .pvr, etc) and capacity of children.
|
/** creates a CCSpriteSheet with a file image (.png, .jpeg, .pvr, etc) and capacity of children.
|
||||||
The capacity will be increased in 33% in runtime if it run out of space.
|
The capacity will be increased in 33% in runtime if it run out of space.
|
||||||
The file will be loaded using the TextureMgr.
|
The file will be loaded using the TextureMgr.
|
||||||
*/
|
*/
|
||||||
static CCSpriteSheet* spriteSheetWithFile(const char *pszFileImage, UINT32 uCapacity);
|
static CCSpriteSheet* spriteSheetWithFile(const char *pszFileImage, unsigned int uCapacity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateBlendFunc(void);
|
void updateBlendFunc(void);
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __CCTEXTURE2D_H__
|
#ifndef __CCTEXTURE2D_H__
|
||||||
#define __CCTEXTURE2D_H__
|
#define __CCTEXTURE2D_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
|
|
||||||
#include "Cocos2dDefine.h"
|
#include "Cocos2dDefine.h"
|
||||||
#include "cocoa/NSObject.h"
|
#include "cocoa/NSObject.h"
|
||||||
#include "cocoa/CGGeometry.h"
|
#include "cocoa/CGGeometry.h"
|
||||||
|
@ -89,9 +89,9 @@ class CCTexture2D : public NSObject
|
||||||
/** pixel format of the texture */
|
/** pixel format of the texture */
|
||||||
CCX_PROPERTY_READONLY(CCTexture2DPixelFormat, m_ePixelFormat, PixelFormat)
|
CCX_PROPERTY_READONLY(CCTexture2DPixelFormat, m_ePixelFormat, PixelFormat)
|
||||||
/** width in pixels */
|
/** width in pixels */
|
||||||
CCX_PROPERTY_READONLY(UINT32, m_uPixelsWide, PixelsWide)
|
CCX_PROPERTY_READONLY(unsigned int, m_uPixelsWide, PixelsWide)
|
||||||
/** hight in pixels */
|
/** hight in pixels */
|
||||||
CCX_PROPERTY_READONLY(UINT32, m_uPixelsHigh, PixelsHigh)
|
CCX_PROPERTY_READONLY(unsigned int, m_uPixelsHigh, PixelsHigh)
|
||||||
|
|
||||||
/** texture name */
|
/** texture name */
|
||||||
CCX_PROPERTY_READONLY(GLuint, m_uName, Name)
|
CCX_PROPERTY_READONLY(GLuint, m_uName, Name)
|
||||||
|
@ -112,7 +112,7 @@ public:
|
||||||
std::string description(void);
|
std::string description(void);
|
||||||
|
|
||||||
/** Intializes with a texture2d with data */
|
/** Intializes with a texture2d with data */
|
||||||
CCTexture2D * initWithData(const void* data, CCTexture2DPixelFormat pixelFormat, UINT32 pixelsWide, UINT32 pixelsHigh, CGSize contentSize);
|
CCTexture2D * initWithData(const void* data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, CGSize contentSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Drawing extensions to make it easy to draw basic quads using a CCTexture2D object.
|
Drawing extensions to make it easy to draw basic quads using a CCTexture2D object.
|
||||||
|
@ -200,9 +200,9 @@ public:
|
||||||
static CCTexture2DPixelFormat defaultAlphaPixelFormat();
|
static CCTexture2DPixelFormat defaultAlphaPixelFormat();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCTexture2D * initPremultipliedATextureWithImage(UIImage * image, UINT32 pixelsWide, UINT32 pixelsHigh);
|
CCTexture2D * initPremultipliedATextureWithImage(UIImage * image, unsigned int pixelsWide, unsigned int pixelsHigh);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //__CCTEXTURE2D_H__
|
#endif //__CCTEXTURE2D_H__
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __CCTEXTURE_ATLAS_H__
|
#ifndef __CCTEXTURE_ATLAS_H__
|
||||||
#define __CCTEXTURE_ATLAS_H__
|
#define __CCTEXTURE_ATLAS_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "ccTypes.h"
|
#include "ccTypes.h"
|
||||||
#include "cocoa/NSObject.h"
|
#include "cocoa/NSObject.h"
|
||||||
|
@ -53,9 +53,9 @@ protected:
|
||||||
#endif // CC_TEXTURE_ATLAS_USES_VBO
|
#endif // CC_TEXTURE_ATLAS_USES_VBO
|
||||||
|
|
||||||
/** quantity of quads that are going to be drawn */
|
/** quantity of quads that are going to be drawn */
|
||||||
CCX_PROPERTY_READONLY(UINT32, m_uTotalQuads, TotalQuads)
|
CCX_PROPERTY_READONLY(unsigned int, m_uTotalQuads, TotalQuads)
|
||||||
/** quantity of quads that can be stored with the current texture atlas size */
|
/** quantity of quads that can be stored with the current texture atlas size */
|
||||||
CCX_PROPERTY_READONLY(UINT32, m_uCapacity, Capacity)
|
CCX_PROPERTY_READONLY(unsigned int, m_uCapacity, Capacity)
|
||||||
/** Texture of the texture atlas */
|
/** Texture of the texture atlas */
|
||||||
CCX_PROPERTY(CCTexture2D *, m_pTexture, Texture)
|
CCX_PROPERTY(CCTexture2D *, m_pTexture, Texture)
|
||||||
/** Quads that are going to be rendered */
|
/** Quads that are going to be rendered */
|
||||||
|
@ -71,20 +71,20 @@ public:
|
||||||
/** creates a TextureAtlas with an filename and with an initial capacity for Quads.
|
/** creates a TextureAtlas with an filename and with an initial capacity for Quads.
|
||||||
* The TextureAtlas capacity can be increased in runtime.
|
* The TextureAtlas capacity can be increased in runtime.
|
||||||
*/
|
*/
|
||||||
static CCTextureAtlas * textureAtlasWithFile(const char* file , UINT32 capacity);
|
static CCTextureAtlas * textureAtlasWithFile(const char* file , unsigned int capacity);
|
||||||
|
|
||||||
/** initializes a TextureAtlas with a filename and with a certain capacity for Quads.
|
/** initializes a TextureAtlas with a filename and with a certain capacity for Quads.
|
||||||
* The TextureAtlas capacity can be increased in runtime.
|
* The TextureAtlas capacity can be increased in runtime.
|
||||||
*
|
*
|
||||||
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
||||||
*/
|
*/
|
||||||
CCTextureAtlas * initWithFile(const char* file, UINT32 capacity);
|
CCTextureAtlas * initWithFile(const char* file, unsigned int capacity);
|
||||||
|
|
||||||
/** creates a TextureAtlas with a previously initialized Texture2D object, and
|
/** creates a TextureAtlas with a previously initialized Texture2D object, and
|
||||||
* with an initial capacity for n Quads.
|
* with an initial capacity for n Quads.
|
||||||
* The TextureAtlas capacity can be increased in runtime.
|
* The TextureAtlas capacity can be increased in runtime.
|
||||||
*/
|
*/
|
||||||
static CCTextureAtlas * textureAtlasWithTexture(CCTexture2D *tex, UINT32 capacity);
|
static CCTextureAtlas * textureAtlasWithTexture(CCTexture2D *tex, unsigned int capacity);
|
||||||
|
|
||||||
/** initializes a TextureAtlas with a previously initialized Texture2D object, and
|
/** initializes a TextureAtlas with a previously initialized Texture2D object, and
|
||||||
* with an initial capacity for Quads.
|
* with an initial capacity for Quads.
|
||||||
|
@ -92,31 +92,31 @@ public:
|
||||||
*
|
*
|
||||||
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
* WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)
|
||||||
*/
|
*/
|
||||||
CCTextureAtlas * initWithTexture(CCTexture2D *tex, UINT32 capacity);
|
CCTextureAtlas * initWithTexture(CCTexture2D *tex, unsigned int capacity);
|
||||||
|
|
||||||
/** updates a Quad (texture, vertex and color) at a certain index
|
/** updates a Quad (texture, vertex and color) at a certain index
|
||||||
* index must be between 0 and the atlas capacity - 1
|
* index must be between 0 and the atlas capacity - 1
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
void updateQuad(ccV3F_C4B_T2F_Quad* quad, UINT32 index);
|
void updateQuad(ccV3F_C4B_T2F_Quad* quad, unsigned int index);
|
||||||
|
|
||||||
/** Inserts a Quad (texture, vertex and color) at a certain index
|
/** Inserts a Quad (texture, vertex and color) at a certain index
|
||||||
index must be between 0 and the atlas capacity - 1
|
index must be between 0 and the atlas capacity - 1
|
||||||
@since v0.8
|
@since v0.8
|
||||||
*/
|
*/
|
||||||
void insertQuad(ccV3F_C4B_T2F_Quad* quad, UINT32 index);
|
void insertQuad(ccV3F_C4B_T2F_Quad* quad, unsigned int index);
|
||||||
|
|
||||||
/** Removes the quad that is located at a certain index and inserts it at a new index
|
/** Removes the quad that is located at a certain index and inserts it at a new index
|
||||||
This operation is faster than removing and inserting in a quad in 2 different steps
|
This operation is faster than removing and inserting in a quad in 2 different steps
|
||||||
@since v0.7.2
|
@since v0.7.2
|
||||||
*/
|
*/
|
||||||
void insertQuadFromIndex(UINT32 fromIndex, UINT32 newIndex);
|
void insertQuadFromIndex(unsigned int fromIndex, unsigned int newIndex);
|
||||||
|
|
||||||
/** removes a quad at a given index number.
|
/** removes a quad at a given index number.
|
||||||
The capacity remains the same, but the total number of quads to be drawn is reduced in 1
|
The capacity remains the same, but the total number of quads to be drawn is reduced in 1
|
||||||
@since v0.7.2
|
@since v0.7.2
|
||||||
*/
|
*/
|
||||||
void removeQuadAtIndex(UINT32 index);
|
void removeQuadAtIndex(unsigned int index);
|
||||||
|
|
||||||
/** removes all Quads.
|
/** removes all Quads.
|
||||||
The TextureAtlas capacity remains untouched. No memory is freed.
|
The TextureAtlas capacity remains untouched. No memory is freed.
|
||||||
|
@ -131,21 +131,21 @@ public:
|
||||||
* It returns YES if the resize was successful.
|
* It returns YES if the resize was successful.
|
||||||
* If it fails to resize the capacity it will return NO with a new capacity of 0.
|
* If it fails to resize the capacity it will return NO with a new capacity of 0.
|
||||||
*/
|
*/
|
||||||
bool resizeCapacity(UINT32 n);
|
bool resizeCapacity(unsigned int n);
|
||||||
|
|
||||||
|
|
||||||
/** draws n quads
|
/** draws n quads
|
||||||
* n can't be greater than the capacity of the Atlas
|
* n can't be greater than the capacity of the Atlas
|
||||||
*/
|
*/
|
||||||
void drawNumberOfQuads(UINT32 n);
|
void drawNumberOfQuads(unsigned int n);
|
||||||
|
|
||||||
/** draws all the Atlas's Quads
|
/** draws all the Atlas's Quads
|
||||||
*/
|
*/
|
||||||
void drawQuads();
|
void drawQuads();
|
||||||
private:
|
private:
|
||||||
void initIndices();
|
void initIndices();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //__CCTEXTURE_ATLAS_H__
|
#endif //__CCTEXTURE_ATLAS_H__
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ THE SOFTWARE.
|
||||||
#define __CCTYPES_H__
|
#define __CCTYPES_H__
|
||||||
|
|
||||||
#include "cocoa/CGGeometry.h"
|
#include "cocoa/CGGeometry.h"
|
||||||
#include "platform/platform.h"
|
|
||||||
#include <GLES/gl.h>
|
#include <GLES/gl.h>
|
||||||
|
|
||||||
/** RGB color composed of bytes 3 bytes
|
/** RGB color composed of bytes 3 bytes
|
||||||
|
|
|
@ -26,7 +26,7 @@ THE SOFTWARE.
|
||||||
#ifndef __COCOS2D_H__
|
#ifndef __COCOS2D_H__
|
||||||
#define __COCOS2D_H__
|
#define __COCOS2D_H__
|
||||||
|
|
||||||
#include "platform/platform.h"
|
//#include "platform/platform.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,43 +1,43 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "CCLayer.h"
|
#include "CCLayer.h"
|
||||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
#include "touch_dispatcher/CCTouchDispatcher.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "support/CGPointExtension.h"
|
#include "support/CGPointExtension.h"
|
||||||
|
|
||||||
// CCLayer
|
// CCLayer
|
||||||
CCLayer::CCLayer()
|
CCLayer::CCLayer()
|
||||||
{
|
{
|
||||||
CGSize s = CCDirector::getSharedDirector()->getWinSize();
|
CGSize s = CCDirector::getSharedDirector()->getWinSize();
|
||||||
m_tAnchorPoint = ccp(0.5f, 0.5f);
|
m_tAnchorPoint = ccp(0.5f, 0.5f);
|
||||||
this->setContentSize(s);
|
this->setContentSize(s);
|
||||||
m_bIsRelativeAnchorPoint = false;
|
m_bIsRelativeAnchorPoint = false;
|
||||||
m_bIsTouchEnabled = false;
|
m_bIsTouchEnabled = false;
|
||||||
m_bIsAccelerometerEnabled = false;
|
m_bIsAccelerometerEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCLayer::~CCLayer()
|
CCLayer::~CCLayer()
|
||||||
{
|
{
|
||||||
|
@ -60,23 +60,23 @@ bool CCLayer::getIsTouchEnabled()
|
||||||
/// isTouchEnabled setter
|
/// isTouchEnabled setter
|
||||||
void CCLayer::setIsTouchEnabled(bool enabled)
|
void CCLayer::setIsTouchEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (m_bIsTouchEnabled != enabled)
|
if (m_bIsTouchEnabled != enabled)
|
||||||
{
|
{
|
||||||
m_bIsTouchEnabled = enabled;
|
m_bIsTouchEnabled = enabled;
|
||||||
if (m_bIsRunning)
|
if (m_bIsRunning)
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
this->registerWithTouchDispatcher();
|
this->registerWithTouchDispatcher();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// have problems?
|
// have problems?
|
||||||
CCTouchDispatcher::getSharedDispatcher()->removeDelegate(static_cast<CCTargetedTouchDelegate*>(this));
|
CCTouchDispatcher::getSharedDispatcher()->removeDelegate(static_cast<CCTargetedTouchDelegate*>(this));
|
||||||
CCTouchDispatcher::getSharedDispatcher()->removeDelegate(static_cast<CCStandardTouchDelegate*>(this));
|
CCTouchDispatcher::getSharedDispatcher()->removeDelegate(static_cast<CCStandardTouchDelegate*>(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isAccelerometerEnabled getter
|
/// isAccelerometerEnabled getter
|
||||||
|
@ -209,7 +209,7 @@ CCColorLayer* CCColorLayer::initWithColorWidthHeight(ccColor4B color, GLfloat wi
|
||||||
m_tColor.b = color.b;
|
m_tColor.b = color.b;
|
||||||
m_cOpacity = color.a;
|
m_cOpacity = color.a;
|
||||||
|
|
||||||
for (UINT32 i=0; i<sizeof(m_pSquareVertices) / sizeof(m_pSquareVertices[0]); i++ )
|
for (unsigned int i=0; i<sizeof(m_pSquareVertices) / sizeof(m_pSquareVertices[0]); i++ )
|
||||||
m_pSquareVertices[i] = 0.0f;
|
m_pSquareVertices[i] = 0.0f;
|
||||||
|
|
||||||
this->updateColor();
|
this->updateColor();
|
||||||
|
@ -251,7 +251,7 @@ void CCColorLayer::changeHeight(GLfloat h)
|
||||||
|
|
||||||
void CCColorLayer::updateColor()
|
void CCColorLayer::updateColor()
|
||||||
{
|
{
|
||||||
for( UINT32 i=0; i < sizeof(m_pSquareColors) / sizeof(m_pSquareColors[0]); i++ )
|
for( unsigned int i=0; i < sizeof(m_pSquareColors) / sizeof(m_pSquareColors[0]); i++ )
|
||||||
{
|
{
|
||||||
if( i % 4 == 0 )
|
if( i % 4 == 0 )
|
||||||
m_pSquareColors[i] = m_tColor.r;
|
m_pSquareColors[i] = m_tColor.r;
|
||||||
|
@ -303,7 +303,7 @@ CCMultiplexLayer::CCMultiplexLayer()
|
||||||
}
|
}
|
||||||
CCMultiplexLayer::~CCMultiplexLayer()
|
CCMultiplexLayer::~CCMultiplexLayer()
|
||||||
{
|
{
|
||||||
m_pLayers->release();
|
m_pLayers->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCMultiplexLayer * CCMultiplexLayer::layerWithLayers(CCLayer * layer, ...)
|
CCMultiplexLayer * CCMultiplexLayer::layerWithLayers(CCLayer * layer, ...)
|
||||||
|
|
|
@ -185,7 +185,7 @@ char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||||
TUString::StrUnicodeToStrUtf8((Char*)pszUserPath, pszTmp);
|
TUString::StrUnicodeToStrUtf8((Char*)pszUserPath, pszTmp);
|
||||||
char *pszRet;
|
char *pszRet;
|
||||||
|
|
||||||
INT32 nLen = strlen(pszRelativePath) + strlen(pszUserPath) + 1;
|
int nLen = strlen(pszRelativePath) + strlen(pszUserPath) + 1;
|
||||||
pszRet = new char[nLen];
|
pszRet = new char[nLen];
|
||||||
memset(pszRet, 0, nLen);
|
memset(pszRet, 0, nLen);
|
||||||
strncat(pszRet, pszUserPath, strlen(pszUserPath));
|
strncat(pszRet, pszUserPath, strlen(pszUserPath));
|
||||||
|
|
|
@ -27,9 +27,9 @@ THE SOFTWARE.
|
||||||
|
|
||||||
// although it is not the same as gettimeofday as unix
|
// although it is not the same as gettimeofday as unix
|
||||||
// but we only use the diffrences of tow values
|
// but we only use the diffrences of tow values
|
||||||
INT32 CCTime::gettimeofday(struct cc_timeval *tp, void *tzp)
|
int CCTime::gettimeofday(struct cc_timeval *tp, void *tzp)
|
||||||
{
|
{
|
||||||
UINT32 uSeconds = GetSysSecond();
|
unsigned int uSeconds = GetSysSecond();
|
||||||
tp->tv_sec = uSeconds;
|
tp->tv_sec = uSeconds;
|
||||||
tp->tv_usec = 0;
|
tp->tv_usec = 0;
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,8 @@ public:
|
||||||
|
|
||||||
bool save(const std::string &strFileName, int nFormat);
|
bool save(const std::string &strFileName, int nFormat);
|
||||||
|
|
||||||
UINT32 width(void);
|
unsigned int width(void);
|
||||||
UINT32 height(void);
|
unsigned int height(void);
|
||||||
|
|
||||||
bool isAlphaPixelFormat(void);
|
bool isAlphaPixelFormat(void);
|
||||||
|
|
||||||
|
|
|
@ -1,43 +1,43 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCSpriteSheet.h"
|
#include "CCSpriteSheet.h"
|
||||||
#include "ccConfig.h"
|
#include "ccConfig.h"
|
||||||
#include "CCSprite.h"
|
#include "CCSprite.h"
|
||||||
#include "CCSpriteFrame.h"
|
#include "CCSpriteFrame.h"
|
||||||
#include "CCSpriteFrameCache.h"
|
#include "CCSpriteFrameCache.h"
|
||||||
#include "CCTextureCache.h"
|
#include "CCTextureCache.h"
|
||||||
#include "support/CGPointExtension.h"
|
#include "support/CGPointExtension.h"
|
||||||
#include "CCDrawingPrimitives.h"
|
#include "CCDrawingPrimitives.h"
|
||||||
#include "cocoa/CGGeometry.h"
|
#include "cocoa/CGGeometry.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
#include "cocoa/CGAffineTransform.h"
|
#include "cocoa/CGAffineTransform.h"
|
||||||
#include "sstsd.h"
|
#include "sstsd.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#if CC_SPRITESHEET_RENDER_SUBPIXEL
|
#if CC_SPRITESHEET_RENDER_SUBPIXEL
|
||||||
#define RENDER_IN_SUBPIXEL
|
#define RENDER_IN_SUBPIXEL
|
||||||
#else
|
#else
|
||||||
|
@ -553,10 +553,10 @@ void CCSprite::draw(void)
|
||||||
#define kQuadSize sizeof(m_sQuad.bl)
|
#define kQuadSize sizeof(m_sQuad.bl)
|
||||||
glBindTexture(GL_TEXTURE_2D, m_pobTexture->getName());
|
glBindTexture(GL_TEXTURE_2D, m_pobTexture->getName());
|
||||||
|
|
||||||
INT32 offset = (INT32)&m_sQuad;
|
int offset = (int)&m_sQuad;
|
||||||
|
|
||||||
// vertex
|
// vertex
|
||||||
INT32 diff = offsetof(ccV3F_C4B_T2F, vertices);
|
int diff = offsetof(ccV3F_C4B_T2F, vertices);
|
||||||
glVertexPointer(3, GL_FLOAT, kQuadSize, (void*)(offset + diff));
|
glVertexPointer(3, GL_FLOAT, kQuadSize, (void*)(offset + diff));
|
||||||
|
|
||||||
// color
|
// color
|
||||||
|
@ -592,12 +592,12 @@ CCNode* CCSprite::addChild(CCNode* pChild)
|
||||||
return __super::addChild(pChild);
|
return __super::addChild(pChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCNode* CCSprite::addChild(CCNode *pChild, INT32 zOrder)
|
CCNode* CCSprite::addChild(CCNode *pChild, int zOrder)
|
||||||
{
|
{
|
||||||
return __super::addChild(pChild, zOrder);
|
return __super::addChild(pChild, zOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCNode* CCSprite::addChild(CCNode *pChild, INT32 zOrder, INT32 tag)
|
CCNode* CCSprite::addChild(CCNode *pChild, int zOrder, int tag)
|
||||||
{
|
{
|
||||||
assert(pChild != NULL);
|
assert(pChild != NULL);
|
||||||
CCNode* pRet = __super::addChild(pChild, zOrder, tag);
|
CCNode* pRet = __super::addChild(pChild, zOrder, tag);
|
||||||
|
@ -606,7 +606,7 @@ CCNode* CCSprite::addChild(CCNode *pChild, INT32 zOrder, INT32 tag)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
///@todo implement after SpriteSheet is implemented
|
///@todo implement after SpriteSheet is implemented
|
||||||
UINT32 index = m_pobSpriteSheet->atlasIndexForChild(static_cast<CCSprite*>(pChild), zOrder);
|
unsigned int index = m_pobSpriteSheet->atlasIndexForChild(static_cast<CCSprite*>(pChild), zOrder);
|
||||||
m_pobSpriteSheet->insertChild(static_cast<CCSprite*>(pChild), index);
|
m_pobSpriteSheet->insertChild(static_cast<CCSprite*>(pChild), index);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -616,7 +616,7 @@ CCNode* CCSprite::addChild(CCNode *pChild, INT32 zOrder, INT32 tag)
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSprite::reorderChild(CCNode *pChild, INT32 zOrder)
|
void CCSprite::reorderChild(CCNode *pChild, int zOrder)
|
||||||
{
|
{
|
||||||
assert(pChild != NULL);
|
assert(pChild != NULL);
|
||||||
assert(m_pChildren->containsObject(pChild));
|
assert(m_pChildren->containsObject(pChild));
|
||||||
|
|
|
@ -42,7 +42,7 @@ CCSpriteSheet* CCSpriteSheet::spriteSheetWithTexture(CCTexture2D *pobTexture)
|
||||||
return pSpriteSheet;
|
return pSpriteSheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCSpriteSheet* CCSpriteSheet::spriteSheetWithTexture(CCTexture2D *pobTexture, UINT32 uCapacity)
|
CCSpriteSheet* CCSpriteSheet::spriteSheetWithTexture(CCTexture2D *pobTexture, unsigned int uCapacity)
|
||||||
{
|
{
|
||||||
CCSpriteSheet *pSpriteSheet = new CCSpriteSheet();
|
CCSpriteSheet *pSpriteSheet = new CCSpriteSheet();
|
||||||
pSpriteSheet->initWithTexture(pobTexture, uCapacity);
|
pSpriteSheet->initWithTexture(pobTexture, uCapacity);
|
||||||
|
@ -52,7 +52,7 @@ CCSpriteSheet* CCSpriteSheet::spriteSheetWithTexture(CCTexture2D *pobTexture, UI
|
||||||
}
|
}
|
||||||
|
|
||||||
// creation with file image
|
// creation with file image
|
||||||
CCSpriteSheet* CCSpriteSheet::spriteSheetWithFile(const char *pszFileImage, UINT32 uCapacity)
|
CCSpriteSheet* CCSpriteSheet::spriteSheetWithFile(const char *pszFileImage, unsigned int uCapacity)
|
||||||
{
|
{
|
||||||
CCSpriteSheet *pSpriteSheet = new CCSpriteSheet();
|
CCSpriteSheet *pSpriteSheet = new CCSpriteSheet();
|
||||||
pSpriteSheet->initWithFile(pszFileImage, uCapacity);
|
pSpriteSheet->initWithFile(pszFileImage, uCapacity);
|
||||||
|
@ -71,7 +71,7 @@ CCSpriteSheet* CCSpriteSheet::spriteSheetWithFile(const char *pszFileImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
// init with CCTexture2D
|
// init with CCTexture2D
|
||||||
CCSpriteSheet* CCSpriteSheet::initWithTexture(CCTexture2D *pobTexture, UINT32 uCapacity)
|
CCSpriteSheet* CCSpriteSheet::initWithTexture(CCTexture2D *pobTexture, unsigned int uCapacity)
|
||||||
{
|
{
|
||||||
m_blendFunc.src = CC_BLEND_SRC;
|
m_blendFunc.src = CC_BLEND_SRC;
|
||||||
m_blendFunc.dst = CC_BLEND_DST;
|
m_blendFunc.dst = CC_BLEND_DST;
|
||||||
|
@ -89,7 +89,7 @@ CCSpriteSheet* CCSpriteSheet::initWithTexture(CCTexture2D *pobTexture, UINT32 uC
|
||||||
}
|
}
|
||||||
|
|
||||||
// init with FileImage
|
// init with FileImage
|
||||||
CCSpriteSheet* CCSpriteSheet::initWithFile(const char *pszFileImage, UINT32 uCapacity)
|
CCSpriteSheet* CCSpriteSheet::initWithFile(const char *pszFileImage, unsigned int uCapacity)
|
||||||
{
|
{
|
||||||
CCTexture2D *pTexture2D = CCTextureCache::sharedTextureCache()->addImage(pszFileImage);
|
CCTexture2D *pTexture2D = CCTextureCache::sharedTextureCache()->addImage(pszFileImage);
|
||||||
return initWithTexture(pTexture2D, uCapacity);
|
return initWithTexture(pTexture2D, uCapacity);
|
||||||
|
@ -107,12 +107,12 @@ CCSpriteSheet::~CCSpriteSheet(void)
|
||||||
// don't call visit on it's children
|
// don't call visit on it's children
|
||||||
void CCSpriteSheet::visit(void)
|
void CCSpriteSheet::visit(void)
|
||||||
{
|
{
|
||||||
// CAREFUL:
|
// CAREFUL:
|
||||||
// This visit is almost identical to CocosNode#visit
|
// This visit is almost identical to CocosNode#visit
|
||||||
// with the exception that it doesn't call visit on it's children
|
// with the exception that it doesn't call visit on it's children
|
||||||
//
|
//
|
||||||
// The alternative is to have a void CCSprite#visit, but
|
// The alternative is to have a void CCSprite#visit, but
|
||||||
// although this is less mantainable, is faster
|
// although this is less mantainable, is faster
|
||||||
//
|
//
|
||||||
if (! m_bIsVisible)
|
if (! m_bIsVisible)
|
||||||
{
|
{
|
||||||
|
@ -123,9 +123,9 @@ void CCSpriteSheet::visit(void)
|
||||||
|
|
||||||
///@todo implement later
|
///@todo implement later
|
||||||
/*
|
/*
|
||||||
if ( grid_ && grid_.active) {
|
if ( grid_ && grid_.active) {
|
||||||
[grid_ beforeDraw];
|
[grid_ beforeDraw];
|
||||||
[self transformAncestors];
|
[self transformAncestors];
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ void CCSpriteSheet::visit(void)
|
||||||
|
|
||||||
///@todo: implement later
|
///@todo: implement later
|
||||||
/*
|
/*
|
||||||
if ( grid_ && grid_.active)
|
if ( grid_ && grid_.active)
|
||||||
[grid_ afterDraw:self];
|
[grid_ afterDraw:self];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ void CCSpriteSheet::removeChild(CCNode *child, bool cleanup)
|
||||||
__super::removeChild(pSprite, cleanup);
|
__super::removeChild(pSprite, cleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCSpriteSheet::removeChildAtIndex(UINT32 uIndex, bool bDoCleanup)
|
void CCSpriteSheet::removeChildAtIndex(unsigned int uIndex, bool bDoCleanup)
|
||||||
{
|
{
|
||||||
removeChild(static_cast<CCSprite*>(m_pChildren->getObjectAtIndex(uIndex)), bDoCleanup);
|
removeChild(static_cast<CCSprite*>(m_pChildren->getObjectAtIndex(uIndex)), bDoCleanup);
|
||||||
}
|
}
|
||||||
|
@ -261,20 +261,20 @@ void CCSpriteSheet::draw(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CC_SPRITESHEET_DEBUG_DRAW
|
#if CC_SPRITESHEET_DEBUG_DRAW
|
||||||
CGRect rect = [child boundingBox]; //Issue #528
|
CGRect rect = [child boundingBox]; //Issue #528
|
||||||
CGPoint vertices[4]={
|
CGPoint vertices[4]={
|
||||||
ccp(rect.origin.x,rect.origin.y),
|
ccp(rect.origin.x,rect.origin.y),
|
||||||
ccp(rect.origin.x+rect.size.width,rect.origin.y),
|
ccp(rect.origin.x+rect.size.width,rect.origin.y),
|
||||||
ccp(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height),
|
ccp(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height),
|
||||||
ccp(rect.origin.x,rect.origin.y+rect.size.height),
|
ccp(rect.origin.x,rect.origin.y+rect.size.height),
|
||||||
};
|
};
|
||||||
ccDrawPoly(vertices, 4, YES);
|
ccDrawPoly(vertices, 4, YES);
|
||||||
#endif // CC_SPRITESHEET_DEBUG_DRAW
|
#endif // CC_SPRITESHEET_DEBUG_DRAW
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
|
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
|
||||||
// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
|
// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
|
||||||
// Unneeded states: -
|
// Unneeded states: -
|
||||||
bool newBlend = false;
|
bool newBlend = false;
|
||||||
if (m_blendFunc.src != CC_BLEND_SRC || m_blendFunc.dst != CC_BLEND_DST)
|
if (m_blendFunc.src != CC_BLEND_SRC || m_blendFunc.dst != CC_BLEND_DST)
|
||||||
|
@ -292,8 +292,8 @@ void CCSpriteSheet::draw(void)
|
||||||
|
|
||||||
void CCSpriteSheet::increaseAtlasCapacity(void)
|
void CCSpriteSheet::increaseAtlasCapacity(void)
|
||||||
{
|
{
|
||||||
// if we're going beyond the current TextureAtlas's capacity,
|
// if we're going beyond the current TextureAtlas's capacity,
|
||||||
// all the previously initialized sprites will need to redo their texture coords
|
// all the previously initialized sprites will need to redo their texture coords
|
||||||
// this is likely computationally expensive
|
// this is likely computationally expensive
|
||||||
unsigned int quantity = (m_pobTextureAtlas->getCapacity() + 1) * 4 / 3;
|
unsigned int quantity = (m_pobTextureAtlas->getCapacity() + 1) * 4 / 3;
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ unsigned int CCSpriteSheet::lowestAtlasIndexInChild(CCSprite *pSprite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CCSpriteSheet::atlasIndexForChild(CCSprite *pobSprite, INT32 nZ)
|
unsigned int CCSpriteSheet::atlasIndexForChild(CCSprite *pobSprite, int nZ)
|
||||||
{
|
{
|
||||||
NSMutableArray<CCNode*> *pBrothers = pobSprite->getParent()->getChildren();
|
NSMutableArray<CCNode*> *pBrothers = pobSprite->getParent()->getChildren();
|
||||||
unsigned int uChildIndex = pBrothers->getIndexOfObject(pobSprite);
|
unsigned int uChildIndex = pBrothers->getIndexOfObject(pobSprite);
|
||||||
|
@ -430,7 +430,7 @@ unsigned int CCSpriteSheet::atlasIndexForChild(CCSprite *pobSprite, INT32 nZ)
|
||||||
|
|
||||||
// add child helper
|
// add child helper
|
||||||
|
|
||||||
void CCSpriteSheet::insertChild(CCSprite *pobSprite, UINT32 uIndex)
|
void CCSpriteSheet::insertChild(CCSprite *pobSprite, unsigned int uIndex)
|
||||||
{
|
{
|
||||||
pobSprite->useSpriteSheetRender(this);
|
pobSprite->useSpriteSheetRender(this);
|
||||||
pobSprite->setAtlasIndex(uIndex);
|
pobSprite->setAtlasIndex(uIndex);
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ void tgaLoadHeader(FILE *pFile, tImageTGA *psInfo) {
|
||||||
// loads the image pixels. You shouldn't call this function directly
|
// loads the image pixels. You shouldn't call this function directly
|
||||||
void tgaLoadImageData(FILE *pFile, tImageTGA *psInfo) {
|
void tgaLoadImageData(FILE *pFile, tImageTGA *psInfo) {
|
||||||
|
|
||||||
INT32 mode,total,i;
|
int mode,total,i;
|
||||||
unsigned char aux;
|
unsigned char aux;
|
||||||
|
|
||||||
// mode equal the number of components for each pixel
|
// mode equal the number of components for each pixel
|
||||||
|
@ -83,9 +83,9 @@ void tgaLoadImageData(FILE *pFile, tImageTGA *psInfo) {
|
||||||
// loads the RLE encoded image pixels. You shouldn't call this function directly
|
// loads the RLE encoded image pixels. You shouldn't call this function directly
|
||||||
void tgaLoadRLEImageData(FILE *pFile, tImageTGA *psInfo)
|
void tgaLoadRLEImageData(FILE *pFile, tImageTGA *psInfo)
|
||||||
{
|
{
|
||||||
UINT32 mode,total,i, index = 0;
|
unsigned int mode,total,i, index = 0;
|
||||||
unsigned char aux[4], runlength = 0;
|
unsigned char aux[4], runlength = 0;
|
||||||
UINT32 skip = 0, flag = 0;
|
unsigned int skip = 0, flag = 0;
|
||||||
|
|
||||||
// mode equal the number of components for each pixel
|
// mode equal the number of components for each pixel
|
||||||
mode = psInfo->pixelDepth / 8;
|
mode = psInfo->pixelDepth / 8;
|
||||||
|
@ -141,10 +141,10 @@ void tgaLoadRLEImageData(FILE *pFile, tImageTGA *psInfo)
|
||||||
void tgaFlipImage( tImageTGA *psInfo )
|
void tgaFlipImage( tImageTGA *psInfo )
|
||||||
{
|
{
|
||||||
// mode equal the number of components for each pixel
|
// mode equal the number of components for each pixel
|
||||||
INT32 mode = psInfo->pixelDepth / 8;
|
int mode = psInfo->pixelDepth / 8;
|
||||||
INT32 rowbytes = psInfo->width*mode;
|
int rowbytes = psInfo->width*mode;
|
||||||
unsigned char *row = (unsigned char *)malloc(rowbytes);
|
unsigned char *row = (unsigned char *)malloc(rowbytes);
|
||||||
INT32 y;
|
int y;
|
||||||
|
|
||||||
if (row == NULL) return;
|
if (row == NULL) return;
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ tImageTGA * tgaLoad(const char *pszFilename) {
|
||||||
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
tImageTGA *info;
|
tImageTGA *info;
|
||||||
INT32 mode,total;
|
int mode,total;
|
||||||
|
|
||||||
// allocate memory for the info struct and check!
|
// allocate memory for the info struct and check!
|
||||||
info = (tImageTGA *)malloc(sizeof(tImageTGA));
|
info = (tImageTGA *)malloc(sizeof(tImageTGA));
|
||||||
|
@ -243,7 +243,7 @@ tImageTGA * tgaLoad(const char *pszFilename) {
|
||||||
// converts RGB to greyscale
|
// converts RGB to greyscale
|
||||||
void tgaRGBtogreyscale(tImageTGA *psInfo) {
|
void tgaRGBtogreyscale(tImageTGA *psInfo) {
|
||||||
|
|
||||||
INT32 mode,i,j;
|
int mode,i,j;
|
||||||
|
|
||||||
unsigned char *newImageData;
|
unsigned char *newImageData;
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __SUPPORT_DATA_SUPPORT_TGALIB_H__
|
#ifndef __SUPPORT_DATA_SUPPORT_TGALIB_H__
|
||||||
#define __SUPPORT_DATA_SUPPORT_TGALIB_H__
|
#define __SUPPORT_DATA_SUPPORT_TGALIB_H__
|
||||||
|
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TGA_OK,
|
TGA_OK,
|
||||||
TGA_ERROR_FILE_OPEN,
|
TGA_ERROR_FILE_OPEN,
|
||||||
|
@ -38,7 +38,7 @@ enum {
|
||||||
|
|
||||||
/** TGA format */
|
/** TGA format */
|
||||||
typedef struct sImageTGA {
|
typedef struct sImageTGA {
|
||||||
INT32 status;
|
int status;
|
||||||
unsigned char type, pixelDepth;
|
unsigned char type, pixelDepth;
|
||||||
|
|
||||||
/** map width */
|
/** map width */
|
||||||
|
@ -49,7 +49,7 @@ typedef struct sImageTGA {
|
||||||
|
|
||||||
/** raw data */
|
/** raw data */
|
||||||
unsigned char *imageData;
|
unsigned char *imageData;
|
||||||
INT32 flipped;
|
int flipped;
|
||||||
} tImageTGA;
|
} tImageTGA;
|
||||||
|
|
||||||
/// load the image header fields. We only keep those that matter!
|
/// load the image header fields. We only keep those that matter!
|
||||||
|
@ -65,6 +65,6 @@ tImageTGA * tgaLoad(const char *pszFilename);
|
||||||
void tgaRGBtogreyscale(tImageTGA *psInfo);
|
void tgaRGBtogreyscale(tImageTGA *psInfo);
|
||||||
|
|
||||||
/// releases the memory used for the image
|
/// releases the memory used for the image
|
||||||
void tgaDestroy(tImageTGA *psInfo);
|
void tgaDestroy(tImageTGA *psInfo);
|
||||||
|
|
||||||
#endif // __SUPPORT_DATA_SUPPORT_TGALIB_H__
|
#endif // __SUPPORT_DATA_SUPPORT_TGALIB_H__
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCPVRTexture.h"
|
#include "CCPVRTexture.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
|
@ -209,7 +209,7 @@ bool CCPVRTexture::createGLTexture()
|
||||||
glBindTexture(GL_TEXTURE_2D, m_uName);
|
glBindTexture(GL_TEXTURE_2D, m_uName);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (UINT32 i=0; i < m_pImageData->count(); i++)
|
for (unsigned int i=0; i < m_pImageData->count(); i++)
|
||||||
{
|
{
|
||||||
/// @todo NSData data = m_pImageData->getObjectAtIndex(i);
|
/// @todo NSData data = m_pImageData->getObjectAtIndex(i);
|
||||||
/// @todo NSData glCompressedTexImage2D(GL_TEXTURE_2D, i, m_uInternalFormat, width, height, 0, [data length], [data bytes]);
|
/// @todo NSData glCompressedTexImage2D(GL_TEXTURE_2D, i, m_uInternalFormat, width, height, 0, [data length], [data bytes]);
|
||||||
|
@ -245,11 +245,11 @@ CCPVRTexture * CCPVRTexture::initWithContentsOfFile(const char* path)
|
||||||
|
|
||||||
m_bRetainName = false; // cocos2d integration
|
m_bRetainName = false; // cocos2d integration
|
||||||
/// @todo
|
/// @todo
|
||||||
// if (!data || ![self unpackPVRData:data] || ![self createGLTexture])
|
// if (!data || ![self unpackPVRData:data] || ![self createGLTexture])
|
||||||
// {
|
// {
|
||||||
// [self release];
|
// [self release];
|
||||||
// self = nil;
|
// self = nil;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,35 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Support for RGBA_4_4_4_4 and RGBA_5_5_5_1 was copied from:
|
* Support for RGBA_4_4_4_4 and RGBA_5_5_5_1 was copied from:
|
||||||
* https://devforums.apple.com/message/37855#37855 by a1studmuffin
|
* https://devforums.apple.com/message/37855#37855 by a1studmuffin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
#include <GLES/glext.h>
|
#include <GLES/glext.h>
|
||||||
|
|
||||||
#include "ccConfig.h"
|
#include "ccConfig.h"
|
||||||
|
@ -82,12 +82,12 @@ CCTexture2DPixelFormat CCTexture2D::getPixelFormat()
|
||||||
return m_ePixelFormat;
|
return m_ePixelFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT32 CCTexture2D::getPixelsWide()
|
unsigned int CCTexture2D::getPixelsWide()
|
||||||
{
|
{
|
||||||
return m_uPixelsWide;
|
return m_uPixelsWide;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT32 CCTexture2D::getPixelsHigh()
|
unsigned int CCTexture2D::getPixelsHigh()
|
||||||
{
|
{
|
||||||
return m_uPixelsHigh;
|
return m_uPixelsHigh;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ bool CCTexture2D::getHasPremultipliedAlpha()
|
||||||
return m_bHasPremultipliedAlpha;
|
return m_bHasPremultipliedAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTexture2D * CCTexture2D::initWithData(const void *data, CCTexture2DPixelFormat pixelFormat, UINT32 pixelsWide, UINT32 pixelsHigh, CGSize contentSize)
|
CCTexture2D * CCTexture2D::initWithData(const void *data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, CGSize contentSize)
|
||||||
{
|
{
|
||||||
glGenTextures(1, &m_uName);
|
glGenTextures(1, &m_uName);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_uName);
|
glBindTexture(GL_TEXTURE_2D, m_uName);
|
||||||
|
@ -173,10 +173,10 @@ CCTexture2D * CCTexture2D::initWithData(const void *data, CCTexture2DPixelFormat
|
||||||
|
|
||||||
std::string CCTexture2D::description(void)
|
std::string CCTexture2D::description(void)
|
||||||
{
|
{
|
||||||
char des[100];
|
char des[100];
|
||||||
sprintf_s(des, 100, "<CCTexture2D | Name = %u | Dimensions = %u x %u | Coordinates = (%.2f, %.2f)>", m_uName, m_uPixelsWide, m_uPixelsHigh, m_fMaxS, m_fMaxT);
|
sprintf_s(des, 100, "<CCTexture2D | Name = %u | Dimensions = %u x %u | Coordinates = (%.2f, %.2f)>", m_uName, m_uPixelsWide, m_uPixelsHigh, m_fMaxS, m_fMaxT);
|
||||||
std::string ret(des);
|
std::string ret(des);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ std::string CCTexture2D::description(void)
|
||||||
|
|
||||||
CCTexture2D* CCTexture2D::initWithImage(UIImage * uiImage)
|
CCTexture2D* CCTexture2D::initWithImage(UIImage * uiImage)
|
||||||
{
|
{
|
||||||
UINT32 POTWide, POTHigh;
|
unsigned int POTWide, POTHigh;
|
||||||
|
|
||||||
if(uiImage == NULL)
|
if(uiImage == NULL)
|
||||||
{
|
{
|
||||||
|
@ -221,9 +221,9 @@ CCTexture2D* CCTexture2D::initWithImage(UIImage * uiImage)
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
/// @todo to be checked
|
/// @todo to be checked
|
||||||
CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, UINT32 POTWide, UINT32 POTHigh)
|
CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, unsigned int POTWide, unsigned int POTHigh)
|
||||||
{
|
{
|
||||||
UINT32 i;
|
unsigned int i;
|
||||||
void* data = NULL;
|
void* data = NULL;
|
||||||
void* tempData =NULL;
|
void* tempData =NULL;
|
||||||
unsigned int* inPixel32 = NULL;
|
unsigned int* inPixel32 = NULL;
|
||||||
|
@ -264,25 +264,25 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, UI
|
||||||
case kCCTexture2DPixelFormat_RGB5A1:
|
case kCCTexture2DPixelFormat_RGB5A1:
|
||||||
// colorSpace = CGColorSpaceCreateDeviceRGB();
|
// colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||||
// data = malloc(POTHigh * POTWide * 4);
|
// data = malloc(POTHigh * POTWide * 4);
|
||||||
// info = hasAlpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipLast;
|
// info = hasAlpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipLast;
|
||||||
// context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, 4 * POTWide, colorSpace, info | kCGBitmapByteOrder32Big);
|
// context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, 4 * POTWide, colorSpace, info | kCGBitmapByteOrder32Big);
|
||||||
// CGColorSpaceRelease(colorSpace);
|
// CGColorSpaceRelease(colorSpace);
|
||||||
// break;
|
// break;
|
||||||
case kCCTexture2DPixelFormat_RGB565:
|
case kCCTexture2DPixelFormat_RGB565:
|
||||||
// colorSpace = CGColorSpaceCreateDeviceRGB();
|
// colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||||
// data = malloc(POTHigh * POTWide * 4);
|
// data = malloc(POTHigh * POTWide * 4);
|
||||||
// info = kCGImageAlphaNoneSkipLast;
|
// info = kCGImageAlphaNoneSkipLast;
|
||||||
// context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, 4 * POTWide, colorSpace, info | kCGBitmapByteOrder32Big);
|
// context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, 4 * POTWide, colorSpace, info | kCGBitmapByteOrder32Big);
|
||||||
// CGColorSpaceRelease(colorSpace);
|
// CGColorSpaceRelease(colorSpace);
|
||||||
// break;
|
// break;
|
||||||
case kCCTexture2DPixelFormat_A8:
|
case kCCTexture2DPixelFormat_A8:
|
||||||
// data = malloc(POTHigh * POTWide);
|
// data = malloc(POTHigh * POTWide);
|
||||||
// info = kCGImageAlphaOnly;
|
// info = kCGImageAlphaOnly;
|
||||||
// context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, NULL, info);
|
// context = CGBitmapContextCreate(data, POTWide, POTHigh, 8, POTWide, NULL, info);
|
||||||
|
|
||||||
/// @todo Get image data and convert to POT mode
|
/// @todo Get image data and convert to POT mode
|
||||||
tempData = static_cast<void*>(image->getRGBA8888Data());
|
tempData = static_cast<void*>(image->getRGBA8888Data());
|
||||||
NSAssert(tempData != NULL, "NULL image data.");
|
NSAssert(tempData != NULL, "NULL image data.");
|
||||||
if(image->width() == POTWide && image->height() == POTHigh)
|
if(image->width() == POTWide && image->height() == POTHigh)
|
||||||
{
|
{
|
||||||
data = tempData;
|
data = tempData;
|
||||||
|
@ -295,12 +295,12 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, UI
|
||||||
UINT8* pPixelData = (UINT8*) tempData;
|
UINT8* pPixelData = (UINT8*) tempData;
|
||||||
UINT8* pTargetData = (UINT8*) data;
|
UINT8* pTargetData = (UINT8*) data;
|
||||||
|
|
||||||
for(UINT32 y=0; y<image->height(); ++y)
|
for(unsigned int y=0; y<image->height(); ++y)
|
||||||
{
|
{
|
||||||
memcpy(pTargetData+POTWide*4*y, pPixelData+(image->width())*4*y, (image->width())*4);
|
memcpy(pTargetData+POTWide*4*y, pPixelData+(image->width())*4*y, (image->width())*4);
|
||||||
}
|
}
|
||||||
CCX_SAFE_DELETE(tempData);
|
CCX_SAFE_DELETE(tempData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NSAssert(0, "Invalid pixel format");
|
NSAssert(0, "Invalid pixel format");
|
||||||
|
@ -308,9 +308,9 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, UI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// CGContextClearRect(context, CGRectMake(0, 0, POTWide, POTHigh));
|
// CGContextClearRect(context, CGRectMake(0, 0, POTWide, POTHigh));
|
||||||
// CGContextTranslateCTM(context, 0, POTHigh - imageSize.height);
|
// CGContextTranslateCTM(context, 0, POTHigh - imageSize.height);
|
||||||
// CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image);
|
// CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image);
|
||||||
|
|
||||||
// Repack the pixel data into the right format
|
// Repack the pixel data into the right format
|
||||||
|
|
||||||
|
@ -359,8 +359,8 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, UI
|
||||||
data = tempData;
|
data = tempData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
this->initWithData(data, pixelFormat, POTWide, POTHigh, imageSize);
|
this->initWithData(data, pixelFormat, POTWide, POTHigh, imageSize);
|
||||||
|
|
||||||
// should be after calling super init
|
// should be after calling super init
|
||||||
|
@ -368,7 +368,7 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, UI
|
||||||
|
|
||||||
//CGContextRelease(context);
|
//CGContextRelease(context);
|
||||||
CCX_SAFE_DELETE(data);
|
CCX_SAFE_DELETE(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -544,12 +544,12 @@ CCTexture2D * CCTexture2D::initWithPVRTCData(const void *data, int level, int bp
|
||||||
|
|
||||||
CCTexture2D * CCTexture2D::initWithPVRTCFile(const char* file)
|
CCTexture2D * CCTexture2D::initWithPVRTCFile(const char* file)
|
||||||
{
|
{
|
||||||
if (! CCConfiguration::sharedConfiguration()->isSupportsPVRTC())
|
if (! CCConfiguration::sharedConfiguration()->isSupportsPVRTC())
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: WARNING: PVRTC images is not supported");
|
CCLOG("cocos2d: WARNING: PVRTC images is not supported");
|
||||||
this->release();
|
this->release();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCPVRTexture *pvr = new CCPVRTexture();
|
CCPVRTexture *pvr = new CCPVRTexture();
|
||||||
pvr = pvr->initWithContentsOfFile(file);
|
pvr = pvr->initWithContentsOfFile(file);
|
||||||
|
@ -562,7 +562,7 @@ CCTexture2D * CCTexture2D::initWithPVRTCFile(const char* file)
|
||||||
m_fMaxT = 1.0f;
|
m_fMaxT = 1.0f;
|
||||||
m_uPixelsWide = pvr->getWidth(); // width
|
m_uPixelsWide = pvr->getWidth(); // width
|
||||||
m_uPixelsHigh = pvr->getHeight(); // height
|
m_uPixelsHigh = pvr->getHeight(); // height
|
||||||
/// be careful : UINT32 to float
|
/// be careful : unsigned int to float
|
||||||
m_tContentSize = CGSizeMake(static_cast<float>(m_uPixelsWide), static_cast<float>(m_uPixelsHigh));
|
m_tContentSize = CGSizeMake(static_cast<float>(m_uPixelsWide), static_cast<float>(m_uPixelsHigh));
|
||||||
|
|
||||||
pvr->release();
|
pvr->release();
|
||||||
|
@ -629,4 +629,4 @@ CCTexture2DPixelFormat CCTexture2D::defaultAlphaPixelFormat()
|
||||||
{
|
{
|
||||||
return g_defaultAlphaPixelFormat;
|
return g_defaultAlphaPixelFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "Cocos2dDefine.h"
|
#include "Cocos2dDefine.h"
|
||||||
// cocos2d
|
// cocos2d
|
||||||
#include "CCTextureAtlas.h"
|
#include "CCTextureAtlas.h"
|
||||||
|
@ -31,6 +31,8 @@ THE SOFTWARE.
|
||||||
// support
|
// support
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
//According to some tests GL_TRIANGLE_STRIP is slower, MUCH slower. Probably I'm doing something very wrong
|
//According to some tests GL_TRIANGLE_STRIP is slower, MUCH slower. Probably I'm doing something very wrong
|
||||||
|
|
||||||
// implementation CCTextureAtlas
|
// implementation CCTextureAtlas
|
||||||
|
@ -55,12 +57,12 @@ CCTextureAtlas::~CCTextureAtlas()
|
||||||
m_pTexture->release();
|
m_pTexture->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT32 CCTextureAtlas::getTotalQuads()
|
unsigned int CCTextureAtlas::getTotalQuads()
|
||||||
{
|
{
|
||||||
return m_uTotalQuads;
|
return m_uTotalQuads;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT32 CCTextureAtlas::getCapacity()
|
unsigned int CCTextureAtlas::getCapacity()
|
||||||
{
|
{
|
||||||
return m_uCapacity;
|
return m_uCapacity;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +89,7 @@ void CCTextureAtlas::setQuads(ccV3F_C4B_T2F_Quad *var)
|
||||||
|
|
||||||
// TextureAtlas - alloc & init
|
// TextureAtlas - alloc & init
|
||||||
|
|
||||||
CCTextureAtlas * CCTextureAtlas::textureAtlasWithFile(const char* file, UINT32 capacity)
|
CCTextureAtlas * CCTextureAtlas::textureAtlasWithFile(const char* file, unsigned int capacity)
|
||||||
{
|
{
|
||||||
CCTextureAtlas * pTextureAtlas = new CCTextureAtlas();
|
CCTextureAtlas * pTextureAtlas = new CCTextureAtlas();
|
||||||
pTextureAtlas->initWithFile(file, capacity);
|
pTextureAtlas->initWithFile(file, capacity);
|
||||||
|
@ -95,7 +97,7 @@ CCTextureAtlas * CCTextureAtlas::textureAtlasWithFile(const char* file, UINT32 c
|
||||||
return pTextureAtlas;
|
return pTextureAtlas;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTextureAtlas * CCTextureAtlas::textureAtlasWithTexture(CCTexture2D *tex, UINT32 capacity)
|
CCTextureAtlas * CCTextureAtlas::textureAtlasWithTexture(CCTexture2D *tex, unsigned int capacity)
|
||||||
{
|
{
|
||||||
CCTextureAtlas * pTextureAtlas = new CCTextureAtlas();
|
CCTextureAtlas * pTextureAtlas = new CCTextureAtlas();
|
||||||
pTextureAtlas->initWithTexture(tex, capacity);
|
pTextureAtlas->initWithTexture(tex, capacity);
|
||||||
|
@ -103,7 +105,7 @@ CCTextureAtlas * CCTextureAtlas::textureAtlasWithTexture(CCTexture2D *tex, UINT3
|
||||||
return pTextureAtlas;
|
return pTextureAtlas;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTextureAtlas * CCTextureAtlas::initWithFile(const char * file, UINT32 capacity)
|
CCTextureAtlas * CCTextureAtlas::initWithFile(const char * file, unsigned int capacity)
|
||||||
{
|
{
|
||||||
// retained in property
|
// retained in property
|
||||||
CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addImage(file);
|
CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addImage(file);
|
||||||
|
@ -111,7 +113,7 @@ CCTextureAtlas * CCTextureAtlas::initWithFile(const char * file, UINT32 capacity
|
||||||
return initWithTexture(tex, capacity);
|
return initWithTexture(tex, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTextureAtlas * CCTextureAtlas::initWithTexture(CCTexture2D *tex, UINT32 capacity)
|
CCTextureAtlas * CCTextureAtlas::initWithTexture(CCTexture2D *tex, unsigned int capacity)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_uCapacity = capacity;
|
m_uCapacity = capacity;
|
||||||
|
@ -142,17 +144,17 @@ CCTextureAtlas * CCTextureAtlas::initWithTexture(CCTexture2D *tex, UINT32 capaci
|
||||||
|
|
||||||
std::string CCTextureAtlas::description()
|
std::string CCTextureAtlas::description()
|
||||||
{
|
{
|
||||||
char des[100];
|
char des[100];
|
||||||
sprintf_s(des, 100, "<CCTextureAtlas | totalQuads = %u>", m_uTotalQuads);
|
sprintf_s(des, 100, "<CCTextureAtlas | totalQuads = %u>", m_uTotalQuads);
|
||||||
std::string ret(des);
|
std::string ret(des);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CCTextureAtlas::initIndices()
|
void CCTextureAtlas::initIndices()
|
||||||
{
|
{
|
||||||
for( UINT32 i=0; i < m_uCapacity; i++)
|
for( unsigned int i=0; i < m_uCapacity; i++)
|
||||||
{
|
{
|
||||||
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
|
#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
|
||||||
m_pIndices[i*6+0] = i*4+0;
|
m_pIndices[i*6+0] = i*4+0;
|
||||||
|
@ -188,16 +190,16 @@ void CCTextureAtlas::initIndices()
|
||||||
|
|
||||||
// TextureAtlas - Update, Insert, Move & Remove
|
// TextureAtlas - Update, Insert, Move & Remove
|
||||||
|
|
||||||
void CCTextureAtlas::updateQuad(ccV3F_C4B_T2F_Quad *quad, UINT32 index)
|
void CCTextureAtlas::updateQuad(ccV3F_C4B_T2F_Quad *quad, unsigned int index)
|
||||||
{
|
{
|
||||||
NSAssert( index >= 0 && index < m_uCapacity, "updateQuadWithTexture: Invalid index");
|
NSAssert( index >= 0 && index < m_uCapacity, "updateQuadWithTexture: Invalid index");
|
||||||
|
|
||||||
m_uTotalQuads = MAX( index+1, m_uTotalQuads);
|
m_uTotalQuads = max( index+1, m_uTotalQuads);
|
||||||
|
|
||||||
m_pQuads[index] = *quad;
|
m_pQuads[index] = *quad;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureAtlas::insertQuad(ccV3F_C4B_T2F_Quad *quad, UINT32 index)
|
void CCTextureAtlas::insertQuad(ccV3F_C4B_T2F_Quad *quad, unsigned int index)
|
||||||
{
|
{
|
||||||
NSAssert( index >= 0 && index < m_uCapacity, "insertQuadWithTexture: Invalid index");
|
NSAssert( index >= 0 && index < m_uCapacity, "insertQuadWithTexture: Invalid index");
|
||||||
|
|
||||||
|
@ -216,7 +218,7 @@ void CCTextureAtlas::insertQuad(ccV3F_C4B_T2F_Quad *quad, UINT32 index)
|
||||||
m_pQuads[index] = *quad;
|
m_pQuads[index] = *quad;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureAtlas::insertQuadFromIndex(UINT32 oldIndex, UINT32 newIndex)
|
void CCTextureAtlas::insertQuadFromIndex(unsigned int oldIndex, unsigned int newIndex)
|
||||||
{
|
{
|
||||||
NSAssert( newIndex >= 0 && newIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
NSAssert( newIndex >= 0 && newIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
||||||
NSAssert( oldIndex >= 0 && oldIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
NSAssert( oldIndex >= 0 && oldIndex < m_uTotalQuads, "insertQuadFromIndex:atIndex: Invalid index");
|
||||||
|
@ -224,7 +226,7 @@ void CCTextureAtlas::insertQuadFromIndex(UINT32 oldIndex, UINT32 newIndex)
|
||||||
if( oldIndex == newIndex )
|
if( oldIndex == newIndex )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UINT32 howMany = std::abs( oldIndex - newIndex);
|
unsigned int howMany = std::abs( oldIndex - newIndex);
|
||||||
int dst = oldIndex;
|
int dst = oldIndex;
|
||||||
int src = oldIndex + 1;
|
int src = oldIndex + 1;
|
||||||
if( oldIndex > newIndex) {
|
if( oldIndex > newIndex) {
|
||||||
|
@ -238,11 +240,11 @@ void CCTextureAtlas::insertQuadFromIndex(UINT32 oldIndex, UINT32 newIndex)
|
||||||
m_pQuads[newIndex] = quadsBackup;
|
m_pQuads[newIndex] = quadsBackup;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureAtlas::removeQuadAtIndex(UINT32 index)
|
void CCTextureAtlas::removeQuadAtIndex(unsigned int index)
|
||||||
{
|
{
|
||||||
NSAssert( index >= 0 && index < m_uTotalQuads, "removeQuadAtIndex: Invalid index");
|
NSAssert( index >= 0 && index < m_uTotalQuads, "removeQuadAtIndex: Invalid index");
|
||||||
|
|
||||||
UINT32 remaining = (m_uTotalQuads-1) - index;
|
unsigned int remaining = (m_uTotalQuads-1) - index;
|
||||||
|
|
||||||
|
|
||||||
// last object doesn't need to be moved
|
// last object doesn't need to be moved
|
||||||
|
@ -262,13 +264,13 @@ void CCTextureAtlas::removeAllQuads()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TextureAtlas - Resize
|
// TextureAtlas - Resize
|
||||||
bool CCTextureAtlas::resizeCapacity(UINT32 newCapacity)
|
bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity)
|
||||||
{
|
{
|
||||||
if( newCapacity == m_uCapacity )
|
if( newCapacity == m_uCapacity )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// update capacity and totolQuads
|
// update capacity and totolQuads
|
||||||
m_uTotalQuads = MIN(m_uTotalQuads, newCapacity);
|
m_uTotalQuads = min(m_uTotalQuads, newCapacity);
|
||||||
m_uCapacity = newCapacity;
|
m_uCapacity = newCapacity;
|
||||||
|
|
||||||
void * tmpQuads = realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity );
|
void * tmpQuads = realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity );
|
||||||
|
@ -307,7 +309,7 @@ void CCTextureAtlas::drawQuads()
|
||||||
this->drawNumberOfQuads(m_uTotalQuads);
|
this->drawNumberOfQuads(m_uTotalQuads);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureAtlas::drawNumberOfQuads(UINT32 n)
|
void CCTextureAtlas::drawNumberOfQuads(unsigned int n)
|
||||||
{
|
{
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_pTexture->getName());
|
glBindTexture(GL_TEXTURE_2D, m_pTexture->getName());
|
||||||
|
@ -365,4 +367,4 @@ void CCTextureAtlas::drawNumberOfQuads(UINT32 n)
|
||||||
#endif // CC_TEXTURE_ATLAS_USES_VBO
|
#endif // CC_TEXTURE_ATLAS_USES_VBO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,34 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
Copyright (c) 2010 cocos2d-x.org
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include "CCTextureCache.h"
|
#include "CCTextureCache.h"
|
||||||
#include "CCTexture2D.h"
|
#include "CCTexture2D.h"
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include "cocoa/NSData.h"
|
#include "cocoa/NSData.h"
|
||||||
#include "platform/platform.h"
|
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
|
|
||||||
/// @todo EAGLContext static EAGLContext *auxEAGLcontext = NULL;
|
/// @todo EAGLContext static EAGLContext *auxEAGLcontext = NULL;
|
||||||
|
@ -77,13 +76,13 @@ CCTextureCache::~CCTextureCache()
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: deallocing CCTextureCache.");
|
CCLOG("cocos2d: deallocing CCTextureCache.");
|
||||||
/// @todo release
|
/// @todo release
|
||||||
// [textures release];
|
// [textures release];
|
||||||
// [dictLock release];
|
// [dictLock release];
|
||||||
// [contextLock release];
|
// [contextLock release];
|
||||||
// [auxEAGLcontext release];
|
// [auxEAGLcontext release];
|
||||||
// auxEAGLcontext = nil;
|
// auxEAGLcontext = nil;
|
||||||
// sharedTextureCache = nil;
|
// sharedTextureCache = nil;
|
||||||
// [super dealloc];
|
// [super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureCache::purgeSharedTextureCache()
|
void CCTextureCache::purgeSharedTextureCache()
|
||||||
|
@ -94,10 +93,10 @@ void CCTextureCache::purgeSharedTextureCache()
|
||||||
|
|
||||||
std::string CCTextureCache::description()
|
std::string CCTextureCache::description()
|
||||||
{
|
{
|
||||||
char des[100];
|
char des[100];
|
||||||
sprintf_s(des, 100, "<CCTextureCache | Number of textures = %u>", m_pTextures->count());
|
sprintf_s(des, 100, "<CCTextureCache | Number of textures = %u>", m_pTextures->count());
|
||||||
std::string ret(des);
|
std::string ret(des);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,26 +145,30 @@ void CCTextureCache::addImageAsync(const char* filename, NSObject *target, fpAsy
|
||||||
// optimization
|
// optimization
|
||||||
|
|
||||||
CCTexture2D * tex;
|
CCTexture2D * tex;
|
||||||
//
|
//
|
||||||
// if ( (tex = m_pTextures->objectForKey(filename)) )
|
// if ( (tex = m_pTextures->objectForKey(filename)) )
|
||||||
// {
|
|
||||||
// target->
|
// {
|
||||||
// }
|
|
||||||
//
|
// target->
|
||||||
// if( (tex=[textures objectForKey: filename] ) ) {
|
|
||||||
// [target performSelector:selector withObject:tex];
|
// }
|
||||||
// return;
|
|
||||||
// }
|
//
|
||||||
//
|
// if( (tex=[textures objectForKey: filename] ) ) {
|
||||||
// // schedule the load
|
// [target performSelector:selector withObject:tex];
|
||||||
//
|
// return;
|
||||||
// CCAsyncObject *asyncObject = [[CCAsyncObject alloc] init];
|
// }
|
||||||
// asyncObject.selector = selector;
|
//
|
||||||
// asyncObject.target = target;
|
// // schedule the load
|
||||||
// asyncObject.data = filename;
|
//
|
||||||
//
|
// CCAsyncObject *asyncObject = [[CCAsyncObject alloc] init];
|
||||||
// [NSThread detachNewThreadSelector:@selector(addImageWithAsyncObject:) toTarget:self withObject:asyncObject];
|
// asyncObject.selector = selector;
|
||||||
// [asyncObject release];
|
// asyncObject.target = target;
|
||||||
|
// asyncObject.data = filename;
|
||||||
|
//
|
||||||
|
// [NSThread detachNewThreadSelector:@selector(addImageWithAsyncObject:) toTarget:self withObject:asyncObject];
|
||||||
|
// [asyncObject release];
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTexture2D * CCTextureCache::addImage(const char * path)
|
CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
|
@ -189,12 +192,12 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
|
||||||
|
|
||||||
// all images are handled by UIImage except PVR extension that is handled by our own handler
|
// all images are handled by UIImage except PVR extension that is handled by our own handler
|
||||||
// if ( [[path lowercaseString] hasSuffix:@".pvr"] )
|
// if ( [[path lowercaseString] hasSuffix:@".pvr"] )
|
||||||
for (UINT32 i = 0; i < temp.length(); ++i)
|
for (unsigned int i = 0; i < temp.length(); ++i)
|
||||||
temp[i] = tolower(temp[i]);
|
temp[i] = tolower(temp[i]);
|
||||||
if (temp.find(".pvr"))
|
if (temp.find(".pvr"))
|
||||||
{
|
{
|
||||||
tex = this->addPVRTCImage(fullpath.c_str());
|
tex = this->addPVRTCImage(fullpath.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// prevents overloading the autorelease pool
|
// prevents overloading the autorelease pool
|
||||||
|
@ -227,10 +230,10 @@ CCTexture2D* CCTextureCache::addPVRTCImage(const char* path, int bpp, bool hasAl
|
||||||
|
|
||||||
CCTexture2D * tex;
|
CCTexture2D * tex;
|
||||||
std::string temp(path);
|
std::string temp(path);
|
||||||
if ( (tex = m_pTextures->objectForKey(temp)) )
|
if ( (tex = m_pTextures->objectForKey(temp)) )
|
||||||
{
|
{
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split up directory and filename
|
// Split up directory and filename
|
||||||
std::string fullpath( CCFileUtils::fullPathFromRelativePath(path) );
|
std::string fullpath( CCFileUtils::fullPathFromRelativePath(path) );
|
||||||
|
@ -307,15 +310,15 @@ 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)
|
||||||
{
|
{
|
||||||
CCLOG("cocos2d: CCTextureCache: removing unused texture: %s", (*it).c_str());
|
CCLOG("cocos2d: CCTextureCache: removing unused texture: %s", (*it).c_str());
|
||||||
m_pTextures->removeObjectForKey(*it);
|
m_pTextures->removeObjectForKey(*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureCache::removeTexture(CCTexture2D* tex)
|
void CCTextureCache::removeTexture(CCTexture2D* tex)
|
||||||
|
@ -325,10 +328,10 @@ void CCTextureCache::removeTexture(CCTexture2D* tex)
|
||||||
|
|
||||||
std::vector<std::string> keys = m_pTextures->allKeysForObject(tex);
|
std::vector<std::string> keys = m_pTextures->allKeysForObject(tex);
|
||||||
|
|
||||||
for (UINT32 i = 0; i < keys.size(); i++)
|
for (unsigned int i = 0; i < keys.size(); i++)
|
||||||
{
|
{
|
||||||
m_pTextures->removeObjectForKey(keys[i]);
|
m_pTextures->removeObjectForKey(keys[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTextureCache::removeTextureForKey(const std::string & textureKeyName)
|
void CCTextureCache::removeTextureForKey(const std::string & textureKeyName)
|
||||||
|
|
|
@ -56,13 +56,13 @@ CCTouchDispatcher* CCTouchDispatcher::getSharedDispatcher(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
+(id) allocWithZone:(NSZone *)zone
|
+(id) allocWithZone:(NSZone *)zone
|
||||||
{
|
{
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
NSAssert(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton.");
|
NSAssert(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton.");
|
||||||
return [super allocWithZone:zone];
|
return [super allocWithZone:zone];
|
||||||
}
|
}
|
||||||
return nil; // on subsequent allocation attempts return nil
|
return nil; // on subsequent allocation attempts return nil
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -96,12 +96,12 @@ CCTouchDispatcher::~CCTouchDispatcher(void)
|
||||||
m_pHandlersToRemove->release();
|
m_pHandlersToRemove->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// handlers management
|
// handlers management
|
||||||
//
|
//
|
||||||
void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, NSMutableArray<CCTouchHandler*> *pArray)
|
void CCTouchDispatcher::forceAddHandler(CCTouchHandler *pHandler, NSMutableArray<CCTouchHandler*> *pArray)
|
||||||
{
|
{
|
||||||
UINT32 u = 0;
|
unsigned int u = 0;
|
||||||
|
|
||||||
NSMutableArray<CCTouchHandler*>::NSMutableArrayIterator iter;
|
NSMutableArray<CCTouchHandler*>::NSMutableArrayIterator iter;
|
||||||
for (iter = pArray->begin(); iter != pArray->end(); ++iter)
|
for (iter = pArray->begin(); iter != pArray->end(); ++iter)
|
||||||
|
@ -226,10 +226,10 @@ void CCTouchDispatcher::setPriority(int nPriority, CCTouchDelegate *pDelegate)
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// dispatch events
|
|
||||||
//
|
//
|
||||||
void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, UINT32 uIndex)
|
// dispatch events
|
||||||
|
//
|
||||||
|
void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, unsigned int uIndex)
|
||||||
{
|
{
|
||||||
assert(uIndex > 0 && uIndex < 4);
|
assert(uIndex > 0 && uIndex < 4);
|
||||||
|
|
||||||
|
@ -237,15 +237,15 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, UINT32 uIndex)
|
||||||
m_bLocked = true;
|
m_bLocked = true;
|
||||||
|
|
||||||
// optimization to prevent a mutable copy when it is not necessary
|
// optimization to prevent a mutable copy when it is not necessary
|
||||||
UINT32 uTargetedHandlersCount = m_pTargetedHandlers->count();
|
unsigned int uTargetedHandlersCount = m_pTargetedHandlers->count();
|
||||||
UINT32 uStandardHandlersCount = m_pStandardHandlers->count();
|
unsigned int uStandardHandlersCount = m_pStandardHandlers->count();
|
||||||
bool bNeedsMutableSet = (uTargetedHandlersCount && uStandardHandlersCount);
|
bool bNeedsMutableSet = (uTargetedHandlersCount && uStandardHandlersCount);
|
||||||
|
|
||||||
pMutableTouches = (bNeedsMutableSet ? pTouches->mutableCopy() : pTouches);
|
pMutableTouches = (bNeedsMutableSet ? pTouches->mutableCopy() : pTouches);
|
||||||
|
|
||||||
struct ccTouchHandlerHelperData sHelper = m_sHandlerHelperData[uIndex];
|
struct ccTouchHandlerHelperData sHelper = m_sHandlerHelperData[uIndex];
|
||||||
//
|
//
|
||||||
// process the target handlers 1st
|
// process the target handlers 1st
|
||||||
//
|
//
|
||||||
if (uTargetedHandlersCount > 0)
|
if (uTargetedHandlersCount > 0)
|
||||||
{
|
{
|
||||||
|
@ -301,8 +301,8 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, UINT32 uIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// process standard handlers 2nd
|
// process standard handlers 2nd
|
||||||
//
|
//
|
||||||
if (uStandardHandlersCount > 0 && pMutableTouches->count() > 0)
|
if (uStandardHandlersCount > 0 && pMutableTouches->count() > 0)
|
||||||
{
|
{
|
||||||
|
@ -335,9 +335,9 @@ void CCTouchDispatcher::touches(NSSet *pTouches, UIEvent *pEvent, UINT32 uIndex)
|
||||||
pMutableTouches->release();
|
pMutableTouches->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Optimization. To prevent a [handlers copy] which is expensive
|
// Optimization. To prevent a [handlers copy] which is expensive
|
||||||
// the add/removes/quit is done after the iterations
|
// the add/removes/quit is done after the iterations
|
||||||
//
|
//
|
||||||
m_bLocked = false;
|
m_bLocked = false;
|
||||||
if (m_bToRemove)
|
if (m_bToRemove)
|
||||||
|
|
|
@ -29,60 +29,60 @@ THE SOFTWARE.
|
||||||
#include "cocoa/NSObject.h"
|
#include "cocoa/NSObject.h"
|
||||||
#include "cocoa/NSMutableArray.h"
|
#include "cocoa/NSMutableArray.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
ccTouchSelectorBeganBit = 1 << 0,
|
ccTouchSelectorBeganBit = 1 << 0,
|
||||||
ccTouchSelectorMovedBit = 1 << 1,
|
ccTouchSelectorMovedBit = 1 << 1,
|
||||||
ccTouchSelectorEndedBit = 1 << 2,
|
ccTouchSelectorEndedBit = 1 << 2,
|
||||||
ccTouchSelectorCancelledBit = 1 << 3,
|
ccTouchSelectorCancelledBit = 1 << 3,
|
||||||
ccTouchSelectorAllBits = ( ccTouchSelectorBeganBit | ccTouchSelectorMovedBit | ccTouchSelectorEndedBit | ccTouchSelectorCancelledBit),
|
ccTouchSelectorAllBits = ( ccTouchSelectorBeganBit | ccTouchSelectorMovedBit | ccTouchSelectorEndedBit | ccTouchSelectorCancelledBit),
|
||||||
} ccTouchSelectorFlag;
|
} ccTouchSelectorFlag;
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ccTouchBegan,
|
ccTouchBegan,
|
||||||
ccTouchMoved,
|
ccTouchMoved,
|
||||||
ccTouchEnded,
|
ccTouchEnded,
|
||||||
ccTouchCancelled,
|
ccTouchCancelled,
|
||||||
|
|
||||||
ccTouchMax,
|
ccTouchMax,
|
||||||
};
|
};
|
||||||
|
|
||||||
class NSSet;
|
class NSSet;
|
||||||
class UIEvent;
|
class UIEvent;
|
||||||
|
|
||||||
struct ccTouchHandlerHelperData {
|
struct ccTouchHandlerHelperData {
|
||||||
// we only use the type
|
// we only use the type
|
||||||
// void (StandardTouchDelegate::*touchesSel)(NSSet*, UIEvent*);
|
// void (StandardTouchDelegate::*touchesSel)(NSSet*, UIEvent*);
|
||||||
// void (TargetedTouchDelegate::*touchSel)(NSTouch*, UIEvent*);
|
// void (TargetedTouchDelegate::*touchSel)(NSTouch*, UIEvent*);
|
||||||
int m_type;
|
int m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class EGLTouchDelegate
|
class EGLTouchDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void touchesBegan(NSSet* touches, UIEvent* pEvent) = 0;
|
virtual void touchesBegan(NSSet* touches, UIEvent* pEvent) = 0;
|
||||||
virtual void touchesMoved(NSSet* touches, UIEvent* pEvent) = 0;
|
virtual void touchesMoved(NSSet* touches, UIEvent* pEvent) = 0;
|
||||||
virtual void touchesEnded(NSSet* touches, UIEvent* pEvent) = 0;
|
virtual void touchesEnded(NSSet* touches, UIEvent* pEvent) = 0;
|
||||||
virtual void touchesCancelled(NSSet* touches, UIEvent* pEvent) = 0;
|
virtual void touchesCancelled(NSSet* touches, UIEvent* pEvent) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** CCTouchDispatcher.
|
/** CCTouchDispatcher.
|
||||||
Singleton that handles all the touch events.
|
Singleton that handles all the touch events.
|
||||||
The dispatcher dispatches events to the registered TouchHandlers.
|
The dispatcher dispatches events to the registered TouchHandlers.
|
||||||
There are 2 different type of touch handlers:
|
There are 2 different type of touch handlers:
|
||||||
- Standard Touch Handlers
|
- Standard Touch Handlers
|
||||||
- Targeted Touch Handlers
|
- Targeted Touch Handlers
|
||||||
|
|
||||||
The Standard Touch Handlers work like the CocoaTouch touch handler: a set of touches is passed to the delegate.
|
The Standard Touch Handlers work like the CocoaTouch touch handler: a set of touches is passed to the delegate.
|
||||||
On the other hand, the Targeted Touch Handlers only receive 1 touch at the time, and they can "swallow" touches (avoid the propagation of the event).
|
On the other hand, the Targeted Touch Handlers only receive 1 touch at the time, and they can "swallow" touches (avoid the propagation of the event).
|
||||||
|
|
||||||
Firstly, the dispatcher sends the received touches to the targeted touches.
|
Firstly, the dispatcher sends the received touches to the targeted touches.
|
||||||
These touches can be swallowed by the Targeted Touch Handlers. If there are still remaining touches, then the remaining touches will be sent
|
These touches can be swallowed by the Targeted Touch Handlers. If there are still remaining touches, then the remaining touches will be sent
|
||||||
to the Standard Touch Handlers.
|
to the Standard Touch Handlers.
|
||||||
|
|
||||||
@since v0.8.0
|
@since v0.8.0
|
||||||
*/
|
*/
|
||||||
class CCTouchHandler;
|
class CCTouchHandler;
|
||||||
class CCTouchDispatcher : public NSObject, public EGLTouchDelegate
|
class CCTouchDispatcher : public NSObject, public EGLTouchDelegate
|
||||||
|
@ -97,35 +97,35 @@ public:
|
||||||
bool isDispatchEvents(void);
|
bool isDispatchEvents(void);
|
||||||
void setDispatchEvents(bool bDispatchEvents);
|
void setDispatchEvents(bool bDispatchEvents);
|
||||||
|
|
||||||
/** Adds a standard touch delegate to the dispatcher's list.
|
/** Adds a standard touch delegate to the dispatcher's list.
|
||||||
See StandardTouchDelegate description.
|
See StandardTouchDelegate description.
|
||||||
IMPORTANT: The delegate will be retained.
|
IMPORTANT: The delegate will be retained.
|
||||||
*/
|
*/
|
||||||
void addStandardDelegate(CCStandardTouchDelegate *pDelegate, int nPriority);
|
void addStandardDelegate(CCStandardTouchDelegate *pDelegate, int nPriority);
|
||||||
|
|
||||||
/** Adds a targeted touch delegate to the dispatcher's list.
|
/** Adds a targeted touch delegate to the dispatcher's list.
|
||||||
See TargetedTouchDelegate description.
|
See TargetedTouchDelegate description.
|
||||||
IMPORTANT: The delegate will be retained.
|
IMPORTANT: The delegate will be retained.
|
||||||
*/
|
*/
|
||||||
void addTargetedDelegate(CCTargetedTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches);
|
void addTargetedDelegate(CCTargetedTouchDelegate *pDelegate, int nPriority, bool bSwallowsTouches);
|
||||||
|
|
||||||
/** Removes a touch delegate.
|
/** Removes a touch delegate.
|
||||||
The delegate will be released
|
The delegate will be released
|
||||||
*/
|
*/
|
||||||
void removeDelegate(CCTouchDelegate *pDelegate);
|
void removeDelegate(CCTouchDelegate *pDelegate);
|
||||||
|
|
||||||
// Removes all touch delegates, releasing all the delegates
|
// Removes all touch delegates, releasing all the delegates
|
||||||
void removeAllDelegates(void);
|
void removeAllDelegates(void);
|
||||||
|
|
||||||
/** Changes the priority of a previously added delegate. The lower the number,
|
/** Changes the priority of a previously added delegate. The lower the number,
|
||||||
the higher the priority */
|
the higher the priority */
|
||||||
void setPriority(int nPriority, CCTouchDelegate *pDelegate);
|
void setPriority(int nPriority, CCTouchDelegate *pDelegate);
|
||||||
|
|
||||||
void touches(NSSet *pTouches, UIEvent *pEvent, UINT32 uIndex);
|
void touches(NSSet *pTouches, UIEvent *pEvent, unsigned int uIndex);
|
||||||
|
|
||||||
virtual void touchesBegan(NSSet* touches, UIEvent* pEvent);
|
virtual void touchesBegan(NSSet* touches, UIEvent* pEvent);
|
||||||
virtual void touchesMoved(NSSet* touches, UIEvent* pEvent);
|
virtual void touchesMoved(NSSet* touches, UIEvent* pEvent);
|
||||||
virtual void touchesEnded(NSSet* touches, UIEvent* pEvent);
|
virtual void touchesEnded(NSSet* touches, UIEvent* pEvent);
|
||||||
virtual void touchesCancelled(NSSet* touches, UIEvent* pEvent);
|
virtual void touchesCancelled(NSSet* touches, UIEvent* pEvent);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -36,27 +36,27 @@ void CCTouchHandler::setDelegate(CCTouchDelegate *pDelegate)
|
||||||
m_pDelegate = pDelegate;
|
m_pDelegate = pDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
INT32 CCTouchHandler::getPriority(void)
|
int CCTouchHandler::getPriority(void)
|
||||||
{
|
{
|
||||||
return m_nPriority;
|
return m_nPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTouchHandler::setPriority(Int32 nPriority)
|
void CCTouchHandler::setPriority(int nPriority)
|
||||||
{
|
{
|
||||||
m_nPriority = nPriority;
|
m_nPriority = nPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
INT32 CCTouchHandler::getEnabledSelectors(void)
|
int CCTouchHandler::getEnabledSelectors(void)
|
||||||
{
|
{
|
||||||
return m_nEnabledSelectors;
|
return m_nEnabledSelectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCTouchHandler::setEnalbedSelectors(Int32 nValue)
|
void CCTouchHandler::setEnalbedSelectors(int nValue)
|
||||||
{
|
{
|
||||||
m_nEnabledSelectors = nValue;
|
m_nEnabledSelectors = nValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTouchHandler* CCTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, Int32 nPriority)
|
CCTouchHandler* CCTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||||
{
|
{
|
||||||
CCTouchHandler *pHandler = new CCTouchHandler();
|
CCTouchHandler *pHandler = new CCTouchHandler();
|
||||||
pHandler->autorelease();
|
pHandler->autorelease();
|
||||||
|
@ -64,7 +64,7 @@ CCTouchHandler* CCTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate,
|
||||||
return pHandler->initWithDelegate(pDelegate, nPriority);
|
return pHandler->initWithDelegate(pDelegate, nPriority);
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTouchHandler* CCTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, Int32 nPriority)
|
CCTouchHandler* CCTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||||
{
|
{
|
||||||
assert(pDelegate != NULL);
|
assert(pDelegate != NULL);
|
||||||
|
|
||||||
|
@ -81,19 +81,19 @@ CCTouchHandler::~CCTouchHandler(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// implementation of CCStandardTouchHandler
|
// implementation of CCStandardTouchHandler
|
||||||
CCTouchHandler* CCStandardTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, Int32 nPriority)
|
CCTouchHandler* CCStandardTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
|
||||||
{
|
{
|
||||||
if (__super::initWithDelegate(pDelegate, nPriority))
|
if (__super::initWithDelegate(pDelegate, nPriority))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* we can not do this in c++
|
* we can not do this in c++
|
||||||
if( [del respondsToSelector:@selector(ccTouchesBegan:withEvent:)] )
|
if( [del respondsToSelector:@selector(ccTouchesBegan:withEvent:)] )
|
||||||
enabledSelectors_ |= ccTouchSelectorBeganBit;
|
enabledSelectors_ |= ccTouchSelectorBeganBit;
|
||||||
if( [del respondsToSelector:@selector(ccTouchesMoved:withEvent:)] )
|
if( [del respondsToSelector:@selector(ccTouchesMoved:withEvent:)] )
|
||||||
enabledSelectors_ |= ccTouchSelectorMovedBit;
|
enabledSelectors_ |= ccTouchSelectorMovedBit;
|
||||||
if( [del respondsToSelector:@selector(ccTouchesEnded:withEvent:)] )
|
if( [del respondsToSelector:@selector(ccTouchesEnded:withEvent:)] )
|
||||||
enabledSelectors_ |= ccTouchSelectorEndedBit;
|
enabledSelectors_ |= ccTouchSelectorEndedBit;
|
||||||
if( [del respondsToSelector:@selector(ccTouchesCancelled:withEvent:)] )
|
if( [del respondsToSelector:@selector(ccTouchesCancelled:withEvent:)] )
|
||||||
enabledSelectors_ |= ccTouchSelectorCancelledBit;
|
enabledSelectors_ |= ccTouchSelectorCancelledBit;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ CCTouchHandler* CCStandardTouchHandler::initWithDelegate(CCTouchDelegate *pDeleg
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCStandardTouchHandler* CCStandardTouchHandler::handlerWithDelegate(CCStandardTouchDelegate *pDelegate, Int32 nPriority)
|
CCStandardTouchHandler* CCStandardTouchHandler::handlerWithDelegate(CCStandardTouchDelegate *pDelegate, int nPriority)
|
||||||
{
|
{
|
||||||
CCStandardTouchHandler* pTouchHandler = new CCStandardTouchHandler();
|
CCStandardTouchHandler* pTouchHandler = new CCStandardTouchHandler();
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ NSMutableSet* CCTargetedTouchHandler::getClaimedTouches(void)
|
||||||
return m_pClaimedTouches;
|
return m_pClaimedTouches;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTargetedTouchHandler* CCTargetedTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, Int32 nPriority, bool bSwallow)
|
CCTargetedTouchHandler* CCTargetedTouchHandler::handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow)
|
||||||
{
|
{
|
||||||
CCTargetedTouchHandler *pTargetedHandler = new CCTargetedTouchHandler();
|
CCTargetedTouchHandler *pTargetedHandler = new CCTargetedTouchHandler();
|
||||||
pTargetedHandler->initWithDelegate(pDelegate, nPriority, bSwallow);
|
pTargetedHandler->initWithDelegate(pDelegate, nPriority, bSwallow);
|
||||||
|
@ -137,7 +137,7 @@ CCTargetedTouchHandler* CCTargetedTouchHandler::handlerWithDelegate(CCTouchDeleg
|
||||||
return pTargetedHandler;
|
return pTargetedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCTouchHandler* CCTargetedTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, Int32 nPriority, bool bSwallow)
|
CCTouchHandler* CCTargetedTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow)
|
||||||
{
|
{
|
||||||
if (__super::initWithDelegate(pDelegate, nPriority))
|
if (__super::initWithDelegate(pDelegate, nPriority))
|
||||||
{
|
{
|
||||||
|
@ -145,13 +145,13 @@ CCTouchHandler* CCTargetedTouchHandler::initWithDelegate(CCTouchDelegate *pDeleg
|
||||||
m_bSwallowsTouches = bSwallow;
|
m_bSwallowsTouches = bSwallow;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if( [aDelegate respondsToSelector:@selector(ccTouchBegan:withEvent:)] )
|
if( [aDelegate respondsToSelector:@selector(ccTouchBegan:withEvent:)] )
|
||||||
enabledSelectors_ |= ccTouchSelectorBeganBit;
|
enabledSelectors_ |= ccTouchSelectorBeganBit;
|
||||||
if( [aDelegate respondsToSelector:@selector(ccTouchMoved:withEvent:)] )
|
if( [aDelegate respondsToSelector:@selector(ccTouchMoved:withEvent:)] )
|
||||||
enabledSelectors_ |= ccTouchSelectorMovedBit;
|
enabledSelectors_ |= ccTouchSelectorMovedBit;
|
||||||
if( [aDelegate respondsToSelector:@selector(ccTouchEnded:withEvent:)] )
|
if( [aDelegate respondsToSelector:@selector(ccTouchEnded:withEvent:)] )
|
||||||
enabledSelectors_ |= ccTouchSelectorEndedBit;
|
enabledSelectors_ |= ccTouchSelectorEndedBit;
|
||||||
if( [aDelegate respondsToSelector:@selector(ccTouchCancelled:withEvent:)] )
|
if( [aDelegate respondsToSelector:@selector(ccTouchCancelled:withEvent:)] )
|
||||||
enabledSelectors_ |= ccTouchSelectorCancelledBit;
|
enabledSelectors_ |= ccTouchSelectorCancelledBit;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,9 @@ THE SOFTWARE.
|
||||||
#include "cocoa/NSObject.h"
|
#include "cocoa/NSObject.h"
|
||||||
#include "cocoa/NSSet.h"
|
#include "cocoa/NSSet.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
CCTouchHandler
|
CCTouchHandler
|
||||||
Object than contains the delegate and priority of the event handler.
|
Object than contains the delegate and priority of the event handler.
|
||||||
*/
|
*/
|
||||||
class CCTouchHandler : public NSObject
|
class CCTouchHandler : public NSObject
|
||||||
{
|
{
|
||||||
|
@ -44,42 +44,42 @@ public:
|
||||||
void setDelegate(CCTouchDelegate *pDelegate);
|
void setDelegate(CCTouchDelegate *pDelegate);
|
||||||
|
|
||||||
// priority
|
// priority
|
||||||
INT32 getPriority(void);
|
int getPriority(void);
|
||||||
void setPriority(INT32 nPriority);
|
void setPriority(int nPriority);
|
||||||
|
|
||||||
// enabled selectors
|
// enabled selectors
|
||||||
INT32 getEnabledSelectors(void);
|
int getEnabledSelectors(void);
|
||||||
void setEnalbedSelectors(INT32 nValue);
|
void setEnalbedSelectors(int nValue);
|
||||||
|
|
||||||
// initializes a TouchHandler with a delegate and a priority
|
// initializes a TouchHandler with a delegate and a priority
|
||||||
virtual CCTouchHandler* initWithDelegate(CCTouchDelegate *pDelegate, INT32 nPriority);
|
virtual CCTouchHandler* initWithDelegate(CCTouchDelegate *pDelegate, int nPriority);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// allocates a TouchHandler with a delegate and a priority
|
// allocates a TouchHandler with a delegate and a priority
|
||||||
static CCTouchHandler* handlerWithDelegate(CCTouchDelegate *pDelegate, INT32 nPriority);
|
static CCTouchHandler* handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CCTouchDelegate *m_pDelegate;
|
CCTouchDelegate *m_pDelegate;
|
||||||
INT32 m_nPriority;
|
int m_nPriority;
|
||||||
INT32 m_nEnabledSelectors;
|
int m_nEnabledSelectors;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** CCStandardTouchHandler
|
/** CCStandardTouchHandler
|
||||||
It forwardes each event to the delegate.
|
It forwardes each event to the delegate.
|
||||||
*/
|
*/
|
||||||
class CCStandardTouchHandler : public CCTouchHandler
|
class CCStandardTouchHandler : public CCTouchHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual CCTouchHandler* initWithDelegate(CCTouchDelegate *pDelegate, INT32 nPriority);
|
virtual CCTouchHandler* initWithDelegate(CCTouchDelegate *pDelegate, int nPriority);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CCStandardTouchHandler* handlerWithDelegate(CCStandardTouchDelegate *pDelegate, INT32 nPriority);
|
static CCStandardTouchHandler* handlerWithDelegate(CCStandardTouchDelegate *pDelegate, int nPriority);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
CCTargetedTouchHandler
|
CCTargetedTouchHandler
|
||||||
Object than contains the claimed touches and if it swallos touches.
|
Object than contains the claimed touches and if it swallos touches.
|
||||||
Used internally by TouchDispatcher
|
Used internally by TouchDispatcher
|
||||||
*/
|
*/
|
||||||
class CCTargetedTouchHandler : public CCTouchHandler
|
class CCTargetedTouchHandler : public CCTouchHandler
|
||||||
{
|
{
|
||||||
|
@ -93,10 +93,10 @@ public:
|
||||||
// MutableSet that contains the claimed touches
|
// MutableSet that contains the claimed touches
|
||||||
NSMutableSet* getClaimedTouches(void);
|
NSMutableSet* getClaimedTouches(void);
|
||||||
|
|
||||||
CCTouchHandler* initWithDelegate(CCTouchDelegate *pDelegate, INT32 nPriority, bool bSwallow);
|
CCTouchHandler* initWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CCTargetedTouchHandler* handlerWithDelegate(CCTouchDelegate *pDelegate, INT32 nPriority, bool bSwallow);
|
static CCTargetedTouchHandler* handlerWithDelegate(CCTouchDelegate *pDelegate, int nPriority, bool bSwallow);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_bSwallowsTouches;
|
bool m_bSwallowsTouches;
|
||||||
|
|
Loading…
Reference in New Issue