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

All around update and fixes

git-svn-id: http://xni.googlecode.com/svn/XNI@104 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
Matej Jan 2012-05-14 08:40:49 +00:00
parent e56e806481
commit d04d7bf8f3
34 changed files with 365 additions and 98 deletions

BIN
Classes/.DS_Store vendored

Binary file not shown.

View File

@ -12,6 +12,8 @@
@interface SoundEffect (Internal) @interface SoundEffect (Internal)
@property (nonatomic, readonly) NSUInteger bufferID;
+ (void) update; + (void) update;
@end @end

View File

@ -7,6 +7,7 @@
// //
#import "SoundEffect.h" #import "SoundEffect.h"
#import "SoundEffect+Internal.h"
#import "Retronator.Xni.Framework.Audio.h" #import "Retronator.Xni.Framework.Audio.h"
@ -68,6 +69,10 @@ static float masterVolume = 1;
@synthesize duration, name; @synthesize duration, name;
- (NSUInteger)bufferID {
return bufferID;
}
+ (float) speedOfSound { + (float) speedOfSound {
return speedOfSound; return speedOfSound;
} }
@ -125,7 +130,7 @@ static float masterVolume = 1;
} }
- (SoundEffectInstance *) createInstance { - (SoundEffectInstance *) createInstance {
return [[[SoundEffectInstance alloc] initWithBufferID:bufferID] autorelease]; return [[[SoundEffectInstance alloc] initWithSoundEffect:self] autorelease];
} }
- (BOOL) play { - (BOOL) play {

View File

@ -11,6 +11,6 @@
@interface SoundEffectInstance (Internal) @interface SoundEffectInstance (Internal)
- (id) initWithBufferID:(NSUInteger)bufferID; - (id) initWithSoundEffect:(SoundEffect*)soundEffect;
@end @end

View File

@ -16,6 +16,7 @@
@private @private
BOOL isLooped; BOOL isLooped;
float pan, pitch, volume; float pan, pitch, volume;
SoundEffect *parent;
NSUInteger sourceID; NSUInteger sourceID;
} }

View File

@ -8,18 +8,21 @@
#import "SoundEffectInstance.h" #import "SoundEffectInstance.h"
#import "SoundEffectInstance+Internal.h" #import "SoundEffectInstance+Internal.h"
#import "SoundEffect+Internal.h"
@implementation SoundEffectInstance @implementation SoundEffectInstance
- (id) initWithBufferID:(NSUInteger)bufferID - (id) initWithSoundEffect:(SoundEffect *)soundEffect
{ {
self = [super init]; self = [super init];
if (self != nil) { if (self != nil) {
parent = [soundEffect retain];
// grab a source ID from openAL // grab a source ID from openAL
alGenSources(1, &sourceID); alGenSources(1, &sourceID);
// attach the buffer to the source // attach the buffer to the source
alSourcei(sourceID, AL_BUFFER, bufferID); alSourcei(sourceID, AL_BUFFER, parent.bufferID);
// set some basic source prefs // set some basic source prefs
alSourcef(sourceID, AL_PITCH, 1.0f); alSourcef(sourceID, AL_PITCH, 1.0f);
@ -84,6 +87,7 @@
- (void) dealloc - (void) dealloc
{ {
alDeleteSources(1, &sourceID); alDeleteSources(1, &sourceID);
[parent release];
[super dealloc]; [super dealloc];
} }

View File

@ -15,4 +15,12 @@
@synthesize sourceFilename; @synthesize sourceFilename;
@synthesize sourceTool; @synthesize sourceTool;
- (void)dealloc
{
[fragmentIdentifier release];
[sourceFilename release];
[sourceTool release];
[super dealloc];
}
@end @end

View File

@ -29,4 +29,7 @@
- (void) loadContent; - (void) loadContent;
- (void) unloadContent; - (void) unloadContent;
- (void) onVisibleChanged;
- (void) onDrawOrderChanged;
@end @end

View File

@ -30,7 +30,7 @@
- (void) setVisible:(BOOL)value { - (void) setVisible:(BOOL)value {
if (visible != value) { if (visible != value) {
visible = value; visible = value;
[visibleChanged raiseWithSender:self]; [self onVisibleChanged];
} }
} }
@ -38,7 +38,7 @@
- (void) setDrawOrder:(int)value { - (void) setDrawOrder:(int)value {
if (drawOrder != value) { if (drawOrder != value) {
drawOrder = value; drawOrder = value;
[drawOrderChanged raiseWithSender:self]; [self onDrawOrderChanged];
} }
} }
@ -60,6 +60,14 @@
- (void) drawWithGameTime:(GameTime*)gameTime {} - (void) drawWithGameTime:(GameTime*)gameTime {}
- (void) unloadContent {} - (void) unloadContent {}
- (void)onVisibleChanged {
[visibleChanged raiseWithSender:self];
}
- (void)onDrawOrderChanged {
[drawOrderChanged raiseWithSender:self];
}
- (void) dealloc - (void) dealloc
{ {
if (contentLoaded) { if (contentLoaded) {

View File

@ -46,9 +46,7 @@
NSMutableArray *enabledComponents; NSMutableArray *enabledComponents;
NSMutableArray *visibleComponents; NSMutableArray *visibleComponents;
NSMutableArray *componentsList; NSMutableArray *componentsList;
NSMutableSet *initializedComponents;
// Services // Services
GameServiceContainer *services; GameServiceContainer *services;

View File

@ -14,6 +14,8 @@
#import "Retronator.Xni.Framework.Content.h" #import "Retronator.Xni.Framework.Content.h"
#import "TouchPanel+Internal.h" #import "TouchPanel+Internal.h"
#import "GameWindow+Internal.h" #import "GameWindow+Internal.h"
#import "GameViewController.h"
#import "GameView.h"
#import "Guide+Internal.h" #import "Guide+Internal.h"
#import "SoundEffect+Internal.h" #import "SoundEffect+Internal.h"
@ -57,9 +59,7 @@ static NSArray *drawOrderSort;
// First it is used for constructing a list of components, that need to be initialized. // First it is used for constructing a list of components, that need to be initialized.
// In run it is used to make a copy of enabled/visible components for enumerating over them. // In run it is used to make a copy of enabled/visible components for enumerating over them.
componentsList = [[NSMutableArray alloc] init]; componentsList = [[NSMutableArray alloc] init];
initializedComponents = [[NSMutableSet alloc] init];
[components.componentAdded subscribeDelegate: [components.componentAdded subscribeDelegate:
[Delegate delegateWithTarget:self Method:@selector(componentAddedTo:eventArgs:)]]; [Delegate delegateWithTarget:self Method:@selector(componentAddedTo:eventArgs:)]];
@ -84,7 +84,7 @@ static NSArray *drawOrderSort;
[Guide initializeWithGame:self]; [Guide initializeWithGame:self];
// Get the game host. // Get the game host.
gameHost = (GameHost*)[UIApplication sharedApplication]; gameHost = (GameHost*)[UIApplication sharedApplication];
} }
return self; return self;
@ -130,15 +130,26 @@ static NSArray *drawOrderSort;
inRun = YES; inRun = YES;
[self beginRun]; [self beginRun];
// First update with zero gameTime. // First frame with zero gameTime.
[self updateWithGameTime:gameTime]; [self updateWithGameTime:gameTime];
lastFrameTime = [[NSDate alloc] init];
if ([self beginDraw]) {
[self drawWithGameTime:gameTime];
[self endDraw];
}
// Force redraw.
[self.window.gameViewController.gameView layoutSubviews];
// Run the game host with a delay event, so we don't block this method. // Run the game host with a delay event, so we don't block this method.
[gameHost performSelector:@selector(run) withObject:nil afterDelay:0]; [gameHost performSelector:@selector(run) withObject:nil afterDelay:0];
} }
- (void) tick { - (void) tick {
if (!lastFrameTime) {
lastFrameTime = [[NSDate alloc] init];
}
// Sleep if inactive. // Sleep if inactive.
if (!isActive) { if (!isActive) {
CFRunLoopRunInMode(kCFRunLoopDefaultMode, inactiveSleepTime, NO); CFRunLoopRunInMode(kCFRunLoopDefaultMode, inactiveSleepTime, NO);
@ -195,7 +206,8 @@ static NSArray *drawOrderSort;
- (void) applicationDidFinishLaunching:(UIApplication *)application { - (void) applicationDidFinishLaunching:(UIApplication *)application {
NSLog(@"Application has started."); NSLog(@"Application has started.");
[self performSelector:@selector(run) withObject:nil afterDelay:0];
[self run];
} }
- (void) applicationWillResignActive:(UIApplication *)application - (void) applicationWillResignActive:(UIApplication *)application
@ -235,7 +247,6 @@ static NSArray *drawOrderSort;
while ([componentsList count] > 0) { while ([componentsList count] > 0) {
id<IGameComponent> component = [componentsList objectAtIndex:0]; id<IGameComponent> component = [componentsList objectAtIndex:0];
[component initialize]; [component initialize];
[initializedComponents addObject:component];
[componentsList removeObjectAtIndex:0]; [componentsList removeObjectAtIndex:0];
} }
initializeDone = YES; initializeDone = YES;
@ -270,7 +281,7 @@ static NSArray *drawOrderSort;
- (void) endDraw { - (void) endDraw {
[graphicsDeviceManager endDraw]; [graphicsDeviceManager endDraw];
} }
- (void) unloadContent {} - (void) unloadContent {}
- (void) endRun {} - (void) endRun {}
@ -310,10 +321,7 @@ static NSArray *drawOrderSort;
- (void) componentAddedTo:(GameComponentCollection*)sender eventArgs:(GameComponentCollectionEventArgs*)e { - (void) componentAddedTo:(GameComponentCollection*)sender eventArgs:(GameComponentCollectionEventArgs*)e {
// Initialize component if it's being added after main initialize has been called. // Initialize component if it's being added after main initialize has been called.
if (initializeDone) { if (initializeDone) {
if (![initializedComponents containsObject:e.gameComponent]) { [e.gameComponent initialize];
[e.gameComponent initialize];
[initializedComponents addObject:e.gameComponent];
}
} else { } else {
[componentsList addObject:e.gameComponent]; [componentsList addObject:e.gameComponent];
} }
@ -411,7 +419,6 @@ static NSArray *drawOrderSort;
[self unloadContent]; [self unloadContent];
[gameTime release]; [gameTime release];
[initializedComponents release];
[componentsList release]; [componentsList release];
[enabledComponents release]; [enabledComponents release];
[visibleComponents release]; [visibleComponents release];

View File

@ -26,4 +26,7 @@
@property (nonatomic, readonly) Game *game; @property (nonatomic, readonly) Game *game;
- (void) onEnabledChanged;
- (void) onUpdateOrderChanged;
@end @end

View File

@ -32,7 +32,7 @@
- (void) setEnabled:(BOOL)value { - (void) setEnabled:(BOOL)value {
if (enabled != value) { if (enabled != value) {
enabled = value; enabled = value;
[enabledChanged raiseWithSender:self]; [self onEnabledChanged];
} }
} }
@ -40,7 +40,7 @@
- (void) setUpdateOrder:(int)value { - (void) setUpdateOrder:(int)value {
if (updateOrder != value) { if (updateOrder != value) {
updateOrder = value; updateOrder = value;
[updateOrderChanged raiseWithSender:self]; [self onUpdateOrderChanged];
} }
} }
@ -49,6 +49,14 @@
- (void) initialize {} - (void) initialize {}
- (void) onEnabledChanged {
[enabledChanged raiseWithSender:self];
}
- (void) onUpdateOrderChanged {
[updateOrderChanged raiseWithSender:self];
}
- (void) updateWithGameTime:(GameTime*)gameTime {} - (void) updateWithGameTime:(GameTime*)gameTime {}
- (void) dealloc - (void) dealloc

View File

@ -18,7 +18,7 @@
self = [super init]; self = [super init];
if (self) { if (self) {
[MediaPlayer load]; [MediaPlayer load];
window = [[GameWindow alloc] init]; window = [[GameWindow alloc] init];
} }
return self; return self;
} }

View File

@ -13,6 +13,7 @@
@interface BasicEffectPass : EffectPass { @interface BasicEffectPass : EffectPass {
BasicEffect *basicEffect; BasicEffect *basicEffect;
ReachGraphicsDevice *reachGraphicsDevice;
} }
- (id) initWithBasicEffect:(BasicEffect*)theBasicEffect graphicsDevice:(GraphicsDevice*)theGraphicsDevice; - (id) initWithBasicEffect:(BasicEffect*)theBasicEffect graphicsDevice:(GraphicsDevice*)theGraphicsDevice;
@ -124,6 +125,7 @@
self = [super initWithName:@"BasicEffectPass" graphicsDevice:theGraphicsDevice]; self = [super initWithName:@"BasicEffectPass" graphicsDevice:theGraphicsDevice];
if (self) { if (self) {
basicEffect = theBasicEffect; basicEffect = theBasicEffect;
reachGraphicsDevice = (ReachGraphicsDevice*)theGraphicsDevice;
} }
return self; return self;
} }
@ -153,7 +155,7 @@
// Set texturing. // Set texturing.
if (basicEffect.textureEnabled) { if (basicEffect.textureEnabled) {
[graphicsDevice.textures setItem:basicEffect.texture atIndex:0]; [graphicsDevice.textures setItem:basicEffect.texture atIndex:0];
glActiveTexture(GL_TEXTURE0); //glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
} else { } else {
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
@ -188,10 +190,9 @@
} }
- (void) activateLight:(DirectionalLight *)light name:(uint)lightName { - (void) activateLight:(DirectionalLight *)light name:(uint)lightName {
if (light.enabled) { [reachGraphicsDevice setLight:lightName to:light.enabled];
glEnable(lightName);
} else { if (!light.enabled) {
glDisable(lightName);
return; return;
} }

View File

@ -41,6 +41,7 @@
SamplerStateCollection *samplerStates; SamplerStateCollection *samplerStates;
TextureCollection *textures; TextureCollection *textures;
Viewport *viewport; Viewport *viewport;
int activeTextureIndex;
// Events // Events
Event *deviceResetting; Event *deviceResetting;

View File

@ -86,10 +86,12 @@
self.blendFactor = [Color white]; self.blendFactor = [Color white];
self.blendState = [BlendState opaque]; self.blendState = [BlendState opaque];
self.depthStencilState = [DepthStencilState defaultDepth]; self.depthStencilState = [DepthStencilState defaultDepth];
glDepthRangef(0, 1);
graphicsDeviceStatus = GraphicsDeviceStatusNormal; graphicsDeviceStatus = GraphicsDeviceStatusNormal;
self.indices = nil; self.indices = nil;
self.rasterizerState = [RasterizerState cullCounterClockwise]; self.rasterizerState = [RasterizerState cullCounterClockwise];
self.referenceStencil = 0; self.referenceStencil = 0;
activeTextureIndex = -1;
[samplerStates setItem:[SamplerState linearClamp] atIndex:0]; [samplerStates setItem:[SamplerState linearClamp] atIndex:0];
// Create events. // Create events.
@ -108,30 +110,54 @@
@synthesize blendState; @synthesize blendState;
- (void) setBlendState:(BlendState*)value { - (void) setBlendState:(BlendState*)value {
if (value != blendState) { if (value != blendState) {
[value retain]; BlendState *old = blendState;
[blendState release]; blendState = [value retain];
blendState = value;
// Apply the blend state. // Apply the blend state.
glBlendFunc(blendState.colorSourceBlend, blendState.colorDestinationBlend); if (old.colorSourceBlend != blendState.colorSourceBlend ||
old.colorDestinationBlend != blendState.colorDestinationBlend ||
old.alphaSourceBlend != blendState.alphaSourceBlend ||
old.alphaDestinationBlend != blendState.alphaDestinationBlend) {
glBlendFuncSeparate(blendState.colorSourceBlend,
blendState.colorDestinationBlend,
blendState.alphaSourceBlend,
blendState.alphaDestinationBlend);
}
if (old.colorBlendFunction != blendState.colorBlendFunction ||
old.alphaBlendFunction != blendState.alphaBlendFunction) {
glBlendEquationSeparate(blendState.colorBlendFunction,
blendState.alphaBlendFunction);
}
[old release];
} }
} }
@synthesize depthStencilState; @synthesize depthStencilState;
- (void) setDepthStencilState:(DepthStencilState*)value { - (void) setDepthStencilState:(DepthStencilState*)value {
if (value != depthStencilState) { if (value != depthStencilState) {
[value retain]; DepthStencilState *old = depthStencilState;
[depthStencilState release]; depthStencilState = [value retain];
depthStencilState = value;
// Apply depth state. // Apply depth state.
FLAG_BLOCK(depthStencilState.depthBufferEnable, GL_DEPTH_TEST) if (old.depthBufferEnable != depthStencilState.depthBufferEnable) {
glDepthFunc(depthStencilState.depthBufferFunction); FLAG_BLOCK(depthStencilState.depthBufferEnable, GL_DEPTH_TEST)
glDepthMask(depthStencilState.depthBufferWriteEnable); }
glDepthRangef(0, 1);
if (old.depthBufferFunction != depthStencilState.depthBufferFunction) {
glDepthFunc(depthStencilState.depthBufferFunction);
}
if (old.depthBufferWriteEnable != depthStencilState.depthBufferWriteEnable) {
glDepthMask(depthStencilState.depthBufferWriteEnable);
}
// TODO: Apply stencil state. // TODO: Apply stencil state.
[old release];
} }
} }
@ -337,7 +363,7 @@
[GraphicsDevice getFormat:&format AndType:&type ForSurfaceFormat:texture.format]; [GraphicsDevice getFormat:&format AndType:&type ForSurfaceFormat:texture.format];
glBindTexture(GL_TEXTURE_2D, texture.textureId); glBindTexture(GL_TEXTURE_2D, texture.textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@ -348,7 +374,7 @@
} else { } else {
glTexImage2D(GL_TEXTURE_2D, level, format, texture.width, texture.height, 0, format, type, data); glTexImage2D(GL_TEXTURE_2D, level, format, texture.width, texture.height, 0, format, type, data);
} }
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} }
@ -452,7 +478,10 @@
} }
- (void) applySamplerState:(id)sender eventArgs:(XniSamplerEventArgs*)e { - (void) applySamplerState:(id)sender eventArgs:(XniSamplerEventArgs*)e {
glActiveTexture(e.samplerIndex); if (activeTextureIndex != e.samplerIndex) {
activeTextureIndex = e.samplerIndex;
glActiveTexture(GL_TEXTURE0 + e.samplerIndex);
}
Texture *texture = [textures itemAtIndex:e.samplerIndex]; Texture *texture = [textures itemAtIndex:e.samplerIndex];

View File

@ -18,11 +18,11 @@ typedef enum {
} Blend; } Blend;
typedef enum { typedef enum {
BlendFunctionAdd, BlendFunctionAdd = GL_FUNC_ADD,
BlendFunctionMax, //BlendFunctionMax = GL_MAX,
BlendFunctionMin, //BlendFunctionMin = GL_MIN,
BlendFunctionReverseSubstract, BlendFunctionReverseSubstract = GL_FUNC_REVERSE_SUBTRACT,
BlendFunctionSubtract BlendFunctionSubtract = GL_FUNC_SUBTRACT
} BlendFunction; } BlendFunction;
typedef enum { typedef enum {

View File

@ -12,6 +12,9 @@
@interface ReachGraphicsDevice : GraphicsDevice { @interface ReachGraphicsDevice : GraphicsDevice {
BOOL lightsActive[8];
} }
- (void) setLight:(uint)lightname to:(BOOL)value;
@end @end

View File

@ -38,6 +38,18 @@
@implementation ReachGraphicsDevice @implementation ReachGraphicsDevice
- (id)initWithGame:(Game *)theGame {
self = [super initWithGame:theGame];
if (self) {
// Disable lights.
for (int i=0; i<8; i++) {
lightsActive[i] = false;
glDisable(GL_LIGHT0 + i);
}
}
return self;
}
- (EAGLContext*) createContext { - (EAGLContext*) createContext {
return [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1] autorelease]; return [[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1] autorelease];
} }
@ -59,7 +71,7 @@
minVertexIndex:(int)minVertexIndex minVertexIndex:(int)minVertexIndex
numVertices:(int)numVertices numVertices:(int)numVertices
startIndex:(int)startIndex startIndex:(int)startIndex
primitiveCount:(int)primitiveCount; primitiveCount:(int)primitiveCount
{ {
[self enableVertexBuffers]; [self enableVertexBuffers];
@ -176,6 +188,19 @@
} }
- (void)setLight:(uint)lightname to:(BOOL)value {
int index = lightname - GL_LIGHT0;
if (value != lightsActive[index]) {
lightsActive[index] = value;
if (value) {
glEnable(lightname);
} else {
glDisable(lightname);
}
}
}
// Private methods // Private methods
- (void) enableVertexBuffers { - (void) enableVertexBuffers {

View File

@ -12,6 +12,8 @@
#import "SpriteFont+Internal.h" #import "SpriteFont+Internal.h"
#import "XniAdaptiveArray.h"
typedef struct { typedef struct {
float x; float x;
float y; float y;
@ -60,6 +62,8 @@ static inline void SpriteSetSource(XniSprite *sprite, Rectangle *source, Texture
} else { } else {
sprite->source.width = 1; sprite->source.width = 1;
sprite->source.height = 1; sprite->source.height = 1;
sprite->source.x = 0;
sprite->source.y = 0;
} }
if (effects & SpriteEffectsFlipHorizontally) { if (effects & SpriteEffectsFlipHorizontally) {
@ -76,8 +80,12 @@ static inline void SpriteSetSource(XniSprite *sprite, Rectangle *source, Texture
static inline void SpriteSetVertices(XniSprite *sprite, float positionX, float positionY, float originX, float originY, float scaleX, float scaleY, float rotation, float width, float height) { static inline void SpriteSetVertices(XniSprite *sprite, float positionX, float positionY, float originX, float originY, float scaleX, float scaleY, float rotation, float width, float height) {
float x = originX * scaleX; float x = originX * scaleX;
float y = -originY * scaleY; float y = -originY * scaleY;
float c = cos(rotation); float c = 1;
float s = sin(rotation); float s = 0;
if (rotation) {
c = cosf(rotation);
s = sinf(rotation);
}
sprite->position.x = positionX - x * c - y * s; sprite->position.x = positionX - x * c - y * s;
sprite->position.y = positionY - x * s + y * c; sprite->position.y = positionY - x * s + y * c;
sprite->width.x = width * scaleX * c; sprite->width.x = width * scaleX * c;
@ -90,7 +98,9 @@ static inline void SpriteSetDestinationFast(XniSprite *sprite, Rectangle *destin
sprite->position.x = destination.x; sprite->position.x = destination.x;
sprite->position.y = destination.y; sprite->position.y = destination.y;
sprite->width.x = destination.width; sprite->width.x = destination.width;
sprite->width.y = 0;
sprite->height.y = destination.height; sprite->height.y = destination.height;
sprite->height.x = 0;
} }
static inline void SpriteSetDestination(XniSprite *sprite, Rectangle *destination, float originX, float originY, float rotation) { static inline void SpriteSetDestination(XniSprite *sprite, Rectangle *destination, float originX, float originY, float rotation) {
@ -113,7 +123,7 @@ static inline void SpriteSetPosition(XniSprite *sprite, Vector2 *position, float
- (void) setProjection; - (void) setProjection;
- (void) apply; - (void) apply;
- (void) draw:(XniSprite*)sprite; void draw(XniSprite *sprite, NSMutableArray *sprites, SpriteSortMode sortMode, SpriteBatch *it);
- (void) draw; - (void) draw;
- (void) drawFrom:(int)startIndex to:(int)endIndex; - (void) drawFrom:(int)startIndex to:(int)endIndex;
@ -121,6 +131,30 @@ static inline void SpriteSetPosition(XniSprite *sprite, Vector2 *position, float
@implementation SpriteBatch @implementation SpriteBatch
// Sprite pool
static XniAdaptiveArray *spritePool;
static inline XniSprite *SpriteFromPool() {
if (spritePool.count > 0) {
XniSprite *sprite = *(XniSprite**)[spritePool removeLastItem];
return sprite;
} else {
XniSprite *sprite = [[XniSprite alloc] init];
return sprite;
}
}
static inline void ReturnSpriteToPool(XniSprite *sprite) {
[spritePool addItem:&sprite];
}
static inline void ReturnSpritesToPool(NSArray *sprites) {
for (XniSprite *sprite in sprites) {
[spritePool addItem:&sprite];
}
}
// Recyclable vertices // Recyclable vertices
static VertexPositionColorTextureStruct vertices[4]; static VertexPositionColorTextureStruct vertices[4];
@ -151,6 +185,8 @@ static VertexPositionColorTextureStruct vertices[4];
textureSort = [[NSArray arrayWithObject:textureSortDescriptor] retain]; textureSort = [[NSArray arrayWithObject:textureSortDescriptor] retain];
frontToBackSort = [[NSArray arrayWithObject:depthAscendingSortDescriptor] retain]; frontToBackSort = [[NSArray arrayWithObject:depthAscendingSortDescriptor] retain];
backToFrontSort = [[NSArray arrayWithObject:depthDescendingSortDescriptor] retain]; backToFrontSort = [[NSArray arrayWithObject:depthDescendingSortDescriptor] retain];
spritePool = [[XniAdaptiveArray alloc] initWithItemSize:sizeof(XniSprite*) initialCapacity:64];
} }
- (void) setProjection { - (void) setProjection {
@ -185,7 +221,14 @@ static VertexPositionColorTextureStruct vertices[4];
DepthStencilState:(DepthStencilState*)theDepthStencilState DepthStencilState:(DepthStencilState*)theDepthStencilState
RasterizerState:(RasterizerState*)theRasterizerState RasterizerState:(RasterizerState*)theRasterizerState
Effect:(Effect*)theEffect { Effect:(Effect*)theEffect {
[self beginWithSortMode:theSortMode BlendState:theBlendState SamplerState:theSamplerState DepthStencilState:theDepthStencilState RasterizerState:theRasterizerState Effect:theEffect TransformMatrix:nil];
// Make sure not to overwrite the world transform in basic effect.
Matrix *transform = nil;
if ([theEffect isKindOfClass:[BasicEffect class]]) {
transform = ((BasicEffect*)theEffect).world;
}
[self beginWithSortMode:theSortMode BlendState:theBlendState SamplerState:theSamplerState DepthStencilState:theDepthStencilState RasterizerState:theRasterizerState Effect:theEffect TransformMatrix:transform];
} }
- (void) beginWithSortMode:(SpriteSortMode)theSortMode - (void) beginWithSortMode:(SpriteSortMode)theSortMode
@ -223,72 +266,72 @@ static VertexPositionColorTextureStruct vertices[4];
} }
- (void) draw:(Texture2D*)texture toRectangle:(Rectangle*)destinationRectangle tintWithColor:(Color*)color { - (void) draw:(Texture2D*)texture toRectangle:(Rectangle*)destinationRectangle tintWithColor:(Color*)color {
XniSprite *sprite = [[[XniSprite alloc] init] autorelease]; XniSprite *sprite = SpriteFromPool();
sprite->texture = texture; sprite->texture = texture;
SpriteSetDestinationFast(sprite, destinationRectangle); SpriteSetDestinationFast(sprite, destinationRectangle);
SpriteSetSource(sprite, nil, texture, SpriteEffectsNone); SpriteSetSource(sprite, nil, texture, SpriteEffectsNone);
sprite->color = color.packedValue; sprite->color = color.packedValue;
[self draw:sprite]; draw(sprite, sprites, sortMode, self);
} }
- (void) draw:(Texture2D*)texture toRectangle:(Rectangle*)destinationRectangle fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color { - (void) draw:(Texture2D*)texture toRectangle:(Rectangle*)destinationRectangle fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color {
XniSprite *sprite = [[[XniSprite alloc] init] autorelease]; XniSprite *sprite = SpriteFromPool();
sprite->texture = texture; sprite->texture = texture;
SpriteSetDestinationFast(sprite, destinationRectangle); SpriteSetDestinationFast(sprite, destinationRectangle);
SpriteSetSource(sprite, sourceRectangle, texture, SpriteEffectsNone); SpriteSetSource(sprite, sourceRectangle, texture, SpriteEffectsNone);
sprite->color = color.packedValue; sprite->color = color.packedValue;
[self draw:sprite]; draw(sprite, sprites, sortMode, self);
} }
- (void) draw:(Texture2D*)texture toRectangle:(Rectangle*)destinationRectangle fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color - (void) draw:(Texture2D*)texture toRectangle:(Rectangle*)destinationRectangle fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color
rotation:(float)rotation origin:(Vector2*)origin effects:(SpriteEffects)effects layerDepth:(float)layerDepth { rotation:(float)rotation origin:(Vector2*)origin effects:(SpriteEffects)effects layerDepth:(float)layerDepth {
XniSprite *sprite = [[[XniSprite alloc] init] autorelease]; XniSprite *sprite = SpriteFromPool();
sprite->texture = texture; sprite->texture = texture;
SpriteSetDestination(sprite, destinationRectangle, origin.x, origin.y, rotation); SpriteSetDestination(sprite, destinationRectangle, origin.x, origin.y, rotation);
SpriteSetSource(sprite, sourceRectangle, texture, effects); SpriteSetSource(sprite, sourceRectangle, texture, effects);
sprite->color = color.packedValue; sprite->color = color.packedValue;
sprite->layerDepth = layerDepth; sprite->layerDepth = layerDepth;
[self draw:sprite]; draw(sprite, sprites, sortMode, self);
} }
- (void) draw:(Texture2D*)texture to:(Vector2*)position tintWithColor:(Color*)color { - (void) draw:(Texture2D*)texture to:(Vector2*)position tintWithColor:(Color*)color {
XniSprite *sprite = [[[XniSprite alloc] init] autorelease]; XniSprite *sprite = SpriteFromPool();
sprite->texture = texture; sprite->texture = texture;
SpriteSetPositionFast(sprite, position, texture.width, texture.height); SpriteSetPositionFast(sprite, position, texture.width, texture.height);
SpriteSetSource(sprite, nil, texture, SpriteEffectsNone); SpriteSetSource(sprite, nil, texture, SpriteEffectsNone);
sprite->color = color.packedValue; sprite->color = color.packedValue;
[self draw:sprite]; draw(sprite, sprites, sortMode, self);
} }
- (void) draw:(Texture2D*)texture to:(Vector2*)position fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color { - (void) draw:(Texture2D*)texture to:(Vector2*)position fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color {
XniSprite *sprite = [[[XniSprite alloc] init] autorelease]; XniSprite *sprite = SpriteFromPool();
sprite->texture = texture; sprite->texture = texture;
SpriteSetPositionFast(sprite, position, sourceRectangle ? sourceRectangle.width : texture.width, sourceRectangle ? sourceRectangle.height : texture.height); SpriteSetPositionFast(sprite, position, sourceRectangle ? sourceRectangle.width : texture.width, sourceRectangle ? sourceRectangle.height : texture.height);
SpriteSetSource(sprite, sourceRectangle, texture, SpriteEffectsNone); SpriteSetSource(sprite, sourceRectangle, texture, SpriteEffectsNone);
sprite->color = color.packedValue; sprite->color = color.packedValue;
[self draw:sprite]; draw(sprite, sprites, sortMode, self);
} }
- (void) draw:(Texture2D*)texture to:(Vector2*)position fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color - (void) draw:(Texture2D*)texture to:(Vector2*)position fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color
rotation:(float)rotation origin:(Vector2*)origin scaleUniform:(float)scale effects:(SpriteEffects)effects layerDepth:(float)layerDepth { rotation:(float)rotation origin:(Vector2*)origin scaleUniform:(float)scale effects:(SpriteEffects)effects layerDepth:(float)layerDepth {
XniSprite *sprite = [[[XniSprite alloc] init] autorelease]; XniSprite *sprite = SpriteFromPool();
sprite->texture = texture; sprite->texture = texture;
SpriteSetPosition(sprite, position, origin.x, origin.y, scale, scale, rotation, sourceRectangle ? sourceRectangle.width : texture.width, sourceRectangle ? sourceRectangle.height : texture.height); SpriteSetPosition(sprite, position, origin.x, origin.y, scale, scale, rotation, sourceRectangle ? sourceRectangle.width : texture.width, sourceRectangle ? sourceRectangle.height : texture.height);
SpriteSetSource(sprite, sourceRectangle, texture, effects); SpriteSetSource(sprite, sourceRectangle, texture, effects);
sprite->color = color.packedValue; sprite->color = color.packedValue;
sprite->layerDepth = layerDepth; sprite->layerDepth = layerDepth;
[self draw:sprite]; draw(sprite, sprites, sortMode, self);
} }
- (void) draw:(Texture2D*)texture to:(Vector2*)position fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color - (void) draw:(Texture2D*)texture to:(Vector2*)position fromRectangle:(Rectangle*)sourceRectangle tintWithColor:(Color*)color
rotation:(float)rotation origin:(Vector2*)origin scale:(Vector2*)scale effects:(SpriteEffects)effects layerDepth:(float)layerDepth { rotation:(float)rotation origin:(Vector2*)origin scale:(Vector2*)scale effects:(SpriteEffects)effects layerDepth:(float)layerDepth {
XniSprite *sprite = [[[XniSprite alloc] init] autorelease]; XniSprite *sprite = SpriteFromPool();
sprite->texture = texture; sprite->texture = texture;
SpriteSetPosition(sprite, position, origin.x, origin.y, scale.x, scale.y, rotation, sourceRectangle ? sourceRectangle.width : texture.width, sourceRectangle ? sourceRectangle.height : texture.height); SpriteSetPosition(sprite, position, origin.x, origin.y, scale.x, scale.y, rotation, sourceRectangle ? sourceRectangle.width : texture.width, sourceRectangle ? sourceRectangle.height : texture.height);
SpriteSetSource(sprite, sourceRectangle, texture, effects); SpriteSetSource(sprite, sourceRectangle, texture, effects);
sprite->color = color.packedValue; sprite->color = color.packedValue;
sprite->layerDepth = layerDepth; sprite->layerDepth = layerDepth;
[self draw:sprite]; draw(sprite, sprites, sortMode, self);
} }
- (void) drawStringWithSpriteFont:(SpriteFont*)spriteFont text:(NSString*)text to:(Vector2*)position tintWithColor:(Color*)color { - (void) drawStringWithSpriteFont:(SpriteFont*)spriteFont text:(NSString*)text to:(Vector2*)position tintWithColor:(Color*)color {
@ -326,11 +369,12 @@ static VertexPositionColorTextureStruct vertices[4];
} }
} }
- (void) draw:(XniSprite *)sprite { void draw(XniSprite *sprite, NSMutableArray *sprites, SpriteSortMode sortMode, SpriteBatch *it) {
[sprites addObject:sprite]; [sprites addObject:sprite];
if (sortMode == SpriteSortModeImmediate) { if (sortMode == SpriteSortModeImmediate) {
[self draw]; [it draw];
ReturnSpritesToPool(sprites);
[sprites removeAllObjects]; [sprites removeAllObjects];
} }
} }
@ -365,6 +409,7 @@ static VertexPositionColorTextureStruct vertices[4];
[self draw]; [self draw];
// Clean up. // Clean up.
ReturnSpritesToPool(sprites);
[sprites removeAllObjects]; [sprites removeAllObjects];
beginCalled = NO; beginCalled = NO;
} }
@ -430,7 +475,7 @@ static VertexPositionColorTextureStruct vertices[4];
vertices[3].position.x = vertices[0].position.x + sprite->height.x + sprite->width.x; vertices[3].position.x = vertices[0].position.x + sprite->height.x + sprite->width.x;
vertices[3].position.y = vertices[0].position.y + sprite->height.y + sprite->width.y; vertices[3].position.y = vertices[0].position.y + sprite->height.y + sprite->width.y;
vertices[3].position.z = sprite->layerDepth; vertices[3].position.z = sprite->layerDepth;
vertices[0].texture.x = sprite->source.x; vertices[0].texture.x = sprite->source.x;
vertices[1].texture.x = sprite->source.x; vertices[1].texture.x = sprite->source.x;
vertices[2].texture.x = sprite->source.x + sprite->source.width; vertices[2].texture.x = sprite->source.x + sprite->source.width;

View File

@ -17,6 +17,7 @@
} }
- (id) initWithItemSize:(int)itemSize initialCapacity:(int)initialCapacity; - (id) initWithItemSize:(int)itemSize initialCapacity:(int)initialCapacity;
- (id) initWithArray:(VertexArray*)source;
@property (nonatomic, readonly) void *array; @property (nonatomic, readonly) void *array;
@property (nonatomic, readonly) int count; @property (nonatomic, readonly) int count;

View File

@ -19,6 +19,13 @@
return self; return self;
} }
- (id)initWithArray:(VertexArray *)source {
if (self = [super init]) {
array = [[XniAdaptiveArray alloc] initWithArray:source->array];
}
return self;
}
- (void *) array { - (void *) array {
return array.array; return array.array;
} }

View File

@ -57,11 +57,21 @@
float projectionY = -((source.y - y) * 2 / height) + 1; float projectionY = -((source.y - y) * 2 / height) + 1;
float projectionZ = (source.z - minDepth) / (maxDepth - minDepth); float projectionZ = (source.z - minDepth) / (maxDepth - minDepth);
Vector4 *objectSpace = [Vector4 vectorWithX:projectionX y:projectionY z:projectionZ w:1]; Vector4Struct objectSpace = Vector4Make(projectionX,projectionY,projectionZ,1);
[objectSpace transformWith:[Matrix invert:projection]];
[objectSpace transformWith:[Matrix invert:view]]; MatrixStruct m = *projection.data;
[objectSpace transformWith:[Matrix invert:world]]; MatrixInvert(&m);
[objectSpace multiplyBy:1/objectSpace.w]; Vector4Transform(&objectSpace, &m, &objectSpace);
m = *view.data;
MatrixInvert(&m);
Vector4Transform(&objectSpace, &m, &objectSpace);
m = *world.data;
MatrixInvert(&m);
Vector4Transform(&objectSpace, &m, &objectSpace);
Vector4Multiply(&objectSpace, 1/objectSpace.w, &objectSpace);
return [Vector3 vectorWithX:objectSpace.x y:objectSpace.y z:objectSpace.z]; return [Vector3 vectorWithX:objectSpace.x y:objectSpace.y z:objectSpace.z];
} }

View File

@ -27,6 +27,7 @@
NSMutableSet *releaseTouches; NSMutableSet *releaseTouches;
NSMutableSet *lateReleaseTouches; NSMutableSet *lateReleaseTouches;
NSMutableDictionary *touchLocations; NSMutableDictionary *touchLocations;
NSMutableDictionary *uiTouchesForLocations;
} }
@property (nonatomic) int displayWidth; @property (nonatomic) int displayWidth;

View File

@ -15,16 +15,16 @@
#import "GameView.h" #import "GameView.h"
@interface XniTouchLocation : NSObject { @interface XniTouchLocation : NSObject {
@public
int identifier; int identifier;
Vector2 *position; Vector2 *position;
Vector2 *previousPosition; Vector2 *previousPosition;
TouchLocationState state; TouchLocationState state;
int age;
} }
- (id) initWithPosition:(Vector2*)thePosition; - (id) initWithPosition:(Vector2*)thePosition;
@property (nonatomic) TouchLocationState state;
- (void) update; - (void) update;
- (void) moveToPosition:(Vector2*)newPosition; - (void) moveToPosition:(Vector2*)newPosition;
@ -48,10 +48,9 @@ static int nextID = 0;
return self; return self;
} }
@synthesize state;
- (void) update { - (void) update {
[self moveToPosition:position]; [self moveToPosition:position];
age++;
} }
- (void) moveToPosition:(Vector2*)newPosition { - (void) moveToPosition:(Vector2*)newPosition {
@ -93,6 +92,7 @@ static TouchPanel *instance;
lateReleaseTouches = [[NSMutableSet alloc] init]; lateReleaseTouches = [[NSMutableSet alloc] init];
touchLocations = (NSMutableDictionary*)CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); touchLocations = (NSMutableDictionary*)CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
uiTouchesForLocations = (NSMutableDictionary*)CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
} }
return self; return self;
} }
@ -134,7 +134,11 @@ static TouchPanel *instance;
// After get state is done, all pressed touches should be moved. // After get state is done, all pressed touches should be moved.
[touch update]; [touch update];
} if (touch->age > 200) {
UITouch *key = [uiTouchesForLocations objectForKey:touch];
[removeTouches addObject:key];
}
}
return collection; return collection;
} }
@ -152,7 +156,8 @@ static TouchPanel *instance;
float scale = view.scale; float scale = view.scale;
for (UITouch *touch in touches) { for (UITouch *touch in touches) {
XniTouchLocation *location = [touchLocations objectForKey:touch]; XniTouchLocation *location = [touchLocations objectForKey:touch];
if (location) { if (location) {
location->age = 0;
CGPoint position = [touch locationInView:view]; CGPoint position = [touch locationInView:view];
[location moveToPosition:[Vector2 vectorWithX:position.x * scale y:position.y * scale]]; [location moveToPosition:[Vector2 vectorWithX:position.x * scale y:position.y * scale]];
} }
@ -179,14 +184,21 @@ static TouchPanel *instance;
- (void) update { - (void) update {
// Remove all previously released touches. // Remove all previously released touches.
for (UITouch *touch in removeTouches) { for (UITouch *touch in removeTouches) {
XniTouchLocation *location = [[touchLocations objectForKey:touch] retain];
[touchLocations removeObjectForKey:touch]; [touchLocations removeObjectForKey:touch];
if (location) {
[uiTouchesForLocations removeObjectForKey:location];
[location release];
}
} }
[removeTouches removeAllObjects]; [removeTouches removeAllObjects];
// Set released touches. // Set released touches.
for (UITouch *touch in releaseTouches) { for (UITouch *touch in releaseTouches) {
XniTouchLocation *location = [touchLocations objectForKey:touch]; XniTouchLocation *location = [touchLocations objectForKey:touch];
location.state = TouchLocationStateReleased; if (location) {
location->state = TouchLocationStateReleased;
}
} }
// Shift the pools. // Shift the pools.
@ -203,6 +215,7 @@ static TouchPanel *instance;
initWithPosition:[Vector2 vectorWithX:position.x * scale y:position.y * scale]] autorelease]; initWithPosition:[Vector2 vectorWithX:position.x * scale y:position.y * scale]] autorelease];
CFDictionaryAddValue((CFMutableDictionaryRef)touchLocations, touch, location); CFDictionaryAddValue((CFMutableDictionaryRef)touchLocations, touch, location);
CFDictionaryAddValue((CFMutableDictionaryRef)uiTouchesForLocations, location, touch);
} }
[addTouches removeAllObjects]; [addTouches removeAllObjects];
@ -215,6 +228,7 @@ static TouchPanel *instance;
[releaseTouches release]; [releaseTouches release];
[lateReleaseTouches release]; [lateReleaseTouches release];
[touchLocations release]; [touchLocations release];
[uiTouchesForLocations release];
[super dealloc]; [super dealloc];
} }

View File

@ -258,4 +258,24 @@ static inline void MatrixDivide(MatrixStruct *value1, MatrixStruct *value2, Matr
result->m42 = value1->m42 / value2->m42; result->m42 = value1->m42 / value2->m42;
result->m43 = value1->m43 / value2->m43; result->m43 = value1->m43 / value2->m43;
result->m44 = value1->m44 / value2->m44; result->m44 = value1->m44 / value2->m44;
}
static inline void MatrixLerp(MatrixStruct *value1, MatrixStruct *value2, float amount, MatrixStruct *result) {
float first = 1 - amount;
result->m11 = value1->m11 * first + value2->m11 * amount;
result->m12 = value1->m12 * first + value2->m12 * amount;
result->m13 = value1->m13 * first + value2->m13 * amount;
result->m14 = value1->m14 * first + value2->m14 * amount;
result->m21 = value1->m21 * first + value2->m21 * amount;
result->m22 = value1->m22 * first + value2->m22 * amount;
result->m23 = value1->m23 * first + value2->m23 * amount;
result->m24 = value1->m24 * first + value2->m24 * amount;
result->m31 = value1->m31 * first + value2->m31 * amount;
result->m32 = value1->m32 * first + value2->m32 * amount;
result->m33 = value1->m33 * first + value2->m33 * amount;
result->m34 = value1->m34 * first + value2->m34 * amount;
result->m41 = value1->m41 * first + value2->m41 * amount;
result->m42 = value1->m42 * first + value2->m42 * amount;
result->m43 = value1->m43 * first + value2->m43 * amount;
result->m44 = value1->m44 * first + value2->m44 * amount;
} }

View File

@ -91,7 +91,7 @@ static MediaPlayer *instance;
@synthesize volume; @synthesize volume;
- (void) setVolume:(float)value { - (void) setVolume:(float)value {
volume = value; volume = MAX(0, MIN(1, value));
if (!isMuted) { if (!isMuted) {
queue.activeSong.audioPlayer.volume = volume; queue.activeSong.audioPlayer.volume = volume;
@ -160,8 +160,14 @@ static MediaPlayer *instance;
if (![self checkAvailability]) { if (![self checkAvailability]) {
return; return;
} }
if (queue.activeSong) {
[queue.activeSong.audioPlayer stop];
}
song.audioPlayer.currentTime = 0;
song.audioPlayer.delegate = self; song.audioPlayer.delegate = self;
[queue setSong:song]; [queue setSong:song];
[self fillSongIndices]; [self fillSongIndices];
[self moveNext]; [self moveNext];
@ -221,9 +227,10 @@ static MediaPlayer *instance;
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag { - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
if ([remainingSongIndices count] == 0 && !isRepeating) { if ([remainingSongIndices count] == 0 && !isRepeating) {
// The music stops, activate the ambient category again. // The music stops, activate the ambient category again.
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error:nil]; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error:nil];
soloModeActivated = NO; soloModeActivated = NO;
return; [self setMediaState:MediaStateStopped];
return;
} }
[self moveNext]; [self moveNext];

View File

@ -13,4 +13,12 @@ static inline PointStruct PointMake(int x, int y) {
static inline void PointSet(PointStruct *point, int x, int y) { static inline void PointSet(PointStruct *point, int x, int y) {
point->x = x; point->x = x;
point->y = y; point->y = y;
} }
static inline void PointAdd(PointStruct *value1, PointStruct *value2, PointStruct *result) {
PointSet(result, value1->x + value2->x, value1->y + value2->y);
}
static inline void PointSubtract(PointStruct *value1, PointStruct *value2, PointStruct *result) {
PointSet(result, value1->x - value2->x, value1->y - value2->y);
}

View File

@ -28,8 +28,14 @@
@property (nonatomic) int y; @property (nonatomic) int y;
@property (nonatomic, readonly) PointStruct *data; @property (nonatomic, readonly) PointStruct *data;
+ (XniPoint*) add:(XniPoint*)value1 to:(XniPoint*)value2;
+ (XniPoint*) subtract:(XniPoint*)value1 by:(XniPoint*)value2;
- (XniPoint*) set:(XniPoint*)value; - (XniPoint*) set:(XniPoint*)value;
- (XniPoint*) add:(XniPoint*)value;
- (XniPoint*) subtract:(XniPoint*)value;
- (BOOL) equals:(XniPoint*)point; - (BOOL) equals:(XniPoint*)point;
+ (XniPoint*) zero; + (XniPoint*) zero;

View File

@ -59,11 +59,33 @@
// METHODS // METHODS
+ (XniPoint *)add:(XniPoint *)value1 to:(XniPoint *)value2 {
PointStruct resultData;
PointAdd(value1.data, value2.data, &resultData);
return [XniPoint pointWithStruct:&resultData];
}
+ (XniPoint *)subtract:(XniPoint *)value1 by:(XniPoint *)value2 {
PointStruct resultData;
PointSubtract(value1.data, value2.data, &resultData);
return [XniPoint pointWithStruct:&resultData];
}
- (XniPoint*) set:(XniPoint*)value { - (XniPoint*) set:(XniPoint*)value {
data = *value.data; data = *value.data;
return self; return self;
} }
- (XniPoint *)add:(XniPoint *)value {
PointAdd(&data, value.data, &data);
return self;
}
- (XniPoint *)subtract:(XniPoint *)value {
PointSubtract(&data, value.data, &data);
return self;
}
- (id) copyWithZone:(NSZone *)zone { - (id) copyWithZone:(NSZone *)zone {
return [[XniPoint allocWithZone:zone] initWithPointStruct:&data]; return [[XniPoint allocWithZone:zone] initWithPointStruct:&data];
} }

View File

@ -17,6 +17,7 @@
} }
- (id) initWithItemSize:(int)theItemSize initialCapacity:(int)theCapacity; - (id) initWithItemSize:(int)theItemSize initialCapacity:(int)theCapacity;
- (id) initWithArray:(XniAdaptiveArray*)source;
@property (nonatomic, readonly) int itemSize; @property (nonatomic, readonly) int itemSize;
@property (nonatomic, readonly) void *array; @property (nonatomic, readonly) void *array;
@ -24,5 +25,6 @@
- (void) addItem:(void*)item; - (void) addItem:(void*)item;
- (void) clear; - (void) clear;
- (void*) removeLastItem;
@end @end

View File

@ -19,6 +19,17 @@
return self; return self;
} }
- (id) initWithArray:(XniAdaptiveArray*)source {
if (self = [super init]) {
itemSize = source.itemSize;
capacity = source.count;
count = source.count;
array = malloc(capacity * itemSize);
memcpy(array, source.array, capacity * itemSize);
}
return self;
}
@synthesize itemSize; @synthesize itemSize;
@synthesize array; @synthesize array;
@synthesize count; @synthesize count;
@ -40,6 +51,11 @@
count = 0; count = 0;
} }
- (void*)removeLastItem {
count--;
return array + count * itemSize;
}
- (void) dealloc - (void) dealloc
{ {
free(array); free(array);

View File

@ -2664,7 +2664,6 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
DSTROOT = /tmp/XNI.dst; DSTROOT = /tmp/XNI.dst;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
@ -2684,7 +2683,6 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
DSTROOT = /tmp/XNI.dst; DSTROOT = /tmp/XNI.dst;
GCC_MODEL_TUNING = G5; GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;
@ -2700,7 +2698,10 @@
1DEB922308733DC00010E9CD /* Debug */ = { 1DEB922308733DC00010E9CD /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)"; ARCHS = (
armv7,
armv6,
);
GCC_C_LANGUAGE_STANDARD = c99; GCC_C_LANGUAGE_STANDARD = c99;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = ""; GCC_PREPROCESSOR_DEFINITIONS = "";
@ -2716,7 +2717,10 @@
1DEB922408733DC00010E9CD /* Release */ = { 1DEB922408733DC00010E9CD /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)"; ARCHS = (
armv7,
armv6,
);
GCC_C_LANGUAGE_STANDARD = c99; GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
@ -2731,7 +2735,6 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
DSTROOT = /tmp/XNI.dst; DSTROOT = /tmp/XNI.dst;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
@ -2751,7 +2754,6 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
DSTROOT = /tmp/XNI.dst; DSTROOT = /tmp/XNI.dst;
GCC_MODEL_TUNING = G5; GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES;