#define kVK_ANSI_KeypadEnter 0x4C
static NSString * const AngbandDirectoryNameLib = @"lib";
-static NSString * const AngbandDirectoryNameBase = @"Hengband";
+static NSString * const AngbandDirectoryNameBase = @VERSION_NAME;
static NSString * const AngbandMessageCatalog = @"Localizable";
static NSString * const AngbandTerminalsDefaultsKey = @"Terminals";
- (void)playSound:(int)event;
/**
- * Impose an arbitary limit on number of possible samples per event.
+ * Impose an arbitrary limit on the number of possible samples per event.
* Currently not declaring this as a class property for compatibility with
* versions of Xcode prior to 8.
*/
+ (AngbandSoundCatalog*)sharedSounds;
/**
- * Release any resouces associated with shared sounds.
+ * Release any resources associated with shared sounds.
*/
+ (void)clearSharedSounds;
if (gSharedSounds == nil) {
gSharedSounds = [[AngbandSoundCatalog alloc] init];
}
- return gSharedSounds;;
+ return gSharedSounds;
}
+ (void)clearSharedSounds {
static NSString* get_doc_directory(void);
static NSString* AngbandCorrectedDirectoryPath(NSString *originalPath);
static void prepare_paths_and_directories(void);
+static void load_prefs(void);
+static void init_windows(void);
static void handle_open_when_ready(void);
static void play_sound(int event);
static BOOL check_events(int wait);
@implementation AngbandContext
-@synthesize hasSubwindowFlags=_hasSubwindowFlags;
-@synthesize windowVisibilityChecked=_windowVisibilityChecked;
-
- (NSSize)baseSize
{
/*
/* Pick the center to find the median */
CGFloat medianAdvance = 0;
+ /* In case we have all zero advances for some reason */
if (startIdx < GLYPH_COUNT)
{
- /* In case we have all zero advances for some reason */
medianAdvance = advances[(startIdx + GLYPH_COUNT)/2].width;
}
backing:NSBackingStoreBuffered defer:YES];
}
-
/* Not to be released when closed */
[self.primaryWindow setReleasedWhenClosed:NO];
[self.primaryWindow setExcludedFromWindowsMenu: YES]; /* we're using custom window menu handling */
NSGraphicsContext *nsctx = nil;
CGContextRef ctx = 0;
NSFont* screenFont = nil;
- term *old = 0;
int graf_width = 0, graf_height = 0;
int overdraw_row = 0, overdraw_max = 0;
wchar_t blank = 0;
rect.origin.x + rect.size.width > self.borderSize.width &&
rect.origin.y < bottomY &&
rect.origin.y + rect.size.height > self.borderSize.height) {
- old = Term;
- Term_activate(self->terminal);
nsctx = [NSGraphicsContext currentContext];
ctx = [nsctx graphicsPort];
screenFont = [self.angbandViewFont screenFont];
if (overdraw_row && invalidCount > 1) {
sortedRects = malloc(invalidCount * sizeof(NSRect));
if (sortedRects == 0) {
- if (old != 0) {
- Term_activate(old);
- }
NSException *exc = [NSException exceptionWithName:@"OutOfMemory"
reason:@"sorted rects in drawRect"
userInfo:nil];
}
free(sortedRects);
- if (old != 0) {
- Term_activate(old);
- }
}
- (BOOL)isOrderedIn
* This is a bit of a trick to allow us to display multiple
* windows in the "standard default" window position in OS X:
* the upper center of the screen. The term sizes set in
- * AngbandAppDelegate's loadPrefs() are based on a 5-wide by
- * 3-high grid, with the main term being 4/5 wide by 2/3 high
- * (hence the scaling to find what the containing rect would
- * be).
+ * load_prefs() are based on a 5-wide by 3-high grid, with the
+ * main term being 4/5 wide by 2/3 high (hence the scaling to
+ * find what the containing rect would be).
*/
NSRect originalMainTermFrame = [window frame];
NSRect scaledFrame = originalMainTermFrame;
@"Could not load the tile set. Switched back to ASCII.",
@"Alert informative message for failed tile set load");
NSAlert *alert = [[NSAlert alloc] init];
-
alert.messageText = msg;
alert.informativeText = info;
[alert runModal];
{
/* Hack -- Forget messages and term */
msg_flag = FALSE;
- Term->mapped_flag = FALSE;
+ Term->mapped_flag = FALSE;
/* Save the game */
do_cmd_save_game(FALSE);
if( !libExists || !isDirectory )
{
- NSLog( @"Hengband: can't find %@/ in bundle: isDirectory: %d libExists: %d", AngbandDirectoryNameLib, isDirectory, libExists );
+ NSLog( @"%@: can't find %@/ in bundle: isDirectory: %d libExists: %d", @VERSION_NAME, AngbandDirectoryNameLib, isDirectory, libExists );
NSString *msg = NSLocalizedStringWithDefaultValue(
@"Error.MissingResources",
@"Label.Quit", AngbandMessageCatalog, [NSBundle mainBundle],
@"Quit", @"Quit");
NSAlert *alert = [[NSAlert alloc] init];
-
/*
* Note that NSCriticalAlertStyle was deprecated in 10.10. The
* replacement is NSAlertStyleCritical.
alert.informativeText = info;
[alert addButtonWithTitle:quit_label];
[alert runModal];
- exit( 0 );
+ exit(0);
}
return bundleLibPath;
}
/**
+ * Create and initialize Angband terminal number "i".
+ */
+static term *term_data_link(int i)
+{
+ NSArray *terminalDefaults = [[NSUserDefaults standardUserDefaults]
+ valueForKey: AngbandTerminalsDefaultsKey];
+ NSInteger rows = 24;
+ NSInteger columns = 80;
+
+ if (i < (int)[terminalDefaults count]) {
+ NSDictionary *term = [terminalDefaults objectAtIndex:i];
+ rows = [[term valueForKey: AngbandTerminalRowsDefaultsKey]
+ integerValue];
+ columns = [[term valueForKey: AngbandTerminalColumnsDefaultsKey]
+ integerValue];
+ }
+
+ /* Allocate */
+ term *newterm = ZNEW(term);
+
+ /* Initialize the term */
+ term_init(newterm, columns, rows, 256 /* keypresses, for some reason? */);
+
+ /* Use a "software" cursor */
+ newterm->soft_cursor = TRUE;
+
+ /* Disable the per-row flush notifications since they are not used. */
+ newterm->never_frosh = TRUE;
+
+ /*
+ * Differentiate between BS/^h, Tab/^i, ... so ^h and ^j work under the
+ * roguelike command set.
+ */
+ /* newterm->complex_input = TRUE; */
+
+ /* Erase with "white space" */
+ newterm->attr_blank = TERM_WHITE;
+ newterm->char_blank = ' ';
+
+ /* Prepare the init/nuke hooks */
+ newterm->init_hook = Term_init_cocoa;
+ newterm->nuke_hook = Term_nuke_cocoa;
+
+ /* Prepare the function hooks */
+ newterm->xtra_hook = Term_xtra_cocoa;
+ newterm->wipe_hook = Term_wipe_cocoa;
+ newterm->curs_hook = Term_curs_cocoa;
+ newterm->bigcurs_hook = Term_bigcurs_cocoa;
+ newterm->text_hook = Term_text_cocoa;
+ newterm->pict_hook = Term_pict_cocoa;
+ /* newterm->mbcs_hook = Term_mbcs_cocoa; */
+
+ /* Global pointer */
+ angband_term[i] = newterm;
+
+ return newterm;
+}
+
+/**
+ * Load preferences from preferences file for current host+current user+
+ * current application.
+ */
+static void load_prefs(void)
+{
+ NSUserDefaults *defs = [NSUserDefaults angbandDefaults];
+
+ /* Make some default defaults */
+ NSMutableArray *defaultTerms = [[NSMutableArray alloc] init];
+
+ /*
+ * The following default rows/cols were determined experimentally by first
+ * finding the ideal window/font size combinations. But because of awful
+ * temporal coupling in Term_init_cocoa(), it's impossible to set up the
+ * defaults there, so we do it this way.
+ */
+ for (NSUInteger i = 0; i < ANGBAND_TERM_MAX; i++) {
+ int columns, rows;
+ BOOL visible = YES;
+
+ switch (i) {
+ case 0:
+ columns = 129;
+ rows = 32;
+ break;
+ case 1:
+ columns = 84;
+ rows = 20;
+ break;
+ case 2:
+ columns = 42;
+ rows = 24;
+ break;
+ case 3:
+ columns = 42;
+ rows = 20;
+ break;
+ case 4:
+ columns = 42;
+ rows = 16;
+ break;
+ case 5:
+ columns = 84;
+ rows = 20;
+ break;
+ default:
+ columns = 80;
+ rows = 24;
+ visible = NO;
+ break;
+ }
+
+ NSDictionary *standardTerm =
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt: rows], AngbandTerminalRowsDefaultsKey,
+ [NSNumber numberWithInt: columns], AngbandTerminalColumnsDefaultsKey,
+ [NSNumber numberWithBool: visible], AngbandTerminalVisibleDefaultsKey,
+ nil];
+ [defaultTerms addObject: standardTerm];
+ }
+
+ NSDictionary *defaults = [[NSDictionary alloc] initWithObjectsAndKeys:
+#ifdef JP
+ @"Osaka", @"FontName",
+#else
+ @"Menlo", @"FontName",
+#endif
+ [NSNumber numberWithFloat:13.f], @"FontSize",
+ [NSNumber numberWithInt:60], AngbandFrameRateDefaultsKey,
+ [NSNumber numberWithBool:YES], AngbandSoundDefaultsKey,
+ [NSNumber numberWithInt:GRAPHICS_NONE], AngbandGraphicsDefaultsKey,
+ [NSNumber numberWithBool:YES], AngbandBigTileDefaultsKey,
+ defaultTerms, AngbandTerminalsDefaultsKey,
+ nil];
+ [defs registerDefaults:defaults];
+
+ /* Preferred graphics mode */
+ graf_mode_req = [defs integerForKey:AngbandGraphicsDefaultsKey];
+ if (graphics_will_be_enabled() &&
+ [defs boolForKey:AngbandBigTileDefaultsKey] == YES) {
+ use_bigtile = TRUE;
+ arg_bigtile = TRUE;
+ } else {
+ use_bigtile = FALSE;
+ arg_bigtile = FALSE;
+ }
+
+ /* Use sounds; set the Angband global */
+ if ([defs boolForKey:AngbandSoundDefaultsKey] == YES) {
+ use_sound = TRUE;
+ [AngbandSoundCatalog sharedSounds].enabled = YES;
+ } else {
+ use_sound = FALSE;
+ [AngbandSoundCatalog sharedSounds].enabled = NO;
+ }
+
+ /* fps */
+ frames_per_second = [defs integerForKey:AngbandFrameRateDefaultsKey];
+
+ /* Font */
+ [AngbandContext
+ setDefaultFont:[NSFont fontWithName:[defs valueForKey:@"FontName-0"]
+ size:[defs floatForKey:@"FontSize-0"]]];
+ if (! [AngbandContext defaultFont])
+ [AngbandContext
+ setDefaultFont:[NSFont fontWithName:@"Menlo" size:13.]];
+}
+
+/**
* Play sound effects asynchronously. Select a sound from any available
* for the required event, and bridge to Cocoa to play it.
*/
}
/**
+ * Allocate the primary Angband terminal and activate it. Allocate the other
+ * Angband terminals.
+ */
+static void init_windows(void)
+{
+ /* Create the primary window */
+ term *primary = term_data_link(0);
+
+ /* Prepare to create any additional windows */
+ for (int i = 1; i < ANGBAND_TERM_MAX; i++) {
+ term_data_link(i);
+ }
+
+ /* Activate the primary term */
+ Term_activate(primary);
+}
+
+/**
* ------------------------------------------------------------------------
* Main program
* ------------------------------------------------------------------------ */
}
/**
- * Create and initialize Angband terminal number "termIndex".
- */
-- (void)linkTermData:(int)termIndex
-{
- NSArray *terminalDefaults = [[NSUserDefaults standardUserDefaults]
- valueForKey: AngbandTerminalsDefaultsKey];
- NSInteger rows = 24;
- NSInteger columns = 80;
-
- if (termIndex < (int)[terminalDefaults count]) {
- NSDictionary *term = [terminalDefaults objectAtIndex:termIndex];
- rows = [[term valueForKey: AngbandTerminalRowsDefaultsKey]
- integerValue];
- columns = [[term valueForKey: AngbandTerminalColumnsDefaultsKey]
- integerValue];
- }
-
- /* Allocate */
- term *newterm = ZNEW(term);
-
- /* Initialize the term */
- term_init(newterm, columns, rows, 256 /* keypresses, for some reason? */);
-
- /* Differentiate between BS/^h, Tab/^i, etc. */
- /* newterm->complex_input = TRUE; */
-
- /* Use a "software" cursor */
- newterm->soft_cursor = TRUE;
-
- /* Disable the per-row flush notifications since they are not used. */
- newterm->never_frosh = TRUE;
-
- /* Erase with "white space" */
- newterm->attr_blank = TERM_WHITE;
- newterm->char_blank = ' ';
-
- /* Prepare the init/nuke hooks */
- newterm->init_hook = Term_init_cocoa;
- newterm->nuke_hook = Term_nuke_cocoa;
-
- /* Prepare the function hooks */
- newterm->xtra_hook = Term_xtra_cocoa;
- newterm->wipe_hook = Term_wipe_cocoa;
- newterm->curs_hook = Term_curs_cocoa;
- newterm->bigcurs_hook = Term_bigcurs_cocoa;
- newterm->text_hook = Term_text_cocoa;
- newterm->pict_hook = Term_pict_cocoa;
- /* newterm->mbcs_hook = Term_mbcs_cocoa; */
-
- /* Global pointer */
- angband_term[termIndex] = newterm;
-}
-
-/**
- * Allocate the primary Angband terminal and activate it. Allocate the other
- * Angband terminals.
- */
-- (void)initWindows {
- for (int i = 0; i < ANGBAND_TERM_MAX; i++) {
- [self linkTermData:i];
- }
-
- Term_activate(angband_term[0]);
-}
-
-/**
- * Load preferences from preferences file for current host+current user+
- * current application.
- */
-- (void)loadPrefs
-{
- NSUserDefaults *defs = [NSUserDefaults angbandDefaults];
-
- /* Make some default defaults */
- NSMutableArray *defaultTerms = [[NSMutableArray alloc] init];
-
- /*
- * The following default rows/cols were determined experimentally by first
- * finding the ideal window/font size combinations. But because of awful
- * temporal coupling in Term_init_cocoa(), it's impossible to set up the
- * defaults there, so we do it this way.
- */
- for (NSUInteger i = 0; i < ANGBAND_TERM_MAX; i++) {
- int columns, rows;
- BOOL visible = YES;
-
- switch (i) {
- case 0:
- columns = 129;
- rows = 32;
- break;
- case 1:
- columns = 84;
- rows = 20;
- break;
- case 2:
- columns = 42;
- rows = 24;
- break;
- case 3:
- columns = 42;
- rows = 20;
- break;
- case 4:
- columns = 42;
- rows = 16;
- break;
- case 5:
- columns = 84;
- rows = 20;
- break;
- default:
- columns = 80;
- rows = 24;
- visible = NO;
- break;
- }
-
- NSDictionary *standardTerm =
- [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt: rows], AngbandTerminalRowsDefaultsKey,
- [NSNumber numberWithInt: columns], AngbandTerminalColumnsDefaultsKey,
- [NSNumber numberWithBool: visible], AngbandTerminalVisibleDefaultsKey,
- nil];
- [defaultTerms addObject: standardTerm];
- }
-
- NSDictionary *defaults = [[NSDictionary alloc] initWithObjectsAndKeys:
-#ifdef JP
- @"Osaka", @"FontName",
-#else
- @"Menlo", @"FontName",
-#endif
- [NSNumber numberWithFloat:13.f], @"FontSize",
- [NSNumber numberWithInt:60], AngbandFrameRateDefaultsKey,
- [NSNumber numberWithBool:YES], AngbandSoundDefaultsKey,
- [NSNumber numberWithInt:GRAPHICS_NONE], AngbandGraphicsDefaultsKey,
- [NSNumber numberWithBool:YES], AngbandBigTileDefaultsKey,
- defaultTerms, AngbandTerminalsDefaultsKey,
- nil];
- [defs registerDefaults:defaults];
-
- /* Preferred graphics mode */
- graf_mode_req = [defs integerForKey:AngbandGraphicsDefaultsKey];
- if (graphics_will_be_enabled() &&
- [defs boolForKey:AngbandBigTileDefaultsKey] == YES) {
- use_bigtile = TRUE;
- arg_bigtile = TRUE;
- } else {
- use_bigtile = FALSE;
- arg_bigtile = FALSE;
- }
-
- /* Use sounds; set the Angband global */
- if ([defs boolForKey:AngbandSoundDefaultsKey] == YES) {
- use_sound = TRUE;
- [AngbandSoundCatalog sharedSounds].enabled = YES;
- } else {
- use_sound = FALSE;
- [AngbandSoundCatalog sharedSounds].enabled = NO;
- }
-
- /* fps */
- frames_per_second = [defs integerForKey:AngbandFrameRateDefaultsKey];
-
- /* Font */
- [AngbandContext
- setDefaultFont:[NSFont fontWithName:[defs valueForKey:@"FontName-0"]
- size:[defs floatForKey:@"FontSize-0"]]];
- if (! [AngbandContext defaultFont])
- [AngbandContext
- setDefaultFont:[NSFont fontWithName:@"Menlo" size:13.]];
-}
-
-/**
* Entry point for initializing Angband
*/
- (void)beginGame
init_graphics_modes();
/* Load preferences */
- [self loadPrefs];
+ load_prefs();
/* Prepare the windows */
- [self initWindows];
+ init_windows();
/* Set up game event handlers */
/* init_display(); */