Changeset 739


Ignore:
Timestamp:
Mar 13, 2011, 1:58:53 AM (9 years ago)
Author:
sam
Message:

ios: clean up code.

Location:
trunk/monsterz/ios
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/ios/classes/EAGLView.h

    r731 r739  
    11//
    2 //  EAGLView.h
    3 //  Monsterz
     2// Monsterz
    43//
    5 //  Created by user on 05.03.11.
    6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
     4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
     5//   This program is free software; you can redistribute it and/or
     6//   modify it under the terms of the Do What The Fuck You Want To
     7//   Public License, Version 2, as published by Sam Hocevar. See
     8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
    79//
    810
     
    1416#import <OpenGLES/ES2/glext.h>
    1517
    16 // This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
    17 // The view content is basically an EAGL surface you render your OpenGL scene into.
    18 // Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
     18// This class wraps the CAEAGLLayer from CoreAnimation into a convenient
     19// UIView subclass. The view content is basically an EAGL surface you
     20// render your OpenGL scene into. Note that setting the view non-opaque
     21// will only work if the EAGL surface has an alpha channel.
    1922@interface EAGLView : UIView
    2023{
    2124@private
    2225    EAGLContext *context;
    23    
     26
    2427    // The pixel dimensions of the CAEAGLLayer.
    2528    GLint framebufferWidth;
    2629    GLint framebufferHeight;
    27    
    28     // The OpenGL ES names for the framebuffer and renderbuffer used to render to this view.
     30
     31    // The OpenGL ES names for the framebuffer and renderbuffer used to
     32    // render to this view.
    2933    GLuint defaultFramebuffer, colorRenderbuffer;
    3034}
     
    3640
    3741@end
     42
  • trunk/monsterz/ios/classes/EAGLView.m

    r731 r739  
    11//
    2 //  EAGLView.m
    3 //  Monsterz
     2// Monsterz
    43//
    5 //  Created by user on 05.03.11.
    6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
     4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
     5//   This program is free software; you can redistribute it and/or
     6//   modify it under the terms of the Do What The Fuck You Want To
     7//   Public License, Version 2, as published by Sam Hocevar. See
     8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
    79//
    810
     
    2628}
    2729
    28 //The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:.
     30// The EAGL view is stored in the nib file. When it's unarchived it's sent
     31// -initWithCoder:.
    2932- (id)initWithCoder:(NSCoder*)coder
    3033{
    3134    self = [super initWithCoder:coder];
    32         if (self)
     35    if (self)
    3336    {
    3437        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
    35        
     38
    3639        eaglLayer.opaque = TRUE;
    3740        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
     
    4043                                        nil];
    4144    }
    42    
     45
    4346    return self;
    4447}
     
    4649- (void)dealloc
    4750{
    48     [self deleteFramebuffer];   
     51    [self deleteFramebuffer];
    4952    [context release];
    50    
    5153    [super dealloc];
    5254}
     
    6264    {
    6365        [self deleteFramebuffer];
    64        
    6566        [context release];
    6667        context = [newContext retain];
    67        
    6868        [EAGLContext setCurrentContext:nil];
    6969    }
     
    7575    {
    7676        [EAGLContext setCurrentContext:context];
    77        
     77
    7878        // Create default framebuffer object.
    7979        glGenFramebuffers(1, &defaultFramebuffer);
    8080        glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
    81        
     81
    8282        // Create color render buffer and allocate backing store.
    8383        glGenRenderbuffers(1, &colorRenderbuffer);
     
    8686        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth);
    8787        glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight);
    88        
     88
    8989        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer);
    90        
     90
    9191        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
    9292            NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatus(GL_FRAMEBUFFER));
     
    9999    {
    100100        [EAGLContext setCurrentContext:context];
    101        
     101
    102102        if (defaultFramebuffer)
    103103        {
     
    105105            defaultFramebuffer = 0;
    106106        }
    107        
     107
    108108        if (colorRenderbuffer)
    109109        {
     
    119119    {
    120120        [EAGLContext setCurrentContext:context];
    121        
     121
    122122        if (!defaultFramebuffer)
    123123            [self createFramebuffer];
    124        
     124
    125125        glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
    126        
    127126        glViewport(0, 0, framebufferWidth, framebufferHeight);
    128127    }
     
    132131{
    133132    BOOL success = FALSE;
    134    
     133
    135134    if (context)
    136135    {
    137136        [EAGLContext setCurrentContext:context];
    138        
    139137        glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer);
    140        
    141138        success = [context presentRenderbuffer:GL_RENDERBUFFER];
    142139    }
    143    
     140
    144141    return success;
    145142}
     
    147144- (void)layoutSubviews
    148145{
    149     // The framebuffer will be re-created at the beginning of the next setFramebuffer method call.
     146    // The framebuffer will be re-created at the beginning of the next
     147    // setFramebuffer method call.
    150148    [self deleteFramebuffer];
    151149}
    152150
    153151@end
     152
  • trunk/monsterz/ios/classes/MonsterzAppDelegate.h

    r731 r739  
    11//
    2 //  MonsterzAppDelegate.h
    3 //  Monsterz
     2// Monsterz
    43//
    5 //  Created by user on 05.03.11.
    6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
     4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
     5//   This program is free software; you can redistribute it and/or
     6//   modify it under the terms of the Do What The Fuck You Want To
     7//   Public License, Version 2, as published by Sam Hocevar. See
     8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
    79//
    810
     
    1113@class MonsterzViewController;
    1214
    13 @interface MonsterzAppDelegate : NSObject <UIApplicationDelegate> {
     15@interface MonsterzAppDelegate : NSObject <UIApplicationDelegate>
     16{
    1417    UIWindow *window;
    1518    MonsterzViewController *viewController;
  • trunk/monsterz/ios/classes/MonsterzAppDelegate.m

    r731 r739  
    11//
    2 //  MonsterzAppDelegate.m
    3 //  Monsterz
     2// Monsterz
    43//
    5 //  Created by user on 05.03.11.
    6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
     4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
     5//   This program is free software; you can redistribute it and/or
     6//   modify it under the terms of the Do What The Fuck You Want To
     7//   Public License, Version 2, as published by Sam Hocevar. See
     8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
    79//
    810
     
    5052    [viewController release];
    5153    [window release];
    52    
    5354    [super dealloc];
    5455}
    5556
    5657@end
     58
  • trunk/monsterz/ios/classes/MonsterzViewController.h

    r731 r739  
    11//
    2 //  MonsterzViewController.h
    3 //  Monsterz
     2// Monsterz
    43//
    5 //  Created by user on 05.03.11.
    6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
     4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
     5//   This program is free software; you can redistribute it and/or
     6//   modify it under the terms of the Do What The Fuck You Want To
     7//   Public License, Version 2, as published by Sam Hocevar. See
     8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
    79//
    810
     
    1921{
    2022    EAGLContext *context;
    21    
     23
    2224    BOOL animating;
    2325    NSInteger animationFrameInterval;
     
    3234
    3335@end
     36
  • trunk/monsterz/ios/classes/MonsterzViewController.mm

    r731 r739  
    11//
    2 //  MonsterzViewController.m
    3 //  Monsterz
     2// Monsterz
    43//
    5 //  Created by user on 05.03.11.
    6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
     4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
     5//   This program is free software; you can redistribute it and/or
     6//   modify it under the terms of the Do What The Fuck You Want To
     7//   Public License, Version 2, as published by Sam Hocevar. See
     8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
    79//
    810
     
    3133- (void)awakeFromNib
    3234{
    33         Ticker::Setup(30.0f);
    34         Video::Setup(320, 480);
    35        
    36         new Interface();
    37         new DebugFps(20, 20);
    38        
     35    Ticker::Setup(30.0f);
     36    Video::Setup(320, 480);
     37
     38    new Interface();
     39    new DebugFps(20, 20);
     40
    3941    EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
    4042    if (!aContext)
     
    4244    else if (![EAGLContext setCurrentContext:aContext])
    4345        NSLog(@"Failed to set ES context current");
    44    
    45         self.context = aContext;
    46         [aContext release];
    47        
     46
     47    self.context = aContext;
     48    [aContext release];
     49
    4850    [(EAGLView *)self.view setContext:context];
    4951    [(EAGLView *)self.view setFramebuffer];
    50    
     52
    5153    animating = FALSE;
    5254    animationFrameInterval = 1;
     
    5961    if ([EAGLContext currentContext] == context)
    6062        [EAGLContext setCurrentContext:nil];
    61    
     63
    6264    [context release];
    63    
    6465    [super dealloc];
    6566}
     
    6869{
    6970    [self startAnimation];
    70    
    7171    [super viewWillAppear:animated];
    7272}
     
    7575{
    7676    [self stopAnimation];
    77    
    7877    [super viewWillDisappear:animated];
    7978}
     
    8180- (void)viewDidUnload
    8281{
    83         [super viewDidUnload];
     82    [super viewDidUnload];
    8483
    8584    // Tear down context.
    8685    if ([EAGLContext currentContext] == context)
    8786        [EAGLContext setCurrentContext:nil];
    88         self.context = nil;     
     87    self.context = nil;
    8988}
    9089
     
    9695- (void)setAnimationFrameInterval:(NSInteger)frameInterval
    9796{
    98     /*
    99          Frame interval defines how many display frames must pass between each time the display link fires.
    100          The display link will only fire 30 times a second when the frame internal is two on a display that refreshes 60 times a second. The default frame interval setting of one will fire 60 times a second when the display refreshes at 60 times a second. A frame interval setting of less than one results in undefined behavior.
    101          */
     97    /* Frame interval defines how many display frames must pass between each
     98     * time the display link fires. The display link will only fire 30 times
     99     * a second when the frame internal is two on a display that refreshes
     100     * 60 times a second. The default frame interval setting of one will
     101     * fire 60 times a second when the display refreshes at 60 times a
     102     * second. A frame interval setting of less than one results in undefined
     103     * behavior. */
    102104    if (frameInterval >= 1)
    103105    {
    104106        animationFrameInterval = frameInterval;
    105        
     107
    106108        if (animating)
    107109        {
     
    120122        [aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    121123        self.displayLink = aDisplayLink;
    122        
     124
    123125        animating = TRUE;
    124126    }
     
    138140{
    139141    [(EAGLView *)self.view setFramebuffer];
    140    
    141         Ticker::ClampFps();
    142         Ticker::TickGame();
    143         Ticker::TickDraw();
    144 
     142    Ticker::ClampFps();
     143    Ticker::TickGame();
     144    Ticker::TickDraw();
    145145    [(EAGLView *)self.view presentFramebuffer];
    146146}
     
    150150    // Releases the view if it doesn't have a superview.
    151151    [super didReceiveMemoryWarning];
    152    
    153152    // Release any cached data, images, etc. that aren't in use.
    154153}
    155154
    156155@end
     156
  • trunk/monsterz/ios/main.m

    r731 r739  
    11//
    2 //  main.m
    3 //  Monsterz
     2// Monsterz
    43//
    5 //  Created by user on 05.03.11.
    6 //  Copyright 2011 __MyCompanyName__. All rights reserved.
     4// Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
     5//   This program is free software; you can redistribute it and/or
     6//   modify it under the terms of the Do What The Fuck You Want To
     7//   Public License, Version 2, as published by Sam Hocevar. See
     8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
    79//
    810
    911#import <UIKit/UIKit.h>
    1012
    11 int main(int argc, char *argv[]) {
    12    
     13int main(int argc, char *argv[])
     14{
    1315    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    1416    int retVal = UIApplicationMain(argc, argv, nil, nil);
Note: See TracChangeset for help on using the changeset viewer.