X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsystem.c;h=da3797358cb263e72ba21da1ac2205024c9d1988;hb=3c53030b9e20c59004046274e94eff2ee90d0ab5;hp=e67cbaeb80c1701f879022671243aaf716f64115;hpb=76c6cf34f934b80bcd42ed1f0940c6c56ac1c209;p=rocksndiamonds.git diff --git a/src/libgame/system.c b/src/libgame/system.c index e67cbaeb..da379735 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -46,6 +46,8 @@ LevelDirTree *leveldir_first = NULL; LevelDirTree *leveldir_current = NULL; int level_nr; +struct LevelStats level_stats[MAX_LEVELS]; + Display *display = NULL; Visual *visual = NULL; int screen = 0; @@ -127,9 +129,13 @@ void InitPlatformDependentStuff(void) updateUserGameDataDir(); #endif +#if 1 + openErrorFile(); +#else #if !defined(PLATFORM_UNIX) || defined(PLATFORM_MACOSX) openErrorFile(); #endif +#endif #if defined(TARGET_SDL) if (SDL_Init(SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE) < 0) @@ -211,6 +217,15 @@ void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height) gfx.scrollbuffer_height = scrollbuffer_height; } +void InitGfxClipRegion(boolean enabled, int x, int y, int width, int height) +{ + gfx.clipping_enabled = enabled; + gfx.clip_x = x; + gfx.clip_y = y; + gfx.clip_width = width; + gfx.clip_height = height; +} + void InitGfxDrawBusyAnimFunction(void (*draw_busy_anim_function)(void)) { gfx.draw_busy_anim_function = draw_busy_anim_function; @@ -235,6 +250,8 @@ void SetDrawBackgroundMask(int draw_background_mask) gfx.draw_background_mask = draw_background_mask; } +#if 0 + static void DrawBitmapFromTile(Bitmap *bitmap, Bitmap *tile, int dest_x, int dest_y, int width, int height) { @@ -291,6 +308,39 @@ void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask) } } +#else + +void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask) +{ + if (background_bitmap_tile != NULL) + gfx.background_bitmap_mask |= mask; + else + gfx.background_bitmap_mask &= ~mask; + +#if 0 + if (gfx.background_bitmap == NULL) + gfx.background_bitmap = CreateBitmap(video.width, video.height, + DEFAULT_DEPTH); +#endif + + if (background_bitmap_tile == NULL) /* empty background requested */ + return; + + if (mask == REDRAW_ALL) + BlitBitmapTiled(background_bitmap_tile, gfx.background_bitmap, 0, 0, 0, 0, + 0, 0, video.width, video.height); + else if (mask == REDRAW_FIELD) + BlitBitmapTiled(background_bitmap_tile, gfx.background_bitmap, 0, 0, 0, 0, + gfx.real_sx, gfx.real_sy, gfx.full_sxsize, gfx.full_sysize); + else if (mask == REDRAW_DOOR_1) + { + BlitBitmapTiled(background_bitmap_tile, gfx.background_bitmap, 0, 0, 0, 0, + gfx.dx, gfx.dy, gfx.dxsize, gfx.dysize); + } +} + +#endif + void SetWindowBackgroundBitmap(Bitmap *background_bitmap_tile) { /* remove every mask before setting mask for window */ @@ -512,9 +562,61 @@ 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) +static boolean InClippedRectangle(Bitmap *bitmap, int *x, int *y, + int *width, int *height, boolean is_dest) { +#if 1 + int clip_x, clip_y, clip_width, clip_height; + + if (gfx.clipping_enabled && is_dest) /* only clip destination bitmap */ + { + clip_x = MIN(MAX(0, gfx.clip_x), bitmap->width); + clip_y = MIN(MAX(0, gfx.clip_y), bitmap->height); + clip_width = MIN(MAX(0, gfx.clip_width), bitmap->width - clip_x); + clip_height = MIN(MAX(0, gfx.clip_height), bitmap->height - clip_y); + } + else + { + clip_x = 0; + clip_y = 0; + clip_width = bitmap->width; + clip_height = bitmap->height; + } + + /* skip if rectangle completely outside bitmap */ + + if (*x + *width <= clip_x || + *y + *height <= clip_y || + *x >= clip_x + clip_width || + *y >= clip_y + clip_height) + return FALSE; + + /* clip if rectangle overlaps bitmap */ + + if (*x < clip_x) + { + *width -= clip_x - *x; + *x = clip_x; + } + else if (*x + *width > clip_x + clip_width) + { + *width = clip_x + clip_width - *x; + } + + if (*y < clip_y) + { + *height -= clip_y - *y; + *y = clip_y; + } + else if (*y + *height > clip_y + clip_height) + { + *height = clip_y + clip_height - *y; + } + + return TRUE; + +#else + /* skip if rectangle completely outside bitmap */ if (*x + *width <= 0 || @@ -546,6 +648,7 @@ static boolean ValidClippedRectangle(Bitmap *bitmap, int *x, int *y, } return TRUE; +#endif } void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, @@ -559,8 +662,8 @@ 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)) + if (!InClippedRectangle(src_bitmap, &src_x, &src_y, &width, &height, FALSE) || + !InClippedRectangle(dst_bitmap, &dst_x, &dst_y, &width, &height, TRUE)) return; /* source x/y might need adjustment if destination x/y was clipped top/left */ @@ -639,17 +742,50 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, #endif #endif +#if 0 + if (dst_x < gfx.sx + gfx.sxsize) + printf("::: %d: BlitBitmap(%d, %d, %d, %d)\n", + FrameCounter, dst_x, dst_y, width, height); +#endif + sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, dst_x, dst_y, BLIT_OPAQUE); } +void BlitBitmapTiled(Bitmap *src_bitmap, Bitmap *dst_bitmap, + int src_x, int src_y, int src_width, int src_height, + int dst_x, int dst_y, int dst_width, int dst_height) +{ + int src_xsize = (src_width == 0 ? src_bitmap->width : src_width); + int src_ysize = (src_height == 0 ? src_bitmap->height : src_height); + int dst_xsize = dst_width; + int dst_ysize = dst_height; + int src_xsteps = (dst_xsize + src_xsize - 1) / src_xsize; + int src_ysteps = (dst_ysize + src_ysize - 1) / src_ysize; + int x, y; + + for (y = 0; y < src_ysteps; y++) + { + for (x = 0; x < src_xsteps; x++) + { + int draw_x = dst_x + x * src_xsize; + int draw_y = dst_y + y * src_ysize; + int draw_xsize = MIN(src_xsize, dst_xsize - x * src_xsize); + int draw_ysize = MIN(src_ysize, dst_ysize - y * src_ysize); + + BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, draw_xsize, draw_ysize, + draw_x, draw_y); + } + } +} + 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)) + /* (use destination bitmap "backbuffer" -- "bitmap_cross" may be undefined) */ + if (!InClippedRectangle(backbuffer, &x, &y, &width, &height, TRUE)) return; #endif @@ -669,7 +805,7 @@ void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height, return; #if 1 - if (!ValidClippedRectangle(bitmap, &x, &y, &width, &height)) + if (!InClippedRectangle(bitmap, &x, &y, &width, &height, TRUE)) return; #else /* skip if rectangle starts outside bitmap */ @@ -1048,7 +1184,9 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, int width_4, height_4; int width_8, height_8; int width_16, height_16; +#if 0 int width_32, height_32; +#endif int new_width, new_height; /* calculate new image dimensions for normal sized image */ @@ -1079,8 +1217,10 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, height_8 = height_1 / 8; width_16 = width_1 / 16; height_16 = height_1 / 16; +#if 0 width_32 = width_1 / 32; height_32 = height_1 / 32; +#endif UPDATE_BUSY_STATE();