Attempts to add debug view support. No idea why the linker is bitching.
authordsc <david.schoonover@gmail.com>
Fri, 27 May 2011 04:15:07 +0000 (21:15 -0700)
committerdsc <david.schoonover@gmail.com>
Fri, 27 May 2011 04:15:07 +0000 (21:15 -0700)
12 files changed:
src/game/QQGame.h
src/game/QQGame.mm
src/physics/QQWorld.h
src/physics/QQWorld.mm
src/physics/debug/QQGLESDebugDraw.h
src/physics/debug/QQGLESDebugDraw.mm
src/physics/debug/QQPhysicsDebugView.h
src/physics/debug/QQPhysicsDebugView.mm
src/ui/QQAppDelegate.h
src/ui/QQAppDelegate.mm
src/ui/iPad/en.lproj/MainWindow_iPad.xib
src/ui/iPhone/en.lproj/MainWindow_iPhone.xib

index 835b132..e0a6ff1 100644 (file)
@@ -21,6 +21,8 @@
 @property (nonatomic, retain) QQWorld* world;
 @property (nonatomic, retain) NSSet* actors;
 
+- (void) tick:(float)elapsed;
+
 - (QQGame*) addActor:(QQActor*)actor;
 - (QQGame*) removeActor:(QQActor*)actor;
 
index 1ed5ff4..fbfc2c5 100644 (file)
@@ -69,22 +69,24 @@ static QQGame* _CurrentGame = NULL;
 
 
 - (void) onEnterFrame:(SPEnterFrameEvent*)event {
+    [self tick:event.passedTime];
+}
+
+- (void) tick:(float)elapsed {
     _ticks++;
     if ((_ticks % 100) == 0) {
-        NSLog(@"[%ld] Time passed since last 100 frames: %f", _ticks, event.passedTime);
+        NSLog(@"[%ld] Time passed since last 100 frames: %f", _ticks, elapsed);
         for (QQActor* actor in self.actors) {
             b2Vec2 v = actor.body->GetLinearVelocity();
             NSLog(@"[%@ pos:(%f,%f) impulse:(%f,%f)]", actor, actor.x,actor.y, v.x,v.y);
         }
     }
     
-    for (QQActor* actor in self.actors) [actor tick:event.passedTime]; // XXX: self.awakeAgents
+    for (QQActor* actor in self.actors) [actor tick:elapsed]; // XXX: self.awakeAgents
     [self.world step];
     for (QQActor* actor in self.actors) [actor draw];    // XXX: self.drawableAgents
 }
 
-
-
 + (QQGame*) current {
     if (!_CurrentGame)
         [[[QQGame alloc] init]  // init assigns to singleton, but singleton is a weakref,
index 91f505a..eeb4c96 100644 (file)
@@ -5,14 +5,14 @@
 @interface QQWorld : NSObject {
 
 @private
-    QQGLESDebugDraw debugDraw;
+    QQGLESDebugDraw* _debugDraw;
     b2World* _world;
     NSMutableArray* _walls;
     
     float   _timestep;
     int     _velocityIterations;
     int     _positionIterations;
-    BOOL    _drawDebugLayer;
+    BOOL    _debugDrawingEnabled;
     float   _scale;
 }
 
@@ -21,7 +21,7 @@
 @property (nonatomic, assign) float timestep;
 @property (nonatomic, assign) int   velocityIterations;
 @property (nonatomic, assign) int   positionIterations;
-@property (nonatomic, assign) BOOL  drawDebugLayer;
+@property (nonatomic, assign) BOOL  debugDrawingEnabled;
 @property (nonatomic, assign) float scale; // pixels per meter
 
 
@@ -30,6 +30,7 @@
 - (void) setGravityX:(float)x y:(float)y;
 
 - (void) step;
+- (void) drawDebug;
 
 
 @end
index ed986f9..d97bf1c 100644 (file)
@@ -6,13 +6,13 @@
 
 @implementation QQWorld
 
-@synthesize timestep           = _timestep;
-@synthesize velocityIterations = _velocityIterations;
-@synthesize positionIterations = _positionIterations;
-@synthesize drawDebugLayer     = _drawDebugLayer;
-@synthesize scale              = _scale;
+@synthesize timestep            = _timestep;
+@synthesize velocityIterations  = _velocityIterations;
+@synthesize positionIterations  = _positionIterations;
+@synthesize debugDrawingEnabled = _debugDrawingEnabled;
+@synthesize scale               = _scale;
 
-@synthesize world              = _world;
+@synthesize world               = _world;
 
 
 - (QQWorld*) init {
         _timestep = 1.0f/60.0f;
         _velocityIterations = 10;
         _positionIterations = 10;
-        _drawDebugLayer = NO;
+        _debugDrawingEnabled = NO;
         _scale = 5.0f;
         
         _world = new b2World(b2Vec2(0.0f, 0.0f), true); // b2World(gravity, doSleep)
-        // _world->SetDebugDraw(&debugDraw);
+        _debugDraw = new QQGLESDebugDraw();
+        _world->SetDebugDraw(_debugDraw);
         
         _walls = [[NSMutableArray alloc] initWithCapacity:4];
         
 
 - (void) step {
     _world->Step(self.timestep, self.velocityIterations, self.positionIterations);
-    #ifdef DEBUG
-        if (_drawDebugLayer) _world->DrawDebugData();
-    #endif
+}
+
+- (void) drawDebug {
+    if (_debugDrawingEnabled) _world->DrawDebugData();
 }
 
 - (void) setGravityX:(float)x y:(float)y {
index 058ac90..eb08b8e 100644 (file)
@@ -35,17 +35,21 @@ struct b2AABB;
 class QQGLESDebugDraw : public b2DebugDraw
 {
 public:
-       void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
+    float32 globalAlpha;
+    
+    QQGLESDebugDraw();
+    
+    void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
 
-       void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
+    void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
 
-       void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color);
+    void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color);
 
-       void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color);
+    void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color);
 
-       void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color);
+    void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color);
 
-       void DrawTransform(const b2Transform& xf);
+    void DrawTransform(const b2Transform& xf);
 
     void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color);
 
index 674f60e..7aaea54 100644 (file)
 
 #include <cstring>
 
+QQGLESDebugDraw::QQGLESDebugDraw() {
+    globalAlpha = 1;
+}
+
 void QQGLESDebugDraw::DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
 {
-       glColor4f(color.r, color.g, color.b,1);
-       glVertexPointer(2, GL_FLOAT, 0, vertices);
-       glDrawArrays(GL_LINE_LOOP, 0, vertexCount);
+    glColor4f(color.r, color.g, color.b, globalAlpha);
+    glVertexPointer(2, GL_FLOAT, 0, vertices);
+    glDrawArrays(GL_LINE_LOOP, 0, vertexCount);
 }
 
 void QQGLESDebugDraw::DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
 {
-       glVertexPointer(2, GL_FLOAT, 0, vertices);
-       
-       glColor4f(color.r, color.g, color.b,0.5f);
-       glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);
-       
-       glColor4f(color.r, color.g, color.b,1);
-       glDrawArrays(GL_LINE_LOOP, 0, vertexCount);
+    glVertexPointer(2, GL_FLOAT, 0, vertices);
+    
+    glColor4f(color.r, color.g, color.b, 0.5f*globalAlpha);
+    glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);
+    
+    glColor4f(color.r, color.g, color.b, globalAlpha);
+    glDrawArrays(GL_LINE_LOOP, 0, vertexCount);
 }
 
 void QQGLESDebugDraw::DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color)
 {
-       const float32 k_segments = 16.0f;
-       int vertexCount=16;
-       const float32 k_increment = 2.0f * b2_pi / k_segments;
-       float32 theta = 0.0f;
-       
-       GLfloat                         glVertices[vertexCount*2];
-       for (int32 i = 0; i < k_segments; ++i)
-       {
-               b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
-               glVertices[i*2]=v.x;
-               glVertices[i*2+1]=v.y;
-               theta += k_increment;
-       }
-       
-       glColor4f(color.r, color.g, color.b,1);
-       glVertexPointer(2, GL_FLOAT, 0, glVertices);
-       
-       glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);
+    const float32 k_segments = 16.0f;
+    int vertexCount=16;
+    const float32 k_increment = 2.0f * b2_pi / k_segments;
+    float32 theta = 0.0f;
+    
+    GLfloat             glVertices[vertexCount*2];
+    for (int32 i = 0; i < k_segments; ++i)
+    {
+        b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
+        glVertices[i*2]=v.x;
+        glVertices[i*2+1]=v.y;
+        theta += k_increment;
+    }
+    
+    glColor4f(color.r, color.g, color.b, globalAlpha);
+    glVertexPointer(2, GL_FLOAT, 0, glVertices);
+    
+    glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);
 }
 
 void QQGLESDebugDraw::DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color)
 {
-       const float32 k_segments = 16.0f;
-       int vertexCount=16;
-       const float32 k_increment = 2.0f * b2_pi / k_segments;
-       float32 theta = 0.0f;
-       
-       GLfloat                         glVertices[vertexCount*2];
-       for (int32 i = 0; i < k_segments; ++i)
-       {
-               b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
-               glVertices[i*2]=v.x;
-               glVertices[i*2+1]=v.y;
-               theta += k_increment;
-       }
-       
-       glColor4f(color.r, color.g, color.b,0.5f);
-       glVertexPointer(2, GL_FLOAT, 0, glVertices);
-       glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);
-       glColor4f(color.r, color.g, color.b,1);
-       glDrawArrays(GL_LINE_LOOP, 0, vertexCount);
-       
-       // Draw the axis line
-       DrawSegment(center,center+radius*axis,color);
+    const float32 k_segments = 16.0f;
+    int vertexCount=16;
+    const float32 k_increment = 2.0f * b2_pi / k_segments;
+    float32 theta = 0.0f;
+    
+    GLfloat             glVertices[vertexCount*2];
+    for (int32 i = 0; i < k_segments; ++i)
+    {
+        b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
+        glVertices[i*2]=v.x;
+        glVertices[i*2+1]=v.y;
+        theta += k_increment;
+    }
+    
+    glColor4f(color.r, color.g, color.b, 0.5f*globalAlpha);
+    glVertexPointer(2, GL_FLOAT, 0, glVertices);
+    glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);
+    glColor4f(color.r, color.g, color.b, globalAlpha);
+    glDrawArrays(GL_LINE_LOOP, 0, vertexCount);
+    
+    // Draw the axis line
+    DrawSegment(center,center+radius*axis,color);
 }
 
 void QQGLESDebugDraw::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
 {
-       glColor4f(color.r, color.g, color.b,1);
-       GLfloat                         glVertices[] = {
-               p1.x,p1.y,p2.x,p2.y
-       };
-       glVertexPointer(2, GL_FLOAT, 0, glVertices);
-       glDrawArrays(GL_LINES, 0, 2);
+    glColor4f(color.r, color.g, color.b, globalAlpha);
+    GLfloat             glVertices[] = {
+        p1.x,p1.y,p2.x,p2.y
+    };
+    glVertexPointer(2, GL_FLOAT, 0, glVertices);
+    glDrawArrays(GL_LINES, 0, 2);
 }
 
 void QQGLESDebugDraw::DrawTransform(const b2Transform& xf)
 {
-       b2Vec2 p1 = xf.position, p2;
-       const float32 k_axisScale = 0.4f;
-
-       p2 = p1 + k_axisScale * xf.R.col1;
-       DrawSegment(p1,p2,b2Color(1,0,0));
-       
-       p2 = p1 + k_axisScale * xf.R.col2;
-       DrawSegment(p1,p2,b2Color(0,1,0));
+    b2Vec2 p1 = xf.position, p2;
+    const float32 k_axisScale = 0.4f;
+
+    p2 = p1 + k_axisScale * xf.R.col1;
+    DrawSegment(p1,p2,b2Color(1,0,0));
+    
+    p2 = p1 + k_axisScale * xf.R.col2;
+    DrawSegment(p1,p2,b2Color(0,1,0));
 }
 
 void QQGLESDebugDraw::DrawPoint(const b2Vec2& p, float32 size, const b2Color& color)
 {
-       glColor4f(color.r, color.g, color.b,1);
-       glPointSize(size);
-       GLfloat                         glVertices[] = {
-               p.x,p.y
-       };
-       glVertexPointer(2, GL_FLOAT, 0, glVertices);
-       glDrawArrays(GL_POINTS, 0, 1);
-       glPointSize(1.0f);
+    glColor4f(color.r, color.g, color.b, globalAlpha);
+    glPointSize(size);
+    GLfloat             glVertices[] = {
+        p.x,p.y
+    };
+    glVertexPointer(2, GL_FLOAT, 0, glVertices);
+    glDrawArrays(GL_POINTS, 0, 1);
+    glPointSize(1.0f);
 }
 
 void QQGLESDebugDraw::DrawString(int x, int y, const char *string, ...)
 {
 
-       /* Unsupported as yet. Could replace with bitmap font renderer at a later date */
+    /* Unsupported as yet. Could replace with bitmap font renderer at a later date */
 }
 
 void QQGLESDebugDraw::DrawAABB(b2AABB* aabb, const b2Color& c)
 {
-       
-       glColor4f(c.r, c.g, c.b,1);
-
-       GLfloat                         glVertices[] = {
-               aabb->lowerBound.x, aabb->lowerBound.y,
-               aabb->upperBound.x, aabb->lowerBound.y,
-               aabb->upperBound.x, aabb->upperBound.y,
-               aabb->lowerBound.x, aabb->upperBound.y
-       };
-       glVertexPointer(2, GL_FLOAT, 0, glVertices);
-       glDrawArrays(GL_LINE_LOOP, 0, 8);
-       
+    
+    glColor4f(c.r, c.g, c.b, globalAlpha);
+
+    GLfloat             glVertices[] = {
+        aabb->lowerBound.x, aabb->lowerBound.y,
+        aabb->upperBound.x, aabb->lowerBound.y,
+        aabb->upperBound.x, aabb->upperBound.y,
+        aabb->lowerBound.x, aabb->upperBound.y
+    };
+    glVertexPointer(2, GL_FLOAT, 0, glVertices);
+    glDrawArrays(GL_LINE_LOOP, 0, 8);
+    
 }
index a8f63b6..261b7b5 100644 (file)
@@ -5,21 +5,50 @@
 
 #include <Box2D/Box2D.h>
 
-#import "physics/QQPhysicsView.h"
+#import "physics/QQWorld.h"
+
 
 /*
 This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
 The view content is basically an EAGL surface you render your OpenGL scene into.
 Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
 */
-@interface QQPhysicsDebugView : QQPhysicsView {}
+@interface QQPhysicsDebugView : UIView {
+@private
+    QQWorld* _world;
+    BOOL _panning;
 
-@property (nonatomic, readonly, getter=isRunning) BOOL running;
-@property (nonatomic, assign) NSTimeInterval animationInterval;
+    // Position offset and scale
+    float sceneScale;
+    CGPoint positionOffset;
+    
+    CGPoint lastWorldTouch;
+    CGPoint lastScreenTouch;
+    
+    b2MouseJoint* mouseJoint;
+    b2Vec2 mouseWorld;
+    int32 stepCount;
+    
+    /// OpenGL ///
+    
+    /* The pixel dimensions of the backbuffer */
+    GLint backingWidth;
+    GLint backingHeight;
+    
+    EAGLContext *context;
+    
+    /* OpenGL names for the renderbuffer and framebuffers used to render to this view */
+    GLuint viewRenderbuffer, viewFramebuffer;
+    
+    /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
+    GLuint depthRenderbuffer;
+    
+}
 
+@property (nonatomic, readwrite, retain) QQWorld* world;
+@property (nonatomic, readonly, assign, getter=isPanning) BOOL panning;
 
-- (void) startAnimation;
-- (void) stopAnimation;
+- (void) drawView;
 
 @end
 
index 6c48262..bd645ac 100644 (file)
 
 
 // A class extension to declare private methods
-@interface QQPhysicsDebugView () {
-
-@private
-    QQWorld* _world;
-    BOOL _running;
-    
-    NSTimer* animationTimer;
-    NSTimeInterval animationInterval;
-    BOOL panning;
-    
-    // Position offset and scale
-    float sceneScale;
-    CGPoint positionOffset;
-    
-    CGPoint lastWorldTouch;
-    CGPoint lastScreenTouch;
-    
-    b2MouseJoint* mouseJoint;
-    b2Vec2 mouseWorld;
-    int32 stepCount;
-
-    
-    /// OpenGL ///
-    
-    /* The pixel dimensions of the backbuffer */
-    GLint backingWidth;
-    GLint backingHeight;
-    
-    EAGLContext *context;
-    
-    /* OpenGL names for the renderbuffer and framebuffers used to render to this view */
-    GLuint viewRenderbuffer, viewFramebuffer;
-    
-    /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
-    GLuint depthRenderbuffer;
-    
-}
+@interface QQPhysicsDebugView ()
 
 @property (nonatomic, retain) EAGLContext *context;
-@property (nonatomic, assign) NSTimer *animationTimer;
+
+- (void) setup;
 
 - (BOOL) createFramebuffer;
 - (void) destroyFramebuffer;
 
+- (void) prepContext;
+- (void) flushContext;
+
 @end
 
 
 @implementation QQPhysicsDebugView
 
 @synthesize world = _world;
-@synthesize running = _running;
+@synthesize panning = _panning;
 
 @synthesize context;
-@synthesize animationTimer;
-@synthesize animationInterval;
 
 
 // You must implement this method
     return [CAEAGLLayer class];
 }
 
+- (id) initWithFrame:(CGRect)aRect {
+    if ((self = [super initWithFrame:aRect])) {
+        [self setup];
+    }
+    return self;
+}
 
 //The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
-- (id)initWithCoder:(NSCoder*)coder {
-    
+- (id) initWithCoder:(NSCoder*)coder {
     if ((self = [super initWithCoder:coder])) {
-        // Get the layer
-        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
-        
-        eaglLayer.opaque = YES;
-        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
-                                        [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
-        
-        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
-        
-        if (!context || ![EAGLContext setCurrentContext:context]) {
-            [self release];
-            return nil;
-        }
-        
-        _running = NO;
-        animationInterval = 1.0 / 60.0;
-        sceneScale = 10.0f;
-        positionOffset = CGPointMake(0, 0);
-        lastWorldTouch = CGPointMake(0, 0);
-        
-        [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)];
-        [[UIAccelerometer sharedAccelerometer] setDelegate:self];
+        [self setup];
     }
-    
     return self;
 }
 
-- (void) dealloc {
-    [self stopAnimation];
+- (void) setup {
+    // Get the layer
+    CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
     
-    if ([EAGLContext currentContext] == context) {
-        [EAGLContext setCurrentContext:nil];
+    eaglLayer.opaque = NO;
+    eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
+                                        [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking,
+                                        kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
+                                    nil];
+    
+    context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
+    
+    if (!context || ![EAGLContext setCurrentContext:context]) {
+        [self release];
+        return nil;
     }
     
-    [context release];
-    [super dealloc];
+    sceneScale = 10.0f;
+    positionOffset = CGPointMake(0,0);
+    lastWorldTouch = CGPointMake(0,0);
+    
+    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)];
+    [[UIAccelerometer sharedAccelerometer] setDelegate:self];
 }
 
-
-/// Accessors ///
-
-- (void) setAnimationTimer:(NSTimer*)newTimer {
-    [animationTimer invalidate];
-    animationTimer = newTimer;
+- (void) dealloc {
+    if ([EAGLContext currentContext] == context)
+        [EAGLContext setCurrentContext:nil];
+    [context release];
+    [_world release];
+    [super dealloc];
 }
 
-- (void) setAnimationInterval:(NSTimeInterval)interval {
-    animationInterval = interval;
-    if (animationTimer) {
-        [self stopAnimation];
-        [self startAnimation];
-    }
-}
 
 
 /// Methods ///
 
-- (void) startAnimation {
-    _running = YES;
-    self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
-}
-
-- (void) stopAnimation {
-    _running = NO;
-    self.animationTimer = nil;
-}
-
 - (CGPoint) screenSpaceToWorldSpace:(CGPoint) screenLocation {
     screenLocation.x -= 160;
     screenLocation.y -= 240;
 
 /// OpenGL ///
 
-- (void) drawView {
+- (void) layoutSubviews {
+    [EAGLContext setCurrentContext:context];
+    [self destroyFramebuffer];
+    [self createFramebuffer];
+    [self drawView];
+}
+
+- (void) prepContext {
     [EAGLContext setCurrentContext:context];
     
     glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
     
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
-    glTranslatef(positionOffset.x, positionOffset.y,0);
-    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+    glTranslatef(positionOffset.x, positionOffset.y, 0);
+    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     glClear(GL_COLOR_BUFFER_BIT);
     
     glEnable(GL_BLEND);
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
     glEnableClientState(GL_VERTEX_ARRAY);
-    
-    [self.world step];
-    
-    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
-    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
 }
 
+- (void) drawView {
+    [self prepContext];
+    [self.world drawDebug];
+    [self flushContext];
+}
 
-- (void) layoutSubviews {
-    [EAGLContext setCurrentContext:context];
-    [self destroyFramebuffer];
-    [self createFramebuffer];
-    [self drawView];
+- (void) flushContext {
+    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
+    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
 }
 
 
index f868fe1..29dbd78 100644 (file)
@@ -1,16 +1,19 @@
 #import "Sparrow.h"
 #import "game/QQGame.h"
+#import "physics/debug/QQPhysicsDebugView.h"
 
 
 @interface QQAppDelegate : NSObject <UIApplicationDelegate>
 {
     UIWindow* window;
     SPView* sparrowView;
+    QQPhysicsDebugView* _debugView;
     QQGame* _game;
 }
 
 @property (nonatomic, retain) IBOutlet UIWindow* window;
 @property (nonatomic, retain) IBOutlet SPView* sparrowView;
+@property (nonatomic, retain) QQPhysicsDebugView* debugView;
 @property (nonatomic, retain) QQGame* game;
 
 @end
\ No newline at end of file
index 7eaeb17..3e161ef 100644 (file)
@@ -13,6 +13,7 @@
 
 @synthesize window;
 @synthesize sparrowView;
+@synthesize debugView = _debugView;
 @synthesize game = _game;
 
 
         sparrowView.frameRate = 60.0f;
     // sparrowView.stage = [[[SPStage alloc] init] autorelease];
     
-    _game = [[QQGame alloc] init];
+    self.game = [[[QQGame alloc] init] autorelease];
     sparrowView.stage = _game;
+    self.debugView = [[[QQPhysicsDebugView alloc] initWithFrame:sparrowView.frame] autorelease];
+    [window addSubview:self.debugView];
     
     [window makeKeyAndVisible];
     [sparrowView start];
index f0d386c..50d6ea2 100644 (file)
@@ -40,7 +40,6 @@
                                                <string key="NSFrame">{{284, 501}, {200, 22}}</string>
                                                <reference key="NSSuperview" ref="62075450"/>
                                                <reference key="NSWindow"/>
-                                               <reference key="NSNextKeyView"/>
                                                <bool key="IBUIOpaque">NO</bool>
                                                <bool key="IBUIClipsSubviews">YES</bool>
                                                <int key="IBUIContentMode">7</int>
@@ -58,7 +57,7 @@
                                        <object class="IBUIView" id="607297697">
                                                <reference key="NSNextResponder" ref="62075450"/>
                                                <int key="NSvFlags">292</int>
-                                               <string key="NSFrame">{{0, 21}, {768, 1003}}</string>
+                                               <string key="NSFrameSize">{768, 1003}</string>
                                                <reference key="NSSuperview" ref="62075450"/>
                                                <reference key="NSWindow"/>
                                                <reference key="NSNextKeyView" ref="348798989"/>
@@ -83,9 +82,7 @@
                                </object>
                                <bool key="IBUIOpaque">NO</bool>
                                <bool key="IBUIClearsContextBeforeDrawing">NO</bool>
-                               <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics">
-                                       <int key="IBUIStatusBarStyle">2</int>
-                               </object>
+                               <bool key="IBUIMultipleTouchEnabled">YES</bool>
                                <string key="targetRuntimeIdentifier">IBIPadFramework</string>
                                <bool key="IBUIResizesToFullScreen">YES</bool>
                        </object>
index 32443c1..a5af9d2 100644 (file)
@@ -86,7 +86,7 @@
                                </object>
                                <bool key="IBUIOpaque">NO</bool>
                                <bool key="IBUIClearsContextBeforeDrawing">NO</bool>
-                               <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
+                               <bool key="IBUIMultipleTouchEnabled">YES</bool>
                                <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
                                <bool key="IBUIResizesToFullScreen">YES</bool>
                        </object>