Hey all. I'm new to Apple's ecosystem and need some help with a few basics.
Specifically, I've started with Xcode 14's metal game code and am struggling to read user inputs. I've tried variations of the below without luck:
#import "GameViewController.h"
#import "Renderer.h"
@interface InputView : NSView
@end
@implementation InputView
- (BOOL)acceptsFirstResponder{ return YES; }
- (void)mouseDown:(NSEvent*)event
{
printf("mouse down");
}
- (void)keyDown:(NSEvent *)event
{
printf("key down");
}
@end
@implementation GameViewController
{
MTKView *_view;
InputView *_input_view;
Renderer *_renderer;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_view = (MTKView *)self.view;
_view.device = MTLCreateSystemDefaultDevice();
if(!_view.device)
{
NSLog(@"Metal is not supported on this device");
self.view = [[NSView alloc] initWithFrame:self.view.frame];
return;
}
_renderer = [[Renderer alloc] initWithMetalKitView:_view];
[_renderer mtkView:_view drawableSizeWillChange:_view.bounds.size];
_view.delegate = _renderer;
_input_view = [[InputView alloc] initWithFrame:_view.frame];
BOOL fr = [_input_view becomeFirstResponder];
printf("fr %d\n", fr);
}
@end
But I also don't understand the basic structure of this boilerplate application. I see my main file is this:
#import <Cocoa/Cocoa.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
}
return NSApplicationMain(argc, argv);
}
It doesn't seem to touch any of the rest of the code (GameViewController, AppDelegate, etc.), and yet it obviously does, since it runs and renders things. I assume some build magic is happening, but where can I find information on that? What official resources can I read to understand how this app is being built? I've been having a lot of trouble navigating Apple's official documentation and could use some direction.
1
0
760