From fa0ff96533462b8d627f59790b4e21d698797e2e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 1 Feb 2012 19:52:13 +0900 Subject: [PATCH] Clean up the mess with host_basepal and vid_colormap. Libs should not be reaching into the exe :P --- include/QF/vid.h | 2 +- libs/video/targets/vid.c | 1 + libs/video/targets/vid_3dfxsvga.c | 4 ++-- libs/video/targets/vid_fbdev.c | 4 +++- libs/video/targets/vid_glx.c | 4 ++-- libs/video/targets/vid_sdl.c | 4 +++- libs/video/targets/vid_sdl32.c | 4 +++- libs/video/targets/vid_sgl.c | 4 ++-- libs/video/targets/vid_svgalib.c | 3 ++- libs/video/targets/vid_wgl.c | 4 ++-- libs/video/targets/vid_x11.c | 4 ++-- nq/source/cl_main.c | 10 ++++------ qw/source/cl_main.c | 20 +++++++++----------- 13 files changed, 36 insertions(+), 32 deletions(-) diff --git a/include/QF/vid.h b/include/QF/vid.h index 882c75ec5..41bfe2375 100644 --- a/include/QF/vid.h +++ b/include/QF/vid.h @@ -98,7 +98,7 @@ void VID_Init_Cvars (void); // Called at startup to set up translation tables, takes 256 8 bit RGB values // the palette data will go away after the call, so it must be copied off if // the video driver will need it again -void VID_Init (unsigned char *); +void VID_Init (byte *palette, byte *colormap); // Called at shutdown void VID_Shutdown (void); diff --git a/libs/video/targets/vid.c b/libs/video/targets/vid.c index f2689f7ce..cb7a0b77d 100644 --- a/libs/video/targets/vid.c +++ b/libs/video/targets/vid.c @@ -51,6 +51,7 @@ static __attribute__ ((used)) const char rcsid[] = /* Software and hardware gamma support */ VISIBLE byte gammatable[256]; +byte *vid_colormap; cvar_t *vid_gamma; cvar_t *vid_system_gamma; cvar_t *con_width; // FIXME: Try to move with rest of con code diff --git a/libs/video/targets/vid_3dfxsvga.c b/libs/video/targets/vid_3dfxsvga.c index bc6a3ca2a..4b1be3387 100644 --- a/libs/video/targets/vid_3dfxsvga.c +++ b/libs/video/targets/vid_3dfxsvga.c @@ -271,7 +271,7 @@ findres (unsigned int *width, unsigned int *height) } void -VID_Init (unsigned char *palette) +VID_Init (byte *palette, byte *colormap) { GLint attribs[32]; @@ -290,7 +290,7 @@ VID_Init (unsigned char *palette) vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpheight = WARP_HEIGHT; - vid.colormap8 = vid_colormap; + vid.colormap8 = vid_colormap = colormap; vid.fullbright = 256 - vid.colormap8[256 * VID_GRADES]; // interpret command-line params diff --git a/libs/video/targets/vid_fbdev.c b/libs/video/targets/vid_fbdev.c index 2ff05dcfe..33cb9e28e 100644 --- a/libs/video/targets/vid_fbdev.c +++ b/libs/video/targets/vid_fbdev.c @@ -399,7 +399,7 @@ fb_switch_init (void) } void -VID_Init (unsigned char *palette) +VID_Init (byte *palette, byte *colormap) { struct VideoMode *vmode; const char *modestr; @@ -410,6 +410,8 @@ VID_Init (unsigned char *palette) if (fbdev_inited) return; + vid_colormap = colormap; + if (COM_CheckParm ("-novideo")) { vid.width = 320; vid.height = 200; diff --git a/libs/video/targets/vid_glx.c b/libs/video/targets/vid_glx.c index 7a5619088..15993e4e9 100644 --- a/libs/video/targets/vid_glx.c +++ b/libs/video/targets/vid_glx.c @@ -187,7 +187,7 @@ GL_EndRendering (void) } void -VID_Init (unsigned char *palette) +VID_Init (byte *palette, byte *colormap) { int attrib[] = { GLX_RGBA, @@ -205,7 +205,7 @@ VID_Init (unsigned char *palette) vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpheight = WARP_HEIGHT; - vid.colormap8 = vid_colormap; + vid.colormap8 = vid_colormap = colormap; vid.fullbright = 256 - vid.colormap8[256 * VID_GRADES]; X11_OpenDisplay (); diff --git a/libs/video/targets/vid_sdl.c b/libs/video/targets/vid_sdl.c index b5d96e74d..4bfbafea9 100644 --- a/libs/video/targets/vid_sdl.c +++ b/libs/video/targets/vid_sdl.c @@ -85,7 +85,7 @@ do_screen_buffer (void) } void -VID_Init (unsigned char *palette) +VID_Init (byte *palette, byte *colormap) { Uint32 flags; @@ -104,6 +104,8 @@ VID_Init (unsigned char *palette) // Initialize display if (!(screen = SDL_SetVideoMode (vid.width, vid.height, 8, flags))) Sys_Error ("VID: Couldn't set video mode: %s", SDL_GetError ()); + + vid_colormap = colormap; VID_InitGamma (palette); VID_SetPalette (vid.palette); diff --git a/libs/video/targets/vid_sdl32.c b/libs/video/targets/vid_sdl32.c index 670c3be2e..a342e5b42 100644 --- a/libs/video/targets/vid_sdl32.c +++ b/libs/video/targets/vid_sdl32.c @@ -89,7 +89,7 @@ do_screen_buffer (void) } void -VID_Init (unsigned char *palette) +VID_Init (byte *palette, byte *colormap) { Uint32 flags; @@ -119,6 +119,8 @@ VID_Init (unsigned char *palette) if (!(screen = SDL_SetVideoMode (vid.width, vid.height, vid_bitdepth->int_val, flags))) Sys_Error ("VID: Couldn't set video mode: %s", SDL_GetError ()); + + vid_colormap = colormap; VID_InitGamma (palette); VID_SetPalette (vid.palette); diff --git a/libs/video/targets/vid_sgl.c b/libs/video/targets/vid_sgl.c index 0287b37e5..1c3d9cb26 100644 --- a/libs/video/targets/vid_sgl.c +++ b/libs/video/targets/vid_sgl.c @@ -99,7 +99,7 @@ GL_EndRendering (void) } void -VID_Init (unsigned char *palette) +VID_Init (byte *palette, byte *colormap) { Uint32 flags = SDL_OPENGL; int i, j; @@ -114,7 +114,7 @@ VID_Init (unsigned char *palette) vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpheight = WARP_HEIGHT; - vid.colormap8 = vid_colormap; + vid.colormap8 = vid_colormap = colormap; vid.fullbright = 256 - vid.colormap8[256 * VID_GRADES]; // Check if we want fullscreen diff --git a/libs/video/targets/vid_svgalib.c b/libs/video/targets/vid_svgalib.c index 32cf6cd20..d2c9ef9f4 100644 --- a/libs/video/targets/vid_svgalib.c +++ b/libs/video/targets/vid_svgalib.c @@ -352,7 +352,7 @@ comefrom_background (void) } void -VID_Init (unsigned char *palette) +VID_Init (byte *palette, byte *colormap) { int err; @@ -382,6 +382,7 @@ VID_Init (unsigned char *palette) current_mode = get_mode (vid.width, vid.height, 8); /* Set vid parameters */ + vid_colormap = colormap; VID_SetMode (current_mode, palette); VID_InitGamma (palette); diff --git a/libs/video/targets/vid_wgl.c b/libs/video/targets/vid_wgl.c index 8f61ecb94..fee5086b3 100644 --- a/libs/video/targets/vid_wgl.c +++ b/libs/video/targets/vid_wgl.c @@ -450,7 +450,7 @@ bSetupPixelFormat (HDC hDC) } void -VID_Init (unsigned char *palette) +VID_Init (byte *palette, byte *colormap) { BOOL stat; WORD bpp, vid_mode; @@ -536,7 +536,7 @@ VID_Init (unsigned char *palette) vid.maxwarpwidth = WARP_WIDTH; vid.maxwarpheight = WARP_HEIGHT; - vid.colormap8 = vid_colormap; + vid.colormap8 = vid_colormap = colormap; vid.fullbright = 256 - vid.colormap8[256 * VID_GRADES]; #ifdef SPLASH_SCREEN diff --git a/libs/video/targets/vid_x11.c b/libs/video/targets/vid_x11.c index 1715492a1..5a11c3fb3 100644 --- a/libs/video/targets/vid_x11.c +++ b/libs/video/targets/vid_x11.c @@ -392,7 +392,7 @@ x11_init_buffers (void) need it later. */ void -VID_Init (unsigned char *palette) +VID_Init (byte *palette, byte *colormap) { int pnum, i; XVisualInfo template; @@ -402,7 +402,7 @@ VID_Init (unsigned char *palette) VID_GetWindowSize (320, 200); vid.numpages = 2; - vid.colormap8 = vid_colormap; + vid.colormap8 = vid_colormap = colormap; vid.fullbright = 256 - vid.colormap8[256 * VID_GRADES]; srandom (getpid ()); diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index d8ac4f0e2..86679bb0d 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -60,8 +60,6 @@ static __attribute__ ((used)) const char rcsid[] = #include "server.h" #include "sbar.h" -byte *vid_colormap; - // these two are not intended to be set directly cvar_t *cl_name; cvar_t *cl_color; @@ -505,17 +503,17 @@ Force_CenterView_f (void) void CL_Init (cbuf_t *cbuf) { - byte *basepal; + byte *basepal, *colormap; basepal = (byte *) QFS_LoadHunkFile ("gfx/palette.lmp"); if (!basepal) Sys_Error ("Couldn't load gfx/palette.lmp"); - vid_colormap = (byte *) QFS_LoadHunkFile ("gfx/colormap.lmp"); - if (!vid_colormap) + colormap = (byte *) QFS_LoadHunkFile ("gfx/colormap.lmp"); + if (!colormap) Sys_Error ("Couldn't load gfx/colormap.lmp"); Key_Init (cbuf); - VID_Init (basepal); + VID_Init (basepal, colormap); Draw_Init (); SCR_Init (); R_Init (); diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 12d1e9314..578a919ea 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -118,7 +118,7 @@ static __attribute__ ((used)) const char rcsid[] = CLIENT_PLUGIN_PROTOS static plugin_list_t client_plugin_list[] = { - CLIENT_PLUGIN_LIST + CLIENT_PLUGIN_LIST }; // we need to declare some mouse variables here, because the menu system @@ -212,9 +212,6 @@ double oldcon_realtime; int host_hunklevel; -byte *host_basepal; -byte *vid_colormap; - cvar_t *host_speeds; cvar_t *hud_fps; cvar_t *hud_ping; @@ -1717,6 +1714,8 @@ CL_Autoexec (int phase) void Host_Init (void) { + byte *basepal, *colormap; + cl_cbuf = Cbuf_New (&id_interp); cl_stbuf = Cbuf_New (&id_interp); @@ -1798,14 +1797,14 @@ Host_Init (void) Sys_Printf ("%4.1f megabyte heap.\n", cl_mem_size->value); - host_basepal = (byte *) QFS_LoadHunkFile ("gfx/palette.lmp"); - if (!host_basepal) + basepal = (byte *) QFS_LoadHunkFile ("gfx/palette.lmp"); + if (!basepal) Sys_Error ("Couldn't load gfx/palette.lmp"); - vid_colormap = (byte *) QFS_LoadHunkFile ("gfx/colormap.lmp"); - if (!vid_colormap) + colormap = (byte *) QFS_LoadHunkFile ("gfx/colormap.lmp"); + if (!colormap) Sys_Error ("Couldn't load gfx/colormap.lmp"); - VID_Init (host_basepal); + VID_Init (basepal, colormap); Draw_Init (); SCR_Init (); R_Init (); @@ -1877,6 +1876,5 @@ Host_Shutdown (void) NET_Shutdown (); S_Shutdown (); IN_Shutdown (); - if (host_basepal) - VID_Shutdown (); + VID_Shutdown (); }