AGS: Defer texture update until update_screen()

This commit is contained in:
kichikuou
2025-02-22 15:24:27 +09:00
parent 71bc53e9b1
commit 446d34132a
7 changed files with 17 additions and 54 deletions
+11 -24
View File
@@ -36,7 +36,7 @@ SDL_Texture* create_scanline_texture(SDL_Renderer* renderer, int width, int heig
} // namespace
AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id), dirty(false)
AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id)
{
// 画面サイズ
if (game_id.is(GameId::GAKUEN)) {
@@ -357,6 +357,7 @@ void AGS::set_palette(int index, uint8_t r, uint8_t g, uint8_t b)
}
SDL_SetPaletteColors(screen_palette, &color, index, 1);
SDL_SetPaletteColors(program_palette, &color, index, 1);
dirty_rect = {0, 0, screen_width, screen_height};
}
std::vector<uint32_t> AGS::get_screen_palette() const
@@ -380,7 +381,6 @@ void AGS::fade_out(int duration_ms, bool white)
g_nact->sys_sleep(16);
int t = SDL_GetTicks() - dwStart;
fade_level = t >= duration_ms ? 255 : t * 255 / duration_ms;
dirty = true;
}
update_screen();
}
@@ -395,37 +395,29 @@ void AGS::fade_in(int duration_ms)
g_nact->sys_sleep(16);
int t = SDL_GetTicks() - dwStart;
fade_level = t >= duration_ms ? 0 : (duration_ms - t) * 255 / duration_ms;
dirty = true;
}
update_screen();
}
void AGS::flush_screen(bool update)
{
if (update)
draw_screen(0, 0, screen_width, screen_height);
else
dirty = true;
}
void AGS::draw_screen(int sx, int sy, int width, int height)
{
SDL_Rect rect = {sx, sy, width, height};
SDL_Rect screen_rect = {0, 0, screen_width, screen_height};
SDL_IntersectRect(&rect, &screen_rect, &rect);
SDL_Surface *sf;
SDL_LockTextureToSurface(sdlTexture, &rect, &sf);
SDL_BlitSurface(hBmpScreen[0], &rect, sf, NULL);
SDL_UnlockTexture(sdlTexture);
dirty = true;
SDL_UnionRect(&dirty_rect, &rect, &dirty_rect);
}
void AGS::update_screen()
{
if (!dirty)
return;
SDL_RenderClear(g_renderer);
if (!SDL_RectEmpty(&dirty_rect)) {
SDL_Surface *sf;
SDL_LockTextureToSurface(sdlTexture, &dirty_rect, &sf);
SDL_BlitSurface(hBmpScreen[0], &dirty_rect, sf, NULL);
SDL_UnlockTexture(sdlTexture);
dirty_rect = {};
}
SDL_RenderClear(g_renderer);
SDL_Rect src = {0, 0, screen_width, screen_height};
SDL_Rect dest = {0, 0, screen_width, screen_height};
if (scroll > 0) {
@@ -447,20 +439,15 @@ void AGS::update_screen()
if (scanline_texture)
SDL_RenderCopy(g_renderer, scanline_texture, NULL, NULL);
SDL_RenderPresent(g_renderer);
dirty = false;
}
void AGS::set_scanline_mode(bool enable)
{
if (enable && !scanline_texture) {
scanline_texture = create_scanline_texture(g_renderer, screen_width, screen_height);
dirty = true;
update_screen();
} else if (!enable && scanline_texture) {
SDL_DestroyTexture(scanline_texture);
scanline_texture = NULL;
dirty = true;
update_screen();
}
}
+1 -3
View File
@@ -84,8 +84,6 @@ public:
void update_screen();
void flush_screen(bool update);
void load_cg(int page, int transparent);
void set_cg_file(const char *file_name);
@@ -141,7 +139,7 @@ public:
bool save_screenshot(const char* path);
int calculate_menu_max(int window);
bool dirty;
SDL_Rect dirty_rect = {};
// 画面選択
int src_screen;
-9
View File
@@ -133,15 +133,6 @@ void NACT::execute()
// 1コマンド実行
uint8 cmd = sco.fetch_command();
if(set_palette && cmd != 'P') {
// パレット設定が終わった
ags->flush_screen(true);
set_palette = false;
#ifdef ENABLE_DEBUGGER
if (g_debugger)
g_debugger->on_palette_change();
#endif
}
if(verb_obj && cmd != '[' && cmd != ':') {
// 動詞-目的語メニューの表示
sco.ungetd();
-1
View File
@@ -132,7 +132,6 @@ protected:
std::string caption_obj[MAX_OBJ];
bool verb_obj = false; // 動詞-形容詞型メニューの定義中
bool set_palette = false;
// 下位関数
bool is_message(uint8_t c) { return c == ' ' || c & 0x80; }
-13
View File
@@ -36,15 +36,6 @@ void NACT::handle_event(SDL_Event e)
quit(0);
break;
case SDL_WINDOWEVENT:
switch (e.window.event) {
case SDL_WINDOWEVENT_EXPOSED:
case SDL_WINDOWEVENT_SIZE_CHANGED:
ags->flush_screen(false);
break;
}
break;
case SDL_MOUSEMOTION:
mousex = e.motion.x * ags->screen_width / ags->window_width;
mousey = e.motion.y * ags->screen_height / ags->window_height;
@@ -76,10 +67,6 @@ void NACT::handle_event(SDL_Event e)
}
break;
case SDL_APP_DIDENTERFOREGROUND:
ags->flush_screen(false);
break;
default:
#ifdef ENABLE_DEBUGGER
if (e.type == sdl_custom_event_type) {
+5 -2
View File
@@ -14,6 +14,7 @@
#include "fileio.h"
#include "encoding.h"
#include "texthook.h"
#include "debugger/debugger.h"
#define D01 var[ 1]
#define D02 var[ 2]
@@ -606,7 +607,10 @@ void NACT_Sys3::cmd_p()
TRACE("P %d,%d,%d,%d:", index, r, g, b);
ags->set_palette(index, r, g, b);
set_palette = true;
#ifdef ENABLE_DEBUGGER
if (g_debugger)
g_debugger->on_palette_change();
#endif
}
void NACT_Sys3::cmd_q()
@@ -864,7 +868,6 @@ void NACT_Sys3::cmd_y()
break;
case 60:
ags->scroll = param - 400;
ags->flush_screen(false);
break;
case 61:
if(param) {
-2
View File
@@ -193,11 +193,9 @@ bool NACT::handle_platform_event(const SDL_Event& e)
break;
case ID_SCREEN_WINDOW:
SDL_SetWindowFullscreen(g_window, 0);
ags->flush_screen(false);
break;
case ID_SCREEN_FULL:
SDL_SetWindowFullscreen(g_window, SDL_WINDOW_FULLSCREEN_DESKTOP);
ags->flush_screen(false);
break;
case ID_SCANLINE:
ags->set_scanline_mode(!ags->get_scanline_mode());