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

Adding missing folders

git-svn-id: http://xni.googlecode.com/svn/XNI@55 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
Matej Jan 2011-02-01 15:47:13 +00:00
parent 2adbc50363
commit 74ccf177c5
61 changed files with 1932 additions and 0 deletions

View File

@ -0,0 +1,23 @@
//
// FontTextureProcessor.h
// XNI
//
// Created by Matej Jan on 20.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ContentProcessor.h"
@interface FontTextureProcessor : ContentProcessor {
unichar firstCharacter;
BOOL premultiplyAlpha;
}
@property (nonatomic) unichar firstCharacter;
@property (nonatomic) BOOL premultiplyAlpha;
- (unichar) getCharacterForIndex:(int)index;
@end

View File

@ -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

View File

@ -0,0 +1,17 @@
//
// MaterialProcessor.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ContentProcessor.h"
@interface MaterialProcessor : ContentProcessor {
}
@end

View File

@ -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

View File

@ -0,0 +1,21 @@
//
// ModelBoneContent+Internal.h
// XNI
//
// Created by Matej Jan on 29.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ModelBoneContent (Internal)
- (id) initWithChildren:(NSArray*)theChildren
index:(int)theIndex
name:(NSString*)theName
transform:(Matrix*)theTransform;
- (void) setParent:(ModelBoneContent*)theParent;
@end

View File

@ -0,0 +1,28 @@
//
// ModelBoneContent.h
// XNI
//
// Created by Matej Jan on 29.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#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

View File

@ -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

View File

@ -0,0 +1,19 @@
//
// ModelBoneContentCollection.h
// XNI
//
// Created by Matej Jan on 29.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h"
#define ReadOnlyCollection ModelBoneContentCollection
#define T ModelBoneContent*
#include "ReadOnlyCollection.h"
#undef ReadOnlyCollection
#undef T

View File

@ -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

View File

@ -0,0 +1,17 @@
//
// ModelContent+Internal.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "ModelContent.h"
@interface ModelContent (Internal)
- (id) initWithBones:(NSArray*)theBones meshes:(NSArray*)theMeshes root:(ModelBoneContent*)theRoot tag:(id)theTag;
@end

View File

@ -0,0 +1,25 @@
//
// ModelContent.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#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

View File

@ -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

View File

@ -0,0 +1,17 @@
//
// ModelMeshContent+Internal.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "ModelMeshContent.h"
@interface ModelMeshContent (Internal)
- (id) initWithName:(NSString*)theName parentBone:(ModelBoneContent*)theParentBone modelMeshParts:(NSArray*)theModelMeshParts tag:(id)theTag sourceMesh:(MeshContent*)theSourceMesh;
@end

View File

@ -0,0 +1,28 @@
//
// ModelMeshContent.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#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

View File

@ -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

View File

@ -0,0 +1,19 @@
//
// ModelMeshContentCollection.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h"
#define ReadOnlyCollection ModelMeshContentCollection
#define T ModelMeshContent*
#include "ReadOnlyCollection.h"
#undef ReadOnlyCollection
#undef T

View File

@ -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

View File

@ -0,0 +1,24 @@
//
// ModelMeshPartContent+Internal.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <UIKit/UIKit.h>
#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

View File

@ -0,0 +1,36 @@
//
// ModelMeshPartContent.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#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

View File

@ -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

View File

@ -0,0 +1,20 @@
//
// ModelMeshPartContentCollection.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.classes.h"
#define ReadOnlyCollection ModelMeshPartContentCollection
#define T ModelMeshPartContent*
#include "ReadOnlyCollection.h"
#undef ReadOnlyCollection
#undef T

View File

@ -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

View File

@ -0,0 +1,17 @@
//
// ModelProcessor.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ContentProcessor.h"
@interface ModelProcessor : ContentProcessor {
}
@end

View File

@ -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

View File

@ -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;

View File

@ -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"

View File

@ -0,0 +1,18 @@
//
// SongContent+Internal.h
// XNI
//
// Created by Matej Jan on 18.1.11.
// Copyright 2011 Retronator. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SongContent (Internal)
- (id) initWithFileName:(NSString*)fileName;
@property (nonatomic, readonly) NSURL *url;
@end

View File

@ -0,0 +1,15 @@
//
// SongContent.h
// XNI
//
// Created by Matej Jan on 15.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface SongContent : NSObject {
NSURL *url;
}
@end

View File

@ -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

View File

@ -0,0 +1,17 @@
//
// SongProcessor.h
// XNI
//
// Created by Matej Jan on 15.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ContentProcessor.h"
@interface SongProcessor : ContentProcessor {
}
@end

View File

@ -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

View File

@ -0,0 +1,19 @@
//
// SoundEffectContent+Internal.h
// XNI
//
// Created by Matej Jan on 15.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SoundEffectContent (Internal)
- (id) initWithData:(NSData*)theData format:(AudioFormat*)theFormat;
@property (nonatomic, readonly) NSData *data;
@property (nonatomic, readonly) AudioFormat *format;
@end

View File

@ -0,0 +1,19 @@
//
// SoundEffectContent.h
// XNI
//
// Created by Matej Jan on 15.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Retronator.Xni.Framework.Content.Pipeline.Audio.classes.h"
@interface SoundEffectContent : NSObject {
@private
NSData *data;
AudioFormat *format;
}
@end

View File

@ -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

View File

@ -0,0 +1,17 @@
//
// SoundEffectProcessor.h
// XNI
//
// Created by Matej Jan on 15.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ContentProcessor.h"
@interface SoundEffectProcessor : ContentProcessor {
}
@end

View File

@ -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

View File

@ -0,0 +1,21 @@
//
// SpriteFontContent+Internal.h
// XNI
//
// Created by Matej Jan on 20.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <UIKit/UIKit.h>
#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

View File

@ -0,0 +1,20 @@
//
// SpriteFontContent.h
// XNI
//
// Created by Matej Jan on 20.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
@interface SpriteFontContent : NSObject {
@private
Texture2DContent *texture;
NSDictionary *characterMap;
int lineSpacing;
}
@end

View File

@ -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

View File

@ -0,0 +1,17 @@
//
// TextureProcessor.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ContentProcessor.h"
@interface TextureProcessor : ContentProcessor {
}
@end

View File

@ -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

View File

@ -0,0 +1,23 @@
//
// VertexBufferContent.h
// XNI
//
// Created by Matej Jan on 22.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#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

View File

@ -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

View File

@ -0,0 +1,21 @@
//
// VertexDeclarationContent.h
// XNI
//
// Created by Matej Jan on 26.11.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ContentItem.h"
@interface VertexDeclarationContent : ContentItem {
NSMutableArray *vertexElements;
NSNumber *vertexStride;
}
@property (nonatomic, readonly) NSMutableArray *vertexElements;
@property (nonatomic, retain) NSNumber *vertexStride;
@end

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,29 @@
//
// Guide.h
// XNI
//
// Created by Matej Jan on 7.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>
#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

View File

@ -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

View File

@ -0,0 +1 @@
#import "Guide.h"

View File

@ -0,0 +1,5 @@
typedef enum {
MediaStatePaused,
MediaStatePlaying,
MediaStateStopped
} MediaState;

View File

@ -0,0 +1,57 @@
//
// MediaPlayer.h
// XNI
//
// Created by Matej Jan on 18.1.11.
// Copyright 2011 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "System.h"
#import "Retronator.Xni.Framework.Media.classes.h"
@interface MediaPlayer : NSObject <AVAudioPlayerDelegate> {
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

View File

@ -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 <AudioToolbox/AudioToolbox.h>
#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

View File

@ -0,0 +1,19 @@
//
// MediaQueue+Internal.h
// XNI
//
// Created by Matej Jan on 18.1.11.
// Copyright 2011 Retronator. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "MediaQueue.h"
@interface MediaQueue (Internal)
@property (nonatomic, readonly) Event *activeSongChanged;
- (void) setSong:(Song*)song;
@end

View File

@ -0,0 +1,28 @@
//
// MediaQueue.h
// XNI
//
// Created by Matej Jan on 18.1.11.
// Copyright 2011 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#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

View File

@ -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 <AVFoundation/AVFoundation.h>
#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

View File

@ -0,0 +1,4 @@
#import "MediaEnums.h"
@class Song;
@class MediaPlayer, MediaQueue;

View File

@ -0,0 +1,6 @@
#import "MediaEnums.h"
#import "Song.h"
#import "MediaPlayer.h"
#import "MediaQueue.h"

View File

@ -0,0 +1,19 @@
//
// Song+Internal.h
// XNI
//
// Created by Matej Jan on 18.1.11.
// Copyright 2011 Retronator. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Song.h"
@interface Song (Internal)
- (id) initWithUrl:(NSURL*)url;
@property (nonatomic, readonly) AVAudioPlayer *audioPlayer;
@end

View File

@ -0,0 +1,19 @@
//
// Song.h
// XNI
//
// Created by Matej Jan on 18.1.11.
// Copyright 2011 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface Song : NSObject {
AVAudioPlayer *audioPlayer;
}
@property (nonatomic, readonly) NSTimeInterval duration;
@end

View File

@ -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