Send events through queue instead of calling game methods directly

This commit is contained in:
Phil Marell
2021-08-08 16:59:27 +10:00
parent 744b06796d
commit 5b5fb15780
6 changed files with 54 additions and 11 deletions

View File

@@ -1,10 +1,9 @@
#import "AerofoilAppDelegate.h"
#import "About.h"
#import "AerofoilApplication.h"
#include "WindowManager.h"
#include "GliderDefines.h" // kPlayMode
extern short theMode;
void DoSettingsMain(void);
@interface AerofoilAppDelegate ()
@@ -17,19 +16,13 @@ void DoSettingsMain(void);
@implementation AerofoilAppDelegate
- (IBAction)showAboutAerofoil:(id)sender {
[self performAsynchronously:DoAboutFramework];
[NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutAerofoil];
}
- (IBAction)showAboutGliderPRO:(id)sender {
[self performAsynchronously:DoAbout];
[NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutGliderPRO];
}
- (IBAction)showPreferences:(id)sender {
[self performAsynchronously:DoSettingsMain];
}
- (void)performAsynchronously:(void(*)())function {
dispatch_async(dispatch_get_main_queue(), ^{
function();
});
[NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kPreferences];
}
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {

View File

@@ -1,9 +1,12 @@
#import <Cocoa/Cocoa.h>
#include "GpVOSEvent.h"
NS_ASSUME_NONNULL_BEGIN
@interface AerofoilApplication : NSApplication
- (void)sendMenuItemEvent:(GpMenuItemSelectionEvent_t)itemEvent;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,4 +1,6 @@
#import "AerofoilApplication.h"
#include "IGpVOSEventQueue.h"
#include "GpAppInterface.h"
#include "SDL.h"
@implementation AerofoilApplication
@@ -10,4 +12,17 @@
SDL_PushEvent(&event);
}
- (void)sendMenuItemEvent:(GpMenuItemSelectionEvent_t)itemEvent {
GpVOSEvent event;
event.m_eventType = GpVOSEventTypes::kMenuItemSelected;
event.m_event.m_menuItemSelectionEvent = itemEvent;
[self sendVOSEvent:event];
}
- (void)sendVOSEvent:(GpVOSEvent)event {
IGpVOSEventQueue* queue = GpAppInterface_Get()->PL_GetDriverCollection()->GetDriver<GpDriverIDs::kEventQueue>();
if (GpVOSEvent *evt = queue->QueueEvent())
*evt = event;
}
@end