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

Added initial window handling.

git-svn-id: http://xni.googlecode.com/svn/XNI@7 ac433895-eea3-a490-d80a-17149a75e588
This commit is contained in:
Matej Jan 2010-07-22 16:13:55 +00:00
parent 43c1f445db
commit e8b63f4208
14 changed files with 435 additions and 3 deletions

View File

@ -0,0 +1,6 @@
typedef enum {
DisplayOrientationDefault = 0,
DisplayOrientationLandscapeLeft = 1,
DisplayOrientationLandscapeRight = 2,
DisplayOrientationPortrait
} DisplayOrientation;

View File

@ -0,0 +1,26 @@
//
// GameHost.h
// XNI
//
// Created by Matej Jan on 20.7.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Retronator.Xni.Framework.classes.h"
@interface GameHost : UIApplication {
BOOL isExiting;
//Game *game;
GameWindow *window;
}
@property (nonatomic, readonly) GameWindow *window;
- (void) initialize;
- (void) run;
- (void) exit;
@end

View File

@ -0,0 +1,65 @@
//
// GameHost.m
// XNI
//
// Created by Matej Jan on 20.7.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import "GameHost.h"
#import "Retronator.Xni.Framework.h"
@implementation GameHost
- (id) init {
if (self = [super init]) {
window = [[GameWindow alloc] init];
}
return self;
}
@synthesize window;
- (void) initialize {
[window initialize];
}
- (void) run {
// Hijack the run loop.
NSLog(@"Starting the game loop.");
//game = [self delegate];
SInt32 runResult;
while (!isExiting)
{
// We run a very tight autorelease pool loop.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Handle all the waiting event sources.
do {
runResult = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES);
} while (runResult == kCFRunLoopRunHandledSource);
//[game tick];
// We release memory every frame.
[pool release];
}
}
- (void) exit {
NSLog(@"Exiting the game loop.");
isExiting = YES;
}
- (void) dealloc
{
[window release];
[super dealloc];
}
@end

View File

@ -0,0 +1,19 @@
//
// GameView.h
// XNI
//
// Created by Matej Jan on 22.7.10.
// Copyright 2010 Retronator, Razum. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "System.h"
@interface GameView : UIView {
Event *viewSizeChanged;
}
@property (nonatomic, readonly) Event *viewSizeChanged;
@end

View File

@ -0,0 +1,47 @@
//
// GameView.m
// XNI
//
// Created by Matej Jan on 22.7.10.
// Copyright 2010 Retronator, Razum. All rights reserved.
//
#import "GameView.h"
#import <QuartzCore/QuartzCore.h>
@implementation GameView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
viewSizeChanged = [[Event alloc] init];
CAEAGLLayer *eaglLayer = (CAEAGLLayer*)self.layer;
eaglLayer.opaque = TRUE;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
}
return self;
}
@synthesize viewSizeChanged;
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
- (void) layoutSubviews
{
[viewSizeChanged raiseWithSender:self];
}
- (void) dealloc
{
[viewSizeChanged release];
[super dealloc];
}
@end

View File

@ -0,0 +1,18 @@
//
// GameViewController.h
// XNI
//
// Created by Matej Jan on 22.7.10.
// Copyright 2010 Retronator, Razum. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Retronator.Xni.Framework.classes.h"
@interface GameViewController : UIViewController {
GameWindow *gameWindow;
}
- initWithGameWindow: (GameWindow*)theGameWindow;
@end

View File

@ -0,0 +1,73 @@
//
// GameViewController.m
// XNI
//
// Created by Matej Jan on 22.7.10.
// Copyright 2010 Retronator, Razum. All rights reserved.
//
#import "GameViewController.h"
#import "Retronator.Xni.Framework.h"
@implementation GameViewController
- initWithGameWindow: (GameWindow*)theGameWindow {
if (self = [super init]) {
gameWindow = theGameWindow;
}
return self;
}
- (void)loadView {
GameView *gameView = [[GameView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
self.view = gameView;
[gameView release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//InterfaceOrientationFlags orientationFlag = 1 << interfaceOrientation;
return YES;// gameWindow.allowedOrientations & orientationFlag;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
// Touches
/*
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[MultiTouch instance].touchesBegan fireWithSender:self eventArgs:[TouchEventArgs argsWithTouches:touches event:event]];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[[MultiTouch instance].touchesMoved fireWithSender:self eventArgs:[TouchEventArgs argsWithTouches:touches event:event]];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[MultiTouch instance].touchesEnded fireWithSender:self eventArgs:[TouchEventArgs argsWithTouches:touches event:event]];
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[[MultiTouch instance].touchesCancelled fireWithSender:self eventArgs:[TouchEventArgs argsWithTouches:touches event:event]];
}*/
- (void)dealloc {
[super dealloc];
}
@end

View File

@ -0,0 +1,38 @@
//
// GameWindow.h
// XNI
//
// Created by Matej Jan on 20.7.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "System.h"
#import "Retronator.Xni.Framework.classes.h"
@interface GameWindow : NSObject {
Rectangle *clientBounds;
DisplayOrientation currentOrientation;
Event *clientSizeChanged;
Event *orientationChanged;
UIWindow *window;
GameViewController *gameViewController;
}
@property (nonatomic, readonly) Rectangle *clientBounds;
@property (nonatomic, readonly) DisplayOrientation currentOrientation;
@property (nonatomic, readonly) id handle;
@property (nonatomic, readonly) Event *clientSizeChanged;
@property (nonatomic, readonly) Event *orientationChanged;
- (void) initialize;
- (void) beginScreenDeviceChangeWithFullscreen:(BOOL)willBeFullscreen;
- (void) endScreenDeviceChange;
@end

View File

@ -0,0 +1,82 @@
//
// GameWindow.m
// XNI
//
// Created by Matej Jan on 20.7.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import "GameWindow.h"
#import "Retronator.Xni.Framework.h"
@implementation GameWindow
- (id) init {
if (self = [super init]) {
clientBounds = [[Rectangle empty] retain];
currentOrientation = DisplayOrientationDefault;
clientSizeChanged = [[Event alloc] init];
orientationChanged = [[Event alloc] init];
}
return self;
}
// PROPERTIES
@synthesize clientBounds;
@synthesize currentOrientation;
@synthesize clientSizeChanged;
@synthesize orientationChanged;
- (id) handle {
return nil;//(id)gameViewController.view.layer;
}
// METHODS
- (void) initialize {
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Initialize game view controller.
gameViewController = [[GameViewController alloc] initWithGameWindow:self];
[((GameView*)gameViewController.view).viewSizeChanged
subscribeDelegate:[Delegate delegateWithTarget:self Method:@selector(gameViewSizeChanged)]];
// Add the game view to the window.
[window addSubview: gameViewController.view];
// Present the window.
[window makeKeyAndVisible];
}
- (void) beginScreenDeviceChangeWithFullscreen:(BOOL)willBeFullscreen {
gameViewController.wantsFullScreenLayout = willBeFullscreen;
[[UIApplication sharedApplication] setStatusBarHidden:willBeFullscreen];
gameViewController.view.frame = [UIScreen mainScreen].applicationFrame;
clientBounds = [Rectangle rectangleWithCGRect:gameViewController.view.bounds];
}
- (void) endScreenDeviceChange {
}
- (void) gameViewSizeChanged {
Rectangle *newClientBounds = [Rectangle rectangleWithCGRect:gameViewController.view.bounds];
if (![newClientBounds equals:clientBounds]) {
[clientBounds release];
clientBounds = [newClientBounds retain];
[clientSizeChanged raiseWithSender:self];
}
}
- (void) dealloc
{
[clientBounds release];
[gameViewController release];
[window release];
[super dealloc];
}
@end

View File

@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "Retronator.Xni.Framework.classes.h"
@ -21,6 +22,7 @@
+ (Rectangle*) rectangleWithX:(int)x Y:(int)y Width:(int)width Height:(int)height;
+ (Rectangle*) rectangleWithStruct:(RectangleStruct*) rectangleStruct;
+ (Rectangle*) rectangleWithRectangle:(Rectangle*) rectangle;
+ (Rectangle*) rectangleWithCGRect:(CGRect) cgRect;
@property (nonatomic) int x;
@property (nonatomic) int y;
@ -29,6 +31,8 @@
@property (nonatomic, readonly) RectangleStruct *data;
- (BOOL) equals:(Rectangle*)rectangle;
+ (Rectangle*) empty;
@end

View File

@ -11,6 +11,8 @@
@implementation Rectangle
// CONSTRUCTORS
- (id) initWithX:(int)x Y:(int)y Width:(int)width Height:(int)height {
if (self = [super init]) {
data = RectangleMake(x, y, width, height);
@ -41,6 +43,13 @@
return [[[Rectangle alloc] initWithRectangle:rectangle] autorelease];
}
+ (Rectangle*) rectangleWithCGRect:(CGRect) cgRect {
return [Rectangle rectangleWithX:cgRect.origin.x Y:cgRect.origin.y
Width:cgRect.size.width Height:cgRect.size.height];
}
// PROPERTIES
- (int) x {return data.x;}
- (void) setX:(int)value {data.x = value;}
@ -55,6 +64,26 @@
- (RectangleStruct*) data {return &data;}
// METHODS
- (BOOL) equals:(Rectangle*)rectangle {
return rectangle.data->x == data.x && rectangle.data->y == data.y &&
rectangle.data->width == data.width && rectangle.data->height == data.height;
}
- (BOOL) isEqual:(id)object {
if ([object isKindOfClass:[Rectangle class]]) {
return [self equals:object];
}
return NO;
}
- (NSUInteger) hash {
return data.x ^ data.y ^ data.width ^ data.height;
}
// CONSTANTS
+ (Rectangle*) empty {return [Rectangle rectangleWithX:0 Y:0 Width:0 Height:0];}
@end

View File

@ -1,3 +1,7 @@
// Data structures
#import "RectangleStruct.h"
@class Rectangle;
@class Rectangle;
// Host
#import "DisplayOrientation.h"
@class GameWindow, GameViewController, GameView;

View File

@ -1,2 +1,7 @@
// Data structures
#import "Rectangle.h"
#import "Rectangle.h"
// Host
#import "GameWindow.h"
#import "GameViewController.h"
#import "GameView.h"

View File

@ -26,6 +26,10 @@
B5DE190511F88AF500BF3275 /* Rectangle.m in Sources */ = {isa = PBXBuildFile; fileRef = B5DE190311F88AF500BF3275 /* Rectangle.m */; };
B5DE190711F88B5D00BF3275 /* RectangleStruct.h in Headers */ = {isa = PBXBuildFile; fileRef = B5DE190611F88B5D00BF3275 /* RectangleStruct.h */; };
B5DE193111F898AE00BF3275 /* DisplayOrientation.h in Headers */ = {isa = PBXBuildFile; fileRef = B5DE193011F898AE00BF3275 /* DisplayOrientation.h */; };
B5DE194A11F89C0900BF3275 /* GameViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = B5DE194811F89C0900BF3275 /* GameViewController.h */; };
B5DE194B11F89C0900BF3275 /* GameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B5DE194911F89C0900BF3275 /* GameViewController.m */; };
B5DE194E11F89C1F00BF3275 /* GameView.h in Headers */ = {isa = PBXBuildFile; fileRef = B5DE194C11F89C1F00BF3275 /* GameView.h */; };
B5DE194F11F89C1F00BF3275 /* GameView.m in Sources */ = {isa = PBXBuildFile; fileRef = B5DE194D11F89C1F00BF3275 /* GameView.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -49,6 +53,10 @@
B5DE190311F88AF500BF3275 /* Rectangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Rectangle.m; sourceTree = "<group>"; };
B5DE190611F88B5D00BF3275 /* RectangleStruct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RectangleStruct.h; sourceTree = "<group>"; };
B5DE193011F898AE00BF3275 /* DisplayOrientation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayOrientation.h; sourceTree = "<group>"; };
B5DE194811F89C0900BF3275 /* GameViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameViewController.h; sourceTree = "<group>"; };
B5DE194911F89C0900BF3275 /* GameViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameViewController.m; sourceTree = "<group>"; };
B5DE194C11F89C1F00BF3275 /* GameView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameView.h; sourceTree = "<group>"; };
B5DE194D11F89C1F00BF3275 /* GameView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameView.m; sourceTree = "<group>"; };
D2AAC07E0554694100DB518D /* libXNI.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libXNI.a; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@ -131,12 +139,16 @@
B5DE18A011F8888B00BF3275 /* Retronator.Xni.Framework.h */,
B5DE18FA11F88AD900BF3275 /* GameHost.h */,
B5DE18FB11F88AD900BF3275 /* GameHost.m */,
B5DE193011F898AE00BF3275 /* DisplayOrientation.h */,
B5DE18FC11F88AD900BF3275 /* GameWindow.h */,
B5DE18FD11F88AD900BF3275 /* GameWindow.m */,
B5DE190611F88B5D00BF3275 /* RectangleStruct.h */,
B5DE190211F88AF500BF3275 /* Rectangle.h */,
B5DE190311F88AF500BF3275 /* Rectangle.m */,
B5DE193011F898AE00BF3275 /* DisplayOrientation.h */,
B5DE194811F89C0900BF3275 /* GameViewController.h */,
B5DE194911F89C0900BF3275 /* GameViewController.m */,
B5DE194C11F89C1F00BF3275 /* GameView.h */,
B5DE194D11F89C1F00BF3275 /* GameView.m */,
);
path = Framework;
sourceTree = "<group>";
@ -175,6 +187,8 @@
B5DE190411F88AF500BF3275 /* Rectangle.h in Headers */,
B5DE190711F88B5D00BF3275 /* RectangleStruct.h in Headers */,
B5DE193111F898AE00BF3275 /* DisplayOrientation.h in Headers */,
B5DE194A11F89C0900BF3275 /* GameViewController.h in Headers */,
B5DE194E11F89C1F00BF3275 /* GameView.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -227,6 +241,8 @@
B5DE18FF11F88AD900BF3275 /* GameHost.m in Sources */,
B5DE190111F88AD900BF3275 /* GameWindow.m in Sources */,
B5DE190511F88AF500BF3275 /* Rectangle.m in Sources */,
B5DE194B11F89C0900BF3275 /* GameViewController.m in Sources */,
B5DE194F11F89C1F00BF3275 /* GameView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};