1
0
mirror of https://github.com/thes3m/XNI synced 2024-12-26 13:26:06 +01:00

NSCoding support added to data classes.

git-svn-id: http://xni.googlecode.com/svn/XNI@120 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
Matej Jan 2012-10-11 21:45:34 +00:00
parent 72b6b40a2a
commit 08abf7ffe0
18 changed files with 113 additions and 10 deletions

View File

@ -10,7 +10,7 @@
#import "Retronator.Xni.Framework.classes.h"
@interface Color : NSObject <NSCopying> {
@interface Color : NSObject <NSCopying, NSCoding> {
uint packedValue;
}

View File

@ -43,6 +43,18 @@
return [self initWithRed:color.r green:color.g blue:color.b alpha:color.a];
}
- (id) initWithCoder:(NSCoder *)aDecoder {
if (self = [super init]) {
packedValue = [aDecoder decodeIntForKey:@"packedValue"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeInt:packedValue forKey:@"packedValue"];
}
+ (Color*) colorWithRed:(int)red green:(int)green blue:(int)blue alpha:(int)alpha {
return [[[Color alloc] initWithRed:red green:green blue:blue alpha:alpha] autorelease];
}

View File

@ -10,7 +10,7 @@
#import "Retronator.Xni.Framework.classes.h"
@interface Vector4 : NSObject <NSCopying> {
@interface Vector4 : NSObject <NSCopying, NSCoding> {
Vector4Struct data;
}

View File

@ -32,6 +32,20 @@
return [self initWithVector4Struct:vector.data];
}
- (id) initWithCoder:(NSCoder *)aDecoder {
return [self initWithX:[aDecoder decodeFloatForKey:@"x"]
y:[aDecoder decodeFloatForKey:@"y"]
z:[aDecoder decodeFloatForKey:@"z"]
w:[aDecoder decodeFloatForKey:@"w"]];
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeFloat:data.x forKey:@"x"];
[aCoder encodeFloat:data.y forKey:@"y"];
[aCoder encodeFloat:data.z forKey:@"z"];
[aCoder encodeFloat:data.w forKey:@"w"];
}
+ (Vector4*) vectorWithX:(float)x y:(float)y z:(float)z w:(float)w {
return [[[Vector4 alloc] initWithX:x y:y z:z w:w] autorelease];
}

View File

@ -10,7 +10,7 @@
#import "Retronator.Xni.Framework.classes.h"
@interface Matrix : NSObject <NSCopying> {
@interface Matrix : NSObject <NSCopying, NSCoding> {
MatrixStruct data;
}

View File

@ -23,6 +23,25 @@
return [self initWithMatrixStruct:matrix.data];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if (self) {
float *values = &data.m11;
for (int i=0; i<16; i++) {
values[i] = [aDecoder decodeFloatForKey:[NSString stringWithFormat:@"%i", i]];
}
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
float *values = &data.m11;
for (int i=0; i<16; i++) {
[aCoder encodeFloat:values[i] forKey:[NSString stringWithFormat:@"%i", i]];
}
}
+ (Matrix*) matrixWithStruct: (MatrixStruct*)matrixStruct {
return [[[Matrix alloc] initWithMatrixStruct:matrixStruct] autorelease];
}

View File

@ -10,7 +10,7 @@
#import "Retronator.Xni.Framework.classes.h"
@interface Quaternion : NSObject <NSCopying> {
@interface Quaternion : NSObject <NSCopying, NSCoding> {
Vector4Struct data;
}

View File

@ -37,6 +37,20 @@
return [self initWithVector4Struct:quaternion.data];
}
- (id) initWithCoder:(NSCoder *)aDecoder {
return [self initWithX:[aDecoder decodeFloatForKey:@"x"]
y:[aDecoder decodeFloatForKey:@"y"]
z:[aDecoder decodeFloatForKey:@"z"]
w:[aDecoder decodeFloatForKey:@"w"]];
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeFloat:data.x forKey:@"x"];
[aCoder encodeFloat:data.y forKey:@"y"];
[aCoder encodeFloat:data.z forKey:@"z"];
[aCoder encodeFloat:data.w forKey:@"w"];
}
+ (Quaternion*) quaternionWithX:(float)x y:(float)y z:(float)z w:(float)w {
return [[[Quaternion alloc] initWithX:x y:y z:z w:w] autorelease];
}

View File

@ -11,7 +11,7 @@
#import "Retronator.Xni.Framework.classes.h"
@interface Rectangle : NSObject <NSCopying> {
@interface Rectangle : NSObject <NSCopying, NSCoding> {
RectangleStruct data;
}

View File

@ -32,6 +32,20 @@
return [self initWithRectangleStruct:rectangle.data];
}
- (id) initWithCoder:(NSCoder *)aDecoder {
return [self initWithX:[aDecoder decodeIntForKey:@"x"]
y:[aDecoder decodeIntForKey:@"y"]
width:[aDecoder decodeIntForKey:@"width"]
height:[aDecoder decodeIntForKey:@"height"]];
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeInt:data.x forKey:@"x"];
[aCoder encodeInt:data.y forKey:@"y"];
[aCoder encodeInt:data.width forKey:@"width"];
[aCoder encodeInt:data.height forKey:@"height"];
}
+ (Rectangle*) rectangleWithX:(int)x y:(int)y width:(int)width height:(int)height {
return [[[Rectangle alloc] initWithX:x y:y width:width height:height] autorelease];
}

View File

@ -10,7 +10,7 @@
#import "Retronator.Xni.Framework.classes.h"
@interface Vector2 : NSObject <NSCopying> {
@interface Vector2 : NSObject <NSCopying, NSCoding> {
Vector2Struct data;
}

View File

@ -32,6 +32,15 @@
return [self initWithVector2Struct:vector.data];
}
- (id) initWithCoder:(NSCoder *)aDecoder {
return [self initWithX:[aDecoder decodeFloatForKey:@"x"] y:[aDecoder decodeFloatForKey:@"y"]];
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeFloat:data.x forKey:@"x"];
[aCoder encodeFloat:data.y forKey:@"y"];
}
+ (Vector2*) vectorWithX:(float)x y:(float)y{
return [[[Vector2 alloc] initWithX:x y:y] autorelease];
}

View File

@ -10,7 +10,7 @@
#import "Retronator.Xni.Framework.classes.h"
@interface Vector3 : NSObject <NSCopying> {
@interface Vector3 : NSObject <NSCopying, NSCoding> {
Vector3Struct data;
}

View File

@ -32,6 +32,18 @@
return [self initWithVector3Struct:vector.data];
}
- (id) initWithCoder:(NSCoder *)aDecoder {
return [self initWithX:[aDecoder decodeFloatForKey:@"x"]
y:[aDecoder decodeFloatForKey:@"y"]
z:[aDecoder decodeFloatForKey:@"z"]];
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeFloat:data.x forKey:@"x"];
[aCoder encodeFloat:data.y forKey:@"y"];
[aCoder encodeFloat:data.z forKey:@"z"];
}
+ (Vector3*) vectorWithX:(float)x y:(float)y z:(float)z {
return [[[Vector3 alloc] initWithX:x y:y z:z] autorelease];
}

View File

@ -11,7 +11,7 @@
#import "Retronator.Xni.Framework.classes.h"
@interface XniPoint : NSObject <NSCopying> {
@interface XniPoint : NSObject <NSCopying, NSCoding> {
PointStruct data;
}

View File

@ -31,6 +31,15 @@
return [self initWithPointStruct:point.data];
}
- (id) initWithCoder:(NSCoder *)aDecoder {
return [self initWithIntX:[aDecoder decodeIntForKey:@"x"] y:[aDecoder decodeIntForKey:@"y"]];
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeInt:data.x forKey:@"x"];
[aCoder encodeInt:data.y forKey:@"y"];
}
+ (XniPoint*) pointWithX:(int)x y:(int)y {
return [[[XniPoint alloc] initWithIntX:x y:y] autorelease];
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0440"
LastUpgradeVersion = "0450"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0440"
LastUpgradeVersion = "0450"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"