NSMutableArray with vec2 as cells?
+2
oioioi
Muller
6 posters
NSMutableArray with vec2 as cells?
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?
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
Re: NSMutableArray with vec2 as cells?
Why not just make a normal c array?
oioioi- Posts : 136
Join date : 2008-12-02
Location : Norway
Re: NSMutableArray with vec2 as cells?
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.
C? Screw it. I'm all for OOP.
Muller- Posts : 11
Join date : 2009-05-26
Re: NSMutableArray with vec2 as cells?
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.
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
Re: NSMutableArray with vec2 as cells?
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?
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
Re: NSMutableArray with vec2 as cells?
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..
Re: NSMutableArray with vec2 as cells?
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?
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
Re: NSMutableArray with vec2 as cells?
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
Re: NSMutableArray with vec2 as cells?
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
Re: NSMutableArray with vec2 as cells?
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?
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
Re: NSMutableArray with vec2 as cells?
Hi, perhaps this post will help you:
https://sio2interactive.forumotion.net/sio2-engine-f3/integrating-sio2-with-obj-c-classes-t791.htm
--yarri
https://sio2interactive.forumotion.net/sio2-engine-f3/integrating-sio2-with-obj-c-classes-t791.htm
--yarri
yarri- Posts : 81
Join date : 2009-04-10
Re: NSMutableArray with vec2 as cells?
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
Re: NSMutableArray with vec2 as cells?
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.
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
Re: NSMutableArray with vec2 as cells?
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
yarri- Posts : 81
Join date : 2009-04-10
Permissions in this forum:
You cannot reply to topics in this forum