[patch] less footprint to load PNG

View previous topic View next topic Go down

[patch] less footprint to load PNG

Post  ricardoquesada on Tue Aug 04, 2009 9:04 am

Hi,

this is a patch for sio2 1.4.0.
It loads .PNG images with less memory footprint (a probably it loads them a little faster).
It doesn't call sioImageFlip. Instead, it "flips" the image when it loads it.

Code:

--- sio2_image.cc   2009-08-04 11:56:16.000000000 -0300
+++ sio2_image-patch.cc   2009-08-04 11:56:08.000000000 -0300
@@ -413,7 +413,7 @@
    while( i < ( int )_SIO2image->height )
    {
       _png_bytep[ i ] = ( png_bytep )(  _SIO2image->tex    +
-                               ( _SIO2image->height - ( i + 1 ) ) *
+                               i  *
                                 _SIO2image->width  *
                                 _SIO2image->bits );
       ++i;
@@ -428,7 +428,7 @@
                       &_png_infop, NULL );
    free( _png_bytep );
    
-   sio2ImageFlip( _SIO2image );
+//   sio2ImageFlip( _SIO2image );
    
    if( _SIO2image->bits == 4 )
    { sio2ImageRGBAtoBGRA( _SIO2image ); }
avatar
ricardoquesada

Posts : 3
Join date : 2009-08-04

View user profile http://www.cocos2d-iphone.org

Back to top Go down

Re: [patch] less footprint to load PNG

Post  yarri on Tue Aug 04, 2009 12:17 pm

Wow, Riq good to see you here... I was just thinking about using cocos2D for my HUD gui layer on top of SIO2; any chance you have a patch to support that :-) If not, a recommendation will do.

--yarri

yarri

Posts : 81
Join date : 2009-04-10

View user profile

Back to top Go down

Re: [patch] less footprint to load PNG

Post  ricardoquesada on Tue Aug 04, 2009 7:31 pm

Hi yarri,
I'm not familiar with sio2's internals, so this is just a guess:

To mix cocos2d inside sio2:
- initialize cocos2d, but comment the opengl initialization (already done by sio2)
- don't run any scene
- modify Director.m so that you can insert an scene without running using the API
- from a sio2 timer, call Director#mainLoop
- also, sio2's openglview should be assigned to the Director (so both of them uses the same openglview)
- Director#mainLoop should have these lines commented:
- // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // don't clear the screen, let sio2 do it
- // [openGLView_ swapBuffers]; // don't swap the opengl buffers
- Director mainLoop should also have:
- save the current projection matrix (sio2 projection matrix)
- set cocos2d projection matrix
- (draw cocos2d scene)
- restore sio2 projection matrix

as I said, this is just a guess.
avatar
ricardoquesada

Posts : 3
Join date : 2009-08-04

View user profile http://www.cocos2d-iphone.org

Back to top Go down

Re: [patch] less footprint to load PNG

Post  yarri on Sat Sep 05, 2009 12:45 am

Hi, I think I got this working by the way... I'm running cocos2D on top of SIO2. As Riq said, you have to initialize cocos2D within EAGLView, modify Director.m to call mainLoop() within templateRender() and it seems to be running ok:



--yarri

yarri

Posts : 81
Join date : 2009-04-10

View user profile

Back to top Go down

Re: [patch] less footprint to load PNG

Post  ricardoquesada on Sat Sep 05, 2009 7:49 am

Nice work yarri!
avatar
ricardoquesada

Posts : 3
Join date : 2009-08-04

View user profile http://www.cocos2d-iphone.org

Back to top Go down

Re: [patch] less footprint to load PNG

Post  yarri on Sat Sep 05, 2009 9:34 am

Thanks, so far minimal changes to cocos2D. I'll try to work on an HUD example but having trouble with your new TouchDispatcher. I think I need to have SIO2 pass touches to cocos2D instead of the other way around. I'll upload a test case of cocos2D menus/buttons controlling the rate of the spinning square from SIO2 tutorial01. Hopefully.

--yarri

yarri

Posts : 81
Join date : 2009-04-10

View user profile

Back to top Go down

Re: [patch] less footprint to load PNG

Post  Francescu on Sat Sep 05, 2009 3:58 pm

Hey Yarri,

Am just curious about the use of Cocos2D on top of SIO2 - what does that give you for your hud versus using plain sio2 widgets?

Thanks for sharing this btw.

Cheers

--Frank

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: [patch] less footprint to load PNG

Post  yarri on Sat Sep 05, 2009 4:55 pm

Hi, for our games we have some simple sprite animations that I've written with SIO2widgets but it's tedious. The power of cocos2d is to do something like this to animate a sprite:

Code:

id action1 = [MoveTo actionWithDuration:2 position:ccp(100,100)];
id action2 = [MoveBy actionWithDuration:2  position: ccp(80,80)];
id action3 = [MoveBy actionWithDuration:2  position: ccp(0,80)];
[sprite runAction: [Sequence actions:action1, action2, action3, nil]];

Someone posted similar capabilities for SIO2 v1.2:
http://sio2interactive.forumotion.net/sio2-engine-f3/sprite-additions-t502.htm

Without this type of sequence controller it's hard to have an animated HUD... think of "blooms" and "particle effects" around high score achievements, etc.

Thanks,
--yarri

yarri

Posts : 81
Join date : 2009-04-10

View user profile

Back to top Go down

Re: [patch] less footprint to load PNG

Post  Francescu on Sat Sep 05, 2009 8:07 pm

I see - interesting indeed.

I haven't looked at Cocos2D footprint but am wondering how this would add up with SIO2's one at runtime (memory footprint) and the downloadable footprint for the .app (size)...

Thanks.

PS: Might have been good to see Uprise's changes available as part of SIO2 or as an extension to it...

Francescu

Posts : 136
Join date : 2009-03-18

View user profile

Back to top Go down

Re: [patch] less footprint to load PNG

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum