From 41def9c1d8c6939b8754fdab43579272e49d4da4 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 17 Apr 2010 10:51:38 +0200 Subject: [PATCH] rnd-20100417-1-src --- src/conf_gfx.c | 16 ++++++++++-- src/conf_var.c | 48 ++++++++++++++++++++++++++++++++++++ src/conftime.h | 2 +- src/files.c | 37 ++++++++++++++++++--------- src/game_sp/DDScrollBuffer.c | 32 +++++++++++++++++++++--- src/game_sp/DDScrollBuffer.h | 4 +++ src/game_sp/DDSpriteBuffer.c | 2 +- src/game_sp/MainForm.c | 32 +++++++++++++++++++++++- src/game_sp/MainGameLoop.c | 14 ++++++++--- src/game_sp/export.h | 2 ++ src/game_sp/init.c | 33 ++++++++++++++++++++++--- src/game_sp/main_sp.h | 26 +++++++++++++------ src/init.c | 2 ++ src/libgame/system.c | 45 +++++++++++++++++++++++++++++++++ src/libgame/system.h | 7 ++++++ src/main.c | 6 +++++ src/main.h | 12 +++++---- src/tools.c | 44 ++++++++++++++++++++++----------- 18 files changed, 311 insertions(+), 53 deletions(-) diff --git a/src/conf_gfx.c b/src/conf_gfx.c index b5156490..f8a5ae3f 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -6408,14 +6408,26 @@ struct ConfigInfo image_config[] = { "viewport.window.width", "672" }, { "viewport.window.height", "560" }, - { "viewport.playfield.width", "17" }, - { "viewport.playfield.height", "17" }, + { "viewport.playfield.x", "6" }, + { "viewport.playfield.y", "6" }, + { "viewport.playfield.width", "548" }, + { "viewport.playfield.height", "548" }, + { "viewport.playfield.border_size", "2" }, + { "viewport.playfield.MAIN.x", ARG_DEFAULT }, + { "viewport.playfield.MAIN.y", ARG_DEFAULT }, { "viewport.playfield.MAIN.width", ARG_DEFAULT }, { "viewport.playfield.MAIN.height", ARG_DEFAULT }, + { "viewport.playfield.MAIN.border_size", ARG_DEFAULT }, + { "viewport.playfield.PLAYING.x", ARG_DEFAULT }, + { "viewport.playfield.PLAYING.y", ARG_DEFAULT }, { "viewport.playfield.PLAYING.width", ARG_DEFAULT }, { "viewport.playfield.PLAYING.height", ARG_DEFAULT }, + { "viewport.playfield.PLAYING.border_size", ARG_DEFAULT }, + { "viewport.playfield.EDITOR.x", ARG_DEFAULT }, + { "viewport.playfield.EDITOR.y", ARG_DEFAULT }, { "viewport.playfield.EDITOR.width", ARG_DEFAULT }, { "viewport.playfield.EDITOR.height", ARG_DEFAULT }, + { "viewport.playfield.EDITOR.border_size", ARG_DEFAULT }, { "viewport.door_1.x", "566" }, { "viewport.door_1.y", "60" }, { "viewport.door_1.MAIN.x", ARG_DEFAULT }, diff --git a/src/conf_var.c b/src/conf_var.c index 4593e424..e12f0015 100644 --- a/src/conf_var.c +++ b/src/conf_var.c @@ -5100,6 +5100,14 @@ struct TokenIntPtrInfo image_config_vars[] = "viewport.window.height", &viewport.window.height }, + { + "viewport.playfield.x", + &viewport.playfield[GFX_SPECIAL_ARG_DEFAULT].x + }, + { + "viewport.playfield.y", + &viewport.playfield[GFX_SPECIAL_ARG_DEFAULT].y + }, { "viewport.playfield.width", &viewport.playfield[GFX_SPECIAL_ARG_DEFAULT].width @@ -5108,6 +5116,18 @@ struct TokenIntPtrInfo image_config_vars[] = "viewport.playfield.height", &viewport.playfield[GFX_SPECIAL_ARG_DEFAULT].height }, + { + "viewport.playfield.border_size", + &viewport.playfield[GFX_SPECIAL_ARG_DEFAULT].border_size + }, + { + "viewport.playfield.MAIN.x", + &viewport.playfield[GFX_SPECIAL_ARG_MAIN].x + }, + { + "viewport.playfield.MAIN.y", + &viewport.playfield[GFX_SPECIAL_ARG_MAIN].y + }, { "viewport.playfield.MAIN.width", &viewport.playfield[GFX_SPECIAL_ARG_MAIN].width @@ -5116,6 +5136,18 @@ struct TokenIntPtrInfo image_config_vars[] = "viewport.playfield.MAIN.height", &viewport.playfield[GFX_SPECIAL_ARG_MAIN].height }, + { + "viewport.playfield.MAIN.border_size", + &viewport.playfield[GFX_SPECIAL_ARG_MAIN].border_size + }, + { + "viewport.playfield.PLAYING.x", + &viewport.playfield[GFX_SPECIAL_ARG_PLAYING].x + }, + { + "viewport.playfield.PLAYING.y", + &viewport.playfield[GFX_SPECIAL_ARG_PLAYING].y + }, { "viewport.playfield.PLAYING.width", &viewport.playfield[GFX_SPECIAL_ARG_PLAYING].width @@ -5124,6 +5156,18 @@ struct TokenIntPtrInfo image_config_vars[] = "viewport.playfield.PLAYING.height", &viewport.playfield[GFX_SPECIAL_ARG_PLAYING].height }, + { + "viewport.playfield.PLAYING.border_size", + &viewport.playfield[GFX_SPECIAL_ARG_PLAYING].border_size + }, + { + "viewport.playfield.EDITOR.x", + &viewport.playfield[GFX_SPECIAL_ARG_EDITOR].x + }, + { + "viewport.playfield.EDITOR.y", + &viewport.playfield[GFX_SPECIAL_ARG_EDITOR].y + }, { "viewport.playfield.EDITOR.width", &viewport.playfield[GFX_SPECIAL_ARG_EDITOR].width @@ -5132,6 +5176,10 @@ struct TokenIntPtrInfo image_config_vars[] = "viewport.playfield.EDITOR.height", &viewport.playfield[GFX_SPECIAL_ARG_EDITOR].height }, + { + "viewport.playfield.EDITOR.border_size", + &viewport.playfield[GFX_SPECIAL_ARG_EDITOR].border_size + }, { "viewport.door_1.x", &viewport.door_1[GFX_SPECIAL_ARG_DEFAULT].x diff --git a/src/conftime.h b/src/conftime.h index d918a3cb..aa3503a0 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2010-04-16 11:49" +#define COMPILE_DATE_STRING "2010-04-17 10:50" diff --git a/src/files.c b/src/files.c index 9f92ad68..a1017dd2 100644 --- a/src/files.c +++ b/src/files.c @@ -9957,31 +9957,44 @@ static void LoadMenuDesignSettingsFromFilename(char *filename) /* (eg, init "viewport.door_1.MAIN.xyz" from "viewport.door_1.xyz") */ for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++) { - char *token_1 = "viewport.playfield.width"; - char *token_2 = "viewport.playfield.height"; - char *token_3 = "viewport.door_1.x"; - char *token_4 = "viewport.door_1.y"; - char *token_5 = "viewport.door_2.x"; - char *token_6 = "viewport.door_2.y"; + char *token_1 = "viewport.playfield.x"; + char *token_2 = "viewport.playfield.y"; + char *token_3 = "viewport.playfield.width"; + char *token_4 = "viewport.playfield.height"; + char *token_5 = "viewport.playfield.border_size"; + char *token_6 = "viewport.door_1.x"; + char *token_7 = "viewport.door_1.y"; + char *token_8 = "viewport.door_2.x"; + char *token_9 = "viewport.door_2.y"; char *value_1 = getHashEntry(setup_file_hash, token_1); char *value_2 = getHashEntry(setup_file_hash, token_2); char *value_3 = getHashEntry(setup_file_hash, token_3); char *value_4 = getHashEntry(setup_file_hash, token_4); char *value_5 = getHashEntry(setup_file_hash, token_5); char *value_6 = getHashEntry(setup_file_hash, token_6); + char *value_7 = getHashEntry(setup_file_hash, token_7); + char *value_8 = getHashEntry(setup_file_hash, token_8); + char *value_9 = getHashEntry(setup_file_hash, token_9); if (value_1 != NULL) - viewport.playfield[i].width = get_token_parameter_value(token_1,value_1); + viewport.playfield[i].x = get_token_parameter_value(token_1, value_1); if (value_2 != NULL) - viewport.playfield[i].height = get_token_parameter_value(token_2,value_2); + viewport.playfield[i].y = get_token_parameter_value(token_2, value_2); if (value_3 != NULL) - viewport.door_1[i].x = get_token_parameter_value(token_3, value_3); + viewport.playfield[i].width = get_token_parameter_value(token_3, value_3); if (value_4 != NULL) - viewport.door_1[i].y = get_token_parameter_value(token_4, value_4); + viewport.playfield[i].height = get_token_parameter_value(token_4,value_4); if (value_5 != NULL) - viewport.door_2[i].x = get_token_parameter_value(token_5, value_5); + viewport.playfield[i].border_size = get_token_parameter_value(token_5, + value_5); if (value_6 != NULL) - viewport.door_2[i].y = get_token_parameter_value(token_6, value_6); + viewport.door_1[i].x = get_token_parameter_value(token_6, value_6); + if (value_7 != NULL) + viewport.door_1[i].y = get_token_parameter_value(token_7, value_7); + if (value_8 != NULL) + viewport.door_2[i].x = get_token_parameter_value(token_8, value_8); + if (value_9 != NULL) + viewport.door_2[i].y = get_token_parameter_value(token_9, value_9); } /* special case: initialize with default values that may be overwritten */ diff --git a/src/game_sp/DDScrollBuffer.c b/src/game_sp/DDScrollBuffer.c index 48710ace..70c4c5a6 100644 --- a/src/game_sp/DDScrollBuffer.c +++ b/src/game_sp/DDScrollBuffer.c @@ -10,8 +10,13 @@ long mScrollX, mScrollY; long mScrollX_last, mScrollY_last; +#if 1 +long ScreenBuffer[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; +boolean redraw[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; +#else long ScreenBuffer[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; +#endif void RestorePlayfield() @@ -45,7 +50,7 @@ static void ScrollPlayfield(int dx, int dy) int y2 = mScrollY_last / TILEY + (SCR_FIELDY - 1) + 2; int x, y; - BlitBitmap(screenBitmap, screenBitmap, + BlitBitmap(bitmap_db_field_sp, bitmap_db_field_sp, TILEX * (dx == -1), TILEY * (dy == -1), (MAX_BUF_XSIZE * TILEX) - TILEX * (dx != 0), @@ -217,6 +222,13 @@ void BlitScreenToBitmap_SP(Bitmap *target_bitmap) int py = 2 * TILEY + (mScrollY - mScrollY_last) % TILEY; int sx, sy, sxsize, sysize; +#if 1 + printf("::: %d, %d - %d, %d - %ld, %ld\n", + MurphyScreenXPos, MurphyScreenYPos, + ScreenScrollXPos, ScreenScrollYPos, + mScrollX, mScrollY); +#endif + int xsize = SXSIZE; int ysize = SYSIZE; int full_xsize = (FieldWidth - (menBorder ? 0 : 1)) * TILEX; @@ -227,13 +239,27 @@ void BlitScreenToBitmap_SP(Bitmap *target_bitmap) sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0); sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0); +#if 1 + if (0 && !menBorder) + { + if (mScrollX < ScrollMinX + TILEX / 2) + px += ScrollMinX + TILEX / 2 - mScrollX; + else if (mScrollX > ScrollMaxX - TILEX / 2) + px -= mScrollX - (ScrollMaxX - TILEX / 2); + if (mScrollY < ScrollMinY + TILEY / 2) + py += ScrollMinY + TILEY / 2 - mScrollY; + else if (mScrollY > ScrollMaxY - TILEY / 2) + py -= mScrollY - (ScrollMaxY - TILEY / 2); + } +#else if (!menBorder) { px += TILEX / 2; py += TILEY / 2; } +#endif - BlitBitmap(screenBitmap, target_bitmap, px, py, sxsize, sysize, sx, sy); + BlitBitmap(bitmap_db_field_sp, target_bitmap, px, py, sxsize, sysize, sx, sy); } void BackToFront_SP(void) @@ -261,7 +287,7 @@ void BackToFront_SP(void) int yy = (top + y) % MAX_BUF_YSIZE; if (redraw[xx][yy]) - BlitBitmap(screenBitmap, window, + BlitBitmap(bitmap_db_field_sp, window, xx * TILEX, yy * TILEY, TILEX, TILEY, SX + x * TILEX, SY + y * TILEY); } diff --git a/src/game_sp/DDScrollBuffer.h b/src/game_sp/DDScrollBuffer.h index 78c6e563..e34ef219 100644 --- a/src/game_sp/DDScrollBuffer.h +++ b/src/game_sp/DDScrollBuffer.h @@ -11,7 +11,11 @@ extern long mScrollX, mScrollY; extern long mScrollX_last, mScrollY_last; +#if 1 +extern boolean redraw[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; +#else extern boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; +#endif extern int TEST_flag; diff --git a/src/game_sp/DDSpriteBuffer.c b/src/game_sp/DDSpriteBuffer.c index 863aac39..4683d319 100644 --- a/src/game_sp/DDSpriteBuffer.c +++ b/src/game_sp/DDSpriteBuffer.c @@ -24,7 +24,7 @@ static void Blt(int pX, int pY, Bitmap *bitmap, int SpriteX, int SpriteY) if (pX < sx1 || pX > sx2 || pY < sy1 || pY > sy2) return; - BlitBitmap(bitmap, screenBitmap, SpriteX, SpriteY, + BlitBitmap(bitmap, bitmap_db_field_sp, SpriteX, SpriteY, TILEX, TILEY, sx, sy); } diff --git a/src/game_sp/MainForm.c b/src/game_sp/MainForm.c index d4c3545e..9f0b6cb5 100644 --- a/src/game_sp/MainForm.c +++ b/src/game_sp/MainForm.c @@ -31,8 +31,12 @@ void DisplayLevel() return; ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); - ClearRectangle(screenBitmap, 0, 0, +#if 1 + ClearRectangle(bitmap_db_field_sp, 0, 0, FXSIZE, FYSIZE); +#else + ClearRectangle(bitmap_db_field_sp, 0, 0, MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY); +#endif #if 1 SetDisplayRegion(); @@ -177,10 +181,36 @@ static void ReStretch() void SetScrollEdges() { +#if 1 + int border_offset = (menBorder ? 1 : 2); + + ScrollMinX = 0; + ScrollMinY = 0; + ScrollMaxX = (DisplayMaxX + border_offset) * BaseWidth - SXSIZE; + ScrollMaxY = (DisplayMaxY + border_offset) * BaseWidth - SYSIZE; + +#if 1 + if (!menBorder) + { + ScrollMinX += TILEX / 2; + ScrollMinY += TILEY / 2; + ScrollMaxX -= TILEX / 2; + ScrollMaxY -= TILEY / 2; + } +#endif + +#else ScrollMinX = (int)(DisplayMinX - 0.5) * BaseWidth; ScrollMinY = (int)(DisplayMinY - 0.5) * BaseWidth; ScrollMaxX = (int)(DisplayMaxX + 1.5) * BaseWidth - SXSIZE; ScrollMaxY = (int)(DisplayMaxY + 1.5) * BaseWidth - SYSIZE; +#endif + +#if 1 + printf("::: (%ld, %ld), (%ld, %ld) -> (%d, %d), (%d, %d)\n", + DisplayMinX, DisplayMinY, DisplayMaxX, DisplayMaxY, + ScrollMinX, ScrollMinY, ScrollMaxX, ScrollMaxY); +#endif } void DrawField(int X, int Y) diff --git a/src/game_sp/MainGameLoop.c b/src/game_sp/MainGameLoop.c index 145c0436..2a6d2551 100644 --- a/src/game_sp/MainGameLoop.c +++ b/src/game_sp/MainGameLoop.c @@ -122,11 +122,17 @@ void subCalculateScreenScrollPos() // printf("::: ExplosionShake [%d]\n", FrameCounter); } - { - ax = SXSIZE / 2; - ay = SYSIZE / 2; - } +#if 1 + ax = (SCR_FIELDX / 2) * TILESIZE; + ay = (SCR_FIELDY / 2) * TILESIZE; + + ScreenScrollXPos = MurphyScreenXPos - ax; + ScreenScrollYPos = MurphyScreenYPos - ay; +#else + ax = SXSIZE / 2; + ay = SYSIZE / 2; ScreenScrollXPos = (MurphyScreenXPos + TILEX / 2) - ax; ScreenScrollYPos = (MurphyScreenYPos + TILEY / 2) - ay; +#endif } diff --git a/src/game_sp/export.h b/src/game_sp/export.h index ca5912b6..b5c0d0bb 100644 --- a/src/game_sp/export.h +++ b/src/game_sp/export.h @@ -184,6 +184,8 @@ extern struct EngineSnapshotInfo_SP engine_snapshot_sp; extern void sp_open_all(); extern void sp_close_all(); +extern void InitGfxBuffers_SP(); + extern void InitGameEngine_SP(); extern void GameActions_SP(byte *, boolean); diff --git a/src/game_sp/init.c b/src/game_sp/init.c index 32a832c2..a8e67276 100644 --- a/src/game_sp/init.c +++ b/src/game_sp/init.c @@ -3,7 +3,7 @@ #include "global.h" -Bitmap *screenBitmap; +Bitmap *bitmap_db_field_sp; struct EngineSnapshotInfo_SP engine_snapshot_sp; @@ -11,14 +11,41 @@ void sp_open_all() { Form_Load(); - screenBitmap = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY, - DEFAULT_DEPTH); +#if 0 + printf("::: open 1: %d, %d [%08x]\n", FXSIZE, FYSIZE, bitmap_db_field_sp); + + /* + bitmap_db_field_sp = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH); + bitmap_db_field_sp = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY, + DEFAULT_DEPTH); + */ + + ReCreateBitmap(&bitmap_db_field_sp, FXSIZE, FYSIZE, DEFAULT_DEPTH); + + printf("::: open 2: %d, %d [%08x]\n", FXSIZE, FYSIZE, bitmap_db_field_sp); +#endif } void sp_close_all() { } +void InitGfxBuffers_SP() +{ +#if 1 + printf("::: init 1: %d, %d [%08x]\n", FXSIZE, FYSIZE, bitmap_db_field_sp); + + /* + ReCreateBitmap(&bitmap_db_field_sp, MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY, + DEFAULT_DEPTH); + */ + + ReCreateBitmap(&bitmap_db_field_sp, FXSIZE, FYSIZE, DEFAULT_DEPTH); + + printf("::: init 2: %d, %d [%08x]\n", FXSIZE, FYSIZE, bitmap_db_field_sp); +#endif +} + unsigned int InitEngineRandom_SP(long seed) { if (seed == NEW_RANDOMIZE) diff --git a/src/game_sp/main_sp.h b/src/game_sp/main_sp.h index ff3035a4..6e61508b 100644 --- a/src/game_sp/main_sp.h +++ b/src/game_sp/main_sp.h @@ -27,31 +27,45 @@ /* screen sizes and positions for SP engine */ -#define ORIG_TILEX 16 -#define ORIG_TILEY 16 +#define ORIG_TILESIZE 16 #define ZOOM_FACTOR 2 -#define TILEX (ORIG_TILEX * ZOOM_FACTOR) -#define TILEY (ORIG_TILEY * ZOOM_FACTOR) +#define TILESIZE (ORIG_TILESIZE * ZOOM_FACTOR) +#define TILEX TILESIZE +#define TILEY TILESIZE #define ORIG_SCR_MENUX 20 #define ORIG_SCR_MENUY 12 #define SCR_MENUX 17 #define SCR_MENUY 12 +#if 1 +extern int SCR_FIELDX, SCR_FIELDY; +#else #define SCR_FIELDX 17 #define SCR_FIELDY 17 +#endif #define MAX_BUF_XSIZE (2 + SCR_FIELDX + 2) #define MAX_BUF_YSIZE (2 + SCR_FIELDY + 2) /* often used screen positions */ +#if 1 +extern int SX, SY; +#else #define SX 8 #define SY 8 +#endif #define SXSIZE (SCR_FIELDX * TILEX) #define SYSIZE (SCR_FIELDY * TILEY) +#define FXSIZE (MAX_BUF_XSIZE * TILEX) +#define FYSIZE (MAX_BUF_YSIZE * TILEY) +#if 1 +extern int REAL_SX, REAL_SY; +#else #define REAL_SX (SX - 2) #define REAL_SY (SY - 2) +#endif #define FULL_SXSIZE (2 + SXSIZE + 2) #define FULL_SYSIZE (2 + SYSIZE + 2) @@ -66,9 +80,7 @@ extern struct LevelInfo_SP native_sp_level; -extern Bitmap *screenBitmap; - -extern Bitmap *sp_objects; +extern Bitmap *bitmap_db_field_sp; extern int GfxElementLast[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT]; extern int GfxGraphicLast[SP_MAX_PLAYFIELD_WIDTH][SP_MAX_PLAYFIELD_HEIGHT]; diff --git a/src/init.c b/src/init.c index 89b4bc6a..3d7b3065 100644 --- a/src/init.c +++ b/src/init.c @@ -5465,6 +5465,8 @@ void InitGfxBuffers() InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE); InitGfxWindowInfo(WIN_XSIZE, WIN_YSIZE); InitGfxScrollbufferInfo(FXSIZE, FYSIZE); + + InitGfxBuffers_SP(); } void InitGfx() diff --git a/src/libgame/system.c b/src/libgame/system.c index 8a5942da..bccb5fdd 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -512,6 +512,38 @@ boolean DrawingOnBackground(int x, int y) CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask)); } +static boolean ValidClippedRectangle(Bitmap *bitmap, int *x, int *y, + int *width, int *height) +{ + /* skip if rectangle completely outside bitmap */ + + if (*x + *width <= 0 || + *y + *height <= 0 || + *x >= bitmap->width || + *y >= bitmap->height) + return FALSE; + + /* clip if rectangle overlaps bitmap */ + + if (*x < 0) + { + *x = 0; + *width += *x; + } + else if (*x + *width > bitmap->width) + *width = bitmap->width - *x; + + if (*y < 0) + { + *y = 0; + *height += *y; + } + else if (*y + *height > bitmap->height) + *height = bitmap->height - *y; + + return TRUE; +} + void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, int src_x, int src_y, int width, int height, int dst_x, int dst_y) @@ -520,6 +552,10 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, return; #if 1 + if (!ValidClippedRectangle(src_bitmap, &src_x, &src_y, &width, &height) || + !ValidClippedRectangle(dst_bitmap, &dst_x, &dst_y, &width, &height)) + return; +#else /* skip if rectangle starts outside bitmap */ if (src_x >= src_bitmap->width || src_y >= src_bitmap->height || @@ -599,6 +635,12 @@ void FadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, int fade_mode, int fade_delay, int post_delay, void (*draw_border_function)(void)) { +#if 1 + /* (use bitmap "backbuffer" -- "bitmap_cross" may be undefined) */ + if (!ValidClippedRectangle(backbuffer, &x, &y, &width, &height)) + return; +#endif + #if defined(TARGET_SDL) SDLFadeRectangle(bitmap_cross, x, y, width, height, fade_mode, fade_delay, post_delay, draw_border_function); @@ -615,6 +657,9 @@ void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height, return; #if 1 + if (!ValidClippedRectangle(bitmap, &x, &y, &width, &height)) + return; +#else /* skip if rectangle starts outside bitmap */ if (x >= bitmap->width || y >= bitmap->height) diff --git a/src/libgame/system.h b/src/libgame/system.h index d35505b5..51017fec 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1108,6 +1108,13 @@ struct Rect int width, height; }; +struct RectWithBorder +{ + int x, y; + int width, height; + int border_size; +}; + struct MenuPosInfo { int x, y; diff --git a/src/main.c b/src/main.c index aab51a38..b9e35e2b 100644 --- a/src/main.c +++ b/src/main.c @@ -90,11 +90,17 @@ int scroll_x, scroll_y; int WIN_XSIZE = 672, WIN_YSIZE = 560; int SCR_FIELDX = 17, SCR_FIELDY = 17; +int SX = 8, SY = 8; +int REAL_SX = 6, REAL_SY = 6; int DX = 566, DY = 60; int VX = 566, VY = 400; int EX = 566, EY = 356; +#if 1 +int FX, FY; +#else int FX = SX, FY = SY; +#endif int ScrollStepSize; int ScreenMovDir = MV_NONE, ScreenMovPos = 0; int ScreenGfxPos = 0; diff --git a/src/main.h b/src/main.h index 4268c901..f71341b2 100644 --- a/src/main.h +++ b/src/main.h @@ -947,11 +947,11 @@ #define MAX_INITIAL_INVENTORY_SIZE 8 /* often used screen positions */ +#if 0 #define SX 8 #define SY 8 #define REAL_SX (SX - 2) #define REAL_SY (SY - 2) -#if 0 #define DX 566 #define DY 60 #define VX DX @@ -2259,10 +2259,10 @@ struct PreviewInfo struct ViewportInfo { - struct Rect window; - struct Rect playfield[NUM_SPECIAL_GFX_ARGS]; - struct Rect door_1[NUM_SPECIAL_GFX_ARGS]; - struct Rect door_2[NUM_SPECIAL_GFX_ARGS]; + struct RectWithBorder window; + struct RectWithBorder playfield[NUM_SPECIAL_GFX_ARGS]; + struct RectWithBorder door_1[NUM_SPECIAL_GFX_ARGS]; + struct RectWithBorder door_2[NUM_SPECIAL_GFX_ARGS]; }; struct HiScore @@ -2863,6 +2863,8 @@ extern int scroll_x, scroll_y; extern int WIN_XSIZE, WIN_YSIZE; extern int SCR_FIELDX, SCR_FIELDY; +extern int SX, SY; +extern int REAL_SX, REAL_SY; extern int DX, DY; extern int VX, VY; extern int EX, EY; diff --git a/src/tools.c b/src/tools.c index 2ec7c9ee..cb23bae6 100644 --- a/src/tools.c +++ b/src/tools.c @@ -8095,6 +8095,14 @@ void ChangeViewportPropertiesIfNeeded() int gfx_game_mode = (game_status == GAME_MODE_PLAYING || game_status == GAME_MODE_EDITOR ? game_status : GAME_MODE_MAIN); + struct RectWithBorder *vp_playfield = &viewport.playfield[gfx_game_mode]; + struct RectWithBorder *vp_door_1 = &viewport.door_1[gfx_game_mode]; + struct RectWithBorder *vp_door_2 = &viewport.door_2[gfx_game_mode]; + int border_size = vp_playfield->border_size; + int new_sx = vp_playfield->x + border_size; + int new_sy = vp_playfield->y + border_size; + int new_scr_fieldx = (vp_playfield->width - 2 * border_size) / TILESIZE; + int new_scr_fieldy = (vp_playfield->height - 2 * border_size) / TILESIZE; if (viewport.window.width != WIN_XSIZE || viewport.window.height != WIN_YSIZE) @@ -8113,20 +8121,28 @@ void ChangeViewportPropertiesIfNeeded() #endif } - if (viewport.playfield[gfx_game_mode].width != SCR_FIELDX || - viewport.playfield[gfx_game_mode].height != SCR_FIELDY || - viewport.door_1[gfx_game_mode].x != *door_1_x || - viewport.door_1[gfx_game_mode].y != *door_1_y || - viewport.door_2[gfx_game_mode].x != *door_2_x || - viewport.door_2[gfx_game_mode].y != *door_2_y) - { - SCR_FIELDX = viewport.playfield[gfx_game_mode].width; - SCR_FIELDY = viewport.playfield[gfx_game_mode].height; - - *door_1_x = viewport.door_1[gfx_game_mode].x; - *door_1_y = viewport.door_1[gfx_game_mode].y; - *door_2_x = viewport.door_2[gfx_game_mode].x; - *door_2_y = viewport.door_2[gfx_game_mode].y; + if (new_scr_fieldx != SCR_FIELDX || + new_scr_fieldy != SCR_FIELDY || + new_sx != SX || + new_sy != SY || + vp_playfield->x != REAL_SX || + vp_playfield->y != REAL_SY || + vp_door_1->x != *door_1_x || + vp_door_1->y != *door_1_y || + vp_door_2->x != *door_2_x || + vp_door_2->y != *door_2_y) + { + SCR_FIELDX = new_scr_fieldx; + SCR_FIELDY = new_scr_fieldy; + SX = new_sx; + SY = new_sy; + REAL_SX = vp_playfield->x; + REAL_SY = vp_playfield->y; + + *door_1_x = vp_door_1->x; + *door_1_y = vp_door_1->y; + *door_2_x = vp_door_2->x; + *door_2_y = vp_door_2->y; InitGfxBuffers(); -- 2.34.1