mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-10-08 06:48:05 +03:00
AGS: Move scroll handling to update_screen()
This fixes an out-of-bounds access bug when scroll > 400.
This commit is contained in:
+13
-8
@@ -48,7 +48,6 @@ AGS::AGS(const Config& config, const GameId& game_id) : game_id(game_id), dirty(
|
|||||||
window_width = screen_width = 640;
|
window_width = screen_width = 640;
|
||||||
window_height = screen_height = 400;
|
window_height = screen_height = 400;
|
||||||
}
|
}
|
||||||
scroll = screen_height;
|
|
||||||
|
|
||||||
SDL_SetWindowSize(g_window, window_width, window_height);
|
SDL_SetWindowSize(g_window, window_width, window_height);
|
||||||
SDL_RenderSetLogicalSize(g_renderer, window_width, window_height);
|
SDL_RenderSetLogicalSize(g_renderer, window_width, window_height);
|
||||||
@@ -425,12 +424,7 @@ void AGS::draw_screen(int sx, int sy, int width, int height)
|
|||||||
|
|
||||||
void AGS::invalidate_screen(int sx, int sy, int width, int height)
|
void AGS::invalidate_screen(int sx, int sy, int width, int height)
|
||||||
{
|
{
|
||||||
int top = screen_height == 400 ? sy + (scroll - 400) : sy;
|
uint32* pixels = surface_line(hBmpDest, sy) + sx;
|
||||||
if (top < 0) {
|
|
||||||
height += top;
|
|
||||||
top = 0;
|
|
||||||
}
|
|
||||||
uint32* pixels = surface_line(hBmpDest, top) + sx;
|
|
||||||
if (sy + height > screen_height)
|
if (sy + height > screen_height)
|
||||||
height = screen_height - sy;
|
height = screen_height - sy;
|
||||||
if (sx + width > hBmpDest->w)
|
if (sx + width > hBmpDest->w)
|
||||||
@@ -445,7 +439,18 @@ void AGS::update_screen()
|
|||||||
if (!dirty)
|
if (!dirty)
|
||||||
return;
|
return;
|
||||||
SDL_RenderClear(g_renderer);
|
SDL_RenderClear(g_renderer);
|
||||||
SDL_RenderCopy(g_renderer, sdlTexture, NULL, NULL);
|
|
||||||
|
SDL_Rect src = {0, 0, screen_width, screen_height};
|
||||||
|
SDL_Rect dest = {0, 0, screen_width, screen_height};
|
||||||
|
if (scroll > 0) {
|
||||||
|
src.y = scroll;
|
||||||
|
src.h = dest.h = screen_height - scroll;
|
||||||
|
} else if (scroll < 0) {
|
||||||
|
dest.y = -scroll;
|
||||||
|
src.h = dest.h = screen_height + scroll;
|
||||||
|
}
|
||||||
|
SDL_RenderCopy(g_renderer, sdlTexture, &src, &dest);
|
||||||
|
|
||||||
if (fade_level) {
|
if (fade_level) {
|
||||||
SDL_SetRenderDrawBlendMode(g_renderer, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(g_renderer, SDL_BLENDMODE_BLEND);
|
||||||
SDL_SetRenderDrawColor(g_renderer, fade_color, fade_color, fade_color, fade_level);
|
SDL_SetRenderDrawColor(g_renderer, fade_color, fade_color, fade_color, fade_level);
|
||||||
|
|||||||
+1
-1
@@ -149,7 +149,7 @@ public:
|
|||||||
int src_screen;
|
int src_screen;
|
||||||
int dest_screen;
|
int dest_screen;
|
||||||
|
|
||||||
int scroll;
|
int scroll = 0;
|
||||||
int window_width, window_height;
|
int window_width, window_height;
|
||||||
int screen_width, screen_height;
|
int screen_width, screen_height;
|
||||||
|
|
||||||
|
|||||||
@@ -863,7 +863,7 @@ void NACT_Sys3::cmd_y()
|
|||||||
ags->extract_cg = (param & 1) ? true : false;
|
ags->extract_cg = (param & 1) ? true : false;
|
||||||
break;
|
break;
|
||||||
case 60:
|
case 60:
|
||||||
ags->scroll = param;
|
ags->scroll = param - 400;
|
||||||
ags->flush_screen(false);
|
ags->flush_screen(false);
|
||||||
break;
|
break;
|
||||||
case 61:
|
case 61:
|
||||||
|
|||||||
Reference in New Issue
Block a user