diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/FontTextureProcessor.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/FontTextureProcessor.h new file mode 100644 index 0000000..d632d72 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/FontTextureProcessor.h @@ -0,0 +1,23 @@ +// +// FontTextureProcessor.h +// XNI +// +// Created by Matej Jan on 20.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ContentProcessor.h" + +@interface FontTextureProcessor : ContentProcessor { + unichar firstCharacter; + BOOL premultiplyAlpha; +} + +@property (nonatomic) unichar firstCharacter; +@property (nonatomic) BOOL premultiplyAlpha; + +- (unichar) getCharacterForIndex:(int)index; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/FontTextureProcessor.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/FontTextureProcessor.m new file mode 100644 index 0000000..548b03a --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/FontTextureProcessor.m @@ -0,0 +1,152 @@ +// +// FontTextureProcessor.m +// XNI +// +// Created by Matej Jan on 20.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "FontTextureProcessor.h" + +#import "Retronator.Xni.Framework.h" +#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h" + +#import "SpriteFontContent+Internal.h" + +static inline BOOL IsOnCharacter(Byte *color) { + return color[0] != 255 || color[1] != 0 || color[2] != 255 || color[3] != 255; +} + +static inline BOOL IsOnBlack(Byte *color) { + return color[0] == 0 && color[1] == 0 && color[2] == 0; +} + +@implementation FontTextureProcessor + +- (id) init +{ + self = [super init]; + if (self != nil) { + firstCharacter = ' '; + } + return self; +} + +@synthesize firstCharacter, premultiplyAlpha; + +- (Class) inputType { return [Texture2DContent class];} +- (Class) outputType { return [SpriteFontContent class];} + +- (SpriteFontContent*) process:(Texture2DContent*)input { + PixelBitmapContent *bitmap = (PixelBitmapContent*)[input.mipmaps objectAtIndex:0]; + + NSMutableDictionary *characterMap = [NSMutableDictionary dictionary]; + NSMutableArray *incompleteCharacters = [NSMutableArray array]; + + BOOL usesAlpha = NO; + + int lineSpacing = 0; + + int index = 0; + + for (int y = 0; y < bitmap.height; y++) { + // Clear all incomplete characters past this line. + int i=0; + while (i<[incompleteCharacters count]) { + Rectangle *rectangle = [incompleteCharacters objectAtIndex:i]; + if (y >= rectangle.y + rectangle.height) { + [incompleteCharacters removeObjectAtIndex:i]; + } else { + i++; + } + } + + int x = 0; + BOOL wasOnCharacter = NO; + + while (x < bitmap.width) { + Byte *color = [bitmap getPixelAtX:x Y:y]; + if (!usesAlpha && color[3] < 255) { + usesAlpha = YES; + } + + BOOL onCharacter = IsOnCharacter(color); + + if (!wasOnCharacter && onCharacter) { + // We've reached a new character, but first see if it is one of the incomplete ones. + BOOL new = YES; + for (Rectangle *rectangle in incompleteCharacters) { + if ([rectangle containsX:x y:y]) { + new = NO; + x = rectangle.x + rectangle.width - 1; + break; + } + } + + if (new) { + unichar character = [self getCharacterForIndex:index]; + Rectangle *rectangle = [Rectangle rectangleWithX:x y:y width:0 height:0]; + + // Find first off character pixel to the right. + int right = x; + while (right < bitmap.width && IsOnCharacter([bitmap getPixelAtX:right Y:y])) { + right++; + } + + // Do the same for bottom. + int bottom = y; + while (bottom < bitmap.height && IsOnCharacter([bitmap getPixelAtX:x Y:bottom])) { + bottom++; + } + + rectangle.width = right - x; + rectangle.height = bottom - y; + + if (rectangle.height > lineSpacing) { + lineSpacing = rectangle.height; + } + + [characterMap setObject:rectangle forKey:[NSNumber numberWithChar:character]]; + [incompleteCharacters addObject:rectangle]; + + index++; + x = right - 1; + } + } + + wasOnCharacter = onCharacter; + x++; + } + } + + for (int x = 0; x < bitmap.width; x++) { + for (int y = 0; y < bitmap.height; y++) { + Byte *color = [bitmap getPixelAtX:x Y:y]; + + if (!IsOnCharacter(color) || !usesAlpha && IsOnBlack(color)) { + // If the sprite font does not use an alpha channel we should key the black color. + // Always also key the separator color. + for (int i = 0; i < 4; i++) { + color[i]=0; + } + } else if (premultiplyAlpha) { + // Premultiply alpha for support of non-premultiplied images. + float factor = (float)color[4]/255.0f; + for (int i = 0; i < 3; i++) { + color[i] = (Byte)((float)color[i]*factor); + } + } + } + } + + SpriteFontContent* result = [[[SpriteFontContent alloc] initWithTexture:input + characterMap:characterMap + lineSpacing:lineSpacing] autorelease]; + return result; +} + +- (unichar) getCharacterForIndex:(int)index { + return firstCharacter + index; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/MaterialProcessor.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/MaterialProcessor.h new file mode 100644 index 0000000..18cbcaf --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/MaterialProcessor.h @@ -0,0 +1,17 @@ +// +// MaterialProcessor.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ContentProcessor.h" + +@interface MaterialProcessor : ContentProcessor { + +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/MaterialProcessor.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/MaterialProcessor.m new file mode 100644 index 0000000..725bb29 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/MaterialProcessor.m @@ -0,0 +1,18 @@ +// +// MaterialProcessor.m +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "MaterialProcessor.h" + +#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h" + +@implementation MaterialProcessor + +- (Class) inputType { return [MaterialContent class];} +- (Class) outputType { return [MaterialContent class];} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContent+Internal.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContent+Internal.h new file mode 100644 index 0000000..9e759a7 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContent+Internal.h @@ -0,0 +1,21 @@ +// +// ModelBoneContent+Internal.h +// XNI +// +// Created by Matej Jan on 29.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + + +@interface ModelBoneContent (Internal) + +- (id) initWithChildren:(NSArray*)theChildren + index:(int)theIndex + name:(NSString*)theName + transform:(Matrix*)theTransform; + +- (void) setParent:(ModelBoneContent*)theParent; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContent.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContent.h new file mode 100644 index 0000000..1a8731b --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContent.h @@ -0,0 +1,28 @@ +// +// ModelBoneContent.h +// XNI +// +// Created by Matej Jan on 29.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.classes.h" +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h" + +@interface ModelBoneContent : NSObject { + ModelBoneContentCollection *children; + int index; + NSString *name; + ModelBoneContent *parent; + Matrix *transform; +} + +@property (nonatomic, readonly) ModelBoneContentCollection *children; +@property (nonatomic, readonly) int index; +@property (nonatomic, readonly) NSString *name; +@property (nonatomic, readonly) ModelBoneContent *parent; +@property (nonatomic, retain) Matrix *transform; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContent.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContent.m new file mode 100644 index 0000000..74607f8 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContent.m @@ -0,0 +1,46 @@ +// +// ModelBoneContent.m +// XNI +// +// Created by Matej Jan on 29.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "ModelBoneContent.h" +#import "ModelBoneContent+Internal.h" + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h" + +@implementation ModelBoneContent + +- (id) initWithChildren:(NSArray *)theChildren + index:(int)theIndex + name:(NSString *)theName + transform:(Matrix *)theTransform +{ + self = [super init]; + if (self != nil) { + children = [[ModelBoneContentCollection alloc] initWithItems:theChildren]; + index = theIndex; + name = [theName retain]; + transform = [theTransform retain]; + } + return self; +} + +@synthesize children, index, name, parent, transform; + +- (void) setParent:(ModelBoneContent*)theParent { + parent = theParent; +} + +- (void) dealloc +{ + [children release]; + [name release]; + [transform release]; + [super dealloc]; +} + + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContentCollection.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContentCollection.h new file mode 100644 index 0000000..dd3c057 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContentCollection.h @@ -0,0 +1,19 @@ +// +// ModelBoneContentCollection.h +// XNI +// +// Created by Matej Jan on 29.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h" + +#define ReadOnlyCollection ModelBoneContentCollection +#define T ModelBoneContent* + +#include "ReadOnlyCollection.h" + +#undef ReadOnlyCollection +#undef T \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContentCollection.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContentCollection.m new file mode 100644 index 0000000..4c14596 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelBoneContentCollection.m @@ -0,0 +1,18 @@ +// +// ModelBoneContentCollection.m +// XNI +// +// Created by Matej Jan on 29.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "ModelBoneContentCollection.h" + + +#define ReadOnlyCollection ModelBoneContentCollection +#define T ModelBoneContent* + +#include "ReadOnlyCollection.m.h" + +#undef ReadOnlyCollection +#undef T diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelContent+Internal.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelContent+Internal.h new file mode 100644 index 0000000..5205f89 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelContent+Internal.h @@ -0,0 +1,17 @@ +// +// ModelContent+Internal.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ModelContent.h" + +@interface ModelContent (Internal) + +- (id) initWithBones:(NSArray*)theBones meshes:(NSArray*)theMeshes root:(ModelBoneContent*)theRoot tag:(id)theTag; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelContent.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelContent.h new file mode 100644 index 0000000..64d531b --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelContent.h @@ -0,0 +1,25 @@ +// +// ModelContent.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h" + +@interface ModelContent : NSObject { + ModelBoneContentCollection *bones; + ModelMeshContentCollection *meshes; + ModelBoneContent *root; + id tag; +} + +@property (nonatomic, readonly) ModelBoneContentCollection *bones; +@property (nonatomic, readonly) ModelMeshContentCollection *meshes; +@property (nonatomic, readonly) ModelBoneContent *root; +@property (nonatomic, retain) id tag; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelContent.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelContent.m new file mode 100644 index 0000000..fcd2965 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelContent.m @@ -0,0 +1,40 @@ +// +// ModelContent.m +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "ModelContent.h" + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h" + +@implementation ModelContent + +- (id) initWithBones:(NSArray*)theBones meshes:(NSArray*)theMeshes root:(ModelBoneContent*)theRoot tag:(id)theTag; +{ + self = [super init]; + if (self != nil) { + bones = [[ModelBoneContentCollection alloc] initWithItems:theBones]; + meshes = [[ModelMeshContentCollection alloc] initWithItems:theMeshes]; + root = [theRoot retain]; + self.tag = theTag; + } + return self; +} + +@synthesize bones, meshes, root, tag; + +- (void) dealloc +{ + [bones release]; + [meshes release]; + [root release]; + [tag release]; + [super dealloc]; +} + + +@end + \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContent+Internal.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContent+Internal.h new file mode 100644 index 0000000..9e91211 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContent+Internal.h @@ -0,0 +1,17 @@ +// +// ModelMeshContent+Internal.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ModelMeshContent.h" + +@interface ModelMeshContent (Internal) + +- (id) initWithName:(NSString*)theName parentBone:(ModelBoneContent*)theParentBone modelMeshParts:(NSArray*)theModelMeshParts tag:(id)theTag sourceMesh:(MeshContent*)theSourceMesh; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContent.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContent.h new file mode 100644 index 0000000..63ff2a4 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContent.h @@ -0,0 +1,28 @@ +// +// ModelMeshContent.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h" +#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h" + +@interface ModelMeshContent : NSObject { + ModelMeshPartContentCollection *meshParts; + NSString *name; + ModelBoneContent *parentBone; + id tag; + MeshContent *sourceMesh; +} + +@property (nonatomic, readonly) ModelMeshPartContentCollection *meshParts; +@property (nonatomic, readonly) NSString *name; +@property (nonatomic, readonly) ModelBoneContent *parentBone; +@property (nonatomic, retain) id tag; +@property (nonatomic, readonly) MeshContent *sourceMesh; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContent.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContent.m new file mode 100644 index 0000000..6ce13f5 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContent.m @@ -0,0 +1,41 @@ +// +// ModelMeshContent.m +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "ModelMeshContent.h" + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h" +#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h" + +@implementation ModelMeshContent + +- (id) initWithName:(NSString *)theName parentBone:(ModelBoneContent*)theParentBone modelMeshParts:(NSArray *)theModelMeshParts tag:(id)theTag sourceMesh:(MeshContent*)theSourceMesh +{ + self = [super init]; + if (self != nil) { + name = [[NSString alloc] initWithString:theName]; + meshParts = [[ModelMeshPartContentCollection alloc] initWithItems:theModelMeshParts]; + parentBone = [theParentBone retain]; + self.tag = theTag; + sourceMesh = [theSourceMesh retain]; + } + return self; +} + +@synthesize name, parentBone, meshParts, tag, sourceMesh; + +- (void) dealloc +{ + [sourceMesh release]; + [name release]; + [parentBone release]; + [meshParts release]; + [tag release]; + [super dealloc]; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContentCollection.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContentCollection.h new file mode 100644 index 0000000..d697c12 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContentCollection.h @@ -0,0 +1,19 @@ +// +// ModelMeshContentCollection.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h" + +#define ReadOnlyCollection ModelMeshContentCollection +#define T ModelMeshContent* + +#include "ReadOnlyCollection.h" + +#undef ReadOnlyCollection +#undef T diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContentCollection.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContentCollection.m new file mode 100644 index 0000000..078c669 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshContentCollection.m @@ -0,0 +1,17 @@ +// +// ModelMeshContentCollection.m +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "ModelMeshContentCollection.h" + +#define ReadOnlyCollection ModelMeshContentCollection +#define T ModelMeshContent* + +#include "ReadOnlyCollection.m.h" + +#undef ReadOnlyCollection +#undef T diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContent+Internal.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContent+Internal.h new file mode 100644 index 0000000..0187007 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContent+Internal.h @@ -0,0 +1,24 @@ +// +// ModelMeshPartContent+Internal.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ModelMeshPartContent.h" + +@interface ModelMeshPartContent (Internal) + +- (id) initWithVertexOffset:(int)theVertexOffset + numVertices:(int)theNumVertices + startIndex:(int)theStartIndex + primitiveCount:(int)thePrimitiveCount + tag:(id)theTag + indexBuffer:(IndexCollection*)theIndexBuffer + vertexBuffer:(VertexBufferContent*)theVertexBuffer + material:(MaterialContent*)theMaterial; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContent.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContent.h new file mode 100644 index 0000000..8cb0662 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContent.h @@ -0,0 +1,36 @@ +// +// ModelMeshPartContent.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h" +#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h" +#import "Retronator.Xni.Framework.Graphics.classes.h" + +@interface ModelMeshPartContent : NSObject { + MaterialContent *material; + IndexCollection *indexBuffer; + int numVertices; + int primitiveCount; + int startIndex; + id tag; + VertexBufferContent *vertexBuffer; + int vertexOffset; +} + +@property (nonatomic, retain) MaterialContent *material; +@property (nonatomic, readonly) IndexCollection *indexBuffer; +@property (nonatomic, readonly) int numVertices; +@property (nonatomic, readonly) int primitiveCount; +@property (nonatomic, readonly) int startIndex; +@property (nonatomic, retain) id tag; +@property (nonatomic, readonly) VertexBufferContent *vertexBuffer; +@property (nonatomic, readonly) int vertexOffset; + + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContent.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContent.m new file mode 100644 index 0000000..2aa3f4e --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContent.m @@ -0,0 +1,51 @@ +// +// ModelMeshPartContent.m +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "ModelMeshPartContent.h" + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h" +#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h" +#import "Retronator.Xni.Framework.Graphics.h" + +@implementation ModelMeshPartContent + +- (id) initWithVertexOffset:(int)theVertexOffset + numVertices:(int)theNumVertices + startIndex:(int)theStartIndex + primitiveCount:(int)thePrimitiveCount + tag:(id)theTag + indexBuffer:(IndexCollection*)theIndexBuffer + vertexBuffer:(VertexBufferContent*)theVertexBuffer + material:(MaterialContent*)theMaterial +{ + self = [super init]; + if (self != nil) { + vertexOffset = theVertexOffset; + numVertices = theNumVertices; + startIndex = theStartIndex; + primitiveCount = thePrimitiveCount; + tag = [tag retain]; + indexBuffer = [theIndexBuffer retain]; + vertexBuffer = [theVertexBuffer retain]; + material = [theMaterial retain]; + } + return self; +} + +@synthesize material,indexBuffer,numVertices,primitiveCount,startIndex,tag,vertexBuffer,vertexOffset; + +- (void) dealloc +{ + [indexBuffer release]; + [vertexBuffer release]; + [tag release]; + [material release]; + [super dealloc]; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContentCollection.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContentCollection.h new file mode 100644 index 0000000..2b29421 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContentCollection.h @@ -0,0 +1,20 @@ +// +// ModelMeshPartContentCollection.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h" + +#define ReadOnlyCollection ModelMeshPartContentCollection +#define T ModelMeshPartContent* + +#include "ReadOnlyCollection.h" + +#undef ReadOnlyCollection +#undef T + diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContentCollection.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContentCollection.m new file mode 100644 index 0000000..ed26ad7 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelMeshPartContentCollection.m @@ -0,0 +1,18 @@ +// +// ModelMeshPartContentCollection.m +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "ModelMeshPartContentCollection.h" + + +#define ReadOnlyCollection ModelMeshPartContentCollection +#define T ModelMeshPartContent* + +#include "ReadOnlyCollection.m.h" + +#undef ReadOnlyCollection +#undef T diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelProcessor.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelProcessor.h new file mode 100644 index 0000000..abbf900 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelProcessor.h @@ -0,0 +1,17 @@ +// +// ModelProcessor.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ContentProcessor.h" + +@interface ModelProcessor : ContentProcessor { + +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelProcessor.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelProcessor.m new file mode 100644 index 0000000..9bd9810 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/ModelProcessor.m @@ -0,0 +1,116 @@ +// +// ModelProcessor.m +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "ModelProcessor.h" + +#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h" +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h" + +#import "ModelContent+Internal.h" +#import "ModelMeshContent+Internal.h" +#import "ModelMeshPartContent+Internal.h" +#import "ModelBoneContent+Internal.h" + +@interface ModelProcessor () + +- (ModelBoneContent*) createMeshes:(NSMutableArray*)meshes + bones:(NSMutableArray*)bones + from:(NodeContent*)input; + +- (ModelMeshContent*) createMeshFrom:(MeshContent*)input parentBone:(ModelBoneContent*)parentBone; + +- (ModelMeshPartContent*) createMeshPartFrom:(GeometryContent*)input; + +@end + + +@implementation ModelProcessor + +- (Class) inputType { return [NodeContent class];} +- (Class) outputType { return [ModelContent class];} + +- (ModelContent*) process:(NodeContent*)input { + NSMutableArray *meshes = [NSMutableArray array]; + NSMutableArray *bones = [NSMutableArray array]; + + ModelBoneContent *root = [self createMeshes:meshes bones:bones from:input]; + + ModelContent* output = [[[ModelContent alloc] initWithBones:bones meshes:meshes root:root tag:nil] autorelease]; + + return output; +} + +- (ModelBoneContent*) createMeshes:(NSMutableArray*)meshes + bones:(NSMutableArray*)bones + from:(NodeContent*)input { + + // First create all children bones. + NSMutableArray *childrenBones = [NSMutableArray array]; + + for (NodeContent *node in input.children) { + // Skip meshes. + if (![node isKindOfClass:[MeshContent class]]) { + ModelBoneContent *childBone = [self createMeshes:meshes bones:bones from:node]; + [childrenBones addObject:childBone]; + } + } + + // Now we can create the bone for this node. + ModelBoneContent *bone = [[[ModelBoneContent alloc] initWithChildren:childrenBones + index:[bones count] + name:input.name + transform:input.transform] autorelease]; + [bones addObject:bone]; + + // Update children's parent. + for (ModelBoneContent *child in bone.children) { + [child setParent:bone]; + } + + // Now we can create meshes and pass them the bone as their parent. + for (NodeContent *node in input.children) { + if ([node isKindOfClass:[MeshContent class]]) { + ModelMeshContent *mesh = [self createMeshFrom:(MeshContent*)node parentBone:bone]; + [meshes addObject:mesh]; + } + } + + // Return the created bone. + return bone; +} + +- (ModelMeshContent*) createMeshFrom:(MeshContent*)input parentBone:(ModelBoneContent*)parentBone { + NSMutableArray *meshParts = [NSMutableArray array]; + + for (GeometryContent *geometry in input.geometry) { + ModelMeshPartContent *meshPart = [self createMeshPartFrom:geometry]; + [meshParts addObject:meshPart]; + } + + ModelMeshContent *mesh = [[[ModelMeshContent alloc] initWithName:input.name + parentBone:parentBone + modelMeshParts:meshParts + tag:nil + sourceMesh:input] autorelease]; + + return mesh; +} + +- (ModelMeshPartContent *) createMeshPartFrom:(GeometryContent *)input { + ModelMeshPartContent *meshPart = [[[ModelMeshPartContent alloc] initWithVertexOffset:0 + numVertices:input.vertices.vertexCount + startIndex:0 + primitiveCount:input.indices.count/3 + tag:nil + indexBuffer:input.indices + vertexBuffer:[input.vertices createVertexBuffer] + material:input.material] autorelease]; + return meshPart; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h new file mode 100644 index 0000000..05efe8b --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h @@ -0,0 +1,11 @@ +@class TextureProcessor, FontTextureProcessor; +@class ModelProcessor, MaterialProcessor; +@class SoundEffectProcessor, SongProcessor; + +@class ModelContent, ModelMeshContentCollection, ModelMeshContent; +@class ModelMeshPartContentCollection, ModelMeshPartContent, VertexBufferContent, VertexDeclarationContent; +@class ModelBoneContent, ModelBoneContentCollection; + +@class SoundEffectContent, SongContent; + +@class SpriteFontContent; \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/Retronator.Xni.Framework.Content.Pipeline.Processors.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/Retronator.Xni.Framework.Content.Pipeline.Processors.h new file mode 100644 index 0000000..8977559 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/Retronator.Xni.Framework.Content.Pipeline.Processors.h @@ -0,0 +1,24 @@ +#import "TextureProcessor.h" +#import "FontTextureProcessor.h" + +#import "ModelProcessor.h" +#import "MaterialProcessor.h" + +#import "SoundEffectProcessor.h" +#import "SongProcessor.h" + +#import "ModelContent.h" +#import "ModelMeshContentCollection.h" +#import "ModelMeshContent.h" +#import "ModelMeshPartContentCollection.h" +#import "ModelMeshPartContent.h" +#import "VertexBufferContent.h" +#import "VertexDeclarationContent.h" + +#import "ModelBoneContent.h" +#import "ModelBoneContentCollection.h" + +#import "SoundEffectContent.h" +#import "SongContent.h" + +#import "SpriteFontContent.h" \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongContent+Internal.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongContent+Internal.h new file mode 100644 index 0000000..cf9a405 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongContent+Internal.h @@ -0,0 +1,18 @@ +// +// SongContent+Internal.h +// XNI +// +// Created by Matej Jan on 18.1.11. +// Copyright 2011 Retronator. All rights reserved. +// + +#import + + +@interface SongContent (Internal) + +- (id) initWithFileName:(NSString*)fileName; + +@property (nonatomic, readonly) NSURL *url; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongContent.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongContent.h new file mode 100644 index 0000000..72a7c42 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongContent.h @@ -0,0 +1,15 @@ +// +// SongContent.h +// XNI +// +// Created by Matej Jan on 15.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +@interface SongContent : NSObject { + NSURL *url; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongContent.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongContent.m new file mode 100644 index 0000000..dab47e2 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongContent.m @@ -0,0 +1,34 @@ +// +// SongContent.m +// XNI +// +// Created by Matej Jan on 15.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "SongContent.h" +#import "SongContent+Internal.h" + +@implementation SongContent + +- (id) initWithFileName:(NSString*)fileName +{ + self = [super init]; + if (self != nil) { + url = [[NSURL alloc] initFileURLWithPath:fileName]; + } + return self; +} + +- (NSURL *) url { + return url; +} + +- (void) dealloc +{ + [url release]; + [super dealloc]; +} + + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongProcessor.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongProcessor.h new file mode 100644 index 0000000..aef1ed7 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongProcessor.h @@ -0,0 +1,17 @@ +// +// SongProcessor.h +// XNI +// +// Created by Matej Jan on 15.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ContentProcessor.h" + +@interface SongProcessor : ContentProcessor { + +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongProcessor.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongProcessor.m new file mode 100644 index 0000000..715b38b --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SongProcessor.m @@ -0,0 +1,25 @@ +// +// SongProcessor.m +// XNI +// +// Created by Matej Jan on 15.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "SongProcessor.h" + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h" +#import "Retronator.Xni.Framework.Content.Pipeline.Audio.h" + +#import "SongContent+Internal.h" + +@implementation SongProcessor + +- (Class) inputType { return [AudioContent class];} +- (Class) outputType { return [SongContent class];} + +- (SongContent*) process:(AudioContent*)input { + return [[[SongContent alloc] initWithFileName:input.fileName] autorelease]; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectContent+Internal.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectContent+Internal.h new file mode 100644 index 0000000..abeb4ec --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectContent+Internal.h @@ -0,0 +1,19 @@ +// +// SoundEffectContent+Internal.h +// XNI +// +// Created by Matej Jan on 15.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + + +@interface SoundEffectContent (Internal) + +- (id) initWithData:(NSData*)theData format:(AudioFormat*)theFormat; + +@property (nonatomic, readonly) NSData *data; +@property (nonatomic, readonly) AudioFormat *format; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectContent.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectContent.h new file mode 100644 index 0000000..a50e90b --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectContent.h @@ -0,0 +1,19 @@ +// +// SoundEffectContent.h +// XNI +// +// Created by Matej Jan on 15.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.Content.Pipeline.Audio.classes.h" + +@interface SoundEffectContent : NSObject { +@private + NSData *data; + AudioFormat *format; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectContent.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectContent.m new file mode 100644 index 0000000..0160bdf --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectContent.m @@ -0,0 +1,40 @@ +// +// SoundEffectContent.m +// XNI +// +// Created by Matej Jan on 15.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "SoundEffectContent.h" +#import "SoundEffectContent+Internal.h" + +@implementation SoundEffectContent + +- (id) initWithData:(NSData *)theData format:(AudioFormat*)theFormat +{ + self = [super init]; + if (self != nil) { + data = [theData retain]; + format = [theFormat retain]; + } + return self; +} + +- (NSData *) data { + return data; +} + +- (AudioFormat *) format { + return format; +} + +- (void) dealloc +{ + [data release]; + [format release]; + [super dealloc]; +} + + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectProcessor.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectProcessor.h new file mode 100644 index 0000000..06deeb0 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectProcessor.h @@ -0,0 +1,17 @@ +// +// SoundEffectProcessor.h +// XNI +// +// Created by Matej Jan on 15.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ContentProcessor.h" + +@interface SoundEffectProcessor : ContentProcessor { + +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectProcessor.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectProcessor.m new file mode 100644 index 0000000..a0a33e4 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SoundEffectProcessor.m @@ -0,0 +1,26 @@ +// +// SoundEffectProcessor.m +// XNI +// +// Created by Matej Jan on 15.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "SoundEffectProcessor.h" + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h" +#import "Retronator.Xni.Framework.Content.Pipeline.Audio.h" + +#import "SoundEffectContent+Internal.h" + +@implementation SoundEffectProcessor + +- (Class) inputType { return [AudioContent class];} +- (Class) outputType { return [SoundEffectContent class];} + +- (SoundEffectContent*) process:(AudioContent*)input { + [input convertFormatTo:ConversionFormatPcm quality:ConversionQualityBest targetFileName:nil]; + return [[[SoundEffectContent alloc] initWithData:input.data format:input.format] autorelease]; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SpriteFontContent+Internal.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SpriteFontContent+Internal.h new file mode 100644 index 0000000..f4ecb12 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SpriteFontContent+Internal.h @@ -0,0 +1,21 @@ +// +// SpriteFontContent+Internal.h +// XNI +// +// Created by Matej Jan on 20.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "SpriteFontContent.h" + +@interface SpriteFontContent (Internal) + +- (id) initWithTexture:(Texture2DContent*)theTexture characterMap:(NSDictionary*)theCharacterMap lineSpacing:(int)theLineSpacing; + +@property (nonatomic, readonly) Texture2DContent *texture; +@property (nonatomic, readonly) NSDictionary *characterMap; +@property (nonatomic, readonly) int lineSpacing; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SpriteFontContent.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SpriteFontContent.h new file mode 100644 index 0000000..c188688 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SpriteFontContent.h @@ -0,0 +1,20 @@ +// +// SpriteFontContent.h +// XNI +// +// Created by Matej Jan on 20.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h" + +@interface SpriteFontContent : NSObject { +@private + Texture2DContent *texture; + NSDictionary *characterMap; + int lineSpacing; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SpriteFontContent.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SpriteFontContent.m new file mode 100644 index 0000000..e0f920b --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/SpriteFontContent.m @@ -0,0 +1,45 @@ +// +// SpriteFontContent.m +// XNI +// +// Created by Matej Jan on 20.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "SpriteFontContent.h" +#import "SpriteFontContent+Internal.h" + + +@implementation SpriteFontContent + +- (id) initWithTexture:(Texture2DContent*)theTexture characterMap:(NSDictionary*)theCharacterMap lineSpacing:(int)theLineSpacing +{ + self = [super init]; + if (self != nil) { + texture = [theTexture retain]; + characterMap = [theCharacterMap retain]; + lineSpacing = theLineSpacing; + } + return self; +} + +- (Texture2DContent *) texture { + return texture; +} + +- (NSDictionary *) characterMap { + return characterMap; +} + +- (int) lineSpacing { + return lineSpacing; +} + +- (void) dealloc +{ + [texture release]; + [characterMap release]; + [super dealloc]; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/TextureProcessor.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/TextureProcessor.h new file mode 100644 index 0000000..0f45df4 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/TextureProcessor.h @@ -0,0 +1,17 @@ +// +// TextureProcessor.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ContentProcessor.h" + +@interface TextureProcessor : ContentProcessor { + +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/TextureProcessor.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/TextureProcessor.m new file mode 100644 index 0000000..ee11631 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/TextureProcessor.m @@ -0,0 +1,18 @@ +// +// TextureProcessor.m +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "TextureProcessor.h" + +#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.h" + +@implementation TextureProcessor + +- (Class) inputType { return [TextureContent class];} +- (Class) outputType { return [TextureContent class];} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexBufferContent.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexBufferContent.h new file mode 100644 index 0000000..450df57 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexBufferContent.h @@ -0,0 +1,23 @@ +// +// VertexBufferContent.h +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h" + +#import "ContentItem.h" + +@interface VertexBufferContent : ContentItem { + NSMutableData *vertexData; + VertexDeclarationContent *vertexDeclaration; +} + +@property (nonatomic, readonly) NSMutableData *vertexData; +@property (nonatomic, retain) VertexDeclarationContent *vertexDeclaration; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexBufferContent.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexBufferContent.m new file mode 100644 index 0000000..84265e4 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexBufferContent.m @@ -0,0 +1,32 @@ +// +// VertexBufferContent.m +// XNI +// +// Created by Matej Jan on 22.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "VertexBufferContent.h" + + +@implementation VertexBufferContent + +- (id) init +{ + self = [super init]; + if (self != nil) { + vertexData = [[NSMutableData alloc] init]; + } + return self; +} + +@synthesize vertexData, vertexDeclaration; + +- (void) dealloc +{ + [vertexData release]; + [vertexDeclaration release]; + [super dealloc]; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexDeclarationContent.h b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexDeclarationContent.h new file mode 100644 index 0000000..45ce878 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexDeclarationContent.h @@ -0,0 +1,21 @@ +// +// VertexDeclarationContent.h +// XNI +// +// Created by Matej Jan on 26.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import + +#import "ContentItem.h" + +@interface VertexDeclarationContent : ContentItem { + NSMutableArray *vertexElements; + NSNumber *vertexStride; +} + +@property (nonatomic, readonly) NSMutableArray *vertexElements; +@property (nonatomic, retain) NSNumber *vertexStride; + +@end diff --git a/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexDeclarationContent.m b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexDeclarationContent.m new file mode 100644 index 0000000..2d7bda4 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Content/Pipeline/Processors/VertexDeclarationContent.m @@ -0,0 +1,33 @@ +// +// VertexDeclarationContent.m +// XNI +// +// Created by Matej Jan on 26.11.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "VertexDeclarationContent.h" + + +@implementation VertexDeclarationContent + +- (id) init +{ + self = [super init]; + if (self != nil) { + vertexElements = [[NSMutableArray alloc] init]; + } + return self; +} + +@synthesize vertexElements, vertexStride; + +- (void) dealloc +{ + [vertexElements release]; + [vertexStride release]; + [super dealloc]; +} + + +@end diff --git a/Classes/Retronator/Xni/Framework/GamerServices/Guide+Internal.h b/Classes/Retronator/Xni/Framework/GamerServices/Guide+Internal.h new file mode 100644 index 0000000..733696b --- /dev/null +++ b/Classes/Retronator/Xni/Framework/GamerServices/Guide+Internal.h @@ -0,0 +1,17 @@ +// +// Guide+Internal.h +// XNI +// +// Created by Matej Jan on 7.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "Guide.h" + +#import "Retronator.Xni.Framework.classes.h" + +@interface Guide (Internal) + ++ (void) initializeWithGame:(Game*)theGame; + +@end diff --git a/Classes/Retronator/Xni/Framework/GamerServices/Guide.h b/Classes/Retronator/Xni/Framework/GamerServices/Guide.h new file mode 100644 index 0000000..c1dca4d --- /dev/null +++ b/Classes/Retronator/Xni/Framework/GamerServices/Guide.h @@ -0,0 +1,29 @@ +// +// Guide.h +// XNI +// +// Created by Matej Jan on 7.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import +#import + +#import "Retronator.Xni.Framework.classes.h" + +@interface Guide : NSObject { + Game *game; + BOOL isVisible; +} + +@property (nonatomic) BOOL isVisible; + ++ (void) showAchievements; ++ (void) showLeaderboard; + ++ (Guide*) getInstance; + +- (void) showAchievements; +- (void) showLeaderboard; + +@end diff --git a/Classes/Retronator/Xni/Framework/GamerServices/Guide.m b/Classes/Retronator/Xni/Framework/GamerServices/Guide.m new file mode 100644 index 0000000..28c23de --- /dev/null +++ b/Classes/Retronator/Xni/Framework/GamerServices/Guide.m @@ -0,0 +1,59 @@ +// +// Guide.m +// XNI +// +// Created by Matej Jan on 7.12.10. +// Copyright 2010 Retronator. All rights reserved. +// + +#import "Guide.h" +#import "Guide+Internal.h" + +#import "Retronator.Xni.Framework.h" + +#import "GameWindow+Internal.h" +#import "GameViewController.h" + +@implementation Guide + +static Guide *instance = nil; + +- (id) initWithGame:(Game*)theGame; +{ + self = [super init]; + if (self != nil) { + game = theGame; + } + return self; +} + ++ (void) initializeWithGame:(Game *)theGame +{ + if (!instance) { + instance = [[Guide alloc] initWithGame:theGame]; + } +} + +@synthesize isVisible; + ++ (void) showAchievements { + [instance showAchievements]; +} + ++ (void) showLeaderboard { + [instance showLeaderboard]; +} + ++ (Guide*) getInstance { + return instance; +} + +- (void) showAchievements { + [game.window.gameViewController showAchievementsView]; +} + +- (void) showLeaderboard { + [game.window.gameViewController showLeaderboardView]; +} + +@end diff --git a/Classes/Retronator/Xni/Framework/GamerServices/Retronator.Xni.Framework.GamerServices.classes.h b/Classes/Retronator/Xni/Framework/GamerServices/Retronator.Xni.Framework.GamerServices.classes.h new file mode 100644 index 0000000..43f9877 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/GamerServices/Retronator.Xni.Framework.GamerServices.classes.h @@ -0,0 +1 @@ +@class Guide; \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/GamerServices/Retronator.Xni.Framework.GamerServices.h b/Classes/Retronator/Xni/Framework/GamerServices/Retronator.Xni.Framework.GamerServices.h new file mode 100644 index 0000000..f30560f --- /dev/null +++ b/Classes/Retronator/Xni/Framework/GamerServices/Retronator.Xni.Framework.GamerServices.h @@ -0,0 +1 @@ +#import "Guide.h" \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/Media/MediaEnums.h b/Classes/Retronator/Xni/Framework/Media/MediaEnums.h new file mode 100644 index 0000000..7e81078 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/MediaEnums.h @@ -0,0 +1,5 @@ +typedef enum { + MediaStatePaused, + MediaStatePlaying, + MediaStateStopped +} MediaState; \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/Media/MediaPlayer.h b/Classes/Retronator/Xni/Framework/Media/MediaPlayer.h new file mode 100644 index 0000000..374ae71 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/MediaPlayer.h @@ -0,0 +1,57 @@ +// +// MediaPlayer.h +// XNI +// +// Created by Matej Jan on 18.1.11. +// Copyright 2011 Retronator. All rights reserved. +// + +#import +#import + +#import "System.h" + +#import "Retronator.Xni.Framework.Media.classes.h" + +@interface MediaPlayer : NSObject { + BOOL soloModeActivated; + BOOL isMuted; + BOOL isRepeating; + BOOL isShuffled; + MediaQueue *queue; + MediaState state; + float volume; + + Event *activeSongChanged; + Event *mediaStateChanged; +} + +@property (nonatomic, readonly) BOOL gameHasControl; +@property (nonatomic) BOOL isMuted; +@property (nonatomic) BOOL isRepeating; +@property (nonatomic) BOOL isShuffled; +@property (nonatomic, readonly) NSTimeInterval playPosition; +@property (nonatomic, readonly) MediaQueue *queue; +@property (nonatomic, readonly) MediaState state; +@property (nonatomic) float volume; + +@property (nonatomic, readonly) Event *activeSongChanged; +@property (nonatomic, readonly) Event *mediaStateChanged; + ++ (MediaPlayer*) getInstance; + ++ (void) moveNext; ++ (void) movePrevious; ++ (void) pause; ++ (void) playSong:(Song*)song; ++ (void) resume; ++ (void) stop; + +- (void) moveNext; +- (void) movePrevious; +- (void) pause; +- (void) playSong:(Song*)song; +- (void) resume; +- (void) stop; + +@end diff --git a/Classes/Retronator/Xni/Framework/Media/MediaPlayer.m b/Classes/Retronator/Xni/Framework/Media/MediaPlayer.m new file mode 100644 index 0000000..d12beb8 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/MediaPlayer.m @@ -0,0 +1,220 @@ +// +// MediaPlayer.m +// XNI +// +// Created by Matej Jan on 18.1.11. +// Copyright 2011 Retronator. All rights reserved. +// + +#import "MediaPlayer.h" + +#import + +#import "Retronator.Xni.Framework.Media.h" +#import "MediaQueue+Internal.h" +#import "Song+Internal.h" + +@interface MediaPlayer () + +- (BOOL) checkAvailability; +- (void) setMediaState:(MediaState)value; + +@end + + +@implementation MediaPlayer + +static MediaPlayer *instance; + ++ (void) initialize { + if (!instance) { + instance = [[MediaPlayer alloc] init]; + } +} + +- (id) init +{ + self = [super init]; + if (self != nil) { + // Start in ambient mode so we let user music play until a call to MediaPlayer play changes this. + [[AVAudioSession sharedInstance] + setCategory: AVAudioSessionCategoryAmbient + error: nil]; + + queue = [[MediaQueue alloc] init]; + isMuted = NO; + volume = 1; + + [queue.activeSongChanged subscribeDelegate:[Delegate delegateWithTarget:self Method:@selector(queueActiveSongChanged)]]; + + activeSongChanged = [[Event alloc] init]; + mediaStateChanged = [[Event alloc] init]; + } + return self; +} + +- (BOOL) gameHasControl { + UInt32 otherAudioIsPlaying; + UInt32 propertySize = sizeof(otherAudioIsPlaying); + + AudioSessionGetProperty ( + kAudioSessionProperty_OtherAudioIsPlaying, + &propertySize, + &otherAudioIsPlaying + ); + + return !otherAudioIsPlaying; +} + +@synthesize isMuted; + +- (void) setIsMuted:(BOOL)value { + isMuted = value; + + if (isMuted) { + queue.activeSong.audioPlayer.volume = 0; + } else { + queue.activeSong.audioPlayer.volume = volume; + } +} + +@synthesize isRepeating; +@synthesize isShuffled; + +- (NSTimeInterval) playPosition { + return queue.activeSong.audioPlayer.currentTime; +} + +@synthesize volume; + +- (void) setVolume:(float)value { + volume = value; + + if (!isMuted) { + queue.activeSong.audioPlayer.volume = volume; + } +} + +@synthesize queue, state, mediaStateChanged; + +- (Event *) activeSongChanged { + return queue.activeSongChanged; +} + + ++ (MediaPlayer*) getInstance { + return instance; +} + ++ (void) moveNext { [instance moveNext];} ++ (void) movePrevious { [instance movePrevious];} ++ (void) pause { [instance pause];} ++ (void) playSong:(Song*)song { [instance playSong:song];} ++ (void) resume { [instance resume];} ++ (void) stop { [instance stop];} + +- (void) moveNext { + if (![self checkAvailability]) { + return; + } + + if (isShuffled) { + queue.activeSongIndex = random() % queue.count; + } else { + queue.activeSongIndex = (queue.activeSongIndex + 1) % queue.count; + } +} + +- (void) movePrevious { + if (![self checkAvailability]) { + return; + } + + if (isShuffled) { + queue.activeSongIndex = random() % queue.count; + } else { + queue.activeSongIndex = (queue.activeSongIndex - 1 + queue.count) % queue.count; + } +} + +- (void) pause { + if (![self checkAvailability]) { + return; + } + + [queue.activeSong.audioPlayer pause]; + [self setMediaState:MediaStatePaused]; +} + +- (void) playSong:(Song*)song { + if (![self checkAvailability]) { + return; + } + + song.audioPlayer.delegate = self; + [queue setSong:song]; + [queue.activeSong.audioPlayer play]; + [self setMediaState:MediaStatePlaying]; +} + +- (void) resume { + if (![self checkAvailability]) { + return; + } + + [queue.activeSong.audioPlayer play]; + [self setMediaState:MediaStatePlaying]; +} + +- (void) stop { + if (![self checkAvailability]) { + return; + } + + [queue.activeSong.audioPlayer pause]; + queue.activeSong.audioPlayer.currentTime = 0; + [self setMediaState:MediaStateStopped]; +} + +- (BOOL) checkAvailability { + if (!self.gameHasControl) { + return NO; + } + + if (!soloModeActivated) { + // Switch to solo mode so we silence user audio before playing our music. + [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategorySoloAmbient error:nil]; + soloModeActivated = YES; + } + + return YES; +} + +- (void) queueActiveSongChanged { + [activeSongChanged raiseWithSender:self]; +} + +- (void) setMediaState:(MediaState)value { + if (state == value) { + return; + } + + state = value; + [mediaStateChanged raiseWithSender:self]; +} + +- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag { + [self moveNext]; + [self resume]; +} + +- (void) dealloc +{ + [activeSongChanged release]; + [mediaStateChanged release]; + [queue release]; + [super dealloc]; +} + + +@end diff --git a/Classes/Retronator/Xni/Framework/Media/MediaQueue+Internal.h b/Classes/Retronator/Xni/Framework/Media/MediaQueue+Internal.h new file mode 100644 index 0000000..b58c9f2 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/MediaQueue+Internal.h @@ -0,0 +1,19 @@ +// +// MediaQueue+Internal.h +// XNI +// +// Created by Matej Jan on 18.1.11. +// Copyright 2011 Retronator. All rights reserved. +// + +#import + +#import "MediaQueue.h" + +@interface MediaQueue (Internal) + +@property (nonatomic, readonly) Event *activeSongChanged; + +- (void) setSong:(Song*)song; + +@end diff --git a/Classes/Retronator/Xni/Framework/Media/MediaQueue.h b/Classes/Retronator/Xni/Framework/Media/MediaQueue.h new file mode 100644 index 0000000..fa3380e --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/MediaQueue.h @@ -0,0 +1,28 @@ +// +// MediaQueue.h +// XNI +// +// Created by Matej Jan on 18.1.11. +// Copyright 2011 Retronator. All rights reserved. +// + +#import + +#import "System.h" + +#import "Retronator.Xni.Framework.Media.classes.h" + +@interface MediaQueue : NSObject { + NSMutableArray *queue; + int activeSongIndex; + + Event *activeSongChanged; +} + +@property (nonatomic, readonly) Song *activeSong; +@property (nonatomic) int activeSongIndex; +@property (nonatomic, readonly) int count; + +- (Song*) itemAt:(int)index; + +@end diff --git a/Classes/Retronator/Xni/Framework/Media/MediaQueue.m b/Classes/Retronator/Xni/Framework/Media/MediaQueue.m new file mode 100644 index 0000000..132fb2c --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/MediaQueue.m @@ -0,0 +1,86 @@ +// +// MediaQueue.m +// XNI +// +// Created by Matej Jan on 18.1.11. +// Copyright 2011 Retronator. All rights reserved. +// + +#import "MediaQueue.h" + +#import + +#import "MediaQueue+Internal.h" +#import "Song+Internal.h" + +@implementation MediaQueue + +- (id) init +{ + self = [super init]; + if (self != nil) { + queue = [[NSMutableArray alloc] init]; + + activeSongChanged = [[Event alloc] init]; + } + return self; +} + +@synthesize activeSongIndex; + +- (Event *) activeSongChanged { + return activeSongChanged; +} + +- (void) setActiveSongIndex:(int)value { + if (value == activeSongIndex) { + return; + } + + AVAudioPlayer *player = self.activeSong.audioPlayer; + BOOL playing = player.playing; + + if (playing) { + // Stop playing current song. + [player pause]; + player.currentTime = 0; + } + + activeSongIndex = value; + + if (playing) { + // Start new song. + [self.activeSong.audioPlayer play]; + } + + [activeSongChanged raiseWithSender:self]; +} + +- (Song *) activeSong { + return [queue objectAtIndex:activeSongIndex]; +} + +- (int) count { + return [queue count]; +} + +- (Song *) itemAt:(int)index { + return [queue objectAtIndex:index]; +} + +- (void) setSong:(Song *)song { + [queue removeAllObjects]; + [queue addObject:song]; + activeSongIndex = 0; +} + +- (void) dealloc +{ + [activeSongChanged release]; + [queue release]; + [super dealloc]; +} + + + +@end diff --git a/Classes/Retronator/Xni/Framework/Media/Retronator.Xni.Framework.Media.classes.h b/Classes/Retronator/Xni/Framework/Media/Retronator.Xni.Framework.Media.classes.h new file mode 100644 index 0000000..4844d51 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/Retronator.Xni.Framework.Media.classes.h @@ -0,0 +1,4 @@ +#import "MediaEnums.h" + +@class Song; +@class MediaPlayer, MediaQueue; \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/Media/Retronator.Xni.Framework.Media.h b/Classes/Retronator/Xni/Framework/Media/Retronator.Xni.Framework.Media.h new file mode 100644 index 0000000..7d146cb --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/Retronator.Xni.Framework.Media.h @@ -0,0 +1,6 @@ +#import "MediaEnums.h" + +#import "Song.h" + +#import "MediaPlayer.h" +#import "MediaQueue.h" \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/Media/Song+Internal.h b/Classes/Retronator/Xni/Framework/Media/Song+Internal.h new file mode 100644 index 0000000..8a60e58 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/Song+Internal.h @@ -0,0 +1,19 @@ +// +// Song+Internal.h +// XNI +// +// Created by Matej Jan on 18.1.11. +// Copyright 2011 Retronator. All rights reserved. +// + +#import + +#import "Song.h" + +@interface Song (Internal) + +- (id) initWithUrl:(NSURL*)url; + +@property (nonatomic, readonly) AVAudioPlayer *audioPlayer; + +@end diff --git a/Classes/Retronator/Xni/Framework/Media/Song.h b/Classes/Retronator/Xni/Framework/Media/Song.h new file mode 100644 index 0000000..a35357a --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/Song.h @@ -0,0 +1,19 @@ +// +// Song.h +// XNI +// +// Created by Matej Jan on 18.1.11. +// Copyright 2011 Retronator. All rights reserved. +// + +#import + +#import + +@interface Song : NSObject { + AVAudioPlayer *audioPlayer; +} + +@property (nonatomic, readonly) NSTimeInterval duration; + +@end diff --git a/Classes/Retronator/Xni/Framework/Media/Song.m b/Classes/Retronator/Xni/Framework/Media/Song.m new file mode 100644 index 0000000..d311713 --- /dev/null +++ b/Classes/Retronator/Xni/Framework/Media/Song.m @@ -0,0 +1,39 @@ +// +// Song.m +// XNI +// +// Created by Matej Jan on 18.1.11. +// Copyright 2011 Retronator. All rights reserved. +// + +#import "Song.h" +#import "Song+Internal.h" + +@implementation Song + +- (id) initWithUrl:(NSURL*)url +{ + self = [super init]; + if (self != nil) { + audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; + [audioPlayer prepareToPlay]; + } + return self; +} + +- (NSTimeInterval) duration { + return audioPlayer.duration; +} + +- (AVAudioPlayer *) audioPlayer { + return audioPlayer; +} + +- (void) dealloc +{ + [audioPlayer release]; + [super dealloc]; +} + + +@end