X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fsystem.c;h=38ec0b5b2e5148a2dbf69dd2a8accc65b959b694;hp=9484cbd2e5b5840c5b8f10083f575676885d217b;hb=8ae535c1c76e1c33572afbcd4b2d3d9c3d7ba63e;hpb=76ae1ac5119938169d8201d94bd44fedaa4e298b diff --git a/src/libgame/system.c b/src/libgame/system.c index 9484cbd2..38ec0b5b 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -44,11 +44,6 @@ int level_nr; struct LevelStats level_stats[MAX_LEVELS]; -Display *display = NULL; -Visual *visual = NULL; -int screen = 0; -Colormap cmap = None; - DrawWindow *window = NULL; DrawBuffer *backbuffer = NULL; DrawBuffer *drawto = NULL; @@ -60,7 +55,6 @@ boolean keyrepeat_status = TRUE; #endif int redraw_mask = REDRAW_NONE; -int redraw_tiles = 0; int FrameCounter = 0; @@ -69,24 +63,24 @@ int FrameCounter = 0; /* init/close functions */ /* ========================================================================= */ -void InitProgramInfo(char *argv0, - char *userdata_subdir, char *userdata_subdir_unix, +void InitProgramInfo(char *argv0, char *config_filename, char *userdata_subdir, char *program_title, char *icon_title, - char *sdl_icon_filename, char *cookie_prefix, + char *icon_filename, char *cookie_prefix, int program_version) { program.command_basepath = getBasePath(argv0); program.command_basename = getBaseName(argv0); + program.config_filename = config_filename; + program.userdata_subdir = userdata_subdir; - program.userdata_subdir_unix = userdata_subdir_unix; program.userdata_path = getUserGameDataDir(); program.program_title = program_title; program.window_title = "(undefined)"; program.icon_title = icon_title; - program.sdl_icon_filename = sdl_icon_filename; + program.icon_filename = icon_filename; program.cookie_prefix = cookie_prefix; @@ -96,8 +90,10 @@ void InitProgramInfo(char *argv0, program.version_build = VERSION_BUILD(program_version); program.version_ident = program_version; - program.error_filename = getErrorFilename(ERROR_BASENAME); - program.error_file = stderr; + program.log_filename[LOG_OUT_ID] = getLogFilename(LOG_OUT_BASENAME); + program.log_filename[LOG_ERR_ID] = getLogFilename(LOG_ERR_BASENAME); + program.log_file[LOG_OUT_ID] = program.log_file_default[LOG_OUT_ID] = stdout; + program.log_file[LOG_ERR_ID] = program.log_file_default[LOG_ERR_ID] = stderr; } void SetWindowTitle() @@ -122,7 +118,7 @@ void InitExitFunction(void (*exit_function)(int)) program.exit_function = exit_function; /* set signal handlers to custom exit function */ - signal(SIGINT, exit_function); + // signal(SIGINT, exit_function); signal(SIGTERM, exit_function); /* set exit function to automatically cleanup SDL stuff after exit() */ @@ -134,11 +130,7 @@ void InitPlatformDependentStuff(void) // this is initialized in GetOptions(), but may already be used before options.verbose = TRUE; -#if defined(PLATFORM_MACOSX) - updateUserGameDataDir(); -#endif - - openErrorFile(); + OpenLogFiles(); #if defined(TARGET_SDL2) int sdl_init_flags = SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE; @@ -154,9 +146,7 @@ void InitPlatformDependentStuff(void) void ClosePlatformDependentStuff(void) { -#if defined(PLATFORM_WIN32) - closeErrorFile(); -#endif + CloseLogFiles(); } void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize, @@ -217,6 +207,9 @@ void InitGfxWindowInfo(int win_xsize, int win_ysize) gfx.background_bitmap_mask = REDRAW_NONE; ReCreateBitmap(&gfx.background_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH); +#if USE_FINAL_SCREEN_BITMAP + ReCreateBitmap(&gfx.final_screen_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH); +#endif } void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height) @@ -241,6 +234,16 @@ void InitGfxDrawBusyAnimFunction(void (*draw_busy_anim_function)(void)) gfx.draw_busy_anim_function = draw_busy_anim_function; } +void InitGfxDrawGlobalAnimFunction(void (*draw_global_anim_function)(int)) +{ + gfx.draw_global_anim_function = draw_global_anim_function; +} + +void InitGfxDrawGlobalBorderFunction(void (*draw_global_border_function)(int)) +{ + gfx.draw_global_border_function = draw_global_border_function; +} + void InitGfxCustomArtworkInfo() { gfx.override_level_graphics = FALSE; @@ -250,6 +253,11 @@ void InitGfxCustomArtworkInfo() gfx.draw_init_text = TRUE; } +void InitGfxOtherSettings() +{ + gfx.cursor_mode = CURSOR_DEFAULT; +} + void SetDrawDeactivationMask(int draw_deactivation_mask) { gfx.draw_deactivation_mask = draw_deactivation_mask; @@ -316,9 +324,12 @@ inline static int GetRealDepth(int depth) } inline static void sysFillRectangle(Bitmap *bitmap, int x, int y, - int width, int height, Pixel color) + int width, int height, Pixel color) { SDLFillRectangle(bitmap, x, y, width, height, color); + + if (bitmap == backbuffer) + SetRedrawMaskFromArea(x, y, width, height); } inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, @@ -327,6 +338,9 @@ inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, { SDLCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, dst_x, dst_y, mask_mode); + + if (dst_bitmap == backbuffer) + SetRedrawMaskFromArea(dst_x, dst_y, width, height); } void LimitScreenUpdates(boolean enable) @@ -359,6 +373,8 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen) SDLInitVideoBuffer(&backbuffer, &window, fullscreen); + video.initialized = TRUE; + drawto = backbuffer; } @@ -396,7 +412,7 @@ void FreeBitmap(Bitmap *bitmap) Bitmap *CreateBitmapStruct(void) { - return checked_calloc(sizeof(struct SDLSurfaceInfo)); + return checked_calloc(sizeof(Bitmap)); } Bitmap *CreateBitmap(int width, int height, int depth) @@ -433,6 +449,28 @@ void CloseWindow(DrawWindow *window) { } +void SetRedrawMaskFromArea(int x, int y, int width, int height) +{ + int x1 = x; + int y1 = y; + int x2 = x + width - 1; + int y2 = y + height - 1; + + if (width == 0 || height == 0) + return; + + if (IN_GFX_FIELD_FULL(x1, y1) && IN_GFX_FIELD_FULL(x2, y2)) + redraw_mask |= REDRAW_FIELD; + else if (IN_GFX_DOOR_1(x1, y1) && IN_GFX_DOOR_1(x2, y2)) + redraw_mask |= REDRAW_DOOR_1; + else if (IN_GFX_DOOR_2(x1, y1) && IN_GFX_DOOR_2(x2, y2)) + redraw_mask |= REDRAW_DOOR_2; + else if (IN_GFX_DOOR_3(x1, y1) && IN_GFX_DOOR_3(x2, y2)) + redraw_mask |= REDRAW_DOOR_3; + else + redraw_mask = REDRAW_ALL; +} + inline static boolean CheckDrawingArea(int x, int y, int width, int height, int draw_mask) { @@ -660,14 +698,6 @@ void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y, ClearRectangle(bitmap, x, y, width, height); } -void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap) -{ -} - -void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y) -{ -} - void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap, int src_x, int src_y, int width, int height, int dst_x, int dst_y) @@ -690,8 +720,6 @@ void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap, dst_x, dst_y); /* draw foreground */ - SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc, - dst_x - src_x, dst_y - src_y); BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, width, height, dst_x, dst_y); } @@ -700,6 +728,58 @@ void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap, dst_x, dst_y); } +void BlitTexture(Bitmap *bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y) +{ + if (bitmap == NULL) + return; + + SDLBlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y, + BLIT_OPAQUE); +} + +void BlitTextureMasked(Bitmap *bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y) +{ + if (bitmap == NULL) + return; + + SDLBlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y, + BLIT_MASKED); +} + +void BlitToScreen(Bitmap *bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y) +{ + if (bitmap == NULL) + return; + +#if USE_FINAL_SCREEN_BITMAP + BlitBitmap(bitmap, gfx.final_screen_bitmap, src_x, src_y, + width, height, dst_x, dst_y); +#else + BlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y); +#endif +} + +void BlitToScreenMasked(Bitmap *bitmap, + int src_x, int src_y, int width, int height, + int dst_x, int dst_y) +{ + if (bitmap == NULL) + return; + +#if USE_FINAL_SCREEN_BITMAP + BlitBitmapMasked(bitmap, gfx.final_screen_bitmap, src_x, src_y, + width, height, dst_x, dst_y); +#else + BlitTextureMasked(bitmap, src_x, src_y, width, height, dst_x, dst_y); +#endif +} + void DrawSimpleBlackLine(Bitmap *bitmap, int from_x, int from_y, int to_x, int to_y) { @@ -774,16 +854,6 @@ Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color) return GetPixelFromRGB(bitmap, color_r, color_g, color_b); } -/* execute all pending screen drawing operations */ -void FlushDisplay(void) -{ -} - -/* execute and wait for all pending screen drawing operations */ -void SyncDisplay(void) -{ -} - void KeyboardAutoRepeatOn(void) { #if defined(TARGET_SDL2) @@ -805,11 +875,6 @@ void KeyboardAutoRepeatOff(void) #endif } -boolean PointerInWindow(DrawWindow *window) -{ - return TRUE; -} - boolean SetVideoMode(boolean fullscreen) { return SDLSetVideoMode(&backbuffer, fullscreen); @@ -845,7 +910,7 @@ Bitmap *LoadCustomImage(char *basename) Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename); if ((new_bitmap = LoadImage(filename)) == NULL) - Error(ERR_EXIT, "LoadImage() failed: %s", GetError()); + Error(ERR_EXIT, "LoadImage('%s') failed: %s", basename, GetError()); return new_bitmap; } @@ -872,7 +937,7 @@ void ReloadCustomImage(Bitmap *bitmap, char *basename) if ((new_bitmap = LoadImage(filename)) == NULL) { - Error(ERR_WARN, "LoadImage() failed: %s", GetError()); + Error(ERR_WARN, "LoadImage('%s') failed: %s", basename, GetError()); return; } @@ -1125,6 +1190,16 @@ void CreateBitmapWithSmallBitmaps(Bitmap **bitmaps, int zoom_factor, CreateScaledBitmaps(bitmaps, zoom_factor, tile_size, TRUE); } +void CreateBitmapTextures(Bitmap **bitmaps) +{ + SDLCreateBitmapTextures(bitmaps[IMG_BITMAP_STANDARD]); +} + +void FreeBitmapTextures(Bitmap **bitmaps) +{ + SDLFreeBitmapTextures(bitmaps[IMG_BITMAP_STANDARD]); +} + void ScaleBitmap(Bitmap **bitmaps, int zoom_factor) { CreateScaledBitmaps(bitmaps, zoom_factor, 0, FALSE); @@ -1275,6 +1350,8 @@ void SetMouseCursor(int mode) mode == CURSOR_PLAYFIELD ? cursor_playfield : NULL); SDLSetMouseCursor(cursor_new); + + gfx.cursor_mode = mode; }