Re: ObjC 3D Engine
Re: ObjC 3D Engine
- Subject: Re: ObjC 3D Engine
- From: Jonathan deWerd <email@hidden>
- Date: Mon, 25 Jun 2007 18:35:09 -0600
On Jun 25, 2007, at 2:45 PM, Uli Kusterer wrote:
> On 25.06.2007, at 18:59, Kaelin Colclasure wrote:
>> Second, if you *must* use C++ keep it isolated into dedicated (and
>> hopefully small), performance-critical modules -- ideally that are
>> compiled as a separate target from the bulk of your project. I
>> recommend against falling into the practice of using ObjC++ for
>> all of your sources. Your compilation times suffer, and more
>> insidiously the incompatibility between ObjC and C++ exceptions
>> makes it extremely tricky to use either safely.
>
> I can definitely attest to that. You don't want to run the ObjC++
> compiler on even one more file than you need to.
Unfortunately, I currently use templated vectors and matricies, which
need to be in pch files, forcing the extremely slow pch compiles. If
we can agree on structure formats (i.e. only use O3Mat4x4d) we could
really clean a lot of code up. Probably the biggest ugliness I was
referring to in my original post was the ObjC++ build lag and the
complexity of templates.
I guess the only question remaining, then, is whether the bulk of the
app is in C++ or ObjC (either of which should compile quickly
enough). Of course, if you're in my line of work this decision is
made for you by the Windows guys ;)
ObjC. All C++ should be put to death ASAP (IMHO, but I think most
will agree).
> Personally, I'd create a Cocoa wrapper class that looks like
> NSArray from the outside and uses STL only on the inside. Or even
> better, just write your own code with an NSMutableData block as the
> backing store for a C array. Or just malloc a block, whatever
> floats your boat, man. If you're really only using std::vector,
> that should give you about the same performance if you know any
> algorithm basics.
I am darn near positive that I saw a wrapper which let you use
vectors and NSArrays interchangeably somewhere, but I cannot remember
where :(
Yuck! NSValueArray hopefully solves the problem of storing vectors. I
have yet to add one-dimensional convenience functions and a mutable
version (right now it is mutable but can't grow), but it is
absolutely awesome for this kind of stuff. Think NSArray of NSValues
but without the memory overhead and perhaps slightly faster on top of
that. My original idea was to abstract away all uncompressed image
formats, but I only realized how powerful the concept was when I
started testing it. It's really cool. Oh, and when I get the
O3GPUData class working better it will be able to use a VBO as a
backing. For instance, this works:
double vals[] = {1,2,3,4,
5,6,7,8,
9,10,11,12,
13,14,15,16};
O3Mat4x4d mat(vals);
O3ValueArray* vals = [[O3ValueArray alloc]
initWithDimensions:O3MakeIndex(3,2) objcType:@encode(mat)]; //A 3x2
matrix of 4x4d matricies.
[vals setValueAtIndex:O3MakeIndex(2,1) toMatrix:mat];
NSData* d = [vals portableData]; //Send this over a network, across
architectures, in a file, whatever.
O3ValueArray* d2 = d; //The receiving end
O3Mat4x4i mat(vals); //Note: ints, not doubles as above
O3ValueArray* vals2 = [[O3ValueArray alloc] initWithPortableData:d
objcType:@encode(O3Mat4x4d) dimensions:O3MakeIndex(3,2)];
mat = [vals2 matrixAtIndex:O3MakeIndex(2,1)]; //Proper casting from
double to int performed automatically
> The only types where it would be worthwhile are std::map and a few
> other of the more complex STL types.
Speaking of this, is there any equivalent type to set<> or map<> in
Cocoa? There are arrays and hash table types, but are there any
ordered-container types? I was dealing with this just recently and
ended up using an NSMutableDictionary along with a line I am not
proud of:
return [dict objectForKey:[[[dict allKeys]
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]
objectAtIndex:index]];
I kept telling myself, "this isn't going to be used in shipping code,
it's fast enough, who cares" but in the back of my head I'm still
trying to think of alternate solutions
Unfortunately I don't think so. I used the C++ :/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden