mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-22 22:45:39 +00:00
Send events through queue instead of calling game methods directly
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -466,6 +466,21 @@ void HandleEvent (void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (theEvent.m_vosEvent.m_eventType == GpVOSEventType_t::kMenuItemSelected)
|
||||
{
|
||||
switch (theEvent.m_vosEvent.m_event.m_menuItemSelectionEvent)
|
||||
{
|
||||
case GpMenuItemSelectionEvents::kAboutGliderPRO:
|
||||
DoAbout();
|
||||
break;
|
||||
case GpMenuItemSelectionEvents::kAboutAerofoil:
|
||||
DoAboutFramework();
|
||||
break;
|
||||
case GpMenuItemSelectionEvents::kPreferences:
|
||||
DoSettingsMain();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
HandleIdleTask();
|
||||
|
@@ -270,6 +270,17 @@ struct GpVideoResolutionChangedEvent
|
||||
uint32_t m_newHeight;
|
||||
};
|
||||
|
||||
namespace GpMenuItemSelectionEvents
|
||||
{
|
||||
enum GpMenuItemSelectionEvent {
|
||||
kAboutGliderPRO,
|
||||
kAboutAerofoil,
|
||||
kPreferences
|
||||
};
|
||||
}
|
||||
|
||||
typedef GpMenuItemSelectionEvents::GpMenuItemSelectionEvent GpMenuItemSelectionEvent_t;
|
||||
|
||||
namespace GpVOSEventTypes
|
||||
{
|
||||
enum GpVOSEventType
|
||||
@@ -279,6 +290,7 @@ namespace GpVOSEventTypes
|
||||
kTouchInput,
|
||||
kGamepadInput,
|
||||
kVideoResolutionChanged,
|
||||
kMenuItemSelected,
|
||||
kQuit
|
||||
};
|
||||
}
|
||||
@@ -294,6 +306,7 @@ struct GpVOSEvent
|
||||
GpTouchInputEvent m_touchInputEvent;
|
||||
GpGamepadInputEvent m_gamepadInputEvent;
|
||||
GpVideoResolutionChangedEvent m_resolutionChangedEvent;
|
||||
GpMenuItemSelectionEvent_t m_menuItemSelectionEvent;
|
||||
};
|
||||
|
||||
EventUnion m_event;
|
||||
|
@@ -169,6 +169,10 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po
|
||||
appHandler->OnQuit();
|
||||
|
||||
break;
|
||||
case GpVOSEventTypes::kMenuItemSelected:
|
||||
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
|
||||
*evt = TimeTaggedVOSEvent::Create(*vosEvent, timestamp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user