OSDN Git Service

Be more consistent about the format of comments.
[hengbandforosx/hengbandosx.git] / src / main-cocoa.m
index 65885c5..0248530 100644 (file)
@@ -118,7 +118,7 @@ static wchar_t convert_two_byte_eucjp_to_utf16_native(const char *cp);
 - (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.
  */
@@ -132,7 +132,7 @@ static wchar_t convert_two_byte_eucjp_to_utf16_native(const char *cp);
 + (AngbandSoundCatalog*)sharedSounds;
 
 /**
- * Release any resouces associated with shared sounds.
+ * Release any resources associated with shared sounds.
  */
 + (void)clearSharedSounds;
 
@@ -333,7 +333,7 @@ static __strong AngbandSoundCatalog* gSharedSounds = nil;
     if (gSharedSounds == nil) {
        gSharedSounds = [[AngbandSoundCatalog alloc] init];
     }
-    return gSharedSounds;;
+    return gSharedSounds;
 }
 
 + (void)clearSharedSounds {
@@ -1804,8 +1804,10 @@ static void draw_image_tile(
  */
 #define GLYPH_COUNT 256
 
-/* An AngbandContext represents a logical Term (i.e. what Angband thinks is
- * a window). */
+/*
+ * An AngbandContext represents a logical Term (i.e. what Angband thinks is
+ * a window).
+ */
 @interface AngbandContext : NSObject <NSWindowDelegate>
 {
 @public
@@ -1890,8 +1892,10 @@ static void draw_image_tile(
 - (void)drawWChar:(wchar_t)wchar inRect:(NSRect)tile screenFont:(NSFont*)font
          context:(CGContextRef)ctx;
 
-/* Returns the primary window for this angband context, creating it if
- * necessary */
+/*
+ * Returns the primary window for this angband context, creating it if
+ * necessary
+ */
 - (NSWindow *)makePrimaryWindow;
 
 /* Handle becoming the main window */
@@ -1983,8 +1987,10 @@ u32b AngbandMaskForValidSubwindowFlags(void)
  */
 static void AngbandUpdateWindowVisibility(void)
 {
-    /* Because this function is called frequently, we'll make the mask static.
-        * It doesn't change between calls, as the flags themselves are hardcoded */
+    /*
+     * Because this function is called frequently, we'll make the mask static.
+     * It doesn't change between calls, as the flags themselves are hardcoded
+     */
     static u32b validWindowFlagsMask = 0;
 
     if( validWindowFlagsMask == 0 )
@@ -1992,9 +1998,11 @@ static void AngbandUpdateWindowVisibility(void)
         validWindowFlagsMask = AngbandMaskForValidSubwindowFlags();
     }
 
-    /* Loop through all of the subwindows and see if there is a change in the
-        * flags. If so, show or hide the corresponding window. We don't care about
-        * the flags themselves; we just want to know if any are set. */
+    /*
+     * Loop through all of the subwindows and see if there is a change in the
+     * flags. If so, show or hide the corresponding window. We don't care about
+     * the flags themselves; we just want to know if any are set.
+     */
     for( int i = 1; i < ANGBAND_TERM_MAX; i++ )
     {
         AngbandContext *angbandContext =
@@ -2005,12 +2013,14 @@ static void AngbandUpdateWindowVisibility(void)
             continue;
         }
 
-        /* This horrible mess of flags is so that we can try to maintain some
-                * user visibility preference. This should allow the user a window and
-                * have it stay closed between application launches. However, this
-                * means that when a subwindow is turned on, it will no longer appear
-                * automatically. Angband has no concept of user control over window
-                * visibility, other than the subwindow flags. */
+        /*
+         * This horrible mess of flags is so that we can try to maintain some
+         * user visibility preference. This should allow the user a window and
+         * have it stay closed between application launches. However, this
+         * means that when a subwindow is turned on, it will no longer appear
+         * automatically. Angband has no concept of user control over window
+         * visibility, other than the subwindow flags.
+         */
         if( !angbandContext.windowVisibilityChecked )
         {
             if( [angbandContext windowVisibleUsingDefaults] )
@@ -2144,8 +2154,10 @@ static bool initialized = FALSE;
 }
 @end
 
-/* Methods for pulling images out of the Angband bundle (which may be separate
- * from the current bundle in the case of a screensaver */
+/*
+ * Methods for pulling images out of the Angband bundle (which may be separate
+ * from the current bundle in the case of a screensaver
+ */
 @interface NSImage (AngbandImages)
 + (NSImage *)angbandImage:(NSString *)name;
 @end
@@ -2163,8 +2175,10 @@ static bool initialized = FALSE;
 
 @implementation NSImage (AngbandImages)
 
-/* Returns an image in the resource directoy of the bundle containing the
- * Angband view class. */
+/*
+ * Returns an image in the resource directoy of the bundle containing the
+ * Angband view class.
+ */
 + (NSImage *)angbandImage:(NSString *)name
 {
     NSBundle *bundle = [NSBundle bundleForClass:[AngbandView class]];
@@ -2441,10 +2455,12 @@ static int compare_advances(const void *ap, const void *bp)
        advances, 1);
     CGSize advance = advances[0];
 
-    /* If our font is not monospaced, our tile width is deliberately not big
-        * enough for every character. In that event, if our glyph is too wide, we
-        * need to compress it horizontally. Compute the compression ratio.
-        * 1.0 means no compression. */
+    /*
+     * If our font is not monospaced, our tile width is deliberately not big
+     * enough for every character. In that event, if our glyph is too wide, we
+     * need to compress it horizontally. Compute the compression ratio.
+     * 1.0 means no compression.
+     */
     double compressionRatio;
     if (advance.width <= NSWidth(tile))
     {
@@ -2503,8 +2519,10 @@ static int compare_advances(const void *ap, const void *bp)
 
     if( adjustTerminal )
     {
-        /* Adjust terminal to fit window with new font; save the new columns
-                * and rows since they could be changed */
+        /*
+         * Adjust terminal to fit window with new font; save the new columns
+         * and rows since they could be changed
+         */
         NSRect contentRect =
            [self.primaryWindow
                 contentRectForFrameRect: [self.primaryWindow frame]];
@@ -2629,8 +2647,10 @@ static __strong NSFont* gDefaultFont = nil;
 {
     if (! self.primaryWindow)
     {
-        /* This has to be done after the font is set, which it already is in
-                * term_init_cocoa() */
+        /*
+         * This has to be done after the font is set, which it already is in
+         * term_init_cocoa()
+         */
         NSSize sz = self.baseSize;
         NSRect contentRect = NSMakeRect( 0.0, 0.0, sz.width, sz.height );
 
@@ -3271,8 +3291,9 @@ static int compare_nsrect_yorigin_greater(const void *ap, const void *bp)
  */
 - (void)drawRect:(NSRect)rect inView:(NSView *)view
 {
-    /* Take this opportunity to throttle so we don't flush faster than desired.
-        */
+    /*
+     * Take this opportunity to throttle so we don't flush faster than desired.
+     */
     [self throttle];
 
     CGFloat bottomY =
@@ -3291,7 +3312,6 @@ static int compare_nsrect_yorigin_greater(const void *ap, const void *bp)
     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;
@@ -3299,8 +3319,6 @@ static int compare_nsrect_yorigin_greater(const void *ap, const void *bp)
        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];
@@ -3326,9 +3344,6 @@ static int compare_nsrect_yorigin_greater(const void *ap, const void *bp)
     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];
@@ -3675,9 +3690,6 @@ static int compare_nsrect_yorigin_greater(const void *ap, const void *bp)
     }
 
     free(sortedRects);
-    if (old != 0) {
-       Term_activate(old);
-    }
 }
 
 - (BOOL)isOrderedIn
@@ -4922,7 +4934,7 @@ static void quit_calmly(void)
     {
         /* Hack -- Forget messages and term */
         msg_flag = FALSE;
-               Term->mapped_flag = FALSE;
+        Term->mapped_flag = FALSE;
 
         /* Save the game */
         do_cmd_save_game(FALSE);
@@ -4971,31 +4983,39 @@ static void AngbandHandleEventMouseDown( NSEvent *event )
                NSSize border = angbandContext.borderSize;
                NSPoint windowPoint = [event locationInWindow];
 
-               /* Adjust for border; add border height because window origin is at
-                * bottom */
+               /*
+                * Adjust for border; add border height because window origin
+                * is at bottom
+                */
                windowPoint = NSMakePoint( windowPoint.x - border.width, windowPoint.y + border.height );
 
                NSPoint p = [[[event window] contentView] convertPoint: windowPoint fromView: nil];
                x = floor( p.x / tileSize.width );
                y = floor( p.y / tileSize.height );
 
-               /* Being safe about this, since xcode doesn't seem to like the
-                * bool_hack stuff */
+               /*
+                * Being safe about this, since xcode doesn't seem to like the
+                * bool_hack stuff
+                */
                BOOL displayingMapInterface = ((int)inkey_flag != 0);
 
                /* Sidebar plus border == thirteen characters; top row is reserved. */
                /* Coordinates run from (0,0) to (cols-1, rows-1). */
                BOOL mouseInMapSection = (x > 13 && x <= cols - 1 && y > 0  && y <= rows - 2);
 
-               /* If we are displaying a menu, allow clicks anywhere within
+               /*
+                * If we are displaying a menu, allow clicks anywhere within
                 * the terminal bounds; if we are displaying the main game
-                * interface, only allow clicks in the map section */
+                * interface, only allow clicks in the map section
+                */
                if ((!displayingMapInterface && x >= 0 && x < cols &&
                     y >= 0 && y < rows) ||
                     (displayingMapInterface && mouseInMapSection))
                {
-                       /* [event buttonNumber] will return 0 for left click,
-                        * 1 for right click, but this is safer */
+                       /*
+                        * [event buttonNumber] will return 0 for left click,
+                        * 1 for right click, but this is safer
+                        */
                        int button = ([event type] == NSLeftMouseDown) ? 1 : 2;
 
 #ifdef KC_MOD_ALT
@@ -5243,7 +5263,7 @@ static NSString* get_lib_directory(void)
 
     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",
@@ -5357,15 +5377,18 @@ static term *term_data_link(int i)
     /* 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;
 
+    /*
+     * 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 = ' ';
@@ -5786,7 +5809,7 @@ static void init_windows(void)
         {
            /*
             * Another window is only usable after Term_init_cocoa() has
-            * been called for it.  For Angband if window_flag[i] is nonzero
+            * been called for it.  For Angband, if window_flag[i] is nonzero
             * then that has happened for window i.  For Hengband, that is
             * not the case so also test angband_term[i]->data.
             */
@@ -6074,8 +6097,10 @@ static void init_windows(void)
 {
     [self beginGame];
     
-    /* Once beginGame finished, the game is over - that's how Angband works,
-        * and we should quit */
+    /*
+     * Once beginGame finished, the game is over - that's how Angband works,
+     * and we should quit
+     */
     game_is_finished = TRUE;
     [NSApp terminate:self];
 }
@@ -6097,12 +6122,16 @@ static void init_windows(void)
         /* Stop playing */
         /* player->upkeep->playing = FALSE; */
 
-        /* Post an escape event so that we can return from our get-key-event
-                * function */
+        /*
+         * Post an escape event so that we can return from our get-key-event
+         * function
+         */
         wakeup_event_loop();
         quit_when_ready = true;
-        /* Must return Cancel, not Later, because we need to get out of the
-                * run loop and back to Angband's loop */
+        /*
+         * Must return Cancel, not Later, because we need to get out of the
+         * run loop and back to Angband's loop
+         */
         return NSTerminateCancel;
     }
 }
@@ -6116,10 +6145,12 @@ static void init_windows(void)
     if (! [menu isEqual:self.graphicsMenu])
         return;
     
-    /* If it's non-empty, then we've already built it. Currently graphics modes
-        * won't change once created; if they ever can we can remove this check.
+    /*
+     * If it's non-empty, then we've already built it. Currently graphics modes
+     * won't change once created; if they ever can we can remove this check.
      * Note that the check mark does change, but that's handled in
-        * validateMenuItem: instead of menuNeedsUpdate: */
+     * validateMenuItem: instead of menuNeedsUpdate:
+     */
     if ([menu numberOfItems] > 0)
         return;
     
@@ -6187,8 +6218,10 @@ static void init_windows(void)
 
     game_in_progress = TRUE;
 
-    /* Wake us up in case this arrives while we're sitting at the Welcome
-        * screen! */
+    /*
+     * Wake us up in case this arrives while we're sitting at the Welcome
+     * screen!
+     */
     wakeup_event_loop();
 
     [[NSApplication sharedApplication]