OSDN Git Service

[Refactor] 無駄な空白、改行の削除、includeのソート
[hengbandforosx/hengbandosx.git] / src / term / z-term.c
index b70e779..5942862 100644 (file)
@@ -8,8 +8,10 @@
  */
 
 #include "term/z-term.h"
+#include "game-option/map-screen-options.h"
 #include "game-option/runtime-arguments.h"
 #include "game-option/special-options.h"
+#include "term/gameterm.h"
 #include "term/term-color-types.h"
 #include "term/z-virt.h"
 
 #endif
 
 /* The current "term" */
-term *Term = NULL;
+term_type *Term = NULL;
 
 /*** Local routines ***/
 
 /*
  * Nuke a term_win (see below)
  */
-static errr term_win_nuke(term_win *s, TERM_LEN w, TERM_LEN h)
+errr term_win_nuke(term_win *s, TERM_LEN w, TERM_LEN h)
 {
     /* Free the window access arrays */
     C_KILL(s->a, h, TERM_COLOR *);
@@ -274,7 +276,6 @@ void term_queue_char(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c, TERM_COLOR ta
  */
 void term_queue_bigchar(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c, TERM_COLOR ta, char tc)
 {
-
 #ifdef JP
     /*
      * A table which relates each ascii character to a multibyte
@@ -416,7 +417,7 @@ void term_queue_line(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR *a, char *c, TERM
  * a valid location, so the first "n" characters of "s" can all be added
  * starting at (x,y) without causing any illegal operations.
  */
-void term_queue_chars(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr s)
+static void term_queue_chars(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr s)
 {
     TERM_LEN x1 = -1, x2 = -1;
 
@@ -511,7 +512,6 @@ void term_queue_chars(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr s)
      * (条件追加:タイルの1文字目でない事を確かめるように。)
      */
     {
-
         int w, h;
         term_get_size(&w, &h);
         if (x != w && !(scr_aa[x] & AF_TILE1) && (scr_aa[x] & AF_KANJI2)) {
@@ -1021,6 +1021,13 @@ static void term_fresh_row_text(TERM_LEN y, TERM_LEN x1, TERM_LEN x2)
     }
 }
 
+bool macro_running(void)
+{
+    int diff = angband_term[0]->key_head - angband_term[0]->key_tail;
+    return diff < -1 || 1 < diff;
+}
+
+bool need_term_fresh(void) { return !macro_running() || fresh_after; }
 /*
  * @brief Actually perform all requested changes to the window
  */
@@ -1501,38 +1508,6 @@ errr term_putstr(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr s)
     return 0;
 }
 
-#ifdef JP
-/*
- * Move to a location and, using an attr, add a string vertically
- */
-errr term_putstr_v(TERM_LEN x, TERM_LEN y, int n, byte a, concptr s)
-{
-    errr res;
-    int y0 = y;
-
-    for (int i = 0; i < n && s[i] != 0; i++) {
-        /* Move first */
-        if ((res = term_gotoxy(x, y0)) != 0)
-            return (res);
-
-        if (iskanji(s[i])) {
-            if ((res = term_addstr(2, a, &s[i])) != 0)
-                return (res);
-            i++;
-            y0++;
-            if (s[i] == 0)
-                break;
-        } else {
-            if ((res = term_addstr(1, a, &s[i])) != 0)
-                return (res);
-            y0++;
-        }
-    }
-
-    return 0;
-}
-#endif
-
 /*
  * Place cursor at (x,y), and clear the next "n" chars
  */
@@ -1699,7 +1674,7 @@ errr term_redraw(void)
 /*
  * Redraw part of a window.
  */
-static errr term_redraw_section(TERM_LEN x1, TERM_LEN y1, TERM_LEN x2, TERM_LEN y2)
+errr term_redraw_section(TERM_LEN x1, TERM_LEN y1, TERM_LEN x2, TERM_LEN y2)
 {
     char *g_ptr;
 
@@ -1837,28 +1812,6 @@ errr term_flush(void)
 }
 
 /*
- * Add a keypress to the "queue"
- */
-errr term_keypress(int k)
-{
-    /* Refuse to enqueue non-keys */
-    if (!k)
-        return -1;
-
-    /* Store the char, advance the queue */
-    Term->key_queue[Term->key_head++] = (char)k;
-
-    /* Circular queue, handle wrap */
-    if (Term->key_head == Term->key_size)
-        Term->key_head = 0;
-
-    if (Term->key_head != Term->key_tail)
-        return 0;
-
-    return 1;
-}
-
-/*
  * Add a keypress to the FRONT of the "queue"
  */
 errr term_key_push(int k)
@@ -1895,10 +1848,6 @@ errr term_inkey(char *ch, bool wait, bool take)
     /* Assume no key */
     (*ch) = '\0';
 
-#ifdef CHUUKEI
-    flush_ringbuf();
-#endif
-
     /* get bored */
     if (!Term->never_bored) {
         /* Process random events */
@@ -2001,7 +1950,7 @@ errr term_load(void)
 /*
  * Exchange the "requested" screen with the "tmp" screen
  */
-static errr term_exchange(void)
+errr term_exchange(void)
 {
     TERM_LEN w = Term->wid;
     TERM_LEN h = Term->hgt;
@@ -2222,7 +2171,7 @@ errr term_resize(TERM_LEN w, TERM_LEN h)
  * To "create" a valid "term", one should do "term_init(t)", then
  * set the various flags and hooks, and then do "term_activate(t)".
  */
-errr term_activate(term *t)
+errr term_activate(term_type *t)
 {
     /* already done */
     if (Term == t)
@@ -2256,75 +2205,15 @@ errr term_activate(term *t)
 }
 
 /*
- * Nuke a term
- */
-errr term_nuke(term *t)
-{
-    TERM_LEN w = t->wid;
-    TERM_LEN h = t->hgt;
-
-    /* Call the special "nuke" hook */
-    if (t->active_flag) {
-        /* Call the "nuke" hook */
-        if (t->nuke_hook)
-            (*t->nuke_hook)(t);
-
-        /* Remember */
-        t->active_flag = FALSE;
-
-        /* Assume not mapped */
-        t->mapped_flag = FALSE;
-    }
-
-    /* Nuke "displayed" */
-    term_win_nuke(t->old, w, h);
-
-    /* Kill "displayed" */
-    KILL(t->old, term_win);
-
-    /* Nuke "requested" */
-    term_win_nuke(t->scr, w, h);
-
-    /* Kill "requested" */
-    KILL(t->scr, term_win);
-
-    /* If needed */
-    if (t->mem) {
-        /* Nuke "memorized" */
-        term_win_nuke(t->mem, w, h);
-
-        /* Kill "memorized" */
-        KILL(t->mem, term_win);
-    }
-
-    /* If needed */
-    if (t->tmp) {
-        /* Nuke "temporary" */
-        term_win_nuke(t->tmp, w, h);
-
-        /* Kill "temporary" */
-        KILL(t->tmp, term_win);
-    }
-
-    /* Free some arrays */
-    C_KILL(t->x1, h, TERM_LEN);
-    C_KILL(t->x2, h, TERM_LEN);
-
-    /* Free the input queue */
-    C_KILL(t->key_queue, t->key_size, char);
-    return 0;
-}
-
-/*
  * Initialize a term, using a window of the given size.
  * Also prepare the "input queue" for "k" keypresses
  * By default, the cursor starts out "invisible"
  * By default, we "erase" using "black spaces"
  */
-errr term_init(term *t, TERM_LEN w, TERM_LEN h, int k)
+errr term_init(term_type *t, TERM_LEN w, TERM_LEN h, int k)
 {
     /* Wipe it */
-    (void)WIPE(t, term);
+    (void)WIPE(t, term_type);
 
     /* Prepare the input queue */
     t->key_head = t->key_tail = 0;
@@ -2381,3 +2270,69 @@ errr term_init(term *t, TERM_LEN w, TERM_LEN h, int k)
     t->pict_hook = term_pict_hack;
     return 0;
 }
+
+#ifdef JP
+/*
+ * Move to a location and, using an attr, add a string vertically
+ */
+errr term_putstr_v(TERM_LEN x, TERM_LEN y, int n, byte a, concptr s)
+{
+    errr res;
+    int y0 = y;
+
+    for (int i = 0; i < n && s[i] != 0; i++) {
+        /* Move first */
+        if ((res = term_gotoxy(x, y0)) != 0)
+            return (res);
+
+        if (iskanji(s[i])) {
+            if ((res = term_addstr(2, a, &s[i])) != 0)
+                return (res);
+            i++;
+            y0++;
+            if (s[i] == 0)
+                break;
+        } else {
+            if ((res = term_addstr(1, a, &s[i])) != 0)
+                return (res);
+            y0++;
+        }
+    }
+
+    return 0;
+}
+#endif
+
+#ifndef WINDOWS
+errr term_nuke(term_type *t)
+{
+    TERM_LEN w = t->wid;
+    TERM_LEN h = t->hgt;
+    if (t->active_flag) {
+        if (t->nuke_hook)
+            (*t->nuke_hook)(t);
+
+        t->active_flag = FALSE;
+        t->mapped_flag = FALSE;
+    }
+
+    term_win_nuke(t->old, w, h);
+    KILL(t->old, term_win);
+    term_win_nuke(t->scr, w, h);
+    KILL(t->scr, term_win);
+    if (t->mem) {
+        term_win_nuke(t->mem, w, h);
+        KILL(t->mem, term_win);
+    }
+
+    if (t->tmp) {
+        term_win_nuke(t->tmp, w, h);
+        KILL(t->tmp, term_win);
+    }
+
+    C_KILL(t->x1, h, TERM_LEN);
+    C_KILL(t->x2, h, TERM_LEN);
+    C_KILL(t->key_queue, t->key_size, char);
+    return 0;
+}
+#endif
\ No newline at end of file