mirror of https://github.com/axmolengine/axmol.git
issue #7 , implement .cpp
This commit is contained in:
parent
98915e1e9e
commit
adbf70a033
|
@ -25,6 +25,7 @@ THE SOFTWARE.
|
|||
#include "CCNode.h"
|
||||
#include "support/CGPointExtension.h"
|
||||
#include "cocoa/CGGeometry.h"
|
||||
//#include "CCDirector.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
@ -86,8 +86,8 @@ All features from CCLayer are valid, plus the following new features:
|
|||
class CCColorLayer : public CCLayer , public CCRGBAProtocol, public CCBlendProtocol
|
||||
{
|
||||
protected:
|
||||
GLfloat m_fSquareVertices[4 * 2];
|
||||
GLubyte m_cSquareColors[4 * 4];
|
||||
GLfloat m_pSquareVertices[4 * 2];
|
||||
GLubyte m_pSquareColors[4 * 4];
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -30,8 +30,7 @@ THE SOFTWARE.
|
|||
/// @todo #import <CoreGraphics/CGImage.h>
|
||||
//#include "platform/uphone/NSLock.h"
|
||||
#include <string>
|
||||
#include <hash_map>
|
||||
|
||||
#include "cocoa/NSMutableDictionary.h"
|
||||
|
||||
class CCTexture2D;
|
||||
class CCAsyncObject;
|
||||
|
@ -44,11 +43,14 @@ typedef void (*fpAsyncCallback)(CCTexture2D*, void*);
|
|||
class CCTextureCache : public NSObject
|
||||
{
|
||||
protected:
|
||||
/// @todo hash_map<*,*>
|
||||
stdext::hash_map<int ,int > textures;
|
||||
NSMutableDictionary<std::string, CCTexture2D*> * m_pTextures;
|
||||
//NSLock *m_pDictLock;
|
||||
//NSLock *m_pContextLock;
|
||||
|
||||
private:
|
||||
|
||||
void addImageWithAsyncObject(CCAsyncObject* async);
|
||||
|
||||
public:
|
||||
|
||||
CCTextureCache();
|
||||
|
@ -80,9 +82,8 @@ public:
|
|||
* Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr, .gif
|
||||
* @since v0.8
|
||||
*/
|
||||
/// @todo -(void) addImageAsync:(string & ) filename target:(id)target selector:(SEL)selector;
|
||||
|
||||
void addImageWithAsyncObject(CCAsyncObject* async);
|
||||
/// @todo selector
|
||||
void addImageAsync(string & filename, NSObject*target, fpAsyncCallback func);
|
||||
|
||||
/** Returns a Texture2D object given an PVRTC RAW filename
|
||||
* If the file image was not previously loaded, it will create a new CCTexture2D
|
||||
|
|
|
@ -23,12 +23,26 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "CCLayer.h"
|
||||
#include "touch_dispatcher/CCTouchDispatcher.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
// CCLayer
|
||||
CCLayer::CCLayer()
|
||||
{
|
||||
/// @todo
|
||||
/// @todo director
|
||||
// if( (self=[super init]) ) {
|
||||
//
|
||||
// CGSize s = [[CCDirector sharedDirector] winSize];
|
||||
// anchorPoint_ = ccp(0.5f, 0.5f);
|
||||
// [self setContentSize:s];
|
||||
// self.isRelativeAnchorPoint = NO;
|
||||
//
|
||||
// isTouchEnabled = NO;
|
||||
// isAccelerometerEnabled = NO;
|
||||
// }
|
||||
//
|
||||
// return self;
|
||||
}
|
||||
|
||||
CCLayer::~CCLayer()
|
||||
|
@ -41,7 +55,7 @@ CCLayer::~CCLayer()
|
|||
|
||||
void CCLayer::registerWithTouchDispatcher()
|
||||
{
|
||||
/// @todo [[CCTouchDispatcher sharedDispatcher] addStandardDelegate:self priority:0];
|
||||
CCTouchDispatcher::getSharedDispatcher()->addStandardDelegate(this,0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,6 +67,23 @@ bool CCLayer::getIsTouchEnabled()
|
|||
/// isTouchEnabled setter
|
||||
void CCLayer::setIsTouchEnabled(bool enabled)
|
||||
{
|
||||
if (m_bIsTouchEnabled != enabled)
|
||||
{
|
||||
m_bIsTouchEnabled = enabled;
|
||||
if (m_bIsRunning)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
this->registerWithTouchDispatcher();
|
||||
}
|
||||
else
|
||||
{
|
||||
/// @todo param this error
|
||||
//CCTouchDispatcher::getSharedDispatcher()->removeDelegate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @todo
|
||||
if( isTouchEnabled != enabled ) {
|
||||
isTouchEnabled = enabled;
|
||||
|
@ -189,30 +220,26 @@ CCColorLayer * CCColorLayer::layerWithColor(ccColor4B color)
|
|||
|
||||
CCColorLayer* CCColorLayer::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height)
|
||||
{
|
||||
/** @todo
|
||||
if( (self=[super init]) ) {
|
||||
|
||||
// default blend function
|
||||
blendFunc_ = (ccBlendFunc) { CC_BLEND_SRC, CC_BLEND_DST };
|
||||
m_tBlendFunc.src = CC_BLEND_SRC;
|
||||
m_tBlendFunc.dst = CC_BLEND_DST;
|
||||
|
||||
color_.r = color.r;
|
||||
color_.g = color.g;
|
||||
color_.b = color.b;
|
||||
opacity_ = color.a;
|
||||
m_tColor.r = color.r;
|
||||
m_tColor.g = color.g;
|
||||
m_tColor.b = color.b;
|
||||
m_cOpacity = color.a;
|
||||
|
||||
for (NSUInteger i=0; i<sizeof(squareVertices) / sizeof( squareVertices[0]); i++ )
|
||||
squareVertices[i] = 0.0f;
|
||||
for (UINT32 i=0; i<sizeof(m_pSquareVertices) / sizeof(m_pSquareVertices[0]); i++ )
|
||||
m_pSquareVertices[i] = 0.0f;
|
||||
|
||||
[self updateColor];
|
||||
[self setContentSize:CGSizeMake(w,h)];
|
||||
}
|
||||
return self;*/
|
||||
return NULL;
|
||||
this->updateColor();
|
||||
this->setContentSize(CGSizeMake(width,height));
|
||||
return this;
|
||||
}
|
||||
|
||||
CCColorLayer * CCColorLayer::initWithColor(ccColor4B color)
|
||||
{
|
||||
/** @todo
|
||||
/** @todo director
|
||||
CGSize s = [[CCDirector sharedDirector] winSize];
|
||||
return [self initWithColor:color width:s.width height:s.height];*/
|
||||
return NULL;
|
||||
|
@ -221,65 +248,63 @@ CCColorLayer * CCColorLayer::initWithColor(ccColor4B color)
|
|||
/// override contentSize
|
||||
void CCColorLayer::setContentSize(CGSize size)
|
||||
{
|
||||
/** @todo
|
||||
squareVertices[2] = size.width;
|
||||
squareVertices[5] = size.height;
|
||||
squareVertices[6] = size.width;
|
||||
squareVertices[7] = size.height;
|
||||
m_pSquareVertices[2] = size.width;
|
||||
m_pSquareVertices[5] = size.height;
|
||||
m_pSquareVertices[6] = size.width;
|
||||
m_pSquareVertices[7] = size.height;
|
||||
|
||||
[super setContentSize:size];*/
|
||||
this->setContentSize(size);
|
||||
}
|
||||
|
||||
void CCColorLayer::changeWidthAndHeight(GLfloat w ,GLfloat h)
|
||||
{
|
||||
/// @todo [self setContentSize:CGSizeMake(w,h)];
|
||||
this->setContentSize(CGSizeMake(w, h));
|
||||
}
|
||||
|
||||
void CCColorLayer::changeWidth(GLfloat w)
|
||||
{
|
||||
/// @todo [self setContentSize:CGSizeMake(w,contentSize_.height)];
|
||||
this->setContentSize(CGSizeMake(w, m_tContentSize.height));
|
||||
}
|
||||
|
||||
void CCColorLayer::changeHeight(GLfloat h)
|
||||
{
|
||||
/// @todo [self setContentSize:CGSizeMake(contentSize_.width,h)];
|
||||
this->setContentSize(CGSizeMake(m_tContentSize.width, h));
|
||||
}
|
||||
|
||||
void CCColorLayer::updateColor()
|
||||
{
|
||||
/** @todo
|
||||
for( NSUInteger i=0; i < sizeof(squareColors) / sizeof(squareColors[0]);i++ )
|
||||
for( UINT32 i=0; i < sizeof(m_pSquareColors) / sizeof(m_pSquareColors[0]); i++ )
|
||||
{
|
||||
if( i % 4 == 0 )
|
||||
squareColors[i] = color_.r;
|
||||
m_pSquareColors[i] = m_tColor.r;
|
||||
else if( i % 4 == 1)
|
||||
squareColors[i] = color_.g;
|
||||
m_pSquareColors[i] = m_tColor.g;
|
||||
else if( i % 4 ==2 )
|
||||
squareColors[i] = color_.b;
|
||||
m_pSquareColors[i] = m_tColor.b;
|
||||
else
|
||||
squareColors[i] = opacity_;
|
||||
}*/
|
||||
m_pSquareColors[i] = m_cOpacity;
|
||||
}
|
||||
}
|
||||
|
||||
void CCColorLayer::draw()
|
||||
{
|
||||
/** @todo
|
||||
/** @todo*/
|
||||
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
|
||||
// Needed states: GL_VERTEX_ARRAY, GL_COLOR_ARRAY
|
||||
// Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 0, squareVertices);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
|
||||
glVertexPointer(2, GL_FLOAT, 0, m_pSquareVertices);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, 0, m_pSquareColors);
|
||||
|
||||
BOOL newBlend = NO;
|
||||
if( blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST ) {
|
||||
newBlend = YES;
|
||||
glBlendFunc(blendFunc_.src, blendFunc_.dst);
|
||||
bool newBlend = false;
|
||||
if( m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST ) {
|
||||
newBlend = true;
|
||||
glBlendFunc(m_tBlendFunc.src, m_tBlendFunc.dst);
|
||||
}
|
||||
else if( opacity_ != 255 ) {
|
||||
newBlend = YES;
|
||||
else if( m_cOpacity != 255 ) {
|
||||
newBlend = true;
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
|
@ -290,7 +315,7 @@ void CCColorLayer::draw()
|
|||
|
||||
// restore default GL state
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnable(GL_TEXTURE_2D);*/
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
||||
|
@ -302,73 +327,63 @@ CCMultiplexLayer::CCMultiplexLayer()
|
|||
}
|
||||
CCMultiplexLayer::~CCMultiplexLayer()
|
||||
{
|
||||
/// @todo
|
||||
m_pLayers->release();
|
||||
}
|
||||
|
||||
CCMultiplexLayer * CCMultiplexLayer::layerWithLayers(CCLayer * layer, ...)
|
||||
{
|
||||
/** @todo va_list args;
|
||||
va_list args;
|
||||
va_start(args,layer);
|
||||
|
||||
id s = [[[self alloc] initWithLayers: layer vaList:args] autorelease];
|
||||
CCMultiplexLayer * pMultiplexLayer = new CCMultiplexLayer();
|
||||
pMultiplexLayer->initWithLayers(layer, args);
|
||||
pMultiplexLayer->autorelease();
|
||||
|
||||
va_end(args);
|
||||
return s;*/
|
||||
return NULL;
|
||||
return pMultiplexLayer;
|
||||
}
|
||||
|
||||
CCMultiplexLayer * CCMultiplexLayer::initWithLayers(CCLayer *layer, va_list params)
|
||||
{
|
||||
/** @todo
|
||||
if( (self=[super init]) ) {
|
||||
m_pLayers = new NSMutableArray<CCLayer*>(5);
|
||||
m_pLayers->retain();
|
||||
|
||||
layers = [[NSMutableArray arrayWithCapacity:5] retain];
|
||||
|
||||
[layers addObject: layer];
|
||||
m_pLayers->addObject(layer);
|
||||
|
||||
CCLayer *l = va_arg(params,CCLayer*);
|
||||
while( l ) {
|
||||
[layers addObject: l];
|
||||
m_pLayers->addObject(l);
|
||||
l = va_arg(params,CCLayer*);
|
||||
}
|
||||
|
||||
enabledLayer = 0;
|
||||
[self addChild: [layers objectAtIndex: enabledLayer]];
|
||||
m_nEnabledLayer = 0;
|
||||
this->addChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
return self;*/
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** @todo
|
||||
-(void) dealloc
|
||||
{
|
||||
[layers release];
|
||||
[super dealloc];
|
||||
}*/
|
||||
|
||||
void CCMultiplexLayer::switchTo(unsigned int n)
|
||||
{
|
||||
/** @todo
|
||||
NSAssert( n < [layers count], @"Invalid index in MultiplexLayer switchTo message" );
|
||||
NSAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
||||
|
||||
[self removeChild: [layers objectAtIndex:enabledLayer] cleanup:YES];
|
||||
this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true);
|
||||
|
||||
enabledLayer = n;
|
||||
m_nEnabledLayer = n;
|
||||
|
||||
[self addChild: [layers objectAtIndex:n]]; */
|
||||
this->addChild(m_pLayers->getObjectAtIndex(n));
|
||||
}
|
||||
|
||||
void CCMultiplexLayer::switchToAndReleaseMe(unsigned int n)
|
||||
{
|
||||
/** @todo
|
||||
NSAssert( n < [layers count], @"Invalid index in MultiplexLayer switchTo message" );
|
||||
NSAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" );
|
||||
|
||||
[self removeChild: [layers objectAtIndex:enabledLayer] cleanup:YES];
|
||||
this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true);
|
||||
|
||||
[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]];
|
||||
//[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]];
|
||||
m_pLayers->replaceObjectAtIndex(m_nEnabledLayer, NULL);
|
||||
|
||||
enabledLayer = n;
|
||||
m_nEnabledLayer = n;
|
||||
|
||||
[self addChild: [layers objectAtIndex:n]]; */
|
||||
this->addChild(m_pLayers->getObjectAtIndex(n));
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ enum {
|
|||
|
||||
CCTransitionScene::CCTransitionScene()
|
||||
{
|
||||
/// @todo
|
||||
}
|
||||
CCTransitionScene::~CCTransitionScene()
|
||||
{
|
||||
|
@ -42,7 +41,6 @@ CCTransitionScene::~CCTransitionScene()
|
|||
|
||||
CCTransitionScene * CCTransitionScene::transitionWithDurationAndScene(ccTime t, CCScene *scene)
|
||||
{
|
||||
/// @todo return [[[self alloc] initWithDuration:t scene:s] autorelease];
|
||||
CCTransitionScene * pScene = new CCTransitionScene();
|
||||
pScene->initWithDurationAndScene(t,scene);
|
||||
pScene->autorelease();
|
||||
|
@ -51,7 +49,7 @@ CCTransitionScene * CCTransitionScene::transitionWithDurationAndScene(ccTime t,
|
|||
|
||||
CCTransitionScene * CCTransitionScene::initWithDurationAndScene(ccTime t, CCScene *scene)
|
||||
{
|
||||
/** @todo
|
||||
/** @todo ccdirector
|
||||
NSAssert( s != nil, @"Argument scene must be non-nil");
|
||||
|
||||
if( (self=[super init]) ) {
|
||||
|
@ -92,29 +90,30 @@ void CCTransitionScene::draw()
|
|||
|
||||
void CCTransitionScene::finish()
|
||||
{
|
||||
/** @todo
|
||||
// clean up
|
||||
// m_pInScene->setIsVisible(true);
|
||||
// m_pInScene->setPosition(ccp(0,0));
|
||||
// m_pInScene->setScale(1.0f);
|
||||
// m_pInScene->setRotation(0.0f);
|
||||
// m_pInScene->getCamera()->restore();
|
||||
//
|
||||
// m_pOutScene->setIsVisible(false);
|
||||
// m_pOutScene->setPosition(ccp(0,0));
|
||||
// m_pOutScene->setScale(1.0f);
|
||||
// m_pOutScene->setRotation(0.0f);
|
||||
// m_pOutScene->getCamera()->restore();
|
||||
m_pInScene->setIsVisible(true);
|
||||
m_pInScene->setPosition(ccp(0,0));
|
||||
m_pInScene->setScale(1.0f);
|
||||
m_pInScene->setRotation(0.0f);
|
||||
m_pInScene->getCamera()->restore();
|
||||
|
||||
this->schedule(&CCTransitionScene::setNewScene, 0);
|
||||
// [self schedule:@selector(setNewScene:) interval:0];*/
|
||||
m_pOutScene->setIsVisible(false);
|
||||
m_pOutScene->setPosition(ccp(0,0));
|
||||
m_pOutScene->setScale(1.0f);
|
||||
m_pOutScene->setRotation(0.0f);
|
||||
m_pOutScene->getCamera()->restore();
|
||||
|
||||
//[self schedule:@selector(setNewScene:) interval:0];
|
||||
this->schedule(schedule_selector(CCTransitionScene::setNewScene), 0);
|
||||
|
||||
}
|
||||
|
||||
void CCTransitionScene::setNewScene(ccTime dt)
|
||||
{
|
||||
/** @todo
|
||||
[self unschedule:_cmd];
|
||||
/** @todo CCDirector
|
||||
|
||||
//[self unschedule:_cmd];
|
||||
this->unschedule(schedule_selector(CCTransitionScene::setNewScene));
|
||||
|
||||
CCDirector *director = [CCDirector sharedDirector];
|
||||
|
||||
|
|
|
@ -520,35 +520,37 @@ CCTexture2D * CCTexture2D::initWithPVRTCData(const void *data, int level, int bp
|
|||
|
||||
CCTexture2D * CCTexture2D::initWithPVRTCFile(string & file)
|
||||
{
|
||||
/** @todo
|
||||
if( ! [[CCConfiguration sharedConfiguration] supportsPVRTC] ) {
|
||||
CCLOG(@"cocos2d: WARNING: PVRTC images is not supported");
|
||||
[self release];
|
||||
return nil;
|
||||
if (! CCConfiguration::sharedConfiguration()->isSupportsPVRTC())
|
||||
{
|
||||
CCLOG("cocos2d: WARNING: PVRTC images is not supported");
|
||||
this->release();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( (self = [super init]) ) {
|
||||
CCPVRTexture *pvr = [[CCPVRTexture alloc] initWithContentsOfFile:file];
|
||||
if( pvr ) {
|
||||
pvr.retainName = YES; // don't dealloc texture on release
|
||||
CCPVRTexture *pvr = new CCPVRTexture();
|
||||
pvr = pvr->initWithContentsOfFile(file);
|
||||
if( pvr )
|
||||
{
|
||||
pvr->setRetainName(true); // don't dealloc texture on release
|
||||
|
||||
_name = pvr.name; // texture id
|
||||
_maxS = 1.0f;
|
||||
_maxT = 1.0f;
|
||||
_width = pvr.width; // width
|
||||
_height = pvr.height; // height
|
||||
_size = CGSizeMake(_width, _height);
|
||||
m_uName = pvr->getName(); // texture id
|
||||
m_fMaxS = 1.0f;
|
||||
m_fMaxT = 1.0f;
|
||||
m_uPixelsWide = pvr->getWidth(); // width
|
||||
m_uPixelsHigh = pvr->getHeight(); // height
|
||||
/// be careful : UINT32 to float
|
||||
m_tContentSize = CGSizeMake((float)m_uPixelsWide, (float)m_uPixelsHigh);
|
||||
|
||||
[pvr release];
|
||||
pvr->release();
|
||||
|
||||
[self setAntiAliasTexParameters];
|
||||
} else {
|
||||
|
||||
CCLOG(@"cocos2d: Couldn't load PVR image");
|
||||
[self release];
|
||||
return nil;
|
||||
this->setAntiAliasTexParameters();
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("cocos2d: Couldn't load PVR image");
|
||||
this->release();
|
||||
return NULL;
|
||||
}
|
||||
}*/
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -180,9 +180,9 @@ void CCTextureAtlas::initIndices()
|
|||
|
||||
#if CC_TEXTURE_ATLAS_USES_VBO
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(ccV3F_C4B_T2F_Quad) * m_uCapacity, m_pQuads, GL_DYNAMIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(m_pQuads[0]) * m_uCapacity, m_pQuads, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_pIndices[0]) * m_uCapacity * 6, m_pIndices, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
#endif // CC_TEXTURE_ATLAS_USES_VBO
|
||||
|
@ -212,7 +212,7 @@ void CCTextureAtlas::insertQuad(ccV3F_C4B_T2F_Quad *quad, UINT32 index)
|
|||
// last object doesn't need to be moved
|
||||
if( remaining > 0) {
|
||||
// tex coordinates
|
||||
memmove( &m_pQuads[index+1],&m_pQuads[index], sizeof(ccV3F_C4B_T2F_Quad) * remaining );
|
||||
memmove( &m_pQuads[index+1],&m_pQuads[index], sizeof(m_pQuads[0]) * remaining );
|
||||
}
|
||||
|
||||
m_pQuads[index] = *quad;
|
||||
|
@ -236,7 +236,7 @@ void CCTextureAtlas::insertQuadFromIndex(UINT32 oldIndex, UINT32 newIndex)
|
|||
|
||||
// tex coordinates
|
||||
ccV3F_C4B_T2F_Quad quadsBackup = m_pQuads[oldIndex];
|
||||
memmove( &m_pQuads[dst],&m_pQuads[src], sizeof(ccV3F_C4B_T2F_Quad) * howMany );
|
||||
memmove( &m_pQuads[dst],&m_pQuads[src], sizeof(m_pQuads[0]) * howMany );
|
||||
m_pQuads[newIndex] = quadsBackup;
|
||||
}
|
||||
|
||||
|
@ -250,7 +250,7 @@ void CCTextureAtlas::removeQuadAtIndex(UINT32 index)
|
|||
// last object doesn't need to be moved
|
||||
if( remaining ) {
|
||||
// tex coordinates
|
||||
memmove( &m_pQuads[index],&m_pQuads[index+1], sizeof(ccV3F_C4B_T2F_Quad) * remaining );
|
||||
memmove( &m_pQuads[index],&m_pQuads[index+1], sizeof(m_pQuads[0]) * remaining );
|
||||
}
|
||||
|
||||
m_uTotalQuads--;
|
||||
|
@ -273,8 +273,8 @@ bool CCTextureAtlas::resizeCapacity(UINT32 newCapacity)
|
|||
m_uTotalQuads = MIN(m_uTotalQuads, newCapacity);
|
||||
m_uCapacity = newCapacity;
|
||||
|
||||
void * tmpQuads = realloc( m_pQuads, sizeof(ccV3F_C4B_T2F_Quad) * m_uCapacity );
|
||||
void * tmpIndices = realloc( m_pIndices, sizeof(GLushort) * m_uCapacity * 6 );
|
||||
void * tmpQuads = realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity );
|
||||
void * tmpIndices = realloc( m_pIndices, sizeof(m_pIndices[0]) * m_uCapacity * 6 );
|
||||
|
||||
if( ! ( tmpQuads && tmpIndices) ) {
|
||||
CCLOG("cocos2d: CCTextureAtlas: not enough memory");
|
||||
|
@ -313,14 +313,14 @@ void CCTextureAtlas::drawNumberOfQuads(UINT32 n)
|
|||
{
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, m_pTexture->getName());
|
||||
#define kQuadSize sizeof(ccV3F_C4B_T2F)
|
||||
#define kQuadSize sizeof(m_pQuads[0].bl)
|
||||
|
||||
|
||||
#if CC_TEXTURE_ATLAS_USES_VBO
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
|
||||
|
||||
// XXX: update is done in draw... perhaps it should be done in a timer
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(ccV3F_C4B_T2F_Quad) * n, m_pQuads);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(m_pQuads[0]) * n, m_pQuads);
|
||||
|
||||
// vertices
|
||||
glVertexPointer(3, GL_FLOAT, kQuadSize, (void*) offsetof( ccV3F_C4B_T2F, vertices));
|
||||
|
|
|
@ -22,9 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "CCTextureCache.h"
|
||||
|
||||
|
||||
#include "CCTextureCache.h"
|
||||
#include "CCTexture2D.h"
|
||||
#include "ccMacros.h"
|
||||
|
@ -69,8 +66,11 @@ CCTextureCache * CCTextureCache::sharedTextureCache()
|
|||
CCTextureCache::CCTextureCache()
|
||||
{
|
||||
NSAssert(sharedTextureCache == NULL, "Attempted to allocate a second instance of a singleton.");
|
||||
/** @todo NSMutableDictionary , NSLock
|
||||
textures = [[NSMutableDictionary dictionaryWithCapacity: 10] retain];
|
||||
|
||||
//textures = [[NSMutableDictionary dictionaryWithCapacity: 10] retain];
|
||||
m_pTextures = new NSMutableDictionary<std::string, CCTexture2D*>();
|
||||
m_pTextures->retain();
|
||||
/** @todo NSLock
|
||||
dictLock = [[NSLock alloc] init];
|
||||
contextLock = [[NSLock alloc] init];*/
|
||||
}
|
||||
|
@ -96,14 +96,12 @@ void CCTextureCache::purgeSharedTextureCache()
|
|||
|
||||
std::string CCTextureCache::description()
|
||||
{
|
||||
/** @todo CCMutableDictionary
|
||||
return [NSString stringWithFormat:@"<%@ = %08X | num of textures = %i>", [self class], self, [textures count]];
|
||||
/** @todo CCMutableDictionary::count()*/
|
||||
char des[100];
|
||||
sprintf_s(des, 100, "<CCTextureCache | num of textures = %d>", m_pTextures->count());
|
||||
sprintf_s(des, 100, "<CCTextureCache | Number of textures = %d>", m_pTextures->count());
|
||||
string ret(des);
|
||||
|
||||
return ret;*/
|
||||
return NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -143,31 +141,36 @@ sharegroup:[[[[CCDirector sharedDirector] openGLView] context] sharegroup]];
|
|||
[autoreleasepool release];*/
|
||||
}
|
||||
|
||||
/** @todo
|
||||
-(void) addImageAsync: (string & ) filename target:(id)target selector:(SEL)selector
|
||||
/** @todo selector*/
|
||||
void CCTextureCache::addImageAsync(std::string &filename, NSObject *target, fpAsyncCallback func)
|
||||
{
|
||||
NSAssert(filename != nil, @"TextureCache: fileimage MUST not be nill");
|
||||
NSAssert(!filename.empty() , "TextureCache: fileimage MUST not be nill");
|
||||
|
||||
// optimization
|
||||
|
||||
CCTexture2D * tex;
|
||||
|
||||
if( (tex=[textures objectForKey: filename] ) ) {
|
||||
[target performSelector:selector withObject:tex];
|
||||
return;
|
||||
//
|
||||
// if ( (tex = m_pTextures->objectForKey(filename)) )
|
||||
// {
|
||||
// target->
|
||||
// }
|
||||
//
|
||||
// if( (tex=[textures objectForKey: filename] ) ) {
|
||||
// [target performSelector:selector withObject:tex];
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // schedule the load
|
||||
//
|
||||
// CCAsyncObject *asyncObject = [[CCAsyncObject alloc] init];
|
||||
// asyncObject.selector = selector;
|
||||
// asyncObject.target = target;
|
||||
// asyncObject.data = filename;
|
||||
//
|
||||
// [NSThread detachNewThreadSelector:@selector(addImageWithAsyncObject:) toTarget:self withObject:asyncObject];
|
||||
// [asyncObject release];
|
||||
}
|
||||
|
||||
// schedule the load
|
||||
|
||||
CCAsyncObject *asyncObject = [[CCAsyncObject alloc] init];
|
||||
asyncObject.selector = selector;
|
||||
asyncObject.target = target;
|
||||
asyncObject.data = filename;
|
||||
|
||||
[NSThread detachNewThreadSelector:@selector(addImageWithAsyncObject:) toTarget:self withObject:asyncObject];
|
||||
[asyncObject release];
|
||||
}*/
|
||||
|
||||
CCTexture2D * CCTextureCache::addImage(string & path)
|
||||
{
|
||||
NSAssert(!path.empty(), "TextureCache: fileimage MUST not be nill");
|
||||
|
@ -245,17 +248,19 @@ CCTexture2D * CCTextureCache::addPVRTCImage(string & fileimage)
|
|||
NSAssert(!fileimage.empty(), "TextureCache: fileimage MUST not be nill");
|
||||
|
||||
CCTexture2D * tex;
|
||||
/** @todo
|
||||
if( (tex=[textures objectForKey: fileimage] ) ) {
|
||||
/** @todo*/
|
||||
if( (tex = m_pTextures->objectForKey(fileimage )) )
|
||||
{
|
||||
return tex;
|
||||
}
|
||||
|
||||
tex = [[CCTexture2D alloc] initWithPVRTCFile: fileimage];
|
||||
tex = new CCTexture2D();
|
||||
tex = tex->initWithPVRTCFile(fileimage);
|
||||
if( tex )
|
||||
[textures setObject: tex forKey:fileimage];
|
||||
m_pTextures-> setObject( tex, fileimage);
|
||||
else
|
||||
CCLOG(@"cocos2d: Couldn't add PVRTCImage:%@ in CCTextureCache",fileimage);
|
||||
*/
|
||||
CCLOG("cocos2d: Couldn't add PVRTCImage:%s in CCTextureCache",fileimage);
|
||||
|
||||
tex->autorelease();
|
||||
return tex;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue