Refactor main loop

This commit is contained in:
kichikuou
2021-07-17 22:12:16 +09:00
parent fb44e5b1e3
commit 2e2fbbaa1b
6 changed files with 58 additions and 46 deletions
+1 -5
View File
@@ -17,9 +17,6 @@
#include "night.h"
#include "nt_msg.h"
/* defined by cmd_check.c */
extern void check_command(int c0);
#define MAINLOOP_EVENTCHECK_INTERVAL 16 /* 16 msec */
@@ -57,10 +54,9 @@ static void ntmain(struct _scoadr inadr) {
while (!nact->is_quit) {
for (int cnt = 0; !nact->wait_vsync && cnt < 10000; cnt++) {
DEBUG_MESSAGE("%d:%x\n", sl_getPage(), sl_getIndex());
//SACT_DEBUG("%d:%x\n", sl_getPage(), sl_getIndex());
if (!nact->popupmenu_opened) {
check_command(sl_getc());
exec_command();
if (sl_getPage() == inadr.page &&
sl_getIndex() == inadr.index) {
// ~E%05dからの戻り
+35 -2
View File
@@ -147,10 +147,43 @@ static void undeferr() {
SYSERROR("Undefined Command:@ %03d,%05x\n", sl_getPage(), sl_getIndex());
}
void check_command(int c0) {
static void message(int c0) {
char buf[512];
char *p = buf;
while (c0 == 0x20 || c0 >= 0x80) {
if (nact->encoding == UTF8) {
*p++ = (char)c0;
} else if (c0 == 0x20) {
*p++ = (char)c0;
} else if (c0 >= 0xe0) {
*p++ = (char)c0; *p++ = (char)sl_getc();
} else if (c0 >= 0xa0) {
*p++ = (char)c0;
} else {
*p++ = (char)c0; *p++ = (char)sl_getc();
}
c0 = sl_getc();
}
sl_ungetc();
if (p != buf) {
*p = '\0';
sys_addMsg(buf);
}
}
void exec_command(void) {
DEBUG_MESSAGE("%d:%x\n", sl_getPage(), sl_getIndex());
int page, index;
int bool;
int c0 = sl_getc();
if (c0 == 0x20 || c0 >= 0x80) {
message(c0);
return;
}
switch(c0) {
case 0:
/* メッセージのゴミ? */
+13 -39
View File
@@ -54,8 +54,6 @@ MG コマンド: 表示時の ZH に依存
*/
/* defined by cmd_check.c */
extern void check_command(int c0);
/* defined by cmdv.c */
extern void va_animation();
/* コマンド解析時の展開バッファ */
@@ -138,32 +136,6 @@ void sys_addMsg(const char *str) {
}
}
/* 文字列抽出 */
static int checkMessage() {
char *index = msgbuf;
int c0 = sl_getc();
while (c0 == 0x20 || c0 >= 0x80) {
if (nact->encoding == UTF8) {
*index++ = (char)c0;
} else if (c0 == 0x20) {
*index++ = (char)c0;
} else if (c0 >= 0xe0) {
*index++ = (char)c0; *index++ = (char)sl_getc();
} else if (c0 >= 0xa0) {
*index++ = (char)c0;
} else {
*index++ = (char)c0; *index++ = (char)sl_getc();
}
c0 = sl_getc();
}
if (index != msgbuf) {
*index = 0;
sys_addMsg(msgbuf);
}
return c0;
}
void nact_main() {
reset_counter_high(SYSTEMCOUNTER_MSEC, 1, 0);
@@ -175,22 +147,24 @@ void nact_main() {
for (int cnt = 0; cnt < 10000; cnt++) {
if (nact->wait_vsync || nact->popupmenu_opened || nact->is_quit)
break;
DEBUG_MESSAGE("%d:%x\n", sl_getPage(), sl_getIndex());
int c0 = checkMessage();
check_command(c0);
exec_command();
nact->cmd_count++;
}
nact->callback();
if (!nact->is_message_locked)
sys_getInputInfo();
sdl_wait_vsync();
nact->frame_count++;
nact->wait_vsync = FALSE;
nact_endframe();
}
}
void nact_endframe(void) {
nact->callback();
if (!nact->is_message_locked)
sys_getInputInfo();
sdl_wait_vsync();
nact->frame_count++;
nact->wait_vsync = FALSE;
}
static void nact_callback() {
if (nact->is_va_animation) {
va_animation();
+4
View File
@@ -58,6 +58,10 @@ extern char *sys_getConstString();
// extern boolean sys_nact_engine();
extern void nact_main();
extern void nact_init();
extern void nact_endframe(void);
// cmd_check.c
extern void exec_command(void);
typedef struct {
/* general */
+4
View File
@@ -200,6 +200,10 @@ int sl_getadr() {
return c0 + (c1 << 16);
}
void sl_ungetc(void) {
sl_index--;
}
/* @address */
void sl_jmpNear(int address) {
sl_index = address;
+1
View File
@@ -35,6 +35,7 @@ extern int sl_getdAt(int address);
extern int sl_getwAt(int address);
extern int sl_getcAt(int address);
extern int sl_getadr();
extern void sl_ungetc(void);
extern void sl_jmpNear(int address);
extern boolean sl_jmpFar(int page);
extern boolean sl_jmpFar2(int page, int address);