Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/GameController.m
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ - (void) doPerformGameTick

@try
{
[gameView display];
[gameView updateScreen];
}
@catch (id exception) {}
}
Expand Down
10 changes: 4 additions & 6 deletions src/Core/NSBundle+Override.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#import <Foundation/Foundation.h>

@interface NSBundle (Override)
@interface NSBundle (ResourceOverride)

/**
* Overrides the standard -infoDictionary method via a category name-clash.
* Forces the bundle to manually load and return the contents of 'info-gnustep.plist'.
*/
- (NSDictionary *)infoDictionary;
// Declaring the swizzled method signature ensures clean compilation
// if referenced internally and establishes the category interface.
- (NSString *)oolite_resourcePath;

@end
90 changes: 42 additions & 48 deletions src/Core/NSBundle+Override.m
Original file line number Diff line number Diff line change
@@ -1,51 +1,45 @@
/*
* NSBundle+Override.m
*
* Oolite Core Framework Override
* Bypasses standard plist loading to manually locate and parse info-gnustep.plist
* across Windows and Linux environments safely at boot.
*/

#import "NSBundle+Override.h"
#import <Foundation/NSFileManager.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSDictionary.h>

@implementation NSBundle (Override)

- (NSDictionary *)infoDictionary {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *startingDir = [fileManager currentDirectoryPath]; // Start from cwd

NSString *primaryResourcesPath = [startingDir stringByAppendingPathComponent:@"Resources"];
BOOL isDir = NO;

NSString *resourcesFolder = nil;
if ([fileManager fileExistsAtPath:primaryResourcesPath isDirectory:&isDir] && isDir) {
resourcesFolder = primaryResourcesPath;
} else {
// Fallback: Look in startingDir / ../share/oolite/Resources (Standard Linux system layout)
NSString *fallbackPath = [[startingDir stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"share/oolite/Resources"];
resourcesFolder = [fallbackPath stringByStandardizingPath];
}

// Append the target file name to the resolved path root
NSString *plistPath = [resourcesFolder stringByAppendingPathComponent:@"Info-gnustep.plist"];

// Load the target configuration file
NSDictionary *gnustepPlist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
NSMutableDictionary *workingDict = nil;

if (gnustepPlist) {
workingDict = [gnustepPlist mutableCopy];
} else {
// Fallback block prevents runtime crashes if files are missing during dev/build refactors
workingDict = [[NSMutableDictionary alloc] init];
NSLog(@"[Oolite-Core] Warning: Failed to find info-gnustep.plist at calculated path: %@", plistPath);
}

// Return the dictionary cleanly managed for memory
return [workingDict autorelease];
#import <Foundation/Foundation.h>
#import <objc/runtime.h>

@implementation NSBundle (ResourceOverride)

+ (void)load {
// Synchronously swizzle -resourcePath when the category is loaded into memory.
Class class = [self class];
SEL originalSelector = @selector(resourcePath);
SEL swizzledSelector = @selector(oolite_resourcePath);

Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

if (originalMethod && swizzledMethod) {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}

- (NSString *)oolite_resourcePath {
// Guard: Only apply custom path resolution to the main application bundle.
// GNUstep internal framework bundles will fall back to default behaviour.
if (self != [NSBundle mainBundle]) {
return [self oolite_resourcePath];
}

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *startingDir = [fileManager currentDirectoryPath]; // Start from cwd

NSString *primaryResourcesPath = [startingDir stringByAppendingPathComponent:@"Resources"];
BOOL isDir = NO;

NSString *resourcesFolder = nil;
if ([fileManager fileExistsAtPath:primaryResourcesPath isDirectory:&isDir] && isDir) {
resourcesFolder = primaryResourcesPath;
} else {
// Fallback: Look in startingDir / ../share/oolite/Resources (Standard Linux system layout)
NSString *fallbackPath = [[startingDir stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"share/oolite/Resources"];
resourcesFolder = [fallbackPath stringByStandardizingPath];
}

return resourcesFolder;
}

@end
4 changes: 0 additions & 4 deletions src/SDL/MyOpenGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ extern int debug;
- (void) noteMouseInteractionModeChangedFrom:(OOMouseInteractionMode)oldMode to:(OOMouseInteractionMode)newMode;

- (void) initialiseGLWithSize:(NSSize) v_size;
- (void) initialiseGLWithSize:(NSSize) v_size useVideoMode:(BOOL) v_mode;
- (BOOL) isRunningOnPrimaryDisplayDevice;
#if OOLITE_WINDOWS
- (BOOL) getCurrentMonitorInfo:(MONITORINFOEX *)mInfo;
Expand All @@ -315,10 +314,7 @@ extern int debug;

- (void) stringToClipboard:(NSString *)stringToCopy;

- (void) drawRect:(NSRect)rect;
- (void) updateScreen;
- (void) updateScreenWithVideoMode:(BOOL) v_mode;
- (void) display;

- (BOOL) snapShot:(NSString *)filename;

Expand Down
97 changes: 3 additions & 94 deletions src/SDL/MyOpenGLView.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@

@interface MyOpenGLView (OOPrivate)

- (void) resetSDLKeyModifiers;
- (void) handleStringInput: (SDL_KeyboardEvent *) kbd_event keyID:(Uint16)key_id; // DJS
@end

Expand Down Expand Up @@ -765,39 +764,21 @@ - (NSSize) modeAsSize:(int)sizeIndex

#endif

- (void) display
{
[self updateScreen];
}

- (void) updateScreen
{
[self drawRect: NSMakeRect(0, 0, viewSize.width, viewSize.height)];
}

- (void) drawRect:(NSRect)rect
{
SDL_SetWindowSize(window, (int)NSWidth(rect), (int)NSHeight(rect));
[self updateScreenWithVideoMode:YES];
}

- (void) updateScreenWithVideoMode:(BOOL) v_mode
{
SDL_SetWindowSize(window, (int)viewSize.width, (int)viewSize.height);
SDL_Surface* surface = SDL_GetWindowSurface(window);
int windowWidth, windowHeight;
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
if ((viewSize.width != windowWidth)||(viewSize.height != windowHeight)) // resized
{
#if OOLITE_LINUX
m_glContextInitialized = NO; //probably not needed
#endif
viewSize.width = windowWidth;
viewSize.height = windowHeight;
}

if (m_glContextInitialized == NO)
{
[self initialiseGLWithSize:viewSize useVideoMode:v_mode];
[self initialiseGLWithSize:viewSize];
}

if (surface == 0)
Expand Down Expand Up @@ -1020,66 +1001,6 @@ - (void) stringToClipboard:(NSString *)stringToCopy
}


- (void) resetSDLKeyModifiers
{
/* kanthoney - looks like SDL3 won't allow us to change the keyboard state - try without to see if it's needed
// this is used when we regain focus to ensure that all
// modifier keys are reset to their correct status
SDL_Keymod modState = SDL_GetModState();
const BOOL *keyState = SDL_GetKeyboardState(NULL);
BYTE keyboardStatus[256];
#define OO_RESET_SDLKEY_MODIFIER(vkCode, kModCode, sdlkCode) do {\
if (keyboardStatus[vkCode] & 0x0080) \
{ \
modState |= kModCode; \
keyState[sdlkCode] = SDL_PRESSED; \
} \
else \
{ \
modState &= ~kModCode; \
keyState[sdlkCode] = SDL_RELEASED; \
} \
} while(0)
if (GetKeyboardState(keyboardStatus))
{
// A bug noted here https://github.com/libsdl-org/SDL-1.2/issues/449
// was patched in SDL here https://github.com/libsdl-org/SDL-1.2/commit/09980c67290f11c3d088a6a039c550be83536c81
// This was replicated in our SDL binary (Windows-deps rev. 36fd5e6),
// so we no longer need to check the state of Alt when returning to the app.
// SDL change researched and implemented by Nikos 20220622.
// Alt key
//OO_RESET_SDLKEY_MODIFIER(VK_LMENU, KMOD_LALT, SDLK_LALT);
//OO_RESET_SDLKEY_MODIFIER(VK_RMENU, KMOD_RALT, SDLK_RALT);
//opt = (modState & KMOD_LALT || modState & KMOD_RALT);

//Ctrl key
OO_RESET_SDLKEY_MODIFIER(VK_LCONTROL, KMOD_LCTRL, SDLK_LCTRL);
OO_RESET_SDLKEY_MODIFIER(VK_RCONTROL, KMOD_RCTRL, SDLK_RCTRL);
ctrl = (modState & KMOD_LCTRL || modState & KMOD_RCTRL);

// Shift key
OO_RESET_SDLKEY_MODIFIER(VK_LSHIFT, KMOD_LSHIFT, SDLK_LSHIFT);
OO_RESET_SDLKEY_MODIFIER(VK_RSHIFT, KMOD_RSHIFT, SDLK_RSHIFT);
shift = (modState & KMOD_LSHIFT || modState & KMOD_RSHIFT);

// Caps Lock key state
if (GetKeyState(VK_CAPITAL) & 0x0001)
{
modState |= KMOD_CAPS;
keyState[SDLK_CAPSLOCK] = SDL_PRESSED;
}
else
{
modState &= ~KMOD_CAPS;
keyState[SDLK_CAPSLOCK] = SDL_RELEASED;
}
}

SDL_SetModState(modState);
*/
}


- (void) refreshDarKOrLightMode
{
int shouldSetDarkMode = [self isDarkModeOn];
Expand Down Expand Up @@ -1367,12 +1288,6 @@ - (void) stringToClipboard:(NSString *)stringToCopy
}


- (void) resetSDLKeyModifiers
{
// probably not needed for Linux
}


- (BOOL) hdrOutput
{
return NO;
Expand Down Expand Up @@ -1402,12 +1317,6 @@ - (void) setSDRToneMapper: (OOSDRToneMapper)newToneMapper


- (void) initialiseGLWithSize:(NSSize) v_size
{
[self initialiseGLWithSize:v_size useVideoMode:YES];
}


- (void) initialiseGLWithSize:(NSSize) v_size useVideoMode:(BOOL) v_mode
{
if (!window)
{
Expand All @@ -1421,7 +1330,7 @@ - (void) initialiseGLWithSize:(NSSize) v_size useVideoMode:(BOOL) v_mode
if (!fullScreen)
{
SDL_SetWindowSize(window, viewSize.width, viewSize.height);
SDL_SetWindowBordered(window, v_mode);
SDL_SetWindowBordered(window, YES);
}
#if OOLITE_WINDOWS
else // Hack for Windows SDL3 pause issue: https://github.com/libsdl-org/SDL/issues/12791
Expand Down