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.

NSMutableArray with vec2 as cells?

+2
oioioi
Muller
6 posters

Go down

NSMutableArray with vec2 as cells? Empty NSMutableArray with vec2 as cells?

Post  Muller Wed Oct 14, 2009 8:22 am

I'm currently learning to use Objective-C, and trying to create a NSMutableArray where each cell is a vec2 struct from SIO2.

I read that I cannot do that, a cell in a NSMutableArray cannot be a C struct or type (such as bool, float), so what is the solution here exactly?

I thought it'd be easy to use Objective-C and SIO2 structs together?

Muller

Posts : 11
Join date : 2009-05-26

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  oioioi Wed Oct 14, 2009 8:29 am

Why not just make a normal c array?

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  Muller Wed Oct 14, 2009 8:30 am

If anything the choice is between Objective-C (which I'm trying to learn, thus I'd like to use it...) and C++, which I'm very familiar with.

C? Screw it. I'm all for OOP.

Muller

Posts : 11
Join date : 2009-05-26

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  oioioi Wed Oct 14, 2009 8:34 am

Arrays are the same in c and c++

You can make your own array class in c++, that way you can make the size dynamic too.

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  Muller Wed Oct 14, 2009 8:38 am

I know C and C++.

I'm trying to use Objective-C for my game so it'd be easy to interact with iPhone functions and whatnot.

I'm asking if it's easy to use Objective-C with SIO2. I read that it is, but then I find it impossible to create an NSArray where each cell is a C struct, in this case an SIO2 vec2.

Any ideas?

Muller

Posts : 11
Join date : 2009-05-26

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  IanLinart Wed Oct 14, 2009 9:22 am

Muller wrote:I know C and C++.

I'm trying to use Objective-C for my game so it'd be easy to interact with iPhone functions and whatnot.

I'm asking if it's easy to use Objective-C with SIO2. I read that it is, but then I find it impossible to create an NSArray where each cell is a C struct, in this case an SIO2 vec2.

Any ideas?

No.. an NSArray can only contains objects..
IanLinart
IanLinart

Posts : 26
Join date : 2009-08-12
Age : 35
Location : Montréal

http://iapps.linart.qc.ca

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  Muller Wed Oct 14, 2009 9:41 am

Can I convert vec2 into an Obj-C object then?

What language are you people using for your games? C++? C? Obj-C?

Has anyone used Obj-C and found it a smart choice?

If you use C or C++, how easy is it to call iPhone API function calls with your C/C++ objects?

Muller

Posts : 11
Join date : 2009-05-26

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  Francescu Wed Oct 14, 2009 9:50 am

Muller wrote:I'm currently learning to use Objective-C, and trying to create a NSMutableArray where each cell is a vec2 struct from SIO2.

I read that I cannot do that, a cell in a NSMutableArray cannot be a C struct or type (such as bool, float), so what is the solution here exactly?

I thought it'd be easy to use Objective-C and SIO2 structs together?

If you want to do this, create a Vec2 class that encapsulates and represent an sio2 vec2 struct.
Bullet is C++ and has got vector 3D classes, if you want to look at it as an example.

Btw, the more specific objective-C you have in your code, the less portable it will be potentially - if you ever intend to port it on a different platform.

Francescu

Posts : 136
Join date : 2009-03-18

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  uprise78 Wed Oct 14, 2009 10:08 am

You can do it in Obj-C but I sure as heck wouldn't. It doesn't make any sense and the performance hit will be large if you loop it. You need to use NSValues as the objects in your array. Obj-C is just a thin layer on top of C so using C/C++ arrays IS Obj-C by it's very roots.

uprise78

Posts : 228
Join date : 2008-10-31

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  Muller Wed Oct 14, 2009 1:47 pm

Portability doesn't interest me, however...

If I use Obj-C, I will have to create custom classes for every SIO2 struct I wish to use? Sounds like too much work.

If I use C++ it will be trivial to use SIO2 and Bullet, but what about when I need to make iPhone API calls?

Muller

Posts : 11
Join date : 2009-05-26

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  yarri Wed Oct 14, 2009 1:52 pm


yarri

Posts : 81
Join date : 2009-04-10

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  oioioi Wed Oct 14, 2009 1:54 pm

Muller wrote:What language are you people using for your games? C++? C? Obj-C?

I think most people here only use obj-c for UIkit and calls to obj-c api. All the game logic is coded in c/c++ and maybe some lua. The developer of enigmo(popular mac and iphone game) said that the only obj-c code they had was to set up the opengl window, the rest was pure c, because it's easier to port to different platforms. I think you should write your games OO in c++ since that what your good at(right?)


EDIT:
-If I use C++ it will be trivial to use SIO2 and Bullet, but what about when I need to make iPhone API calls?

if you use the .mm file extension you can use c/c++/obj-c in the same file

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  Muller Wed Oct 14, 2009 3:38 pm

Looks like OO C++ it is.

Though I went through that other thread and it does seem like calls to UIKit elements in Obj-C together with SIO2 iss still a but messy at this stage.

Muller

Posts : 11
Join date : 2009-05-26

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  yarri Wed Oct 14, 2009 11:14 pm

FWIW, I've been writing ObjC helper classes to do things like read level information stored as pLists, stuff it into an NSArray and then access it from the C code within the templateLoading() function, for example. The structure I use is to simply include sio2.h in the class definition *.m file, and import that ObjC class in the template.mm file. Works great. Not at all portable, of course.

--yarri

yarri

Posts : 81
Join date : 2009-04-10

Back to top Go down

NSMutableArray with vec2 as cells? Empty Re: NSMutableArray with vec2 as cells?

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


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