-/* chuukei.c */
+/*!
+ @file chuukei.c
+ @brief 中継機能の実装
+ @date 2014/01/02
+ @author
+ 2014 Deskull rearranged comment for Doxygen.
+ */
#include "angband.h"
#ifdef WINDOWS
#define WAIT 100
#else
-#define WAIT 100*1000 /* ¥Ö¥é¥¦¥ºÂ¦¤Î¥¦¥¨¥¤¥È(usñ°Ì) */
+#define WAIT 100*1000 /* ブラウズ側のウエイト(us単位) */
#endif
#define DEFAULT_DELAY 50
#define RECVBUF_SIZE 1024
-static long epoch_time; /* ¥Ð¥Ã¥Õ¥¡³«»Ï»þ¹ï */
-static int browse_delay; /* ɽ¼¨¤¹¤ë¤Þ¤Ç¤Î»þ´Ö(100msñ°Ì)(¤³¤Î´Ö¤Ë¥é¥°¤òµÛ¼ý¤¹¤ë) */
+static long epoch_time; /* バッファ開始時刻 */
+static int browse_delay; /* 表示するまでの時間(100ms単位)(この間にラグを吸収する) */
#ifdef CHUUKEI
-static int sd; /* ¥½¥±¥Ã¥È¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿ */
-static long time_diff; /* ¥×¥ì¥¤Â¦¤È¤Î»þ´Ö¤Î¤º¤ì(¤³¤ì¤ò¸«¤Ê¤¬¤é¥Ç¥£¥ì¥¤¤òÄ´À°¤·¤Æ¤¤¤¯) */
+static int sd; /* ã\82½ã\82±ã\83\83ã\83\88ã\81®ã\83\95ã\82¡ã\82¤ã\83«ã\83\87ã\82£ã\82¹ã\82¯ã\83ªã\83\97ã\82¿ */
+static long time_diff; /* プレイ側との時間のずれ(これを見ながらディレイを調整していく) */
static int server_port;
static char server_name[MAX_HOSTNAME];
#endif
static EndpointRef ep = kOTInvalidEndpointRef;
#endif
#endif
-/* ÉÁ²è¤¹¤ë»þ¹ï¤ò³Ð¤¨¤Æ¤ª¤¯¥¥å¡¼¹½Â¤ÂÎ */
+/* 描画する時刻を覚えておくキュー構造体 */
static struct
{
int time[FRESH_QUEUE_SIZE];
}fresh_queue;
-/* ¥ê¥ó¥°¥Ð¥Ã¥Õ¥¡¹½Â¤ÂÎ */
+/* リングバッファ構造体 */
static struct
{
char *buf;
t->text_hook = old_text_hook;
}
-/* ANSI C¤Ë¤è¤ì¤ÐstaticÊÑ¿ô¤Ï0¤Ç½é´ü²½¤µ¤ì¤ë¤¬°ì±þ½é´ü²½¤¹¤ë */
+/* ANSI Cによればstatic変数は0で初期化されるが一応初期化する */
static errr init_buffer(void)
{
fresh_queue.next = fresh_queue.tail = 0;
return (0);
}
-/* ¸½ºß¤Î»þ´Ö¤ò100msñ°Ì¤Ç¼èÆÀ¤¹¤ë */
+/* 現在の時間を100ms単位で取得する */
static long get_current_time(void)
{
#ifdef WINDOWS
}
-/* ¥ê¥ó¥°¥Ð¥Ã¥Õ¥¡¹½Â¤ÂÎ¤Ë buf ¤ÎÆâÍƤò²Ã¤¨¤ë */
+/* リングバッファ構造体に buf の内容を加える */
static errr insert_ringbuf(char *buf)
{
int len;
- len = strlen(buf) + 1; /* +1¤Ï½ªÃ¼Ê¸»úʬ */
+ len = strlen(buf) + 1; /* +1は終端文字分 */
if (movie_mode)
{
#endif
}
- /* ¥Ð¥Ã¥Õ¥¡¤ò¥ª¡¼¥Ð¡¼ */
+ /* ã\83\90ã\83\83ã\83\95ã\82¡ã\82\92ã\82ªã\83¼ã\83\90ã\83¼ */
if (ring.inlen + len >= RINGBUF_SIZE)
{
#ifdef CHUUKEI
if (chuukei_server) disable_chuukei_server();
else chuukei_client = FALSE;
- prt("Á÷¼õ¿®¥Ð¥Ã¥Õ¥¡¤¬°î¤ì¤Þ¤·¤¿¡£¥µ¡¼¥Ð¤È¤ÎÀܳ¤òÀÚÃǤ·¤Þ¤¹¡£", 0, 0);
+ prt("送受信バッファが溢れました。サーバとの接続を切断します。", 0, 0);
inkey();
close(sd);
return (-1);
}
- /* ¥Ð¥Ã¥Õ¥¡¤Î½ªÃ¼¤Þ¤Ç¤Ë¼ý¤Þ¤ë */
+ /* バッファの終端までに収まる */
if (ring.wptr + len < RINGBUF_SIZE)
{
memcpy(ring.buf + ring.wptr, buf, len);
ring.wptr += len;
}
- /* ¥Ð¥Ã¥Õ¥¡¤Î½ªÃ¼¤Þ¤Ç¤Ë¼ý¤Þ¤é¤Ê¤¤(¥Ô¥Ã¥¿¥ê¼ý¤Þ¤ë¾ì¹ç¤â´Þ¤à) */
+ /* バッファの終端までに収まらない(ピッタリ収まる場合も含む) */
else
{
- int head = RINGBUF_SIZE - ring.wptr; /* Á°È¾ */
- int tail = len - head; /* ¸åȾ */
+ int head = RINGBUF_SIZE - ring.wptr; /* 前半 */
+ int tail = len - head; /* 後半 */
memcpy(ring.buf + ring.wptr, buf, head);
memcpy(ring.buf, buf + head, tail);
tmp_fdset = fdset;
- /* ¥½¥±¥Ã¥È¤Ë¥Ç¡¼¥¿¤ò½ñ¤¹þ¤á¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë */
+ /* ソケットにデータを書き込めるかどうか調べる */
select(sd+1, (fd_set *)NULL, &tmp_fdset, (fd_set *)NULL, &tv);
- /* ½ñ¤¹þ¤á¤Ê¤±¤ì¤ÐÌá¤ë */
+ /* 書き込めなければ戻る */
if (FD_ISSET(sd, &tmp_fdset) == 0) break;
result = send(sd, ring.buf + ring.rptr, ((ring.wptr > ring.rptr ) ? ring.wptr : RINGBUF_SIZE) - ring.rptr, 0);
if (result <= 0)
{
- /* ¥µ¡¼¥Ð¤È¤ÎÀܳÃÇ¡© */
+ /* サーバとの接続断? */
if (chuukei_server) disable_chuukei_server();
- prt("¥µ¡¼¥Ð¤È¤ÎÀܳ¤¬ÀÚÃǤµ¤ì¤Þ¤·¤¿¡£", 0, 0);
+ prt("サーバとの接続が切断されました。", 0, 0);
inkey();
close(sd);
{
int result;
- /* ¥½¥±¥Ã¥È¤Ë¥Ç¡¼¥¿¤ò½ñ¤¹þ¤á¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë */
+ /* ソケットにデータを書き込めるかどうか調べる */
result = OTSnd(ep, ring.buf + ring.rptr, ((ring.wptr > ring.rptr ) ? ring.wptr : RINGBUF_SIZE) - ring.rptr, 0);
if (result <= 0)
{
- /* ¥µ¡¼¥Ð¤È¤ÎÀܳÃÇ¡© */
+ /* サーバとの接続断? */
if (chuukei_server) disable_chuukei_server();
- prt("¥µ¡¼¥Ð¤È¤ÎÀܳ¤¬ÀÚÃǤµ¤ì¤Þ¤·¤¿¡£", 0, 0);
+ prt("サーバとの接続が切断されました。", 0, 0);
inkey();
close(sd);
if (!fp) return (-1);
- /* ½é´ü²½ */
+ /* 初期化 */
server_port = -1;
server_name[0] = 0;
browse_delay = DEFAULT_DELAY;
while (0 == my_fgets(fp, buf, sizeof(buf)))
{
- /* ¥µ¡¼¥Ð̾ */
+ /* サーバ名 */
if (!strncmp(buf, "server:", 7))
{
strncpy(server_name, buf + 7, MAX_HOSTNAME - 1);
server_name[MAX_HOSTNAME - 1] = '\0';
}
- /* ¥Ý¡¼¥ÈÈÖ¹æ */
+ /* ポート番号 */
if (!strncmp(buf, "port:", 5))
{
server_port = atoi(buf + 5);
}
- /* ¥Ç¥£¥ì¥¤ */
+ /* ã\83\87ã\82£ã\83¬ã\82¤ */
if (!strncmp(buf, "delay:", 6))
{
browse_delay = atoi(buf + 6);
my_fclose(fp);
- /* prf¥Õ¥¡¥¤¥ë¤¬´°Á´¤Ç¤Ê¤¤ */
+ /* prfファイルが完全でない */
if (server_port == -1 || server_name[0] == 0) return (-1);
return (0);
}
#endif /* CHUUKEI */
-/* str¤¬Æ±¤¸Ê¸»ú¤Î·«¤êÊÖ¤·¤«¤É¤¦¤«Ä´¤Ù¤ë */
+/* strが同じ文字の繰り返しかどうか調べる */
static bool string_is_repeat(char *str, int len)
{
char c = str[0];
}
else
{
-#ifdef SJIS
+#if defined(SJIS) && defined(JP)
sjis2euc(buf2);
#endif
sprintf(buf, "t%c%c%c%c%s", x+1, y+1, len, col, buf2);
disable_chuukei_server();
#endif
fd_close(movie_fd);
-#ifdef JP
- msg_print("Ï¿²è¤ò½ªÎ»¤·¤Þ¤·¤¿¡£");
-#else
- msg_print("Stopped recording.");
-#endif
+ msg_print(_("録画を終了しました。", "Stopped recording."));
}
else
{
sprintf(tmp, "%s.amv", player_base);
-#ifdef JP
- if (get_string("¥à¡¼¥Ó¡¼µÏ¿¥Õ¥¡¥¤¥ë: ", tmp, 80))
-#else
- if (get_string("Movie file name: ", tmp, 80))
-#endif
+ if (get_string(_("ムービー記録ファイル: ", "Movie file name: "), tmp, 80))
{
int fd;
(void)fd_close(fd);
/* Build query */
-#ifdef JP
- (void)sprintf(out_val, "¸½Â¸¤¹¤ë¥Õ¥¡¥¤¥ë¤Ë¾å½ñ¤¤·¤Þ¤¹¤«? (%s)", buf);
-#else
- (void)sprintf(out_val, "Replace existing file %s? ", buf);
-#endif
+ (void)sprintf(out_val, _("現存するファイルに上書きしますか? (%s)", "Replace existing file %s? "), buf);
/* Ask */
if (!get_check(out_val)) return;
if (!movie_fd)
{
-#ifdef JP
- msg_print("¥Õ¥¡¥¤¥ë¤ò³«¤±¤Þ¤»¤ó¡ª");
-#else
- msg_print("Can not open file.");
-#endif
+ msg_print(_("ファイルを開けません!", "Can not open file."));
return;
}
{
long current_time = get_current_time();
- /* ÉÁ²è¥¥å¡¼¤Ï¶õ¤«¤É¤¦¤«¡© */
+ /* 描画キューは空かどうか? */
if (fresh_queue.tail == fresh_queue.next)
{
- /* ¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤·»Ï¤á¤Î»þ´Ö¤òÊݸ¤·¤Æ¤ª¤¯ */
+ /* バッファリングし始めの時間を保存しておく */
epoch_time = current_time;
epoch_time += browse_delay;
epoch_time -= timestamp;
time_diff = current_time - timestamp;
}
- /* ÉÁ²è¥¥å¡¼¤ËÊݸ¤·¡¢Êݸ°ÌÃÖ¤ò¿Ê¤á¤ë */
+ /* 描画キューに保存し、保存位置を進める */
fresh_queue.time[fresh_queue.tail] = timestamp;
fresh_queue.tail ++;
- /* ¥¥å¡¼¤ÎºÇ¸åÈø¤ËÅþ㤷¤¿¤éÀèƬ¤ËÌ᤹ */
+ /* キューの最後尾に到達したら先頭に戻す */
fresh_queue.tail %= FRESH_QUEUE_SIZE;
if (fresh_queue.tail == fresh_queue.next)
{
- /* ÉÁ²è¥¥å¡¼°î¤ì */
- prt("ÉÁ²è¥¿¥¤¥ß¥ó¥°¥¥å¡¼¤¬°î¤ì¤Þ¤·¤¿¡£¥µ¡¼¥Ð¤È¤ÎÀܳ¤òÀÚÃǤ·¤Þ¤¹¡£", 0, 0);
+ /* 描画キュー溢れ */
+ prt("描画タイミングキューが溢れました。サーバとの接続を切断します。", 0, 0);
inkey();
close(sd);
return -1;
}
- /* ¥×¥ì¥¤Â¦¤È¤Î¥Ç¥£¥ì¥¤¤òÄ´À° */
+ /* プレイ側とのディレイを調整 */
if (time_diff != current_time - timestamp)
{
long old_time_diff = time_diff;
{
static int initialized = FALSE;
- /* ÉÁ²è¥¥å¡¼¤Ï¶õ¤«¤É¤¦¤«¡© */
+ /* 描画キューは空かどうか? */
if (!initialized)
{
- /* ¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤·»Ï¤á¤Î»þ´Ö¤òÊݸ¤·¤Æ¤ª¤¯ */
+ /* バッファリングし始めの時間を保存しておく */
epoch_time = get_current_time();
epoch_time += browse_delay;
epoch_time -= timestamp;
initialized = TRUE;
}
- /* ÉÁ²è¥¥å¡¼¤ËÊݸ¤·¡¢Êݸ°ÌÃÖ¤ò¿Ê¤á¤ë */
+ /* 描画キューに保存し、保存位置を進める */
fresh_queue.time[fresh_queue.tail] = timestamp;
fresh_queue.tail ++;
- /* ¥¥å¡¼¤ÎºÇ¸åÈø¤ËÅþ㤷¤¿¤éÀèƬ¤ËÌ᤹ */
+ /* キューの最後尾に到達したら先頭に戻す */
fresh_queue.tail %= FRESH_QUEUE_SIZE;
/* Success */
int recv_bytes;
int i;
- /* Á°²ó»Ä¤Ã¤¿¥Ç¡¼¥¿¤Î¸å¤Ë¤Ä¤Å¤±¤ÆÇÛ¿®¥µ¡¼¥Ð¤«¤é¥Ç¡¼¥¿¼õ¿® */
+ /* 前回残ったデータの後につづけて配信サーバからデータ受信 */
recv_bytes = recv(sd, recv_buf + remain_bytes, RECVBUF_SIZE - remain_bytes, 0);
if (recv_bytes <= 0)
return -1;
- /* Á°²ó»Ä¤Ã¤¿¥Ç¡¼¥¿Î̤˺£²óÆɤó¤À¥Ç¡¼¥¿Î̤òÄɲà */
+ /* 前回残ったデータ量に今回読んだデータ量を追加 */
remain_bytes += recv_bytes;
for (i = 0; i < remain_bytes; i ++)
{
- /* ¥Ç¡¼¥¿¤Î¤¯¤®¤ê('\0')¤òõ¤¹ */
+ /* データのくぎり('\0')を探す */
if (recv_buf[i] == '\0')
{
- /* 'd'¤Ç»Ï¤Þ¤ë¥Ç¡¼¥¿(¥¿¥¤¥à¥¹¥¿¥ó¥×)¤Î¾ì¹ç¤Ï
- ÉÁ²è¥¥å¡¼¤ËÊݸ¤¹¤ë½èÍý¤ò¸Æ¤Ö */
+ /* 'd'で始まるデータ(タイムスタンプ)の場合は
+ 描画キューに保存する処理を呼ぶ */
if ((recv_buf[0] == 'd') &&
(handle_timestamp_data(atoi(recv_buf + 1)) < 0))
return -1;
- /* ¼õ¿®¥Ç¡¼¥¿¤òÊݸ */
+ /* 受信データを保存 */
if (insert_ringbuf(recv_buf) < 0)
return -1;
- /* ¼¡¤Î¥Ç¡¼¥¿°Ü¹Ô¤òrecv_buf¤ÎÀèƬ¤Ë°ÜÆ° */
+ /* 次のデータ移行をrecv_bufの先頭に移動 */
memmove(recv_buf, recv_buf + i + 1, remain_bytes - i - 1);
remain_bytes -= (i+1);
if (recv_bytes <= 0)
return -1;
- /* Á°²ó»Ä¤Ã¤¿¥Ç¡¼¥¿Î̤˺£²óÆɤó¤À¥Ç¡¼¥¿Î̤òÄɲà */
+ /* 前回残ったデータ量に今回読んだデータ量を追加 */
remain_bytes += recv_bytes;
for (i = 0; i < remain_bytes; i ++)
{
- /* ¥Ç¡¼¥¿¤Î¤¯¤®¤ê('\0')¤òõ¤¹ */
+ /* データのくぎり('\0')を探す */
if (recv_buf[i] == '\0')
{
- /* 'd'¤Ç»Ï¤Þ¤ë¥Ç¡¼¥¿(¥¿¥¤¥à¥¹¥¿¥ó¥×)¤Î¾ì¹ç¤Ï
- ÉÁ²è¥¥å¡¼¤ËÊݸ¤¹¤ë½èÍý¤ò¸Æ¤Ö */
+ /* 'd'で始まるデータ(タイムスタンプ)の場合は
+ 描画キューに保存する処理を呼ぶ */
if ((recv_buf[0] == 'd') &&
(handle_movie_timestamp_data(atoi(recv_buf + 1)) < 0))
return -1;
- /* ¼õ¿®¥Ç¡¼¥¿¤òÊݸ */
+ /* 受信データを保存 */
if (insert_ringbuf(recv_buf) < 0)
return -1;
- /* ¼¡¤Î¥Ç¡¼¥¿°Ü¹Ô¤òrecv_buf¤ÎÀèƬ¤Ë°ÜÆ° */
+ /* 次のデータ移行をrecv_bufの先頭に移動 */
memmove(recv_buf, recv_buf + i + 1, remain_bytes - i - 1);
remain_bytes -= (i+1);
#ifndef WINDOWS
-/* WinÈǤÎÃæÅÀ¤ÈÊɤÎƦÉå¤ò¥Ô¥ê¥ª¥É¤È¥·¥ã¡¼¥×¤Ë¤¹¤ë¡£*/
+/* Win版の床の中点と壁の豆腐をピリオドとシャープにする。*/
static void win2unix(int col, char *buf)
{
char kabe;
return (TRUE);
}
-/* ¥×¥ì¥¤¥Û¥¹¥È¤Î¥Þ¥Ã¥×¤¬Â礤¤¤È¤¥¯¥é¥¤¥¢¥ó¥È¤Î¥Þ¥Ã¥×¤â¥ê¥µ¥¤¥º¤¹¤ë */
+/* プレイホストのマップが大きいときクライアントのマップもリサイズする */
static void update_term_size(int x, int y, int len)
{
int ox, oy;
nx = ox;
ny = oy;
- /* ²£Êý¸þ¤Î¥Á¥§¥Ã¥¯ */
+ /* 横æ\96¹å\90\91ã\81®ã\83\81ã\82§ã\83\83ã\82¯ */
if (x + len > ox) nx = x + len;
- /* ½ÄÊý¸þ¤Î¥Á¥§¥Ã¥¯ */
+ /* 縦æ\96¹å\90\91ã\81®ã\83\81ã\82§ã\83\83ã\82¯ */
if (y + 1 > oy) ny = y + 1;
if (nx != ox || ny != oy) Term_resize(nx, ny);
{
char buf[1024];
- /* ½ñ¤¯¥Ç¡¼¥¿¤Ê¤· */
+ /* 書くデータなし */
if (fresh_queue.next == fresh_queue.tail) return (FALSE);
- /* ¤Þ¤À½ñ¤¯¤Ù¤»þ¤Ç¤Ê¤¤ */
+ /* まだ書くべき時でない */
if (fresh_queue.time[fresh_queue.next] > get_current_time() - epoch_time) return (FALSE);
- /* »þ´Ö¾ðÊó(¶èÀÚ¤ê)¤¬ÆÀ¤é¤ì¤ë¤Þ¤Ç½ñ¤¯ */
+ /* 時間情報(区切り)が得られるまで書く */
while (get_nextbuf(buf))
{
char id;
switch (id)
{
- case 't': /* Ä̾ï */
-#ifdef SJIS
+ case 't': /* 通常 */
+#if defined(SJIS) && defined(JP)
euc2sjis(mesg);
#endif
update_term_size(x, y, len);
}
break;
- case 'n': /* ·«¤êÊÖ¤· */
+ case 'n': /* 繰り返し */
for (i = 1; i < len; i++)
{
mesg[i] = mesg[0];
}
break;
- case 's': /* °ìʸ»ú */
+ case 's': /* 一文字 */
update_term_size(x, y, 1);
(void)((*angband_term[0]->text_hook)(x, y, 1, (byte)col, mesg));
strncpy(&Term->scr->c[y][x], mesg, 1);
tmp_fdset = fdset;
tmp_tv = tv;
- /* ¥½¥±¥Ã¥È¤Ë¥Ç¡¼¥¿¤¬Íè¤Æ¤¤¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë */
+ /* ソケットにデータが来ているかどうか調べる */
select(sd+1, &tmp_fdset, (fd_set *)NULL, (fd_set *)NULL, &tmp_tv);
if (FD_ISSET(sd, &tmp_fdset) == 0)
{
chuukei_client = FALSE;
}
- /* Àܳ¤¬Àڤ줿¾õÂ֤ǽñ¤¯¤Ù¤¥Ç¡¼¥¿¤¬¤Ê¤¯¤Ê¤Ã¤Æ¤¤¤¿¤é½ªÎ» */
+ /* 接続が切れた状態で書くべきデータがなくなっていたら終了 */
if (!chuukei_client && fresh_queue.next == fresh_queue.tail ) break;
}
#else
if (flush_ringbuf_client()) continue;
- /* ¥½¥±¥Ã¥È¤Ë¥Ç¡¼¥¿¤¬Íè¤Æ¤¤¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë */
+ /* ソケットにデータが来ているかどうか調べる */
OTCountDataBytes(ep, &unreadData);
if(unreadData <= 0 ){
chuukei_client = FALSE;
}
- /* Àܳ¤¬Àڤ줿¾õÂ֤ǽñ¤¯¤Ù¤¥Ç¡¼¥¿¤¬¤Ê¤¯¤Ê¤Ã¤Æ¤¤¤¿¤é½ªÎ» */
+ /* 接続が切れた状態で書くべきデータがなくなっていたら終了 */
if (!chuukei_client && fresh_queue.next == fresh_queue.tail ) break;
}
#endif /*MACINTOSH*/
{
Term_xtra(TERM_XTRA_FLUSH, 0);
- /* ¥½¥±¥Ã¥È¤Ë¥Ç¡¼¥¿¤¬Íè¤Æ¤¤¤ë¤«¤É¤¦¤«Ä´¤Ù¤ë */
+ /* ソケットにデータが来ているかどうか調べる */
#ifdef WINDOWS
Sleep(WAIT);
#else