mirror of
https://github.com/thes3m/XNI
synced 2024-12-26 13:26:06 +01:00
74 lines
1.4 KiB
Objective-C
74 lines
1.4 KiB
Objective-C
//
|
|
// GameHost.m
|
|
// XNI
|
|
//
|
|
// Created by Matej Jan on 20.7.10.
|
|
// Copyright 2010 Retronator. All rights reserved.
|
|
//
|
|
|
|
#import "GameHost.h"
|
|
#import <QuartzCore/QuartzCore.h>
|
|
|
|
#import "Retronator.Xni.Framework.h"
|
|
#import "Retronator.Xni.Framework.Media.h"
|
|
|
|
@implementation GameHost
|
|
|
|
- (id) init {
|
|
self = [super init];
|
|
if (self) {
|
|
[MediaPlayer load];
|
|
window = [[GameWindow alloc] init];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
@synthesize window;
|
|
|
|
- (void) run {
|
|
// Hijack the run loop.
|
|
NSLog(@"Starting the game loop.");
|
|
|
|
game = [self delegate];
|
|
|
|
|
|
SInt32 runResult;
|
|
|
|
isExiting = NO;
|
|
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];
|
|
}
|
|
|
|
/*
|
|
CADisplayLink *aDisplayLink = [CADisplayLink displayLinkWithTarget:game selector:@selector(tick)];
|
|
[aDisplayLink setFrameInterval:1];
|
|
[aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
|
*/
|
|
}
|
|
|
|
- (void) exit {
|
|
NSLog(@"Exiting the game loop.");
|
|
isExiting = YES;
|
|
}
|
|
|
|
- (void) dealloc
|
|
{
|
|
[window release];
|
|
[super dealloc];
|
|
}
|
|
|
|
|
|
@end
|