From 3f98902d982e3189fc530baee8a6ac479cd32471 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Thu, 3 Sep 2026 10:15:14 +0900 Subject: [PATCH] Remove SCREEN_MENU --- src/sys/ags.cpp | 1 - src/sys/ags.h | 3 ++- src/sys/ags_draw.cpp | 15 ++++++++++++++ src/sys/nact_gakuenking.cpp | 40 ++++++++++++++++++++++++++----------- src/sys/nact_sys3.cpp | 10 ++++++---- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/sys/ags.cpp b/src/sys/ags.cpp index aaddcc5..e2ee07e 100644 --- a/src/sys/ags.cpp +++ b/src/sys/ags.cpp @@ -63,7 +63,6 @@ AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id) // All surfaces share the same palette. screen_palette = hBmpScreen[SCREEN_FRONT]->format->palette; SDL_SetSurfacePalette(hBmpScreen[SCREEN_BACK], screen_palette); - SDL_SetSurfacePalette(hBmpScreen[SCREEN_MENU], screen_palette); if (!config.censor_list.empty()) load_censor_list(config.censor_list.c_str()); diff --git a/src/sys/ags.h b/src/sys/ags.h index 2a32b16..65fdfe0 100644 --- a/src/sys/ags.h +++ b/src/sys/ags.h @@ -23,7 +23,6 @@ struct Config; enum ScreenId { SCREEN_FRONT, SCREEN_BACK, - SCREEN_MENU, NR_SCREENS, }; @@ -91,7 +90,9 @@ public: // Returns an ACG page bytes, without decoding it. std::vector load_cg_data(int page) { return acg.load(page); } void blit_cg(ScreenId dest, CG& cg, const SDL_Rect* src, int dx, int dy); + void blit_cg(CG& dest, CG& cg, const SDL_Rect* src, int dx, int dy); void set_cg_file(const char *file_name); + CG create_offscreen(int width, int height); void load_censor_list(const char* fname); diff --git a/src/sys/ags_draw.cpp b/src/sys/ags_draw.cpp index a743c97..e566870 100644 --- a/src/sys/ags_draw.cpp +++ b/src/sys/ags_draw.cpp @@ -119,6 +119,21 @@ void AGS::blit_cg(ScreenId dest, CG& cg, const SDL_Rect* src, int dx, int dy) } } +void AGS::blit_cg(CG& dest, CG& cg, const SDL_Rect* src, int dx, int dy) +{ + if (!cg.surface()) + return; + SDL_Rect dstrect = { dx, dy, src ? src->w : cg.width(), src ? src->h : cg.height() }; + SDL_BlitSurface(cg.surface(), src, dest.surface(), &dstrect); +} + +CG AGS::create_offscreen(int width, int height) +{ + CG cg(0, 0, width, height); + SDL_SetSurfacePalette(cg.surface(), screen_palette); + return cg; +} + void AGS::load_cg(int page, int transparent, uint8_t flags) { CG cg = load_cg_surface(page, transparent, flags); diff --git a/src/sys/nact_gakuenking.cpp b/src/sys/nact_gakuenking.cpp index 5dd0f12..0bb8091 100644 --- a/src/sys/nact_gakuenking.cpp +++ b/src/sys/nact_gakuenking.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -46,6 +47,7 @@ public: box[1] = {0, 40, 0, 599, 298}; load_executable_data(); amap.open("AMAP.DAT"); + composed_map = ags->create_offscreen((VIEW_COLS + 1) * TILE_SIZE, (VIEW_ROWS + 1) * TILE_SIZE); map_base.fill(0); map_layer_z.fill(CELL_EMPTY); map_layer_w.fill(CELL_EMPTY); @@ -462,6 +464,8 @@ private: // 1-10 with the number keys, but we do not support that. int map_animation_ticks = 9; + CG composed_map; + // The sheets loaded by Y 50-53, kept whole rather than split into per-tile images. CG map_sprite_cg; CG map_tile_cg[NR_TILE_BANKS]; @@ -563,8 +567,8 @@ private: if (!map_base_visible_view) base = CELL_EMPTY; if (base == CELL_EMPTY) { - ags->box_fill(SCREEN_MENU, px, py, - px + TILE_SIZE - 1, py + TILE_SIZE - 1, 0); + SDL_Rect rect = { px, py, TILE_SIZE, TILE_SIZE }; + SDL_FillRect(composed_map.surface(), &rect, 0); } else { draw_map_tile(base, px, py, false); } @@ -601,9 +605,8 @@ private: for (int frame = 1; frame <= frames && !terminate; frame++) { int wx = step_position(window_x, view_step_x, frame, frames); int wy = step_position(window_y, view_step_y, frame, frames); - ags->copy_screen(SCREEN_MENU, SCREEN_FRONT, wx, wy, - wx + VIEW_COLS * TILE_SIZE - 1, - wy + VIEW_ROWS * TILE_SIZE - 1, VIEW_X, VIEW_Y); + SDL_Rect window = { wx, wy, VIEW_COLS * TILE_SIZE, VIEW_ROWS * TILE_SIZE }; + ags->blit_cg(SCREEN_FRONT, composed_map, &window, VIEW_X, VIEW_Y); if (map_sprite_frame != SPRITE_HIDDEN) { int sx = step_position(sprite_x, sprite_step_x, frame, frames); int sy = step_position(sprite_y, sprite_step_y, frame, frames); @@ -632,7 +635,7 @@ private: return; } int index = tile % TILES_PER_BANK; - blit_sheet(SCREEN_MENU, map_tile_cg[bank], + blit_sheet(composed_map, map_tile_cg[bank], (index % SHEET_COLS) * TILE_SIZE, (index / SHEET_COLS) * TILE_SIZE, TILE_SIZE, TILE_SIZE, px, py, transparent); @@ -654,17 +657,30 @@ private: right - left, bottom - top, left, top, true); } - void blit_sheet(ScreenId dest, CG& cg, int sheet_x, int sheet_y, - int width, int height, int dx, int dy, bool transparent) { - SDL_Rect src = { sheet_x, sheet_y, width, height }; - if (src.x + width > cg.width() || src.y + height > cg.height()) { + // Returns the rect of a sheet cell, and sets the color key the blit needs. + // Returns nullopt if the cell is outside the sheet. + std::optional sheet_cell(CG& cg, int sheet_x, int sheet_y, + int width, int height, bool transparent) { + if (sheet_x + width > cg.width() || sheet_y + height > cg.height()) { WARNING("map resource error: (%d,%d)+%dx%d outside CG %dx%d", sheet_x, sheet_y, width, height, cg.width(), cg.height()); - return; + return std::nullopt; } SDL_SetColorKey(cg.surface(), transparent ? SDL_TRUE : SDL_FALSE, TRANSPARENT_COLOR); - ags->blit_cg(dest, cg, &src, dx, dy); + return SDL_Rect{ sheet_x, sheet_y, width, height }; + } + + void blit_sheet(ScreenId dest, CG& cg, int sheet_x, int sheet_y, + int width, int height, int dx, int dy, bool transparent) { + if (auto src = sheet_cell(cg, sheet_x, sheet_y, width, height, transparent)) + ags->blit_cg(dest, cg, &*src, dx, dy); + } + + void blit_sheet(CG& dest, CG& cg, int sheet_x, int sheet_y, + int width, int height, int dx, int dy, bool transparent) { + if (auto src = sheet_cell(cg, sheet_x, sheet_y, width, height, transparent)) + ags->blit_cg(dest, cg, &*src, dx, dy); } // --- overview map ----------------------------------------------------- diff --git a/src/sys/nact_sys3.cpp b/src/sys/nact_sys3.cpp index b620cd1..98e46d2 100644 --- a/src/sys/nact_sys3.cpp +++ b/src/sys/nact_sys3.cpp @@ -814,10 +814,12 @@ void NACT_Sys3::exec_y(int cmd, int param) ags->scroll = param - 400; break; case 61: - if(param) { - ags->set_pixel(static_cast(D03), D01, D02, (uint8)RND); - } else { - RND = ags->get_pixel(static_cast(D03), D01, D02); + { + ScreenId screen = D03 ? SCREEN_BACK : SCREEN_FRONT; + if (param) + ags->set_pixel(screen, D01, D02, (uint8)RND); + else + RND = ags->get_pixel(screen, D01, D02); } break; case 70: