From 91c5d9b12cc1eea9ee728c8641a8c8d6b0f17aad Mon Sep 17 00:00:00 2001 From: dsc Date: Mon, 6 Jun 2011 01:38:55 -0700 Subject: [PATCH] Minor reorg of unit crap. --- src/Tanks.h | 7 +- src/TanksMacros.h | 2 +- src/game/QQGame.h | 16 ++- src/game/QQGame.mm | 98 +++++++-------- src/game/QQThing.h | 2 +- src/game/actor/QQActor.h | 50 -------- src/game/actor/QQActor.mm | 152 ---------------------- src/game/actor/QQActorDelegate.h | 6 - src/game/actor/QQActors.h | 5 - src/game/actor/QQIUnit.h | 16 --- src/game/actor/QQUnit.h | 32 ----- src/game/actor/QQUnit.mm | 101 --------------- src/game/actor/bullet/QQBullet.h | 14 -- src/game/actor/bullet/QQBullet.mm | 48 ------- src/game/actor/unit/QQTank.h | 10 -- src/game/actor/unit/QQTank.mm | 66 ---------- src/game/unit/QQActor.h | 50 ++++++++ src/game/unit/QQActor.mm | 153 ++++++++++++++++++++++ src/game/unit/QQActorDelegate.h | 6 + src/game/unit/QQActors.h | 5 + src/game/unit/QQBullet.h | 14 ++ src/game/unit/QQBullet.mm | 48 +++++++ src/game/unit/QQTank.h | 10 ++ src/game/unit/QQTank.mm | 66 ++++++++++ src/game/unit/QQUnit.h | 32 +++++ src/game/unit/QQUnit.mm | 101 +++++++++++++++ src/physics/QQWorld.h | 4 +- src/physics/event/QQContactNotification.h | 14 ++- src/physics/event/QQPhysicalEvents.mm | 2 +- src/qq/QQNotification.h | 21 --- src/qq/QQNotification.mm | 67 ---------- src/qq/QQNotificationCenter.h | 16 --- src/qq/QQNotificationCenter.mm | 69 ---------- src/qq/QQNotificationProxy.h | 16 --- src/qq/QQNotificationProxy.mm | 70 ---------- src/qq/QQNotifier.h | 29 ----- src/qq/QQNotifiers.h | 42 ------ src/qq/QQObservable.h | 24 ---- src/qq/event/QQNotification.h | 21 +++ src/qq/event/QQNotification.mm | 67 ++++++++++ src/qq/event/QQNotificationCenter.h | 16 +++ src/qq/event/QQNotificationCenter.mm | 69 ++++++++++ src/qq/event/QQNotificationProxy.h | 16 +++ src/qq/event/QQNotificationProxy.mm | 70 ++++++++++ src/qq/event/QQNotifier.h | 29 +++++ src/qq/event/QQNotifiers.h | 46 +++++++ src/qq/event/QQObservable.h | 24 ++++ tanks.xcodeproj/project.pbxproj | 196 ++++++++++++++-------------- 48 files changed, 1013 insertions(+), 1025 deletions(-) delete mode 100644 src/game/ability/QQStat.h delete mode 100644 src/game/ability/QQStat.mm create mode 100644 src/game/ability/QQStats.h create mode 100644 src/game/ability/QQStats.mm delete mode 100644 src/game/actor/QQActor.h delete mode 100644 src/game/actor/QQActor.mm delete mode 100644 src/game/actor/QQActorDelegate.h delete mode 100644 src/game/actor/QQActors.h delete mode 100644 src/game/actor/QQIUnit.h delete mode 100644 src/game/actor/QQUnit.h delete mode 100644 src/game/actor/QQUnit.mm delete mode 100644 src/game/actor/bullet/QQBullet.h delete mode 100644 src/game/actor/bullet/QQBullet.mm delete mode 100644 src/game/actor/unit/QQTank.h delete mode 100644 src/game/actor/unit/QQTank.mm create mode 100644 src/game/unit/QQActor.h create mode 100644 src/game/unit/QQActor.mm create mode 100644 src/game/unit/QQActorDelegate.h create mode 100644 src/game/unit/QQActors.h create mode 100644 src/game/unit/QQBullet.h create mode 100644 src/game/unit/QQBullet.mm create mode 100644 src/game/unit/QQTank.h create mode 100644 src/game/unit/QQTank.mm create mode 100644 src/game/unit/QQUnit.h create mode 100644 src/game/unit/QQUnit.mm delete mode 100644 src/qq/QQNotification.h delete mode 100644 src/qq/QQNotification.mm delete mode 100644 src/qq/QQNotificationCenter.h delete mode 100644 src/qq/QQNotificationCenter.mm delete mode 100644 src/qq/QQNotificationProxy.h delete mode 100644 src/qq/QQNotificationProxy.mm delete mode 100644 src/qq/QQNotifier.h delete mode 100644 src/qq/QQNotifiers.h delete mode 100644 src/qq/QQObservable.h create mode 100644 src/qq/event/QQNotification.h create mode 100644 src/qq/event/QQNotification.mm create mode 100644 src/qq/event/QQNotificationCenter.h create mode 100644 src/qq/event/QQNotificationCenter.mm create mode 100644 src/qq/event/QQNotificationProxy.h create mode 100644 src/qq/event/QQNotificationProxy.mm create mode 100644 src/qq/event/QQNotifier.h create mode 100644 src/qq/event/QQNotifiers.h create mode 100644 src/qq/event/QQObservable.h diff --git a/src/Tanks.h b/src/Tanks.h index 6a4d3c0..a2a448b 100644 --- a/src/Tanks.h +++ b/src/Tanks.h @@ -1,9 +1,14 @@ #ifndef TANKS_H #define TANKS_H +#ifdef DEBUG +#define TANKS_DEBUG_LOG 1 +#else #define TANKS_DEBUG_LOG 0 +#endif // DEBUG -#endif +#endif // TANKS_H #import "TanksMacros.h" +#import "qq/NSSet+QQExtensions.h" #import "render/QQSparrowExtensions.h" diff --git a/src/TanksMacros.h b/src/TanksMacros.h index e85b6b2..b36a57c 100644 --- a/src/TanksMacros.h +++ b/src/TanksMacros.h @@ -1,7 +1,7 @@ #ifndef TANKS_MACROS_H #define TANKS_MACROS_H -#define qqBoolToString(__val) ((__val)?("YES"):("NO")) +#define b2s(__val) ((__val)?("YES"):("NO")) #endif \ No newline at end of file diff --git a/src/game/QQGame.h b/src/game/QQGame.h index 1c5e0a4..f69644d 100644 --- a/src/game/QQGame.h +++ b/src/game/QQGame.h @@ -1,19 +1,21 @@ #import "Sparrow.h" -#import "qq/QQNotificationCenter.h" +#import "qq/event/QQNotificationCenter.h" + #import "physics/QQWorld.h" #import "physics/debug/QQPhysicsDebugView.h" + #import "game/QQGameTime.h" -#import "game/actor/QQActor.h" +#import "game/unit/QQActor.h" #import "game/map/QQLevel.h" + @interface QQGame : QQNotificationCenter { @private float _now; float _elapsed; long _ticks; - long _realtime; BOOL _running; BOOL _debugDrawingEnabled; @@ -48,14 +50,16 @@ @property (nonatomic, readonly, retain) NSSet* actors; -- (void) tick; +- (void) tick:(float)elapsed; +/** Alerts the game to a new actor. */ - (QQGame*) addActor:(QQActor*)actor; -// - (QQGame*) addActorAndShape:(QQActor*)actor; - (QQGame*) removeActor:(QQActor*)actor; -- (QQGame*) destroyActor:(QQActor*)actor; +/** Starts/unpauses the game. */ - (void) start; + +/** Pauses the game. */ - (void) stop; diff --git a/src/game/QQGame.mm b/src/game/QQGame.mm index 1a06899..ad60683 100644 --- a/src/game/QQGame.mm +++ b/src/game/QQGame.mm @@ -1,16 +1,11 @@ #import #import "Tanks.h" -#import "qq/NSSet+QQExtensions.h" #import "game/QQGame.h" -#import "game/actor/QQActors.h" +#import "game/unit/QQActors.h" #import "physics/event/QQContactNotification.h" -static QQGame* _CurrentGame = NULL; - - - @interface QQGame () @property (nonatomic, readwrite, retain) NSSet* actors; @@ -19,8 +14,17 @@ static QQGame* _CurrentGame = NULL; @end +static QQGame* _CurrentGame = NULL; + @implementation QQGame ++ (QQGame*) current { + if (!_CurrentGame) + [[[QQGame alloc] init] // init assigns to singleton, but singleton is a weakref, + autorelease]; // XXX: so game will still be released if not retained + return _CurrentGame; +} + - (id) init { if (_CurrentGame) { [self release]; @@ -32,6 +36,8 @@ static QQGame* _CurrentGame = NULL; } if ( (self = [super init]) ){ + // We set the singleton here, in init, in case someone referenced during initialization + // asks for the current game (causing a loop). _CurrentGame = self; _now = 0; _ticks = 0; @@ -64,7 +70,9 @@ static QQGame* _CurrentGame = NULL; [[[QQTank alloc] initAtX:wMax/6 y:hMax/6 width:50 height:50 color:0xFF0071] autorelease]; [[[QQUnit alloc] initAtX:wMax/3 y:hMax/2 width:50 height:50 color:0x4596FF] autorelease]; +#if TANKS_DEBUG_LOG [_stage addEventListener:@selector(logEvent:) atObject:self forType:SP_EVENT_TYPE_ANY]; +#endif } return self; } @@ -117,7 +125,22 @@ static QQGame* _CurrentGame = NULL; /// methods +- (void) tick:(float)elapsed { + if (!self.isPaused) return; + _ticks++; + _elapsed = elapsed; + _now += elapsed; + + for (QQActor* actor in self.actors) + [actor tick]; + [self.world step]; + for (QQActor* actor in self.actors) + [actor draw]; +} + - (QQGame*) addActor:(QQActor*)actor { + // Create a new copy of the mutated set on change to avoid the need to copy + // on every iteration, which happens WAAAY more often self.actors = [self.actors setByAddingObject:actor]; // if (actor.isActive) // _awake = [_awake setByAddingObject:actor]; @@ -129,6 +152,8 @@ static QQGame* _CurrentGame = NULL; } - (QQGame*) removeActor:(QQActor*)actor { + // Create a new copy of the mutated set on change to avoid the need to copy + // on every iteration, which happens WAAAY more often self.actors = [self.actors setByRemovingObject:actor]; // if (actor.isActive) // _awake = [_awake setByRemovingObject:actor]; @@ -136,58 +161,27 @@ static QQGame* _CurrentGame = NULL; // _units = [_units setByRemovingObject:actor]; // if ([actor isKindOfClass:[QQBullet class]]) // _bullets = [_bullets setByRemovingObject:actor]; - return self; -} - -- (QQGame*) destroyActor:(QQActor*)actor { [_world destroy:actor]; - return [self removeActor:actor]; -} - - -- (void) tick { -#if TANKS_DEBUG_LOG - if ((_ticks % 100) == 0) { - NSLog(@"[%ld] Time passed since last 100 frames: %f", _ticks, _elapsed); - for (QQActor* actor in self.actors) { - b2Vec2 v = actor.body->GetLinearVelocity(); - NSLog(@"[%@ impulse:(%f,%f)]", actor, v.x,v.y); - } - } -#endif - - for (QQActor* actor in self.actors) - [actor tick]; - [self.world step]; - for (QQActor* actor in self.actors) - if (!actor.dead) [actor draw]; + return self; } - - (void) start { - if (!_running) { - _running = YES; - [_stage addEventListener:@selector(onEnterFrame:) atObject:self forType:SP_EVENT_TYPE_ENTER_FRAME]; - } + if (_running) return; + _running = YES; + [_stage addEventListener:@selector(onEnterFrame:) atObject:self forType:SP_EVENT_TYPE_ENTER_FRAME]; } - (void) stop { - if (_running) { - [_stage removeEventListener:@selector(onEnterFrame:) atObject:self forType:SP_EVENT_TYPE_ENTER_FRAME]; - _running = NO; - } + if (!_running) return; + [_stage removeEventListener:@selector(onEnterFrame:) atObject:self forType:SP_EVENT_TYPE_ENTER_FRAME]; + _running = NO; } /// event handlers - (void) onEnterFrame:(SPEnterFrameEvent*)event { - if (_running) { - _ticks++; - _elapsed = event.passedTime; - _now += _elapsed; - [self tick]; - } + [self tick:event.passedTime]; } - (void) onCollide:(QQContactNotification*)msg { @@ -195,23 +189,17 @@ static QQGame* _CurrentGame = NULL; } - (void) logEvent:(SPEvent*)evt { + // ignore enter-frame events, as they happen constantly if ([evt.type isEqualToString:SP_EVENT_TYPE_ENTER_FRAME]) return; NSLog(@"%@", evt); } + - (NSString*) description { - return [NSString stringWithFormat:@"<%@: %x> {running=%s, #actors=%i, time={now=%f, elapsed=%f, ticks=%l}}", - [self class], (long)self, qqBoolToString(self.isPaused), [self.actors count], + return [NSString stringWithFormat:@"<%@: %p> {running=%s, #actors=%i, time={now=%f, elapsed=%f, ticks=%l}}", + [self class], (long)self, b2s(self.isPaused), [self.actors count], self.now, self.elapsed, self.ticks]; } -+ (QQGame*) current { - if (!_CurrentGame) - [[[QQGame alloc] init] // init assigns to singleton, but singleton is a weakref, - autorelease]; // XXX: so game will still be released if not retained... - return _CurrentGame; -} - - @end \ No newline at end of file diff --git a/src/game/QQThing.h b/src/game/QQThing.h index e10aa65..8ee089f 100644 --- a/src/game/QQThing.h +++ b/src/game/QQThing.h @@ -1,4 +1,4 @@ -#import "qq/QQObservable.h" +#import "qq/event/QQObservable.h" @class QQGame; @class QQWorld; diff --git a/src/game/ability/QQStat.h b/src/game/ability/QQStat.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/game/ability/QQStat.mm b/src/game/ability/QQStat.mm deleted file mode 100644 index e69de29..0000000 diff --git a/src/game/ability/QQStats.h b/src/game/ability/QQStats.h new file mode 100644 index 0000000..e69de29 diff --git a/src/game/ability/QQStats.mm b/src/game/ability/QQStats.mm new file mode 100644 index 0000000..e69de29 diff --git a/src/game/actor/QQActor.h b/src/game/actor/QQActor.h deleted file mode 100644 index 4eaaf09..0000000 --- a/src/game/actor/QQActor.h +++ /dev/null @@ -1,50 +0,0 @@ -#include - -#import "qq/QQNotificationProxy.h" -#import "game/QQThing.h" -#import "game/QQActive.h" -#import "game/QQPhysical.h" -#import "game/QQDisplayable.h" -#import "game/actor/QQActorDelegate.h" -#import "physics/QQWorld.h" - -@class QQGame; - - -@interface QQActor : QQNotificationProxy { - -@protected - b2Body* _body; - -@private - BOOL _active; - BOOL _dirty; - BOOL _dead; - id _delegate; - NSArray* _cooldowns; -} - -@property (nonatomic, readonly) QQGame* game; -@property (nonatomic, readonly) QQWorld* world; -@property (nonatomic, readwrite, retain) id delegate; -@property (nonatomic, readonly) BOOL dead; - -- (id) initAtX:(float)x y:(float)y; -- (id) initType:(b2BodyType)type atX:(float)x y:(float)y; - -- (void) destroy; - - -/// internal methods - -/** Updates the Shape using values from Box2D. */ -- (void) updateShape; - -/** Updates the Shape's position, pulling rotation from Box2D. */ -- (void) updateShapeX:(float)x y:(float)y; - -/** Updates the Shape's position and rotation. */ -- (void) updateShapeX:(float)x y:(float)y rotation:(float)r; - - -@end diff --git a/src/game/actor/QQActor.mm b/src/game/actor/QQActor.mm deleted file mode 100644 index 241226b..0000000 --- a/src/game/actor/QQActor.mm +++ /dev/null @@ -1,152 +0,0 @@ -#import "QQActor.h" -#import "render/QQSparrowExtensions.h" -#import "game/QQGame.h" - - -@implementation QQActor - -/// properties - -@dynamic shape; - -@synthesize active = _active; -@synthesize dirty = _dirty; -@synthesize dead = _dead; -@synthesize delegate = _delegate; -@synthesize cooldowns = _cooldowns; - - -- (QQGame*) game { return QQGame.current; } -- (QQWorld*) world { return self.game.world; } - -- (b2Body*) body { return _body; } -- (b2Fixture*) fixture { return nil; } - -- (id) implicitNotificationSender { return self; } -- (void) setImplicitNotificationSender:(id)sender {} - -- (id) proxiedNotifier { return self.game; } -- (void) setProxiedNotifier:(id)notifier {} - - -- (float) x { return self.body->GetPosition().x; } -- (void) setX:(float)x { [self setPositionX:x y:self.y]; } - -- (float) y { return self.body->GetPosition().y; } -- (void) setY:(float)y { [self setPositionX:self.x y:y]; } - -- (CGPoint) position { - b2Vec2 pos = self.body->GetPosition(); - return CGPointMake(pos.x, pos.y); -} -- (void) setPosition:(CGPoint)pos { - [self setPositionX:pos.x y:pos.y]; -} -- (void) setPositionX:(float)x y:(float)y { - self.body->SetTransform(b2Vec2(x,y), self.body->GetAngle()); -} - -- (float) rotation { return self.body->GetAngle(); } -- (void) setRotation:(float)r { self.body->SetTransform(self.body->GetPosition(), r); } - - -- (void) updateShapeX:(float)x y:(float)y { - float px = self.world.scale; - [self.shape setCenterX:x*px y:y*px]; -} - -- (void) updateShapeX:(float)x y:(float)y rotation:(float)r { - [self updateShapeX:x y:y]; - self.shape.rotation = r; -} - -- (void) updateShape { - b2Transform trans = self.body->GetTransform(); - [self updateShapeX:trans.position.x y:trans.position.y rotation:trans.GetAngle()]; -} - - - -/// initializers - -- (id) initAtX:(float)x y:(float)y { - return [self initType:b2_dynamicBody atX:x y:y]; -} - -- (id) initType:(b2BodyType)type atX:(float)x y:(float)y { - if ((self = [super init])) { - _active = YES; - _dead = NO; - self.proxiedNotifier = self.game; - self.cooldowns = [NSArray array]; - [self.game addActor:self]; - - b2BodyDef bd; - bd.type = type; - bd.position = b2Vec2(x, y); - bd.userData = self; - _body = self.world.world->CreateBody(&bd); - - if ([self respondsToSelector:@selector(onCollideBegin:)]) - [self addObserver:self selector:@selector(onCollideBegin:) name:QQ_EVENT_CONTACT_BEGIN]; - } - return self; -} - -- (void) dealloc { - self.delegate = nil; - [_cooldowns release]; - [super dealloc]; -} - - - -/// methods - -- (void) destroy { - NSLog(@"retainCount=%i", [self retainCount]); - if (!self.dead) { - _dead = YES; - self.shape = nil; - [self.game destroyActor:self]; - NSLog(@"%@ \v\tretainCount=%i \v\tgame=%@", self, [self retainCount], self.game); - } -} - -- (void) tick { - if (!self.dead) { - [self.cooldowns makeObjectsPerformSelector:@selector(tick:)withObject:self.game.time]; - if (self.isActive) [self act]; - } -} - -- (void) act {} - -- (SPDisplayObject*) setupShape { - return self.shape; -} - -- (void) draw { - [self updateShape]; -} - -- (void) setupPhysics {} - - -- (void) applyLinearImpulseX:(float)xNs y:(float)yNs { - self.body->ApplyLinearImpulse(b2Vec2(xNs, yNs), self.body->GetPosition()); -} - - -- (NSString*) description { - b2Transform trans = self.body->GetTransform(); - b2Vec2 pos = trans.position; - //b2Vec2 v = actor.body->GetLinearVelocity(); - SPDisplayObject* s = self.shape; - return [NSString stringWithFormat:@"[%@ box2d=[ (%f,%f) rotation=%f], shape=%@]", - [super description], pos.x,pos.y, trans.GetAngle(), s]; -} - - - -@end diff --git a/src/game/actor/QQActorDelegate.h b/src/game/actor/QQActorDelegate.h deleted file mode 100644 index bae4a18..0000000 --- a/src/game/actor/QQActorDelegate.h +++ /dev/null @@ -1,6 +0,0 @@ - -@protocol QQActorDelegate - -- (void) updateWithTick:(float)time; - -@end diff --git a/src/game/actor/QQActors.h b/src/game/actor/QQActors.h deleted file mode 100644 index f7bad80..0000000 --- a/src/game/actor/QQActors.h +++ /dev/null @@ -1,5 +0,0 @@ -#import "game/actor/QQActor.h" -#import "game/actor/QQActorDelegate.h" -#import "game/actor/QQUnit.h" -#import "game/actor/bullet/QQBullet.h" -#import "game/actor/unit/QQTank.h" diff --git a/src/game/actor/QQIUnit.h b/src/game/actor/QQIUnit.h deleted file mode 100644 index 15878ea..0000000 --- a/src/game/actor/QQIUnit.h +++ /dev/null @@ -1,16 +0,0 @@ -#import "game/actor/QQActor.h" -#import "game/QQThing.h" - - -@protocol QQUnit - -@property (nonatomic, readonly) BOOL canAttack; - -- (void) attackTarget:(QQActor*)actor; -- (void) attackToward:(CGPoint)point; -- (void) attackTowardX:(float)x y:(float)y; - - -@end - -//typedef id QQUnit; diff --git a/src/game/actor/QQUnit.h b/src/game/actor/QQUnit.h deleted file mode 100644 index e963b45..0000000 --- a/src/game/actor/QQUnit.h +++ /dev/null @@ -1,32 +0,0 @@ -#include -#import "Sparrow.h" - -#import "physics/QQWorld.h" -#import "game/actor/QQActor.h" -#import "game/actor/QQActorDelegate.h" -#import "render/QQSparrowExtensions.h" - - -@interface QQUnit : QQActor { - -@private - SPDisplayObject* _shape; -} - -/// properties -@property (nonatomic, readonly) BOOL canAttack; -- (void) setShapeFromFile:(NSString*)filename; - -/// initializers -- (id) initAtX:(float)x y:(float)y width:(float)w height:(float)h color:(uint)color; -- (id) initAtX:(float)x y:(float)y withShape:(SPDisplayObject*)shape; - - -/// methods - -- (void) attack:(QQActor*)actor; -- (void) attackToward:(CGPoint)point; -- (void) attackTowardX:(float)x y:(float)y; - - -@end diff --git a/src/game/actor/QQUnit.mm b/src/game/actor/QQUnit.mm deleted file mode 100644 index f68c5fc..0000000 --- a/src/game/actor/QQUnit.mm +++ /dev/null @@ -1,101 +0,0 @@ -#include -#import "Sparrow.h" - -#import "game/actor/QQUnit.h" -#import "game/QQGame.h" -#import "render/QQSparrowExtensions.h" - - - - -@implementation QQUnit - -@dynamic world; // Eliminates compiler warnings due to inheritance (!) -@dynamic game; - -@synthesize shape = _shape; - -- (float) shapeCenterX { return self.shape.registrationX; } -- (void) setShapeCenterX:(float)x { self.shape.registrationX = x; } -- (float) shapeCenterY { return self.shape.registrationY; } -- (void) setShapeCenterY:(float)y { self.shape.registrationY = y; } - -- (BOOL) canAttack { return NO; } - - -/// initializers - -- (id) init { - return [self initAtX:50 y:50 width:50 height:50 color:0xff0071]; -} - -- (id) initAtX:(float)x y:(float)y width:(float)w height:(float)h color:(uint)color { - SPQuad* shape = [SPQuad quadWithWidth:w height:h color:color]; - return [self initAtX:x y:y withShape:shape]; -} - -- (id) initAtX:(float)x y:(float)y withShape:(SPDisplayObject*)shape { - if ((self = [super initAtX:x y:y])) { - self.shape = shape; - - float dblpx = 2*self.world.scale; - b2PolygonShape box; - box.SetAsBox(shape.width/dblpx, shape.height/dblpx); - b2FixtureDef fix; - fix.shape = &box; - fix.density = 1.0f; - fix.userData = self; - self.body->CreateFixture(&fix); - } - return self; -} - -- (void) dealloc { - [self.game.level removeChild:_shape]; - [_shape release]; - [super dealloc]; -} - -/// methods - -- (void) setShape:(SPDisplayObject*)newShape { - if (_shape != newShape) { - [self.game.level removeChild:_shape]; - [_shape release]; - - _shape = [newShape retain]; - if (_shape) { - [self updateShape]; - [self.game.level addChild:_shape]; - } - } -} - -- (void) setShapeFromFile:(NSString*)filename { - [self setShape:[[[SPImage alloc] autorelease] initWithContentsOfFile:filename]]; -} - -- (void) act { - if ((self.game.ticks % 50) == 0) { - self.rotation += b2_pi / 8; - } -} - -- (void) draw { - [super draw]; -} - - -- (void) attack:(QQActor*)actor { - [self attackTowardX:actor.x y:actor.y]; -} -- (void) attackToward:(CGPoint)pt { - [self attackTowardX:pt.x y:pt.y]; -} -- (void) attackTowardX:(float)x y:(float)y { - -} - - - -@end diff --git a/src/game/actor/bullet/QQBullet.h b/src/game/actor/bullet/QQBullet.h deleted file mode 100644 index 4a61675..0000000 --- a/src/game/actor/bullet/QQBullet.h +++ /dev/null @@ -1,14 +0,0 @@ -#import "game/actor/QQUnit.h" - - -@interface QQBullet : QQUnit { -@private - QQUnit* _owner; -} - -@property (nonatomic, readonly) QQUnit* owner; - -- (id) init:(QQUnit*)owner x:(float)x y:(float)y; - - -@end diff --git a/src/game/actor/bullet/QQBullet.mm b/src/game/actor/bullet/QQBullet.mm deleted file mode 100644 index 99b3f42..0000000 --- a/src/game/actor/bullet/QQBullet.mm +++ /dev/null @@ -1,48 +0,0 @@ -#include -#import "SparrowExtras.h" - -#import "QQBullet.h" -#import "physics/event/QQContactNotification.h" - - - -@implementation QQBullet - -@synthesize owner = _owner; - -- (id) init:(QQUnit*)owner x:(float)x y:(float)y { - if ((self = [super initAtX:x y:y])){ - _owner = owner; - - float px = self.world.scale; - float radius = 1.5f; - self.shape = [SHCircle circleWithWidth:2*radius*px height:2*radius*px]; - - b2CircleShape circle; - circle.m_radius = radius; - b2FixtureDef fix; - fix.shape = &circle; - fix.restitution = 1.0f; - fix.density = 0.1f; - fix.userData = self; - self.body->CreateFixture(&fix); - } - return self; -} - -- (void) onCollideBegin:(QQContactNotification*)msg { - QQActor* other = (msg.actorA && (msg.actorA != self) ? msg.actorA : - (msg.actorB && (msg.actorB != self) ? msg.actorB : nil)); - if (other) { - NSLog(@"BOOM! %@", msg); - [other destroy]; - [self destroy]; - } -} - -- (void) dealloc { - [super dealloc]; -} - - -@end diff --git a/src/game/actor/unit/QQTank.h b/src/game/actor/unit/QQTank.h deleted file mode 100644 index ee8c4c1..0000000 --- a/src/game/actor/unit/QQTank.h +++ /dev/null @@ -1,10 +0,0 @@ -#import "game/actor/QQUnit.h" -#import "game/ability/QQCooldown.h" - -@interface QQTank : QQUnit { - QQCooldown* _coolAtk; -} - -@property (nonatomic, readonly, retain) QQCooldown* coolAtk; - -@end diff --git a/src/game/actor/unit/QQTank.mm b/src/game/actor/unit/QQTank.mm deleted file mode 100644 index 4b2622b..0000000 --- a/src/game/actor/unit/QQTank.mm +++ /dev/null @@ -1,66 +0,0 @@ -#import "QQTank.h" -#import "render/QQSparrowExtensions.h" -#import "game/QQGame.h" -#import "game/actor/bullet/QQBullet.h" - - -// private interface -@interface QQTank () -@property (nonatomic, readwrite, retain) QQCooldown* coolAtk; -- (void) onTouch:(SPTouchEvent*)event; -@end - - - -@implementation QQTank - -@synthesize coolAtk = _coolAtk; - -- (id) initAtX:(float)x y:(float)y withShape:(SPDisplayObject*)shape { - if ((self = [super initAtX:x y:y withShape:shape])){ - self.coolAtk = [QQCooldown cooldownWithDuration:0.5f]; - self.cooldowns = [self.cooldowns arrayByAddingObject:self.coolAtk]; - [self.game.stage addEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH]; - } - return self; -} - -- (void) dealloc { - [self.game.stage removeEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH]; - [_coolAtk release]; - [super dealloc]; -} - - -- (void) onTouch:(SPTouchEvent*)event { - SPTouch* touch = [[event touchesWithTarget:(SPDisplayObject*)self.game.stage] anyObject]; - if (touch && [self.coolAtk activate]) { - // Touch's normal vector in local coords (rel unit origin) - SPPoint* normVec = [[[touch locationInSpace:self.shape.parent] subtractPoint:self.shape.position] normalize]; - - // Bullet starting position - float offset = 7.5f + fmaxf(self.shape.width, self.shape.height) * 1.41421356237f; // bullet_radius + tank_diagonal_length - SPPoint* start = [[self.shape.position addPoint:[normVec scaleBy:offset]] scaleBy:1.0f/self.world.scale]; - QQBullet* bullet = [[[QQBullet alloc] init:self x:start.x y:start.y] autorelease]; - - // Bullet impulse vector - SPPoint* imp = [normVec scaleBy:50]; - [bullet applyLinearImpulseX:imp.x y:imp.y]; - NSLog(@"[%@ pos:(%f,%f) impulse:(%f,%f)]", bullet, bullet.x,bullet.y, imp.x,imp.y); - } -} - -- (void) _moveOnTouch:(SPTouchEvent*)event { - SPTouch* touch = [[event touchesWithTarget:self.shape.parent] anyObject]; - if (touch) { - SPPoint* touchPosition = [touch locationInSpace:self.shape.parent]; - float x = self.shape.x = touchPosition.x - self.shape.width / 2.0f; - float y = self.shape.y = touchPosition.y - self.shape.height / 2.0f; - - float px = self.world.scale; - [self setPositionX:x/px y:y/px]; - // self.body->SetTransform(b2Vec2(x/px, y/px), self.body->GetAngle()); - } -} - -@end \ No newline at end of file diff --git a/src/game/unit/QQActor.h b/src/game/unit/QQActor.h new file mode 100644 index 0000000..b5dc695 --- /dev/null +++ b/src/game/unit/QQActor.h @@ -0,0 +1,50 @@ +#include + +#import "qq/event/QQNotificationProxy.h" +#import "game/QQThing.h" +#import "game/QQActive.h" +#import "game/QQPhysical.h" +#import "game/QQDisplayable.h" +#import "game/unit/QQActorDelegate.h" +#import "physics/QQWorld.h" + +@class QQGame; + + +@interface QQActor : QQNotificationProxy { + +@protected + b2Body* _body; + +@private + BOOL _active; + BOOL _dirty; + BOOL _dead; + id _delegate; + NSArray* _cooldowns; +} + +@property (nonatomic, readonly) QQGame* game; +@property (nonatomic, readonly) QQWorld* world; +@property (nonatomic, readwrite, retain) id delegate; +@property (nonatomic, readonly) BOOL dead; + +- (id) initAtX:(float)x y:(float)y; +- (id) initType:(b2BodyType)type atX:(float)x y:(float)y; + +- (void) destroy; + + +/// internal methods + +/** Updates the Shape using values from Box2D. */ +- (void) updateShape; + +/** Updates the Shape's position, pulling rotation from Box2D. */ +- (void) updateShapeX:(float)x y:(float)y; + +/** Updates the Shape's position and rotation. */ +- (void) updateShapeX:(float)x y:(float)y rotation:(float)r; + + +@end diff --git a/src/game/unit/QQActor.mm b/src/game/unit/QQActor.mm new file mode 100644 index 0000000..8421992 --- /dev/null +++ b/src/game/unit/QQActor.mm @@ -0,0 +1,153 @@ +#import "QQActor.h" +#import "render/QQSparrowExtensions.h" +#import "game/QQGame.h" + + +@implementation QQActor + +/// properties + +@dynamic shape; + +@synthesize active = _active; +@synthesize dirty = _dirty; +@synthesize dead = _dead; +@synthesize delegate = _delegate; +@synthesize cooldowns = _cooldowns; + + +- (QQGame*) game { return QQGame.current; } +- (QQWorld*) world { return self.game.world; } + +- (b2Body*) body { return _body; } +- (b2Fixture*) fixture { return nil; } + +- (id) implicitNotificationSender { return self; } +- (void) setImplicitNotificationSender:(id)sender {} + +- (id) proxiedNotifier { return self.game; } +- (void) setProxiedNotifier:(id)notifier {} + + +- (float) x { return self.body->GetPosition().x; } +- (void) setX:(float)x { [self setPositionX:x y:self.y]; } + +- (float) y { return self.body->GetPosition().y; } +- (void) setY:(float)y { [self setPositionX:self.x y:y]; } + +- (CGPoint) position { + b2Vec2 pos = self.body->GetPosition(); + return CGPointMake(pos.x, pos.y); +} +- (void) setPosition:(CGPoint)pos { + [self setPositionX:pos.x y:pos.y]; +} +- (void) setPositionX:(float)x y:(float)y { + self.body->SetTransform(b2Vec2(x,y), self.body->GetAngle()); +} + +- (float) rotation { return self.body->GetAngle(); } +- (void) setRotation:(float)r { self.body->SetTransform(self.body->GetPosition(), r); } + + +- (void) updateShapeX:(float)x y:(float)y { + float px = self.world.scale; + [self.shape setCenterX:x*px y:y*px]; +} + +- (void) updateShapeX:(float)x y:(float)y rotation:(float)r { + [self updateShapeX:x y:y]; + self.shape.rotation = r; +} + +- (void) updateShape { + b2Transform trans = self.body->GetTransform(); + [self updateShapeX:trans.position.x y:trans.position.y rotation:trans.GetAngle()]; +} + + + +/// initializers + +- (id) initAtX:(float)x y:(float)y { + return [self initType:b2_dynamicBody atX:x y:y]; +} + +- (id) initType:(b2BodyType)type atX:(float)x y:(float)y { + if ((self = [super init])) { + _active = YES; + _dead = NO; + self.proxiedNotifier = self.game; + self.cooldowns = [NSArray array]; + [self.game addActor:self]; + + b2BodyDef bd; + bd.type = type; + bd.position = b2Vec2(x, y); + bd.userData = self; + _body = self.world.world->CreateBody(&bd); + + if ([self respondsToSelector:@selector(onCollideBegin:)]) + [self addObserver:self selector:@selector(onCollideBegin:) name:QQ_EVENT_CONTACT_BEGIN]; + } + return self; +} + +- (void) dealloc { + self.delegate = nil; + [_cooldowns release]; + [super dealloc]; +} + + + +/// methods + +- (void) destroy { + if (self.dead) return; + + _dead = YES; + self.shape = nil; + [self.game removeActor:self]; +} + +- (void) tick { + if (self.dead) return; + + [self.cooldowns makeObjectsPerformSelector:@selector(tick:) withObject:self.game.time]; + if (self.isActive) + [self act]; +} + +- (void) act {} + +- (SPDisplayObject*) setupShape { + return self.shape; +} + +- (void) draw { + if (self.dead) return; + + [self updateShape]; +} + +- (void) setupPhysics {} + + +- (void) applyLinearImpulseX:(float)xNs y:(float)yNs { + self.body->ApplyLinearImpulse(b2Vec2(xNs, yNs), self.body->GetPosition()); +} + + +- (NSString*) description { + b2Transform trans = self.body->GetTransform(); + b2Vec2 pos = trans.position; + //b2Vec2 v = actor.body->GetLinearVelocity(); + SPDisplayObject* s = self.shape; + return [NSString stringWithFormat:@"[%@ box2d=[ (%f,%f) rotation=%f], shape=%@]", + [super description], pos.x,pos.y, trans.GetAngle(), s]; +} + + + +@end diff --git a/src/game/unit/QQActorDelegate.h b/src/game/unit/QQActorDelegate.h new file mode 100644 index 0000000..bae4a18 --- /dev/null +++ b/src/game/unit/QQActorDelegate.h @@ -0,0 +1,6 @@ + +@protocol QQActorDelegate + +- (void) updateWithTick:(float)time; + +@end diff --git a/src/game/unit/QQActors.h b/src/game/unit/QQActors.h new file mode 100644 index 0000000..1bb6ca8 --- /dev/null +++ b/src/game/unit/QQActors.h @@ -0,0 +1,5 @@ +#import "game/unit/QQActor.h" +#import "game/unit/QQActorDelegate.h" +#import "game/unit/QQUnit.h" +#import "game/unit/QQBullet.h" +#import "game/unit/QQTank.h" diff --git a/src/game/unit/QQBullet.h b/src/game/unit/QQBullet.h new file mode 100644 index 0000000..b4a6241 --- /dev/null +++ b/src/game/unit/QQBullet.h @@ -0,0 +1,14 @@ +#import "game/unit/QQUnit.h" + + +@interface QQBullet : QQUnit { +@private + QQUnit* _owner; +} + +@property (nonatomic, readonly) QQUnit* owner; + +- (id) init:(QQUnit*)owner x:(float)x y:(float)y; + + +@end diff --git a/src/game/unit/QQBullet.mm b/src/game/unit/QQBullet.mm new file mode 100644 index 0000000..99b3f42 --- /dev/null +++ b/src/game/unit/QQBullet.mm @@ -0,0 +1,48 @@ +#include +#import "SparrowExtras.h" + +#import "QQBullet.h" +#import "physics/event/QQContactNotification.h" + + + +@implementation QQBullet + +@synthesize owner = _owner; + +- (id) init:(QQUnit*)owner x:(float)x y:(float)y { + if ((self = [super initAtX:x y:y])){ + _owner = owner; + + float px = self.world.scale; + float radius = 1.5f; + self.shape = [SHCircle circleWithWidth:2*radius*px height:2*radius*px]; + + b2CircleShape circle; + circle.m_radius = radius; + b2FixtureDef fix; + fix.shape = &circle; + fix.restitution = 1.0f; + fix.density = 0.1f; + fix.userData = self; + self.body->CreateFixture(&fix); + } + return self; +} + +- (void) onCollideBegin:(QQContactNotification*)msg { + QQActor* other = (msg.actorA && (msg.actorA != self) ? msg.actorA : + (msg.actorB && (msg.actorB != self) ? msg.actorB : nil)); + if (other) { + NSLog(@"BOOM! %@", msg); + [other destroy]; + [self destroy]; + } +} + +- (void) dealloc { + [super dealloc]; +} + + +@end diff --git a/src/game/unit/QQTank.h b/src/game/unit/QQTank.h new file mode 100644 index 0000000..c4c5971 --- /dev/null +++ b/src/game/unit/QQTank.h @@ -0,0 +1,10 @@ +#import "game/unit/QQUnit.h" +#import "game/ability/QQCooldown.h" + +@interface QQTank : QQUnit { + QQCooldown* _coolAtk; +} + +@property (nonatomic, readonly, retain) QQCooldown* coolAtk; + +@end diff --git a/src/game/unit/QQTank.mm b/src/game/unit/QQTank.mm new file mode 100644 index 0000000..edd130a --- /dev/null +++ b/src/game/unit/QQTank.mm @@ -0,0 +1,66 @@ +#import "QQTank.h" +#import "render/QQSparrowExtensions.h" +#import "game/QQGame.h" +#import "game/unit/QQBullet.h" + + +// private interface +@interface QQTank () +@property (nonatomic, readwrite, retain) QQCooldown* coolAtk; +- (void) onTouch:(SPTouchEvent*)event; +@end + + + +@implementation QQTank + +@synthesize coolAtk = _coolAtk; + +- (id) initAtX:(float)x y:(float)y withShape:(SPDisplayObject*)shape { + if ((self = [super initAtX:x y:y withShape:shape])){ + self.coolAtk = [QQCooldown cooldownWithDuration:0.5f]; + self.cooldowns = [self.cooldowns arrayByAddingObject:self.coolAtk]; + [self.game.stage addEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH]; + } + return self; +} + +- (void) dealloc { + [self.game.stage removeEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH]; + [_coolAtk release]; + [super dealloc]; +} + + +- (void) onTouch:(SPTouchEvent*)event { + SPTouch* touch = [[event touchesWithTarget:(SPDisplayObject*)self.game.stage] anyObject]; + if (touch && [self.coolAtk activate]) { + // Touch's normal vector in local coords (rel unit origin) + SPPoint* normVec = [[[touch locationInSpace:self.shape.parent] subtractPoint:self.shape.position] normalize]; + + // Bullet starting position + float offset = 7.5f + fmaxf(self.shape.width, self.shape.height) * 1.41421356237f; // bullet_radius + tank_diagonal_length + SPPoint* start = [[self.shape.position addPoint:[normVec scaleBy:offset]] scaleBy:1.0f/self.world.scale]; + QQBullet* bullet = [[[QQBullet alloc] init:self x:start.x y:start.y] autorelease]; + + // Bullet impulse vector + SPPoint* imp = [normVec scaleBy:50]; + [bullet applyLinearImpulseX:imp.x y:imp.y]; + NSLog(@"[%@ pos:(%f,%f) impulse:(%f,%f)]", bullet, bullet.x,bullet.y, imp.x,imp.y); + } +} + +- (void) _moveOnTouch:(SPTouchEvent*)event { + SPTouch* touch = [[event touchesWithTarget:self.shape.parent] anyObject]; + if (touch) { + SPPoint* touchPosition = [touch locationInSpace:self.shape.parent]; + float x = self.shape.x = touchPosition.x - self.shape.width / 2.0f; + float y = self.shape.y = touchPosition.y - self.shape.height / 2.0f; + + float px = self.world.scale; + [self setPositionX:x/px y:y/px]; + // self.body->SetTransform(b2Vec2(x/px, y/px), self.body->GetAngle()); + } +} + +@end \ No newline at end of file diff --git a/src/game/unit/QQUnit.h b/src/game/unit/QQUnit.h new file mode 100644 index 0000000..6fdee22 --- /dev/null +++ b/src/game/unit/QQUnit.h @@ -0,0 +1,32 @@ +#include +#import "Sparrow.h" + +#import "physics/QQWorld.h" +#import "game/unit/QQActor.h" +#import "game/unit/QQActorDelegate.h" +#import "render/QQSparrowExtensions.h" + + +@interface QQUnit : QQActor { + +@private + SPDisplayObject* _shape; +} + +/// properties +@property (nonatomic, readonly) BOOL canAttack; +- (void) setShapeFromFile:(NSString*)filename; + +/// initializers +- (id) initAtX:(float)x y:(float)y width:(float)w height:(float)h color:(uint)color; +- (id) initAtX:(float)x y:(float)y withShape:(SPDisplayObject*)shape; + + +/// methods + +- (void) attack:(QQActor*)actor; +- (void) attackToward:(CGPoint)point; +- (void) attackTowardX:(float)x y:(float)y; + + +@end diff --git a/src/game/unit/QQUnit.mm b/src/game/unit/QQUnit.mm new file mode 100644 index 0000000..0959cfb --- /dev/null +++ b/src/game/unit/QQUnit.mm @@ -0,0 +1,101 @@ +#include +#import "Sparrow.h" + +#import "game/unit/QQUnit.h" +#import "game/QQGame.h" +#import "render/QQSparrowExtensions.h" + + + + +@implementation QQUnit + +@dynamic world; // Eliminates compiler warnings due to inheritance (!) +@dynamic game; + +@synthesize shape = _shape; + +- (float) shapeCenterX { return self.shape.registrationX; } +- (void) setShapeCenterX:(float)x { self.shape.registrationX = x; } +- (float) shapeCenterY { return self.shape.registrationY; } +- (void) setShapeCenterY:(float)y { self.shape.registrationY = y; } + +- (BOOL) canAttack { return NO; } + + +/// initializers + +- (id) init { + return [self initAtX:50 y:50 width:50 height:50 color:0xff0071]; +} + +- (id) initAtX:(float)x y:(float)y width:(float)w height:(float)h color:(uint)color { + SPQuad* shape = [SPQuad quadWithWidth:w height:h color:color]; + return [self initAtX:x y:y withShape:shape]; +} + +- (id) initAtX:(float)x y:(float)y withShape:(SPDisplayObject*)shape { + if ((self = [super initAtX:x y:y])) { + self.shape = shape; + + float dblpx = 2*self.world.scale; + b2PolygonShape box; + box.SetAsBox(shape.width/dblpx, shape.height/dblpx); + b2FixtureDef fix; + fix.shape = &box; + fix.density = 1.0f; + fix.userData = self; + self.body->CreateFixture(&fix); + } + return self; +} + +- (void) dealloc { + [self.game.level removeChild:_shape]; + [_shape release]; + [super dealloc]; +} + +/// methods + +- (void) setShape:(SPDisplayObject*)newShape { + if (_shape != newShape) { + [self.game.level removeChild:_shape]; + [_shape release]; + + _shape = [newShape retain]; + if (_shape) { + [self updateShape]; + [self.game.level addChild:_shape]; + } + } +} + +- (void) setShapeFromFile:(NSString*)filename { + [self setShape:[[[SPImage alloc] autorelease] initWithContentsOfFile:filename]]; +} + +- (void) act { + if ((self.game.ticks % 50) == 0) { + self.rotation += b2_pi / 8; + } +} + +- (void) draw { + [super draw]; +} + + +- (void) attack:(QQActor*)actor { + [self attackTowardX:actor.x y:actor.y]; +} +- (void) attackToward:(CGPoint)pt { + [self attackTowardX:pt.x y:pt.y]; +} +- (void) attackTowardX:(float)x y:(float)y { + +} + + + +@end diff --git a/src/physics/QQWorld.h b/src/physics/QQWorld.h index 3b47e73..54bf6c9 100644 --- a/src/physics/QQWorld.h +++ b/src/physics/QQWorld.h @@ -1,6 +1,6 @@ #include -#import "qq/QQNotifier.h" -#import "qq/QQNotificationProxy.h" +#import "qq/event/QQNotifier.h" +#import "qq/event/QQNotificationProxy.h" #import "physics/event/QQPhysicalEvents.h" #import "physics/debug/QQGLESDebugDraw.h" #import "game/QQPhysical.h" diff --git a/src/physics/event/QQContactNotification.h b/src/physics/event/QQContactNotification.h index 4c173f3..b7a815c 100644 --- a/src/physics/event/QQContactNotification.h +++ b/src/physics/event/QQContactNotification.h @@ -1,6 +1,7 @@ -#include "qq/QQNotification.h" #include -#include "game/actor/QQActor.h" + +#import "qq/event/QQNotification.h" +#import "game/unit/QQActor.h" @interface QQContactNotification : QQNotification { @@ -8,10 +9,6 @@ b2Contact* _contact; } -- (id) initWithName:(NSString*)name contact:(b2Contact*)contact; -- (id) initWithName:(NSString*)name object:(id)obj contact:(b2Contact*)contact; -- (id) initWithName:(NSString*)name object:(id)obj userInfo:(NSDictionary*)info contact:(b2Contact*)contact; - @property (nonatomic, readonly) b2Contact* contact; @property (nonatomic, readonly) QQActor* actorA; @@ -23,6 +20,11 @@ @property (nonatomic, readonly) b2Body* bodyB; +- (id) initWithName:(NSString*)name contact:(b2Contact*)contact; +- (id) initWithName:(NSString*)name object:(id)obj contact:(b2Contact*)contact; +- (id) initWithName:(NSString*)name object:(id)obj userInfo:(NSDictionary*)info contact:(b2Contact*)contact; + + + (QQContactNotification*) notification:(NSString*)name contact:(b2Contact*)contact; + (QQContactNotification*) notification:(NSString*)name object:(id)obj contact:(b2Contact*)contact; + (QQContactNotification*) notification:(NSString*)name object:(id)obj userInfo:(NSDictionary*)info contact:(b2Contact*)contact; diff --git a/src/physics/event/QQPhysicalEvents.mm b/src/physics/event/QQPhysicalEvents.mm index 6d722f0..bfba110 100644 --- a/src/physics/event/QQPhysicalEvents.mm +++ b/src/physics/event/QQPhysicalEvents.mm @@ -1,4 +1,4 @@ -#include "QQPhysicalEvents.h" +#import "QQPhysicalEvents.h" void QQContactListener::BeginContact(b2Contact* contact) { diff --git a/src/qq/QQNotification.h b/src/qq/QQNotification.h deleted file mode 100644 index b2a24bd..0000000 --- a/src/qq/QQNotification.h +++ /dev/null @@ -1,21 +0,0 @@ - -@interface QQNotification : NSNotification { -@private - NSString* mName; - id mObject; - NSDictionary* mUserInfo; -} - -@property (nonatomic, readwrite, retain) NSString* name; -@property (nonatomic, readwrite, retain) id object; -@property (nonatomic, readwrite, retain) NSDictionary* userInfo; - -- (id) initWithName:(NSString*)name; -- (id) initWithName:(NSString*)name object:(id)obj; -- (id) initWithName:(NSString*)name object:(id)obj userInfo:(NSDictionary*)info; - -+ (QQNotification*) notification:(NSString*)name; -+ (QQNotification*) notification:(NSString*)name object:(id)obj; -+ (QQNotification*) notification:(NSString*)name object:(id)obj userInfo:(NSDictionary*)info; - -@end diff --git a/src/qq/QQNotification.mm b/src/qq/QQNotification.mm deleted file mode 100644 index e4b2448..0000000 --- a/src/qq/QQNotification.mm +++ /dev/null @@ -1,67 +0,0 @@ -#include "qq/QQNotification.h" - - -@implementation QQNotification - -- (id) initWithName:(NSString*)name { - return [self initWithName:name object:nil userInfo:nil]; -} - -- (id) initWithName:(NSString*)name object:(id)object { - return [self initWithName:name object:object userInfo:nil]; -} - -- (id) initWithName:(NSString*)name object:(id)object userInfo:(NSDictionary*)userInfo { - // From: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSNotification - // - // You can choose any designated initializer you like, but be sure that your initializer - // **does not call** NSNotification’s implementation of init (via [super init]). - // NSNotification is not meant to be instantiated directly, and its init method raises an exception. - if (self) { - self.name = name; - self.object = object; - self.userInfo = userInfo; - } - return self; -} - -- (void) dealloc { - [mName release]; - [mObject release]; - [mUserInfo release]; - [super dealloc]; -} - - -- (NSString*) name { return mName; } -- (void) setName:(NSString*)str { - [mName release]; - mName = [str retain]; -} - -- (id) object { return mObject; } -- (void) setObject:(id)obj { - [mObject release]; - mObject = [obj retain]; -} - -- (NSDictionary*) userInfo { return mUserInfo; } -- (void) setUserInfo:(NSDictionary*)info { - [mUserInfo release]; - mUserInfo = [info retain]; -} - - -+ (QQNotification*) notification:(NSString*)name { - return [[[QQNotification alloc] initWithName:name] autorelease]; -} -+ (QQNotification*) notification:(NSString*)name object:(id)obj { - return [[[QQNotification alloc] initWithName:name object:obj] autorelease]; -} -+ (QQNotification*) notification:(NSString*)name object:(id)obj userInfo:(NSDictionary*)info { - return [[[QQNotification alloc] initWithName:name object:obj userInfo:info] autorelease]; -} - - - -@end diff --git a/src/qq/QQNotificationCenter.h b/src/qq/QQNotificationCenter.h deleted file mode 100644 index 65c60ec..0000000 --- a/src/qq/QQNotificationCenter.h +++ /dev/null @@ -1,16 +0,0 @@ -#import "qq/QQNotifier.h" - -@interface QQNotificationCenter : NSNotificationCenter { -@private - id _implicitNotificationSender; -} -/** Object used for implicit sender when adding or removing observers. */ -@property (nonatomic, readwrite, retain) id implicitNotificationSender; - -/** Initialize with self as implicit sender. */ -- (id) init; - -/** Returns a center with given implicit target. A nil target will subscript observers to all objects. */ -+ (QQNotificationCenter*) notifierWithTarget:(id)target; - -@end diff --git a/src/qq/QQNotificationCenter.mm b/src/qq/QQNotificationCenter.mm deleted file mode 100644 index 232c794..0000000 --- a/src/qq/QQNotificationCenter.mm +++ /dev/null @@ -1,69 +0,0 @@ -#import "qq/QQNotificationCenter.h" - - -@implementation QQNotificationCenter - -- (id) init { - if ((self = [super init])){ - _implicitNotificationSender = self; - } - return self; -} - -- (void) dealloc { - [_implicitNotificationSender release]; - [super dealloc]; -} - -@synthesize implicitNotificationSender = _implicitNotificationSender; - - -/// observable - -- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event { - [self addObserver:observer selector:selector name:event object:self.implicitNotificationSender]; -} - -// Remove a listener from this object -- (void) removeObserver:(id)observer { - [self removeObserver:observer name:nil object:self.implicitNotificationSender]; -} -- (void) removeObserver:(id)observer name:(NSString*)event { - [self removeObserver:observer name:event object:self.implicitNotificationSender]; -} - -// Send a notification from this object -- (void) postNotificationName:(NSString*)name { - [self postNotificationName:name object:self.implicitNotificationSender]; -} -- (void) postNotificationName:(NSString*)name userInfo:(NSDictionary*)info { - [self postNotificationName:name object:self.implicitNotificationSender userInfo:info]; -} - - -/// notifier - -- (void) removeObservers:(id)observer { - [super removeObserver:observer]; -} - - -/// NSNotificationCenter (superclass) provides: - -// - (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event object:(id)sender -// - (void) removeObserver:(id)observer name:(NSString*)event object:(id)sender -// - (void) postNotification:(NSNotification*)msg -// - (void) postNotificationName:(NSString*)name object:(id)sender -// - (void) postNotificationName:(NSString*)name object:(id)sender userInfo:(NSDictionary*)info - -// as well as... -// - (id)addObserverForName:(NSString *)name object:(id)obj queue:(NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *))block - - -+ (QQNotificationCenter*) notifierWithTarget:(id)target { - QQNotificationCenter* notifier = [[[QQNotificationCenter alloc] init] autorelease]; - notifier.implicitNotificationSender = target; - return notifier; -} - -@end diff --git a/src/qq/QQNotificationProxy.h b/src/qq/QQNotificationProxy.h deleted file mode 100644 index 4b99c54..0000000 --- a/src/qq/QQNotificationProxy.h +++ /dev/null @@ -1,16 +0,0 @@ -#import "qq/QQNotifier.h" - -/** - * Proxies all QQObservableNotifier calls to another QQObservableNotifier. - */ -@interface QQNotificationProxy : NSObject { -@private - id _proxiedNotifier; - id _implicitNotificationSender; -} - -@property (nonatomic, readwrite, retain) id proxiedNotifier; - -- (id) initWithNotifier:(id)notifier; - -@end diff --git a/src/qq/QQNotificationProxy.mm b/src/qq/QQNotificationProxy.mm deleted file mode 100644 index 39b4697..0000000 --- a/src/qq/QQNotificationProxy.mm +++ /dev/null @@ -1,70 +0,0 @@ -#import "qq/QQNotificationProxy.h" - - -@implementation QQNotificationProxy - -@synthesize proxiedNotifier = _proxiedNotifier; -@synthesize implicitNotificationSender = _implicitNotificationSender; - - -- (id) initWithNotifier:(id)notifier { - if ((self = [super init])){ - self.proxiedNotifier = notifier; - } - return self; -} - -- (void) dealloc { - self.proxiedNotifier = nil; - [super dealloc]; -} - -/// observable - -- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event { - [self addObserver:observer selector:selector name:event object:self.implicitNotificationSender]; -} - -// Remove a listener from this object -- (void) removeObserver:(id)observer { - [self removeObserver:observer name:nil object:self.implicitNotificationSender]; -} -- (void) removeObserver:(id)observer name:(NSString*)event { - [self removeObserver:observer name:event object:self.implicitNotificationSender]; -} - -// Send a notification from this object -- (void) postNotificationName:(NSString*)name { - [self postNotificationName:name object:self.implicitNotificationSender]; -} -- (void) postNotificationName:(NSString*)name userInfo:(NSDictionary*)info { - [self postNotificationName:name object:self.implicitNotificationSender userInfo:info]; -} - - -/// notifier - -- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event object:(id)sender { - [self.proxiedNotifier addObserver:observer selector:selector name:event object:sender]; -} - -- (void) removeObserver:(id)observer name:(NSString*)event object:(id)sender { - [self.proxiedNotifier removeObserver:observer name:event object:sender]; -} -- (void) removeObservers:(id)observer { - [self.proxiedNotifier removeObserver:observer]; -} - -- (void) postNotification:(NSNotification*)msg { - [self.proxiedNotifier postNotification:msg]; -} -- (void) postNotificationName:(NSString*)name object:(id)sender { - [self.proxiedNotifier postNotificationName:name object:sender]; -} -- (void) postNotificationName:(NSString*)name object:(id)sender userInfo:(NSDictionary*)info { - [self.proxiedNotifier postNotificationName:name object:sender userInfo:info]; -} - - - -@end diff --git a/src/qq/QQNotifier.h b/src/qq/QQNotifier.h deleted file mode 100644 index 1ca2a5d..0000000 --- a/src/qq/QQNotifier.h +++ /dev/null @@ -1,29 +0,0 @@ -#import "qq/QQObservable.h" - - -@protocol QQNotifier - -/** - * Adds an observer of specified object. - * - * A nil name means observer will be notified of all events for specified object. - * A nil object means observer will be notified of all events for specified name. - * An observer specifying nil for both name and object will be notified of all events. - */ -- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event object:(id)sender; - -- (void) removeObserver:(id)observer name:(NSString*)event object:(id)sender; - -/** Removes observer from all subscribed notices. */ -- (void) removeObservers:(id)observer; - -- (void) postNotification:(NSNotification*)msg; -- (void) postNotificationName:(NSString*)name object:(id)sender; -- (void) postNotificationName:(NSString*)name object:(id)sender userInfo:(NSDictionary*)info; - - -@end - -@protocol QQObservableNotifier - -@end \ No newline at end of file diff --git a/src/qq/QQNotifiers.h b/src/qq/QQNotifiers.h deleted file mode 100644 index f36c283..0000000 --- a/src/qq/QQNotifiers.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Various macros relating to notification dispatch. - */ - -/** - * As a QQNotificationProxy, but via encapsulation. - */ -#define qqNotifierProxy(__target, __notifier) \ -- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event { \ - [self addObserver:observer selector:selector name:event object:__target]; \ -} \ -- (void) removeObserver:(id)observer { \ - [self removeObserver:observer name:nil object:__target]; \ -} \ -- (void) removeObserver:(id)observer name:(NSString*)event { \ - [self removeObserver:observer name:event object:__target]; \ -} \ -- (void) postNotificationName:(NSString*)name { \ - [self postNotificationName:name object:__target]; \ -} \ -- (void) postNotificationName:(NSString*)name userInfo:(NSDictionary*)info { \ - [self postNotificationName:name object:__target userInfo:info]; \ -} \ -- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event object:(id)sender { \ - [__notifier addObserver:observer selector:selector name:event object:sender]; \ -} \ -- (void) removeObserver:(id)observer name:(NSString*)event object:(id)sender { \ - [__notifier removeObserver:observer name:event object:sender]; \ -} \ -- (void) removeObservers:(id)observer { \ - [__notifier removeObserver:observer]; \ -} \ -- (void) postNotification:(NSNotification*)msg { \ - [__notifier postNotification:msg]; \ -} \ -- (void) postNotificationName:(NSString*)name object:(id)sender { \ - [__notifier postNotificationName:name object:sender]; \ -} \ -- (void) postNotificationName:(NSString*)name object:(id)sender userInfo:(NSDictionary*)info { \ - [__notifier postNotificationName:name object:sender userInfo:info]; \ -} - diff --git a/src/qq/QQObservable.h b/src/qq/QQObservable.h deleted file mode 100644 index 8814775..0000000 --- a/src/qq/QQObservable.h +++ /dev/null @@ -1,24 +0,0 @@ - -/** - * An observable object implicitly uses itself as the sender or target of calls - * that would normally take an object if the call was made to an NSNotificationCenter. - */ -@protocol QQObservable - -@property (nonatomic, readwrite, retain) id implicitNotificationSender; - -//- (void) observe:(NSString*)event notify:(id)observer selector:(SEL)selector; - -/** Adds an observer of this object. */ -- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event; - -// Remove a listener from this object -- (void) removeObserver:(id)observer; -- (void) removeObserver:(id)observer name:(NSString*)event; - -// Send a notification from this object -- (void) postNotificationName:(NSString*)name; -- (void) postNotificationName:(NSString*)name userInfo:(NSDictionary*)info; - - -@end diff --git a/src/qq/event/QQNotification.h b/src/qq/event/QQNotification.h new file mode 100644 index 0000000..b2a24bd --- /dev/null +++ b/src/qq/event/QQNotification.h @@ -0,0 +1,21 @@ + +@interface QQNotification : NSNotification { +@private + NSString* mName; + id mObject; + NSDictionary* mUserInfo; +} + +@property (nonatomic, readwrite, retain) NSString* name; +@property (nonatomic, readwrite, retain) id object; +@property (nonatomic, readwrite, retain) NSDictionary* userInfo; + +- (id) initWithName:(NSString*)name; +- (id) initWithName:(NSString*)name object:(id)obj; +- (id) initWithName:(NSString*)name object:(id)obj userInfo:(NSDictionary*)info; + ++ (QQNotification*) notification:(NSString*)name; ++ (QQNotification*) notification:(NSString*)name object:(id)obj; ++ (QQNotification*) notification:(NSString*)name object:(id)obj userInfo:(NSDictionary*)info; + +@end diff --git a/src/qq/event/QQNotification.mm b/src/qq/event/QQNotification.mm new file mode 100644 index 0000000..d72e3f4 --- /dev/null +++ b/src/qq/event/QQNotification.mm @@ -0,0 +1,67 @@ +#import "qq/event/QQNotification.h" + + +@implementation QQNotification + +- (id) initWithName:(NSString*)name { + return [self initWithName:name object:nil userInfo:nil]; +} + +- (id) initWithName:(NSString*)name object:(id)object { + return [self initWithName:name object:object userInfo:nil]; +} + +- (id) initWithName:(NSString*)name object:(id)object userInfo:(NSDictionary*)userInfo { + // From: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSNotification_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSNotification + // + // You can choose any designated initializer you like, but be sure that your initializer + // **does not call** NSNotification’s implementation of init (via [super init]). + // NSNotification is not meant to be instantiated directly, and its init method raises an exception. + if (self) { + self.name = name; + self.object = object; + self.userInfo = userInfo; + } + return self; +} + +- (void) dealloc { + [mName release]; + [mObject release]; + [mUserInfo release]; + [super dealloc]; +} + + +- (NSString*) name { return mName; } +- (void) setName:(NSString*)str { + [mName release]; + mName = [str retain]; +} + +- (id) object { return mObject; } +- (void) setObject:(id)obj { + [mObject release]; + mObject = [obj retain]; +} + +- (NSDictionary*) userInfo { return mUserInfo; } +- (void) setUserInfo:(NSDictionary*)info { + [mUserInfo release]; + mUserInfo = [info retain]; +} + + ++ (QQNotification*) notification:(NSString*)name { + return [[[QQNotification alloc] initWithName:name] autorelease]; +} ++ (QQNotification*) notification:(NSString*)name object:(id)obj { + return [[[QQNotification alloc] initWithName:name object:obj] autorelease]; +} ++ (QQNotification*) notification:(NSString*)name object:(id)obj userInfo:(NSDictionary*)info { + return [[[QQNotification alloc] initWithName:name object:obj userInfo:info] autorelease]; +} + + + +@end diff --git a/src/qq/event/QQNotificationCenter.h b/src/qq/event/QQNotificationCenter.h new file mode 100644 index 0000000..661d909 --- /dev/null +++ b/src/qq/event/QQNotificationCenter.h @@ -0,0 +1,16 @@ +#import "qq/event/QQNotifier.h" + +@interface QQNotificationCenter : NSNotificationCenter { +@private + id _implicitNotificationSender; +} +/** Object used for implicit sender when adding or removing observers. */ +@property (nonatomic, readwrite, retain) id implicitNotificationSender; + +/** Initialize with self as implicit sender. */ +- (id) init; + +/** Returns a center with given implicit target. A nil target will subscript observers to all objects. */ ++ (QQNotificationCenter*) notifierWithTarget:(id)target; + +@end diff --git a/src/qq/event/QQNotificationCenter.mm b/src/qq/event/QQNotificationCenter.mm new file mode 100644 index 0000000..64e5703 --- /dev/null +++ b/src/qq/event/QQNotificationCenter.mm @@ -0,0 +1,69 @@ +#import "qq/event/QQNotificationCenter.h" + + +@implementation QQNotificationCenter + +- (id) init { + if ((self = [super init])){ + _implicitNotificationSender = self; + } + return self; +} + +- (void) dealloc { + [_implicitNotificationSender release]; + [super dealloc]; +} + +@synthesize implicitNotificationSender = _implicitNotificationSender; + + +/// observable + +- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event { + [self addObserver:observer selector:selector name:event object:self.implicitNotificationSender]; +} + +// Remove a listener from this object +- (void) removeObserver:(id)observer { + [self removeObserver:observer name:nil object:self.implicitNotificationSender]; +} +- (void) removeObserver:(id)observer name:(NSString*)event { + [self removeObserver:observer name:event object:self.implicitNotificationSender]; +} + +// Send a notification from this object +- (void) postNotificationName:(NSString*)name { + [self postNotificationName:name object:self.implicitNotificationSender]; +} +- (void) postNotificationName:(NSString*)name userInfo:(NSDictionary*)info { + [self postNotificationName:name object:self.implicitNotificationSender userInfo:info]; +} + + +/// notifier + +- (void) removeObservers:(id)observer { + [super removeObserver:observer]; +} + + +/// NSNotificationCenter (superclass) provides: + +// - (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event object:(id)sender +// - (void) removeObserver:(id)observer name:(NSString*)event object:(id)sender +// - (void) postNotification:(NSNotification*)msg +// - (void) postNotificationName:(NSString*)name object:(id)sender +// - (void) postNotificationName:(NSString*)name object:(id)sender userInfo:(NSDictionary*)info + +// as well as... +// - (id)addObserverForName:(NSString *)name object:(id)obj queue:(NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *))block + + ++ (QQNotificationCenter*) notifierWithTarget:(id)target { + QQNotificationCenter* notifier = [[[QQNotificationCenter alloc] init] autorelease]; + notifier.implicitNotificationSender = target; + return notifier; +} + +@end diff --git a/src/qq/event/QQNotificationProxy.h b/src/qq/event/QQNotificationProxy.h new file mode 100644 index 0000000..0030b68 --- /dev/null +++ b/src/qq/event/QQNotificationProxy.h @@ -0,0 +1,16 @@ +#import "qq/event/QQNotifier.h" + +/** + * Proxies all QQObservableNotifier calls to another QQObservableNotifier. + */ +@interface QQNotificationProxy : NSObject { +@private + id _proxiedNotifier; + id _implicitNotificationSender; +} + +@property (nonatomic, readwrite, retain) id proxiedNotifier; + +- (id) initWithNotifier:(id)notifier; + +@end diff --git a/src/qq/event/QQNotificationProxy.mm b/src/qq/event/QQNotificationProxy.mm new file mode 100644 index 0000000..3d2c3ee --- /dev/null +++ b/src/qq/event/QQNotificationProxy.mm @@ -0,0 +1,70 @@ +#import "qq/event/QQNotificationProxy.h" + + +@implementation QQNotificationProxy + +@synthesize proxiedNotifier = _proxiedNotifier; +@synthesize implicitNotificationSender = _implicitNotificationSender; + + +- (id) initWithNotifier:(id)notifier { + if ((self = [super init])){ + self.proxiedNotifier = notifier; + } + return self; +} + +- (void) dealloc { + self.proxiedNotifier = nil; + [super dealloc]; +} + +/// observable + +- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event { + [self addObserver:observer selector:selector name:event object:self.implicitNotificationSender]; +} + +// Remove a listener from this object +- (void) removeObserver:(id)observer { + [self removeObserver:observer name:nil object:self.implicitNotificationSender]; +} +- (void) removeObserver:(id)observer name:(NSString*)event { + [self removeObserver:observer name:event object:self.implicitNotificationSender]; +} + +// Send a notification from this object +- (void) postNotificationName:(NSString*)name { + [self postNotificationName:name object:self.implicitNotificationSender]; +} +- (void) postNotificationName:(NSString*)name userInfo:(NSDictionary*)info { + [self postNotificationName:name object:self.implicitNotificationSender userInfo:info]; +} + + +/// notifier + +- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event object:(id)sender { + [self.proxiedNotifier addObserver:observer selector:selector name:event object:sender]; +} + +- (void) removeObserver:(id)observer name:(NSString*)event object:(id)sender { + [self.proxiedNotifier removeObserver:observer name:event object:sender]; +} +- (void) removeObservers:(id)observer { + [self.proxiedNotifier removeObserver:observer]; +} + +- (void) postNotification:(NSNotification*)msg { + [self.proxiedNotifier postNotification:msg]; +} +- (void) postNotificationName:(NSString*)name object:(id)sender { + [self.proxiedNotifier postNotificationName:name object:sender]; +} +- (void) postNotificationName:(NSString*)name object:(id)sender userInfo:(NSDictionary*)info { + [self.proxiedNotifier postNotificationName:name object:sender userInfo:info]; +} + + + +@end diff --git a/src/qq/event/QQNotifier.h b/src/qq/event/QQNotifier.h new file mode 100644 index 0000000..445d501 --- /dev/null +++ b/src/qq/event/QQNotifier.h @@ -0,0 +1,29 @@ +#import "qq/event/QQObservable.h" + + +@protocol QQNotifier + +/** + * Adds an observer of specified object. + * + * A nil name means observer will be notified of all events for specified object. + * A nil object means observer will be notified of all events for specified name. + * An observer specifying nil for both name and object will be notified of all events. + */ +- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event object:(id)sender; + +- (void) removeObserver:(id)observer name:(NSString*)event object:(id)sender; + +/** Removes observer from all subscribed notices. */ +- (void) removeObservers:(id)observer; + +- (void) postNotification:(NSNotification*)msg; +- (void) postNotificationName:(NSString*)name object:(id)sender; +- (void) postNotificationName:(NSString*)name object:(id)sender userInfo:(NSDictionary*)info; + + +@end + +@protocol QQObservableNotifier + +@end \ No newline at end of file diff --git a/src/qq/event/QQNotifiers.h b/src/qq/event/QQNotifiers.h new file mode 100644 index 0000000..8eeab9a --- /dev/null +++ b/src/qq/event/QQNotifiers.h @@ -0,0 +1,46 @@ +#import "qq/event/QQObservable.h" +#import "qq/event/QQNotifier.h" +#import "qq/event/QQNotification.h" +#import "qq/event/QQNotificationCenter.h" +#import "qq/event/QQNotificationProxy.h" + + + +/** + * As a QQNotificationProxy, but via encapsulation. + */ +#define qqNotifierProxy(__target, __notifier) \ +- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event { \ + [self addObserver:observer selector:selector name:event object:__target]; \ +} \ +- (void) removeObserver:(id)observer { \ + [self removeObserver:observer name:nil object:__target]; \ +} \ +- (void) removeObserver:(id)observer name:(NSString*)event { \ + [self removeObserver:observer name:event object:__target]; \ +} \ +- (void) postNotificationName:(NSString*)name { \ + [self postNotificationName:name object:__target]; \ +} \ +- (void) postNotificationName:(NSString*)name userInfo:(NSDictionary*)info { \ + [self postNotificationName:name object:__target userInfo:info]; \ +} \ +- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event object:(id)sender { \ + [__notifier addObserver:observer selector:selector name:event object:sender]; \ +} \ +- (void) removeObserver:(id)observer name:(NSString*)event object:(id)sender { \ + [__notifier removeObserver:observer name:event object:sender]; \ +} \ +- (void) removeObservers:(id)observer { \ + [__notifier removeObserver:observer]; \ +} \ +- (void) postNotification:(NSNotification*)msg { \ + [__notifier postNotification:msg]; \ +} \ +- (void) postNotificationName:(NSString*)name object:(id)sender { \ + [__notifier postNotificationName:name object:sender]; \ +} \ +- (void) postNotificationName:(NSString*)name object:(id)sender userInfo:(NSDictionary*)info { \ + [__notifier postNotificationName:name object:sender userInfo:info]; \ +} + diff --git a/src/qq/event/QQObservable.h b/src/qq/event/QQObservable.h new file mode 100644 index 0000000..8814775 --- /dev/null +++ b/src/qq/event/QQObservable.h @@ -0,0 +1,24 @@ + +/** + * An observable object implicitly uses itself as the sender or target of calls + * that would normally take an object if the call was made to an NSNotificationCenter. + */ +@protocol QQObservable + +@property (nonatomic, readwrite, retain) id implicitNotificationSender; + +//- (void) observe:(NSString*)event notify:(id)observer selector:(SEL)selector; + +/** Adds an observer of this object. */ +- (void) addObserver:(id)observer selector:(SEL)selector name:(NSString*)event; + +// Remove a listener from this object +- (void) removeObserver:(id)observer; +- (void) removeObserver:(id)observer name:(NSString*)event; + +// Send a notification from this object +- (void) postNotificationName:(NSString*)name; +- (void) postNotificationName:(NSString*)name userInfo:(NSDictionary*)info; + + +@end diff --git a/tanks.xcodeproj/project.pbxproj b/tanks.xcodeproj/project.pbxproj index 79377d3..8bd63cc 100644 --- a/tanks.xcodeproj/project.pbxproj +++ b/tanks.xcodeproj/project.pbxproj @@ -12,13 +12,7 @@ 492D80CC138B231B0042D918 /* QQPhysical.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D80CB138B231B0042D918 /* QQPhysical.h */; }; 492D80E4138BA4910042D918 /* QQCooldown.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D80DE138BA4910042D918 /* QQCooldown.h */; }; 492D80E5138BA4910042D918 /* QQCooldown.mm in Sources */ = {isa = PBXBuildFile; fileRef = 492D80DF138BA4910042D918 /* QQCooldown.mm */; }; - 492D80EB138BA4B40042D918 /* QQTank.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D80E9138BA4B40042D918 /* QQTank.h */; }; - 492D80EC138BA4B40042D918 /* QQTank.mm in Sources */ = {isa = PBXBuildFile; fileRef = 492D80EA138BA4B40042D918 /* QQTank.mm */; }; - 492D80F0138BA4BC0042D918 /* QQBullet.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D80EE138BA4BC0042D918 /* QQBullet.h */; }; - 492D80F1138BA4BC0042D918 /* QQBullet.mm in Sources */ = {isa = PBXBuildFile; fileRef = 492D80EF138BA4BC0042D918 /* QQBullet.mm */; }; 492D80F3138BA4CE0042D918 /* QQThing.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D80F2138BA4CE0042D918 /* QQThing.h */; }; - 492D80FD138BCA840042D918 /* QQUnit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 492D80FC138BCA840042D918 /* QQUnit.mm */; }; - 492D80FF138BCC9F0042D918 /* QQActorDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D80FE138BCC9F0042D918 /* QQActorDelegate.h */; }; 492D810C138C07540042D918 /* BEParallaxSprite.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D8101138C07540042D918 /* BEParallaxSprite.h */; }; 492D810D138C07540042D918 /* BEParallaxSprite.m in Sources */ = {isa = PBXBuildFile; fileRef = 492D8102138C07540042D918 /* BEParallaxSprite.m */; }; 492D810E138C07540042D918 /* SHCircle.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D8103138C07540042D918 /* SHCircle.h */; }; @@ -31,18 +25,12 @@ 492D8115138C07540042D918 /* SXFPSMeter.h in Headers */ = {isa = PBXBuildFile; fileRef = 492D810A138C07540042D918 /* SXFPSMeter.h */; }; 492D8116138C07540042D918 /* SXFPSMeter.m in Sources */ = {isa = PBXBuildFile; fileRef = 492D810B138C07540042D918 /* SXFPSMeter.m */; }; 494DE9971376927C00FDB3D7 /* libBox2D.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 494DE9961376927C00FDB3D7 /* libBox2D.a */; }; - 4978AD0E1395E5CE00930447 /* QQActors.h in Headers */ = {isa = PBXBuildFile; fileRef = 4978AD0D1395E5CE00930447 /* QQActors.h */; }; 4978AD141396139100930447 /* Tanks.h in Headers */ = {isa = PBXBuildFile; fileRef = 4978AD131396139100930447 /* Tanks.h */; }; 4978AD1A1396302300930447 /* QQContactNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 4978AD161396302300930447 /* QQContactNotification.h */; }; 4978AD1B1396302300930447 /* QQContactNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4978AD171396302300930447 /* QQContactNotification.mm */; }; 4978AD1C1396302300930447 /* QQPhysicalEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = 4978AD181396302300930447 /* QQPhysicalEvents.h */; }; 4978AD1D1396302300930447 /* QQPhysicalEvents.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4978AD191396302300930447 /* QQPhysicalEvents.mm */; }; - 4978AD251396302F00930447 /* QQNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 4978AD1F1396302F00930447 /* QQNotification.h */; }; - 4978AD261396302F00930447 /* QQNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4978AD201396302F00930447 /* QQNotification.mm */; }; - 4978AD271396302F00930447 /* QQNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 4978AD211396302F00930447 /* QQNotifier.h */; }; - 4978AD2A1396302F00930447 /* QQObservable.h in Headers */ = {isa = PBXBuildFile; fileRef = 4978AD241396302F00930447 /* QQObservable.h */; }; 4995ABB213816CCE00334646 /* QQGame.h in Headers */ = {isa = PBXBuildFile; fileRef = 49E834A513812427007A6598 /* QQGame.h */; }; - 4995ABB313816CD400334646 /* QQUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 49E834A213812427007A6598 /* QQUnit.h */; }; 4995ABF91381C46B00334646 /* Icon-iPad.png in Resources */ = {isa = PBXBuildFile; fileRef = 4995ABCA1381C46B00334646 /* Icon-iPad.png */; }; 4995ABFA1381C46B00334646 /* Icon-iPhone.png in Resources */ = {isa = PBXBuildFile; fileRef = 4995ABCB1381C46B00334646 /* Icon-iPhone.png */; }; 4995AC261381C5ED00334646 /* Icon-iPhone@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4995ABCC1381C46B00334646 /* Icon-iPhone@2x.png */; }; @@ -54,10 +42,26 @@ 49966919136930E8006E8125 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49966914136930E8006E8125 /* OpenAL.framework */; }; 4996691A136930E8006E8125 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49966915136930E8006E8125 /* OpenGLES.framework */; }; 4996691B136930E8006E8125 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49966916136930E8006E8125 /* QuartzCore.framework */; }; - 499D6A9C1399BFB8008E4C0D /* QQNotificationCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 499D6A981399BFB8008E4C0D /* QQNotificationCenter.h */; }; - 499D6A9D1399BFB8008E4C0D /* QQNotificationCenter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499D6A991399BFB8008E4C0D /* QQNotificationCenter.mm */; }; - 499D6A9E1399BFB8008E4C0D /* QQNotificationProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 499D6A9A1399BFB8008E4C0D /* QQNotificationProxy.h */; }; - 499D6A9F1399BFB8008E4C0D /* QQNotificationProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499D6A9B1399BFB8008E4C0D /* QQNotificationProxy.mm */; }; + 499F65C9139CBC0C00309DE4 /* QQNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65C0139CBC0C00309DE4 /* QQNotification.h */; }; + 499F65CA139CBC0C00309DE4 /* QQNotification.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499F65C1139CBC0C00309DE4 /* QQNotification.mm */; }; + 499F65CB139CBC0C00309DE4 /* QQNotificationCenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65C2139CBC0C00309DE4 /* QQNotificationCenter.h */; }; + 499F65CC139CBC0C00309DE4 /* QQNotificationCenter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499F65C3139CBC0C00309DE4 /* QQNotificationCenter.mm */; }; + 499F65CD139CBC0C00309DE4 /* QQNotificationProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65C4139CBC0C00309DE4 /* QQNotificationProxy.h */; }; + 499F65CE139CBC0C00309DE4 /* QQNotificationProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499F65C5139CBC0C00309DE4 /* QQNotificationProxy.mm */; }; + 499F65CF139CBC0C00309DE4 /* QQNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65C6139CBC0C00309DE4 /* QQNotifier.h */; }; + 499F65D0139CBC0C00309DE4 /* QQNotifiers.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65C7139CBC0C00309DE4 /* QQNotifiers.h */; }; + 499F65D1139CBC0C00309DE4 /* QQObservable.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65C8139CBC0C00309DE4 /* QQObservable.h */; }; + 499F65E1139CBCBA00309DE4 /* QQActor.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65D7139CBCBA00309DE4 /* QQActor.h */; }; + 499F65E2139CBCBA00309DE4 /* QQActor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499F65D8139CBCBA00309DE4 /* QQActor.mm */; }; + 499F65E3139CBCBA00309DE4 /* QQActorDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65D9139CBCBA00309DE4 /* QQActorDelegate.h */; }; + 499F65E4139CBCBA00309DE4 /* QQActors.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65DA139CBCBA00309DE4 /* QQActors.h */; }; + 499F65E5139CBCBA00309DE4 /* QQBullet.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65DB139CBCBA00309DE4 /* QQBullet.h */; }; + 499F65E6139CBCBA00309DE4 /* QQBullet.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499F65DC139CBCBA00309DE4 /* QQBullet.mm */; }; + 499F65E7139CBCBA00309DE4 /* QQTank.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65DD139CBCBA00309DE4 /* QQTank.h */; }; + 499F65E8139CBCBA00309DE4 /* QQTank.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499F65DE139CBCBA00309DE4 /* QQTank.mm */; }; + 499F65E9139CBCBA00309DE4 /* QQUnit.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65DF139CBCBA00309DE4 /* QQUnit.h */; }; + 499F65EA139CBCBA00309DE4 /* QQUnit.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499F65E0139CBCBA00309DE4 /* QQUnit.mm */; }; + 499F65EC139CBCC000309DE4 /* QQGameTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 499F65EB139CBCC000309DE4 /* QQGameTime.h */; }; 49D8645D1392DB2800BC341C /* QQShape.h in Headers */ = {isa = PBXBuildFile; fileRef = 49D8645B1392DB2800BC341C /* QQShape.h */; }; 49D8645E1392DB2800BC341C /* QQShape.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49D8645C1392DB2800BC341C /* QQShape.mm */; }; 49DA67D4137847A7004841E9 /* QQWorld.h in Headers */ = {isa = PBXBuildFile; fileRef = 49DA67D2137847A7004841E9 /* QQWorld.h */; }; @@ -66,8 +70,6 @@ 49E3C5D3139A73E700A3958A /* NSSet+QQExtensions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49E3C5D1139A73E700A3958A /* NSSet+QQExtensions.mm */; }; 49E67E11139B341600DDFC07 /* TanksMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 49E67E10139B341600DDFC07 /* TanksMacros.h */; }; 49E834A713812427007A6598 /* QQActive.h in Headers */ = {isa = PBXBuildFile; fileRef = 49E8349E13812427007A6598 /* QQActive.h */; }; - 49E834A813812427007A6598 /* QQActor.h in Headers */ = {isa = PBXBuildFile; fileRef = 49E834A013812427007A6598 /* QQActor.h */; }; - 49E834A913812427007A6598 /* QQActor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49E834A113812427007A6598 /* QQActor.mm */; }; 49E834AC13812427007A6598 /* QQDisplayable.h in Headers */ = {isa = PBXBuildFile; fileRef = 49E834A413812427007A6598 /* QQDisplayable.h */; }; 49E834AE13812427007A6598 /* QQGame.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49E834A613812427007A6598 /* QQGame.mm */; }; 49E834BE13812555007A6598 /* QQAppDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 49E834B013812555007A6598 /* QQAppDelegate.h */; }; @@ -208,13 +210,7 @@ 492D80CB138B231B0042D918 /* QQPhysical.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QQPhysical.h; path = src/game/QQPhysical.h; sourceTree = SOURCE_ROOT; }; 492D80DE138BA4910042D918 /* QQCooldown.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQCooldown.h; sourceTree = ""; }; 492D80DF138BA4910042D918 /* QQCooldown.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQCooldown.mm; sourceTree = ""; }; - 492D80E9138BA4B40042D918 /* QQTank.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQTank.h; sourceTree = ""; }; - 492D80EA138BA4B40042D918 /* QQTank.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQTank.mm; sourceTree = ""; }; - 492D80EE138BA4BC0042D918 /* QQBullet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQBullet.h; sourceTree = ""; }; - 492D80EF138BA4BC0042D918 /* QQBullet.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQBullet.mm; sourceTree = ""; }; 492D80F2138BA4CE0042D918 /* QQThing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQThing.h; sourceTree = ""; }; - 492D80FC138BCA840042D918 /* QQUnit.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQUnit.mm; sourceTree = ""; }; - 492D80FE138BCC9F0042D918 /* QQActorDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQActorDelegate.h; sourceTree = ""; }; 492D8101138C07540042D918 /* BEParallaxSprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BEParallaxSprite.h; sourceTree = ""; }; 492D8102138C07540042D918 /* BEParallaxSprite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BEParallaxSprite.m; sourceTree = ""; }; 492D8103138C07540042D918 /* SHCircle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SHCircle.h; sourceTree = ""; }; @@ -227,16 +223,11 @@ 492D810A138C07540042D918 /* SXFPSMeter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SXFPSMeter.h; sourceTree = ""; }; 492D810B138C07540042D918 /* SXFPSMeter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SXFPSMeter.m; sourceTree = ""; }; 494DE9961376927C00FDB3D7 /* libBox2D.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libBox2D.a; sourceTree = SOURCE_ROOT; }; - 4978AD0D1395E5CE00930447 /* QQActors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQActors.h; sourceTree = ""; }; 4978AD131396139100930447 /* Tanks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tanks.h; sourceTree = ""; }; 4978AD161396302300930447 /* QQContactNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQContactNotification.h; sourceTree = ""; }; 4978AD171396302300930447 /* QQContactNotification.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQContactNotification.mm; sourceTree = ""; }; 4978AD181396302300930447 /* QQPhysicalEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQPhysicalEvents.h; sourceTree = ""; }; 4978AD191396302300930447 /* QQPhysicalEvents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQPhysicalEvents.mm; sourceTree = ""; }; - 4978AD1F1396302F00930447 /* QQNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQNotification.h; sourceTree = ""; }; - 4978AD201396302F00930447 /* QQNotification.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQNotification.mm; sourceTree = ""; }; - 4978AD211396302F00930447 /* QQNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQNotifier.h; sourceTree = ""; }; - 4978AD241396302F00930447 /* QQObservable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQObservable.h; sourceTree = ""; }; 4995ABCA1381C46B00334646 /* Icon-iPad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-iPad.png"; sourceTree = ""; }; 4995ABCB1381C46B00334646 /* Icon-iPhone.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-iPhone.png"; sourceTree = ""; }; 4995ABCC1381C46B00334646 /* Icon-iPhone@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-iPhone@2x.png"; sourceTree = ""; }; @@ -272,10 +263,26 @@ 49966914136930E8006E8125 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; }; 49966915136930E8006E8125 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; 49966916136930E8006E8125 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - 499D6A981399BFB8008E4C0D /* QQNotificationCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQNotificationCenter.h; sourceTree = ""; }; - 499D6A991399BFB8008E4C0D /* QQNotificationCenter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQNotificationCenter.mm; sourceTree = ""; }; - 499D6A9A1399BFB8008E4C0D /* QQNotificationProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQNotificationProxy.h; sourceTree = ""; }; - 499D6A9B1399BFB8008E4C0D /* QQNotificationProxy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQNotificationProxy.mm; sourceTree = ""; }; + 499F65C0139CBC0C00309DE4 /* QQNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQNotification.h; sourceTree = ""; }; + 499F65C1139CBC0C00309DE4 /* QQNotification.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQNotification.mm; sourceTree = ""; }; + 499F65C2139CBC0C00309DE4 /* QQNotificationCenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQNotificationCenter.h; sourceTree = ""; }; + 499F65C3139CBC0C00309DE4 /* QQNotificationCenter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQNotificationCenter.mm; sourceTree = ""; }; + 499F65C4139CBC0C00309DE4 /* QQNotificationProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQNotificationProxy.h; sourceTree = ""; }; + 499F65C5139CBC0C00309DE4 /* QQNotificationProxy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQNotificationProxy.mm; sourceTree = ""; }; + 499F65C6139CBC0C00309DE4 /* QQNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQNotifier.h; sourceTree = ""; }; + 499F65C7139CBC0C00309DE4 /* QQNotifiers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQNotifiers.h; sourceTree = ""; }; + 499F65C8139CBC0C00309DE4 /* QQObservable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQObservable.h; sourceTree = ""; }; + 499F65D7139CBCBA00309DE4 /* QQActor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQActor.h; sourceTree = ""; }; + 499F65D8139CBCBA00309DE4 /* QQActor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQActor.mm; sourceTree = ""; }; + 499F65D9139CBCBA00309DE4 /* QQActorDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQActorDelegate.h; sourceTree = ""; }; + 499F65DA139CBCBA00309DE4 /* QQActors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQActors.h; sourceTree = ""; }; + 499F65DB139CBCBA00309DE4 /* QQBullet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQBullet.h; sourceTree = ""; }; + 499F65DC139CBCBA00309DE4 /* QQBullet.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQBullet.mm; sourceTree = ""; }; + 499F65DD139CBCBA00309DE4 /* QQTank.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQTank.h; sourceTree = ""; }; + 499F65DE139CBCBA00309DE4 /* QQTank.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQTank.mm; sourceTree = ""; }; + 499F65DF139CBCBA00309DE4 /* QQUnit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQUnit.h; sourceTree = ""; }; + 499F65E0139CBCBA00309DE4 /* QQUnit.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQUnit.mm; sourceTree = ""; }; + 499F65EB139CBCC000309DE4 /* QQGameTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQGameTime.h; sourceTree = ""; }; 49D8645B1392DB2800BC341C /* QQShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQShape.h; sourceTree = ""; }; 49D8645C1392DB2800BC341C /* QQShape.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQShape.mm; sourceTree = ""; }; 49DA67D2137847A7004841E9 /* QQWorld.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQWorld.h; sourceTree = ""; }; @@ -284,9 +291,6 @@ 49E3C5D1139A73E700A3958A /* NSSet+QQExtensions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSSet+QQExtensions.mm"; sourceTree = ""; }; 49E67E10139B341600DDFC07 /* TanksMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TanksMacros.h; sourceTree = ""; }; 49E8349E13812427007A6598 /* QQActive.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQActive.h; sourceTree = ""; }; - 49E834A013812427007A6598 /* QQActor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQActor.h; sourceTree = ""; }; - 49E834A113812427007A6598 /* QQActor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQActor.mm; sourceTree = ""; }; - 49E834A213812427007A6598 /* QQUnit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQUnit.h; sourceTree = ""; }; 49E834A413812427007A6598 /* QQDisplayable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQDisplayable.h; sourceTree = ""; }; 49E834A513812427007A6598 /* QQGame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QQGame.h; sourceTree = ""; }; 49E834A613812427007A6598 /* QQGame.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QQGame.mm; sourceTree = ""; }; @@ -447,24 +451,6 @@ path = ability; sourceTree = ""; }; - 492D80E8138BA4B40042D918 /* unit */ = { - isa = PBXGroup; - children = ( - 492D80E9138BA4B40042D918 /* QQTank.h */, - 492D80EA138BA4B40042D918 /* QQTank.mm */, - ); - path = unit; - sourceTree = ""; - }; - 492D80ED138BA4BC0042D918 /* bullet */ = { - isa = PBXGroup; - children = ( - 492D80EE138BA4BC0042D918 /* QQBullet.h */, - 492D80EF138BA4BC0042D918 /* QQBullet.mm */, - ); - path = bullet; - sourceTree = ""; - }; 492D8100138C07540042D918 /* Extras */ = { isa = PBXGroup; children = ( @@ -497,16 +483,9 @@ 4978AD1E1396302E00930447 /* qq */ = { isa = PBXGroup; children = ( + 499F65BF139CBC0C00309DE4 /* event */, 49E3C5D0139A73E700A3958A /* NSSet+QQExtensions.h */, 49E3C5D1139A73E700A3958A /* NSSet+QQExtensions.mm */, - 499D6A981399BFB8008E4C0D /* QQNotificationCenter.h */, - 499D6A991399BFB8008E4C0D /* QQNotificationCenter.mm */, - 499D6A9A1399BFB8008E4C0D /* QQNotificationProxy.h */, - 499D6A9B1399BFB8008E4C0D /* QQNotificationProxy.mm */, - 4978AD1F1396302F00930447 /* QQNotification.h */, - 4978AD201396302F00930447 /* QQNotification.mm */, - 4978AD211396302F00930447 /* QQNotifier.h */, - 4978AD241396302F00930447 /* QQObservable.h */, ); path = qq; sourceTree = ""; @@ -621,37 +600,56 @@ name = Frameworks; sourceTree = ""; }; + 499F65BF139CBC0C00309DE4 /* event */ = { + isa = PBXGroup; + children = ( + 499F65C0139CBC0C00309DE4 /* QQNotification.h */, + 499F65C1139CBC0C00309DE4 /* QQNotification.mm */, + 499F65C2139CBC0C00309DE4 /* QQNotificationCenter.h */, + 499F65C3139CBC0C00309DE4 /* QQNotificationCenter.mm */, + 499F65C4139CBC0C00309DE4 /* QQNotificationProxy.h */, + 499F65C5139CBC0C00309DE4 /* QQNotificationProxy.mm */, + 499F65C6139CBC0C00309DE4 /* QQNotifier.h */, + 499F65C7139CBC0C00309DE4 /* QQNotifiers.h */, + 499F65C8139CBC0C00309DE4 /* QQObservable.h */, + ); + path = event; + sourceTree = ""; + }; + 499F65D6139CBCBA00309DE4 /* unit */ = { + isa = PBXGroup; + children = ( + 499F65D7139CBCBA00309DE4 /* QQActor.h */, + 499F65D8139CBCBA00309DE4 /* QQActor.mm */, + 499F65D9139CBCBA00309DE4 /* QQActorDelegate.h */, + 499F65DA139CBCBA00309DE4 /* QQActors.h */, + 499F65DB139CBCBA00309DE4 /* QQBullet.h */, + 499F65DC139CBCBA00309DE4 /* QQBullet.mm */, + 499F65DD139CBCBA00309DE4 /* QQTank.h */, + 499F65DE139CBCBA00309DE4 /* QQTank.mm */, + 499F65DF139CBCBA00309DE4 /* QQUnit.h */, + 499F65E0139CBCBA00309DE4 /* QQUnit.mm */, + ); + path = unit; + sourceTree = ""; + }; 49E8349D13812427007A6598 /* game */ = { isa = PBXGroup; children = ( + 499F65D6139CBCBA00309DE4 /* unit */, 49193BEE139280180005B3DD /* map */, 492D80DB138BA4910042D918 /* ability */, - 49E8349F13812427007A6598 /* actor */, 492D80F2138BA4CE0042D918 /* QQThing.h */, 49E8349E13812427007A6598 /* QQActive.h */, 49E834A413812427007A6598 /* QQDisplayable.h */, 492D80CB138B231B0042D918 /* QQPhysical.h */, + 499F65EB139CBCC000309DE4 /* QQGameTime.h */, 49E834A513812427007A6598 /* QQGame.h */, 49E834A613812427007A6598 /* QQGame.mm */, ); path = game; sourceTree = ""; }; - 49E8349F13812427007A6598 /* actor */ = { - isa = PBXGroup; - children = ( - 492D80ED138BA4BC0042D918 /* bullet */, - 492D80E8138BA4B40042D918 /* unit */, - 4978AD0D1395E5CE00930447 /* QQActors.h */, - 492D80FE138BCC9F0042D918 /* QQActorDelegate.h */, - 49E834A013812427007A6598 /* QQActor.h */, - 49E834A113812427007A6598 /* QQActor.mm */, - 49E834A213812427007A6598 /* QQUnit.h */, - 492D80FC138BCA840042D918 /* QQUnit.mm */, - ); - path = actor; - sourceTree = ""; - }; 49E834AF13812555007A6598 /* ui */ = { isa = PBXGroup; children = ( @@ -707,15 +705,15 @@ 49F2D9AE13764666000B6B8C /* src */ = { isa = PBXGroup; children = ( - 4978AD1E1396302E00930447 /* qq */, 49F2D9B313764666000B6B8C /* render */, 49E834AF13812555007A6598 /* ui */, + 4978AD1E1396302E00930447 /* qq */, 49F2D9B113764666000B6B8C /* physics */, 49E8349D13812427007A6598 /* game */, 49F2D9B013764666000B6B8C /* main.mm */, 49F2D9B213764666000B6B8C /* prefix.pch */, - 4978AD131396139100930447 /* Tanks.h */, 49E67E10139B341600DDFC07 /* TanksMacros.h */, + 4978AD131396139100930447 /* Tanks.h */, ); path = src; sourceTree = ""; @@ -1051,10 +1049,8 @@ 49DA67D4137847A7004841E9 /* QQWorld.h in Headers */, 4B8B2A50137D098500CA4076 /* QQAnimationContainer.h in Headers */, 49E834A713812427007A6598 /* QQActive.h in Headers */, - 49E834A813812427007A6598 /* QQActor.h in Headers */, 49E834AC13812427007A6598 /* QQDisplayable.h in Headers */, 4995ABB213816CCE00334646 /* QQGame.h in Headers */, - 4995ABB313816CD400334646 /* QQUnit.h in Headers */, 49E834BE13812555007A6598 /* QQAppDelegate.h in Headers */, 49E834C013812555007A6598 /* QQAppDelegate_iPad.h in Headers */, 49E834C313812555007A6598 /* QQAppDelegate_iPhone.h in Headers */, @@ -1063,23 +1059,27 @@ 49E834D3138166A6007A6598 /* QQSparrowExtensions.h in Headers */, 492D80CC138B231B0042D918 /* QQPhysical.h in Headers */, 492D80E4138BA4910042D918 /* QQCooldown.h in Headers */, - 492D80EB138BA4B40042D918 /* QQTank.h in Headers */, - 492D80F0138BA4BC0042D918 /* QQBullet.h in Headers */, 492D80F3138BA4CE0042D918 /* QQThing.h in Headers */, - 492D80FF138BCC9F0042D918 /* QQActorDelegate.h in Headers */, 49193BF5139280180005B3DD /* QQLevel.h in Headers */, 49D8645D1392DB2800BC341C /* QQShape.h in Headers */, - 4978AD0E1395E5CE00930447 /* QQActors.h in Headers */, 4978AD141396139100930447 /* Tanks.h in Headers */, 4978AD1A1396302300930447 /* QQContactNotification.h in Headers */, 4978AD1C1396302300930447 /* QQPhysicalEvents.h in Headers */, - 4978AD251396302F00930447 /* QQNotification.h in Headers */, - 4978AD271396302F00930447 /* QQNotifier.h in Headers */, - 4978AD2A1396302F00930447 /* QQObservable.h in Headers */, - 499D6A9C1399BFB8008E4C0D /* QQNotificationCenter.h in Headers */, - 499D6A9E1399BFB8008E4C0D /* QQNotificationProxy.h in Headers */, 49E3C5D2139A73E700A3958A /* NSSet+QQExtensions.h in Headers */, 49E67E11139B341600DDFC07 /* TanksMacros.h in Headers */, + 499F65C9139CBC0C00309DE4 /* QQNotification.h in Headers */, + 499F65CB139CBC0C00309DE4 /* QQNotificationCenter.h in Headers */, + 499F65CD139CBC0C00309DE4 /* QQNotificationProxy.h in Headers */, + 499F65CF139CBC0C00309DE4 /* QQNotifier.h in Headers */, + 499F65D0139CBC0C00309DE4 /* QQNotifiers.h in Headers */, + 499F65D1139CBC0C00309DE4 /* QQObservable.h in Headers */, + 499F65E1139CBCBA00309DE4 /* QQActor.h in Headers */, + 499F65E3139CBCBA00309DE4 /* QQActorDelegate.h in Headers */, + 499F65E4139CBCBA00309DE4 /* QQActors.h in Headers */, + 499F65E5139CBCBA00309DE4 /* QQBullet.h in Headers */, + 499F65E7139CBCBA00309DE4 /* QQTank.h in Headers */, + 499F65E9139CBCBA00309DE4 /* QQUnit.h in Headers */, + 499F65EC139CBCC000309DE4 /* QQGameTime.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1220,7 +1220,6 @@ 4B91A15A138F644000EF4D7C /* QQPhysicsDebugView.mm in Sources */, 49DA67D5137847A7004841E9 /* QQWorld.mm in Sources */, 4B8B2A51137D098500CA4076 /* QQAnimationContainer.mm in Sources */, - 49E834A913812427007A6598 /* QQActor.mm in Sources */, 49E834AE13812427007A6598 /* QQGame.mm in Sources */, 49E834BF13812555007A6598 /* QQAppDelegate.mm in Sources */, 49E834C113812555007A6598 /* QQAppDelegate_iPad.mm in Sources */, @@ -1228,18 +1227,19 @@ 49E834C713812555007A6598 /* QQViewport.mm in Sources */, 49E834D4138166A6007A6598 /* QQSparrowExtensions.mm in Sources */, 492D80E5138BA4910042D918 /* QQCooldown.mm in Sources */, - 492D80EC138BA4B40042D918 /* QQTank.mm in Sources */, - 492D80F1138BA4BC0042D918 /* QQBullet.mm in Sources */, - 492D80FD138BCA840042D918 /* QQUnit.mm in Sources */, 49193BF6139280180005B3DD /* QQLevel.mm in Sources */, 49F2D9C413764666000B6B8C /* main.mm in Sources */, 49D8645E1392DB2800BC341C /* QQShape.mm in Sources */, 4978AD1B1396302300930447 /* QQContactNotification.mm in Sources */, 4978AD1D1396302300930447 /* QQPhysicalEvents.mm in Sources */, - 4978AD261396302F00930447 /* QQNotification.mm in Sources */, - 499D6A9D1399BFB8008E4C0D /* QQNotificationCenter.mm in Sources */, - 499D6A9F1399BFB8008E4C0D /* QQNotificationProxy.mm in Sources */, 49E3C5D3139A73E700A3958A /* NSSet+QQExtensions.mm in Sources */, + 499F65CA139CBC0C00309DE4 /* QQNotification.mm in Sources */, + 499F65CC139CBC0C00309DE4 /* QQNotificationCenter.mm in Sources */, + 499F65CE139CBC0C00309DE4 /* QQNotificationProxy.mm in Sources */, + 499F65E2139CBCBA00309DE4 /* QQActor.mm in Sources */, + 499F65E6139CBCBA00309DE4 /* QQBullet.mm in Sources */, + 499F65E8139CBCBA00309DE4 /* QQTank.mm in Sources */, + 499F65EA139CBCBA00309DE4 /* QQUnit.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; -- 1.7.0.4