Expose g_nact

This commit is contained in:
kichikuou
2024-12-11 14:03:55 +09:00
parent e791af2a1e
commit 4930154d45
9 changed files with 85 additions and 87 deletions
+6 -6
View File
@@ -19,7 +19,7 @@
SDL_Window* g_window;
SDL_Renderer* g_renderer;
NACT* g_nact;
std::unique_ptr<NACT> g_nact;
namespace {
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
g_renderer = SDL_CreateRenderer(g_window, -1, 0);
// system3 初期化
g_nact = NACT::create(config, game_id);
g_nact.reset(NACT::create(config, game_id));
if (!config.save_dir.empty()) {
std::string path = config.save_dir;
@@ -107,12 +107,12 @@ int main(int argc, char *argv[])
texthook_set_mode(config.texthook_mode);
texthook_set_suppression_list(config.texthook_suppressions.c_str());
int exit_code = NACT_RESTART;
while (exit_code == NACT_RESTART) {
int exit_code = 0;
while (g_nact) {
exit_code = g_nact->mainloop();
delete g_nact;
g_nact.reset();
if (exit_code == NACT_RESTART)
g_nact = NACT::create(config, game_id);
g_nact.reset(NACT::create(config, game_id));
}
SDL_DestroyRenderer(g_renderer);
+4 -3
View File
@@ -6,6 +6,7 @@
#include "ags.h"
#include <string.h>
#include "nact.h"
#include "game_id.h"
#include "../config.h"
#include "../fileio.h"
@@ -58,7 +59,7 @@ SDL_Texture* create_scanline_texture(SDL_Renderer* renderer, int width, int heig
} // namespace
AGS::AGS(NACT* parent, const Config& config) : nact(parent), game_id(parent->game_id), dirty(false)
AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id), dirty(false)
{
// 画面サイズ
if (game_id.crc32_a == CRC32_GAKUEN || game_id.crc32_a == CRC32_GAKUEN_ENG) {
@@ -475,7 +476,7 @@ void AGS::fade_out(int duration_ms, bool white)
Uint32 dwStart = SDL_GetTicks();
while (fade_level < 255) {
nact->sys_sleep(16);
g_nact->sys_sleep(16);
int t = SDL_GetTicks() - dwStart;
fade_level = t >= duration_ms ? 255 : t * 255 / duration_ms;
dirty = true;
@@ -490,7 +491,7 @@ void AGS::fade_in(int duration_ms)
Uint32 dwStart = SDL_GetTicks();
while (fade_level > 0) {
nact->sys_sleep(16);
g_nact->sys_sleep(16);
int t = SDL_GetTicks() - dwStart;
fade_level = t >= duration_ms ? 0 : (duration_ms - t) * 255 / duration_ms;
dirty = true;
+2 -3
View File
@@ -10,7 +10,7 @@
#include <memory>
#include <stdio.h>
#include "../common.h"
#include "nact.h"
#include "game_id.h"
#include "dri.h"
#include <SDL_ttf.h>
@@ -39,7 +39,6 @@ struct Config;
class AGS
{
protected:
NACT* nact;
const GameId& game_id;
private:
SDL_Texture* sdlTexture;
@@ -90,7 +89,7 @@ private:
int fade_color = 0; // 0: black, 255: white
public:
AGS(NACT* parent, const Config& config);
AGS(const Config& config, const GameId& game_id);
~AGS();
void update_screen();
+4 -3
View File
@@ -6,6 +6,7 @@
#include <string.h>
#include "ags.h"
#include "nact.h"
#include "encoding.h"
#include "texthook.h"
@@ -384,7 +385,7 @@ void AGS::draw_text(const char* string, bool text_wait)
dest_y -= (ascent - descent - font_size) / 2;
while (*string) {
int code = nact->encoding->next_codepoint(&string);
int code = g_nact->encoding->next_codepoint(&string);
if(draw_hankaku) {
code = convert_to_hankaku(code);
} else {
@@ -398,7 +399,7 @@ void AGS::draw_text(const char* string, bool text_wait)
dest_x += font_size;
} else {
if (!draw_menu)
texthook_character(nact->get_scenario_page(), code);
texthook_character(g_nact->get_scenario_page(), code);
if (antialias)
draw_char_antialias(screen, dest_x, dest_y, code, font, font_color, antialias_cache);
@@ -419,7 +420,7 @@ void AGS::draw_text(const char* string, bool text_wait)
draw_screen(text_dest_x, dest_y, dest_x - text_dest_x, ascent - descent);
text_dest_x = dest_x;
// Wait
nact->text_wait();
g_nact->text_wait();
}
}
if (draw_menu)
+4 -5
View File
@@ -19,9 +19,8 @@ inline uint32 hash(uint32 x, int s) {
} // namespace
MsgSkip::MsgSkip(NACT* nact)
: nact(nact),
bloom(new uint8[BLOOM_FILTER_SIZE / 8]),
MsgSkip::MsgSkip()
: bloom(new uint8[BLOOM_FILTER_SIZE / 8]),
dirty(false),
flags(MSGSKIP_STOP_ON_UNSEEN | MSGSKIP_STOP_ON_MENU | MSGSKIP_STOP_ON_CLICK),
activated(false),
@@ -65,7 +64,7 @@ void MsgSkip::activate(bool enable)
{
if (activated != enable) {
activated = enable;
nact->set_skip_menu_state(enabled, activated);
g_nact->set_skip_menu_state(enabled, activated);
}
}
@@ -95,7 +94,7 @@ void MsgSkip::on_message(int page, int addr)
enabled = true;
}
if (enabled != old_enabled || activated != old_activated)
nact->set_skip_menu_state(enabled, activated);
g_nact->set_skip_menu_state(enabled, activated);
}
void MsgSkip::set_flags(unsigned val, unsigned mask) {
+1 -4
View File
@@ -3,8 +3,6 @@
#include "common.h"
class NACT;
enum MsgSkipFlags {
MSGSKIP_SKIP_UNSEEN = 1,
MSGSKIP_STOP_ON_UNSEEN = 2,
@@ -14,7 +12,7 @@ enum MsgSkipFlags {
class MsgSkip {
public:
MsgSkip(NACT* nact);
MsgSkip();
~MsgSkip();
void activate(bool enable);
@@ -27,7 +25,6 @@ class MsgSkip {
void set_flags(unsigned flags, unsigned mask);
private:
NACT* nact;
uint8* bloom;
bool dirty;
unsigned flags;
+2 -2
View File
@@ -88,9 +88,9 @@ NACT::NACT(const Config& config, const GameId& game_id)
memset(pcm, 0, sizeof(pcm));
// 各種クラス生成
ags = new AGS(this, config);
ags = new AGS(config, game_id);
mako = new MAKO(config, game_id);
msgskip = new MsgSkip(this);
msgskip = new MsgSkip();
SDL_Init(SDL_INIT_GAMECONTROLLER);
for (int i = 0; i < SDL_NumJoysticks(); ++i) {
+2
View File
@@ -392,4 +392,6 @@ private:
bool k3_hack(const K3HackInfo* info_table);
};
extern std::unique_ptr<NACT> g_nact;
#endif // _NACT_H_
+60 -61
View File
@@ -67,72 +67,71 @@ void save_screenshot(AGS* ags)
ags->save_screenshot(pathbuf);
}
INT_PTR CALLBACK TextDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static NACT* nact;
char string[64];
wchar_t wstring[64];
switch(msg) {
case WM_CLOSE:
EndDialog(hDlg, IDCANCEL);
break;
case WM_INITDIALOG:
{
// get this pointer
nact = (NACT *)lParam;
// init dialog
swprintf_s(wstring, 64, L"文字列を入力してください(最大%d文字)", nact->tvar_maxlen);
SetWindowTextW(GetDlgItem(hDlg, IDC_TEXT), wstring);
char *oldstr = nact->encoding->toUtf8(nact->tvar[nact->tvar_index - 1]);
MultiByteToWideChar(CP_UTF8, 0, oldstr, -1, wstring, 64);
SetWindowTextW(GetDlgItem(hDlg, IDC_EDITBOX), wstring);
EnableWindow(GetDlgItem(hDlg, IDOK), oldstr[0] != '\0');
free(oldstr);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_EDITBOX:
{
int len = GetWindowTextLengthW(GetDlgItem(hDlg, IDC_EDITBOX));
if (len == 0 || len > nact->tvar_maxlen) {
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
} else {
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
}
}
break;
case IDOK:
{
GetDlgItemTextW(hDlg, IDC_EDITBOX, wstring, 64);
WideCharToMultiByte(CP_UTF8, 0, wstring, -1, string, sizeof(string), NULL, NULL);
char *newstr = nact->encoding->fromUtf8(string);
strcpy_s(nact->tvar[nact->tvar_index - 1], 22, newstr);
free(newstr);
EndDialog(hDlg, IDOK);
}
break;
default:
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
}
} // namespace
void NACT::text_dialog()
{
auto dialog_proc = [](HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) -> INT_PTR
#ifdef __MINGW32__
CALLBACK // MinGW requires this but MSVC doesn't like it
#endif
{
char string[64];
wchar_t wstring[64];
switch(msg) {
case WM_CLOSE:
EndDialog(hDlg, IDCANCEL);
break;
case WM_INITDIALOG:
{
// init dialog
swprintf_s(wstring, 64, L"文字列を入力してください(最大%d文字)", g_nact->tvar_maxlen);
SetWindowTextW(GetDlgItem(hDlg, IDC_TEXT), wstring);
char *oldstr = g_nact->encoding->toUtf8(g_nact->tvar[g_nact->tvar_index - 1]);
MultiByteToWideChar(CP_UTF8, 0, oldstr, -1, wstring, 64);
SetWindowTextW(GetDlgItem(hDlg, IDC_EDITBOX), wstring);
EnableWindow(GetDlgItem(hDlg, IDOK), oldstr[0] != '\0');
free(oldstr);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_EDITBOX:
{
int len = GetWindowTextLengthW(GetDlgItem(hDlg, IDC_EDITBOX));
if (len == 0 || len > g_nact->tvar_maxlen) {
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
} else {
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
}
}
break;
case IDOK:
{
GetDlgItemTextW(hDlg, IDC_EDITBOX, wstring, 64);
WideCharToMultiByte(CP_UTF8, 0, wstring, -1, string, sizeof(string), NULL, NULL);
char *newstr = g_nact->encoding->fromUtf8(string);
strcpy_s(g_nact->tvar[g_nact->tvar_index - 1], 22, newstr);
free(newstr);
EndDialog(hDlg, IDOK);
}
break;
default:
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
};
HINSTANCE hinst = (HINSTANCE)GetModuleHandle(NULL);
DialogBoxParam(hinst, MAKEINTRESOURCE(IDD_DIALOG1), get_hwnd(g_window), TextDialogProc, (LPARAM)this);
DialogBoxParam(hinst, MAKEINTRESOURCE(IDD_DIALOG1), get_hwnd(g_window), dialog_proc, 0);
}
void NACT::platform_initialize()