mirror of
https://github.com/thes3m/XNI
synced 2024-12-26 13:26:06 +01:00
SoundEffect support implemented.
git-svn-id: http://xni.googlecode.com/svn/XNI@49 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
parent
796a3a85f3
commit
2f0bc9f91a
@ -12,6 +12,7 @@
|
|||||||
#import "Retronator.Xni.Framework.Content.h"
|
#import "Retronator.Xni.Framework.Content.h"
|
||||||
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
#import "Retronator.Xni.Framework.Content.Pipeline.h"
|
||||||
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
#import "Retronator.Xni.Framework.Content.Pipeline.Processors.h"
|
||||||
|
#import "Retronator.Xni.Framework.Content.Pipeline.Audio.h"
|
||||||
|
|
||||||
@implementation ContentManager
|
@implementation ContentManager
|
||||||
|
|
||||||
@ -89,21 +90,35 @@
|
|||||||
// Compare lowercase extension.
|
// Compare lowercase extension.
|
||||||
extension = [extension lowercaseString];
|
extension = [extension lowercaseString];
|
||||||
|
|
||||||
if ([extension isEqual:@"png"] || [extension isEqual:@"jpg"] || [extension isEqual:@"jpeg"] ||
|
if ([extension isEqualToString:@"png"] || [extension isEqualToString:@"jpg"] || [extension isEqualToString:@"jpeg"] ||
|
||||||
[extension isEqual:@"gif"] || [extension isEqual:@"tif"] || [extension isEqual:@"tiff"] ||
|
[extension isEqualToString:@"gif"] || [extension isEqualToString:@"tif"] || [extension isEqualToString:@"tiff"] ||
|
||||||
[extension isEqual:@"ico"] || [extension isEqual:@"bmp"]) {
|
[extension isEqualToString:@"ico"] || [extension isEqualToString:@"bmp"]) {
|
||||||
// We have texture content
|
// Texture content
|
||||||
TextureImporter *textureImporter = [[[TextureImporter alloc] init] autorelease];
|
TextureImporter *textureImporter = [[[TextureImporter alloc] init] autorelease];
|
||||||
TextureContent *textureContent = [textureImporter importFile:absolutePath];
|
TextureContent *textureContent = [textureImporter importFile:absolutePath];
|
||||||
input = [[ContentReader alloc] initWithContentManager:self Content:textureContent];
|
input = [[ContentReader alloc] initWithContentManager:self Content:textureContent];
|
||||||
|
|
||||||
} else if ([extension isEqual:@"x"]) {
|
} else if ([extension isEqualToString:@"x"]) {
|
||||||
// We have direct x model content
|
// Direct x model content
|
||||||
XImporter *xImporter = [[[XImporter alloc] init] autorelease];
|
XImporter *xImporter = [[[XImporter alloc] init] autorelease];
|
||||||
NodeContent *root = [xImporter importFile:absolutePath];
|
NodeContent *root = [xImporter importFile:absolutePath];
|
||||||
ModelProcessor *modelProcessor = [[[ModelProcessor alloc] init] autorelease];
|
ModelProcessor *modelProcessor = [[[ModelProcessor alloc] init] autorelease];
|
||||||
ModelContent *modelContent = [modelProcessor process:root];
|
ModelContent *modelContent = [modelProcessor process:root];
|
||||||
input = [[ContentReader alloc] initWithContentManager:self Content:modelContent];
|
input = [[ContentReader alloc] initWithContentManager:self Content:modelContent];
|
||||||
|
} else if ([extension isEqualToString:@"wav"]) {
|
||||||
|
// Wave audio content
|
||||||
|
WavImporter *wavImporter = [[[WavImporter alloc] init] autorelease];
|
||||||
|
AudioContent *audioContent = [wavImporter importFile:absolutePath];
|
||||||
|
SoundEffectProcessor *soundEffectProcessor = [[[SoundEffectProcessor alloc] init] autorelease];
|
||||||
|
SoundEffectContent *soundEffectContent = [soundEffectProcessor process:audioContent];
|
||||||
|
input = [[ContentReader alloc] initWithContentManager:self Content:soundEffectContent];
|
||||||
|
} else if ([extension isEqualToString:@"mp3"]) {
|
||||||
|
// Wave audio content
|
||||||
|
WavImporter *wavImporter = [[[WavImporter alloc] init] autorelease];
|
||||||
|
AudioContent *audioContent = [wavImporter importFile:absolutePath];
|
||||||
|
SongProcessor *songProcessor = [[[SongProcessor alloc] init] autorelease];
|
||||||
|
SongContent *songContent = [songProcessor process:audioContent];
|
||||||
|
input = [[ContentReader alloc] initWithContentManager:self Content:songContent];
|
||||||
} else {
|
} else {
|
||||||
[NSException raise:@"InvalidArgumentException" format:@"Files with extension %@ are not supported", extension];
|
[NSException raise:@"InvalidArgumentException" format:@"Files with extension %@ are not supported", extension];
|
||||||
}
|
}
|
||||||
@ -114,7 +129,7 @@
|
|||||||
pool = [[NSAutoreleasePool alloc] init];
|
pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
ContentTypeReader *reader = [readerManager getTypeReaderFor:[input.content class]];
|
ContentTypeReader *reader = [readerManager getTypeReaderFor:[input.content class]];
|
||||||
id result = [reader readFromInput:input into:nil];
|
id result = [[reader readFromInput:input into:nil] retain];
|
||||||
|
|
||||||
// Save the loaded asset for quick retreival.
|
// Save the loaded asset for quick retreival.
|
||||||
if (assetName) {
|
if (assetName) {
|
||||||
@ -128,7 +143,7 @@
|
|||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
// We are returning a retained object since the loaded asset is always used for a longer time.
|
// We are returning a retained object since the loaded asset is always used for a longer time.
|
||||||
return [result retain];
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) unload {
|
- (void) unload {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
VertexBufferReader *vertexBufferReader;
|
VertexBufferReader *vertexBufferReader;
|
||||||
ModelBoneReader *modelBoneReader;
|
ModelBoneReader *modelBoneReader;
|
||||||
VertexDeclarationReader *vertexDeclarationReader;
|
VertexDeclarationReader *vertexDeclarationReader;
|
||||||
|
SoundEffectReader *soundEffectReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ContentTypeReader*) getTypeReaderFor:(Class)targetType;
|
- (ContentTypeReader*) getTypeReaderFor:(Class)targetType;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
vertexBufferReader = [[VertexBufferReader alloc] init];
|
vertexBufferReader = [[VertexBufferReader alloc] init];
|
||||||
modelBoneReader = [[ModelBoneReader alloc] init];
|
modelBoneReader = [[ModelBoneReader alloc] init];
|
||||||
vertexDeclarationReader = [[VertexDeclarationReader alloc] init];
|
vertexDeclarationReader = [[VertexDeclarationReader alloc] init];
|
||||||
|
soundEffectReader = [[SoundEffectReader alloc] init];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -51,6 +52,8 @@
|
|||||||
return modelBoneReader;
|
return modelBoneReader;
|
||||||
} else if (targetType == [VertexDeclarationContent class]) {
|
} else if (targetType == [VertexDeclarationContent class]) {
|
||||||
return vertexDeclarationReader;
|
return vertexDeclarationReader;
|
||||||
|
} else if (targetType == [SoundEffectContent class]) {
|
||||||
|
return soundEffectReader;
|
||||||
} else {
|
} else {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
@class ContentImporter;
|
@class ContentImporter;
|
||||||
@class TextureImporter;
|
@class TextureImporter;
|
||||||
@class XImporter;
|
@class XImporter;
|
||||||
|
@class WavImporter;
|
||||||
|
@class Mp3Importer;
|
||||||
|
|
||||||
@protocol IContentProcessor;
|
@protocol IContentProcessor;
|
||||||
@class ContentProcessor;
|
@class ContentProcessor;
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#import "ContentImporter.h"
|
#import "ContentImporter.h"
|
||||||
#import "TextureImporter.h"
|
#import "TextureImporter.h"
|
||||||
#import "XImporter.h"
|
#import "XImporter.h"
|
||||||
|
#import "WavImporter.h"
|
||||||
|
#import "Mp3Importer.h"
|
||||||
|
|
||||||
#import "IContentProcessor.h"
|
#import "IContentProcessor.h"
|
||||||
#import "ContentProcessor.h"
|
#import "ContentProcessor.h"
|
@ -8,14 +8,10 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#import "Retronator.Xni.Framework.Content.Pipeline.Graphics.classes.h"
|
|
||||||
|
|
||||||
#import "ContentImporter.h"
|
#import "ContentImporter.h"
|
||||||
|
|
||||||
@interface TextureImporter : ContentImporter {
|
@interface TextureImporter : ContentImporter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (TextureContent*) importFile:(NSString*)filename;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -3,4 +3,5 @@
|
|||||||
@class Texture2DReader;
|
@class Texture2DReader;
|
||||||
@class ModelReader, ModelMeshReader, ModelMeshPartReader;
|
@class ModelReader, ModelMeshReader, ModelMeshPartReader;
|
||||||
@class BasicEffectReader, IndexBufferReader, VertexBufferReader;
|
@class BasicEffectReader, IndexBufferReader, VertexBufferReader;
|
||||||
@class ModelBoneReader, VertexDeclarationReader;
|
@class ModelBoneReader, VertexDeclarationReader;
|
||||||
|
@class SoundEffectReader;
|
@ -14,4 +14,6 @@
|
|||||||
#import "VertexBufferReader.h"
|
#import "VertexBufferReader.h"
|
||||||
|
|
||||||
#import "ModelBoneReader.h"
|
#import "ModelBoneReader.h"
|
||||||
#import "VertexDeclarationReader.h"
|
#import "VertexDeclarationReader.h"
|
||||||
|
|
||||||
|
#import "SoundEffectReader.h"
|
@ -14,6 +14,7 @@
|
|||||||
#import "TouchPanel+Internal.h"
|
#import "TouchPanel+Internal.h"
|
||||||
#import "GameWindow+Internal.h"
|
#import "GameWindow+Internal.h"
|
||||||
#import "Guide+Internal.h"
|
#import "Guide+Internal.h"
|
||||||
|
#import "SoundEffect+Internal.h"
|
||||||
|
|
||||||
@interface Game ()
|
@interface Game ()
|
||||||
|
|
||||||
@ -133,7 +134,7 @@ static NSArray *drawOrderSort;
|
|||||||
- (void) tick {
|
- (void) tick {
|
||||||
// Sleep if inactive.
|
// Sleep if inactive.
|
||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
//CFRunLoopRunInMode(kCFRunLoopDefaultMode, inactiveSleepTime, NO);
|
CFRunLoopRunInMode(kCFRunLoopDefaultMode, inactiveSleepTime, NO);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ static NSArray *drawOrderSort;
|
|||||||
NSTimeInterval elapsedRealTime = [currentFrameTime timeIntervalSinceDate:lastFrameTime];
|
NSTimeInterval elapsedRealTime = [currentFrameTime timeIntervalSinceDate:lastFrameTime];
|
||||||
|
|
||||||
// Sleep if we're ahead of the target elapsed time.
|
// Sleep if we're ahead of the target elapsed time.
|
||||||
/*if (isFixedTimeStep) {
|
if (isFixedTimeStep) {
|
||||||
if (elapsedRealTime < targetElapsedTime) {
|
if (elapsedRealTime < targetElapsedTime) {
|
||||||
NSTimeInterval sleepTime = targetElapsedTime - elapsedRealTime;
|
NSTimeInterval sleepTime = targetElapsedTime - elapsedRealTime;
|
||||||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, sleepTime, NO);
|
CFRunLoopRunInMode(kCFRunLoopDefaultMode, sleepTime, NO);
|
||||||
@ -155,7 +156,7 @@ static NSArray *drawOrderSort;
|
|||||||
} else {
|
} else {
|
||||||
gameTime.isRunningSlowly = YES;
|
gameTime.isRunningSlowly = YES;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
// Store current time for next frame.
|
// Store current time for next frame.
|
||||||
[lastFrameTime release];
|
[lastFrameTime release];
|
||||||
@ -169,7 +170,7 @@ static NSArray *drawOrderSort;
|
|||||||
|
|
||||||
// Update input.
|
// Update input.
|
||||||
[[TouchPanel getInstance] update];
|
[[TouchPanel getInstance] update];
|
||||||
|
|
||||||
// Update the game.
|
// Update the game.
|
||||||
[self updateWithGameTime:gameTime];
|
[self updateWithGameTime:gameTime];
|
||||||
|
|
||||||
@ -183,6 +184,9 @@ static NSArray *drawOrderSort;
|
|||||||
}
|
}
|
||||||
[enabledChangedComponents removeAllObjects];
|
[enabledChangedComponents removeAllObjects];
|
||||||
|
|
||||||
|
// Update audio.
|
||||||
|
[SoundEffect update];
|
||||||
|
|
||||||
// Draw to display.
|
// Draw to display.
|
||||||
if ([self beginDraw]) {
|
if ([self beginDraw]) {
|
||||||
[self drawWithGameTime:gameTime];
|
[self drawWithGameTime:gameTime];
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
// Handle all the waiting event sources.
|
// Handle all the waiting event sources.
|
||||||
do {
|
do {
|
||||||
runResult = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES);
|
runResult = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES);
|
||||||
NSLog(@"Handling default mode");
|
|
||||||
} while (runResult == kCFRunLoopRunHandledSource);
|
} while (runResult == kCFRunLoopRunHandledSource);
|
||||||
|
|
||||||
[game tick];
|
[game tick];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user