[devel] Mac port status

Forums Programming cocos2d Mac [devel] Mac port status

This topic contains 40 replies, has 16 voices, and was last updated by  Stepan Generalov 3 years, 3 months ago.

Viewing 25 posts - 1 through 25 (of 41 total)
Author Posts
Author Posts
August 23, 2010 at 9:55 pm #224170

riq
Keymaster
@admin

Mac port status:

- CCDirector / MacGLView: renders, but resizing is not working yet.

- Events: 0% Add mouse / keyboard / multitouch support

- CCActions: 100% ported

- CCSprite: 90%. TODO: port CCSpriteFrameCache

- Transitions: 70%. TODO: Port PageTurn and Progress transitions

- Tiles: 100% ported

- Particles: Quad ported but not working (?). Point particle: How do I use point size array ?

- Menu: Not ported yet

- Textures: 70%. TODO support PVR images (PVR non compress images), and texture from string

- Labels: 66%: TODO: support CCLabelTTF

- Misc nodes: 30%

How to test it:

1. Download develop branch

2. cd cocos2d-iphone/mac

3. open the “cocos2d-mac.xcodeproj” and run the only application.

Please don’t report bugs unless it comes with the patch, and please don’t ask for help. The project is very unstable and I don’t recommend using it. It is just a “technology preview”

This video is still in “processing” state, but once it is ready it will show a little demo of the mac port:

http://www.youtube.com/watch?v=BAaEZ7laSQU

August 24, 2010 at 12:14 am #295315

cublah
Participant
@cublah

Awesome start Riq!

August 24, 2010 at 9:29 pm #295316

riq
Keymaster
@admin

Status update:

- All objects were ported except:

- Menu / MenuItems because the events are not supported yet

- point particle system because I don’t know if the point_size_array exists on OpenGL.

cocos2d mac preview II includes:

- resizing

- CCLabelBMFont

- Radial action

- Particle Flower, and particle using Particle Designer

- Tiled Map, and TMX tiled map

- Actions

- Liquid effect

http://www.youtube.com/watch?v=SidU30vajAI

Test on 64 and 32 bit, on debug and release mode

August 24, 2010 at 10:24 pm #295317

finder39
Participant
@finder39

LOOKS AWESOME!! can’t wait :)

August 24, 2010 at 10:30 pm #295318

chrisco
Participant
@chrisco

That is some mesmerizing cleavage. Took me three views before I noticed the particle effect in the background ;)

Great job @riq – I know I had doubts about the whole thing back in the other thread, but it does look damn cool. And a game editor would be quite awesome.

August 24, 2010 at 10:55 pm #295319

ddeaco
Participant
@ddeaco

Looks great, some kind of game/GUI editor would be amazing! i spend so long just moving things to the right position. 71Squared’s particle designer has saved me loads of time, something like that for the wider cocos2D platform would be priceless!

August 24, 2010 at 11:30 pm #295320

manucorporat
Participant
@manucorporat

Hi Riq

Edited: Have you ported CCLabelTTF?

I have ported point particle system to mac:

(The comet is a point particle system)

but Opengl doesn’t support point size pointer.

Here’s the code:

CCParticleSystemPoint.h:

/*
* cocos2d for iPhone: http://www.cocos2d-iphone.org
*
* Copyright (c) 2008-2010 Ricardo Quesada
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#import "CCParticleSystem.h"

#define CC_MAX_PARTICLE_SIZE 64

/** CCParticleSystemPoint is a subclass of CCParticleSystem
Attributes of a Particle System:
* All the attributes of Particle System

Features:
* consumes small memory: uses 1 vertex (x,y) per particle, no need to assign tex coordinates
* size can't be bigger than 64
* the system can't be scaled since the particles are rendered using GL_POINT_SPRITE

Limitations:
* On 3rd gen iPhone devices and iPads, this node performs MUCH slower than CCParticleSystemQuad.
*/
@interface CCParticleSystemPoint : CCParticleSystem
{
// Array of (x,y,size)
ccPointSprite *vertices;
// vertices buffer id
#if (CC_USES_VBO && __IPHONE_OS_VERSION_MIN_REQUIRED)
GLuint verticesID;
#endif
}
@end

CCParticleSystemPoint.m:

/*
* cocos2d for iPhone: http://www.cocos2d-iphone.org
*
* Copyright (c) 2008-2010 Ricardo Quesada
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

// opengl
#import "Platforms/CCGL.h"

// cocos2d
#import "CCParticleSystemPoint.h"
#import "CCTextureCache.h"
#import "ccMacros.h"

// support
#import "Support/OpenGL_Internal.h"
#import "Support/CGPointExtension.h"

@implementation CCParticleSystemPoint

-(id) initWithTotalParticles:(int) numberOfParticles
{
if( (self=[super initWithTotalParticles:numberOfParticles]) ) {

vertices = malloc( sizeof(ccPointSprite) * totalParticles );

if( ! vertices ) {
NSLog(@"cocos2d: Particle system: not enough memory");
[self release];
return nil;
}

#if (CC_USES_VBO && __IPHONE_OS_VERSION_MIN_REQUIRED)
glGenBuffers(1, &verticesID);

// initial binding
glBindBuffer(GL_ARRAY_BUFFER, verticesID);
glBufferData(GL_ARRAY_BUFFER, sizeof(ccPointSprite)*totalParticles, vertices, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
#endif
}

return self;
}

-(void) dealloc
{
free(vertices);
#if (CC_USES_VBO && __IPHONE_OS_VERSION_MIN_REQUIRED)
glDeleteBuffers(1, &verticesID);
#endif

[super dealloc];
}

-(void) updateQuadWithParticle:(tCCParticle*)p newPosition:(CGPoint)newPos
{
ccVertex2F pos;
pos.x = newPos.x;
pos.y = newPos.y;

// place vertices and colos in array
vertices[particleIdx].pos = pos;
vertices[particleIdx].size = p->size;
vertices[particleIdx].colors = p->color;
}

-(void) postStep
{
#if (CC_USES_VBO && __IPHONE_OS_VERSION_MIN_REQUIRED)
glBindBuffer(GL_ARRAY_BUFFER, verticesID);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(ccPointSprite)*particleCount, vertices);
glBindBuffer(GL_ARRAY_BUFFER, 0);
#endif
}

-(void) draw
{
if (particleIdx==0)
return;

// 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
// Unneeded states: GL_TEXTURE_COORD_ARRAY
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glBindTexture(GL_TEXTURE_2D, texture_.name);

#if __IPHONE_OS_VERSION_MIN_REQUIRED
/************************************/
/**** IOS POINT SPRITE RENDERING ****/
/************************************/

#define kPointSize sizeof(vertices[0])

glEnable(GL_POINT_SPRITE_OES);
glTexEnvi( GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE );

#if CC_USES_VBO
glBindBuffer(GL_ARRAY_BUFFER, verticesID);

glVertexPointer(2,GL_FLOAT, kPointSize, 0);
glColorPointer(4, GL_FLOAT, kPointSize, (GLvoid*) offsetof(ccPointSprite, colors) );
glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
glPointSizePointerOES(GL_FLOAT, kPointSize, (GLvoid*) offsetof(ccPointSprite, size) );
#else // Uses Vertex Array List
int offset = (int)vertices;
glVertexPointer(2,GL_FLOAT, kPointSize, (GLvoid*) offset);

int diff = offsetof(ccPointSprite, colors);
glColorPointer(4, GL_FLOAT, kPointSize, (GLvoid*) (offset+diff));

glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
diff = offsetof(ccPointSprite, size);
glPointSizePointerOES(GL_FLOAT, kPointSize, (GLvoid*) (offset+diff));
#endif

BOOL newBlend = NO;
if( blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST ) {
newBlend = YES;
glBlendFunc( blendFunc_.src, blendFunc_.dst );
}

glDrawArrays(GL_POINTS, 0, particleIdx);

// restore blend state
if( newBlend )
glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST);

#if CC_USES_VBO
// unbind VBO buffer
glBindBuffer(GL_ARRAY_BUFFER, 0);
#endif

glDisableClientState(GL_POINT_SIZE_ARRAY_OES);
glDisable(GL_POINT_SPRITE_OES);

#elif __MAC_OS_X_VERSION_MIN_REQUIRED
/************************************/
/** MAC OSX POINT SPRITE RENDERING **/
/************************************/

glDisableClientState(GL_COLOR_ARRAY_POINTER);
glEnable(GL_POINT_SPRITE_ARB);
glTexEnvi( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );

BOOL newBlend = NO;
if( blendFunc_.src != CC_BLEND_SRC || blendFunc_.dst != CC_BLEND_DST ) {
newBlend = YES;
glBlendFunc( blendFunc_.src, blendFunc_.dst );
}

glPointSize(20.0f);
glBegin(GL_POINTS);
{
for(int i=0; i<particleIdx; i++)
{
ccPointSprite point = vertices;
glColor4f(point.colors.r, point.colors.g, point.colors.b, point.colors.a);
glVertex3f(point.pos.x, point.pos.y, 0);
}
}
glEnd();

// restore blend state
if( newBlend )
glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST);

glDisable(GL_POINT_SPRITE_ARB);
glEnableClientState(GL_COLOR_ARRAY_POINTER);
#endif

// restore GL default state
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}

#pragma mark Non supported properties

//
// SPIN IS NOT SUPPORTED
//
-(void) setStartSpin:(float)a
{
NSAssert(a == 0, @"PointParticleSystem doesn't support spinning");
[super setStartSpin:a];
}
-(void) setStartSpinVar:(float)a
{
NSAssert(a == 0, @"PointParticleSystem doesn't support spinning");
[super setStartSpin:a];
}
-(void) setEndSpin:(float)a
{
NSAssert(a == 0, @"PointParticleSystem doesn't support spinning");
[super setStartSpin:a];
}
-(void) setEndSpinVar:(float)a
{
NSAssert(a == 0, @"PointParticleSystem doesn't support spinning");
[super setStartSpin:a];
}

//
// SIZE > 64 IS NOT SUPPORTED
//
-(void) setStartSize:(float)size
{
NSAssert(size >= 0 && size <= CC_MAX_PARTICLE_SIZE, @"PointParticleSystem only supports 0 <= size <= 64");
[super setStartSize:size];
}

-(void) setEndSize:(float)size
{
NSAssert( (size == kCCParticleStartSizeEqualToEndSize) ||
( size >= 0 && size <= CC_MAX_PARTICLE_SIZE), @"PointParticleSystem only supports 0 <= size <= 64");
[super setEndSize:size];
}
@end

August 25, 2010 at 12:14 am #295321

riq
Keymaster
@admin

@manu nice… yes, I don’t know if OpenGL supports point_size_array… perhaps using an extension, but I haven’t found it out yet.

Did you commit it in your repo ? If so, just send me the pull request.

regarding CCLabelTTF… ouch… no. I forgot to mention that I haven’t ported it yet.

August 25, 2010 at 1:08 am #295322

manucorporat
Participant
@manucorporat

ok,

http://github.com/manucorporat/cocos2d-iphone/commit/74a7324a15465f745d117dbdb8157b1bd4fdb2a2

August 25, 2010 at 6:28 pm #295323

manucorporat
Participant
@manucorporat

CCLabelTTF works ok in mac os x:

http://github.com/manucorporat/cocos2d-iphone/commit/ef3a7acdace2abdbe64332ddb087a8ef489d5885

August 25, 2010 at 8:40 pm #295324

riq
Keymaster
@admin

Thanks Manu!

I’ve just merged your cCCLabelTTF changes.

Events are working nice: mouse + keyboard!

I need to do more tests, but I think it that the Mac port is “ready”. Who wants to port his/her game to Mac ?

August 25, 2010 at 10:27 pm #295325

manucorporat
Participant
@manucorporat

I think we should integrate exclusive mac osx features:

- Full Screen

- Fixed window size

- Optimize to the mac os x platform (I don’t know)

August 26, 2010 at 12:14 am #295326

riq
Keymaster
@admin

@Manu:

Yes, fullscreen will be supported, with the option to maintain the aspect ratio.

August 26, 2010 at 12:59 am #295327

bradparks
Participant
@bradparks

kudos to you @riq, and @manucorporat as well… great work, and it’s very much appreciated… the time alone it’ll shave off of build times for testing will save *everyone* lots of time in their lives ;-)

August 26, 2010 at 2:47 am #295328

riq
Keymaster
@admin

quick status report:

It seems that everything was ported. I’ve started porting the tests and they work OK with almost no modifications.

BUT, BUT, BUT… it crashes every now and then while dispatching events… it think the cause of this is that cocos2d’s main loop is running in 1 thread while the cocos2d’s event dispatcher is running in another one.

I still don’t know how to do it, but I’ll try dispatch the events on the same thread as the the main loop thread.

Does anybody know how to do it ?

Update: I’ll try with performSelector:onThread:withObject:waitUntilDone:

August 26, 2010 at 3:11 am #295329

CJ
Moderator
@wiseganesha

@riq you can use this:

performSelectorOnMainThread: withObject: waitUntilDone:

August 26, 2010 at 3:31 am #295330

riq
Keymaster
@admin

@CJ:

Thanks. I tried it but it didn’t work… probably because the cocos2d’s main loop is triggered by the display link. The display link is not the main thread, but it seems that it is an “special” thread.

I tried performing a selector on that thread with “waintUntilDone = NO”, and it never returns… it seems that the display link thread has ultra-super-high priority privileges an nobody can queue messages on that thread (this is pure speculation).

I tried with “waitUntilDone = YES”. It message returns immediately but the selector is never called.

Tomorrow I’ll try with different approaches.

August 26, 2010 at 8:12 am #295331

GameBit
@gamebit

re @riq “Who wants to port his/her game to Mac ?”

I played for 3h trying to port one of my games to Mac and can say that its not a walk in a park :) Well i guess it depends on how complicated your game is…

Actually im bit surprised about way u took doing port. Emulating UIEvent instead using NSEvent (or introducing CCEvent to not use Apple namespaces) would make porting way easier, on the other hand noone forbids do it myself.

Anyway, nice job.

August 26, 2010 at 12:56 pm #295332

riq
Keymaster
@admin

status:

Actually the display link thread is a dedicated thread without a “runloop”, thats why I couldn’t add “perform on thread”.

I think that adding a RunLoop to the display link mainloop is enough to fix it.

But instead of doing that, which I think is a good solution, and I took an slightly different approach:

- cocos2d has its own thread.

- rendering is done on the cocos2d’s thread

- dispatch events are done also on the cocos2d’s thread.

a)

Pros & Cons If cocos2d thread is the same as the Display Link thread:

Pros: rendering doesn’t miss any frame

Cons: dispatching events might be slower

b)

Pros & Cons If cocos2d thread is the different from the display link thread:

Cons: A few frames might be skipped under very intensive GPU games

Pros: Events are dispatched very frequently

For the moment cocos2d-mac is using approach b).

August 26, 2010 at 12:59 pm #295333

riq
Keymaster
@admin

@GameBit:

For the moment cocos2d-mac doesn’t support touch events, but it will.

So, what you have to do is replace you “touches” code with “mouse” code.

eg:

-(id) init
{
if( (self=[super init]) ) {

#if __IPHONE_OS_VERSION_MIN_REQUIRED
self.isTouchEnabled = YES;
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
self.isMouseEnabled = YES;
#endif
}
return self;
}

//
// Callbacks
//
#if __IPHONE_OS_VERSION_MIN_REQUIRED
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch *touch in touches ) {
CGPoint location = [touch locationInView: [touch view]];

location = [[CCDirector sharedDirector] convertToGL: location];

[self addNewSpriteWithCoords: location];
}
}
#elif __MAC_OS_X_VERSION_MIN_REQUIRED
-(BOOL) ccMouseUp:(NSEvent *)event
{
CGPoint location = [(CCDirectorMac*)[CCDirector sharedDirector] convertEventToGL:event];
[self addNewSpriteWithCoords: location];

// return YES to swallow the event.
// return NO if you want to propagate this event to other event delegates
return YES;

}
#endif

August 26, 2010 at 2:45 pm #295334

GameBit
@gamebit

@riq

Yes i understand, i was talking about code level compatibility, when you write 1 code and framework does all heavy lifting of intercompatibility

sorry for confusion.

August 26, 2010 at 3:20 pm #295335

riq
Keymaster
@admin

@gamebit

The code is the same. The only thing that you’ll have to customize is the events basically because the events are handled different in both platforms.

Until cocos2d-mac supports touches, there is no point in creating a CCEvent object that unifies UIEvent and NSEvent, since NSEvent is only used in mac specific code, and UIEvent is used on iOS specific code.

iOS only supports touches, and Mac only supports mouse and keyboard. The intersection between Mac and iOS regarding events is nil, that’s why there is no CCEvent object.

November 15, 2010 at 10:35 pm #295336

cjkeeme
Participant
@cjkeeme

Will there be Mac templates soon for cocos2d?

November 15, 2010 at 10:45 pm #295337

riq
Keymaster
@admin

@cjkeeme: I hope so. Would you like to make them ?

In the meantime you can follow these instructions:

http://chris-fletcher.com/2010/10/24/howto-create-a-cocos2d-mac-project/

November 18, 2010 at 3:13 pm #295338

cfletcher80
Participant
@cfletcher80

@riq: I’m the one that made tutorial, I’d be happy to help with the templates, but I’ve never done any templates before so I’m not sure where to start. If you could point me in the right direction I’d be happy to help.

Viewing 25 posts - 1 through 25 (of 41 total)

You must be logged in to reply to this topic.