Skip to content

Commit

Permalink
Fix Alfredo window management
Browse files Browse the repository at this point in the history
  • Loading branch information
justindriggers committed Mar 1, 2024
1 parent 641d998 commit 3d615b8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions alfredo/src/appkit/AlfredoApplicationDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
@property(nonatomic, strong) NSWindow *window;
@property(nonatomic, strong) MTKView *view;
@property(nonatomic, retain) id<MTLDevice> device;
@property(nonatomic) std::shared_ptr<LifecycleManager> lifecycleManager;
@end
10 changes: 4 additions & 6 deletions alfredo/src/appkit/AlfredoApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self.view setEnableSetNeedsDisplay:NO];
((CAMetalLayer*)[self.view layer]).displaySyncEnabled = NO;

self.lifecycleManager = std::make_shared<MacLifecycleManager>();

auto mtkTextureLoader = [[MTKTextureLoader alloc] initWithDevice:self.device];
auto metalTextureLoader = std::make_unique<MacMetalTextureLoader>(mtkTextureLoader);
auto metalRenderBackend = render::MetalRenderBackend::create(*(__bridge MTK::View*)self.view, std::move(metalTextureLoader));
Expand All @@ -85,11 +87,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification {
auto audioManager = std::make_shared<audio::AudioEngineAudioManager>(std::move(audioFileLoader));
auto inputManager = std::make_shared<MacInputManager>();
auto leaderboardManager = std::make_shared<MacLeaderboardManager>();
auto lifecycleManager = std::make_shared<MacLifecycleManager>();
auto renderer = std::make_shared<Renderer>(std::move(metalRenderBackend));
auto saveManager = std::make_shared<MacSaveManager>();
auto timeManager = std::make_shared<MacTimeManager>();
auto engine = std::make_unique<Engine>(logger, audioManager, inputManager, leaderboardManager, lifecycleManager, renderer, saveManager, timeManager);
auto engine = std::make_unique<Engine>(logger, audioManager, inputManager, leaderboardManager, self.lifecycleManager, renderer, saveManager, timeManager);

_viewDelegate = [[AlfredoViewDelegate alloc] initWithEngine:std::move(engine)];

Expand All @@ -101,10 +102,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self.window makeKeyAndOrderFront:nil];

[NSApp activateIgnoringOtherApps:YES];

while (lifecycleManager->isRunning()) {
[self.view draw];
}
[NSApp stop:nil];
}
}

Expand Down
14 changes: 8 additions & 6 deletions alfredo/src/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
using namespace linguine;

int main(int argc, const char *argv[]) {
@autoreleasepool {
NSApplication *app = NSApplication.sharedApplication;
NSApplication *app = NSApplication.sharedApplication;

AlfredoApplicationDelegate *appDelegate = [[AlfredoApplicationDelegate alloc] init];
app.delegate = appDelegate;
AlfredoApplicationDelegate *appDelegate = [[AlfredoApplicationDelegate alloc] init];
app.delegate = appDelegate;

[app run];
[app run];

return 0;
while (appDelegate.lifecycleManager->isRunning()) {
[appDelegate.view draw];
}

return 0;
}
8 changes: 8 additions & 0 deletions alfredo/src/platform/MacInputManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

if (mouseLocation.x < 0.0f || mouseLocation.x > frameSize.width
|| mouseLocation.y < 0.0f || mouseLocation.y > frameSize.height) {
[app sendEvent:event];
break;
}

Expand All @@ -55,6 +56,7 @@

if (mouseLocation.x < 0.0f || mouseLocation.x > frameSize.width
|| mouseLocation.y < 0.0f || mouseLocation.y > frameSize.height) {
[app sendEvent:event];
break;
}

Expand All @@ -72,6 +74,7 @@

if (mouseLocation.x < 0.0f || mouseLocation.x > frameSize.width
|| mouseLocation.y < 0.0f || mouseLocation.y > frameSize.height) {
[app sendEvent:event];
break;
}

Expand All @@ -87,6 +90,7 @@

if (mouseLocation.x < 0.0f || mouseLocation.x > frameSize.width
|| mouseLocation.y < 0.0f || mouseLocation.y > frameSize.height) {
[app sendEvent:event];
break;
}

Expand All @@ -105,6 +109,10 @@
break;
case kVK_ANSI_W:
_keyStates[Key::W] = true;

if (event.modifierFlags & NSEventModifierFlagCommand) {
[app sendEvent:event];
}
break;
case kVK_ANSI_E:
_keyStates[Key::E] = true;
Expand Down

0 comments on commit 3d615b8

Please sign in to comment.