/[hegemonie]/hegemonie/Source/GameFrame.m
ViewVC logotype

Diff of /hegemonie/Source/GameFrame.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by zaral, Tue Aug 5 12:33:21 2003 UTC revision 1.4 by dam, Mon Aug 18 01:36:32 2003 UTC
# Line 21  Line 21 
21   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22   */   */
23    
24    #include <SDL/SDL_keysym.h> /* FIXME */
25    
26  #include <Foundation/NSObject.h>  #include <Foundation/NSObject.h>
27  #include <Foundation/NSException.h>  #include <Foundation/NSException.h>
28    #include <Foundation/NSDate.h>
29    #include <AppKit/NSEvent.h>
30    
31    #include "Interface/UiLabel.h"
32    
33  #include "Interface.h"  #include "Interface.h"
34  #include "GameWidget.h"  #include "GameWidget.h"
35  #include "GameFrame.h"  #include "GameFrame.h"
36    #include "JoinFrame.h"
37    
38    
39    @interface FrameCounter : UiLabel
40    {
41    @private
42      NSDate   *_date;
43      unsigned  _count;
44    }
45    
46    - (id) initWithPosition: (NSPoint)position;
47    
48    @end
49    
50    @implementation FrameCounter
51    
52    - (id) initWithPosition: (NSPoint)position
53    {
54      self = [super initWithText: @"0 fps"
55                        position: position];
56      if (self != nil)
57        {
58          _date = [[NSDate alloc] init];
59          _count = 0;
60        }
61    
62      return self;
63    }
64    
65    - (void) dealloc
66    {
67      RELEASE(_date);
68      
69      [super dealloc];
70    }
71    
72    - (void) _display
73    {
74      if (-[_date timeIntervalSinceNow] >= 1.0)
75        {
76          [self setText: [NSString stringWithFormat: @"%.1f fps",
77                                   (double)_count /-[_date timeIntervalSinceNow]]];
78          _count = 0;
79          ASSIGN(_date, [[NSDate alloc] init]);
80        }
81      _count++;
82    
83      [super _display];
84    }
85    
86    
87    @end
88    
89    @interface GameController : NSObject
90    {
91    @private
92      GameFrame *_view;
93    }
94    
95    - (id) initWithView: (GameFrame *)view;
96    - (BOOL) keyDown: (NSEvent *)event;
97    
98    @end
99    
100    @implementation GameController
101    
102    - (id) initWithView: (GameFrame *)view
103    {
104      NSParameterAssert (view);
105    
106      self = [super init];
107      if (self != nil)
108        {
109          _view = RETAIN(view);
110        }
111    
112      return self;
113    }
114    
115    - (void) dealloc
116    {
117      RELEASE(_view);
118    
119      [super dealloc];
120    }
121    
122    - (BOOL) keyDown: (NSEvent *)event
123    {
124      NSParameterAssert (event);
125    
126      if ([event keyCode] == SDLK_ESCAPE)
127        {
128          [[_view gameWidget] endGame];
129    
130          Interface *interface = [_view interface];
131          [interface setCurrentFrame: [interface joinFrame]];
132          return YES;
133        }
134      
135      return NO;
136    }
137    
138    @end
139    
140    
141  @implementation GameFrame  @implementation GameFrame
142    
# Line 37  Line 147 
147    self = [super initWithInterface: interface];    self = [super initWithInterface: interface];
148    if (self != nil)    if (self != nil)
149      {      {
150        _gameWidget = [[GameWidget alloc] init];        GameController *controller
151                  = [[GameController alloc] initWithView: self];
152          [self setDelegate: controller];
153          RELEASE (controller);
154    
155          _gameWidget = [[GameWidget alloc] init];      
156        [self addWidget: _gameWidget];        [self addWidget: _gameWidget];
157    
158          FrameCounter *counter
159            = [[FrameCounter alloc] initWithPosition: NSMakePoint (0.0f, 600.0f)];
160          [self addWidget: counter];
161          RELEASE(counter);
162      }      }
163    
164    return self;    return self;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26