FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Integrating SIO2 with Obj C classes

5 posters

Go down

Integrating SIO2 with Obj C classes Empty Integrating SIO2 with Obj C classes

Post  bwalker Tue Jul 28, 2009 5:23 pm

hi there,

I've just started delving into SIO2. Pretty cool so far. I've got one of the tutorial apps integrated as a subview into a basic iPhone app I've been working on. However I'm having trouble conceptualizing how to communicate between my Objective C classes and the C template.mm class. I could throw all my function calls into the EAGL view, but that seems messy and would rather follow how you've set up your tutorials. How do I call the C class functions from my Objective C classes?

thanks!
-brett

p.s. - The "change your file types to ccp.objcpp" trick to solve the 2000 compile errors got me for a couple hours. Might want to include that caveat more prominently, as it's certainly not immediately obvious...

bwalker

Posts : 10
Join date : 2009-07-28

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  sio2interactive Tue Jul 28, 2009 5:27 pm

Why didn't simply use the template project... its inside the SDK especially for that... simply copy past e it then start building...

Linking SIO2 from scratch is a pita... Wink
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  bwalker Tue Jul 28, 2009 5:36 pm

sio2interactive wrote:Why didn't simply use the template project... its inside the SDK especially for that... simply copy past e it then start building...

Linking SIO2 from scratch is a pita... Wink

Mostly because I've already done a fair amount of dev work on my app and the 3D rendering aspect is only a part of it. I looked at the template app, but didn't see any code specifically in there to talk to the template.mm classes from Objective C classes. I need to control certain things within the 3D scene beyond just the touch/accelerometer events.

thanks!
-brett

bwalker

Posts : 10
Join date : 2009-07-28

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  yarri Tue Jul 28, 2009 5:42 pm

I agree, start from the template references. But for the few of us interested in using UIKit based apps, a reference template for integrating SIO2 into a multiview app might be helpful. I personally use SIO2 within a UITabView app, relying on UIKit for game lobby functions. The structure I use is to refactor the default EAGLView class to pass parameters to the standard template() function. Something like this:

Code:

EAGLView.h

- (void)setSceneNumber:(int) scene;

EAGLView.mm
- (void)setSceneNumber:(int) scene
{
   templateSetScene ( scene_number );
}

template.h
void templateSetScene ( int scene );

template.mm
void templateSetScene ( int scene )
{
   scene_number = scene;    // global declared within template.mm, used within templateLoading() to pickup the right SIO2 scene file
}

I can contribute a sample app if interested.

--yarri

yarri

Posts : 81
Join date : 2009-04-10

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  bwalker Tue Jul 28, 2009 6:04 pm

yarri, that code was exactly what I needed to "get it". Thanks so much!

I agree though that a sample tutorial showing integrating other UIKit views/components might be helpful to newcomers.

bwalker

Posts : 10
Join date : 2009-07-28

Back to top Go down

Integrating SIO2 with Obj C classes Empty Sample PLEASE!!

Post  Reece Mon Aug 03, 2009 12:13 am

bwalker wrote:I agree though that a sample tutorial showing integrating other UIKit views/components might be helpful to newcomers.

I need a sample showing how to integrate the UIKit views etc and SIO2. PLEASE can someone make available a sample of this especially in the context of a game lobby use case. A downloadable zip of a working project would be perfect!!

Cheers
Reece

Reece

Posts : 2
Join date : 2009-05-16

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  sio2interactive Mon Aug 03, 2009 12:28 am

If someone make that tutorial, it would be a pleasure for me to host it... cuz my knowledge of cocoa is NULL (yes Im oldschool and prefer to code everything) and I feel sorry that I cannot help on that so... that's the least I can do Smile

Cheers,
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  bwalker Mon Aug 03, 2009 11:40 am

Reece wrote:

I need a sample showing how to integrate the UIKit views etc and SIO2. PLEASE can someone make available a sample of this especially in the context of a game lobby use case. A downloadable zip of a working project would be perfect!!

Cheers
Reece

I'll try to put together a tutorial if I get a chance, but yarri's code is a good start. Basically, since EAGLView extends UIView, you can add that as a subview to whatever UIController you want. That's the easy part. Communicating between the C-based SIO2 code and the Objective C classes is a bit trickier. Basically it breaks down like this. Any UIKit class you import the SIO2 header file into (e.g. '#include "../../src/sio2/sio2.h"') can access the SIO2 methods and classes. You can also do the same thing with the "template.h" header file seen in the SIO2 tutorials. Thus from the UIKit class you can call a method like "exampleMethod(x, y);", where "exampleMethod" has been defined in the template.mm/h files. (See yarri's code above) Note that you call the method in normal C syntax, not the Objective C style, even though you're calling it from Objective C code.

Not sure if that makes sense, but basically you can call methods and pass parameters in your C code as much as you want. I haven't tried calling Obj C methods from the C classes, although I imagine that would work also.

bwalker

Posts : 10
Join date : 2009-07-28

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  yarri Mon Aug 03, 2009 2:33 pm

Hi, here's a working example you can start with:
www.playngive.com/UIKitDemo.zip


Couple of points:
- This is a UITabView based app, with a list of tutorials in one tab and a settings screen the other tab
- As an example, the settings tab currently shows a debug mode switch, you can add others
- Modes are passed to the SIO2 template function via the call chain described earlier in the post
- The current tutorial structure doesn't easily allow you to create an app containing all the individual tutorials because of naming conflicts, you could write a script to rename the template() functions to something like template001(), but I don't have time...
- The sio2 structure is not atomic, so this code is *not* reentrant; you'll have to provide your own clean up function and/or rewrite the EAGLview
- The current tutorials don't have a way to "end" except for a hard exit, so I added a simple UIKit button on top of the EAGLview to pause/quit the game; obviously in a real game this would probably be done by a game loop timer

Thanks,
--yarri

yarri

Posts : 81
Join date : 2009-04-10

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  Reece Tue Aug 04, 2009 2:38 am

yarri wrote:Hi, here's a working example you can start with:
www.playngive.com/UIKitDemo.zip
...
--yarri

This is exactly what I was looking for! Thanks for taking the time to provide it Very Happy

Cheers
Reece

Reece

Posts : 2
Join date : 2009-05-16

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  yarri Tue Aug 04, 2009 12:09 pm

Sure, memory leaks and all! The tricky part is screen orientation and UIKit overlays, which I've solved in a way that works for me. You'll have to find your own way to make the calls to the sio2 engine reentrant, I'd be interested in seeing what you come up with. Also, for some reason the touch point locations are inverted; works fine with 1.3.6 so I did something wrong when integrating with 1.4.

BTW, I think it'd be more elegant to stuff the whole sio2 structure into a singleton to support calls like this:
Code:

[[SIO2 sharedEngine] initWithResource:@"generic.sio2"]

But that would take a little more work Smile

--yarri

yarri

Posts : 81
Join date : 2009-04-10

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  mlc Thu Oct 22, 2009 10:16 pm

Yarri,

Thanks for this code (UIKitCode).

For others who might want to get you example reentrant, I tweaked the template.mm code to make it so.

1) Right before the call to change the _SIO2windowrender to the templateRender, just set the static int back to 0.
sio2->_SIO2window->_SIO2windowrender = templateRender;
i = 0; // mlc addition: sets the static int back to 0 so it will work "next time"!

2) _SIO2font is another static and so it also needs to be re-initialized. Do this after the call to sio2Shutdown():
sio2 = sio2Shutdown();
_SIO2font = NULL; // mlc addition: so font will rebuild itself, "next time"

I agree that a singleton is probably better, but the above code I think is all that's needed for that particular example.

Again, thanks for showing us how to do this mix,

-Mike (mlc)

mlc

Posts : 2
Join date : 2009-10-09

Back to top Go down

Integrating SIO2 with Obj C classes Empty Re: Integrating SIO2 with Obj C classes

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

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