mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 06:53:43 +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 "AerofoilAppDelegate.h"
|
||||||
#import "About.h"
|
#import "AerofoilApplication.h"
|
||||||
#include "WindowManager.h"
|
#include "WindowManager.h"
|
||||||
#include "GliderDefines.h" // kPlayMode
|
#include "GliderDefines.h" // kPlayMode
|
||||||
|
|
||||||
extern short theMode;
|
extern short theMode;
|
||||||
void DoSettingsMain(void);
|
|
||||||
|
|
||||||
@interface AerofoilAppDelegate ()
|
@interface AerofoilAppDelegate ()
|
||||||
|
|
||||||
@@ -17,19 +16,13 @@ void DoSettingsMain(void);
|
|||||||
@implementation AerofoilAppDelegate
|
@implementation AerofoilAppDelegate
|
||||||
|
|
||||||
- (IBAction)showAboutAerofoil:(id)sender {
|
- (IBAction)showAboutAerofoil:(id)sender {
|
||||||
[self performAsynchronously:DoAboutFramework];
|
[NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutAerofoil];
|
||||||
}
|
}
|
||||||
- (IBAction)showAboutGliderPRO:(id)sender {
|
- (IBAction)showAboutGliderPRO:(id)sender {
|
||||||
[self performAsynchronously:DoAbout];
|
[NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kAboutGliderPRO];
|
||||||
}
|
}
|
||||||
- (IBAction)showPreferences:(id)sender {
|
- (IBAction)showPreferences:(id)sender {
|
||||||
[self performAsynchronously:DoSettingsMain];
|
[NSApp sendMenuItemEvent:GpMenuItemSelectionEvents::kPreferences];
|
||||||
}
|
|
||||||
|
|
||||||
- (void)performAsynchronously:(void(*)())function {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
function();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
#include "GpVOSEvent.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface AerofoilApplication : NSApplication
|
@interface AerofoilApplication : NSApplication
|
||||||
|
|
||||||
|
- (void)sendMenuItemEvent:(GpMenuItemSelectionEvent_t)itemEvent;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
#import "AerofoilApplication.h"
|
#import "AerofoilApplication.h"
|
||||||
|
#include "IGpVOSEventQueue.h"
|
||||||
|
#include "GpAppInterface.h"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
@implementation AerofoilApplication
|
@implementation AerofoilApplication
|
||||||
@@ -10,4 +12,17 @@
|
|||||||
SDL_PushEvent(&event);
|
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
|
@end
|
||||||
|
@@ -466,6 +466,21 @@ void HandleEvent (void)
|
|||||||
break;
|
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
|
else
|
||||||
HandleIdleTask();
|
HandleIdleTask();
|
||||||
|
@@ -270,6 +270,17 @@ struct GpVideoResolutionChangedEvent
|
|||||||
uint32_t m_newHeight;
|
uint32_t m_newHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace GpMenuItemSelectionEvents
|
||||||
|
{
|
||||||
|
enum GpMenuItemSelectionEvent {
|
||||||
|
kAboutGliderPRO,
|
||||||
|
kAboutAerofoil,
|
||||||
|
kPreferences
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef GpMenuItemSelectionEvents::GpMenuItemSelectionEvent GpMenuItemSelectionEvent_t;
|
||||||
|
|
||||||
namespace GpVOSEventTypes
|
namespace GpVOSEventTypes
|
||||||
{
|
{
|
||||||
enum GpVOSEventType
|
enum GpVOSEventType
|
||||||
@@ -279,6 +290,7 @@ namespace GpVOSEventTypes
|
|||||||
kTouchInput,
|
kTouchInput,
|
||||||
kGamepadInput,
|
kGamepadInput,
|
||||||
kVideoResolutionChanged,
|
kVideoResolutionChanged,
|
||||||
|
kMenuItemSelected,
|
||||||
kQuit
|
kQuit
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -294,6 +306,7 @@ struct GpVOSEvent
|
|||||||
GpTouchInputEvent m_touchInputEvent;
|
GpTouchInputEvent m_touchInputEvent;
|
||||||
GpGamepadInputEvent m_gamepadInputEvent;
|
GpGamepadInputEvent m_gamepadInputEvent;
|
||||||
GpVideoResolutionChangedEvent m_resolutionChangedEvent;
|
GpVideoResolutionChangedEvent m_resolutionChangedEvent;
|
||||||
|
GpMenuItemSelectionEvent_t m_menuItemSelectionEvent;
|
||||||
};
|
};
|
||||||
|
|
||||||
EventUnion m_event;
|
EventUnion m_event;
|
||||||
|
@@ -169,6 +169,10 @@ static void TranslateVOSEvent(const GpVOSEvent *vosEvent, uint32_t timestamp, Po
|
|||||||
appHandler->OnQuit();
|
appHandler->OnQuit();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
case GpVOSEventTypes::kMenuItemSelected:
|
||||||
|
if (TimeTaggedVOSEvent *evt = queue->Enqueue())
|
||||||
|
*evt = TimeTaggedVOSEvent::Create(*vosEvent, timestamp);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user